Cleaned up integration loading

This commit is contained in:
Auxilor 2020-10-29 20:26:57 +00:00
parent 2de2a5f96c
commit a0bcbeeab4
5 changed files with 46 additions and 49 deletions

View File

@ -11,16 +11,11 @@ import java.util.Set;
public class AnticheatManager {
private static final Set<AnticheatWrapper> anticheats = new HashSet<>();
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);
return true;
public static void register(AnticheatWrapper anticheat) {
if(anticheat instanceof Listener) {
Bukkit.getPluginManager().registerEvents((Listener) anticheat, EcoEnchantsPlugin.getInstance());
}
return false;
anticheats.add(anticheat);
}
public static void exemptPlayer(Player player) {

View File

@ -1,6 +1,5 @@
package com.willfp.ecoenchants.integrations.antigrief;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
@ -12,12 +11,8 @@ import java.util.Set;
public class AntigriefManager {
private static final Set<AntigriefWrapper> antigriefs = new HashSet<>();
public static boolean registerIfPresent(AntigriefWrapper antigrief) {
if(Bukkit.getPluginManager().isPluginEnabled(antigrief.getPluginName())) {
antigriefs.add(antigrief);
return true;
}
return false;
public static void register(AntigriefWrapper antigrief) {
antigriefs.add(antigrief);
}
/**

View File

@ -14,10 +14,11 @@ import org.kingdoms.managers.PvPManager;
import org.kingdoms.managers.land.LandManager;
public final class AntigriefKingdoms implements AntigriefWrapper {
private final LandManager landManager = new LandManager();
@Override
public boolean canBreakBlock(Player player, Block block) {
BlockBreakEvent event = new BlockBreakEvent(block, player);
LandManager landManager = new LandManager();
landManager.onBreak(event);
return !event.isCancelled();
}
@ -36,7 +37,6 @@ public final class AntigriefKingdoms implements AntigriefWrapper {
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 landManager = new LandManager();
landManager.onPlace(event);
return !event.isCancelled();
}

View File

@ -1,19 +1,13 @@
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<EssentialsWrapper> registered = new HashSet<>();
public static boolean registerIfPresent(EssentialsWrapper essentials) {
if(Bukkit.getPluginManager().isPluginEnabled(essentials.getPluginName())) {
registered.add(essentials);
return true;
}
return false;
public static void register(EssentialsWrapper essentials) {
registered.add(essentials);
}
public static void registerEnchantments() {

View File

@ -320,72 +320,85 @@ public class Loader {
Logger.info("");
Logger.info("Loading Integrations...");
if(AntigriefManager.registerIfPresent(new AntigriefWorldGuard())) {
if(Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
AntigriefManager.register(new AntigriefWorldGuard());
Logger.info("WorldGuard: §aENABLED");
} else {
Logger.info("WorldGuard: §9DISABLED");
}
if(AntigriefManager.registerIfPresent(new AntigriefFactionsUUID())) {
Logger.info("FactionsUUID: §aENABLED");
} else {
Logger.info("FactionsUUID: §9DISABLED");
}
if(AntigriefManager.registerIfPresent(new AntigriefGriefPrevention())) {
if(Bukkit.getPluginManager().isPluginEnabled("GriefPrevention")) {
AntigriefManager.register(new AntigriefGriefPrevention());
Logger.info("GriefPrevention: §aENABLED");
} else {
Logger.info("GriefPrevention: §9DISABLED");
}
if(AntigriefManager.registerIfPresent(new AntigriefKingdoms())) {
Logger.info("Kingdoms: §aENABLED");
if(Bukkit.getPluginManager().isPluginEnabled("FactionsUUID")) {
AntigriefManager.register(new AntigriefFactionsUUID());
Logger.info("FactionsUUID: §aENABLED");
} else {
Logger.info("Kingdoms: §9DISABLED");
Logger.info("FactionsUUID: §9DISABLED");
}
if(AntigriefManager.registerIfPresent(new AntigriefLands())) {
Logger.info("Lands: §aENABLED");
} else {
Logger.info("Lands: §9DISABLED");
}
if(AntigriefManager.registerIfPresent(new AntigriefTowny())) {
if(Bukkit.getPluginManager().isPluginEnabled("Towny")) {
AntigriefManager.register(new AntigriefTowny());
Logger.info("Towny: §aENABLED");
} else {
Logger.info("Towny: §9DISABLED");
}
if(EssentialsManager.registerIfPresent(new IntegrationEssentials())) {
if(Bukkit.getPluginManager().isPluginEnabled("Lands")) {
AntigriefManager.register(new AntigriefLands());
Logger.info("Lands: §aENABLED");
} else {
Logger.info("Lands: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Kingdoms")) {
AntigriefManager.register(new AntigriefKingdoms());
Logger.info("Kingdoms: §aENABLED");
} else {
Logger.info("Kingdoms: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
EssentialsManager.register(new IntegrationEssentials());
Logger.info("Essentials: §aENABLED");
EssentialsManager.registerEnchantments();
} else {
Logger.info("Essentials: §9DISABLED");
}
if(AnticheatManager.registerIfPresent(new AnticheatAAC())) {
if(Bukkit.getPluginManager().isPluginEnabled("AAC")) {
AnticheatManager.register(new AnticheatAAC());
Logger.info("AAC: §aENABLED");
} else {
Logger.info("AAC: §9DISABLED");
}
if(AnticheatManager.registerIfPresent(new AnticheatMatrix())) {
if(Bukkit.getPluginManager().isPluginEnabled("Matrix")) {
AnticheatManager.register(new AnticheatMatrix());
Logger.info("Matrix: §aENABLED");
} else {
Logger.info("Matrix: §9DISABLED");
}
if(AnticheatManager.registerIfPresent(new AnticheatNCP())) {
if(Bukkit.getPluginManager().isPluginEnabled("NoCheatPlus")) {
AnticheatManager.register(new AnticheatNCP());
Logger.info("NCP: §aENABLED");
} else {
Logger.info("NCP: §9DISABLED");
}
if(AnticheatManager.registerIfPresent(new AnticheatSpartan())) {
if(Bukkit.getPluginManager().isPluginEnabled("Spartan")) {
AnticheatManager.register(new AnticheatSpartan());
Logger.info("Spartan: §aENABLED");
} else {
Logger.info("Spartan: §9DISABLED");
}
/*
Check for paper
*/