mirror of
https://github.com/aikar/commands.git
synced 2026-05-31 06:11:55 +00:00
@@ -23,9 +23,23 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
public class AikarTiming extends SpigotTiming {// TODO: Extend CommandTiming once migrated to v2
|
||||
public AikarTiming(BaseCommand command, String name) {
|
||||
super(command, name);
|
||||
// TODO: Take plugin from BaseCommand and use Timing.of(plugin, name) and use Timing class
|
||||
import co.aikar.timings.Timing;
|
||||
import co.aikar.timings.Timings;
|
||||
|
||||
public class AikarTiming implements CommandTiming {
|
||||
private final Timing timing;
|
||||
AikarTiming(BaseCommand command, String name) {
|
||||
super();
|
||||
this.timing = Timings.of(command.getPlugin(), name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startTiming() {
|
||||
timing.startTiming();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopTiming() {
|
||||
timing.stopTiming();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -52,17 +53,25 @@ import java.util.stream.Collectors;
|
||||
public abstract class BaseCommand extends Command {
|
||||
|
||||
private final SetMultimap<String, RegisteredCommand> subCommands = HashMultimap.create();
|
||||
private final Plugin plugin;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
protected String execLabel;
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
protected String execSubcommand;
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
protected String[] origArgs;
|
||||
|
||||
public BaseCommand() {
|
||||
this(null);
|
||||
public BaseCommand(Plugin plugin) {
|
||||
this(plugin, null);
|
||||
}
|
||||
|
||||
public BaseCommand(String cmd) {
|
||||
public BaseCommand(Plugin plugin, String cmd) {
|
||||
super(cmd);
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("Plugin can not be null");
|
||||
}
|
||||
this.plugin = plugin;
|
||||
final Class<? extends BaseCommand> self = this.getClass();
|
||||
CommandAlias rootCmdAlias = self.getAnnotation(CommandAlias.class);
|
||||
if (cmd == null) {
|
||||
@@ -131,7 +140,7 @@ public abstract class BaseCommand extends Command {
|
||||
}
|
||||
|
||||
private boolean register(String name, Command cmd) {
|
||||
return Bukkit.getServer().getCommandMap().register(name.toLowerCase(), "empire", cmd);
|
||||
return Bukkit.getServer().getCommandMap().register(name.toLowerCase(), plugin.getName().toLowerCase(), cmd);
|
||||
}
|
||||
|
||||
private void registerSubcommand(Method method, String subCommand) {
|
||||
@@ -405,6 +414,11 @@ public abstract class BaseCommand extends Command {
|
||||
CommandUtil.sendMsg(sender, "&cUsage: /" + cmd.command + " " + cmd.syntax);
|
||||
}
|
||||
|
||||
|
||||
public Plugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/*@Data*/ /*@AllArgsConstructor*/
|
||||
private static class CommandSearch { RegisteredCommand cmd; int argIndex; String checkSub;
|
||||
|
||||
|
||||
@@ -23,14 +23,7 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
public abstract class CommandTiming {
|
||||
private final BaseCommand command;
|
||||
|
||||
CommandTiming(BaseCommand command) {
|
||||
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public abstract void startTiming();
|
||||
public abstract void stopTiming();
|
||||
public interface CommandTiming {
|
||||
void startTiming();
|
||||
void stopTiming();
|
||||
}
|
||||
|
||||
@@ -881,8 +881,8 @@ public final class CommandUtil {
|
||||
}
|
||||
if (hasTimings > 0) {
|
||||
final String name = "Command: " + command;
|
||||
return hasTimings == 1 ? new AikarTiming(cmd, name): new SpigotTiming(cmd, name);
|
||||
return hasTimings == 1 ? new AikarTiming(cmd, name): new SpigotTiming(name);
|
||||
}
|
||||
return new EmptyTiming(cmd);
|
||||
return new EmptyTiming();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
|
||||
package co.aikar.commands;
|
||||
|
||||
public class EmptyTiming extends CommandTiming {
|
||||
EmptyTiming(BaseCommand command) {
|
||||
super(command);
|
||||
public class EmptyTiming implements CommandTiming {
|
||||
EmptyTiming() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,11 +25,11 @@ package co.aikar.commands;
|
||||
|
||||
import org.spigotmc.CustomTimingsHandler;
|
||||
|
||||
public class SpigotTiming extends CommandTiming {
|
||||
public class SpigotTiming implements CommandTiming {
|
||||
private final CustomTimingsHandler timing;
|
||||
|
||||
SpigotTiming(BaseCommand command, String name) {
|
||||
super(command);
|
||||
SpigotTiming(String name) {
|
||||
super();
|
||||
this.timing = new CustomTimingsHandler(name);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user