SimpleEssential/src/main/java/cn/citycraft/SimpleEssential/SimpleEssential.java

152 lines
4.6 KiB
Java

/**
*
*/
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.config.FileConfig;
import cn.citycraft.PluginHelper.utils.VersionChecker;
import cn.citycraft.SimpleEssential.command.CommandBack;
import cn.citycraft.SimpleEssential.command.CommandEnchantBench;
import cn.citycraft.SimpleEssential.command.CommandGc;
import cn.citycraft.SimpleEssential.command.CommandHat;
import cn.citycraft.SimpleEssential.command.CommandHome;
import cn.citycraft.SimpleEssential.command.CommandPing;
import cn.citycraft.SimpleEssential.command.CommandSetHome;
import cn.citycraft.SimpleEssential.command.CommandSetSpawn;
import cn.citycraft.SimpleEssential.command.CommandSpawn;
import cn.citycraft.SimpleEssential.command.CommandSuicide;
import cn.citycraft.SimpleEssential.command.CommandTop;
import cn.citycraft.SimpleEssential.command.CommandTpa;
import cn.citycraft.SimpleEssential.command.CommandTpaccept;
import cn.citycraft.SimpleEssential.command.CommandTpdeny;
import cn.citycraft.SimpleEssential.command.CommandTphere;
import cn.citycraft.SimpleEssential.command.CommandWorkBench;
import cn.citycraft.SimpleEssential.command.CommandWorld;
import cn.citycraft.SimpleEssential.config.I18n;
import cn.citycraft.SimpleEssential.listen.PlayerLocationListen;
import cn.citycraft.SimpleEssential.teleport.TeleportControl;
/**
* 简单基础插件
*
* @author 蒋天蓓 2015年8月11日下午3:29:32
*/
public class SimpleEssential extends JavaPlugin {
/**
* 传送控制
*/
public TeleportControl tpcontrol;
/**
* 命令监听列表
*/
private List<BaseCommand> commandlist;
FileConfig config;
@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"));
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();
new VersionChecker(this);
}
@Override
public void onLoad() {
config = new FileConfig(this);
I18n.load(this);
}
/**
* 注册命令
*
* @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));
}
/**
* 注册事件
*
* @param listener
* - 被注册的事件类
*/
public void registerEvent(final Listener listener) {
getServer().getPluginManager().registerEvents(listener, this);
}
private void initTeleportControl() {
final int tpdelay = config.getInt("Teleport.delay", 3);
final String tpcontorlname = config.getMessage("Teleport.name");
tpcontrol = new TeleportControl(this, tpcontorlname, tpdelay);
}
/**
* 注册事件
*/
private void registerEvents() {
registerEvent(new PlayerLocationListen(this));
}
}