diff --git a/build.gradle.kts b/build.gradle.kts index 14ec35d..fc891f2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "net.azisaba" -version = "1.15.2+6.16.4" +version = "1.15.2+6.16.5" java { toolchain.languageVersion.set(JavaLanguageVersion.of(8)) diff --git a/src/main/java/com/github/mori01231/lifecore/LifeCore.kt b/src/main/java/com/github/mori01231/lifecore/LifeCore.kt index bc121c5..a563384 100644 --- a/src/main/java/com/github/mori01231/lifecore/LifeCore.kt +++ b/src/main/java/com/github/mori01231/lifecore/LifeCore.kt @@ -20,14 +20,11 @@ import org.bukkit.Bukkit import org.bukkit.command.CommandExecutor import org.bukkit.entity.ItemFrame import org.bukkit.plugin.java.JavaPlugin -import org.bukkit.plugin.java.PluginClassLoader import java.io.File import java.io.IOException import java.net.InetSocketAddress -import java.nio.file.Files import java.util.concurrent.Executor import java.util.concurrent.Executors -import java.util.stream.Collectors class LifeCore : JavaPlugin() { val gcListener = GCListener(this) @@ -308,6 +305,7 @@ class LifeCore : JavaPlugin() { pm.registerEvents(UpdateInventoryOnCloseListener(this), this) pm.registerEvents(PromptSignListener, this) pm.registerEvents(PicksawItemListener(dataLoader), this) + pm.registerEvents(BlockListener, this) // Items pm.registerEvents(OreOnlyItemListener(), this) diff --git a/src/main/java/com/github/mori01231/lifecore/command/BlockListener.kt b/src/main/java/com/github/mori01231/lifecore/command/BlockListener.kt new file mode 100644 index 0000000..0c0803a --- /dev/null +++ b/src/main/java/com/github/mori01231/lifecore/command/BlockListener.kt @@ -0,0 +1,17 @@ +package com.github.mori01231.lifecore.command + +import com.github.mori01231.lifecore.util.ItemUtil +import org.bukkit.ChatColor +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockPlaceEvent + +object BlockListener : Listener { + @EventHandler + fun onBlockPlace(e: BlockPlaceEvent) { + if (ItemUtil.containsTag(e.itemInHand, "backup") && !e.player.isSneaking) { + e.player.sendMessage("${ChatColor.RED}このブロックを設置すると中身のアイテムが変質し、元の状態に戻らなくなる可能性があります。") + e.player.sendMessage("${ChatColor.RED}この警告を無視して設置したい場合はスニークしながら設置してください。") + } + } +} diff --git a/src/main/java/com/github/mori01231/lifecore/util/ItemUtil.java b/src/main/java/com/github/mori01231/lifecore/util/ItemUtil.java index ad0da1e..bcaa6c1 100644 --- a/src/main/java/com/github/mori01231/lifecore/util/ItemUtil.java +++ b/src/main/java/com/github/mori01231/lifecore/util/ItemUtil.java @@ -159,4 +159,10 @@ public static ItemStack restoreTag(@Nullable ItemStack stack) { if (backup == null || backup.isEmpty()) return stack; return setTag(stack, null, backup); } + + public static boolean containsTag(@Nullable ItemStack stack, @NotNull String key) { + if (stack == null || stack.getType().isAir()) return false; + NBTTagCompound tag = CraftItemStack.asNMSCopy(stack).getTag(); + return tag != null && tag.hasKey(key); + } }