mirror of
https://e.coding.net/circlecloud/CTZServer.git
synced 2024-11-21 11:28:47 +00:00
update...
This commit is contained in:
parent
c0fef40d73
commit
fa1051717b
64
.classpath
64
.classpath
@ -1,32 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="/PluginHelper"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="/PluginHelper"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
4
pom.xml
4
pom.xml
@ -19,8 +19,8 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -1,10 +0,0 @@
|
||||
name: ${project.artifactId}
|
||||
description: ${project.description}
|
||||
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
|
||||
version: ${project.version}
|
||||
auther: 喵♂呜
|
||||
website: http://ci.citycraft.cn:8800/jenkins/job/${project.artifactId}/
|
||||
commands:
|
||||
yum:
|
||||
description: MC插件仓库
|
||||
usage: §6使用§a/yum help§6查看帮助!
|
@ -5,7 +5,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import cn.citycraft.CTZServer.commands.HandlerCommand;
|
||||
import cn.citycraft.CTZServer.commands.HandlerMainCommand;
|
||||
import cn.citycraft.CTZServer.socket.CTZLoginServerSocket;
|
||||
import cn.citycraft.CTZServerCommon.CTZAuth;
|
||||
import cn.citycraft.CTZServerCommon.CTZServer;
|
||||
@ -16,8 +16,7 @@ import net.md_5.bungee.api.ChatColor;
|
||||
public class ServerThread implements Runnable {
|
||||
protected CTZLoginServerSocket server;
|
||||
protected SQLHelper sql;
|
||||
|
||||
HandlerCommand handlercmd;
|
||||
private HandlerMainCommand handlercmd;
|
||||
|
||||
public CTZLoginServerSocket getServer() {
|
||||
return server;
|
||||
@ -34,17 +33,18 @@ public class ServerThread implements Runnable {
|
||||
server = new CTZLoginServerSocket();
|
||||
server.start();
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
while (true) {
|
||||
String cmdline;
|
||||
try {
|
||||
cmdline = br.readLine();
|
||||
if (cmdline == null || cmdline.isEmpty())
|
||||
if (cmdline == null || cmdline.isEmpty()) {
|
||||
continue;
|
||||
String[] cmdargs = cmdline.split(" ");
|
||||
String cmd = cmdargs[0];
|
||||
handlercmd.execute(cmd, cmdargs);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
final String[] cmdargs = cmdline.split(" ");
|
||||
final String cmd = cmdargs[0];
|
||||
handlercmd.onCommand(cmd, cmdargs);
|
||||
} catch (final IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -54,7 +54,18 @@ public class ServerThread implements Runnable {
|
||||
*/
|
||||
void initCommand() {
|
||||
CTZServer.print(ChatColor.GREEN + "初始化基础命令...");
|
||||
handlercmd = new HandlerCommand(this);
|
||||
handlercmd = new HandlerMainCommand(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化服务器信息
|
||||
*/
|
||||
void initConfigInfo() {
|
||||
CTZServer.print(ChatColor.GREEN + "加载服务器信息...");
|
||||
final File infofile = new File("config.json");
|
||||
FileUtil.saveResource(this, "/config.json", infofile, false);
|
||||
final String configjson = FileUtil.readFile(infofile);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,12 +73,13 @@ public class ServerThread implements Runnable {
|
||||
*/
|
||||
void initServerInfo() {
|
||||
CTZServer.print(ChatColor.GREEN + "加载服务器信息...");
|
||||
File infofile = new File("servers.json");
|
||||
final File infofile = new File("servers.json");
|
||||
FileUtil.saveResource(this, "/servers.json", infofile, false);
|
||||
String json = FileUtil.readFile(infofile);
|
||||
if (CTZServer.Init(json))
|
||||
final String json = FileUtil.readFile(infofile);
|
||||
if (CTZServer.Init(json)) {
|
||||
CTZServer.print(ChatColor.GREEN + "服务器信息加载成功...");
|
||||
else
|
||||
} else {
|
||||
CTZServer.warn(ChatColor.RED + "服务器信息加载失败...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,88 +1,179 @@
|
||||
package cn.citycraft.CTZServer.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseCommand {
|
||||
private String name;
|
||||
private String[] aliases;
|
||||
|
||||
public BaseCommand(String name) {
|
||||
this(name, new String[0]);
|
||||
}
|
||||
|
||||
public BaseCommand(String name, String... aliases) {
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令参数
|
||||
*
|
||||
* @param label
|
||||
* - 命令
|
||||
* @param args
|
||||
* - 命令附加参数
|
||||
*/
|
||||
public abstract void execute(String label, String[] args);
|
||||
|
||||
/**
|
||||
* 获得命令列表
|
||||
*
|
||||
* @return 命令列表
|
||||
*/
|
||||
public List<String> getCommandList() {
|
||||
List<String> cmds = new ArrayList<String>();
|
||||
cmds.add(name);
|
||||
cmds.addAll(Arrays.asList(aliases));
|
||||
return cmds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得命令说明
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String getDescription();
|
||||
|
||||
/**
|
||||
* 获得最小参数个数
|
||||
*
|
||||
* @return 最小参数个数
|
||||
*/
|
||||
public abstract int getMinimumArguments();
|
||||
|
||||
/**
|
||||
* 获取命令名称
|
||||
*
|
||||
* @return 命令名称
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得可能的参数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String getPossibleArguments();
|
||||
|
||||
/**
|
||||
* 命令匹配检测
|
||||
*
|
||||
* @param name
|
||||
* - 命令
|
||||
* @return 是否匹配
|
||||
*/
|
||||
public final boolean isValidTrigger(String name) {
|
||||
if (this.name.equalsIgnoreCase(name))
|
||||
return true;
|
||||
if (aliases != null)
|
||||
for (String alias : aliases)
|
||||
if (alias.equalsIgnoreCase(name))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
package cn.citycraft.CTZServer.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandException;
|
||||
|
||||
/**
|
||||
* 基础命令类
|
||||
*
|
||||
* @author 蒋天蓓
|
||||
* 2015年8月12日下午12:49:34
|
||||
*/
|
||||
public abstract class BaseCommand {
|
||||
private final String[] aliases;
|
||||
private String description = "无";
|
||||
private int minimumArguments = 0;
|
||||
private final String name;
|
||||
private boolean onlyPlayerExecutable = false;
|
||||
private String permission;
|
||||
private String possibleArguments = "";
|
||||
|
||||
public BaseCommand(final String name) {
|
||||
this(name, new String[0]);
|
||||
}
|
||||
|
||||
public BaseCommand(final String name, final String... aliases) {
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令参数
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @param label
|
||||
* - 命令
|
||||
* @param args
|
||||
* - 命令附加参数
|
||||
* @throws CommandException
|
||||
* - 命令异常
|
||||
*/
|
||||
public abstract void execute(String label, String[] args);
|
||||
|
||||
public List<String> getCommandList() {
|
||||
final List<String> cmds = new ArrayList<String>();
|
||||
cmds.add(name);
|
||||
cmds.addAll(Arrays.asList(aliases));
|
||||
return cmds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得命令描述
|
||||
*
|
||||
* @return 命令描述
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得最小参数个数
|
||||
*
|
||||
* @return 最小参数个数
|
||||
*/
|
||||
public int getMinimumArguments() {
|
||||
return minimumArguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取命令名称
|
||||
*
|
||||
* @return 命令名称
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得命令权限
|
||||
*
|
||||
* @return 目录命令权限
|
||||
*/
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得可能的参数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPossibleArguments() {
|
||||
return possibleArguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否只有玩家才能执行此命令
|
||||
*
|
||||
* @return 是否为玩家命令
|
||||
*/
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return onlyPlayerExecutable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 命令匹配检测
|
||||
*
|
||||
* @param name
|
||||
* - 命令
|
||||
* @return 是否匹配
|
||||
*/
|
||||
public final boolean isValidTrigger(final String name) {
|
||||
if (this.name.equalsIgnoreCase(name)) {
|
||||
return true;
|
||||
}
|
||||
if (aliases != null) {
|
||||
for (final String alias : aliases) {
|
||||
if (alias.equalsIgnoreCase(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置命令的描述信息
|
||||
*
|
||||
* @param description
|
||||
* - 命令描述
|
||||
*/
|
||||
public void setDescription(final String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置命令的最小参数个数
|
||||
*
|
||||
* @param minimumArguments
|
||||
* - 最小参数个数
|
||||
*/
|
||||
public void setMinimumArguments(final int minimumArguments) {
|
||||
this.minimumArguments = minimumArguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否只允许玩家执行
|
||||
*
|
||||
* @param onlyPlayerExecutable
|
||||
* - 是否只允许玩家执行
|
||||
*/
|
||||
public void setOnlyPlayerExecutable() {
|
||||
this.onlyPlayerExecutable = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置命令权限
|
||||
*
|
||||
* @param permission
|
||||
* - 命令权限
|
||||
*/
|
||||
public void setPermission(final String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置可能的命令参数
|
||||
*
|
||||
* @param possibleArguments
|
||||
* - 可能的命令参数
|
||||
*/
|
||||
public void setPossibleArguments(final String possibleArguments) {
|
||||
this.possibleArguments = possibleArguments;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
package cn.citycraft.CTZServer.commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* 基础命令类
|
||||
*
|
||||
* @author 蒋天蓓
|
||||
* 2015年8月12日下午12:49:34
|
||||
*/
|
||||
public interface DefaultCommand {
|
||||
|
||||
/**
|
||||
* 默认命令执行接口
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @param label
|
||||
* - 命令
|
||||
* @throws CommandException
|
||||
* - 命令异常
|
||||
*/
|
||||
public abstract void defaultexecute(CommandSender sender, Command command, String label) throws CommandException;
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package cn.citycraft.CTZServer.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cn.citycraft.CTZServer.ServerThread;
|
||||
import cn.citycraft.CTZServerCommon.CTZServer;
|
||||
import cn.citycraft.PluginHelper.utils.StringUtil;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class HandlerCommand {
|
||||
ServerThread serverThread;
|
||||
/**
|
||||
* 已注册命令列表(包括别名)
|
||||
*/
|
||||
List<String> RegisterCommandList = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* 命令监听类列表
|
||||
*/
|
||||
private List<BaseCommand> commandlist = new ArrayList<BaseCommand>();
|
||||
|
||||
public HandlerCommand(ServerThread serverThread) {
|
||||
this.serverThread = serverThread;
|
||||
registerCommand(new CommandStop(serverThread));
|
||||
registerCommand(new CommandGc(serverThread));
|
||||
registerCommand(new CommandRegister(serverThread));
|
||||
}
|
||||
|
||||
public boolean execute(String cmd, String[] args) {
|
||||
String subcmd = args[0];
|
||||
if (subcmd.equalsIgnoreCase("help")) {
|
||||
CTZServer.print("§6=========CTZ服务器帮助列表=========");
|
||||
for (BaseCommand command : commandlist)
|
||||
CTZServer.print(String.format("§6/yum §a%1$s %2$s §6- §b%3$s", command.getName(), command.getPossibleArguments(), command.getDescription()));
|
||||
return true;
|
||||
}
|
||||
String[] subargs = StringUtil.moveStrings(args, 1);
|
||||
for (BaseCommand command : commandlist)
|
||||
if (command.isValidTrigger(subcmd))
|
||||
if (subargs.length >= command.getMinimumArguments()) {
|
||||
command.execute(subcmd, subargs);
|
||||
return true;
|
||||
} else
|
||||
CTZServer.print(ChatColor.RED + "错误的参数 " + ChatColor.YELLOW + "使用方法 /yum " + command.getName() + command.getPossibleArguments());
|
||||
CTZServer.print("未知命令 请使用help查看帮助...");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册命令
|
||||
*
|
||||
* @param command
|
||||
* - 被注册的命令类
|
||||
*/
|
||||
public void registerCommand(BaseCommand command) {
|
||||
if (command != null)
|
||||
commandlist.add(command);
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package cn.citycraft.CTZServer.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandException;
|
||||
|
||||
import cn.citycraft.CTZServer.ServerThread;
|
||||
|
||||
/**
|
||||
* 子命令处理类
|
||||
*
|
||||
* @author 蒋天蓓 2015年8月22日上午8:29:44
|
||||
*/
|
||||
public class HandlerMainCommand {
|
||||
/**
|
||||
* 命令监听类列表
|
||||
*/
|
||||
private final List<BaseCommand> commandlist = new ArrayList<BaseCommand>();;
|
||||
/**
|
||||
* 插件主类
|
||||
*/
|
||||
ServerThread main;
|
||||
|
||||
/**
|
||||
* 注册子命令
|
||||
*
|
||||
* @param yum
|
||||
* - 插件主类
|
||||
*/
|
||||
public HandlerMainCommand(final ServerThread serverThread) {
|
||||
this.main = serverThread;
|
||||
}
|
||||
|
||||
public boolean onCommand(final String label, final String[] args) {
|
||||
for (final BaseCommand command : commandlist) {
|
||||
if (command.isValidTrigger(label)) {
|
||||
if (args.length >= command.getMinimumArguments()) {
|
||||
try {
|
||||
command.execute(label, args);
|
||||
return true;
|
||||
} catch (final CommandException e) {
|
||||
printl(e.getMessage());
|
||||
}
|
||||
} else {
|
||||
printl("§c错误的参数 §e使用方法 /" + command.getName() + command.getPossibleArguments());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void printl(final String msg) {
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册命令
|
||||
*
|
||||
* @param command
|
||||
* - 被注册的命令类
|
||||
*/
|
||||
public void registerCommand(final BaseCommand command) {
|
||||
commandlist.add(command);
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package cn.citycraft.CTZServer.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* 子命令处理类
|
||||
*
|
||||
* @author 蒋天蓓 2015年8月22日上午8:29:44
|
||||
*/
|
||||
public class HandlerSubCommand {
|
||||
/**
|
||||
* 命令监听类列表
|
||||
*/
|
||||
private final List<BaseCommand> commandlist = new ArrayList<BaseCommand>();
|
||||
|
||||
/**
|
||||
* 默认命令处理
|
||||
*/
|
||||
DefaultCommand defaultcommand;
|
||||
|
||||
/**
|
||||
* 插件主类
|
||||
*/
|
||||
Plugin main;
|
||||
|
||||
/**
|
||||
* 已注册命令列表(包括别名)
|
||||
*/
|
||||
List<String> RegisterCommandList = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* 注册子命令
|
||||
*
|
||||
* @param yum
|
||||
* - 插件主类
|
||||
*/
|
||||
public HandlerSubCommand(final Plugin plugin) {
|
||||
this.main = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转移数组
|
||||
*
|
||||
* @param args
|
||||
* - 原数组
|
||||
* @param start
|
||||
* - 数组开始位置
|
||||
* @return 转移后的数组字符串
|
||||
*/
|
||||
public static String[] moveStrings(final String[] args, final int start) {
|
||||
final String[] ret = new String[args.length - start];
|
||||
System.arraycopy(args, start, ret, 0, ret.length);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得已注册的命令列表
|
||||
*
|
||||
* @return - 返回已注册的命令List
|
||||
*/
|
||||
public List<String> getRegisterCommands() {
|
||||
final List<String> cmds = new ArrayList<String>();
|
||||
for (final BaseCommand command : commandlist) {
|
||||
cmds.addAll(command.getCommandList());
|
||||
}
|
||||
return cmds;
|
||||
}
|
||||
|
||||
public boolean onCommand(final String label, final String[] args) {
|
||||
final String prefix = "§6[§b" + main.getName() + "§6] ";
|
||||
final String subcmd = args[0];
|
||||
if (subcmd.equalsIgnoreCase("help")) {
|
||||
printl("§6=========" + prefix + "插件帮助列表=========");
|
||||
for (final BaseCommand command : commandlist) {
|
||||
printl(String.format("§6/" + label + " §a%1$s %2$s §6- §b%3$s", command.getName(), command.getPossibleArguments(), command.getDescription()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
final String[] subargs = moveStrings(args, 1);
|
||||
for (final BaseCommand command : commandlist) {
|
||||
if (command.isValidTrigger(subcmd)) {
|
||||
if (subargs.length >= command.getMinimumArguments()) {
|
||||
try {
|
||||
command.execute(subcmd, subargs);
|
||||
return true;
|
||||
} catch (final CommandException e) {
|
||||
printl(e.getMessage());
|
||||
}
|
||||
} else {
|
||||
printl(prefix + "§c错误的参数 §e使用方法 /" + label + " " + command.getName() + " " + command.getPossibleArguments());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void printl(final String msg) {
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册命令
|
||||
*
|
||||
* @param command
|
||||
* - 被注册的命令类
|
||||
*/
|
||||
public void registerCommand(final BaseCommand command) {
|
||||
commandlist.add(command);
|
||||
RegisterCommandList = getRegisterCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理默认命令
|
||||
*
|
||||
* @param defaultcommand
|
||||
* - 默认命令处理类
|
||||
*/
|
||||
public void setDefaultCommand(final DefaultCommand defaultcommand) {
|
||||
this.defaultcommand = defaultcommand;
|
||||
}
|
||||
|
||||
}
|
10
src/main/resources/config.json
Normal file
10
src/main/resources/config.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"mysql":
|
||||
{
|
||||
"ip": "127.0.0.1",
|
||||
"port": 3306,
|
||||
"username": "root",
|
||||
"password": "",
|
||||
"database": "ctzserver"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user