From bdb213e3e1f51c2e383b54f7263028ab34c6e2fe Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 4 May 2020 15:58:02 +0200 Subject: [PATCH] feat: disable spawn from wandering trader --- .../main/java/de/cliffbreak/varo/Varo.java | 2 ++ .../varo/listeners/CreatureSpawnListener.java | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 varo/src/main/java/de/cliffbreak/varo/listeners/CreatureSpawnListener.java diff --git a/varo/src/main/java/de/cliffbreak/varo/Varo.java b/varo/src/main/java/de/cliffbreak/varo/Varo.java index 4093388..d241b2c 100644 --- a/varo/src/main/java/de/cliffbreak/varo/Varo.java +++ b/varo/src/main/java/de/cliffbreak/varo/Varo.java @@ -15,6 +15,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import de.cliffbreak.varo.commands.VaroCommand; import de.cliffbreak.varo.listeners.BannedItemListener; import de.cliffbreak.varo.listeners.ChatListener; +import de.cliffbreak.varo.listeners.CreatureSpawnListener; import de.cliffbreak.varo.listeners.EntityRegainHealthListener; import de.cliffbreak.varo.listeners.PlayerDeathListener; import de.cliffbreak.varo.listeners.PlayerJoinQuitListener; @@ -43,6 +44,7 @@ public class Varo extends JavaPlugin { getServer().getPluginManager().registerEvents(new EntityRegainHealthListener(), this); getServer().getPluginManager().registerEvents(new PlayerDeathListener(this), this); getServer().getPluginManager().registerEvents(new BannedItemListener(), this); + getServer().getPluginManager().registerEvents(new CreatureSpawnListener(), this); getCommand("varo").setExecutor(new VaroCommand(this)); diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/CreatureSpawnListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/CreatureSpawnListener.java new file mode 100644 index 0000000..970e935 --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/CreatureSpawnListener.java @@ -0,0 +1,21 @@ +package de.cliffbreak.varo.listeners; + +import org.bukkit.Bukkit; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.CreatureSpawnEvent; + +public class CreatureSpawnListener implements Listener { + + @EventHandler() + public void onCreatureSpawn(CreatureSpawnEvent e) { + LivingEntity livingEntity = e.getEntity(); + if (livingEntity.getType().equals(EntityType.WANDERING_TRADER) + || livingEntity.getType().equals(EntityType.TRADER_LLAMA)) { + Bukkit.getLogger().info("Denied Wandering-Trader Spawn"); + e.setCancelled(true); + } + } +} \ No newline at end of file