diff --git a/ButtonProcessor/pom.xml b/ButtonProcessor/pom.xml index e70a246..93f7024 100755 --- a/ButtonProcessor/pom.xml +++ b/ButtonProcessor/pom.xml @@ -33,14 +33,15 @@ - org.apache.maven.plugins + org.apache.maven.plugins maven-compiler-plugin + 3.8.0 -proc:none - 8 - 8 + 8 + 8 - + org.apache.maven.plugins maven-surefire-plugin diff --git a/Chroma-Core/src/main/java/buttondevteam/core/MainPlugin.java b/Chroma-Core/src/main/java/buttondevteam/core/MainPlugin.java index bde8bdf..1c008d0 100755 --- a/Chroma-Core/src/main/java/buttondevteam/core/MainPlugin.java +++ b/Chroma-Core/src/main/java/buttondevteam/core/MainPlugin.java @@ -84,14 +84,12 @@ public class MainPlugin extends ButtonPlugin { return getIConfig().getData("test", false); } - /* - * By default, the plugin uses Vault for all command permission checks, but this can have issues (with PEX for example) where default permissions aren't granted. - * When this setting is off, the plugin uses Bukkit's built-in way of handling permissions, which usually works fine for players. - * You can also grant chroma.command.* to each player (mod-only commands need another permission, chroma.mod). + /** + * If a Chroma command clashes with another plugin's command, this setting determines whether the Chroma command should be executed or the other plugin's. */ - /*public ConfigData useVaultForCommands() { - return getIConfig().getData("useVaultForCommands", true); - }*/ + public ConfigData prioritizeCustomCommands() { + return getIConfig().getData("prioritizeCustomCommands", false); + } @Override public void pluginEnable() { diff --git a/Chroma-Core/src/main/java/buttondevteam/core/component/towny/TownyComponent.java b/Chroma-Core/src/main/java/buttondevteam/core/component/towny/TownyComponent.java index 7455887..d5571d4 100644 --- a/Chroma-Core/src/main/java/buttondevteam/core/component/towny/TownyComponent.java +++ b/Chroma-Core/src/main/java/buttondevteam/core/component/towny/TownyComponent.java @@ -32,7 +32,7 @@ public class TownyComponent extends Component { public static void renameInTowny(String oldName, String newName) { if (!ComponentManager.isEnabled(TownyComponent.class)) return; - Bukkit.getLogger().info("Renaming" + oldName + " in Towny to " + newName); + Bukkit.getLogger().info("Renaming " + oldName + " in Towny to " + newName); TownyUniverse tu = TownyUniverse.getInstance(); try { Resident resident = tu.getDataSource().getResident(oldName); diff --git a/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2.java b/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2.java index 704e92b..c65d36c 100644 --- a/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2.java +++ b/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2.java @@ -165,7 +165,7 @@ public abstract class Command2, TP extends Command2Send * @param sync Whether the command was originally sync * @throws Exception If something's not right */ - public void handleCommandAsync(TP sender, String commandline, SubcommandData sd, String subcommand, boolean sync) throws Exception { + private void handleCommandAsync(TP sender, String commandline, SubcommandData sd, String subcommand, boolean sync) throws Exception { if (sd.method == null || sd.command == null) { //Main command not registered, but we have subcommands sender.sendMessage(sd.helpText); return; @@ -330,15 +330,12 @@ public abstract class Command2, TP extends Command2Send subcommands.put(commandChar + path, sd); addedSubcommands.add(sd); } - if (mainMethod != null && !mainPath.equals(commandChar + path)) { //Main command, typically the same as the above - if (isSubcommand) { //The class itself is a subcommand - val scmd = subcommands.computeIfAbsent(mainPath, p -> new SubcommandData<>(null, null, new String[0], new String[]{"§6---- Subcommands ----"})); - val scmdHelp = Arrays.copyOf(scmd.helpText, scmd.helpText.length + scmdHelpList.size()); - for (int i = 0; i < scmdHelpList.size(); i++) - scmdHelp[scmd.helpText.length + i] = scmdHelpList.get(i); - scmd.helpText = scmdHelp; - } else if (!subcommands.containsKey(mainPath)) - subcommands.put(mainPath, new SubcommandData<>(null, null, new String[0], scmdHelpList.toArray(new String[0]))); + if (isSubcommand) { //The class itself is a subcommand + val scmd = subcommands.computeIfAbsent(mainPath, p -> new SubcommandData<>(null, null, new String[0], new String[]{"§6---- Subcommands ----"})); + val scmdHelp = Arrays.copyOf(scmd.helpText, scmd.helpText.length + scmdHelpList.size()); + for (int i = 0; i < scmdHelpList.size(); i++) + scmdHelp[scmd.helpText.length + i] = scmdHelpList.get(i); + scmd.helpText = scmdHelp; } return addedSubcommands; } diff --git a/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2MC.java b/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2MC.java index 7bbf051..bb2eccf 100644 --- a/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2MC.java +++ b/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2MC.java @@ -4,6 +4,7 @@ import buttondevteam.core.MainPlugin; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.architecture.ButtonPlugin; import buttondevteam.lib.architecture.Component; +import buttondevteam.lib.player.ChromaGamerBase; import com.mojang.brigadier.arguments.*; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; @@ -16,10 +17,7 @@ import me.lucko.commodore.CommodoreProvider; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.OfflinePlayer; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.command.SimpleCommandMap; +import org.bukkit.command.*; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -48,7 +46,15 @@ public class Command2MC extends Command2 implemen */ @Override public void registerCommand(ICommand2MC command) { + /*String mainpath; + var plugin = command.getPlugin(); + { + String cpath = command.getCommandPath(); + int i = cpath.indexOf(' '); + mainpath = cpath.substring(0, i == -1 ? cpath.length() : i); + }*/ var subcmds = super.registerCommand(command, '/'); + var perm = "chroma.command." + command.getCommandPath().replace(' ', '.'); if (Bukkit.getPluginManager().getPermission(perm) == null) //Check needed for plugin reset Bukkit.getPluginManager().addPermission(new Permission(perm, @@ -173,6 +179,19 @@ public class Command2MC extends Command2 implemen event.getCompletions().clear(); } + @Override + public boolean handleCommand(Command2MCSender sender, String commandline) { + int i = commandline.indexOf(' '); + String mainpath = commandline.substring(1, i == -1 ? commandline.length() : i); //Without the slash + PluginCommand pcmd; + if (MainPlugin.Instance.prioritizeCustomCommands().get() + || (pcmd = Bukkit.getPluginCommand(mainpath)) == null //Our commands aren't PluginCommands + || pcmd.getPlugin() instanceof ButtonPlugin) //Unless it's specified in the plugin.yml + return super.handleCommand(sender, commandline); + else + return false; + } + private boolean shouldRegisterOfficially = true; private void registerOfficially(ICommand2MC command, List> subcmds) { @@ -199,7 +218,14 @@ public class Command2MC extends Command2 implemen @Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { - sender.sendMessage("§cThe command wasn't executed for some reason... (command processing failed)"); + var user = ChromaGamerBase.getFromSender(sender); + if (user == null) { + TBMCCoreAPI.SendException("Failed to run Bukkit command for user!", new Throwable("No Chroma user found")); + sender.sendMessage("§cAn internal error occurred."); + return true; + } + ButtonPlugin.getCommand2MC().handleCommand(new Command2MCSender(sender, user.channel().get(), sender), + "/" + getName() + " " + String.join(" ", args)); return true; } @@ -378,6 +404,10 @@ public class Command2MC extends Command2 implemen } } commodore.register(maincmd); + var prefixedcmd = new LiteralCommandNode<>(command2MC.getPlugin().getName().toLowerCase() + ":" + path[0], maincmd.getCommand(), maincmd.getRequirement(), maincmd.getRedirect(), maincmd.getRedirectModifier(), maincmd.isFork()); + for (var child : maincmd.getChildren()) + prefixedcmd.addChild(child); + commodore.register(prefixedcmd); } } } diff --git a/Chroma-Core/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java b/Chroma-Core/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java index f6caff0..88c83b2 100755 --- a/Chroma-Core/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java +++ b/Chroma-Core/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java @@ -1,5 +1,6 @@ package buttondevteam.lib.player; +import buttondevteam.core.MainPlugin; import buttondevteam.core.component.towny.TownyComponent; import buttondevteam.lib.TBMCCoreAPI; import org.bukkit.Bukkit; @@ -114,14 +115,13 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase { */ public static void joinPlayer(Player p) { TBMCPlayer player = TBMCPlayerBase.getPlayer(p.getUniqueId(), TBMCPlayer.class); - Bukkit.getLogger().info("Loaded player: " + player.PlayerName().get()); if (player.PlayerName().get() == null) { player.PlayerName().set(p.getName()); - Bukkit.getLogger().info("Player name saved: " + player.PlayerName().get()); + MainPlugin.Instance.getLogger().info("Player name saved: " + player.PlayerName().get()); } else if (!p.getName().equals(player.PlayerName().get())) { TownyComponent.renameInTowny(player.PlayerName().get(), p.getName()); + MainPlugin.Instance.getLogger().info(player.PlayerName().get() + " renamed to " + p.getName()); player.PlayerName().set(p.getName()); - Bukkit.getLogger().info("Renamed to " + p.getName()); } playermap.put(p.getUniqueId() + "-" + TBMCPlayer.class.getSimpleName(), player);