1
0
mirror of https://e.coding.net/circlecloud/SimpleEssential.git synced 2024-11-17 01:18:47 +00:00

fix Plugin Command handle error...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-10-21 17:17:01 +08:00
parent 6c4009a0ce
commit a821285ac3
2 changed files with 31 additions and 58 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cn.citycraft</groupId>
<artifactId>SimpleEssential</artifactId>
<version>1.4</version>
<version>1.4.1</version>
<name>SimpleEssential</name>
<description>轻量级基础插件</description>
<build>

View File

@ -3,17 +3,12 @@
*/
package cn.citycraft.SimpleEssential;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.PluginHelper.commands.HandlerMainCommand;
import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.utils.VersionChecker;
import cn.citycraft.SimpleEssential.command.CommandBack;
@ -47,42 +42,30 @@ public class SimpleEssential extends JavaPlugin {
* 传送控制
*/
public TeleportControl tpcontrol;
/**
* 命令监听列表
*/
private List<BaseCommand> commandlist;
FileConfig config;
/**
* 命令处理
*/
HandlerMainCommand hmc;
@Override
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
for (final BaseCommand command : commandlist) {
if (command.isValidTrigger(label)) {
if (!command.hasPermission(sender)) {
sender.sendMessage(I18n.p("Base.no-permission"));
if (!hmc.onCommand(sender, cmd, label, args)) {
hmc.sendHelp(sender);
}
return true;
}
if (command.isOnlyPlayerExecutable() && !(sender instanceof Player)) {
sender.sendMessage(I18n.p("Base.playercommand"));
return true;
}
if (args.length >= command.getMinimumArguments()) {
try {
command.execute(sender, cmd, label, args);
return true;
} catch (final CommandException e) {
sender.sendMessage(e.getMessage());
}
}
}
}
return false;
}
@Override
public void onEnable() {
this.initTeleportControl();
this.registerCommands();
this.registerEvents();
this.registerCommands();
new VersionChecker(this);
}
@ -93,37 +76,27 @@ public class SimpleEssential extends JavaPlugin {
}
/**
* 注册命令
*
* @param command
* - 被注册的命令类
*/
public void registerCommand(final BaseCommand command) {
commandlist.add(command);
}
/**
* 注册命令
* 注册插件主要命令
*/
public void registerCommands() {
commandlist = new ArrayList<BaseCommand>();
registerCommand(new CommandTpa(this));
registerCommand(new CommandTop(this));
registerCommand(new CommandTpaccept(this));
registerCommand(new CommandTpdeny(this));
registerCommand(new CommandTphere(this));
registerCommand(new CommandBack(this));
registerCommand(new CommandSetHome(this));
registerCommand(new CommandHome(this));
registerCommand(new CommandHat(this));
registerCommand(new CommandSuicide(this));
registerCommand(new CommandEnchantBench(this));
registerCommand(new CommandWorkBench(this));
registerCommand(new CommandSetSpawn(this));
registerCommand(new CommandSpawn(this));
registerCommand(new CommandGc(this));
registerCommand(new CommandWorld(this));
registerCommand(new CommandPing(this));
hmc = new HandlerMainCommand(this);
hmc.registerCommand(new CommandTpa(this));
hmc.registerCommand(new CommandTop(this));
hmc.registerCommand(new CommandTpaccept(this));
hmc.registerCommand(new CommandTpdeny(this));
hmc.registerCommand(new CommandTphere(this));
hmc.registerCommand(new CommandBack(this));
hmc.registerCommand(new CommandSetHome(this));
hmc.registerCommand(new CommandHome(this));
hmc.registerCommand(new CommandHat(this));
hmc.registerCommand(new CommandSuicide(this));
hmc.registerCommand(new CommandEnchantBench(this));
hmc.registerCommand(new CommandWorkBench(this));
hmc.registerCommand(new CommandSetSpawn(this));
hmc.registerCommand(new CommandSpawn(this));
hmc.registerCommand(new CommandGc(this));
hmc.registerCommand(new CommandWorld(this));
hmc.registerCommand(new CommandPing(this));
}
/**