|
@@ -1,9 +1,9 @@
|
|
|
package me.lethunderhawk.clans.claim;
|
|
package me.lethunderhawk.clans.claim;
|
|
|
|
|
|
|
|
-import me.lethunderhawk.fluxapi.FluxService;
|
|
|
|
|
import me.lethunderhawk.clans.Clan;
|
|
import me.lethunderhawk.clans.Clan;
|
|
|
import me.lethunderhawk.clans.ClanManager;
|
|
import me.lethunderhawk.clans.ClanManager;
|
|
|
-import me.lethunderhawk.clans.settings.ClanSetting;
|
|
|
|
|
|
|
+import me.lethunderhawk.clans.settings.ClaimSetting;
|
|
|
|
|
+import me.lethunderhawk.fluxapi.FluxService;
|
|
|
import net.kyori.adventure.text.Component;
|
|
import net.kyori.adventure.text.Component;
|
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Location;
|
|
@@ -17,23 +17,20 @@ import org.bukkit.entity.LivingEntity;
|
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.entity.Player;
|
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.EventHandler;
|
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.Listener;
|
|
|
-import org.bukkit.event.block.Action;
|
|
|
|
|
-import org.bukkit.event.block.BlockBreakEvent;
|
|
|
|
|
-import org.bukkit.event.block.BlockIgniteEvent;
|
|
|
|
|
-import org.bukkit.event.block.BlockPlaceEvent;
|
|
|
|
|
|
|
+import org.bukkit.event.block.*;
|
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
|
|
|
+import org.bukkit.event.entity.EntityExplodeEvent;
|
|
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
public class ClaimListener implements Listener {
|
|
public class ClaimListener implements Listener {
|
|
|
private final ClaimManager claimManager;
|
|
private final ClaimManager claimManager;
|
|
|
- private final ClanManager clanManager;
|
|
|
|
|
|
|
|
|
|
- public ClaimListener(ClaimManager claimManager, ClanManager clanManager) {
|
|
|
|
|
|
|
+ public ClaimListener(ClaimManager claimManager) {
|
|
|
this.claimManager = claimManager;
|
|
this.claimManager = claimManager;
|
|
|
- this.clanManager = clanManager;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(ignoreCancelled = true)
|
|
@EventHandler(ignoreCancelled = true)
|
|
@@ -48,14 +45,14 @@ public class ClaimListener implements Listener {
|
|
|
|
|
|
|
|
// Containers
|
|
// Containers
|
|
|
if (block.getState() instanceof Container) {
|
|
if (block.getState() instanceof Container) {
|
|
|
- if (preventChange(event.getPlayer().getUniqueId(), loc, ClanSetting.OPEN_CONTAINER)) {
|
|
|
|
|
|
|
+ if (preventChange(event.getPlayer().getUniqueId(), loc, ClaimSetting.OPEN_CONTAINER)) {
|
|
|
event.setCancelled(true);
|
|
event.setCancelled(true);
|
|
|
}
|
|
}
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
Material blockType = block.getType();
|
|
Material blockType = block.getType();
|
|
|
if (blockType.equals(Material.ANVIL) || blockType.equals(Material.CHIPPED_ANVIL)|| blockType.equals(Material.DAMAGED_ANVIL)) {
|
|
if (blockType.equals(Material.ANVIL) || blockType.equals(Material.CHIPPED_ANVIL)|| blockType.equals(Material.DAMAGED_ANVIL)) {
|
|
|
- if (preventChange(event.getPlayer().getUniqueId(), loc, ClanSetting.USE_ANVIL)) {
|
|
|
|
|
|
|
+ if (preventChange(event.getPlayer().getUniqueId(), loc, ClaimSetting.USE_ANVIL)) {
|
|
|
event.setCancelled(true);
|
|
event.setCancelled(true);
|
|
|
}
|
|
}
|
|
|
return;
|
|
return;
|
|
@@ -63,7 +60,7 @@ public class ClaimListener implements Listener {
|
|
|
|
|
|
|
|
// Doors, fence gates, trapdoors, etc.
|
|
// Doors, fence gates, trapdoors, etc.
|
|
|
if (data instanceof Openable || data instanceof Powerable) {
|
|
if (data instanceof Openable || data instanceof Powerable) {
|
|
|
- if (preventChange(event.getPlayer().getUniqueId(), loc, ClanSetting.INTERACT_BLOCK)) {
|
|
|
|
|
|
|
+ if (preventChange(event.getPlayer().getUniqueId(), loc, ClaimSetting.INTERACT_BLOCK)) {
|
|
|
event.setCancelled(true);
|
|
event.setCancelled(true);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -73,7 +70,7 @@ public class ClaimListener implements Listener {
|
|
|
|
|
|
|
|
@EventHandler
|
|
@EventHandler
|
|
|
public void onBreak(BlockBreakEvent e) {
|
|
public void onBreak(BlockBreakEvent e) {
|
|
|
- if(preventChange(e.getPlayer().getUniqueId(), e.getBlock().getLocation(), ClanSetting.BLOCK_BREAK)){
|
|
|
|
|
|
|
+ if(preventChange(e.getPlayer().getUniqueId(), e.getBlock().getLocation(), ClaimSetting.BLOCK_BREAK)){
|
|
|
e.setCancelled(true);
|
|
e.setCancelled(true);
|
|
|
e.getPlayer().sendMessage("§cThis land belongs to another clan!");
|
|
e.getPlayer().sendMessage("§cThis land belongs to another clan!");
|
|
|
}
|
|
}
|
|
@@ -81,7 +78,7 @@ public class ClaimListener implements Listener {
|
|
|
@EventHandler
|
|
@EventHandler
|
|
|
public void onIgnition(BlockIgniteEvent e){
|
|
public void onIgnition(BlockIgniteEvent e){
|
|
|
if(e.getPlayer() == null) return;
|
|
if(e.getPlayer() == null) return;
|
|
|
- if(preventChange(e.getPlayer().getUniqueId(), e.getBlock().getLocation(), ClanSetting.INTERACT_IGNITION)){
|
|
|
|
|
|
|
+ if(preventChange(e.getPlayer().getUniqueId(), e.getBlock().getLocation(), ClaimSetting.INTERACT_IGNITION)){
|
|
|
e.setCancelled(true);
|
|
e.setCancelled(true);
|
|
|
e.getPlayer().sendMessage("§cThis land belongs to another clan!");
|
|
e.getPlayer().sendMessage("§cThis land belongs to another clan!");
|
|
|
}
|
|
}
|
|
@@ -89,17 +86,17 @@ public class ClaimListener implements Listener {
|
|
|
@EventHandler
|
|
@EventHandler
|
|
|
public void onPlayerHittingEvent(EntityDamageByEntityEvent e) {
|
|
public void onPlayerHittingEvent(EntityDamageByEntityEvent e) {
|
|
|
if(!(e.getDamager() instanceof Player p)) return;
|
|
if(!(e.getDamager() instanceof Player p)) return;
|
|
|
- if(e.getEntity() instanceof Player && preventForAll(e.getEntity().getLocation(), ClanSetting.ALLOW_HITTING_PLAYERS)){
|
|
|
|
|
|
|
+ if(e.getEntity() instanceof Player && preventForAll(e.getEntity().getLocation(), ClaimSetting.ALLOW_HITTING_PLAYERS)){
|
|
|
e.setCancelled(true);
|
|
e.setCancelled(true);
|
|
|
e.getDamager().sendMessage(Component.text("You cant damage other Players in this region!", NamedTextColor.RED));
|
|
e.getDamager().sendMessage(Component.text("You cant damage other Players in this region!", NamedTextColor.RED));
|
|
|
- }else if(e.getEntity() instanceof LivingEntity && preventForAll(e.getEntity().getLocation(), ClanSetting.ALLOW_HITTING_MOBS)){
|
|
|
|
|
|
|
+ }else if(e.getEntity() instanceof LivingEntity && preventForAll(e.getEntity().getLocation(), ClaimSetting.ALLOW_HITTING_MOBS)){
|
|
|
e.setCancelled(true);
|
|
e.setCancelled(true);
|
|
|
e.getDamager().sendMessage(Component.text("You cant damage Mobs in this region!", NamedTextColor.RED));
|
|
e.getDamager().sendMessage(Component.text("You cant damage Mobs in this region!", NamedTextColor.RED));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
@EventHandler
|
|
@EventHandler
|
|
|
public void onEntityInteract(PlayerInteractEntityEvent e){
|
|
public void onEntityInteract(PlayerInteractEntityEvent e){
|
|
|
- if(preventChange(e.getPlayer().getUniqueId(), e.getRightClicked().getLocation(), ClanSetting.INTERACT_ENTITY)){
|
|
|
|
|
|
|
+ if(preventChange(e.getPlayer().getUniqueId(), e.getRightClicked().getLocation(), ClaimSetting.INTERACT_ENTITY)){
|
|
|
e.setCancelled(true);
|
|
e.setCancelled(true);
|
|
|
e.getPlayer().sendMessage("§cThis land belongs to another clan!");
|
|
e.getPlayer().sendMessage("§cThis land belongs to another clan!");
|
|
|
}
|
|
}
|
|
@@ -107,27 +104,45 @@ public class ClaimListener implements Listener {
|
|
|
|
|
|
|
|
@EventHandler
|
|
@EventHandler
|
|
|
public void onBlockPlace(BlockPlaceEvent e){
|
|
public void onBlockPlace(BlockPlaceEvent e){
|
|
|
- if(preventChange(e.getPlayer().getUniqueId(), e.getBlock().getLocation(), ClanSetting.BLOCK_PLACE)){
|
|
|
|
|
|
|
+ if(preventChange(e.getPlayer().getUniqueId(), e.getBlock().getLocation(), ClaimSetting.BLOCK_PLACE)){
|
|
|
e.setCancelled(true);
|
|
e.setCancelled(true);
|
|
|
e.getPlayer().sendMessage("§cThis land belongs to another clan!");
|
|
e.getPlayer().sendMessage("§cThis land belongs to another clan!");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- private boolean preventForAll(Location location, ClanSetting setting){
|
|
|
|
|
|
|
+ @EventHandler
|
|
|
|
|
+ public void onEntityExplode(EntityExplodeEvent e){
|
|
|
|
|
+ if(preventGeneral(e.getLocation(), ClaimSetting.EXPLOSIONS)){
|
|
|
|
|
+ e.setCancelled(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ @EventHandler
|
|
|
|
|
+ public void onExplosion(BlockExplodeEvent e){
|
|
|
|
|
+ if(preventGeneral(e.getBlock().getLocation(), ClaimSetting.EXPLOSIONS)){
|
|
|
|
|
+ e.setCancelled(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean preventGeneral(@NotNull Location location, ClaimSetting claimSetting) {
|
|
|
Claim claim = claimManager.getClaimAt(location);
|
|
Claim claim = claimManager.getClaimAt(location);
|
|
|
if(claim != null){
|
|
if(claim != null){
|
|
|
- Clan clan = FluxService.get(ClanManager.class).getClanById(claim.getClanId());
|
|
|
|
|
- if (clan != null) {
|
|
|
|
|
- return !clan.allows(setting);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return !claim.allows(claimSetting);
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean preventForAll(Location location, ClaimSetting setting){
|
|
|
|
|
+ Claim claim = claimManager.getClaimAt(location);
|
|
|
|
|
+ if(claim != null){
|
|
|
|
|
+ return !claim.allows(setting);
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- private boolean preventChange(UUID playerUUID, Location location, ClanSetting setting){
|
|
|
|
|
|
|
+ private boolean preventChange(UUID playerUUID, Location location, ClaimSetting setting){
|
|
|
Claim claim = claimManager.getClaimAt(location);
|
|
Claim claim = claimManager.getClaimAt(location);
|
|
|
if(claim != null){
|
|
if(claim != null){
|
|
|
Clan clan = FluxService.get(ClanManager.class).getClanById(claim.getClanId());
|
|
Clan clan = FluxService.get(ClanManager.class).getClanById(claim.getClanId());
|
|
|
if (clan != null && !clan.isInClan(playerUUID)) {
|
|
if (clan != null && !clan.isInClan(playerUUID)) {
|
|
|
- return !clan.allows(setting);
|
|
|
|
|
|
|
+ return !claim.allows(setting);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|