Skip to content

Commit

Permalink
Optimize things
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Dec 1, 2023
1 parent 3b564b1 commit f350858
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onEnable() {
// Convert listeners and set worlds to commands.
ListenerManager.convert();
// Register all converted commands.
CommandManager.init();
CommandManager.setWorldsToCommands();

// Send a message on finish all Events/Commands.
Bukkit.getConsoleSender().sendMessage("[PerWorldPlugins] " + ChatColor.GREEN + "Converted all Listeners/Commands correctly.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,24 @@

public class CommandManager implements Listener {
private static final List<String> defaultCommands = Arrays.asList("version", "timings", "reload", "plugins", "tps", "mspt", "paper", "spigot", "restart", "perworldplugins");
private static final List<PerWorldCommand> commands = new ArrayList<>();

public static void init() {
// Replace all Commands to PerWorldCommands.
commands.forEach(CommandManager::replace);

// Set the blocked worlds to the commands.
setWorldsToCommands();
commands.clear();
}

public static void addPluginCommands(Plugin plugin) {
// Get all keys.
List<Command> replaced = new ArrayList<>();

for (String key : getCommands().keySet()) {
// Get PerWorldCommand and add to perWorldCommands list.
Command command = getCommands().get(key);

// If a default command or PerWorldCommand, continue.
if (defaultCommands.contains(command.getName()) || command instanceof PerWorldCommand) continue;
// If the command are registered, continue.
if (commands.stream().anyMatch(perWorldCommand -> perWorldCommand.getName().equals(command.getName()) || perWorldCommand.getAliases().contains(command.getName()))) continue;
if (replaced.contains(command)) continue;

// Replace command and add to replaced list.
replace(PerWorldCommand.get(command, plugin));

// Get and add PerWorldCommand.
commands.add(PerWorldCommand.get(command, plugin));
replaced.add(command);
}
}

Expand Down

0 comments on commit f350858

Please sign in to comment.