From c00cb8a8e914cafb4214a03654050a6361cbaee3 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 4 May 2020 11:53:10 +0200 Subject: [PATCH] feat: add forbidden Items --- .../main/java/de/cliffbreak/varo/Varo.java | 2 + .../varo/listeners/BannedItemListener.java | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 varo/src/main/java/de/cliffbreak/varo/listeners/BannedItemListener.java diff --git a/varo/src/main/java/de/cliffbreak/varo/Varo.java b/varo/src/main/java/de/cliffbreak/varo/Varo.java index d405dbd..f9032b9 100644 --- a/varo/src/main/java/de/cliffbreak/varo/Varo.java +++ b/varo/src/main/java/de/cliffbreak/varo/Varo.java @@ -14,6 +14,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import de.cliffbreak.varo.commands.TestCommand; import de.cliffbreak.varo.commands.VaroCommand; +import de.cliffbreak.varo.listeners.BannedItemListener; import de.cliffbreak.varo.listeners.ChatListener; import de.cliffbreak.varo.listeners.EntityRegainHealthListener; import de.cliffbreak.varo.listeners.PlayerDeathListener; @@ -42,6 +43,7 @@ public class Varo extends JavaPlugin { getServer().getPluginManager().registerEvents(new ChatListener(), this); getServer().getPluginManager().registerEvents(new EntityRegainHealthListener(), this); getServer().getPluginManager().registerEvents(new PlayerDeathListener(this), this); + getServer().getPluginManager().registerEvents(new BannedItemListener(), this); getCommand("varo").setExecutor(new VaroCommand(this)); getCommand("test").setExecutor(new TestCommand()); diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/BannedItemListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/BannedItemListener.java new file mode 100644 index 0000000..9ebb33a --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/BannedItemListener.java @@ -0,0 +1,39 @@ +package de.cliffbreak.varo.listeners; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityPickupItemEvent; +import org.bukkit.event.inventory.InventoryClickEvent; + +public class BannedItemListener implements Listener { + + @EventHandler() + public void onEntityPickupItem(EntityPickupItemEvent e) { + if (e.getEntity() instanceof Player) { + Material mat = e.getItem().getItemStack().getType(); + if (isForbiddenMaterial(mat)) { + e.getEntity().sendMessage("§cVerbotenes Item wurde entfernt."); + e.getItem().remove(); + e.setCancelled(true); + } + } + } + + @EventHandler() + public void onInventoryClick(InventoryClickEvent e) { + if (e.getCurrentItem() == null) + return; + Material mat = e.getCurrentItem().getType(); + if (isForbiddenMaterial(mat)) { + e.getWhoClicked().sendMessage("§cVerbotenes Item kann nicht ins Inventar verschoben werden."); + e.setCancelled(true); + } + } + + private boolean isForbiddenMaterial(Material mat) { + return mat.equals(Material.ENCHANTED_GOLDEN_APPLE) || mat.equals(Material.FISHING_ROD) + || mat.equals(Material.TOTEM_OF_UNDYING); + } +} \ No newline at end of file