feat: add forbidden Items
This commit is contained in:
parent
dda0d5cb01
commit
c00cb8a8e9
2 changed files with 41 additions and 0 deletions
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue