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

133 lines
3.5 KiB
Java
Raw Normal View History

2015-08-11 13:06:01 +00:00
/**
*
2015-08-11 13:06:01 +00:00
*/
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;
2015-08-11 13:06:01 +00:00
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.SimpleEssential.command.CommandBack;
2015-08-13 12:41:51 +00:00
import cn.citycraft.SimpleEssential.command.CommandHome;
import cn.citycraft.SimpleEssential.command.CommandSetHome;
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.SimpleEssentialCommand;
2015-08-11 13:06:01 +00:00
import cn.citycraft.SimpleEssential.config.Config;
import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.listen.PlayerLocationListen;
import cn.citycraft.SimpleEssential.teleport.TeleportControl;
import cn.citycraft.SimpleEssential.utils.VersionChecker;
2015-08-11 13:06:01 +00:00
/**
*
*
* @author 20158113:29:32
2015-08-11 13:06:01 +00:00
*/
public class SimpleEssential extends JavaPlugin {
/**
*
*/
public TeleportControl tpcontrol;
/**
*
*/
private List<SimpleEssentialCommand> commandlist;
2015-08-11 13:06:01 +00:00
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
for (SimpleEssentialCommand command : commandlist) {
if (command.isValidTrigger(label)) {
if (!command.hasPermission(sender)) {
sender.sendMessage(Language.getMessage("Base.no-permission"));
return true;
}
if (command.isOnlyPlayerExecutable() && !(sender instanceof Player)) {
sender.sendMessage(Language.getMessage("Base.playercommand"));
return true;
}
if (args.length >= command.getMinimumArguments()) {
try {
command.execute(sender, label, args);
return true;
} catch (CommandException e) {
sender.sendMessage(e.getMessage());
}
}
}
}
return false;
2015-08-11 13:06:01 +00:00
}
@Override
public void onDisable() {
}
@Override
public void onEnable() {
tpcontrol = new TeleportControl(this);
this.registerCommands();
this.registerEvents();
new VersionChecker(this);
}
/**
*
*/
private void registerEvents() {
registerEvent(new PlayerLocationListen(this));
2015-08-11 13:06:01 +00:00
}
@Override
public void onLoad() {
Config.load(this, "1.0");
Language.load(this, "1.0");
}
/**
*
*/
public void registerCommands() {
commandlist = new ArrayList<SimpleEssentialCommand>();
registerCommand(new CommandTpa(this));
registerCommand(new CommandTop(this));
registerCommand(new CommandTpaccept(this));
registerCommand(new CommandTpdeny(this));
registerCommand(new CommandTphere(this));
registerCommand(new CommandBack(this));
2015-08-13 12:41:51 +00:00
registerCommand(new CommandSetHome(this));
registerCommand(new CommandHome(this));
}
/**
*
*
* @param command
* -
*/
public void registerCommand(SimpleEssentialCommand command) {
commandlist.add(command);
}
/**
*
*
* @param listener
* -
*/
public void registerEvent(Listener listener) {
getServer().getPluginManager().registerEvents(listener, this);
}
2015-08-11 13:06:01 +00:00
}