mirror of
https://github.com/songoda/UltimateModeration.git
synced 2024-11-29 21:53:51 +01:00
Fixed command manager.
This commit is contained in:
parent
abfa0b9cee
commit
03ebe22352
@ -9,8 +9,9 @@ import java.util.List;
|
|||||||
|
|
||||||
public abstract class AbstractCommand {
|
public abstract class AbstractCommand {
|
||||||
|
|
||||||
private final AbstractCommand parent;
|
private AbstractCommand parent = null;
|
||||||
private final boolean noConsole;
|
private final boolean noConsole;
|
||||||
|
private boolean hasArgs = false;
|
||||||
private String command;
|
private String command;
|
||||||
|
|
||||||
private List<String> subCommand = new ArrayList<>();
|
private List<String> subCommand = new ArrayList<>();
|
||||||
@ -25,6 +26,13 @@ public abstract class AbstractCommand {
|
|||||||
this.noConsole = noConsole;
|
this.noConsole = noConsole;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected AbstractCommand(boolean noConsole, boolean hasArgs, String... command) {
|
||||||
|
this.command = Arrays.asList(command).get(0);
|
||||||
|
|
||||||
|
this.hasArgs = hasArgs;
|
||||||
|
this.noConsole = noConsole;
|
||||||
|
}
|
||||||
|
|
||||||
public AbstractCommand getParent() {
|
public AbstractCommand getParent() {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
@ -51,6 +59,10 @@ public abstract class AbstractCommand {
|
|||||||
|
|
||||||
public abstract String getDescription();
|
public abstract String getDescription();
|
||||||
|
|
||||||
|
public boolean hasArgs() {
|
||||||
|
return hasArgs;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isNoConsole() {
|
public boolean isNoConsole() {
|
||||||
return noConsole;
|
return noConsole;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package com.songoda.ultimatemoderation.command;
|
package com.songoda.ultimatemoderation.command;
|
||||||
|
|
||||||
|
import com.songoda.epicspawners.References;
|
||||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||||
import com.songoda.ultimatemoderation.command.commands.*;
|
import com.songoda.ultimatemoderation.command.commands.*;
|
||||||
import com.songoda.ultimatemoderation.utils.Methods;
|
import com.songoda.ultimatemoderation.utils.Methods;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -52,24 +54,22 @@ public class CommandManager implements CommandExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||||
for (AbstractCommand abstractCommand : commands) {
|
for (AbstractCommand abstractCommand : commands) {
|
||||||
if (abstractCommand.getCommand() == null)
|
if (abstractCommand.getCommand() != null && abstractCommand.getCommand().equalsIgnoreCase(command.getName().toLowerCase())) {
|
||||||
continue;
|
if (strings.length == 0 || abstractCommand.hasArgs()) {
|
||||||
if (!abstractCommand.getCommand().equalsIgnoreCase(command.getName())) return false;
|
|
||||||
|
|
||||||
if (strings.length == 0) {
|
|
||||||
processRequirements(abstractCommand, commandSender, strings);
|
processRequirements(abstractCommand, commandSender, strings);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName())) {
|
||||||
String cmd = strings[0];
|
String cmd = strings[0];
|
||||||
String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null;
|
String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null;
|
||||||
for (String sub : abstractCommand.getSubCommand()) {
|
for (String cmds : abstractCommand.getSubCommand()) {
|
||||||
if (cmd.equalsIgnoreCase(sub) || (cmd2 != null && cmd2.equalsIgnoreCase(sub))) {
|
if (cmd.equalsIgnoreCase(cmds) || (cmd2 != null && cmd2.equalsIgnoreCase(cmds))) {
|
||||||
processRequirements(abstractCommand, commandSender, strings);
|
processRequirements(abstractCommand, commandSender, strings);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
commandSender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly."));
|
commandSender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly."));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,15 @@ import java.util.List;
|
|||||||
public class CommandClearChat extends AbstractCommand {
|
public class CommandClearChat extends AbstractCommand {
|
||||||
|
|
||||||
public CommandClearChat() {
|
public CommandClearChat() {
|
||||||
super(null, true, "ClearChat");
|
super(true, true,"ClearChat");
|
||||||
addSubCommand("force");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||||
|
|
||||||
|
if (args.length != 0 && !args[0].equalsIgnoreCase("force"))
|
||||||
|
return ReturnType.SYNTAX_ERROR;
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (!player.hasPermission("um.clearchat.bypass") || isForced(args)) {
|
if (!player.hasPermission("um.clearchat.bypass") || isForced(args)) {
|
||||||
String[] toSend = new String[250];
|
String[] toSend = new String[250];
|
||||||
|
@ -12,7 +12,7 @@ import java.util.*;
|
|||||||
public class CommandRandomPlayer extends AbstractCommand {
|
public class CommandRandomPlayer extends AbstractCommand {
|
||||||
|
|
||||||
public CommandRandomPlayer() {
|
public CommandRandomPlayer() {
|
||||||
super(null, true, "RandomPlayer");
|
super(true, false,"RandomPlayer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,7 +19,7 @@ public class CommandToggleChat extends AbstractCommand {
|
|||||||
private boolean toggled = true;
|
private boolean toggled = true;
|
||||||
|
|
||||||
public CommandToggleChat() {
|
public CommandToggleChat() {
|
||||||
super(null, false, "togglechat");
|
super(false, false, "togglechat");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -10,9 +10,7 @@ import java.util.List;
|
|||||||
public class CommandUltimateModeration extends AbstractCommand {
|
public class CommandUltimateModeration extends AbstractCommand {
|
||||||
|
|
||||||
public CommandUltimateModeration() {
|
public CommandUltimateModeration() {
|
||||||
super(null, false, "UltimateModeration");
|
super(false, false, "UltimateModeration");
|
||||||
addSubCommand("reload");
|
|
||||||
addSubCommand("settings");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,7 +22,7 @@ public class CommandVanish extends AbstractCommand {
|
|||||||
private static List<UUID> inVanish = new ArrayList<>();
|
private static List<UUID> inVanish = new ArrayList<>();
|
||||||
|
|
||||||
public CommandVanish() {
|
public CommandVanish() {
|
||||||
super(null, true, "Vanish");
|
super(true, false, "Vanish");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user