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

update I18n.p and gc add runtime...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-09-14 23:00:06 +08:00
parent f9e2ee8e3e
commit 48654099f1
14 changed files with 58 additions and 61 deletions

View File

@ -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())

View File

@ -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

View File

@ -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"));
}
}

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -35,7 +35,7 @@ public class CommandSuicide extends BaseCommand {
Player p = (Player) sender;
List<ItemStack> 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());

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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]));
}
};

View File

@ -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);
}
}

View File

@ -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<PotionEffect> pe = new ArrayList<PotionEffect>();
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);
}
/**

View File

@ -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'