public class BlockListener implements Listener {
private ESIsland plugin;
public BlockListener(ESIsland plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockBreak(BlockBreakEvent event) {
Location location = event.getBlock().getLocation();
if (!location.getWorld().equals(Values.ISLAND_WORLD)) {
return;
}
Island island = plugin.getIslandManager().getIsland(location);
if (island == null) {
event.setCancelled(true);
event.getPlayer().sendMessage("§cIsland protected");
return;
}
if (island.getValue(Island.Flag.ALLOW_BUILD).equals(Island.Value.PRIVATE)) {
if (!event.getPlayer().getUniqueId().equals(island.getOwner().getUniqueId())) {
event.setCancelled(true);
event.getPlayer().sendMessage("§cIsland protected");
}
} else if (island.getValue(Island.Flag.ALLOW_BUILD).equals(Island.Value.FRIENDS)) {
if (!(event.getPlayer().getUniqueId().equals(island.getOwner().getUniqueId()) )) {
event.setCancelled(true);
event.getPlayer().sendMessage("§cIsland protected");
}
}
}
}