|
|
|
|
@ -1,16 +1,29 @@ |
|
|
|
|
package xyz.soukup.ecoCraftCore.regions; |
|
|
|
|
|
|
|
|
|
import org.bukkit.Location; |
|
|
|
|
import org.bukkit.NamespacedKey; |
|
|
|
|
import org.bukkit.block.Block; |
|
|
|
|
import org.bukkit.entity.Entity; |
|
|
|
|
import org.bukkit.entity.Item; |
|
|
|
|
import org.bukkit.entity.Minecart; |
|
|
|
|
import org.bukkit.entity.Player; |
|
|
|
|
import org.bukkit.event.EventHandler; |
|
|
|
|
import org.bukkit.event.Listener; |
|
|
|
|
import org.bukkit.event.block.Action; |
|
|
|
|
import org.bukkit.event.block.BlockBreakEvent; |
|
|
|
|
import org.bukkit.event.block.BlockPlaceEvent; |
|
|
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent; |
|
|
|
|
import org.bukkit.event.inventory.InventoryPickupItemEvent; |
|
|
|
|
import org.bukkit.event.player.*; |
|
|
|
|
import org.bukkit.event.vehicle.VehicleDestroyEvent; |
|
|
|
|
import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; |
|
|
|
|
import org.bukkit.inventory.ItemStack; |
|
|
|
|
import org.bukkit.persistence.PersistentDataType; |
|
|
|
|
import xyz.soukup.ecoCraftCore.database.objects.Region; |
|
|
|
|
import xyz.soukup.ecoCraftCore.database.objects.RegionMember; |
|
|
|
|
|
|
|
|
|
import static xyz.soukup.ecoCraftCore.EcoCraftCore.plugin; |
|
|
|
|
|
|
|
|
|
public class RegionEvents implements Listener { |
|
|
|
|
|
|
|
|
|
@EventHandler |
|
|
|
|
@ -40,7 +53,36 @@ public class RegionEvents implements Listener { |
|
|
|
|
block.getZ() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
event.setCancelled(!allowed); |
|
|
|
|
if (allowed){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EventHandler |
|
|
|
|
public void onPlayerInteractPhysical(PlayerInteractEvent event){ |
|
|
|
|
if (!event.getAction().equals(Action.PHYSICAL)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Player player = event.getPlayer(); |
|
|
|
|
Location location = player.getLocation(); |
|
|
|
|
|
|
|
|
|
boolean allowed = isAllowedToInteract( |
|
|
|
|
location.getWorld().getName(), |
|
|
|
|
player, |
|
|
|
|
location.getBlockX(), |
|
|
|
|
location.getBlockY(), |
|
|
|
|
location.getBlockZ() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (allowed){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EventHandler |
|
|
|
|
@ -55,7 +97,11 @@ public class RegionEvents implements Listener { |
|
|
|
|
block.getZ() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
event.setCancelled(!allowed); |
|
|
|
|
if (allowed){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EventHandler |
|
|
|
|
@ -71,7 +117,11 @@ public class RegionEvents implements Listener { |
|
|
|
|
block.getZ() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
event.setCancelled(!allowed); |
|
|
|
|
if (allowed){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EventHandler |
|
|
|
|
@ -86,7 +136,11 @@ public class RegionEvents implements Listener { |
|
|
|
|
clickedBlock.getZ() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
event.setCancelled(!allowed); |
|
|
|
|
if (allowed){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EventHandler |
|
|
|
|
@ -101,10 +155,142 @@ public class RegionEvents implements Listener { |
|
|
|
|
clickedBlock.getZ() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
event.setCancelled(!allowed); |
|
|
|
|
if (allowed){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EventHandler |
|
|
|
|
public void onEntityInteract(PlayerInteractEntityEvent event){ |
|
|
|
|
Entity entity = event.getRightClicked(); |
|
|
|
|
Location location = entity.getLocation(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean allowed = isAllowedToInteract( |
|
|
|
|
location.getWorld().getName(), |
|
|
|
|
event.getPlayer(), |
|
|
|
|
location.getBlockX(), |
|
|
|
|
location.getBlockY(), |
|
|
|
|
location.getBlockZ()); |
|
|
|
|
|
|
|
|
|
if (allowed){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EventHandler |
|
|
|
|
public void onEntityHit(EntityDamageByEntityEvent event){ |
|
|
|
|
|
|
|
|
|
if (!(event.getDamager() instanceof Player player)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Entity entity = event.getEntity(); |
|
|
|
|
Location location = entity.getLocation(); |
|
|
|
|
|
|
|
|
|
boolean allowed = isAllowedToInteract( |
|
|
|
|
location.getWorld().getName(), |
|
|
|
|
player, |
|
|
|
|
location.getBlockX(), |
|
|
|
|
location.getBlockY(), |
|
|
|
|
location.getBlockZ()); |
|
|
|
|
|
|
|
|
|
if (allowed){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EventHandler |
|
|
|
|
public void onMinecartPush(VehicleEntityCollisionEvent event) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!(event.getEntity() instanceof Player player)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Location location = event.getVehicle().getLocation(); |
|
|
|
|
|
|
|
|
|
boolean allowed = isAllowedToInteract( |
|
|
|
|
location.getWorld().getName(), |
|
|
|
|
player, |
|
|
|
|
location.getBlockX(), |
|
|
|
|
location.getBlockY(), |
|
|
|
|
location.getBlockZ()); |
|
|
|
|
|
|
|
|
|
if (allowed){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//Preventing hopper interaction :P
|
|
|
|
|
@EventHandler |
|
|
|
|
public void onDrop(PlayerDropItemEvent event) { |
|
|
|
|
Player player = event.getPlayer(); |
|
|
|
|
Location location = player.getLocation(); |
|
|
|
|
|
|
|
|
|
boolean allowed = isAllowedToInteract( |
|
|
|
|
location.getWorld().getName(), |
|
|
|
|
player, |
|
|
|
|
location.getBlockX(), |
|
|
|
|
location.getBlockY(), |
|
|
|
|
location.getBlockZ()); |
|
|
|
|
|
|
|
|
|
if (allowed){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Item item = event.getItemDrop(); |
|
|
|
|
|
|
|
|
|
item.getPersistentDataContainer().set(new NamespacedKey(plugin, "hopper_stopper"), PersistentDataType.BYTE, (byte) 1); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EventHandler |
|
|
|
|
public void onHopperPickup(InventoryPickupItemEvent event) { |
|
|
|
|
Item item = event.getItem(); |
|
|
|
|
|
|
|
|
|
if (!item.getPersistentDataContainer().has(new NamespacedKey(plugin, "hopper_stopper"), PersistentDataType.BYTE)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EventHandler |
|
|
|
|
public void onVehicleDestroy(VehicleDestroyEvent event) { |
|
|
|
|
if (!(event.getAttacker() instanceof Player player)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Location location = event.getVehicle().getLocation(); |
|
|
|
|
|
|
|
|
|
boolean allowed = isAllowedToInteract( |
|
|
|
|
location.getWorld().getName(), |
|
|
|
|
player, |
|
|
|
|
location.getBlockX(), |
|
|
|
|
location.getBlockY(), |
|
|
|
|
location.getBlockZ()); |
|
|
|
|
|
|
|
|
|
if (allowed){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isAllowedToInteract(String island, Player player, Location location){ |
|
|
|
|
return isAllowedToInteract(island, player, location.getBlockX(), location.getBlockY(), location.getBlockZ()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isAllowedToInteract(String island, Player player, int x, int y, int z){ |
|
|
|
|
if (player.isOp()){ |
|
|
|
|
|