Skip to content

Commit

Permalink
Some small updates
Browse files Browse the repository at this point in the history
Add ItemStackHandleEvent: similar to ItemStackHandler(after it)
Add Item.drop(): spawn a drop in world
Fix /si give: when inventory is full,drop on the ground
Feature ItemInfo: auto replace & to colorChar(§)
  • Loading branch information
way-zer committed Jul 25, 2019
1 parent 412d568 commit 4a1da9e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ task buildArtifact(type: Zip){
from(shadowJar.getArchiveFile()){
rename("-all","")
}
archiveFileName ="SuperItem-${version}.zip"
archiveFileName = "SuperItem-${version.toString()}.zip"
destinationDirectory =file("$rootDir/artifacts/")
}
artifacts {
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/cf/wayzer/SuperItem/Commander.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class Commander : CommandExecutor {
}
if (item.givePlayer(player))
s.sendMessage("§a给予成功")
else{
item.drop(player.location,player)
player.sendMessage("§a背包已满,已掉落")
s.sendMessage("§e背包已满,已掉落")
}
}

private fun getItem(s: CommandSender, args: Array<String>) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/cf/wayzer/SuperItem/Item.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cf.wayzer.SuperItem.features.CoolDown
import cf.wayzer.SuperItem.features.ItemInfo
import cf.wayzer.SuperItem.features.Permission
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.entity.Player
import org.bukkit.event.Event
import org.bukkit.event.EventPriority
Expand Down Expand Up @@ -101,6 +102,10 @@ abstract class Item : Listener {
return true
}

fun drop(location: Location,player: Player?=null){
location.world.dropItem(location,get<ItemInfo>().newItemStack(player))
}

/**
* 判断物品是否是当前Item的道具
*/
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/cf/wayzer/SuperItem/events/ItemStackHandleEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cf.wayzer.SuperItem.events

import org.bukkit.entity.Player
import org.bukkit.event.Event
import org.bukkit.event.HandlerList
import org.bukkit.inventory.ItemStack

data class ItemStackHandleEvent (var itemStack:ItemStack,val player:Player?):Event() {
override fun getHandlers()=staticHandlers

companion object{
private val staticHandlers = HandlerList()
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/cf/wayzer/SuperItem/features/ItemInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cf.wayzer.SuperItem.features

import cf.wayzer.SuperItem.Feature
import cf.wayzer.SuperItem.Main
import cf.wayzer.SuperItem.Main.Companion.main
import cf.wayzer.SuperItem.events.ItemStackHandleEvent
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
Expand Down Expand Up @@ -48,6 +50,11 @@ class ItemInfo(
fun newItemStack(p:Player?=null):ItemStack{
val itemStack = itemStackTemplate.clone()
itemStackHandlers.forEach { it(itemStack,p) }
main.server.pluginManager.callEvent(ItemStackHandleEvent(itemStack,p))
itemStack.itemMeta = itemStack.itemMeta.apply {
displayName = displayName.replace("&","§")
lore = lore.map { it.replace("&","§") }
}
return itemStack
}

Expand Down

0 comments on commit 4a1da9e

Please sign in to comment.