From b9edf12f093c025ce46071bb9c9a9f5de22211f2 Mon Sep 17 00:00:00 2001 From: j502647092 Date: Fri, 14 Aug 2015 13:50:24 +0800 Subject: [PATCH] add Language file and Complete Teleport System... Signed-off-by: j502647092 --- .../SimpleEssential/SimpleEssential.java | 2 + .../SimpleEssential/command/CommandHome.java | 3 +- .../command/CommandSetHome.java | 5 +- .../SimpleEssential/command/CommandTop.java | 3 +- .../SimpleEssential/command/CommandTpa.java | 11 ++-- .../command/CommandTphere.java | 11 ++-- .../SimpleEssential/config/Language.java | 65 +++++++++++++++++++ .../teleport/TeleportControl.java | 37 ++++++----- src/config.yml | 3 +- src/language.yml | 27 ++++++++ 10 files changed, 136 insertions(+), 31 deletions(-) create mode 100644 src/cn/citycraft/SimpleEssential/config/Language.java create mode 100644 src/language.yml diff --git a/src/cn/citycraft/SimpleEssential/SimpleEssential.java b/src/cn/citycraft/SimpleEssential/SimpleEssential.java index 654f3dc..43902dd 100644 --- a/src/cn/citycraft/SimpleEssential/SimpleEssential.java +++ b/src/cn/citycraft/SimpleEssential/SimpleEssential.java @@ -23,6 +23,7 @@ import cn.citycraft.SimpleEssential.command.CommandTpdeny; import cn.citycraft.SimpleEssential.command.CommandTphere; import cn.citycraft.SimpleEssential.command.SimpleEssentialCommand; 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; @@ -84,6 +85,7 @@ public class SimpleEssential extends JavaPlugin { @Override public void onLoad() { Config.load(this, "1.0"); + Language.load(this, "1.0"); } /** diff --git a/src/cn/citycraft/SimpleEssential/command/CommandHome.java b/src/cn/citycraft/SimpleEssential/command/CommandHome.java index ff58944..44ab073 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandHome.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandHome.java @@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import cn.citycraft.SimpleEssential.SimpleEssential; +import cn.citycraft.SimpleEssential.config.Language; /** * @author 蒋天蓓 2015年8月12日下午2:04:05 TODO @@ -29,7 +30,7 @@ public class CommandHome extends SimpleEssentialCommand { Player p = (Player) sender; Location loc = p.getBedSpawnLocation(); if (loc == null) { - p.sendMessage("§c你的床丢失了或者被方块阻挡了!"); + p.sendMessage(Language.getMessage("Teleport.homelose")); return; } plugin.tpcontrol.magicTeleport(p, loc); diff --git a/src/cn/citycraft/SimpleEssential/command/CommandSetHome.java b/src/cn/citycraft/SimpleEssential/command/CommandSetHome.java index 4dfb8aa..441c5df 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandSetHome.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandSetHome.java @@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import cn.citycraft.SimpleEssential.SimpleEssential; +import cn.citycraft.SimpleEssential.config.Language; /** * @author 蒋天蓓 2015年8月12日下午2:04:05 TODO @@ -31,9 +32,9 @@ public class CommandSetHome extends SimpleEssentialCommand { Block b = p.getLocation().getBlock(); if (b.getType() == Material.BED_BLOCK) { p.setBedSpawnLocation(b.getLocation(), true); - p.sendMessage("§a家设置成功!"); + p.sendMessage(Language.getMessage("Teleport.sethomesuccess")); } else { - p.sendMessage("§c请站在床上设置家!"); + p.sendMessage(Language.getMessage("Teleport.sethomeerror")); } } diff --git a/src/cn/citycraft/SimpleEssential/command/CommandTop.java b/src/cn/citycraft/SimpleEssential/command/CommandTop.java index 15df0cf..ad6cefb 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandTop.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandTop.java @@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import cn.citycraft.SimpleEssential.SimpleEssential; +import cn.citycraft.SimpleEssential.config.Language; /** * @author 蒋天蓓 @@ -43,6 +44,6 @@ public class CommandTop extends SimpleEssentialCommand { int top = loc.getWorld().getHighestBlockYAt(loc); loc.setY(top); p.teleport(loc); - p.sendMessage("&a已传送至当前位置最高方块!"); + p.sendMessage(Language.getMessage("Teleport.top")); } } diff --git a/src/cn/citycraft/SimpleEssential/command/CommandTpa.java b/src/cn/citycraft/SimpleEssential/command/CommandTpa.java index 914d1a5..1124bc9 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandTpa.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandTpa.java @@ -9,6 +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.teleport.TeleportType; /** @@ -41,15 +42,15 @@ public class CommandTpa extends SimpleEssentialCommand { public void execute(CommandSender sender, String label, String[] args) throws CommandException { Player target = Bukkit.getPlayer(args[0]); if (target == null) { - sender.sendMessage("§c玩家 " + args[0] + " 不存在或不在线!"); + sender.sendMessage(Language.getMessage("Base.offline", args[0])); return; } plugin.tpcontrol.addtp((Player) sender, Bukkit.getPlayer(args[0]), TeleportType.TPA); - sender.sendMessage("§a已经向玩家 " + target.getDisplayName() + " §a发送传送请求!"); + sender.sendMessage(Language.getMessage("Teleport.tpsend")); target.sendMessage(new String[] { - "§a玩家: " + sender.getName() + "§a请求传送到你这里!", - "§a输入命令/tpaccept 或 /tpok 接受传送", - "§c输入命令/tpdeny 或 /tpno 拒绝传送" + Language.getMessage("Teleport.tpa", sender.getName()), + Language.getMessage("Teleport.tpaccept"), + Language.getMessage("Teleport.tpdeny") }); } } diff --git a/src/cn/citycraft/SimpleEssential/command/CommandTphere.java b/src/cn/citycraft/SimpleEssential/command/CommandTphere.java index bb00a4f..9b825f2 100644 --- a/src/cn/citycraft/SimpleEssential/command/CommandTphere.java +++ b/src/cn/citycraft/SimpleEssential/command/CommandTphere.java @@ -9,6 +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.teleport.TeleportType; /** @@ -26,15 +27,15 @@ public class CommandTphere extends SimpleEssentialCommand { public void execute(CommandSender sender, String label, String[] args) throws CommandException { Player target = Bukkit.getPlayer(args[0]); if (target == null) { - sender.sendMessage("§c玩家 " + args[0] + " 不存在或不在线!"); + sender.sendMessage(Language.getMessage("Base.offline", args[0])); return; } plugin.tpcontrol.addtp((Player) sender, Bukkit.getPlayer(args[0]), TeleportType.TPH); - sender.sendMessage("§a已经向玩家 " + target.getDisplayName() + " §a发送传送请求!"); + sender.sendMessage(Language.getMessage("Teleport.tpsend")); target.sendMessage(new String[] { - "§b玩家: " + sender.getName() + "§b请求你传送到他那里!", - "§a输入命令/tpaccept 或 /tpok 接受传送", - "§c输入命令/tpdeny 或 /tpno 拒绝传送" + Language.getMessage("Teleport.tphere", sender.getName()), + Language.getMessage("Teleport.tpaccept"), + Language.getMessage("Teleport.tpdeny") }); } diff --git a/src/cn/citycraft/SimpleEssential/config/Language.java b/src/cn/citycraft/SimpleEssential/config/Language.java new file mode 100644 index 0000000..b14ebb9 --- /dev/null +++ b/src/cn/citycraft/SimpleEssential/config/Language.java @@ -0,0 +1,65 @@ +package cn.citycraft.SimpleEssential.config; + +import java.io.File; +import java.io.IOException; + +import org.bukkit.plugin.Plugin; + +public class Language extends ConfigLoader { + private static String CONFIG_NAME = "language.yml"; + private static FileConfig instance; + private static File file; + + public Language(Plugin p) { + super(p, CONFIG_NAME); + file = new File(p.getDataFolder(), CONFIG_NAME); + instance = super.getInstance(); + } + + public Language(Plugin p, String ver) { + super(p, CONFIG_NAME, ver); + instance = super.getInstance(); + } + + public static void load(Plugin p) { + new Language(p); + } + + public static void load(Plugin p, String ver) { + new Language(p, ver); + } + + public static FileConfig getInstance() { + return instance; + } + + public static String getMessage(String path, Object... paramVarArgs) { + String message = instance.getString(path); + try { + if (message != null) + message = String.format(message.replaceAll("&", "§"), paramVarArgs); + } catch (Exception e) { + } + return message; + } + + public static String getMessage(String path) { + String message = instance.getString(path); + if (message != null) + message = message.replaceAll("&", "§"); + return message; + } + + public static String[] getStringArray(String path) { + return instance.getStringList(path).toArray(new String[0]); + } + + public static void save() { + try { + instance.save(file); + } catch (IOException e) { + saveError(file); + e.printStackTrace(); + } + } +} diff --git a/src/cn/citycraft/SimpleEssential/teleport/TeleportControl.java b/src/cn/citycraft/SimpleEssential/teleport/TeleportControl.java index fcf522d..3183987 100644 --- a/src/cn/citycraft/SimpleEssential/teleport/TeleportControl.java +++ b/src/cn/citycraft/SimpleEssential/teleport/TeleportControl.java @@ -15,6 +15,7 @@ import org.bukkit.potion.PotionEffectType; import cn.citycraft.SimpleEssential.SimpleEssential; import cn.citycraft.SimpleEssential.config.Config; +import cn.citycraft.SimpleEssential.config.Language; /** * @author 蒋天蓓 2015年8月12日下午2:26:10 传送控制类 @@ -29,13 +30,16 @@ public class TeleportControl { * - 粒子的数量 */ static void pEffect(Location loc, long range) { - int i; - if (range < 2) { - range = 2; - } - for (i = 0; i < range; i++) { - loc.getWorld().playEffect(loc, Effect.LAVA_POP, 10, 100); - loc.getWorld().playEffect(loc, Effect.PORTAL, 10, 100); + try { + int i; + if (range < 2) { + range = 2; + } + for (i = 0; i < range; i++) { + loc.getWorld().playEffect(loc, Effect.LAVA_POP, 10, 100); + loc.getWorld().playEffect(loc, Effect.PORTAL, 10, 100); + } + } catch (Exception e) { } } @@ -47,6 +51,7 @@ public class TeleportControl { public TeleportControl(SimpleEssential plugin) { this.plugin = plugin; + } /** @@ -61,10 +66,9 @@ public class TeleportControl { Player target = ti.getTarget(); Location loc = null; if (!target.isOnline()) { - player.sendMessage("§c目标玩家已离线 传送失败!"); + player.sendMessage(Language.getMessage("Teleport.offline")); return; } - target.sendMessage("§a玩家: " + player.getDisplayName() + "§a受了您的请求!"); if (ti.getTptype() == TeleportType.TPA) { target = ti.getTarget(); loc = player.getLocation(); @@ -72,10 +76,12 @@ public class TeleportControl { target = player; loc = ti.getTarget().getLocation(); } + player.sendMessage(Language.getMessage("Teleport.accept")); + target.sendMessage(Language.getMessage("Teleport.acceptfrom")); magicTeleport(target, loc, TpDelay); return; } - player.sendMessage("§c未找到需要处理的队列!"); + player.sendMessage(Language.getMessage("Teleport.none")); } /** @@ -103,7 +109,7 @@ public class TeleportControl { if (loc != null) { magicTeleport(player, loc, 3); } else { - player.sendMessage("§c未找到可以Back的地点!"); + player.sendMessage(Language.getMessage("Teleport.nobackloc")); } } @@ -116,14 +122,14 @@ public class TeleportControl { public void deny(Player player) { TeleportInfo ti = teleportList.remove(player); if (ti != null) { - player.sendMessage("§c已拒绝玩家的传送请求!"); Player target = ti.getTarget(); if (target.isOnline()) { - target.sendMessage("§c玩家: " + player.getDisplayName() + "§c拒绝了您的请求!"); + player.sendMessage(Language.getMessage("Teleport.deny")); + target.sendMessage(Language.getMessage("Teleport.denyfrom")); } return; } - player.sendMessage("§c未找到需要处理的队列!"); + player.sendMessage(Language.getMessage("Teleport.none")); } /** @@ -151,8 +157,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("§a传送开始 " + delay + "秒 后到达目的地 §d世界: " + loc.getWorld().getName() - + " §3X: " + loc.getBlockX() + " Z: " + loc.getBlockZ() + "!"); + player.sendMessage(Language.getMessage("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/config.yml b/src/config.yml index 5ec2b47..5925039 100644 --- a/src/config.yml +++ b/src/config.yml @@ -3,9 +3,10 @@ version: 1.0 #服务器名称 servername: '' #插件名称 -pluginname: '&6[&b保护系统&6]&r' +pluginname: '&6[&b基础系统&6]&r' #基础传送系统 Teleport: + name: '&6[&b传送系统&6]&r' #所有传送延时 delay: 3 diff --git a/src/language.yml b/src/language.yml new file mode 100644 index 0000000..4ebc1b0 --- /dev/null +++ b/src/language.yml @@ -0,0 +1,27 @@ +#本文件为基础插件的语言配置文件 +version: 1.0 +#基础语言配置 +Base: + offline: "§c玩家 {0} 不存在或不在线!" +#基础传送系统 +Teleport: + tp: '§a传送开始 {0}秒 后到达 目的地 §d世界: {1} §3X: {2} Z: {3}!' + accept: '§a已接受玩家: {0} §a的传送请求!' + acceptfrom: '§a玩家: {0}§a接受了您的请求!' + deny: '§c已拒绝玩家: {0} §c的传送请求!' + denyfrom: '§c玩家: {0}§c拒绝了您的请求!' + offline: '§c目标玩家已离线 本次传送取消!' + none: '§c没有找到需要传送的队列!' + sethomesuccess: '§a家设置成功!' + sethomeerror: '§c请站在床上设置家!' + homelose: '§c你的床丢失了或者被方块阻挡了!' + top: '&a已传送至当前位置最高方块!' + tpsend: '§a已经向玩家 {0} §a发送传送请求!' + tpa: '§a玩家: {0}§a请求传送到你这里!' + tphere: '§b玩家: {0}§b请求你传送到他那里!' + tpaccept: '§a输入命令/tpaccept 或 /tpok 接受传送' + tpdeny: '§c输入命令/tpdeny 或 /tpno 拒绝传送' + nobackloc: '§c未找到可以Back的地点!' + + + Language.getMessage("Teleport.none") \ No newline at end of file