Skip to content

Commit

Permalink
Not return when is default command, now check with command name and a…
Browse files Browse the repository at this point in the history
…liases, simplify default command checker.
  • Loading branch information
TonimatasDEV committed Sep 10, 2024
1 parent f725e79 commit d7f79cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void onEnable() {

CommandManager.getCommandMap().register("perworldplugins", new PrimaryCommand());

CommandManager.addDefaultCommands();
CommandManager.addDefaultCommands(false);

if (getConfig().getBoolean("metrics")) new Metrics(this, 15794);

Expand All @@ -46,6 +46,7 @@ public void onEnable() {

getServer().getScheduler().scheduleSyncDelayedTask(this, () -> {
ListenerManager.convert();
CommandManager.addDefaultCommands(true);

Bukkit.getConsoleSender().sendMessage("[PerWorldPlugins] " + ChatColor.GREEN + "Converted all Listeners correctly.");
});
Expand Down
41 changes: 18 additions & 23 deletions src/main/java/dev/tonimatas/perworldplugins/listener/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.tonimatas.perworldplugins.PerWorldPlugins;
import dev.tonimatas.perworldplugins.manager.CommandManager;
import dev.tonimatas.perworldplugins.util.PerWorldUtils;
import dev.tonimatas.perworldplugins.util.Why;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -37,45 +38,39 @@ public void onCommandPreProcess(PlayerCommandPreprocessEvent event) {

if (command == null) return;

if (CommandManager.defaultCommands.contains(command)) {
return;
}

List<String> possibleCommands = new ArrayList<>();

for (String plugin : CommandManager.pluginMap.keySet()) {
Map<String, Command> commandMap = CommandManager.pluginMap.get(plugin);
if (PerWorldUtils.getDisabledWorlds(plugin).contains(event.getPlayer().getWorld().getName())) continue;
if (!commandMap.containsKey(commandString)) continue;

if (PerWorldUtils.getDisabledWorlds(plugin).contains(event.getPlayer().getWorld().getName())) {
continue;
}

boolean isHere = false;
for (Command cmd : commandMap.values()) {
if (cmd.getName().equalsIgnoreCase(commandString) || cmd.getAliases().contains(commandString)) {
isHere = true;
break;
}
}

if (!isHere) continue;

String commandStr;

if (commandString.contains(":")) {
commandStr = commandString;
} else {
commandStr = plugin.toLowerCase(Locale.ENGLISH) + ":" + commandString;
commandStr = Why.whyPlugin(plugin) + ":" + commandString;
}


possibleCommands.add(commandStr);
}

for (Command defaultCommand : CommandManager.defaultCommands) {
String[] splitDefaultCommand = defaultCommand.getName().split(":");
if (splitDefaultCommand.length == 0) continue;

String[] splitCommand = commandString.split(":");

if (splitCommand.length == 0) {
if (splitDefaultCommand[1].equals(commandString)) {
possibleCommands.add(defaultCommand.getName());
break;
}
} else {
if (defaultCommand.getName().equals(commandString)) {
possibleCommands.add(defaultCommand.getName());
break;
}
if (defaultCommand.getName().equals(commandString) || defaultCommand.getAliases().contains(commandString)) {
possibleCommands.add(defaultCommand.getName());
}
}

Expand Down

0 comments on commit d7f79cf

Please sign in to comment.