Skip to content

Commit

Permalink
show warning when placing block with backup tag
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Jul 29, 2024
1 parent 730fc71 commit 1d50dd2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/github/mori01231/lifecore/LifeCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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}この警告を無視して設置したい場合はスニークしながら設置してください。")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 1d50dd2

Please sign in to comment.