From 8b5b8a593ba1325cba05336c1935fae9d2e8d012 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Wed, 20 Jul 2016 10:12:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=91=BD=E4=BB=A4CD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 3 +- .../yumc/TeleportRandom/TeleportRandom.java | 56 ++++++++++++++----- src/main/resources/config.yml | 8 ++- src/main/resources/plugin.yml | 3 + 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 97785db..8025f37 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 pw.yumc TeleportRandom - 1.3.2 + 1.4 TeleportRandom ${project.name} @@ -59,6 +59,7 @@ &a代码重构版本 + &b1.4 - &a添加命令CD...; &b1.3.2 - &c修复上个版本的空指针错误...; &b1.3.1 - &c修复上个版本一个逻辑错误...; &b1.3 - &c修复传送世界限制(区分大小写)...; diff --git a/src/main/java/pw/yumc/TeleportRandom/TeleportRandom.java b/src/main/java/pw/yumc/TeleportRandom/TeleportRandom.java index a7e913b..41b1391 100644 --- a/src/main/java/pw/yumc/TeleportRandom/TeleportRandom.java +++ b/src/main/java/pw/yumc/TeleportRandom/TeleportRandom.java @@ -1,6 +1,8 @@ package pw.yumc.TeleportRandom; +import java.util.HashSet; import java.util.Random; +import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -20,20 +22,27 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor { public final static Random rr = new Random(); public static FileConfig config; + private final Set cd = new HashSet<>(); + @Override public boolean onCommand(final CommandSender sender, final Command cmd, final String string, final String[] args) { - if (args.length == 1 && args[0].equalsIgnoreCase("reload")) { + if (args[0].equalsIgnoreCase("reload")) { config.reload(); sender.sendMessage(getPrefix() + config.getMessage("Message.Reload")); return true; } - if (sender instanceof Player) { - final Player p = (Player) sender; - if (!p.hasPermission("tpr.use")) { - sender.sendMessage(getPrefix() + config.getMessage("Message.NoPerm")); - return true; - } - try { + if (args[0].equalsIgnoreCase("help")) { + sender.sendMessage("玩家: /tpr [范围] [世界]"); + sender.sendMessage("控制台: /tpr <玩家> [范围] [世界]"); + return true; + } + try { + if (sender instanceof Player) { + final Player p = (Player) sender; + if (!p.hasPermission("tpr.use")) { + sender.sendMessage(getPrefix() + config.getMessage("Message.NoPerm")); + return true; + } switch (args.length) { case 0: randomTP(0, p.getWorld(), p); @@ -45,13 +54,24 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor { randomTP(Integer.parseInt(args[0]), Bukkit.getWorld(args[1]), p); break; } - } catch (final IllegalArgumentException e) { - sender.sendMessage(getPrefix() + "§c非法的参数或不存在的世界!"); + + return true; + } else if (args.length > 1) { + final Player p = Bukkit.getPlayer(args[0]); + switch (args.length) { + case 2: + randomTP(Integer.parseInt(args[1]), p.getWorld(), p); + break; + case 3: + randomTP(Integer.parseInt(args[1]), Bukkit.getWorld(args[2]), p); + break; + default: + break; + } } return true; - } else if (args.length > 2) { - randomTP(Integer.parseInt(args[1]), Bukkit.getWorld(args[2]), Bukkit.getPlayer(args[0])); - return true; + } catch (final IllegalArgumentException e) { + sender.sendMessage(getPrefix() + "§c非法的参数或不存在的世界!"); } return false; } @@ -71,6 +91,9 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor { if (world == null || p == null) { throw new IllegalArgumentException(); } + if (!p.hasPermission("tpr.nocd") && cd.contains(p.getName())) { + p.sendMessage(getPrefix() + config.getMessage("Message.CD")); + } if (!config.getStringList("AllowWorld").contains(world.getName())) { p.sendMessage(getPrefix() + config.getMessage("Message.NoPermWorld")); } @@ -89,6 +112,13 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor { final Point point = new Point(lr, world); checkBlock(point, p); point.tp(p); + cd.add(p.getName()); + getServer().getScheduler().runTaskLater(this, new Runnable() { + @Override + public void run() { + cd.remove(p.getName()); + } + }, config.getLong("CD")); } private void checkBlock(final Point point, final Player p) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f0ec0df..093bc44 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,5 @@ #本文件为随机传送插件的主配置文件 -version: 1.0 +version: 1.1 #服务器名称 servername: '' #插件名称 @@ -24,6 +24,8 @@ Message: NoPerm: '&c当前没有使用随机传送的权限!' #当前世界不允许传送 NoPermWorld: '&c当前世界不允许使用随机传送!' + #当前世界不允许传送 + CD: '&c随机传送冷却中!' #允许传送的世界(区分大小写) AllowWorld: - world @@ -31,9 +33,11 @@ AllowWorld: - world_the_end #默认传送距离 -default: 10000 +default: 1000 #最大传送距离 Limit: 10000 +#命令CD时间(单位Tick 1秒=20Tick) +CD: 60 #传送保护列表(不区分大小写) ProtectBlock: diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7faaa5c..c6fa8e7 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -18,6 +18,9 @@ permissions: tpr.use: description: 允许使用随机传送! default: true + tpr.nocd: + description: 允许无CD传送! + default: op tpr.reload: description: 允许重载随机传送! default: op \ No newline at end of file