diff --git a/src/main/java/cn/citycraft/SimpleEssential/SimpleEssential.java b/src/main/java/cn/citycraft/SimpleEssential/SimpleEssential.java index d37575c..bbaebe6 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/SimpleEssential.java +++ b/src/main/java/cn/citycraft/SimpleEssential/SimpleEssential.java @@ -57,11 +57,11 @@ public class SimpleEssential extends JavaPlugin { for (BaseCommand command : commandlist) if (command.isValidTrigger(label)) { if (!command.hasPermission(sender)) { - sender.sendMessage(I18n.parse("Base.no-permission")); + sender.sendMessage(I18n.p("Base.no-permission")); return true; } if (command.isOnlyPlayerExecutable() && !(sender instanceof Player)) { - sender.sendMessage(I18n.parse("Base.playercommand")); + sender.sendMessage(I18n.p("Base.playercommand")); return true; } if (args.length >= command.getMinimumArguments()) diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandGc.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandGc.java index 582db5e..6dcf089 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandGc.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandGc.java @@ -11,6 +11,7 @@ import org.bukkit.command.CommandSender; import cn.citycraft.SimpleEssential.SimpleEssential; import cn.citycraft.SimpleEssential.config.I18n; import cn.citycraft.utils.StringUtil; +import cn.citycraft.utils.SystemUtil; /** * 传送到顶部命令 @@ -35,12 +36,13 @@ public class CommandGc extends BaseCommand { 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()))); + sender.sendMessage(I18n.p("Gc.runTime", StringUtil.formatDate(SystemUtil.getRunTime()))); + sender.sendMessage(I18n.p("Gc.Processors", rt.availableProcessors())); + sender.sendMessage(I18n.p("Gc.maxMem", StringUtil.b2mb(rt.maxMemory()))); + sender.sendMessage(I18n.p("Gc.totalMem", StringUtil.b2mb(rt.totalMemory()))); + sender.sendMessage(I18n.p("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())); + sender.sendMessage(I18n.p("World.info", wd.getName(), wd.getEnvironment().toString(), wd.getLoadedChunks().length, wd.getEntities().size(), wd.getPlayers().size())); }; @Override diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandHat.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandHat.java index a08fd03..e868a60 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandHat.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandHat.java @@ -26,7 +26,7 @@ public class CommandHat extends BaseCommand { 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")); + sender.sendMessage(I18n.p("Hat.empty")); return; } else { ItemStack hand = p.getItemInHand(); @@ -35,7 +35,7 @@ public class CommandHat extends BaseCommand { if (!(helmet == null)) p.getInventory().addItem(helmet); p.getInventory().setHelmet(hand); - sender.sendMessage(I18n.parse("Hat.enjoy")); + sender.sendMessage(I18n.p("Hat.enjoy")); } } diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandHome.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandHome.java index abc4f02..0c98f2d 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandHome.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandHome.java @@ -32,7 +32,7 @@ public class CommandHome extends BaseCommand { Player p = (Player) sender; Location loc = p.getBedSpawnLocation(); if (loc == null) { - p.sendMessage(I18n.parse("Teleport.homelose")); + p.sendMessage(I18n.p("Teleport.homelose")); return; } plugin.tpcontrol.magicTeleport(p, loc); diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetHome.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetHome.java index feeb722..b0009fc 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetHome.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetHome.java @@ -31,9 +31,9 @@ public class CommandSetHome extends BaseCommand { Block b = p.getLocation().getBlock(); if (b.getType() == Material.BED_BLOCK) { p.setBedSpawnLocation(b.getLocation(), true); - p.sendMessage(I18n.parse("Teleport.sethomesuccess")); + p.sendMessage(I18n.p("Teleport.sethomesuccess")); } else - p.sendMessage(I18n.parse("Teleport.sethomeerror")); + p.sendMessage(I18n.p("Teleport.sethomeerror")); }; @Override diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetSpawn.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetSpawn.java index f9a862d..6f98208 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetSpawn.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSetSpawn.java @@ -30,7 +30,7 @@ public class CommandSetSpawn extends BaseCommand { Player p = (Player) sender; Location loc = p.getLocation(); p.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); - p.sendMessage(I18n.parse("Teleport.setspawn", p.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + p.sendMessage(I18n.p("Teleport.setspawn", p.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); }; @Override diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSuicide.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSuicide.java index 2469a4a..c97e66f 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandSuicide.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandSuicide.java @@ -35,7 +35,7 @@ public class CommandSuicide extends BaseCommand { Player p = (Player) sender; List drops = Arrays.asList(p.getInventory().getContents()); int deoppedexp = (int) Math.floor(p.getExp()); - String deathMessage = I18n.parse("Suicide.msg"); + String deathMessage = I18n.p("Suicide.msg"); PlayerDeathEvent pd = new PlayerDeathEvent(p, drops, deoppedexp, deathMessage); plugin.getServer().getPluginManager().callEvent(pd); Bukkit.broadcastMessage(pd.getDeathMessage()); diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTop.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTop.java index ffc225b..a345733 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTop.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTop.java @@ -36,7 +36,7 @@ public class CommandTop extends BaseCommand { int top = loc.getWorld().getHighestBlockYAt(loc); loc.setY(top); p.teleport(loc); - p.sendMessage(I18n.parse("Teleport.top")); + p.sendMessage(I18n.p("Teleport.top")); }; @Override diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpa.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpa.java index 81f2723..4b52b4e 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpa.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTpa.java @@ -34,14 +34,14 @@ public class CommandTpa extends BaseCommand { 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])); + sender.sendMessage(I18n.p("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") }); + sender.sendMessage(I18n.p("Teleport.tpsend")); + target.sendMessage(new String[] { I18n.p("Teleport.tpa", sender.getName()), + I18n.p("Teleport.tpaccept"), + I18n.p("Teleport.tpdeny") }); }; @Override diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTphere.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTphere.java index ff6ad51..6c7a19f 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandTphere.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandTphere.java @@ -29,14 +29,14 @@ 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(I18n.parse("Base.offline", args[0])); + sender.sendMessage(I18n.p("Base.offline", args[0])); return; } plugin.tpcontrol.addtp((Player) sender, Bukkit.getPlayer(args[0]), TeleportType.TPH); - sender.sendMessage(I18n.parse("Teleport.tpsend")); - target.sendMessage(new String[] { I18n.parse("Teleport.tphere", sender.getName()), - I18n.parse("Teleport.tpaccept"), - I18n.parse("Teleport.tpdeny") }); + sender.sendMessage(I18n.p("Teleport.tpsend")); + target.sendMessage(new String[] { I18n.p("Teleport.tphere", sender.getName()), + I18n.p("Teleport.tpaccept"), + I18n.p("Teleport.tpdeny") }); } @Override diff --git a/src/main/java/cn/citycraft/SimpleEssential/command/CommandWorld.java b/src/main/java/cn/citycraft/SimpleEssential/command/CommandWorld.java index 7134b68..016de8f 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/command/CommandWorld.java +++ b/src/main/java/cn/citycraft/SimpleEssential/command/CommandWorld.java @@ -31,15 +31,15 @@ public class CommandWorld extends BaseCommand { Player p = (Player) sender; switch (args.length) { case 0: - p.sendMessage(I18n.parse("World.title")); + p.sendMessage(I18n.p("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())); + p.sendMessage(I18n.p("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])); + p.sendMessage(I18n.p("World.unknow", args[1])); } }; diff --git a/src/main/java/cn/citycraft/SimpleEssential/config/I18n.java b/src/main/java/cn/citycraft/SimpleEssential/config/I18n.java index 1cee226..fb5e3f9 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/config/I18n.java +++ b/src/main/java/cn/citycraft/SimpleEssential/config/I18n.java @@ -8,15 +8,15 @@ public class I18n { private static String CONFIG_NAME = "language.yml"; private static FileConfig config; - public static String parse(String path) { - return config.getMessage(path); - } - - public static String parse(String path, Object... args) { - return String.format(parse(path), args); - } - public static void load(Plugin p) { config = new FileConfig(p, CONFIG_NAME); } + + public static String p(String path, Object... args) { + return String.format(p(path), args); + } + + public static String p(String path) { + return config.getMessage(path); + } } diff --git a/src/main/java/cn/citycraft/SimpleEssential/teleport/TeleportControl.java b/src/main/java/cn/citycraft/SimpleEssential/teleport/TeleportControl.java index 61149d4..f023611 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/teleport/TeleportControl.java +++ b/src/main/java/cn/citycraft/SimpleEssential/teleport/TeleportControl.java @@ -46,7 +46,7 @@ public class TeleportControl { Player target = ti.getTarget(); Location loc = null; if (!target.isOnline()) { - player.sendMessage(TpControlName + I18n.parse("Teleport.offline")); + player.sendMessage(TpControlName + I18n.p("Teleport.offline")); return; } if (ti.getTptype() == TeleportType.TPA) { @@ -56,12 +56,12 @@ public class TeleportControl { target = player; loc = ti.getTarget().getLocation(); } - player.sendMessage(TpControlName + I18n.parse("Teleport.accept", target.getDisplayName())); - target.sendMessage(TpControlName + I18n.parse("Teleport.acceptfrom", player.getDisplayName())); + player.sendMessage(TpControlName + I18n.p("Teleport.accept", target.getDisplayName())); + target.sendMessage(TpControlName + I18n.p("Teleport.acceptfrom", player.getDisplayName())); magicTeleport(target, loc, TpDelay); return; } - player.sendMessage(TpControlName + I18n.parse("Teleport.none")); + player.sendMessage(TpControlName + I18n.p("Teleport.none")); } /** @@ -86,11 +86,10 @@ public class TeleportControl { */ public void back(Player player) { Location loc = lastlocList.get(player); - if (loc != null) { + if (loc != null) magicTeleport(player, loc, 3); - } else { - player.sendMessage(TpControlName + I18n.parse("Teleport.nobackloc")); - } + else + player.sendMessage(TpControlName + I18n.p("Teleport.nobackloc")); } /** @@ -104,12 +103,12 @@ public class TeleportControl { if (ti != null) { Player target = ti.getTarget(); if (target.isOnline()) { - player.sendMessage(TpControlName + I18n.parse("Teleport.deny", target.getDisplayName())); - target.sendMessage(TpControlName + I18n.parse("Teleport.denyfrom", player.getDisplayName())); + player.sendMessage(TpControlName + I18n.p("Teleport.deny", target.getDisplayName())); + target.sendMessage(TpControlName + I18n.p("Teleport.denyfrom", player.getDisplayName())); } return; } - player.sendMessage(TpControlName + I18n.parse("Teleport.none")); + player.sendMessage(TpControlName + I18n.p("Teleport.none")); } /** @@ -137,7 +136,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 + I18n.parse("Teleport.tp", delay, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockZ())); + player.sendMessage(TpControlName + I18n.p("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)); @@ -149,9 +148,8 @@ public class TeleportControl { @Override public void run() { while (System.currentTimeMillis() < timeoutmark) { - if (player.isOnline()) { + if (player.isOnline()) EffectUtil.run(player.getLocation(), lrng, Effect.MOBSPAWNER_FLAMES, Effect.PORTAL); - } lrng++; try { Thread.sleep(128); @@ -160,14 +158,10 @@ public class TeleportControl { } } }); - plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { - @Override - public void run() { - if (player.isOnline()) { - player.teleport(loc); - } - } - }, delay * 20); + plugin.getServer().getScheduler().runTaskLater(plugin, () -> { + if (player.isOnline()) + player.teleport(loc); + } , delay * 20); } /** diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 4f8db58..3dc7be2 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -1,5 +1,5 @@ #本文件为基础插件的语言配置文件 -version: 1.0 +version: 1.2 #基础语言配置 Base: offline: "§c玩家 %s 不存在或不在线!" @@ -33,11 +33,12 @@ Hat: empty: '§c看上去你手上什么都没有啊!' enjoy: '§2享受你的新帽子吧!' Gc: - Processors: '§6使用核心: §a%s' + runTime: '§6运行时间: §a%s' + Processors: '§6CPU核心: §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' + info: '§a%s §3-- §a%s §6区块: §a%s §6实体数: §a%s §6玩家数: §a%s' unknow: '§c未知的世界 §a%s' \ No newline at end of file