mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-10-31 09:33:43 +01:00 
			
		
		
		
	Fix command duplication
This commit is contained in:
		| @@ -40,6 +40,7 @@ import com.plotsquared.general.commands.CommandDeclaration; | |||||||
|         permission = "plots.delete", |         permission = "plots.delete", | ||||||
|         description = "Delete a plot", |         description = "Delete a plot", | ||||||
|         usage = "/plot delete", |         usage = "/plot delete", | ||||||
|  |         aliases = "dispose", | ||||||
|         category = CommandCategory.ACTIONS, |         category = CommandCategory.ACTIONS, | ||||||
|         requiredType = RequiredType.NONE |         requiredType = RequiredType.NONE | ||||||
| ) | ) | ||||||
|   | |||||||
| @@ -124,14 +124,6 @@ public class MainCommand extends CommandManager<PlotPlayer> { | |||||||
|         createCommand(new Copy()); |         createCommand(new Copy()); | ||||||
|         createCommand(new Chat()); |         createCommand(new Chat()); | ||||||
|         createCommand(new Trim()); |         createCommand(new Trim()); | ||||||
|          |  | ||||||
|         if (Settings.ENABLE_CLUSTERS) { |  | ||||||
|             createCommand(new Cluster()); |  | ||||||
|         } |  | ||||||
|          |  | ||||||
|         // Broken |  | ||||||
| //        createCommand(new DebugUUID()); |  | ||||||
|          |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean no_permission(final PlotPlayer player, final String permission) { |     public static boolean no_permission(final PlotPlayer player, final String permission) { | ||||||
| @@ -141,7 +133,7 @@ public class MainCommand extends CommandManager<PlotPlayer> { | |||||||
|      |      | ||||||
|     public static List<Command<PlotPlayer>> getCommands(final CommandCategory category, final PlotPlayer player) { |     public static List<Command<PlotPlayer>> getCommands(final CommandCategory category, final PlotPlayer player) { | ||||||
|         List<Command<PlotPlayer>> commands = new ArrayList<>(); |         List<Command<PlotPlayer>> commands = new ArrayList<>(); | ||||||
|         for (Command<PlotPlayer> command : instance.getCommands()) { |         for (Command<PlotPlayer> command : getInstance().getCommands()) { | ||||||
|             if (category != null && !command.getCategory().equals(category)) { |             if (category != null && !command.getCategory().equals(category)) { | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
| @@ -330,14 +322,18 @@ public class MainCommand extends CommandManager<PlotPlayer> { | |||||||
|             args = new String[parts.length - 2]; |             args = new String[parts.length - 2]; | ||||||
|             System.arraycopy(parts, 2, args, 0, args.length); |             System.arraycopy(parts, 2, args, 0, args.length); | ||||||
|         } |         } | ||||||
|         Command<PlotPlayer> cmd = null; |         Command<PlotPlayer> cmd; | ||||||
|         cmd = this.commands.get(label); |         if (label != null) { | ||||||
|  |             cmd = getInstance().commands.get(label); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             cmd = null; | ||||||
|  |         } | ||||||
|         if (cmd == null) { |         if (cmd == null) { | ||||||
|             MainUtil.sendMessage(plr, C.NOT_VALID_SUBCOMMAND); |             MainUtil.sendMessage(plr, C.NOT_VALID_SUBCOMMAND); | ||||||
|             { |             { | ||||||
|                 List<Command<PlotPlayer>> cmds = getCommands(null, plr); |                 List<Command<PlotPlayer>> cmds = getCommands(null, plr); | ||||||
|                 cmd = new StringComparison<>(label, cmds).getMatchObject(); |                 if (label == null || (cmd = new StringComparison<>(label, cmds).getMatchObject()) == null) { | ||||||
|                 if (cmd == null) { |  | ||||||
|                     MainUtil.sendMessage(plr, C.DID_YOU_MEAN, "/plot help"); |                     MainUtil.sendMessage(plr, C.DID_YOU_MEAN, "/plot help"); | ||||||
|                 } |                 } | ||||||
|                 else { |                 else { | ||||||
|   | |||||||
| @@ -78,7 +78,7 @@ public class plugin extends SubCommand { | |||||||
|                         add(String.format("$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92")); |                         add(String.format("$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92")); | ||||||
|                         add(String.format("$2>> $1&lWiki$2: $1https://github.com/IntellectualCrafters/PlotSquared/wiki")); |                         add(String.format("$2>> $1&lWiki$2: $1https://github.com/IntellectualCrafters/PlotSquared/wiki")); | ||||||
|                         add(String.format("$2>> $1&lWebsite$2: $1http://plotsquared.com")); |                         add(String.format("$2>> $1&lWebsite$2: $1http://plotsquared.com")); | ||||||
|                         add(String.format("$2>> $1&lNewest Version$2: $1" + (PS.get().update == null ? PS.get().IMP.getPluginVersion() : PS.get().update))); |                         add(String.format("$2>> $1&lNewest Version$2: $1" + (PS.get().update == null ? StringMan.join(PS.get().IMP.getPluginVersion(), ".") : PS.get().update))); | ||||||
|                     } |                     } | ||||||
|                 }; |                 }; | ||||||
|                 for (final String s : strings) { |                 for (final String s : strings) { | ||||||
|   | |||||||
| @@ -96,6 +96,7 @@ public class Settings { | |||||||
|      * Default kill road mobs: true |      * Default kill road mobs: true | ||||||
|      */ |      */ | ||||||
|     public final static boolean KILL_ROAD_MOBS_DEFAULT = false; |     public final static boolean KILL_ROAD_MOBS_DEFAULT = false; | ||||||
|  |     public final static boolean KILL_ROAD_VEHICLES_DEFAULT = false; | ||||||
|     /** |     /** | ||||||
|      * Default mob pathfinding: true |      * Default mob pathfinding: true | ||||||
|      */ |      */ | ||||||
| @@ -132,6 +133,7 @@ public class Settings { | |||||||
|      * Kill road mobs? |      * Kill road mobs? | ||||||
|      */ |      */ | ||||||
|     public static boolean KILL_ROAD_MOBS; |     public static boolean KILL_ROAD_MOBS; | ||||||
|  |     public static boolean KILL_ROAD_VEHICLES; | ||||||
|     /** |     /** | ||||||
|      * mob pathfinding? |      * mob pathfinding? | ||||||
|      */ |      */ | ||||||
|   | |||||||
| @@ -14,6 +14,8 @@ import org.bukkit.entity.Entity; | |||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
| import org.bukkit.event.Listener; | import org.bukkit.event.Listener; | ||||||
| import org.bukkit.generator.ChunkGenerator; | import org.bukkit.generator.ChunkGenerator; | ||||||
|  | import org.bukkit.metadata.MetadataValue; | ||||||
|  | import org.bukkit.metadata.MetadataValueAdapter; | ||||||
| import org.bukkit.plugin.Plugin; | import org.bukkit.plugin.Plugin; | ||||||
| import org.bukkit.plugin.java.JavaPlugin; | import org.bukkit.plugin.java.JavaPlugin; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -11,8 +11,10 @@ import org.bukkit.command.CommandSender; | |||||||
| import org.bukkit.command.TabCompleter; | import org.bukkit.command.TabCompleter; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
|  | import com.intellectualcrafters.plot.commands.Cluster; | ||||||
| import com.intellectualcrafters.plot.commands.DebugUUID; | import com.intellectualcrafters.plot.commands.DebugUUID; | ||||||
| import com.intellectualcrafters.plot.commands.MainCommand; | import com.intellectualcrafters.plot.commands.MainCommand; | ||||||
|  | import com.intellectualcrafters.plot.config.Settings; | ||||||
| import com.intellectualcrafters.plot.object.ConsolePlayer; | import com.intellectualcrafters.plot.object.ConsolePlayer; | ||||||
| import com.intellectualcrafters.plot.object.PlotPlayer; | import com.intellectualcrafters.plot.object.PlotPlayer; | ||||||
| import com.intellectualcrafters.plot.util.StringComparison; | import com.intellectualcrafters.plot.util.StringComparison; | ||||||
| @@ -27,6 +29,9 @@ public class BukkitCommand implements CommandExecutor, TabCompleter { | |||||||
|      |      | ||||||
|     public BukkitCommand() { |     public BukkitCommand() { | ||||||
|         MainCommand.getInstance().addCommand(new DebugUUID()); |         MainCommand.getInstance().addCommand(new DebugUUID()); | ||||||
|  |         if (Settings.ENABLE_CLUSTERS) { | ||||||
|  |             MainCommand.getInstance().addCommand(new Cluster()); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     @Override |     @Override | ||||||
| @@ -55,6 +60,8 @@ public class BukkitCommand implements CommandExecutor, TabCompleter { | |||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
|         final Set<String> tabOptions = new HashSet<>(); |         final Set<String> tabOptions = new HashSet<>(); | ||||||
|  |         System.out.print(MainCommand.getInstance() + " mc"); | ||||||
|  |         System.out.print(MainCommand.getInstance().getCommands() + " gc"); | ||||||
|         ArrayList<Command<PlotPlayer>> commands = MainCommand.getInstance().getCommands(); |         ArrayList<Command<PlotPlayer>> commands = MainCommand.getInstance().getCommands(); | ||||||
|         String best = new StringComparison(strings[0], commands).getBestMatch(); |         String best = new StringComparison(strings[0], commands).getBestMatch(); | ||||||
|         tabOptions.add(best); |         tabOptions.add(best); | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ package com.plotsquared.general.commands; | |||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.Collections; | import java.util.Collections; | ||||||
| import java.util.Comparator; | import java.util.Comparator; | ||||||
|  | import java.util.HashSet; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.concurrent.ConcurrentHashMap; | import java.util.concurrent.ConcurrentHashMap; | ||||||
|  |  | ||||||
| @@ -51,7 +52,8 @@ public class CommandManager<T extends CommandCaller> { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     final public ArrayList<Command<T>> getCommands() { |     final public ArrayList<Command<T>> getCommands() { | ||||||
|         ArrayList<Command<T>> result = new ArrayList<>(this.commands.values()); |         HashSet<Command<T>> set = new HashSet<>(this.commands.values()); | ||||||
|  |         ArrayList<Command<T>> result = new ArrayList<>(set); | ||||||
|         Collections.sort(result, new Comparator<Command<T>>() { |         Collections.sort(result, new Comparator<Command<T>>() { | ||||||
|             @Override |             @Override | ||||||
|             public int compare(Command<T> a, Command<T> b) { |             public int compare(Command<T> a, Command<T> b) { | ||||||
|   | |||||||
| @@ -33,7 +33,7 @@ public class SpongeCommand implements CommandCallable { | |||||||
|         catch (Exception e) { |         catch (Exception e) { | ||||||
|             pp = ConsolePlayer.getConsole(); |             pp = ConsolePlayer.getConsole(); | ||||||
|         } |         } | ||||||
|         if (MainCommand.onCommand(pp, cmd.getName(), string.split(" "))) { |         if (MainCommand.onCommand(pp, cmd.getName(), string.length() == 0 ? new String[] {} : string.split(" "))) { | ||||||
|             return CommandResult.success(); |             return CommandResult.success(); | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 boy0001
					boy0001