Implement BlockPlace

master
Alexander B 4 years ago
parent 5444f75c21
commit d81f42f360

@ -1,5 +1,6 @@
package eu.railduction.ruakij.spawnerDrops; package eu.railduction.ruakij.spawnerDrops;
import eu.railduction.ruakij.spawnerDrops.listener.OnBlockPlace;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -16,7 +17,8 @@ public class Main extends JavaPlugin {
public void onEnable() { public void onEnable() {
PluginManager PluginManager = Bukkit.getPluginManager(); PluginManager pluginManager = Bukkit.getPluginManager();
pluginManager.registerEvents(new OnBlockPlace(), this);
loadConfigs(); loadConfigs();

@ -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);
}
}
}
}
Loading…
Cancel
Save