@EventHandler
public void onBlockProtect(ProtectBlockEvent event) {
if (event.isProtected()) {
return;
}
Block block = event.getBlock();
Player player = event.getPlayer();
if (player == null) {
return;
}
int x = block.getX();
int y = block.getY();
int z = block.getZ();
String worldName = block.getWorld().getName();
Protection existingProtection = lwc.getPhysicalDatabase().loadProtection(worldName, x, y, z);
if (existingProtection != null) {
event.setProtected(true);
return;
}
LWCProtectionRegisterEvent protectionEvent = new LWCProtectionRegisterEvent(player, block);
lwc.getModuleLoader().dispatchEvent(protectionEvent);
if (protectionEvent.isCancelled()) {
return;
}
Protection protection = lwc.getPhysicalDatabase().registerProtection(block.getType().getId(), Protection.Type.PRIVATE, worldName, player.getUniqueId().toString(), "", x, y, z);
if (protection != null) {
event.setProtected(true);
}
}