+ update SimpleCommandBuilder
This commit is contained in:
parent
da4ddf4493
commit
bc89f1a425
@ -32,6 +32,7 @@ public class SimpleCommandBuilder {
|
||||
private CompleterTab completerTab = EMPTY_COMPLETER_TAB;
|
||||
private CompleterCommand completerCommand = EMPTY_COMPLETER_COMMAND;
|
||||
private boolean silence;
|
||||
private boolean forceRegister;
|
||||
|
||||
SimpleCommandBuilder(String command, Plugin plugin) {
|
||||
this.command = command;
|
||||
@ -43,7 +44,7 @@ public class SimpleCommandBuilder {
|
||||
}
|
||||
|
||||
public static SimpleCommandBuilder create(String command, Plugin plugin) {
|
||||
return new SimpleCommandBuilder(command, plugin);
|
||||
return new SimpleCommandBuilder(command.toLowerCase(), plugin);
|
||||
}
|
||||
|
||||
public SimpleCommandBuilder description(String description) {
|
||||
@ -86,9 +87,17 @@ public class SimpleCommandBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCommandBuilder forceRegister() {
|
||||
this.forceRegister = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCommandBuilder build() {
|
||||
Preconditions.checkNotNull(completerCommand, "缺少 \"CompleterCommand\" 部分");
|
||||
Preconditions.checkNotNull(completerTab, "缺少 \"CompleterTab\" 部分");
|
||||
if (forceRegister) {
|
||||
TCommandHandler.getKnownCommands().remove(command);
|
||||
}
|
||||
TCommandHandler.registerPluginCommand(
|
||||
plugin,
|
||||
command,
|
||||
|
@ -1,7 +1,10 @@
|
||||
package me.skymc.taboolib.commands.internal;
|
||||
|
||||
import com.ilummc.tlib.inject.TPluginManager;
|
||||
import com.ilummc.tlib.resources.TLocale;
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.commands.builder.SimpleCommandBuilder;
|
||||
import me.skymc.taboolib.common.util.SimpleReflection;
|
||||
import me.skymc.taboolib.fileutils.FileUtils;
|
||||
import me.skymc.taboolib.listener.TListener;
|
||||
import me.skymc.taboolib.methods.ReflectionUtils;
|
||||
@ -12,12 +15,14 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.SimplePluginManager;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -28,15 +33,13 @@ import java.util.stream.Collectors;
|
||||
public class TCommandHandler implements Listener {
|
||||
|
||||
private static SimpleCommandMap commandMap;
|
||||
private static Map<String, Command> knownCommands;
|
||||
|
||||
public TCommandHandler() {
|
||||
try {
|
||||
Field commandMap = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
|
||||
commandMap.setAccessible(true);
|
||||
TCommandHandler.commandMap = (SimpleCommandMap) commandMap.get(Bukkit.getPluginManager());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
SimpleReflection.saveFiled(Bukkit.getPluginManager() instanceof TPluginManager ? TPluginManager.class : SimplePluginManager.class, "commandMap");
|
||||
SimpleReflection.saveFiled(SimpleCommandMap.class, "knownCommands");
|
||||
commandMap = (SimpleCommandMap) SimpleReflection.getFieldValue(Bukkit.getPluginManager() instanceof TPluginManager ? TPluginManager.class : SimplePluginManager.class, Bukkit.getPluginManager(), "commandMap");
|
||||
knownCommands = (Map<String, Command>) SimpleReflection.getFieldValue(SimpleCommandMap.class, commandMap, "knownCommands");
|
||||
try {
|
||||
registerCommands();
|
||||
} catch (Exception e) {
|
||||
@ -192,4 +195,8 @@ public class TCommandHandler implements Listener {
|
||||
public static SimpleCommandMap getCommandMap() {
|
||||
return commandMap;
|
||||
}
|
||||
|
||||
public static Map<String, Command> getKnownCommands() {
|
||||
return knownCommands;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user