diff --git a/pom.xml b/pom.xml index d5598b0..5ebba8a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cn.citycraft SimpleEssential - 1.1 + 1.2 SimpleEssential 轻量级基础插件 diff --git a/src/main/java/cn/citycraft/SimpleEssential/SimpleEssential.java b/src/main/java/cn/citycraft/SimpleEssential/SimpleEssential.java index 308dcb2..d37575c 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/SimpleEssential.java +++ b/src/main/java/cn/citycraft/SimpleEssential/SimpleEssential.java @@ -16,6 +16,7 @@ import org.bukkit.plugin.java.JavaPlugin; import cn.citycraft.SimpleEssential.command.BaseCommand; 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.CommandSetHome; @@ -28,7 +29,8 @@ 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.config.Language; +import cn.citycraft.SimpleEssential.command.CommandWorld; +import cn.citycraft.SimpleEssential.config.I18n; import cn.citycraft.SimpleEssential.listen.PlayerLocationListen; import cn.citycraft.SimpleEssential.teleport.TeleportControl; import cn.citycraft.config.FileConfig; @@ -50,22 +52,16 @@ public class SimpleEssential extends JavaPlugin { */ private List commandlist; - private void initTeleportControl() { - int tpdelay = config.getInt("Teleport.delay", 3); - String tpcontorlname = config.getMessage("Teleport.name"); - tpcontrol = new TeleportControl(this, tpcontorlname, tpdelay); - } - @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { for (BaseCommand command : commandlist) if (command.isValidTrigger(label)) { if (!command.hasPermission(sender)) { - sender.sendMessage(Language.getMessage("Base.no-permission")); + sender.sendMessage(I18n.parse("Base.no-permission")); return true; } if (command.isOnlyPlayerExecutable() && !(sender instanceof Player)) { - sender.sendMessage(Language.getMessage("Base.playercommand")); + sender.sendMessage(I18n.parse("Base.playercommand")); return true; } if (args.length >= command.getMinimumArguments()) @@ -90,7 +86,7 @@ public class SimpleEssential extends JavaPlugin { @Override public void onLoad() { config = new FileConfig(this); - Language.load(this); + I18n.load(this); } /** @@ -122,6 +118,8 @@ public class SimpleEssential extends JavaPlugin { registerCommand(new CommandWorkBench(this)); registerCommand(new CommandSetSpawn(this)); registerCommand(new CommandSpawn(this)); + registerCommand(new CommandGc(this)); + registerCommand(new CommandWorld(this)); } /** @@ -134,6 +132,12 @@ public class SimpleEssential extends JavaPlugin { getServer().getPluginManager().registerEvents(listener, this); } + private void initTeleportControl() { + int tpdelay = config.getInt("Teleport.delay", 3); + String tpcontorlname = config.getMessage("Teleport.name"); + tpcontrol = new TeleportControl(this, tpcontorlname, tpdelay); + } + /** * 注册事件 */ diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/BaseCommand.java b/src/main/java/cn/citycraft/SimpleEssential/command/BaseCommand.java index a583537..411c3a7 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/BaseCommand.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/BaseCommand.java @@ -39,6 +39,13 @@ public abstract class BaseCommand { */ public abstract void execute(CommandSender sender, String label, String[] args) throws CommandException; + /** + * 获得命令描述 + * + * @return 命令描述 + */ + public abstract String getDescription(); + /** * 获得最小参数个数 * @@ -101,12 +108,10 @@ public abstract class BaseCommand { public final boolean isValidTrigger(String name) { if (this.name.equalsIgnoreCase(name)) return true; - if (aliases != null) { - for (String alias : aliases) { + if (aliases != null) + for (String alias : aliases) if (alias.equalsIgnoreCase(name)) return true; - } - } return false; } diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandBack.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandBack.java index 1e94ecb..74e13c3 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandBack.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandBack.java @@ -24,13 +24,13 @@ public class CommandBack extends BaseCommand { } @Override - public boolean isOnlyPlayerExecutable() { - return true; + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + plugin.tpcontrol.back((Player) sender); }; @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - plugin.tpcontrol.back((Player) sender); + public String getDescription() { + return "回到上一个地点"; } @Override @@ -42,4 +42,9 @@ public class CommandBack extends BaseCommand { public String getPossibleArguments() { return ""; } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; + } } diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandEnchantBench.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandEnchantBench.java index 6e87ec0..fc50b35 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandEnchantBench.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandEnchantBench.java @@ -29,6 +29,11 @@ public class CommandEnchantBench extends BaseCommand { p.openEnchanting(null, true); } + @Override + public String getDescription() { + return "打开随声附魔台"; + } + @Override public int getMinimumArguments() { return 0; diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandGc.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandGc.java new file mode 100644 index 0000000..ea907f3 --- /dev/null +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandGc.java @@ -0,0 +1,65 @@ +/** + * + */ +package cn.citycraft.SimpleEssential.command; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; + +import cn.citycraft.SimpleEssential.SimpleEssential; +import cn.citycraft.SimpleEssential.config.I18n; +import cn.citycraft.utils.StringUtil; + +/** + * 传送到顶部命令 + * + * @author 蒋天蓓 + * 2015年8月12日下午2:04:05 + * + */ +public class CommandGc extends BaseCommand { + SimpleEssential plugin; + + /** + * @param name + */ + public CommandGc(SimpleEssential main) { + super("gc", "mem"); + this.plugin = main; + } + + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + Runtime rt = Runtime.getRuntime(); + if (label.equalsIgnoreCase("gc")) + rt.gc(); + sender.sendMessage(I18n.parse("Gc.Processors", rt.availableProcessors())); + sender.sendMessage(I18n.parse("Gc.maxMem", StringUtil.b2mb(rt.maxMemory()))); + sender.sendMessage(I18n.parse("Gc.totalMem", StringUtil.b2mb(rt.totalMemory()))); + sender.sendMessage(I18n.parse("Gc.freeMem", StringUtil.b2mb(rt.freeMemory()))); + for (World wd : Bukkit.getWorlds()) + sender.sendMessage(I18n.parse("World.info", wd.getName(), wd.getEnvironment().toString(), wd.getLoadedChunks().length, wd.getEntities().size(), wd.getPlayers().size())); + }; + + @Override + public String getDescription() { + return "清理内存"; + } + + @Override + public int getMinimumArguments() { + return 0; + } + + @Override + public String getPossibleArguments() { + return ""; + } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; + } +} diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandHat.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandHat.java index cf4697e..a08fd03 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandHat.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandHat.java @@ -6,7 +6,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import cn.citycraft.SimpleEssential.SimpleEssential; -import cn.citycraft.SimpleEssential.config.Language; +import cn.citycraft.SimpleEssential.config.I18n; /** * @Author 代小呆 created in 2015年8月16日下午1:44:22 @@ -23,8 +23,26 @@ public class CommandHat extends BaseCommand { } @Override - public String getPossibleArguments() { - return ""; + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + Player p = (Player) sender; + if (p.getItemInHand() == null) { + sender.sendMessage(I18n.parse("Hat.empty")); + return; + } else { + ItemStack hand = p.getItemInHand(); + p.setItemInHand(null); + ItemStack helmet = p.getInventory().getHelmet(); + if (!(helmet == null)) + p.getInventory().addItem(helmet); + p.getInventory().setHelmet(hand); + sender.sendMessage(I18n.parse("Hat.enjoy")); + } + + } + + @Override + public String getDescription() { + return "把手上的方块带在手上"; } @Override @@ -33,22 +51,8 @@ public class CommandHat extends BaseCommand { } @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - Player p = (Player) sender; - if (p.getItemInHand() == null) { - sender.sendMessage(Language.getMessage("Hat.empty")); - return; - } else { - ItemStack hand = p.getItemInHand(); - p.setItemInHand(null); - ItemStack helmet = p.getInventory().getHelmet(); - if (!(helmet == null)) { - p.getInventory().addItem(helmet); - } - p.getInventory().setHelmet(hand); - sender.sendMessage(Language.getMessage("Hat.enjoy")); - } - + public String getPossibleArguments() { + return ""; } @Override diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandHome.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandHome.java index 364c02d..abc4f02 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandHome.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandHome.java @@ -9,11 +9,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import cn.citycraft.SimpleEssential.SimpleEssential; -import cn.citycraft.SimpleEssential.config.Language; +import cn.citycraft.SimpleEssential.config.I18n; /** * 传送回家的命令 - * + * * @author 蒋天蓓 2015年8月12日下午2:04:05 */ public class CommandHome extends BaseCommand { @@ -27,20 +27,20 @@ public class CommandHome extends BaseCommand { this.plugin = main; } - @Override - public boolean isOnlyPlayerExecutable() { - return true; - }; - @Override public void execute(CommandSender sender, String label, String[] args) throws CommandException { Player p = (Player) sender; Location loc = p.getBedSpawnLocation(); if (loc == null) { - p.sendMessage(Language.getMessage("Teleport.homelose")); + p.sendMessage(I18n.parse("Teleport.homelose")); return; } plugin.tpcontrol.magicTeleport(p, loc); + }; + + @Override + public String getDescription() { + return "回到家"; } @Override @@ -52,4 +52,9 @@ public class CommandHome extends BaseCommand { public String getPossibleArguments() { return ""; } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; + } } diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetHome.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetHome.java index 732766b..feeb722 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetHome.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetHome.java @@ -10,11 +10,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import cn.citycraft.SimpleEssential.SimpleEssential; -import cn.citycraft.SimpleEssential.config.Language; +import cn.citycraft.SimpleEssential.config.I18n; /** * 设置家的命令 - * + * * @author 蒋天蓓 2015年8月12日下午2:04:05 */ public class CommandSetHome extends BaseCommand { @@ -25,21 +25,20 @@ public class CommandSetHome extends BaseCommand { this.plugin = main; } - @Override - public boolean isOnlyPlayerExecutable() { - return true; - }; - @Override public void execute(CommandSender sender, String label, String[] args) throws CommandException { Player p = (Player) sender; Block b = p.getLocation().getBlock(); if (b.getType() == Material.BED_BLOCK) { p.setBedSpawnLocation(b.getLocation(), true); - p.sendMessage(Language.getMessage("Teleport.sethomesuccess")); - } else { - p.sendMessage(Language.getMessage("Teleport.sethomeerror")); - } + p.sendMessage(I18n.parse("Teleport.sethomesuccess")); + } else + p.sendMessage(I18n.parse("Teleport.sethomeerror")); + }; + + @Override + public String getDescription() { + return "设置家"; } @Override @@ -51,4 +50,9 @@ public class CommandSetHome extends BaseCommand { public String getPossibleArguments() { return ""; } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; + } } diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetSpawn.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetSpawn.java index 9b95674..f9a862d 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetSpawn.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetSpawn.java @@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import cn.citycraft.SimpleEssential.SimpleEssential; -import cn.citycraft.SimpleEssential.config.Language; +import cn.citycraft.SimpleEssential.config.I18n; /** * @author 蒋天蓓 2015年8月12日下午2:04:05 @@ -30,9 +30,14 @@ public class CommandSetSpawn extends BaseCommand { Player p = (Player) sender; Location loc = p.getLocation(); p.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); - p.sendMessage(Language.getMessage("Teleport.setspawn", p.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + p.sendMessage(I18n.parse("Teleport.setspawn", p.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); }; + @Override + public String getDescription() { + return "设置出生点"; + } + @Override public int getMinimumArguments() { return 0; diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSpawn.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSpawn.java index aa7c61a..74f6685 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSpawn.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSpawn.java @@ -29,6 +29,11 @@ public class CommandSpawn extends BaseCommand { plugin.tpcontrol.magicTeleport(p, p.getWorld().getSpawnLocation()); }; + @Override + public String getDescription() { + return "回到主城"; + } + @Override public int getMinimumArguments() { return 0; diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSuicide.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSuicide.java index 4a33d75..2469a4a 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSuicide.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSuicide.java @@ -12,7 +12,7 @@ import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.inventory.ItemStack; import cn.citycraft.SimpleEssential.SimpleEssential; -import cn.citycraft.SimpleEssential.config.Language; +import cn.citycraft.SimpleEssential.config.I18n; import cn.citycraft.SimpleEssential.utils.EffectUtil; /** @@ -30,22 +30,12 @@ public class CommandSuicide extends BaseCommand { } - @Override - public String getPossibleArguments() { - return ""; - } - - @Override - public int getMinimumArguments() { - return 0; - } - @Override public void execute(CommandSender sender, String label, String[] args) throws CommandException { Player p = (Player) sender; List drops = Arrays.asList(p.getInventory().getContents()); int deoppedexp = (int) Math.floor(p.getExp()); - String deathMessage = Language.getMessage("Suicide.msg"); + String deathMessage = I18n.parse("Suicide.msg"); PlayerDeathEvent pd = new PlayerDeathEvent(p, drops, deoppedexp, deathMessage); plugin.getServer().getPluginManager().callEvent(pd); Bukkit.broadcastMessage(pd.getDeathMessage()); @@ -53,6 +43,21 @@ public class CommandSuicide extends BaseCommand { p.setHealth(0); } + @Override + public String getDescription() { + return "自杀"; + } + + @Override + public int getMinimumArguments() { + return 0; + } + + @Override + public String getPossibleArguments() { + return ""; + } + @Override public boolean isOnlyPlayerExecutable() { return true; diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTop.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTop.java index 725b170..ffc225b 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTop.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTop.java @@ -1,5 +1,5 @@ /** - * + * */ package cn.citycraft.SimpleEssential.command; @@ -9,14 +9,14 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import cn.citycraft.SimpleEssential.SimpleEssential; -import cn.citycraft.SimpleEssential.config.Language; +import cn.citycraft.SimpleEssential.config.I18n; /** * 传送到顶部命令 - * + * * @author 蒋天蓓 * 2015年8月12日下午2:04:05 - * + * */ public class CommandTop extends BaseCommand { SimpleEssential plugin; @@ -30,13 +30,18 @@ public class CommandTop extends BaseCommand { } @Override - public boolean isOnlyPlayerExecutable() { - return true; + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + Player p = (Player) sender; + Location loc = p.getLocation(); + int top = loc.getWorld().getHighestBlockYAt(loc); + loc.setY(top); + p.teleport(loc); + p.sendMessage(I18n.parse("Teleport.top")); }; @Override - public String getPossibleArguments() { - return ""; + public String getDescription() { + return "传送到最高点"; } @Override @@ -45,12 +50,12 @@ public class CommandTop extends BaseCommand { } @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - Player p = (Player) sender; - Location loc = p.getLocation(); - int top = loc.getWorld().getHighestBlockYAt(loc); - loc.setY(top); - p.teleport(loc); - p.sendMessage(Language.getMessage("Teleport.top")); + public String getPossibleArguments() { + return ""; + } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; } } diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpa.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpa.java index 9cf7bb0..81f2723 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpa.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpa.java @@ -1,5 +1,5 @@ /** - * + * */ package cn.citycraft.SimpleEssential.command; @@ -9,12 +9,12 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import cn.citycraft.SimpleEssential.SimpleEssential; -import cn.citycraft.SimpleEssential.config.Language; +import cn.citycraft.SimpleEssential.config.I18n; import cn.citycraft.SimpleEssential.teleport.TeleportType; /** * 玩家传送命令 - * + * * @author 蒋天蓓 * 2015年8月12日下午2:04:05 * @@ -31,13 +31,22 @@ public class CommandTpa extends BaseCommand { } @Override - public boolean isOnlyPlayerExecutable() { - return true; + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + Player target = Bukkit.getPlayer(args[0]); + if (target == null) { + sender.sendMessage(I18n.parse("Base.offline", args[0])); + return; + } + plugin.tpcontrol.addtp((Player) sender, Bukkit.getPlayer(args[0]), TeleportType.TPA); + sender.sendMessage(I18n.parse("Teleport.tpsend")); + target.sendMessage(new String[] { I18n.parse("Teleport.tpa", sender.getName()), + I18n.parse("Teleport.tpaccept"), + I18n.parse("Teleport.tpdeny") }); }; @Override - public String getPossibleArguments() { - return "<目标玩家>"; + public String getDescription() { + return "传送到玩家"; } @Override @@ -46,18 +55,12 @@ public class CommandTpa extends BaseCommand { } @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - Player target = Bukkit.getPlayer(args[0]); - if (target == null) { - sender.sendMessage(Language.getMessage("Base.offline", args[0])); - return; - } - plugin.tpcontrol.addtp((Player) sender, Bukkit.getPlayer(args[0]), TeleportType.TPA); - sender.sendMessage(Language.getMessage("Teleport.tpsend")); - target.sendMessage(new String[] { - Language.getMessage("Teleport.tpa", sender.getName()), - Language.getMessage("Teleport.tpaccept"), - Language.getMessage("Teleport.tpdeny") - }); + public String getPossibleArguments() { + return "<目标玩家>"; + } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; } } diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpaccept.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpaccept.java index 17e4ddc..3177ce2 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpaccept.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpaccept.java @@ -1,5 +1,5 @@ /** - * + * */ package cn.citycraft.SimpleEssential.command; @@ -11,10 +11,10 @@ import cn.citycraft.SimpleEssential.SimpleEssential; /** * 接受传送命令 - * + * * @author 蒋天蓓 * 2015年8月12日下午2:04:05 - * + * */ public class CommandTpaccept extends BaseCommand { SimpleEssential plugin; @@ -28,13 +28,13 @@ public class CommandTpaccept extends BaseCommand { } @Override - public boolean isOnlyPlayerExecutable() { - return true; + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + plugin.tpcontrol.accept((Player) sender); }; @Override - public String getPossibleArguments() { - return ""; + public String getDescription() { + return "接受传送"; } @Override @@ -43,7 +43,12 @@ public class CommandTpaccept extends BaseCommand { } @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - plugin.tpcontrol.accept((Player) sender); + public String getPossibleArguments() { + return ""; + } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; } } diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpdeny.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpdeny.java index 3cfa434..af7607a 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpdeny.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpdeny.java @@ -1,5 +1,5 @@ /** - * + * */ package cn.citycraft.SimpleEssential.command; @@ -11,10 +11,10 @@ import cn.citycraft.SimpleEssential.SimpleEssential; /** * 拒绝传送命令 - * + * * @author 蒋天蓓 * 2015年8月12日下午2:04:05 - * + * */ public class CommandTpdeny extends BaseCommand { SimpleEssential plugin; @@ -25,13 +25,14 @@ public class CommandTpdeny extends BaseCommand { } @Override - public boolean isOnlyPlayerExecutable() { - return true; + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + plugin.tpcontrol.accept((Player) sender); + }; @Override - public String getPossibleArguments() { - return ""; + public String getDescription() { + return "拒绝传送"; } @Override @@ -40,8 +41,12 @@ public class CommandTpdeny extends BaseCommand { } @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - plugin.tpcontrol.accept((Player) sender); + public String getPossibleArguments() { + return ""; + } + @Override + public boolean isOnlyPlayerExecutable() { + return true; } } diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTphere.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTphere.java index 16e37b4..ff6ad51 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTphere.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTphere.java @@ -9,12 +9,12 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import cn.citycraft.SimpleEssential.SimpleEssential; -import cn.citycraft.SimpleEssential.config.Language; +import cn.citycraft.SimpleEssential.config.I18n; import cn.citycraft.SimpleEssential.teleport.TeleportType; /** * 传送到玩家命令 - * + * * @author 蒋天蓓 2015年8月12日下午2:04:05 */ public class CommandTphere extends BaseCommand { @@ -29,21 +29,19 @@ public class CommandTphere extends BaseCommand { public void execute(CommandSender sender, String label, String[] args) throws CommandException { Player target = Bukkit.getPlayer(args[0]); if (target == null) { - sender.sendMessage(Language.getMessage("Base.offline", args[0])); + sender.sendMessage(I18n.parse("Base.offline", args[0])); return; } plugin.tpcontrol.addtp((Player) sender, Bukkit.getPlayer(args[0]), TeleportType.TPH); - sender.sendMessage(Language.getMessage("Teleport.tpsend")); - target.sendMessage(new String[] { - Language.getMessage("Teleport.tphere", sender.getName()), - Language.getMessage("Teleport.tpaccept"), - Language.getMessage("Teleport.tpdeny") - }); + sender.sendMessage(I18n.parse("Teleport.tpsend")); + target.sendMessage(new String[] { I18n.parse("Teleport.tphere", sender.getName()), + I18n.parse("Teleport.tpaccept"), + I18n.parse("Teleport.tpdeny") }); } @Override - public boolean isOnlyPlayerExecutable() { - return true; + public String getDescription() { + return "邀请玩家"; }; @Override @@ -55,4 +53,9 @@ public class CommandTphere extends BaseCommand { public String getPossibleArguments() { return "<目标玩家>"; } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; + } } diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandWorkBench.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandWorkBench.java index e5d77eb..56b9f54 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandWorkBench.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandWorkBench.java @@ -24,13 +24,13 @@ public class CommandWorkBench extends BaseCommand { } @Override - public boolean isOnlyPlayerExecutable() { - return true; + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + Bukkit.getPlayer(sender.getName()).openWorkbench(null, true); }; @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - Bukkit.getPlayer(sender.getName()).openWorkbench(null, true); + public String getDescription() { + return "随身工作台"; } @Override @@ -42,4 +42,9 @@ public class CommandWorkBench extends BaseCommand { public String getPossibleArguments() { return ""; } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; + } } diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandWorld.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandWorld.java new file mode 100644 index 0000000..7134b68 --- /dev/null +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandWorld.java @@ -0,0 +1,65 @@ +/** + * + */ +package cn.citycraft.SimpleEssential.command; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import cn.citycraft.SimpleEssential.SimpleEssential; +import cn.citycraft.SimpleEssential.config.I18n; + +/** + * @author 蒋天蓓 2015年8月12日下午2:04:05 + */ +public class CommandWorld extends BaseCommand { + SimpleEssential plugin; + + /** + * @param name + */ + public CommandWorld(SimpleEssential main) { + super("world", "seworld"); + this.plugin = main; + } + + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + Player p = (Player) sender; + switch (args.length) { + case 0: + p.sendMessage(I18n.parse("World.title")); + for (World wd : Bukkit.getWorlds()) + p.sendMessage(I18n.parse("World.info", wd.getName(), wd.getEnvironment().toString(), wd.getLoadedChunks().length, wd.getEntities().size(), wd.getPlayers().size())); + case 1: + World wd = Bukkit.getWorld(args[1]); + if (wd != null) + p.teleport(wd.getSpawnLocation()); + else + p.sendMessage(I18n.parse("World.unknow", args[1])); + } + }; + + @Override + public String getDescription() { + return ""; + } + + @Override + public int getMinimumArguments() { + return 0; + } + + @Override + public String getPossibleArguments() { + return "[世界名称|世界序号]"; + } + + @Override + public boolean isOnlyPlayerExecutable() { + return true; + } +} diff --git a/src/main/java/cn/citycraft/SimpleEssential/config/Language.java b/src/main/java/cn/citycraft/SimpleEssential/config/I18n.java similarity index 64% rename from src/main/java/cn/citycraft/SimpleEssential/config/Language.java rename to src/main/java/cn/citycraft/SimpleEssential/config/I18n.java index 69aec4e..1cee226 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/config/Language.java +++ b/src/main/java/cn/citycraft/SimpleEssential/config/I18n.java @@ -4,16 +4,16 @@ import org.bukkit.plugin.Plugin; import cn.citycraft.config.FileConfig; -public class Language { +public class I18n { private static String CONFIG_NAME = "language.yml"; private static FileConfig config; - public static String getMessage(String path) { + public static String parse(String path) { return config.getMessage(path); } - public static String getMessage(String path, Object... args) { - return String.format(getMessage(path), args); + public static String parse(String path, Object... args) { + return String.format(parse(path), args); } public static void load(Plugin p) { diff --git a/src/main/java/cn/citycraft/SimpleEssential/teleport/TeleportControl.java b/src/main/java/cn/citycraft/SimpleEssential/teleport/TeleportControl.java index 73884af..61149d4 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/teleport/TeleportControl.java +++ b/src/main/java/cn/citycraft/SimpleEssential/teleport/TeleportControl.java @@ -14,7 +14,7 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import cn.citycraft.SimpleEssential.SimpleEssential; -import cn.citycraft.SimpleEssential.config.Language; +import cn.citycraft.SimpleEssential.config.I18n; import cn.citycraft.SimpleEssential.utils.EffectUtil; /** @@ -46,7 +46,7 @@ public class TeleportControl { Player target = ti.getTarget(); Location loc = null; if (!target.isOnline()) { - player.sendMessage(TpControlName + Language.getMessage("Teleport.offline")); + player.sendMessage(TpControlName + I18n.parse("Teleport.offline")); return; } if (ti.getTptype() == TeleportType.TPA) { @@ -56,12 +56,12 @@ public class TeleportControl { target = player; loc = ti.getTarget().getLocation(); } - player.sendMessage(TpControlName + Language.getMessage("Teleport.accept", target.getDisplayName())); - target.sendMessage(TpControlName + Language.getMessage("Teleport.acceptfrom", player.getDisplayName())); + player.sendMessage(TpControlName + I18n.parse("Teleport.accept", target.getDisplayName())); + target.sendMessage(TpControlName + I18n.parse("Teleport.acceptfrom", player.getDisplayName())); magicTeleport(target, loc, TpDelay); return; } - player.sendMessage(TpControlName + Language.getMessage("Teleport.none")); + player.sendMessage(TpControlName + I18n.parse("Teleport.none")); } /** @@ -89,7 +89,7 @@ public class TeleportControl { if (loc != null) { magicTeleport(player, loc, 3); } else { - player.sendMessage(TpControlName + Language.getMessage("Teleport.nobackloc")); + player.sendMessage(TpControlName + I18n.parse("Teleport.nobackloc")); } } @@ -104,12 +104,12 @@ public class TeleportControl { if (ti != null) { Player target = ti.getTarget(); if (target.isOnline()) { - player.sendMessage(TpControlName + Language.getMessage("Teleport.deny", target.getDisplayName())); - target.sendMessage(TpControlName + Language.getMessage("Teleport.denyfrom", player.getDisplayName())); + player.sendMessage(TpControlName + I18n.parse("Teleport.deny", target.getDisplayName())); + target.sendMessage(TpControlName + I18n.parse("Teleport.denyfrom", player.getDisplayName())); } return; } - player.sendMessage(TpControlName + Language.getMessage("Teleport.none")); + player.sendMessage(TpControlName + I18n.parse("Teleport.none")); } /** @@ -137,7 +137,7 @@ public class TeleportControl { public void magicTeleport(final Player player, final Location loc, final int delay) { int petime = delay * 20 + 10; setLastloc(player, player.getLocation()); - player.sendMessage(TpControlName + Language.getMessage("Teleport.tp", delay, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockZ())); + player.sendMessage(TpControlName + I18n.parse("Teleport.tp", delay, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockZ())); List pe = new ArrayList(); pe.add(new PotionEffect(PotionEffectType.SLOW, petime, 255)); pe.add(new PotionEffect(PotionEffectType.CONFUSION, petime, 255)); diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 67332a8..4f8db58 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -31,4 +31,13 @@ Suicide: #帽子 Hat: empty: '§c看上去你手上什么都没有啊!' - enjoy: '§2享受你的新帽子吧!' \ No newline at end of file + enjoy: '§2享受你的新帽子吧!' +Gc: + Processors: '§6使用核心: §a%s' + maxMem: '§6最大内存: §a%s' + totalMem: '§6已用内存: §a%s' + freeMem: '§6空闲内存: §a%s' +World: + title: '§6当前服务器的启用的世界如下' + info: '§6名称: §a%s §b- §6类型: §a%s §6区块: §a%s §6实体数: §a%s §6玩家数: §a%s' + unknow: '§c未知的世界 §a%s' \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 76ed081..db11b2c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -95,6 +95,18 @@ commands: usage: §6使用 §a/spawn §6返回世界出生点! permission: se.spawn permission-message: §c你没有 的权限来执行此命令! + gc: + description: 清理内存 + aliases: [mem,semem,segc] + usage: §6使用 §a/gc §6清理内存! + permission: se.gc + permission-message: §c你没有 的权限来执行此命令! + world: + description: 清理内存 + aliases: [seworld] + usage: §6使用 §a/world [世界名称|世界序号] §6进行传送! + permission: se.world + permission-message: §c你没有 的权限来执行此命令! permissions: se.*: