Reworked integration loading

This commit is contained in:
Auxilor
2020-11-19 14:35:33 +00:00
parent 78f38efd46
commit 094eb7d5f5
4 changed files with 79 additions and 120 deletions

View File

@@ -5,6 +5,7 @@ import com.willfp.ecoenchants.command.AbstractCommand;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.integrations.placeholder.PlaceholderManager;
import com.willfp.ecoenchants.util.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@@ -23,22 +24,24 @@ import java.util.stream.Collectors;
@SuppressWarnings("unchecked")
public final class CommandEcodebug extends AbstractCommand {
public CommandEcodebug() {
super("ecodebug", "ecoenchants.ecodebug", true);
super("ecodebug", "ecoenchants.ecodebug", false);
}
@Override
public void onExecute(CommandSender sender, List<String> args) {
Logger.info("--------------- BEGIN DEBUG ----------------");
Player player = (Player) sender;
player.sendMessage("Held Item: " + player.getInventory().getItemInMainHand().toString());
Logger.info("");
if(sender instanceof Player) {
Player player = (Player) sender;
player.sendMessage("Held Item: " + player.getInventory().getItemInMainHand().toString());
Logger.info("");
Logger.info("Held Item: " + player.getInventory().getItemInMainHand().toString());
Logger.info("");
}
Logger.info("Running Version: " + EcoEnchantsPlugin.getInstance().getDescription().getVersion());
Logger.info("");
Logger.info("Held Item: " + player.getInventory().getItemInMainHand().toString());
Logger.info("");
Logger.info("EcoEnchants.getAll(): " + EcoEnchants.getAll().toString());
Logger.info("");
@@ -70,11 +73,10 @@ public final class CommandEcodebug extends AbstractCommand {
Logger.info("");
List<Enchantment> brokenCache = Arrays.stream(Enchantment.values()).collect(Collectors.toList());
brokenCache.removeAll(EnchantmentCache.getCache().stream()
.filter(cacheEntry -> cacheEntry.getRawName().equalsIgnoreCase("null")
|| cacheEntry.getName().equalsIgnoreCase("null")
|| cacheEntry.getStringDescription().equalsIgnoreCase("null "))
.map(EnchantmentCache.CacheEntry::getEnchantment).collect(Collectors.toList()));
brokenCache.removeIf(enchantment -> !(
EnchantmentCache.getEntry(enchantment).getName().equalsIgnoreCase("null") ||
EnchantmentCache.getEntry(enchantment).getRawName().equalsIgnoreCase("null") ||
EnchantmentCache.getEntry(enchantment).getStringDescription().equalsIgnoreCase("null")));
Logger.info("Enchantments with broken cache: " + brokenCache.toString());
Logger.info("");

View File

@@ -68,9 +68,6 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
ConfigManager.addEnchantmentConfig(new EnchantmentConfig(this.permissionName, plugin, this.type));
this.config = ConfigManager.getEnchantmentConfig(this.permissionName);
if(!Prerequisite.areMet(prerequisites))
return;
if(Bukkit.getPluginManager().getPermission("ecoenchants.fromtable." + permissionName) == null) {
Permission permission = new Permission(
"ecoenchants.fromtable." + permissionName,
@@ -81,6 +78,9 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
Bukkit.getPluginManager().addPermission(permission);
}
if(!Prerequisite.areMet(prerequisites))
return;
this.update();
this.add();
}

View File

@@ -55,6 +55,7 @@ import com.willfp.ecoenchants.util.ClassUtils;
import com.willfp.ecoenchants.util.Logger;
import com.willfp.ecoenchants.util.StringUtils;
import com.willfp.ecoenchants.util.UpdateChecker;
import com.willfp.ecoenchants.util.interfaces.Callable;
import com.willfp.ecoenchants.util.interfaces.EcoRunnable;
import com.willfp.ecoenchants.util.optional.Prerequisite;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
@@ -62,9 +63,11 @@ import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.plugin.Plugin;
import org.checkerframework.checker.units.qual.A;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
* Class containing methods for the loading and unloading of EcoEnchants
@@ -171,6 +174,58 @@ public class Loader {
Bukkit.getPluginManager().registerEvents(new WatcherTriggers(), EcoEnchantsPlugin.getInstance());
Logger.info("");
/*
Load integrations
*/
Logger.info("Loading Integrations...");
final HashMap<String, Callable> integrations = new HashMap<String, Callable>() {{
// AntiGrief
put("WorldGuard", () -> AntigriefManager.register(new AntigriefWorldGuard()));
put("GriefPrevention", () -> AntigriefManager.register(new AntigriefGriefPrevention()));
put("FactionsUUID", () -> AntigriefManager.register(new AntigriefFactionsUUID()));
put("Towny", () -> AntigriefManager.register(new AntigriefTowny()));
put("Lands", () -> AntigriefManager.register(new AntigriefLands()));
put("Kingdoms", () -> AntigriefManager.register(new AntigriefKingdoms()));
// AntiCheat
put("AAC", () -> AnticheatManager.register(new AnticheatAAC()));
put("Matrix", () -> AnticheatManager.register(new AnticheatMatrix()));
put("NoCheatPlus", () -> AnticheatManager.register(new AnticheatNCP()));
put("Spartan", () -> AnticheatManager.register(new AnticheatSpartan()));
// MISC
put("Essentials", () -> EssentialsManager.register(new IntegrationEssentials()));
put("PlaceholderAPI", () -> PlaceholderManager.addIntegration(new PlaceholderIntegrationPAPI()));
put("mcMMO", () -> McmmoManager.registerIntegration(new McmmoIntegrationImpl()));
}};
Set<String> enabledPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toSet());
integrations.forEach(((s, callable) -> {
StringBuilder log = new StringBuilder();
log.append(s).append(": ");
if(enabledPlugins.contains(s)) {
callable.call();
log.append("&aENABLED");
} else {
log.append("&9DISABLED");
}
Logger.info(log.toString());
}));
Prerequisite.update();
if(ClassUtils.exists("net.wesjd.anvilgui.AnvilGUI")) {
AnvilGUIManager.registerIntegration(new AnvilGUIImpl());
Logger.info("AnvilGUI: &aENABLED");
} else {
Logger.info("AnvilGUI: &9DISABLED");
}
Logger.info("");
/*
Create enchantment config files (for first time use)
*/
@@ -349,109 +404,7 @@ public class Loader {
Logger.info("");
Logger.info("Updating cache...");
EnchantmentCache.update();
Logger.info("");
Logger.info("Loading Integrations...");
if(Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
AntigriefManager.register(new AntigriefWorldGuard());
Logger.info("WorldGuard: &aENABLED");
} else {
Logger.info("WorldGuard: &9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("GriefPrevention")) {
AntigriefManager.register(new AntigriefGriefPrevention());
Logger.info("GriefPrevention: &aENABLED");
} else {
Logger.info("GriefPrevention: &9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("FactionsUUID")) {
AntigriefManager.register(new AntigriefFactionsUUID());
Logger.info("FactionsUUID: &aENABLED");
} else {
Logger.info("FactionsUUID: &9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Towny")) {
AntigriefManager.register(new AntigriefTowny());
Logger.info("Towny: &aENABLED");
} else {
Logger.info("Towny: &9DISABLED");
}
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(Bukkit.getPluginManager().isPluginEnabled("AAC")) {
AnticheatManager.register(new AnticheatAAC());
Logger.info("AAC: &aENABLED");
} else {
Logger.info("AAC: &9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Matrix")) {
AnticheatManager.register(new AnticheatMatrix());
Logger.info("Matrix: &aENABLED");
} else {
Logger.info("Matrix: &9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("NoCheatPlus")) {
AnticheatManager.register(new AnticheatNCP());
Logger.info("NCP: &aENABLED");
} else {
Logger.info("NCP: &9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Spartan")) {
AnticheatManager.register(new AnticheatSpartan());
Logger.info("Spartan: &aENABLED");
} else {
Logger.info("Spartan: &9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
PlaceholderManager.addIntegration(new PlaceholderIntegrationPAPI());
Logger.info("PlaceholderAPI: &aENABLED");
} else {
Logger.info("PlaceholderAPI: &9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("mcMMO")) {
McmmoManager.registerIntegration(new McmmoIntegrationImpl());
Logger.info("mcMMO: &aENABLED");
} else {
Logger.info("mcMMO: &9DISABLED");
}
if(ClassUtils.exists("net.wesjd.anvilgui.AnvilGUI")) {
AnvilGUIManager.registerIntegration(new AnvilGUIImpl());
Logger.info("AnvilGUI: &aENABLED");
} else {
Logger.info("AnvilGUI: &9DISABLED");
}
EssentialsManager.registerEnchantments();
/*
Check for paper

View File

@@ -36,6 +36,10 @@ public enum Prerequisite {
}
static {
update();
}
public static void update() {
MinVer1_16.setMet(!Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3].contains("15"));
HasPaper.setMet(ClassUtils.exists("com.destroystokyo.paper.event.player.PlayerElytraBoostEvent"));
}