From 58e43b41cc1d9b6996536e56c8b556a6eb4008a4 Mon Sep 17 00:00:00 2001 From: DroppingAnvil Date: Mon, 16 Dec 2019 13:32:12 -0600 Subject: [PATCH] CmdReload made more useful by changing how commands that can be disabled are added to the root. You can now get the instance of FCmdRoot, Recheck variable added commands, rebuild brigadierManager, and get the status of each command that can be disabled. CmdDebug now gets the status of variable added commands. Signed-off-by: DroppingAnvil --- .../massivecraft/factions/FactionsPlugin.java | 1 - .../massivecraft/factions/cmd/CmdDebug.java | 19 ++- .../massivecraft/factions/cmd/CmdReload.java | 6 +- .../massivecraft/factions/cmd/FCmdRoot.java | 130 +++++++++++------- .../listeners/FactionsPlayerListener.java | 1 - 5 files changed, 100 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/FactionsPlugin.java b/src/main/java/com/massivecraft/factions/FactionsPlugin.java index a56bca3d..5017ec47 100755 --- a/src/main/java/com/massivecraft/factions/FactionsPlugin.java +++ b/src/main/java/com/massivecraft/factions/FactionsPlugin.java @@ -13,7 +13,6 @@ import com.massivecraft.factions.cmd.check.WeeWooTask; import com.massivecraft.factions.cmd.chest.AntiChestListener; import com.massivecraft.factions.discord.Discord; import com.massivecraft.factions.discord.DiscordListener; -import com.massivecraft.factions.discord.FactionChatHandler; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.dynmap.EngineDynmap; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdDebug.java b/src/main/java/com/massivecraft/factions/cmd/CmdDebug.java index 20a72e29..269f6d7b 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdDebug.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdDebug.java @@ -17,13 +17,28 @@ public class CmdDebug extends FCommand { public void perform(CommandContext context) { FactionsPlugin.getInstance().divider(); System.out.print("----------Debug Info----------"); - System.out.print("--------Main-------"); + System.out.print("-------Main-------"); System.out.print("Server Version: " + FactionsPlugin.getInstance().getServer().getVersion()); System.out.print("Server Bukkit Version: " + FactionsPlugin.getInstance().getServer().getBukkitVersion()); System.out.print("SaberFactions Version: " + FactionsPlugin.getInstance().getDescription().getVersion()); System.out.print("Is Beta Version: " + (FactionsPlugin.getInstance().getDescription().getFullName().contains("BETA") ? "True" : "False")); System.out.print("Players Online: " + Bukkit.getOnlinePlayers().size()); - System.out.print("------End Main-----"); + System.out.print("------Command------"); + System.out.print("Discord Commands: " + FCmdRoot.instance.discordEnabled); + System.out.print("Check/WeeWoo Commands: " + FCmdRoot.instance.checkEnabled); + System.out.print("Mission Command: " + FCmdRoot.instance.missionsEnabled); + System.out.print("Shop Command: " + FCmdRoot.instance.fShopEnabled); + System.out.print("Inventory See Command: " + FCmdRoot.instance.invSeeEnabled); + System.out.print("Points Command: " + FCmdRoot.instance.fPointsEnabled); + System.out.print("Alts Command: " + FCmdRoot.instance.fAltsEnabled); + System.out.print("Grace Command: " + FCmdRoot.instance.fGraceEnabled); + System.out.print("Focus Command: " + FCmdRoot.instance.fFocusEnabled); + System.out.print("Fly Command: " + FCmdRoot.instance.fFlyEnabled); + System.out.print("PayPal Commands: " + FCmdRoot.instance.fPayPalEnabled); + System.out.print("Inspect Command: " + FCmdRoot.instance.coreProtectEnabled); + System.out.print("Internal FTOP Command: " + FCmdRoot.instance.internalFTOPEnabled); + System.out.print("----End Command----"); + System.out.print("-----End Main-----"); System.out.print("------Discord------"); System.out.print("Discord Integration enabled in config: " + Discord.confUseDiscord); System.out.print("Discord Integration enabled: " + Discord.useDiscord); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdReload.java b/src/main/java/com/massivecraft/factions/cmd/CmdReload.java index 9f8f89a8..7c9d4b40 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdReload.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdReload.java @@ -31,7 +31,7 @@ public class CmdReload extends FCommand { FactionsPlugin.getInstance().loadLang(); - if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) { + if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false)) { FactionsPlugin.getInstance().factionsFlight = true; } @@ -40,7 +40,9 @@ public class CmdReload extends FCommand { } Discord.setupDiscord(); - + //Recheck if commands should truly be disabled and rebuild. + FCmdRoot.instance.addVariableCommands(); + FCmdRoot.instance.rebuild(); long timeReload = (System.currentTimeMillis() - timeInitStart); context.msg(TL.COMMAND_RELOAD_TIME, timeReload); diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index 65e5a81c..a483b68d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -42,8 +42,8 @@ public class FCmdRoot extends FCommand implements CommandExecutor { * @author FactionsUUID Team */ + public static FCmdRoot instance; public BrigadierManager brigadierManager; - public CmdAdmin cmdAdmin = new CmdAdmin(); public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim(); public CmdBoom cmdBoom = new CmdBoom(); @@ -160,9 +160,24 @@ public class FCmdRoot extends FCommand implements CommandExecutor { public CmdSetGuild cmdSetGuild = new CmdSetGuild(); public CmdDiscord cmdDiscord = new CmdDiscord(); public CmdDebug cmdDebug = new CmdDebug(); + //Variables to know if we already setup certain sub commands + public Boolean discordEnabled = false; + public Boolean checkEnabled = false; + public Boolean missionsEnabled = false; + public Boolean fShopEnabled = false; + public Boolean invSeeEnabled = false; + public Boolean fPointsEnabled = false; + public Boolean fAltsEnabled = false; + public Boolean fGraceEnabled = false; + public Boolean fFocusEnabled = false; + public Boolean fFlyEnabled = false; + public Boolean fPayPalEnabled = false; + public Boolean coreProtectEnabled = false; + public Boolean internalFTOPEnabled = false; public FCmdRoot() { super(); + instance = this; if (CommodoreProvider.isSupported()) brigadierManager = new BrigadierManager(); @@ -273,75 +288,88 @@ public class FCmdRoot extends FCommand implements CommandExecutor { this.addSubCommand(this.cmdViewChest); this.addSubCommand(this.cmdConvertConfig); this.addSubCommand(this.cmdSpawnerLock); + addVariableCommands(); + if (CommodoreProvider.isSupported()) brigadierManager.build(); + } - if(Conf.useDiscordSystem){ - this.addSubCommand(this.cmdInviteBot); - this.addSubCommand(this.cmdSetGuild); + /** + * Add sub commands to the root if they are enabled + */ + public void addVariableCommands() { + //Discord + if (Conf.useDiscordSystem && !discordEnabled) { + this.addSubCommand(this.cmdInviteBot); + this.addSubCommand(this.cmdSetGuild); + this.addSubCommand(this.cmdSetDiscord); + this.addSubCommand(this.cmdSeeDiscord); + this.addSubCommand(this.cmdDiscord); + discordEnabled = true; + } + //PayPal + if (FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled", false) && !fPayPalEnabled) { + this.addSubCommand(this.cmdPaypalSet); + this.addSubCommand(this.cmdPaypalSee); + fPayPalEnabled = true; } - - if (Conf.useCheckSystem) { + //Check + if (Conf.useCheckSystem && !checkEnabled) { this.addSubCommand(this.cmdCheck); this.addSubCommand(this.cmdWeeWoo); + checkEnabled = true; } - - if (FactionsPlugin.getInstance().getConfig().getBoolean("Missions-Enabled")) { - this.addSubCommand(this.cmdMissions); - } - - if (FactionsPlugin.getInstance().getConfig().getBoolean("F-Shop.Enabled")) { - this.addSubCommand(this.cmdShop); - } - - if (FactionsPlugin.getInstance().getConfig().getBoolean("f-inventory-see.Enabled")) { - this.addSubCommand(this.cmdInventorySee); - } - - if (FactionsPlugin.getInstance().getConfig().getBoolean("f-points.Enabled")) { - this.addSubCommand(this.cmdPoints); - } - - if (FactionsPlugin.getInstance().getConfig().getBoolean("f-alts.Enabled")) { - this.addSubCommand(this.cmdAlts); - } - - if (FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) { - this.addSubCommand(this.cmdGrace); - } - - - if (Bukkit.getServer().getPluginManager().getPlugin("CoreProtect") != null) { + //CoreProtect + if (Bukkit.getServer().getPluginManager().getPlugin("CoreProtect") != null && !coreProtectEnabled) { FactionsPlugin.getInstance().log("Found CoreProtect, enabling Inspect"); this.addSubCommand(this.cmdInspect); + coreProtectEnabled = true; } else { FactionsPlugin.getInstance().log("CoreProtect not found, disabling Inspect"); } - if (FactionsPlugin.getInstance().getConfig().getBoolean("ffocus.Enabled")) { - addSubCommand(this.cmdFocus); - } - - if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false)) { - this.addSubCommand(this.cmdFly); - } - if (Bukkit.getServer().getPluginManager().getPlugin("FactionsTop") != null || Bukkit.getServer().getPluginManager().getPlugin("SavageFTOP") != null || Bukkit.getServer().getPluginManager().getPlugin("SaberFTOP") != null) { + //FTOP + if ((Bukkit.getServer().getPluginManager().getPlugin("FactionsTop") != null || Bukkit.getServer().getPluginManager().getPlugin("SavageFTOP") != null || Bukkit.getServer().getPluginManager().getPlugin("SaberFTOP") != null) && !internalFTOPEnabled) { FactionsPlugin.getInstance().log(Level.INFO, "Found FactionsTop plugin. Disabling our own /f top command."); } else { FactionsPlugin.getInstance().log(Level.INFO, "Enabling FactionsTop command, this is a very basic /f top please get a dedicated /f top resource if you want land calculation etc."); this.addSubCommand(this.cmdTop); + internalFTOPEnabled = true; } - - if (FactionsPlugin.getInstance().getConfig().getBoolean("fdiscord.Enabled")) { - this.addSubCommand(this.cmdSetDiscord); - this.addSubCommand(this.cmdSeeDiscord); + //Other + if (FactionsPlugin.getInstance().getConfig().getBoolean("Missions-Enabled", false) && !missionsEnabled) { + this.addSubCommand(this.cmdMissions); + missionsEnabled = true; } - - if (FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled")) { - this.addSubCommand(this.cmdPaypalSet); - this.addSubCommand(this.cmdPaypalSee); + if (FactionsPlugin.getInstance().getConfig().getBoolean("F-Shop.Enabled", false) && !fShopEnabled) { + this.addSubCommand(this.cmdShop); + fShopEnabled = true; + } + if (FactionsPlugin.getInstance().getConfig().getBoolean("f-inventory-see.Enabled", false) && !invSeeEnabled) { + this.addSubCommand(this.cmdInventorySee); + invSeeEnabled = true; + } + if (FactionsPlugin.getInstance().getConfig().getBoolean("f-points.Enabled", false) && !fPointsEnabled) { + this.addSubCommand(this.cmdPoints); + fPointsEnabled = true; + } + if (FactionsPlugin.getInstance().getConfig().getBoolean("f-alts.Enabled", false) && !fAltsEnabled) { + this.addSubCommand(this.cmdAlts); + fAltsEnabled = true; + } + if (FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled", false) && !fGraceEnabled) { + this.addSubCommand(this.cmdGrace); + fGraceEnabled = true; + } + if (FactionsPlugin.getInstance().getConfig().getBoolean("ffocus.Enabled") && !fFocusEnabled) { + addSubCommand(this.cmdFocus); + fFocusEnabled = true; + } + if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false) && !fFlyEnabled) { + this.addSubCommand(this.cmdFly); + fFlyEnabled = true; } - - if (CommodoreProvider.isSupported()) brigadierManager.build(); } + public void rebuild() {if (CommodoreProvider.isSupported()) brigadierManager.build();} + @Override public void perform(CommandContext context) { context.commandChain.add(this); diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 8fec0d29..bc62897e 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -29,7 +29,6 @@ import net.coreprotect.CoreProtect; import net.coreprotect.CoreProtectAPI; import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.entities.TextChannel; -import net.dv8tion.jda.core.entities.User; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Player;