From d81f42f36013f7a7bc467b345e72754f67d160cf Mon Sep 17 00:00:00 2001 From: Alexander B Date: Tue, 5 Jan 2021 19:25:04 +0100 Subject: [PATCH] Implement BlockPlace --- eu/railduction/ruakij/spawnerDrops/Main.java | 4 +- .../spawnerDrops/listener/OnBlockPlace.java | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 eu/railduction/ruakij/spawnerDrops/listener/OnBlockPlace.java diff --git a/eu/railduction/ruakij/spawnerDrops/Main.java b/eu/railduction/ruakij/spawnerDrops/Main.java index 36abb68..b33da29 100644 --- a/eu/railduction/ruakij/spawnerDrops/Main.java +++ b/eu/railduction/ruakij/spawnerDrops/Main.java @@ -1,5 +1,6 @@ package eu.railduction.ruakij.spawnerDrops; +import eu.railduction.ruakij.spawnerDrops.listener.OnBlockPlace; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.configuration.file.FileConfiguration; @@ -16,7 +17,8 @@ public class Main extends JavaPlugin { public void onEnable() { - PluginManager PluginManager = Bukkit.getPluginManager(); + PluginManager pluginManager = Bukkit.getPluginManager(); + pluginManager.registerEvents(new OnBlockPlace(), this); loadConfigs(); diff --git a/eu/railduction/ruakij/spawnerDrops/listener/OnBlockPlace.java b/eu/railduction/ruakij/spawnerDrops/listener/OnBlockPlace.java new file mode 100644 index 0000000..c06d835 --- /dev/null +++ b/eu/railduction/ruakij/spawnerDrops/listener/OnBlockPlace.java @@ -0,0 +1,40 @@ +package eu.railduction.ruakij.spawnerDrops.listener; + +import eu.railduction.ruakij.spawnerDrops.Main; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; + +public class OnBlockPlace implements Listener { + + public void onBlockPlaceEvent(BlockPlaceEvent e){ + + Player p = e.getPlayer(); + + if(e.getBlock().getType() == Material.MOB_SPAWNER){ + Location loc = e.getBlock().getLocation(); + + // Can break? + boolean isAdmin = p.hasPermission("spawnerDrops.admin"); + if(!isAdmin && !Main.config.getBoolean("place.player.canPlace")){ + + // Cancel place-event + e.setCancelled(true); + + // Send msg + String msg = Main.config.getString("place.player.msg.fail"); + if(msg != null && !msg.equals("")) p.sendMessage(msg); + } + else{ + // Write place-data + Main.data.set(Main.serialiseLocation(loc), isAdmin); + + // Send msg + String msg = Main.config.getString("place.player.msg.success"); + if(msg != null && !msg.equals("")) p.sendMessage(msg); + } + } + } +}