diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 1a316e96..3cc629d4 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -189,6 +189,12 @@ 1.6.9.5-U0.5.13 provided + + org.kingdoms + kingdoms + 1.0.0 + provided + com.github.TownyAdvanced Towny diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/integrations/anticheat/AnticheatManager.java b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/anticheat/AnticheatManager.java index 28bede12..b3d9790f 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/integrations/anticheat/AnticheatManager.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/anticheat/AnticheatManager.java @@ -11,12 +11,16 @@ import java.util.Set; public class AnticheatManager { private static final Set anticheats = new HashSet<>(); - public static void registerAnticheat(AnticheatWrapper anticheat) { - if(anticheat instanceof Listener) { - Bukkit.getPluginManager().registerEvents((Listener) anticheat, EcoEnchantsPlugin.getInstance()); - } + public static boolean registerIfPresent(AnticheatWrapper anticheat) { + if(Bukkit.getPluginManager().isPluginEnabled(anticheat.getPluginName())) { + if(anticheat instanceof Listener) { + Bukkit.getPluginManager().registerEvents((Listener) anticheat, EcoEnchantsPlugin.getInstance()); + } - anticheats.add(anticheat); + anticheats.add(anticheat); + return true; + } + return false; } public static void exemptPlayer(Player player) { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/integrations/antigrief/AntigriefManager.java b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/antigrief/AntigriefManager.java index 319ce060..0d425353 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/integrations/antigrief/AntigriefManager.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/antigrief/AntigriefManager.java @@ -1,5 +1,6 @@ package com.willfp.ecoenchants.integrations.antigrief; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.LivingEntity; @@ -11,8 +12,12 @@ import java.util.Set; public class AntigriefManager { private static final Set antigriefs = new HashSet<>(); - public static void registerAntigrief(AntigriefWrapper antigrief) { - antigriefs.add(antigrief); + public static boolean registerIfPresent(AntigriefWrapper antigrief) { + if(Bukkit.getPluginManager().isPluginEnabled(antigrief.getPluginName())) { + antigriefs.add(antigrief); + return true; + } + return false; } /** diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/integrations/antigrief/plugins/AntigriefKingdomsX.java b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/antigrief/plugins/AntigriefKingdomsX.java new file mode 100644 index 00000000..7396dc97 --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/antigrief/plugins/AntigriefKingdomsX.java @@ -0,0 +1,63 @@ +package com.willfp.ecoenchants.integrations.antigrief.plugins; + +import com.willfp.ecoenchants.integrations.antigrief.AntigriefWrapper; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.inventory.EquipmentSlot; +import org.kingdoms.constants.kingdom.Kingdom; +import org.kingdoms.constants.land.Land; +import org.kingdoms.constants.player.KingdomPlayer; +import org.kingdoms.managers.PvPManager; +import org.kingdoms.managers.land.LandManager; + +public final class AntigriefKingdomsX implements AntigriefWrapper { + private final LandManager landManager = new LandManager(); + + @Override + public boolean canBreakBlock(Player player, Block block) { + BlockBreakEvent event = new BlockBreakEvent(block, player); + landManager.onBreak(event); + return !event.isCancelled(); + } + + @Override + public boolean canCreateExplosion(Player player, Location location) { + Land land = Land.getLand(location); + if (land == null) return true; + if(!land.isClaimed()) return true; + + Kingdom kingdom = land.getKingdom(); + return kingdom.getKingdomMembers().contains(KingdomPlayer.getKingdomPlayer(player)); + } + + @Override + public boolean canPlaceBlock(Player player, Block block) { + Block placedOn = block.getRelative(0, -1, 0); + BlockPlaceEvent event = new BlockPlaceEvent(block, block.getState(), placedOn, player.getInventory().getItemInMainHand(), player, true, EquipmentSlot.HAND); + landManager.onPlace(event); + return !event.isCancelled(); + } + + @Override + public boolean canInjure(Player player, LivingEntity victim) { + if(victim instanceof Player) { + return PvPManager.canFight(player, (Player) victim); + } else { + Land land = Land.getLand(victim.getLocation()); + if (land == null) return true; + if(!land.isClaimed()) return true; + + Kingdom kingdom = land.getKingdom(); + return kingdom.getKingdomMembers().contains(KingdomPlayer.getKingdomPlayer(player)); + } + } + + @Override + public String getPluginName() { + return "KingdomsX"; + } +} diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/integrations/essentials/EssentialsManager.java b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/essentials/EssentialsManager.java index 22bc40a9..0afacd69 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/integrations/essentials/EssentialsManager.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/essentials/EssentialsManager.java @@ -1,13 +1,19 @@ package com.willfp.ecoenchants.integrations.essentials; +import org.bukkit.Bukkit; + import java.util.HashSet; import java.util.Set; public class EssentialsManager { private static final Set registered = new HashSet<>(); - public static void registerEssentials(EssentialsWrapper essentials) { - registered.add(essentials); + public static boolean registerIfPresent(EssentialsWrapper essentials) { + if(Bukkit.getPluginManager().isPluginEnabled(essentials.getPluginName())) { + registered.add(essentials); + return true; + } + return false; } public static void registerEnchantments() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java b/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java index 36a3a41d..b3b99e73 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java @@ -320,72 +320,67 @@ public class Loader { Logger.info(""); Logger.info("Loading Integrations..."); - if(Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) { - AntigriefManager.registerAntigrief(new AntigriefWorldGuard()); + if(AntigriefManager.registerIfPresent(new AntigriefWorldGuard())) { Logger.info("WorldGuard: §aENABLED"); } else { Logger.info("WorldGuard: §9DISABLED"); } - if(Bukkit.getPluginManager().isPluginEnabled("GriefPrevention")) { - AntigriefManager.registerAntigrief(new AntigriefGriefPrevention()); - Logger.info("GriefPrevention: §aENABLED"); - } else { - Logger.info("GriefPrevention: §9DISABLED"); - } - - if(Bukkit.getPluginManager().isPluginEnabled("FactionsUUID")) { - AntigriefManager.registerAntigrief(new AntigriefFactionsUUID()); + if(AntigriefManager.registerIfPresent(new AntigriefFactionsUUID())) { Logger.info("FactionsUUID: §aENABLED"); } else { Logger.info("FactionsUUID: §9DISABLED"); } - if(Bukkit.getPluginManager().isPluginEnabled("Towny")) { - AntigriefManager.registerAntigrief(new AntigriefTowny()); - Logger.info("Towny: §aENABLED"); + if(AntigriefManager.registerIfPresent(new AntigriefGriefPrevention())) { + Logger.info("GriefPrevention: §aENABLED"); } else { - Logger.info("Towny: §9DISABLED"); + Logger.info("GriefPrevention: §9DISABLED"); } - if(Bukkit.getPluginManager().isPluginEnabled("Lands")) { - AntigriefManager.registerAntigrief(new AntigriefLands()); + if(AntigriefManager.registerIfPresent(new AntigriefKingdomsX())) { + Logger.info("KingdomsX: §aENABLED"); + } else { + Logger.info("KingdomsX: §9DISABLED"); + } + + if(AntigriefManager.registerIfPresent(new AntigriefLands())) { Logger.info("Lands: §aENABLED"); } else { Logger.info("Lands: §9DISABLED"); } - if(Bukkit.getPluginManager().isPluginEnabled("Essentials")) { - EssentialsManager.registerEssentials(new IntegrationEssentials()); + if(AntigriefManager.registerIfPresent(new AntigriefTowny())) { + Logger.info("Towny: §aENABLED"); + } else { + Logger.info("Towny: §9DISABLED"); + } + + if(EssentialsManager.registerIfPresent(new IntegrationEssentials())) { Logger.info("Essentials: §aENABLED"); - EssentialsManager.registerEnchantments(); } else { Logger.info("Essentials: §9DISABLED"); } - if(Bukkit.getPluginManager().isPluginEnabled("AAC")) { - AnticheatManager.registerAnticheat(new AnticheatAAC()); + if(AnticheatManager.registerIfPresent(new AnticheatAAC())) { Logger.info("AAC: §aENABLED"); } else { Logger.info("AAC: §9DISABLED"); } - if(Bukkit.getPluginManager().isPluginEnabled("Matrix")) { - AnticheatManager.registerAnticheat(new AnticheatMatrix()); + if(AnticheatManager.registerIfPresent(new AnticheatMatrix())) { Logger.info("Matrix: §aENABLED"); } else { Logger.info("Matrix: §9DISABLED"); } - if(Bukkit.getPluginManager().isPluginEnabled("NoCheatPlus")) { - AnticheatManager.registerAnticheat(new AnticheatNCP()); + if(AnticheatManager.registerIfPresent(new AnticheatNCP())) { Logger.info("NCP: §aENABLED"); } else { Logger.info("NCP: §9DISABLED"); } - if(Bukkit.getPluginManager().isPluginEnabled("Spartan")) { - AnticheatManager.registerAnticheat(new AnticheatSpartan()); + if(AnticheatManager.registerIfPresent(new AnticheatSpartan())) { Logger.info("Spartan: §aENABLED"); } else { Logger.info("Spartan: §9DISABLED"); diff --git a/Plugin/src/main/resources/plugin.yml b/Plugin/src/main/resources/plugin.yml index 742025b5..348304ac 100644 --- a/Plugin/src/main/resources/plugin.yml +++ b/Plugin/src/main/resources/plugin.yml @@ -13,6 +13,7 @@ softdepend: - Towny - FactionsUUID - Lands + - KingdomsX - NoCheatPlus - AAC - Matrix diff --git a/lib/Kingdoms-1.9.2.jar b/lib/Kingdoms-1.9.2.jar new file mode 100644 index 00000000..eafe59b0 Binary files /dev/null and b/lib/Kingdoms-1.9.2.jar differ