diff --git a/src/cn/citycraft/SimpleEssential/SimpleEssential.java b/src/cn/citycraft/SimpleEssential/SimpleEssential.java index 05631de..a930870 100644 --- a/src/cn/citycraft/SimpleEssential/SimpleEssential.java +++ b/src/cn/citycraft/SimpleEssential/SimpleEssential.java @@ -1,26 +1,55 @@ /** - * + * */ package cn.citycraft.SimpleEssential; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; import cn.citycraft.SimpleEssential.config.Config; -import cn.citycraft.SimpleEssential.handler.SimpleEssentialCommandHandler; +import cn.citycraft.SimpleEssential.handler.SimpleEssentialCommand; +import cn.citycraft.SimpleEssential.handler.command.CommandBack; +import cn.citycraft.SimpleEssential.handler.command.CommandTpa; +import cn.citycraft.SimpleEssential.handler.command.CommandTpaccept; +import cn.citycraft.SimpleEssential.handler.command.CommandTpdeny; +import cn.citycraft.SimpleEssential.handler.command.CommandTphere; import cn.citycraft.SimpleEssential.handler.teleport.TeleportControl; import cn.citycraft.SimpleEssential.listen.PlayerLocationListen; /** - * @author 蒋天蓓 - * 2015年8月11日下午3:29:32 - * TODO + * @author 蒋天蓓 2015年8月11日下午3:29:32 TODO */ public class SimpleEssential extends JavaPlugin { public TeleportControl tpcontrol; + private List commandlist; @Override - public void onLoad() { - Config.load(this, "1.0"); + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + for (SimpleEssentialCommand command : commandlist) { + if (command.isValidTrigger(label)) { + if (!command.hasPermission(sender)) { + sender.sendMessage(ChatColor.RED + "你没有此命令的权限."); + return true; + } + if (args.length >= command.getMinimumArguments()) { + try { + command.execute(sender, label, args); + return true; + } catch (CommandException e) { + sender.sendMessage(e.getMessage()); + } + } + sender.sendMessage("命令参数错误!"); + } + } + sender.sendMessage("循环结束!"); + return true; } @Override @@ -30,9 +59,30 @@ public class SimpleEssential extends JavaPlugin { @Override public void onEnable() { - new SimpleEssentialCommandHandler(); + commandlist = new ArrayList(); + // registerSubCommand(new AddlineCommand()); + registerSubCommand(new CommandTpa(this)); + registerSubCommand(new CommandTpaccept(this)); + registerSubCommand(new CommandTpdeny(this)); + registerSubCommand(new CommandTphere(this)); + registerSubCommand(new CommandBack(this)); + tpcontrol = new TeleportControl(this); getServer().getPluginManager().registerEvents(new PlayerLocationListen(this), this); } + @Override + public void onLoad() { + Config.load(this, "1.0"); + } + + /** + * 注册命令 + * + * @param subCommand + * - 被注册的命令类 + */ + public void registerSubCommand(SimpleEssentialCommand subCommand) { + commandlist.add(subCommand); + } } diff --git a/src/cn/citycraft/SimpleEssential/handler/SimpleEssentialCommandHandler.java b/src/cn/citycraft/SimpleEssential/handler/SimpleEssentialCommandHandler.java deleted file mode 100644 index 2256589..0000000 --- a/src/cn/citycraft/SimpleEssential/handler/SimpleEssentialCommandHandler.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * - */ -package cn.citycraft.SimpleEssential.handler; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandException; -import org.bukkit.command.CommandSender; - -import cn.citycraft.SimpleEssential.SimpleEssential; -import cn.citycraft.SimpleEssential.handler.command.CommandBack; -import cn.citycraft.SimpleEssential.handler.command.CommandTpa; -import cn.citycraft.SimpleEssential.handler.command.CommandTpaccept; -import cn.citycraft.SimpleEssential.handler.command.CommandTpdeny; - -/** - * @author 蒋天蓓 - * 2015年8月11日下午4:00:35 - * TODO - */ -public class SimpleEssentialCommandHandler extends SimpleEssential { - private List commandlist; - - public SimpleEssentialCommandHandler() { - commandlist = new ArrayList(); - - // registerSubCommand(new AddlineCommand()); - registerSubCommand(new CommandTpa(this)); - registerSubCommand(new CommandTpaccept(this)); - registerSubCommand(new CommandTpdeny(this)); - registerSubCommand(new CommandBack(this)); - } - - /** - * 注册命令 - * - * @param subCommand - * - 被注册的命令类 - */ - public void registerSubCommand(SimpleEssentialCommand subCommand) { - commandlist.add(subCommand); - } - - /** - * 获取命令列表 - * - * @return 命令列表 - */ - public List getSubCommands() { - return new ArrayList(commandlist); - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - for (SimpleEssentialCommand command : commandlist) { - if (command.isValidTrigger(label)) { - if (!command.hasPermission(sender)) { - sender.sendMessage(ChatColor.RED + "你没有此命令的权限."); - return true; - } - if (args.length >= command.getMinimumArguments()) { - try { - command.execute(sender, label, args); - return true; - } catch (CommandException e) { - sender.sendMessage(e.getMessage()); - } - } - } - } - return false; - } -} diff --git a/src/cn/citycraft/SimpleEssential/handler/command/CommandBack.java b/src/cn/citycraft/SimpleEssential/handler/command/CommandBack.java index 29f04a1..6e52102 100644 --- a/src/cn/citycraft/SimpleEssential/handler/command/CommandBack.java +++ b/src/cn/citycraft/SimpleEssential/handler/command/CommandBack.java @@ -1,5 +1,5 @@ /** - * + * */ package cn.citycraft.SimpleEssential.handler.command; @@ -11,9 +11,7 @@ import cn.citycraft.SimpleEssential.SimpleEssential; import cn.citycraft.SimpleEssential.handler.SimpleEssentialCommand; /** - * @author 蒋天蓓 - * 2015年8月12日下午2:04:05 - * TODO + * @author 蒋天蓓 2015年8月12日下午2:04:05 TODO */ public class CommandBack extends SimpleEssentialCommand { SimpleEssential plugin; @@ -22,13 +20,13 @@ public class CommandBack extends SimpleEssentialCommand { * @param name */ public CommandBack(SimpleEssential main) { - super("tpback"); + super("back", "seback"); this.plugin = main; } @Override - public String getPossibleArguments() { - return ""; + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + plugin.tpcontrol.back((Player) sender); } @Override @@ -37,7 +35,7 @@ public class CommandBack extends SimpleEssentialCommand { } @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - plugin.tpcontrol.back((Player) sender); + public String getPossibleArguments() { + return ""; } } diff --git a/src/cn/citycraft/SimpleEssential/handler/command/CommandTphere.java b/src/cn/citycraft/SimpleEssential/handler/command/CommandTphere.java index 6dbf84e..6d3bc83 100644 --- a/src/cn/citycraft/SimpleEssential/handler/command/CommandTphere.java +++ b/src/cn/citycraft/SimpleEssential/handler/command/CommandTphere.java @@ -1,5 +1,5 @@ /** - * + * */ package cn.citycraft.SimpleEssential.handler.command; @@ -13,31 +13,16 @@ import cn.citycraft.SimpleEssential.handler.SimpleEssentialCommand; import cn.citycraft.SimpleEssential.handler.teleport.TeleportType; /** - * @author 蒋天蓓 - * 2015年8月12日下午2:04:05 - * TODO + * @author 蒋天蓓 2015年8月12日下午2:04:05 TODO */ public class CommandTphere extends SimpleEssentialCommand { SimpleEssential plugin; - /** - * @param name - */ public CommandTphere(SimpleEssential main) { super("tphere", "tph"); this.plugin = main; } - @Override - public String getPossibleArguments() { - return "<目标玩家>"; - } - - @Override - public int getMinimumArguments() { - return 1; - } - @Override public void execute(CommandSender sender, String label, String[] args) throws CommandException { Player target = Bukkit.getPlayer(args[0]); @@ -47,10 +32,17 @@ public class CommandTphere extends SimpleEssentialCommand { } plugin.tpcontrol.addtp((Player) sender, Bukkit.getPlayer(args[0]), TeleportType.TPH); sender.sendMessage("已经向玩家 " + target.getDisplayName() + " 发送传送请求!"); - target.sendMessage(new String[] { - "§b玩家: " + sender.getName() + "§b请求你传送到他那里!", - "§a输入命令/tpaccept 或 /tpok 接受传送", - "§c输入命令/tpdeny 或 /tpno 拒绝传送" - }); + target.sendMessage(new String[] { "§b玩家: " + sender.getName() + "§b请求你传送到他那里!", + "§a输入命令/tpaccept 或 /tpok 接受传送", "§c输入命令/tpdeny 或 /tpno 拒绝传送" }); + } + + @Override + public int getMinimumArguments() { + return 1; + } + + @Override + public String getPossibleArguments() { + return "<目标玩家>"; } } diff --git a/src/cn/citycraft/SimpleEssential/handler/teleport/TeleportControl.java b/src/cn/citycraft/SimpleEssential/handler/teleport/TeleportControl.java index d0120f4..c49fa28 100644 --- a/src/cn/citycraft/SimpleEssential/handler/teleport/TeleportControl.java +++ b/src/cn/citycraft/SimpleEssential/handler/teleport/TeleportControl.java @@ -1,9 +1,11 @@ /** - * + * */ package cn.citycraft.SimpleEssential.handler.teleport; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import org.bukkit.Effect; import org.bukkit.Location; @@ -15,37 +17,41 @@ import cn.citycraft.SimpleEssential.SimpleEssential; import cn.citycraft.SimpleEssential.config.Config; /** - * @author 蒋天蓓 - * 2015年8月12日下午2:26:10 - * 传送控制类 + * @author 蒋天蓓 2015年8月12日下午2:26:10 传送控制类 */ public class TeleportControl { + /** + * 粒子发生器 + * + * @param loc + * - 粒子产生的地点 + * @param range + * - 粒子的数量 + */ + 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); + } + } + protected HashMap teleportList = new HashMap(); protected HashMap lastlocList = new HashMap(); private SimpleEssential plugin; + private int TpDelay = Config.getInstance().getInt("Teleport.delay", 3); public TeleportControl(SimpleEssential plugin) { this.plugin = plugin; } - /** - * 添加传送请求到传送列表 - * - * @param player - * - 发出请求的玩家 - * @param target - * - 目标玩家 - * @param tptype - * - 传送类型 - */ - public void addtp(Player player, Player target, TeleportType tptype) { - teleportList.put(target, new TeleportInfo(player, tptype)); - } - /** * 玩家接受传送请求 - * + * * @param player * - 执行的玩家 */ @@ -72,9 +78,38 @@ public class TeleportControl { player.sendMessage("§c未找到需要处理的队列!"); } + /** + * 添加传送请求到传送列表 + * + * @param player + * - 发出请求的玩家 + * @param target + * - 目标玩家 + * @param tptype + * - 传送类型 + */ + public void addtp(Player player, Player target, TeleportType tptype) { + teleportList.put(target, new TeleportInfo(player, tptype)); + } + + /** + * 玩家返回上次传送的地点 + * + * @param player + * - 被传送的玩家 + */ + public void back(Player player) { + Location loc = lastlocList.get(player); + if (loc != null) { + magicTeleport(player, loc, 3); + } else { + player.sendMessage("§c未找到可以Back的地点!"); + } + } + /** * 玩家拒绝传送请求 - * + * * @param player * - 执行的玩家 */ @@ -91,36 +126,9 @@ public class TeleportControl { player.sendMessage("§c未找到需要处理的队列!"); } - /** - * 设置最后的地址数据 - * - * @param player - * - 玩家 - * @param loc - * - 地点 - */ - public void setLastloc(Player player, Location loc) { - lastlocList.put(player, loc); - } - - /** - * 玩家返回上次传送的地点 - * - * @param player - * - 被传送的玩家 - */ - public void back(Player player) { - Location loc = lastlocList.get(player); - if (loc != null) { - magicTeleport(player, loc, 3); - } else { - player.sendMessage("§c未找到可以Back的地点!"); - } - } - /** * 魔法传送 - * + * * @param player * - 被传送的玩家 * @param loc @@ -129,10 +137,13 @@ 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 + "秒 后到达目的地 世界: " + loc.getWorld() + " X: " - + loc.getX() + " Z: " + loc.getZ() + "!"); - player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, delay, 255)); + player.sendMessage("§a传送开始 " + delay + "秒 后到达目的地 §d世界: " + loc.getWorld().getName() + + " §3X: " + loc.getBlockX() + " Z: " + loc.getBlockZ() + "!"); + List pe = new ArrayList(); + pe.add(new PotionEffect(PotionEffectType.SLOW, petime, 255)); + player.addPotionEffects(pe); plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { long timeoutmark = System.currentTimeMillis() + delay * 1000; long lrng = 0; @@ -140,11 +151,12 @@ public class TeleportControl { @Override public void run() { while (System.currentTimeMillis() < timeoutmark) { - if (player.isOnline()) + if (player.isOnline()) { pEffect(player.getLocation(), lrng); + } lrng++; try { - Thread.sleep(50); + Thread.sleep(128); } catch (Exception e) { } } @@ -153,27 +165,22 @@ public class TeleportControl { plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { @Override public void run() { - if (player.isOnline()) + if (player.isOnline()) { player.teleport(loc); + } } }, delay * 20); } /** - * 粒子发生器 - * + * 设置最后的地址数据 + * + * @param player + * - 玩家 * @param loc - * - 粒子产生的地点 - * @param range - * - 粒子的数量 + * - 地点 */ - 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); - } + public void setLastloc(Player player, Location loc) { + lastlocList.put(player, loc); } } diff --git a/src/config.yml b/src/config.yml index a712d86..5ec2b47 100644 --- a/src/config.yml +++ b/src/config.yml @@ -9,78 +9,3 @@ pluginname: '&6[&b保护系统&6]&r' Teleport: #所有传送延时 delay: 3 - - - - - - - -#登陆提示 -Tip: - #是否开启 - Enable: false - Message: - - '&a服务器已开启保护功能!' - - '&c将会实时监控您的操作!' - - '&e挖矿请带上火把或药水!' - -#耕地保护配置 -BreakFarm: - #是否开启 - Enable: true - Tip: '&c服务器已开启耕地保护,请不要踩庄稼!' - -#爆炸保护配置 -Explosion: - #是否开启 - Enable: true - -#高频红石检测 -HighRedstone: - #是否开启 - Enable: true - Maxevents: 35 - Find: '&c发现高频红石 &3世界:%world% &d坐标: X:%x% Y:%y% Z:%z% §a已清理!' - Check: '&c高频红石数据监测 &5上述高频红石由 &6玩家:&a%player%& 6放置!' - Admin: '&c发现您放置高频红石,由于您是管理员,在服务器重启之前此高频将不会被清理,请用完后及时清理!' - -#防止无限夜视 -Nightvision: - #是否开启 - Enable: true - Tip: '&c为防止无限夜视作弊,已阻止挖矿,请插火把或用夜视药水!' - -#安全地狱门 -SafeNetherDoor: - #是否开启 - Enable: true - Tip: '&5为防止您卡在地狱门,现在将您传送回主城!' - Set: '&a新的传送点已设置!' - World: world - X: 0 - Y: 70 - Z: 0 - -#刷屏保护 -Spam: - #是否开启 - Enable: true - ChatWait: 3 - SameChatWait: 8 - CommandWait: 2 - SameCommandWait: 3 - MuteCheck: 3 - MuteReset: 3 - TooMuchChat: '请不要短时间内发送大量消息' - TooMuchSameChat: '请不要短时间内发送相同的信息' - TooMuchCommand: '请不要短时间内发送大量命令' - TooMuchSameCommand: '请不要短时间内发送相同的命令' - MuteOn: '&a已允许玩家 %player% &a聊天!' - MuteOff: '§c已禁止玩家 %player% §c聊天!' - OffLine: '&c玩家不存在或不在线!' - NotMute: '&c玩家未被禁言或不存在!' - AdminChatOn: '&a服务器已开启管理员聊天!' - AdminChatOff: '&c服务器已关闭管理员聊天!' - AdminChat: '&c服务器已开启管理员聊天!' - MuteMsg: '&c您由于多次刷屏已被禁言,请联系管理解禁!' diff --git a/src/plugin.yml b/src/plugin.yml index f488868..2f1c462 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -33,12 +33,20 @@ commands: usage: §b使用/tpdeny 拒绝传送或邀请! permission: se.tpdeny permission-message: §c你没有 的权限来执行此命令! + back: + description: 回到上一个TP地点 + aliases: [seback] + usage: §b使用/back 回到上一个TP地点! + permission: se.back + permission-message: §c你没有 的权限来执行此命令! permissions: - se.*: - description: 简单基础插件所有权限! - default: op + se.user: + description: 简单基础插件玩家权限! + default: true children: se.tpa: true se.tphere: true se.tpaccept: true se.tpdeny: true + se.back: true +