diff --git a/Knickers/plugin.yml b/Knickers/plugin.yml index 38e3fe4..623e06e 100644 --- a/Knickers/plugin.yml +++ b/Knickers/plugin.yml @@ -2,7 +2,7 @@ name: Knickers main: xiaokai.knickers.Knickers api: - 1.0.0 -version: 1.0d +version: 1.1d load: POSTWORLD website: http://EpicFX.cn description: 多功能菜单,如传送、命令、提示等功能,并且支持多功能个人商店!并且支持自定义商品搜索等!后期还会加入更多功能哦! @@ -12,13 +12,16 @@ loadbefore: commands: mis: description: §9菜单工具主命令 - permission: MiniatureS.Command.main + permission: Knickers.Command.main usage: §b/§6mis §chelp aliases: - miniature - miniatures - 菜单 + - knickers + - 内裤 + - 胖次 permissions: - MiniatureS.Command.main: + Knickers.Command.main: description: 菜单工具主命令 default: true \ No newline at end of file diff --git a/Knickers/resources/Config.yml b/Knickers/resources/Config.yml index 7b40b69..62b011b 100644 --- a/Knickers/resources/Config.yml +++ b/Knickers/resources/Config.yml @@ -1,10 +1,14 @@ #配置开始================== #每个玩家进服的时候都会给一个,当拿着这个玩意右键的时候打开菜单主页,特殊值可以不限定,当特殊值为x时默认匹配所有,特殊值默认为0,当这个值为空(null{在Yml文件内用~表示})时不适用快捷工具! 快捷工具: '347:0' +#当这个值为真时,撤销使用快捷工具打开的事件 +打开撤销: true 货币单位: 金币 检测更新: true 检测更新间隔: 21600 #假如玩家在这个时间段内双击,将无法用快捷工具多次打开主页,防止刷屏 屏蔽玩家双击间隔: 500 仅允许白名单管理菜单: false -白名单: [] \ No newline at end of file +白名单: [] +定时检查快捷工具间隔: 60 +是否允许玩家丢弃快捷工具: false \ No newline at end of file diff --git a/Knickers/resources/Message.yml b/Knickers/resources/Message.yml index ea08796..de4badc 100644 --- a/Knickers/resources/Message.yml +++ b/Knickers/resources/Message.yml @@ -17,12 +17,17 @@ 没有按钮时提示: §4这个页面还不存在按钮哦!快去找管理员添加一个吧~ 权限不足: §4你无权限执行此操作! 金币不足: §4您的{MoneyName}不足!{n}{n}{n}{n} +撤销丢掉快捷工具的提示: §6{ItemName}§f(§9{{ItemID}}§f)§4是你的命根子!你不能丢掉你的命根子! +命令: + 无法打开界面: §4无法打开此界面!{Error} + 未输入想要打开的界面的配置文件名: 请输入想要打开的界面的配置文件名(支持只输入部分) 界面: 打开按钮失败: §4打开按钮失败:§6{Error} 取消按钮: '{RandColor}取消' 返回上级: '{RandColor}返回上级' 执行命令: 标题: §6提示 + 打开失败: §4无法执行该命令!{Error} Tpa界面: 传送请求被拒绝: §6亲爱的§9{TpaPlayer}§6您好, 您的请求已被§8{Player}{Msg}! 发请求的标题: §6提示 diff --git a/Knickers/src/xiaokai/knickers/Knickers.java b/Knickers/src/xiaokai/knickers/Knickers.java index 4780f15..cd67bc7 100644 --- a/Knickers/src/xiaokai/knickers/Knickers.java +++ b/Knickers/src/xiaokai/knickers/Knickers.java @@ -1,94 +1,179 @@ -package xiaokai.knickers; - -import java.time.Duration; -import java.time.Instant; - -import cn.nukkit.Player; -import cn.nukkit.command.Command; -import cn.nukkit.command.CommandSender; -import cn.nukkit.plugin.PluginBase; -import cn.nukkit.plugin.PluginManager; -import cn.nukkit.utils.TextFormat; -import xiaokai.knickers.event.Monitor; -import xiaokai.knickers.event.PlayerEvent; -import xiaokai.knickers.form.MakeForm; -import xiaokai.knickers.mtp.Belle; -import xiaokai.knickers.mtp.Kick; -import xiaokai.tool.Tool; - -/** - * @author Winfxk - */ -public class Knickers extends PluginBase { - private Instant loadTime = Instant.now(); - /** - * 插件缓存数据集合 - */ - protected static Kick kick; - - @Override - public boolean onCommand(CommandSender player, Command command, String label, String[] args) { - new Thread() { - public void run() { - Belle.exMaterials((Player) player); - } - }.start(); - MakeForm.Main((Player) player); - return true; - } - - /** - * 明人不说暗话!这就是插件启动事件 - */ - @Override - public void onEnable() { - super.onEnable(); - PluginManager pm = getServer().getPluginManager(); - pm.registerEvents(new PlayerEvent(kick), this); - pm.registerEvents(new Monitor(kick), this); - this.getServer().getLogger().info(Tool.getColorFont(this.getName() + "启动!") + "§6耗时:§9" - + ((float) (Duration.between(loadTime, Instant.now()).toMillis()) / 1000)); - } - - /** - * 返回货币的名称,如“金币” - * - * @return - */ - public static String getMoneyName() { - return kick.config.getString("货币单位"); - } - - /** - * ????这都看不懂??这是插件关闭事件 - */ - @Override - public void onDisable() { - this.getServer().getLogger() - .info(Tool.getColorFont(this.getName() + "关闭!") + TextFormat.GREEN + "本次运行时长" + TextFormat.BLUE - + Tool.getTimeBy(((float) (Duration.between(loadTime, Instant.now()).toMillis()) / 1000))); - super.onDisable(); - } - - /** - * PY已准备好!插件加载事件 - */ - @Override - public void onLoad() { - this.getServer().getLogger().info(Tool.getColorFont(this.getName() + "正在加载...")); - kick = new Kick(this); - } - - public static Kick getKick() { - return kick; - } - - /** - * 快来和本插件PY交易吧~ - * - * @return 插件主类对象 - */ - public static Knickers getPY() { - return kick.mis; - } -} +package xiaokai.knickers; + +import java.io.File; +import java.time.Duration; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; + +import cn.nukkit.Player; +import cn.nukkit.command.Command; +import cn.nukkit.command.CommandSender; +import cn.nukkit.plugin.PluginBase; +import cn.nukkit.plugin.PluginManager; +import cn.nukkit.utils.TextFormat; +import xiaokai.knickers.event.Monitor; +import xiaokai.knickers.event.PlayerEvent; +import xiaokai.knickers.form.MakeForm; +import xiaokai.knickers.mtp.Belle; +import xiaokai.knickers.mtp.Kick; +import xiaokai.tool.Tool; + +/** + * @author Winfxk + */ +@SuppressWarnings("unchecked") +public class Knickers extends PluginBase { + private Instant loadTime = Instant.now(); + /** + * 插件缓存数据集合 + */ + protected static Kick kick; + + @Override + public boolean onCommand(CommandSender player, Command command, String label, String[] args) { + if (player.isPlayer()) { + new Thread() { + public void run() { + Belle.exMaterials((Player) player); + } + }.start(); + if (args.length < 1) + return MakeForm.Main((Player) player); + } else if (args.length < 1) + return false; + switch (args[0]) { + case "help": + case "h": + case "帮助": + player.sendMessage( + "§4=====§6=====§a=====§e=====§f[§9命令帮助§f]§e=====§a=====§6=====§4=====\n§f/§bmis §dhelp §c:§9打开命令帮助\n§f/§bmis §dadmin §2<§3玩家名§2> §c:§9添加或删除管理员权限\n§f/§bmis §dshow §2<§3文件名§2> §c:§9打开一个界面[文件名支持只写部分]\n§f/§bmis §dui §c:§9打开主页面\n§f/§bmis §c:§9打开主页并且检查是否拥有快捷工具"); + return true; + case "admin": + case "a": + case "管理": + if (!Kick.isAdmin(player)) { + player.sendMessage(kick.Message.getMessage("权限不足")); + return true; + } + if (args.length < 2 || args[1] == null || args[1].isEmpty()) { + player.sendMessage("§4请输入想要添加或删除管理员的玩家名称!"); + return true; + } + List list = kick.config.getList("白名单") == null ? new ArrayList() + : kick.config.getList("白名单"); + if (list.contains(args[1])) { + for (int i = 0; i < list.size(); i++) + if (list.get(i).equals(args[1])) + list.remove(i); + } else + list.add(args[1]); + kick.config.set("白名单", list); + if (kick.config.save()) + player.sendMessage("§6您已" + (list.contains(args[1]) ? "§e添加§9" : "§4删除§9") + args[1] + "§6的管理员权限"); + else + player.sendMessage("§4设置异常!"); + return true; + case "show": + case "打开": + case "open": + if (!player.isPlayer()) { + player.sendMessage("§4请在游戏内执行此命令!"); + return true; + } + if (args.length < 2 || args[1] == null || args[1].isEmpty()) { + player.sendMessage(kick.Message.getSon("命令", "未输入想要打开的界面的配置文件名", new String[] { "{Player}" }, + new String[] { player.getName() })); + return true; + } + String ConfigName = args[1]; + File dFile = new File(getDataFolder(), Kick.MenuConfigPath); + File file = new File(dFile, ConfigName); + boolean isOK = false; + if (!file.exists()) { + String ConfigNames = (ConfigName.lastIndexOf("yml") == ConfigName.length() - 3) ? ConfigName + : ConfigName + ".yml"; + file = new File(dFile, ConfigNames); + if (!file.exists()) { + for (String FileN : dFile.list()) { + file = new File(dFile, FileN); + if (file.isFile() && FileN.contains(ConfigName)) { + isOK = true; + break; + } + } + } else + isOK = file.isFile(); + } else + isOK = file.isFile(); + if (isOK) + return MakeForm.OpenMenu((Player) player, file); + else + player.sendMessage(kick.Message.getSon("命令", "无法打开界面", new String[] { "{Error}", "{Player}" }, + new Object[] { "找不到该界面", player.getName() })); + return true; + case "ui": + if (!player.isPlayer()) { + player.sendMessage("§4请在游戏内执行此命令!"); + return true; + } + return MakeForm.Main((Player) player); + } + return false; + } + + /** + * 明人不说暗话!这就是插件启动事件 + */ + @Override + public void onEnable() { + super.onEnable(); + PluginManager pm = getServer().getPluginManager(); + pm.registerEvents(new PlayerEvent(kick), this); + pm.registerEvents(new Monitor(kick), this); + this.getServer().getLogger().info(Tool.getColorFont(this.getName() + "启动!") + "§6耗时:§9" + + ((float) (Duration.between(loadTime, Instant.now()).toMillis()) / 1000)); + } + + /** + * 返回货币的名称,如“金币” + * + * @return + */ + public static String getMoneyName() { + return kick.config.getString("货币单位"); + } + + /** + * ????这都看不懂??这是插件关闭事件 + */ + @Override + public void onDisable() { + this.getServer().getLogger() + .info(Tool.getColorFont(this.getName() + "关闭!") + TextFormat.GREEN + "本次运行时长" + TextFormat.BLUE + + Tool.getTimeBy(((float) (Duration.between(loadTime, Instant.now()).toMillis()) / 1000))); + super.onDisable(); + } + + /** + * PY已准备好!插件加载事件 + */ + @Override + public void onLoad() { + this.getServer().getLogger().info(Tool.getColorFont(this.getName() + "正在加载...")); + kick = new Kick(this); + } + + public static Kick getKick() { + return kick; + } + + /** + * 快来和本插件PY交易吧~ + * + * @return 插件主类对象 + */ + public static Knickers getPY() { + return kick.mis; + } +} diff --git a/Knickers/src/xiaokai/knickers/event/PlayerEvent.java b/Knickers/src/xiaokai/knickers/event/PlayerEvent.java index 7ff0eb9..e11c682 100644 --- a/Knickers/src/xiaokai/knickers/event/PlayerEvent.java +++ b/Knickers/src/xiaokai/knickers/event/PlayerEvent.java @@ -1,65 +1,101 @@ -package xiaokai.knickers.event; - -import cn.nukkit.Player; -import cn.nukkit.event.EventHandler; -import cn.nukkit.event.Listener; -import cn.nukkit.event.player.PlayerInteractEvent; -import cn.nukkit.event.player.PlayerInteractEvent.Action; -import cn.nukkit.event.player.PlayerQuitEvent; -import cn.nukkit.event.player.PlayerRespawnEvent; -import xiaokai.knickers.form.MakeForm; -import xiaokai.knickers.mtp.Belle; -import xiaokai.knickers.mtp.Kick; -import xiaokai.knickers.mtp.MyPlayer; - -/** - * @author Winfxk - */ -public class PlayerEvent implements Listener { - private Kick kick; - - public PlayerEvent(Kick kick) { - this.kick = kick; - } -/** - * 玩家脑残了点击东西 - * @param e - */ - @EventHandler - public void onClick(PlayerInteractEvent e) { - Player player = e.getPlayer(); - if ((e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK - || e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) - && Belle.isMaterials(e.getItem())) - MakeForm.Main(player); - } - - /** - * 玩家滚蛋事件 - * - * @param e - */ - @EventHandler - public void onQuit(PlayerQuitEvent e) { - Player player = e.getPlayer(); - if (kick.PlayerDataMap.containsKey(player.getName())) - kick.PlayerDataMap.remove(player.getName()); - } - - /** - * 监听玩家嗝了屁重新破壳的事件 - * - * @param e - */ - @EventHandler - public void onPlayerSpawn(PlayerRespawnEvent e) { - Player player = e.getPlayer(); - if (!kick.PlayerDataMap.containsKey(player.getName())) - kick.PlayerDataMap.put(player.getName(), new MyPlayer(player)); - new Thread() { - public void run() { - Belle.exMaterials(player); - } - }.start(); - } -} +package xiaokai.knickers.event; + +import cn.nukkit.Player; +import cn.nukkit.event.EventHandler; +import cn.nukkit.event.Listener; +import cn.nukkit.event.block.BlockBreakEvent; +import cn.nukkit.event.player.PlayerDropItemEvent; +import cn.nukkit.event.player.PlayerInteractEvent; +import cn.nukkit.event.player.PlayerInteractEvent.Action; +import cn.nukkit.item.Item; +import cn.nukkit.event.player.PlayerQuitEvent; +import cn.nukkit.event.player.PlayerRespawnEvent; +import xiaokai.knickers.form.MakeForm; +import xiaokai.knickers.mtp.Belle; +import xiaokai.knickers.mtp.Kick; +import xiaokai.knickers.mtp.MyPlayer; +import xiaokai.tool.ItemIDSunName; + +/** + * @author Winfxk + */ +public class PlayerEvent implements Listener { + private Kick kick; + + public PlayerEvent(Kick kick) { + this.kick = kick; + } + + @EventHandler + public void onSB(PlayerDropItemEvent e) { + Item item = e.getItem(); + if (kick.config.getBoolean("是否允许玩家丢弃快捷工具") || !Belle.isMaterials(item)) + return; + e.setCancelled(); + Player player = e.getPlayer(); + player.sendMessage(kick.Message.getMessage("撤销丢掉快捷工具的提示", new String[] { "{Player}", "{ItemName}", "{ItemID}" }, + new Object[] { player.getName(), ItemIDSunName.getIDByName(item.getId(), item.getDamage()), + item.getId() + ":" + item.getDamage() })); + } + + /** + * 玩家脑残了砸碎点击东西 + * + * @param e + */ + @EventHandler + public void onBreak(BlockBreakEvent e) { + Player player = e.getPlayer(); + if (Belle.isMaterials(e.getItem())) { + MakeForm.Main(player); + if (kick.config.getBoolean("打开撤销")) + e.setCancelled(); + } + } + + /** + * 玩家脑残了点击东西 + * + * @param e + */ + @EventHandler + public void onClick(PlayerInteractEvent e) { + Player player = e.getPlayer(); + Action ac = e.getAction(); + if ((ac == Action.LEFT_CLICK_AIR || ac == Action.LEFT_CLICK_BLOCK || ac == Action.RIGHT_CLICK_AIR + || ac == Action.RIGHT_CLICK_BLOCK) && Belle.isMaterials(e.getItem())) { + MakeForm.Main(player); + if (kick.config.getBoolean("打开撤销")) + e.setCancelled(); + } + } + + /** + * 玩家滚蛋事件 + * + * @param e + */ + @EventHandler + public void onQuit(PlayerQuitEvent e) { + Player player = e.getPlayer(); + if (kick.PlayerDataMap.containsKey(player.getName())) + kick.PlayerDataMap.remove(player.getName()); + } + + /** + * 监听玩家嗝了屁重新破壳的事件 + * + * @param e + */ + @EventHandler + public void onPlayerSpawn(PlayerRespawnEvent e) { + Player player = e.getPlayer(); + if (!kick.PlayerDataMap.containsKey(player.getName())) + kick.PlayerDataMap.put(player.getName(), new MyPlayer(player)); + new Thread() { + public void run() { + Belle.exMaterials(player); + } + }.start(); + } +} diff --git a/Knickers/src/xiaokai/knickers/form/Dispose.java b/Knickers/src/xiaokai/knickers/form/Dispose.java index 313c7cd..cd5dfe2 100644 --- a/Knickers/src/xiaokai/knickers/form/Dispose.java +++ b/Knickers/src/xiaokai/knickers/form/Dispose.java @@ -1,124 +1,145 @@ -package xiaokai.knickers.form; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import cn.nukkit.Player; -import cn.nukkit.form.response.FormResponseCustom; -import cn.nukkit.form.response.FormResponseSimple; -import cn.nukkit.utils.Config; -import xiaokai.knickers.form.man.AddButton; -import xiaokai.knickers.form.man.DelButton; -import xiaokai.knickers.mtp.Kick; -import xiaokai.knickers.mtp.Message; -import xiaokai.knickers.mtp.MyPlayer; -import xiaokai.tool.ItemIDSunName; -import xiaokai.tool.Tool; - -/** - * @author Winfxk - */ -public class Dispose { - private Player player; - private Kick kick; - - /** - * 数据处理 - * - * @param kick Kick对象 - * @param player 触发事件的玩家对象 - */ - public Dispose(Kick kick, Player player) { - this.kick = kick; - this.player = player; - } - - /** - * 处理来至玩家设置数据的数据 - * - * @param data - * @return - */ - public boolean Setting(FormResponseCustom data) { - String id = data.getInputResponse(0); - if (id == null || id.isEmpty()) - return MakeForm.Tip(player, "§4请输入快捷工具的物品名称或物品ID!"); - id = ItemIDSunName.UnknownToID(id); - String MoneyName = data.getInputResponse(1); - if (MoneyName == null || MoneyName.isEmpty()) - return MakeForm.Tip(player, "§4请输入服务器货币的名称!"); - boolean isUpdate = data.getToggleResponse(2); - String UpdateString = data.getInputResponse(3); - if (UpdateString == null || UpdateString.isEmpty()) - return MakeForm.Tip(player, "§4请输入插件更新间隔时间!"); - int UpdateTime = 0; - if (!Tool.isInteger(UpdateString) || !((UpdateTime = Float.valueOf(UpdateString).intValue()) > 0)) - return MakeForm.Tip(player, "§4插件更新间隔时间仅支持大于零的纯整数!!"); - String ClickTimeString = data.getInputResponse(4); - if (ClickTimeString == null || ClickTimeString.isEmpty()) - return MakeForm.Tip(player, "§4请输入快捷工具屏蔽双击的时间!!"); - int ClickTime = 0; - if (!Tool.isInteger(ClickTimeString) || !((ClickTime = Float.valueOf(ClickTimeString).intValue()) > 0)) - return MakeForm.Tip(player, "§4快捷工具屏蔽双击的时间仅支持大于零的纯整数!!"); - boolean isWh = data.getToggleResponse(5); - List list = new ArrayList(); - String wsString = data.getInputResponse(6); - if (wsString.contains(";")) { - String[] Ws = wsString.split(";"); - for (int i = 0; i < Ws.length; i++) - if (Ws[i] != null && !Ws[i].isEmpty()) - list.add(Ws[i]); - } else - list = Arrays.asList(wsString); - Config config = kick.config; - config.set("快捷工具", id); - config.set("货币单位", MoneyName); - config.set("检测更新", isUpdate); - config.set("检测更新间隔", UpdateTime); - config.set("屏蔽玩家双击间隔", ClickTime); - config.set("仅允许白名单管理菜单", isWh); - config.set("白名单", list); - kick.config = config; - if (config.save()) - return MakeForm.Tip(player, "§6数据保存正常!"); - else - return MakeForm.Tip(player, "§4数据保存可能出现问题!"); - } - - /** - * 接收玩家点击主页控件的事件 - * - * @param data - * @return - */ - public boolean start(FormResponseSimple data) { - Message msg = kick.Message; - MyPlayer myPlayer = kick.PlayerDataMap.get(player.getName()); - int ID = data.getClickedButtonId(); - if (ID >= myPlayer.Items.size()) - if (ID == myPlayer.Items.size()) { - if (myPlayer.OpenMenuList == null || myPlayer.OpenMenuList.size() < 1) - return true; - if (myPlayer.OpenMenuList.size() > 1) { - myPlayer.OpenMenuList.remove(myPlayer.OpenMenuList.size() - 1); - File file = myPlayer.OpenMenuList.get(myPlayer.OpenMenuList.size() - 1); - kick.PlayerDataMap.put(player.getName(), myPlayer); - return MakeForm.OpenMenu(player, file, false, false); - } else if (!myPlayer.isMain) - return MakeForm.Main(player); - else - return true; - } else if (Kick.isAdmin(player)) { - if (ID == myPlayer.Items.size() + 1) - return AddButton.addButton(player, myPlayer.BackFile); - else if (ID == (myPlayer.Items.size() + 2)) - return DelButton.delButton(player, myPlayer.BackFile); - else - return MakeForm.Setting(player); - } else - return MakeForm.Tip(player, msg.getMessage("权限不足")); - return new OpenButton(kick, player, myPlayer.BackFile, myPlayer.Items.get(ID).get("Key").toString()).start(); - } -} +package xiaokai.knickers.form; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import cn.nukkit.Player; +import cn.nukkit.form.response.FormResponseCustom; +import cn.nukkit.form.response.FormResponseSimple; +import cn.nukkit.utils.Config; +import xiaokai.knickers.form.man.AddButton; +import xiaokai.knickers.form.man.DelButton; +import xiaokai.knickers.mtp.Kick; +import xiaokai.knickers.mtp.Message; +import xiaokai.knickers.mtp.MyPlayer; +import xiaokai.tool.ItemIDSunName; +import xiaokai.tool.Tool; + +/** + * @author Winfxk + */ +public class Dispose { + private Player player; + private Kick kick; + + /** + * 数据处理 + * + * @param kick Kick对象 + * @param player 触发事件的玩家对象 + */ + public Dispose(Kick kick, Player player) { + this.kick = kick; + this.player = player; + } + + /** + * 处理来至玩家设置数据的数据 + * + * @param data + * @return + */ + public boolean Setting(FormResponseCustom data) { + String id = data.getInputResponse(0); + if (id == null || id.isEmpty()) + return MakeForm.Tip(player, "§4请输入快捷工具的物品名称或物品ID!"); + id = ItemIDSunName.UnknownToID(id); + String MoneyName = data.getInputResponse(1); + if (MoneyName == null || MoneyName.isEmpty()) + return MakeForm.Tip(player, "§4请输入服务器货币的名称!"); + boolean isUpdate = data.getToggleResponse(2); + String UpdateString = data.getInputResponse(3); + if (UpdateString == null || UpdateString.isEmpty()) + return MakeForm.Tip(player, "§4请输入插件更新间隔时间!"); + int UpdateTime = 0; + if (!Tool.isInteger(UpdateString) || !((UpdateTime = Float.valueOf(UpdateString).intValue()) > 0)) + return MakeForm.Tip(player, "§4插件更新间隔时间仅支持大于零的纯整数!!"); + String ClickTimeString = data.getInputResponse(4); + if (ClickTimeString == null || ClickTimeString.isEmpty()) + return MakeForm.Tip(player, "§4请输入快捷工具屏蔽双击的时间!!"); + int ClickTime = 0; + if (!Tool.isInteger(ClickTimeString) || !((ClickTime = Float.valueOf(ClickTimeString).intValue()) > 0)) + return MakeForm.Tip(player, "§4快捷工具屏蔽双击的时间仅支持大于零的纯整数!!"); + boolean isWh = data.getToggleResponse(5); + List list = new ArrayList(); + String wsString = data.getInputResponse(6); + if (wsString != null && !wsString.isEmpty()) + if (wsString.contains(";")) { + String[] Ws = wsString.split(";"); + for (int i = 0; i < Ws.length; i++) + if (Ws[i] != null && !Ws[i].isEmpty()) + list.add(Ws[i]); + } else + list = Arrays.asList(wsString); + boolean isC = data.getToggleResponse(7); + String sovString = data.getInputResponse(8); + if (sovString == null || sovString.isEmpty()) + return MakeForm.Tip(player, "§4请输入自动检查快捷工具的间隔"); + int SovTime = 0; + if (!Tool.isInteger(sovString) || (SovTime = Float.valueOf(sovString).intValue()) < 1) + return MakeForm.Tip(player, "§4自动检查快捷工具的间隔仅支持大于等于0的纯整数!"); + Config config = kick.config; + boolean isD = data.getToggleResponse(9); + config.set("快捷工具", id); + config.set("货币单位", MoneyName); + config.set("检测更新", isUpdate); + config.set("检测更新间隔", UpdateTime); + config.set("屏蔽玩家双击间隔", ClickTime); + config.set("仅允许白名单管理菜单", isWh); + config.set("白名单", list); + config.set("打开撤销", isC); + config.set("定时检查快捷工具间隔", SovTime); + config.set("是否允许玩家丢弃快捷工具", isD); + kick.config = config; + if (kick.config.save()) + return MakeForm.Tip(player, "§6数据保存正常!\n\n§a各类时间间隔将在检查一次后生效"); + else + return MakeForm.Tip(player, "§4数据保存可能出现问题!"); + } + + /** + * 接收玩家点击主页控件的事件 + * + * @param data + * @return + */ + public boolean start(FormResponseSimple data) { + Message msg = kick.Message; + MyPlayer myPlayer = kick.PlayerDataMap.get(player.getName()); + int ID = data.getClickedButtonId(); + if (ID >= myPlayer.Items.size()) + if (ID == myPlayer.Items.size()) { + if (myPlayer.OpenMenuList == null || myPlayer.OpenMenuList.size() < 1 + || (new File(kick.mis.getDataFolder(), kick.MainFileName).getAbsolutePath() + .equals(myPlayer.BackFile.getAbsolutePath())) + || (myPlayer.OpenMenuList.size() >= 2 && myPlayer.BackFile.getAbsolutePath() + .equals(myPlayer.OpenMenuList.get(myPlayer.OpenMenuList.size() - 2).getAbsolutePath()))) + return true; + if (myPlayer.OpenMenuList.size() > 1) { + File file = myPlayer.OpenMenuList.get(myPlayer.OpenMenuList.size() - 1); + myPlayer.OpenMenuList.remove(myPlayer.OpenMenuList.size() - 1); + while (file.getAbsolutePath().equals(myPlayer.BackFile.getAbsolutePath()) + && myPlayer.OpenMenuList.size() > 0) { + file = myPlayer.OpenMenuList.get(myPlayer.OpenMenuList.size() - 1); + myPlayer.OpenMenuList.remove(myPlayer.OpenMenuList.size() - 1); + } + kick.PlayerDataMap.put(player.getName(), myPlayer); + return MakeForm.OpenMenu(player, file, false, false); + } else if (!myPlayer.isMain) + return MakeForm.Main(player); + else + return true; + } else if (Kick.isAdmin(player)) { + if (ID == myPlayer.Items.size() + 1) + return AddButton.addButton(player, myPlayer.BackFile); + else if (ID == (myPlayer.Items.size() + 2)) + return DelButton.delButton(player, myPlayer.BackFile); + else + return MakeForm.Setting(player); + } else + return MakeForm.Tip(player, msg.getMessage("权限不足")); + return new OpenButton(kick, player, myPlayer.BackFile, myPlayer.Items.get(ID).get("Key").toString()).start(); + } +} diff --git a/Knickers/src/xiaokai/knickers/form/MakeForm.java b/Knickers/src/xiaokai/knickers/form/MakeForm.java index b895030..47fdb1a 100644 --- a/Knickers/src/xiaokai/knickers/form/MakeForm.java +++ b/Knickers/src/xiaokai/knickers/form/MakeForm.java @@ -1,242 +1,246 @@ -package xiaokai.knickers.form; - -import java.io.File; -import java.time.Duration; -import java.time.Instant; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import cn.nukkit.Player; -import cn.nukkit.utils.Config; -import xiaokai.knickers.mtp.Kick; -import xiaokai.knickers.mtp.Message; -import xiaokai.knickers.mtp.MyPlayer; -import xiaokai.tool.CustomForm; -import xiaokai.tool.ModalForm; -import xiaokai.tool.SimpleForm; -import xiaokai.tool.Tool; - -/** - * @author Winfxk - */ -@SuppressWarnings("unchecked") -public class MakeForm { - /** - * 打开一个界面,这个界面是用来设置系统配置的 - * - * @param player - * @return - */ - protected static boolean Setting(Player player) { - Kick kick = Kick.kick; - if (!Kick.isAdmin(player)) - return MakeForm.Tip(player, kick.Message.getMessage("权限不足")); - CustomForm form = new CustomForm(kick.formID.getID(9), Tool.getColorFont(kick.mis.getName() + "-Setting")); - form.addInput("快捷工具的物品ID", kick.config.get("快捷工具"), "请输入物品ID或物品名称,如: " + kick.config.get("快捷工具")); - form.addInput("服务器货币名称", kick.config.get("货币单位"), kick.config.get("货币单位")); - form.addToggle("插件启动时检测更新", kick.config.getBoolean("检测更新")); - int s = Float - .valueOf( - Tool.isInteger(kick.config.get("检测更新间隔")) ? String.valueOf(kick.config.get("检测更新间隔")) : "21600") - .intValue(); - form.addInput("服务器自动更新间隔(单位:秒)", s, "服务器在后台多久检测更新一次,如:" + s); - s = Float.valueOf( - Tool.isInteger(kick.config.get("屏蔽玩家双击间隔")) ? String.valueOf(kick.config.get("屏蔽玩家双击间隔")) : "500") - .intValue(); - form.addInput("屏蔽玩家双击时间(单位:毫秒)", s, "服务器在后台多久检测更新一次,如:" + s); - form.addToggle("仅允许白名单管理菜单", kick.config.getBoolean("仅允许白名单管理菜单")); - String string = ""; - List list = kick.config.getList("白名单"); - if (list.size() > 0) - for (int i = 0; i < list.size(); i++) - string += list.get(i) + (((i + 1) < list.size()) ? ";" : ""); - form.addInput("菜单管理白名单\n如将“仅允许白名单管理菜单”选项关闭则此项可以忽略\n多个玩家请使用;分割", string); - form.sendPlayer(player); - return true; - } - - /** - * 打开一个界面 - * - * @param player 要显示这个界面的玩家对象 - * @param file 要打开的界面的文件对象 - * @return - */ - public static boolean OpenMenu(Player player, File file) { - return OpenMenu(player, file, false); - } - - /** - * 打开一个界面 - * - * @param player 要显示这个界面的玩家对象 - * @param file 要打开的界面的文件对象 - * @param isBack 是否存储该页为上一页 - * @return - */ - public static boolean OpenMenu(Player player, File file, boolean isBack) { - return OpenMenu(player, file, isBack, false); - } - - /** - * 打开一个界面 - * - * @param player 要显示这个界面的玩家对象 - * @param file 要打开的界面的文件对象 - * @param isBack 是否存储该页为上一页 - * @param isMain 是否是主页 - * @return - */ - public static boolean OpenMenu(Player player, File file, boolean isBack, boolean isMain) { - Kick kick = Kick.kick; - Message msg = kick.Message; - MyPlayer myPlayer = kick.PlayerDataMap.get(player.getName()); - if (isBack) - myPlayer.OpenMenuList.add(file); - myPlayer.BackFile = file; - Config config = new Config(file, Config.YAML); - List> Items = new ArrayList>(); - int ID = isMain ? kick.formID.getID(0) : getID(myPlayer); - SimpleForm form = new SimpleForm(ID, - msg.getText(config.getString("Title", ""), new String[] { "{Player}" }, - new Object[] { player.getName() }), - msg.getText(config.getString("Content", ""), new String[] { "{Player}" }, - new Object[] { player.getName() })); - Map Buttons = ((config.get("Buttons") instanceof Map) && config.get("Buttons") != null) - ? (HashMap) config.get("Buttons") - : new HashMap(); - for (String ike : Buttons.keySet()) { - Map Item = ((Buttons.get(ike) instanceof Map) && Buttons.get(ike) != null) - ? (HashMap) Buttons.get(ike) - : new HashMap(); - if (Item.size() > 0) { - String Path = (String) Item.get("IconPath"); - form.addButton(String.valueOf(Item.get("Text")), !String.valueOf(Item.get("IconPath")).equals("2"), - Path == null || Path.isEmpty() ? null : Path); - Item.put("Key", ike); - Items.add(Item); - } - } - if (form.getButtonSize() < 1) - form.setContent(form.getContent() + (form.getContent() != null && !form.getContent().isEmpty() ? "\n" : "") - + msg.getMessage("没有按钮时提示", new String[] { "{Player}" }, new Object[] { player.getName() })); - if (myPlayer.OpenMenuList == null || myPlayer.OpenMenuList.size() < 1 || isMain) { - form.addButton(msg.getSon("界面", "取消按钮", new String[] { "{Player}" }, new Object[] { player.getName() })); - } else - form.addButton(msg.getSon("界面", "返回上级", new String[] { "{Player}" }, new Object[] { player.getName() })); - if (Kick.isAdmin(player)) - form.addButton(Tool.getRandColor() + "添加按钮").addButton(Tool.getRandColor() + "删除按钮") - .addButton(Tool.getRandColor() + "系统设置"); - myPlayer.Items = Items; - myPlayer.isMain = isMain; - kick.PlayerDataMap.put(player.getName(), myPlayer); - form.sendPlayer(player); - return true; - } - - /** - * 创建菜单主页 - * - * @param player - */ - public static boolean Main(Player player) { - Kick kick = Kick.kick; - MyPlayer myPlayer = kick.PlayerDataMap.get(player.getName()); - if (myPlayer.loadTime == null - || Duration.between(myPlayer.loadTime, Instant.now()).toMillis() > kick.config.getInt("屏蔽玩家双击间隔")) - myPlayer.loadTime = Instant.now(); - else - return false; - myPlayer.OpenMenuList = new ArrayList(); - return OpenMenu(player, new File(kick.mis.getDataFolder(), kick.MainFileName), true, true); - } - - public static int getID(MyPlayer myPlayer) { - int i = myPlayer.Formid; - if (i >= 0 && i <= 3) { - i++; - } else - i = 0; - myPlayer.Formid = i; - Kick.kick.PlayerDataMap.put(myPlayer.player.getName(), myPlayer); - return Kick.kick.formID.getID("子页" + i); - } - - /** - * 显示一个弹窗 - * - * @param player 要显示弹窗的玩家对象 - * @param Content 弹窗的内容 - * @return back - */ - public static boolean Tip(Player player, String Content) { - return Tip(player, Tool.getRandColor() + Kick.kick.mis.getName(), Content, false); - } - - /** - * 显示一个弹窗 - * - * @param player 要显示弹窗的玩家对象 - * @param Content 弹窗的内容 - * @param back 返回的布尔值 - * @return back - */ - public static boolean Tip(Player player, String Content, boolean back) { - return Tip(player, Tool.getRandColor() + Kick.kick.mis.getName(), Content, back); - } - - /** - * 显示一个弹窗 - * - * @param player 要显示弹窗的玩家对象 - * @param Title 弹窗的标题 - * @param Content 弹窗的内容 - * @param back 返回的布尔值 - * @return back - */ - public static boolean Tip(Player player, String Title, String Content, boolean back) { - return Tip(player, Title, Content, back, false); - } - - /** - * 显示一个弹窗 - * - * @param player 要显示弹窗的玩家对象 - * @param Title 弹窗的标题 - * @param Content 弹窗的内容 - * @param back 返回的布尔值 - * @param Modal 是否是Modal型弹窗 - * @return back - */ - public static boolean Tip(Player player, String Title, String Content, boolean back, boolean Modal) { - return Tip(player, Title, Content, "确定", "取消", back, Modal); - } - - /** - * 显示一个弹窗 - * - * @param player 要显示弹窗的玩家对象 - * @param Title 弹窗的标题 - * @param Content 弹窗的内容 - * @param Button1 弹窗的第一个按钮文本内容 - * @param Button2 弹窗的第二个按钮文本内容 - * @param back 返回的布尔值 - * @param Modal 是否是Modal型弹窗 - * @return back - */ - public static boolean Tip(Player player, String Title, String Content, String Button1, String Button2, boolean back, - boolean Modal) { - if (Modal) { - ModalForm form = new ModalForm(Tool.getRand(), Title, Button1, Button2); - form.setContent(Content); - form.sendPlayer(player); - } else { - SimpleForm form = new SimpleForm(Tool.getRand(), Title, Content); - form.addButton(Button1).addButton(Button2); - form.sendPlayer(player); - } - return back; - } -} +package xiaokai.knickers.form; + +import java.io.File; +import java.time.Duration; +import java.time.Instant; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import cn.nukkit.Player; +import cn.nukkit.utils.Config; +import xiaokai.knickers.mtp.Kick; +import xiaokai.knickers.mtp.Message; +import xiaokai.knickers.mtp.MyPlayer; +import xiaokai.tool.CustomForm; +import xiaokai.tool.ModalForm; +import xiaokai.tool.SimpleForm; +import xiaokai.tool.Tool; + +/** + * @author Winfxk + */ +@SuppressWarnings("unchecked") +public class MakeForm { + /** + * 打开一个界面,这个界面是用来设置系统配置的 + * + * @param player + * @return + */ + protected static boolean Setting(Player player) { + Kick kick = Kick.kick; + if (!Kick.isAdmin(player)) + return MakeForm.Tip(player, kick.Message.getMessage("权限不足")); + Config config = kick.config; + CustomForm form = new CustomForm(kick.formID.getID(9), Tool.getColorFont(kick.mis.getName() + "-Setting")); + form.addInput("快捷工具的物品ID", config.get("快捷工具"), "请输入物品ID或物品名称,如: " + config.get("快捷工具")); + form.addInput("服务器货币名称", config.get("货币单位"), config.get("货币单位")); + form.addToggle("插件启动时检测更新", config.getBoolean("检测更新")); + int s = Float.valueOf(Tool.isInteger(config.get("检测更新间隔")) ? String.valueOf(config.get("检测更新间隔")) : "21600") + .intValue(); + form.addInput("服务器自动更新间隔(单位:秒)", s, "服务器在后台多久检测更新一次,如:" + s); + s = Float.valueOf(Tool.isInteger(config.get("屏蔽玩家双击间隔")) ? String.valueOf(config.get("屏蔽玩家双击间隔")) : "500") + .intValue(); + form.addInput("屏蔽玩家双击时间(单位:毫秒)", s, "服务器在后台多久检测更新一次,如:" + s); + form.addToggle("仅允许白名单管理菜单", config.getBoolean("仅允许白名单管理菜单")); + String string = ""; + List list = config.getList("白名单"); + if (list.size() > 0) + for (int i = 0; i < list.size(); i++) + string += list.get(i) + (((i + 1) < list.size()) ? ";" : ""); + form.addInput("菜单管理白名单\n如将“仅允许白名单管理菜单”选项关闭则此项可以忽略\n多个玩家请使用;分割", string); + form.addToggle("是否撤销玩家使用快捷工具打开菜单产生的事件", config.getBoolean("打开撤销")); + form.addInput("自动检查玩家是否拥有快捷工具的时间间隔\n当这个值小于等于零时不启用该功能", config.getInt("定时检查快捷工具间隔")); + form.addToggle("是否允许玩家丢弃快捷工具", config.getBoolean("是否允许玩家丢弃快捷工具")); + form.sendPlayer(player); + return true; + } + + /** + * 打开一个界面 + * + * @param player 要显示这个界面的玩家对象 + * @param file 要打开的界面的文件对象 + * @return + */ + public static boolean OpenMenu(Player player, File file) { + return OpenMenu(player, file, false); + } + + /** + * 打开一个界面 + * + * @param player 要显示这个界面的玩家对象 + * @param file 要打开的界面的文件对象 + * @param isBack 是否存储该页为上一页 + * @return + */ + public static boolean OpenMenu(Player player, File file, boolean isBack) { + return OpenMenu(player, file, isBack, false); + } + + /** + * 打开一个界面 + * + * @param player 要显示这个界面的玩家对象 + * @param file 要打开的界面的文件对象 + * @param isBack 是否存储该页为上一页 + * @param isMain 是否是主页 + * @return + */ + public static boolean OpenMenu(Player player, File file, boolean isBack, boolean isMain) { + Kick kick = Kick.kick; + Message msg = kick.Message; + MyPlayer myPlayer = kick.PlayerDataMap.get(player.getName()); + if (isBack) + myPlayer.OpenMenuList.add(file); + Config config = new Config(file, Config.YAML); + List> Items = new ArrayList>(); + int ID = isMain ? kick.formID.getID(0) : getID(myPlayer); + SimpleForm form = new SimpleForm(ID, + msg.getText(config.getString("Title", ""), new String[] { "{Player}" }, + new Object[] { player.getName() }), + msg.getText(config.getString("Content", ""), new String[] { "{Player}" }, + new Object[] { player.getName() })); + Map Buttons = ((config.get("Buttons") instanceof Map) && config.get("Buttons") != null) + ? (HashMap) config.get("Buttons") + : new HashMap(); + for (String ike : Buttons.keySet()) { + Map Item = ((Buttons.get(ike) instanceof Map) && Buttons.get(ike) != null) + ? (HashMap) Buttons.get(ike) + : new HashMap(); + if (Item.size() > 0) { + String Path = (String) Item.get("IconPath"); + form.addButton(String.valueOf(Item.get("Text")), !String.valueOf(Item.get("IconPath")).equals("2"), + Path == null || Path.isEmpty() ? null : Path); + Item.put("Key", ike); + Items.add(Item); + } + } + if (form.getButtonSize() < 1) + form.setContent(form.getContent() + (form.getContent() != null && !form.getContent().isEmpty() ? "\n" : "") + + msg.getMessage("没有按钮时提示", new String[] { "{Player}" }, new Object[] { player.getName() })); + if (myPlayer.OpenMenuList == null || myPlayer.OpenMenuList.size() < 1 || isMain + || file.getAbsolutePath() + .equals(new File(kick.mis.getDataFolder(), kick.MainFileName).getAbsolutePath()) + || (myPlayer.BackFile != null && file.getAbsolutePath().equals(myPlayer.BackFile.getAbsolutePath()))) { + form.addButton(msg.getSon("界面", "取消按钮", new String[] { "{Player}" }, new Object[] { player.getName() })); + } else + form.addButton(msg.getSon("界面", "返回上级", new String[] { "{Player}" }, new Object[] { player.getName() })); + if (Kick.isAdmin(player)) + form.addButton(Tool.getRandColor() + "添加按钮").addButton(Tool.getRandColor() + "删除按钮") + .addButton(Tool.getRandColor() + "系统设置"); + myPlayer.BackFile = file; + myPlayer.Items = Items; + myPlayer.isMain = isMain; + kick.PlayerDataMap.put(player.getName(), myPlayer); + form.sendPlayer(player); + return true; + } + + /** + * 创建菜单主页 + * + * @param player + */ + public static boolean Main(Player player) { + Kick kick = Kick.kick; + MyPlayer myPlayer = kick.PlayerDataMap.get(player.getName()); + if (myPlayer.loadTime == null + || Duration.between(myPlayer.loadTime, Instant.now()).toMillis() > kick.config.getInt("屏蔽玩家双击间隔")) + myPlayer.loadTime = Instant.now(); + else + return false; + myPlayer.OpenMenuList = new ArrayList(); + return OpenMenu(player, new File(kick.mis.getDataFolder(), kick.MainFileName), true, true); + } + + public static int getID(MyPlayer myPlayer) { + int i = myPlayer.Formid; + if (i >= 0 && i <= 3) { + i++; + } else + i = 0; + myPlayer.Formid = i; + Kick.kick.PlayerDataMap.put(myPlayer.player.getName(), myPlayer); + return Kick.kick.formID.getID("子页" + i); + } + + /** + * 显示一个弹窗 + * + * @param player 要显示弹窗的玩家对象 + * @param Content 弹窗的内容 + * @return back + */ + public static boolean Tip(Player player, String Content) { + return Tip(player, Tool.getRandColor() + Kick.kick.mis.getName(), Content, false); + } + + /** + * 显示一个弹窗 + * + * @param player 要显示弹窗的玩家对象 + * @param Content 弹窗的内容 + * @param back 返回的布尔值 + * @return back + */ + public static boolean Tip(Player player, String Content, boolean back) { + return Tip(player, Tool.getRandColor() + Kick.kick.mis.getName(), Content, back); + } + + /** + * 显示一个弹窗 + * + * @param player 要显示弹窗的玩家对象 + * @param Title 弹窗的标题 + * @param Content 弹窗的内容 + * @param back 返回的布尔值 + * @return back + */ + public static boolean Tip(Player player, String Title, String Content, boolean back) { + return Tip(player, Title, Content, back, true); + } + + /** + * 显示一个弹窗 + * + * @param player 要显示弹窗的玩家对象 + * @param Title 弹窗的标题 + * @param Content 弹窗的内容 + * @param back 返回的布尔值 + * @param Modal 是否是Modal型弹窗 + * @return back + */ + public static boolean Tip(Player player, String Title, String Content, boolean back, boolean Modal) { + return Tip(player, Title, Content, "确定", "取消", back, Modal); + } + + /** + * 显示一个弹窗 + * + * @param player 要显示弹窗的玩家对象 + * @param Title 弹窗的标题 + * @param Content 弹窗的内容 + * @param Button1 弹窗的第一个按钮文本内容 + * @param Button2 弹窗的第二个按钮文本内容 + * @param back 返回的布尔值 + * @param Modal 是否是Modal型弹窗 + * @return back + */ + public static boolean Tip(Player player, String Title, String Content, String Button1, String Button2, boolean back, + boolean Modal) { + if (Modal) { + ModalForm form = new ModalForm(Tool.getRand(), Title, Button1, Button2); + form.setContent(Content); + form.sendPlayer(player); + } else { + SimpleForm form = new SimpleForm(Tool.getRand(), Title, Content); + form.addButton(Button1).addButton(Button2); + form.sendPlayer(player); + } + return back; + } +} diff --git a/Knickers/src/xiaokai/knickers/form/OpenButton.java b/Knickers/src/xiaokai/knickers/form/OpenButton.java index c60f7ae..c49c2c4 100644 --- a/Knickers/src/xiaokai/knickers/form/OpenButton.java +++ b/Knickers/src/xiaokai/knickers/form/OpenButton.java @@ -1,436 +1,437 @@ -package xiaokai.knickers.form; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import cn.nukkit.Player; -import cn.nukkit.Server; -import cn.nukkit.command.ConsoleCommandSender; -import cn.nukkit.form.response.FormResponseCustom; -import cn.nukkit.form.response.FormResponseSimple; -import cn.nukkit.level.Level; -import cn.nukkit.level.Position; -import cn.nukkit.plugin.Plugin; -import cn.nukkit.utils.Config; -import xiaokai.knickers.mtp.Kick; -import xiaokai.knickers.mtp.Message; -import xiaokai.knickers.mtp.MyPlayer; -import xiaokai.tool.CustomForm; -import xiaokai.tool.SimpleForm; -import xiaokai.tool.Tool; - -/** - * @author Winfxk - */ -public class OpenButton { - private Kick kick; - private Player player; - private File file; - private String Key; - private Map Item; - private Config config; - private Message msg; - - /** - * 打开一个按钮 - * - * @param k Kick对象 - * @param p 玩家对象 - * @param f 要打开的按钮的文件对象 - * @param s 要打开的按钮的Key - */ - @SuppressWarnings("unchecked") - public OpenButton(Kick k, Player p, File f, String s) { - this.kick = k; - this.player = p; - this.file = f; - this.Key = s; - this.config = new Config(file, Config.YAML); - Item = ((config.get("Buttons") != null && config.get("Buttons") instanceof Map) - ? (HashMap) config.get("Buttons") - : new HashMap()); - Item = (Item.get(Key) != null && Item.get(Key) instanceof Map) ? (HashMap) Item.get(Key) - : new HashMap(); - msg = kick.Message; - } - - /** - * 开始处理玩家点击按钮的事件,这里是判断玩家点击跌是什么按钮类型 - * - * @return - */ - public boolean start() { - if (Item.equals(new HashMap()) || Item.get("Type") == null - || String.valueOf(Item.get("Type")).isEmpty()) { - player.sendMessage("§4按钮打开失败!"); - MakeForm.OpenMenu(player, file); - return false; - } - switch (String.valueOf(Item.get("Type")).toLowerCase()) { - case "command": - return (new onCommand(player)).start(Item); - case "open": - return openUI(); - case "tp": - return openTp(); - case "tpa": - return (new Tpa(player, kick)).make(Key, config, Item); - case "tip": - default: - return openTip(); - } - } - - /** - * 当点击的按钮时点击后打开界面的按钮 - * - * @return - */ - private boolean openUI() { - carryCommand(player, Item); - String string = Item.get("Config") == null ? null : String.valueOf(Item.get("Config")); - if (string == null || string.isEmpty()) - return MakeForm.Tip(player, Kick.kick.Message.getSon("界面", "打开按钮失败", new String[] { "{Player}", "{Error}" }, - new Object[] { player.getName(), "无法获取菜单配置文件" })); - File file = new File(new File(kick.mis.getDataFolder(), Kick.MenuConfigPath), string); - if (!file.exists()) - return MakeForm.Tip(player, Kick.kick.Message.getSon("界面", "打开按钮失败", new String[] { "{Player}", "{Error}" }, - new Object[] { player.getName(), "菜单配置文件不存在!" })); - if (delMoney(player, Item)) - return MakeForm.OpenMenu(player, file, true); - return false; - } - - /** - * 处理玩家点击的按钮时Tp按钮的事件 - * - * @return - */ - private boolean openTp() { - carryCommand(player, Item); - if (Item.get("World") == null) { - kick.mis.getLogger().error("一个按钮的数据可能发生了错误!按钮类型为:传送,数据错误项:无法获取目标世界名称!请检查"); - return MakeForm.Tip(player, Kick.kick.Message.getSon("界面", "打开按钮失败", new String[] { "{Player}", "{Error}" }, - new Object[] { player.getName(), "无法获取目标世界名称!" })); - } - String World = String.valueOf(Item.get("World")); - Level level = Server.getInstance().getLevelByName(World); - if (level == null) { - kick.mis.getLogger().error("一个按钮的数据可能发生了错误!按钮类型为:传送,数据错误项:无法获取目标世界对象!请检查"); - return MakeForm.Tip(player, Kick.kick.Message.getSon("界面", "打开按钮失败", new String[] { "{Player}", "{Error}" }, - new Object[] { player.getName(), "无法获取目标世界对象!" })); - } - if (delMoney(player, Item)) - player.teleport( - new Position(ObjToDou(Item.get("X")), ObjToDou(Item.get("Y")), ObjToDou(Item.get("Z")), level)); - return true; - } - - /** - * 处理玩家点击的按钮为TIP按钮的时间 - * - * @return - */ - private boolean openTip() { - carryCommand(player, Item); - if (delMoney(player, Item)) - return MakeForm.Tip(player, - msg.getText(Item.get("Title"), new String[] { "{Player}" }, new Object[] { player.getName() }), - msg.getText(Item.get("Content"), new String[] { "{Player}" }, new Object[] { player.getName() }), - true, !Item.get("TipType").equals("Simple")); - return false; - } - - /** - * 检查点击的按钮是否需要扣费,如果需要,则讲究扣费 - * - * @param player 要检查扣费的玩家对象 - * @param Item 玩家点击的按钮数据对象 - * @return - */ - private static boolean delMoney(Player player, Map Item) { - double Money = 0; - String mString = String.valueOf(Item.get("Money") == null ? 0 : Item.get("Money")); - if (mString != null && !mString.isEmpty() && Tool.isInteger(mString)) - Money = Double.valueOf(mString); - if (Money <= 0) - return true; - Plugin MoneyAPI = Server.getInstance().getPluginManager().getPlugin("EconomyAPI"); - if (MoneyAPI == null || !MoneyAPI.isEnabled()) { - Kick.kick.mis.getLogger().warning("§6EconomyAPI§4未安装或未启用!忽略本次扣费。"); - return true; - } - if (me.onebone.economyapi.EconomyAPI.getInstance().myMoney(player) < Money) - return MakeForm.Tip(player, "§4提示", Kick.kick.Message.getMessage("金币不足", new String[] { "{Player}" }, - new Object[] { player.getName() }), false, true); - me.onebone.economyapi.EconomyAPI.getInstance().reduceMoney(player, Money); - return true; - } - - /** - * 设置玩家点击按钮后处罚的命令 - * - * @param player 点击按钮的玩家对象 - * @param Item 玩家点击跌按钮的数据 - * @return - */ - private static boolean carryCommand(Player player, Map Item) { - String Command = String.valueOf(Item.get("Command") == null ? "" : Item.get("Command")); - if (Command == null || Command.isEmpty()) - return false; - return Server.getInstance().dispatchCommand(player, Command); - } - - /** - * 将Object对象转换为double对象 - * - * @param d - * @return - */ - private static double ObjToDou(Object d) { - try { - return Double.valueOf(String.valueOf(d)); - } catch (Exception e) { - return 0; - } - } - - /** - * 处理玩家点击的是Tpa类型的按钮 - * - * @author Winfxk - * - */ - public static class Tpa { - private Player player; - private Kick kick; - - /** - * 创建玩家列表 - * - * @param player 要显示这个列表的玩家对象 - * @param kick Kick对象 - */ - public Tpa(Player player, Kick kick) { - this.player = player; - this.kick = kick; - } - - /** - * 处理玩家点击Tpa按钮后,但是需要请求,发送请求给玩家,玩家点击后的处理时间 - * - * @param data 返回的数据 - * @param player2 处理请求的玩家对象 - * @return - */ - public boolean isOK(FormResponseSimple data, Player player2) { - if (data != null && data.getClickedButtonId() == 0) - return Tp(player2); - return MakeForm.Tip(player, - kick.Message.getSun("界面", "Tpa界面", "传送请求被拒绝", new String[] { "{Player}", "{TpaPlayer}", "{Msg}" }, - new Object[] { player2.getName(), player.getName(), data != null ? "§4拒绝" : "§7取消" })); - } - - /** - * 处理玩家点击的是哪一个玩家 - * - * @param data - * @return - */ - public boolean start(FormResponseSimple data) { - MyPlayer myPlayer = Kick.kick.PlayerDataMap.get(player.getName()); - List Plist = myPlayer.players; - Player player2 = Plist.size() > data.getClickedButtonId() ? Plist.get(data.getClickedButtonId()) : null; - carryCommand(player, myPlayer.Item); - if (!Tool.ObjToBool(myPlayer.Item.get("isAffirm"))) - return Tp(player2); - SimpleForm form = new SimpleForm(kick.formID.getID(6), - kick.Message.getSun("界面", "Tpa界面", "发请求的标题", new String[] { "{Player}", "{TpaPlayer}" }, - new Object[] { player2.getName(), player.getName() }), - kick.Message.getSun("界面", "Tpa界面", "发请求的内容", new String[] { "{Player}", "{TpaPlayer}" }, - new Object[] { player2.getName(), player.getName() })); - form.addButton(kick.Message.getSun("界面", "Tpa界面", "发请求确认按钮", new String[] { "{Player}", "{TpaPlayer}" }, - new Object[] { player2.getName(), player.getName() })); - form.addButton(kick.Message.getSun("界面", "Tpa界面", "发请求取消按钮", new String[] { "{Player}", "{TpaPlayer}" }, - new Object[] { player2.getName(), player.getName() })); - MyPlayer myPlayer2player2 = Kick.kick.PlayerDataMap.get(player2.getName()); - myPlayer2player2.TpaPlayer = player; - Kick.kick.PlayerDataMap.put(player2.getName(), myPlayer2player2); - form.sendPlayer(player2); - return false; - } - - /** - * 开始传送玩家 - * - * @param player2 要传送到的玩家坐标 - */ - public boolean Tp(Player player2) { - if (player2 != null && player2.isOnline()) { - player.teleport(new Position(player2.getX(), player2.getY(), player2.getZ(), player2.getLevel())); - player.sendMessage( - kick.Message.getSun("界面", "Tpa界面", "传送提示", new String[] { "{Player}", "{TpaPlayer}" }, - new Object[] { player2.getName(), player.getName() })); - return true; - } else - MakeForm.Tip(player, - kick.Message.getSun("界面", "Tpa界面", "玩家不在线", new String[] { "{Player}", "{TpaPlayer}" }, - new Object[] { player2.getName(), player.getName() })); - return true; - } - - /** - * 创建按钮给玩家点击 - * - * @param Key 按钮的Key - * @param config 按钮所在的Config对象 - * @return - */ - public boolean make(String Key, Config config, Map Item) { - MyPlayer myPlayer = Kick.kick.PlayerDataMap.get(player.getName()); - myPlayer.Key = Key; - Map Players = Server.getInstance().getOnlinePlayers(); - if (Players.size() < 2) - return MakeForm.Tip(player, kick.Message.getSun("界面", "Tpa界面", "无玩家在线", new String[] { "{Player}" }, - new Object[] { player.getName() })); - List Plist = new ArrayList(); - List kList = new ArrayList(); - SimpleForm form = new SimpleForm(kick.formID.getID(5), - kick.Message.getSun("界面", "Tpa界面", "玩家列表标题", new String[] { "{Player}", "{BackTitle}" }, - new Object[] { player.getName(), - kick.Message.getText(config.getString("Title"), new String[] { "{Player}" }, - new Object[] { player.getName() }) }), - kick.Message.getSun("界面", "Tpa界面", "玩家列表内容", new String[] { "{Player}" }, - new Object[] { player.getName() })); - for (UUID uuid : Players.keySet()) { - Player player2 = Players.get(uuid); - if (player2.getName().equals(player.getName())) - continue; - Plist.add(player2); - kList.add(player2.getName()); - form.addButton(Tool.getRandColor() + player2.getName()); - } - if (Plist.size() < 1) - return MakeForm.Tip(player, kick.Message.getSun("界面", "Tpa界面", "无玩家在线", new String[] { "{Player}" }, - new Object[] { player.getName() })); - carryCommand(player, Item); - if (delMoney(player, Item)) { - myPlayer.keyList = kList; - myPlayer.players = Plist; - myPlayer.Item = Item; - kick.PlayerDataMap.put(player.getName(), myPlayer); - form.sendPlayer(player); - return true; - } - return false; - } - } - - @SuppressWarnings("unchecked") - public static class onCommand { - private Player player; - - /** - * 处理玩家点击是执行命令的按钮的事件 - * - * @param player - */ - public onCommand(Player player) { - this.player = player; - } - - /** - * 开始处理玩家输入命令的点击事件 - * - * @param data - * @return - */ - public boolean PY(FormResponseCustom data) { - MyPlayer myPlayer = Kick.kick.PlayerDataMap.get(player.getName()); - List Commands = myPlayer.Commnds; - String string = ""; - for (int i = 0; i < Commands.size() - 1; i++) - string += Commands.get(i) + data.getInputResponse(i); - string += Commands.get(Commands.size() - 1); - return carryCommand(player, string, myPlayer.Commander); - } - - /** - * 如果点击的是带{msg}的按钮,那么创建界面 - * - * @param Command 按钮的命令 - * @param Commander 按钮的命令的执行对象 - * @param Item 按钮的数据 - * @return - */ - private boolean make(String Command, String Commander, Map Item) { - MyPlayer myPlayer = Kick.kick.PlayerDataMap.get(player.getName()); - Kick kick = Kick.kick; - String[] Commands = Command.split("\\{Msg\\}"); - CustomForm form = new CustomForm(kick.formID.getID(7), kick.Message.getSun("界面", "执行命令", "标题", - new String[] { "{Player}" }, new Object[] { player.getName() })); - List def = (Item.get("Msg") == null || !(Item.get("Msg") instanceof List)) ? new ArrayList() - : (ArrayList) Item.get("Msg"); - List Hints = (Item.get("Hint") == null || !(Item.get("Hint") instanceof List)) - ? new ArrayList() - : (ArrayList) Item.get("Hint"); - for (int i = 0; i < Commands.length - 1; i++) - form.addInput(Commands[i], - def.size() < 1 ? "" : ((def.size() < i) ? def.get(i) : def.get(def.size() - 1)), - Hints.size() < 1 ? "" : (Hints.size() < i) ? Hints.get(i) : Hints.get(Hints.size() - 1)); - myPlayer.Commnds = Arrays.asList(Commands); - myPlayer.Commander = Commander; - kick.PlayerDataMap.put(player.getName(), myPlayer); - form.sendPlayer(player); - return true; - } - - /** - * 开始处理 - * - * @param Item 玩家点击的按钮的数据对象 - * @return - */ - public boolean start(Map Item) { - String Command = String.valueOf(Item.get("Command")); - String Commander = String.valueOf(Item.get("Commander")); - if (Command != null && !Command.isEmpty() && Commander != null && !Commander.isEmpty() - && delMoney(player, Item)) { - Command = Kick.kick.Message.getText(Command, new String[] { "{Player}" }, - new Object[] { player.getName() }); - Command = (Command.lastIndexOf("}") == Command.length() - 1) ? Command + " " : Command; - if (Command.contains("{Msg}")) { - return make(Command, Commander, Item); - } else - return carryCommand(player, Command, Commander); - } - return false; - } - - /** - * 执行命令 - * - * @param player 触发这个事件的玩家对象 - * @param Command 要执行的命令 - * @param Commander 要执行命令的对象[Console|PlayerByOp|Player] - * @return - */ - private static boolean carryCommand(Player player, String Command, String Commander) { - boolean isOP = player.isOp(); - if (Commander.toLowerCase().equals("playerbyop") && !isOP) - player.setOp(true); - boolean cmd = Server.getInstance().dispatchCommand( - (Commander.toLowerCase().equals("player") || Commander.toLowerCase().equals("playerbyop")) ? player - : new ConsoleCommandSender(), - Command); - if (Commander.toLowerCase().equals("playerbyop") && !isOP) - player.setOp(false); - return cmd; - } - } -} +package xiaokai.knickers.form; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import cn.nukkit.Player; +import cn.nukkit.Server; +import cn.nukkit.command.ConsoleCommandSender; +import cn.nukkit.form.response.FormResponseCustom; +import cn.nukkit.form.response.FormResponseSimple; +import cn.nukkit.level.Level; +import cn.nukkit.level.Position; +import cn.nukkit.plugin.Plugin; +import cn.nukkit.utils.Config; +import xiaokai.knickers.mtp.Kick; +import xiaokai.knickers.mtp.Message; +import xiaokai.knickers.mtp.MyPlayer; +import xiaokai.tool.CustomForm; +import xiaokai.tool.SimpleForm; +import xiaokai.tool.Tool; + +/** + * @author Winfxk + */ +public class OpenButton { + private Kick kick; + private Player player; + private File file; + private String Key; + private Map Item; + private Config config; + private Message msg; + + /** + * 打开一个按钮 + * + * @param k Kick对象 + * @param p 玩家对象 + * @param f 要打开的按钮的文件对象 + * @param s 要打开的按钮的Key + */ + @SuppressWarnings("unchecked") + public OpenButton(Kick k, Player p, File f, String s) { + this.kick = k; + this.player = p; + this.file = f; + this.Key = s; + this.config = new Config(file, Config.YAML); + Item = ((config.get("Buttons") != null && config.get("Buttons") instanceof Map) + ? (HashMap) config.get("Buttons") + : new HashMap()); + Item = (Item.get(Key) != null && Item.get(Key) instanceof Map) ? (HashMap) Item.get(Key) + : new HashMap(); + msg = kick.Message; + } + + /** + * 开始处理玩家点击按钮的事件,这里是判断玩家点击跌是什么按钮类型 + * + * @return + */ + public boolean start() { + if (Item.equals(new HashMap()) || Item.get("Type") == null + || String.valueOf(Item.get("Type")).isEmpty()) { + player.sendMessage("§4按钮打开失败!"); + MakeForm.OpenMenu(player, file); + return false; + } + switch (String.valueOf(Item.get("Type")).toLowerCase()) { + case "command": + return (new onCommand(player)).start(Item); + case "open": + return openUI(); + case "tp": + return openTp(); + case "tpa": + return (new Tpa(player, kick)).make(Key, config, Item); + case "tip": + default: + return openTip(); + } + } + + /** + * 当点击的按钮时点击后打开界面的按钮 + * + * @return + */ + private boolean openUI() { + carryCommand(player, Item); + String string = Item.get("Config") == null ? null : String.valueOf(Item.get("Config")); + if (string == null || string.isEmpty()) + return MakeForm.Tip(player, Kick.kick.Message.getSon("界面", "打开按钮失败", new String[] { "{Player}", "{Error}" }, + new Object[] { player.getName(), "无法获取菜单配置文件" })); + File file = new File(new File(kick.mis.getDataFolder(), Kick.MenuConfigPath), string); + if (!file.exists()) + return MakeForm.Tip(player, Kick.kick.Message.getSon("界面", "打开按钮失败", new String[] { "{Player}", "{Error}" }, + new Object[] { player.getName(), "菜单配置文件不存在!" })); + if (delMoney(player, Item)) + return MakeForm.OpenMenu(player, file, true); + return false; + } + + /** + * 处理玩家点击的按钮时Tp按钮的事件 + * + * @return + */ + private boolean openTp() { + carryCommand(player, Item); + if (Item.get("World") == null) { + kick.mis.getLogger().error("一个按钮的数据可能发生了错误!按钮类型为:传送,数据错误项:无法获取目标世界名称!请检查"); + return MakeForm.Tip(player, Kick.kick.Message.getSon("界面", "打开按钮失败", new String[] { "{Player}", "{Error}" }, + new Object[] { player.getName(), "无法获取目标世界名称!" })); + } + String World = String.valueOf(Item.get("World")); + Level level = Server.getInstance().getLevelByName(World); + if (level == null) { + kick.mis.getLogger().error("一个按钮的数据可能发生了错误!按钮类型为:传送,数据错误项:无法获取目标世界对象!请检查"); + return MakeForm.Tip(player, Kick.kick.Message.getSon("界面", "打开按钮失败", new String[] { "{Player}", "{Error}" }, + new Object[] { player.getName(), "无法获取目标世界对象!" })); + } + if (delMoney(player, Item)) + player.teleport( + new Position(ObjToDou(Item.get("X")), ObjToDou(Item.get("Y")), ObjToDou(Item.get("Z")), level)); + return true; + } + + /** + * 处理玩家点击的按钮为TIP按钮的时间 + * + * @return + */ + private boolean openTip() { + carryCommand(player, Item); + if (delMoney(player, Item)) + return MakeForm.Tip(player, + msg.getText(Item.get("Title"), new String[] { "{Player}" }, new Object[] { player.getName() }), + msg.getText(Item.get("Content"), new String[] { "{Player}" }, new Object[] { player.getName() }), + true, !Item.get("TipType").equals("Simple")); + return false; + } + + /** + * 检查点击的按钮是否需要扣费,如果需要,则讲究扣费 + * + * @param player 要检查扣费的玩家对象 + * @param Item 玩家点击的按钮数据对象 + * @return + */ + private static boolean delMoney(Player player, Map Item) { + double Money = 0; + String mString = String.valueOf(Item.get("Money") == null ? 0 : Item.get("Money")); + if (mString != null && !mString.isEmpty() && Tool.isInteger(mString)) + Money = Double.valueOf(mString); + if (Money <= 0) + return true; + Plugin MoneyAPI = Server.getInstance().getPluginManager().getPlugin("EconomyAPI"); + if (MoneyAPI == null || !MoneyAPI.isEnabled()) { + Kick.kick.mis.getLogger().warning("§6EconomyAPI§4未安装或未启用!忽略本次扣费。"); + return true; + } + if (me.onebone.economyapi.EconomyAPI.getInstance().myMoney(player) < Money) + return MakeForm.Tip(player, "§4提示", Kick.kick.Message.getMessage("金币不足", new String[] { "{Player}" }, + new Object[] { player.getName() }), false, true); + me.onebone.economyapi.EconomyAPI.getInstance().reduceMoney(player, Money); + return true; + } + + /** + * 设置玩家点击按钮后处罚的命令 + * + * @param player 点击按钮的玩家对象 + * @param Item 玩家点击跌按钮的数据 + * @return + */ + private static boolean carryCommand(Player player, Map Item) { + String Command = String.valueOf(Item.get("Command") == null ? "" : Item.get("Command")); + if (Command == null || Command.isEmpty()) + return false; + return Server.getInstance().dispatchCommand(player, Command); + } + + /** + * 将Object对象转换为double对象 + * + * @param d + * @return + */ + private static double ObjToDou(Object d) { + try { + return Double.valueOf(String.valueOf(d)); + } catch (Exception e) { + return 0; + } + } + + /** + * 处理玩家点击的是Tpa类型的按钮 + * + * @author Winfxk + * + */ + public static class Tpa { + private Player player; + private Kick kick; + + /** + * 创建玩家列表 + * + * @param player 要显示这个列表的玩家对象 + * @param kick Kick对象 + */ + public Tpa(Player player, Kick kick) { + this.player = player; + this.kick = kick; + } + + /** + * 处理玩家点击Tpa按钮后,但是需要请求,发送请求给玩家,玩家点击后的处理时间 + * + * @param data 返回的数据 + * @param player2 处理请求的玩家对象 + * @return + */ + public boolean isOK(FormResponseSimple data, Player player2) { + if (data != null && data.getClickedButtonId() == 0) + return Tp(player2); + return MakeForm.Tip(player, + kick.Message.getSun("界面", "Tpa界面", "传送请求被拒绝", new String[] { "{Player}", "{TpaPlayer}", "{Msg}" }, + new Object[] { player2.getName(), player.getName(), data != null ? "§4拒绝" : "§7取消" })); + } + + /** + * 处理玩家点击的是哪一个玩家 + * + * @param data + * @return + */ + public boolean start(FormResponseSimple data) { + MyPlayer myPlayer = Kick.kick.PlayerDataMap.get(player.getName()); + List Plist = myPlayer.players; + Player player2 = Plist.size() > data.getClickedButtonId() ? Plist.get(data.getClickedButtonId()) : null; + carryCommand(player, myPlayer.Item); + if (!Tool.ObjToBool(myPlayer.Item.get("isAffirm"))) + return Tp(player2); + SimpleForm form = new SimpleForm(kick.formID.getID(6), + kick.Message.getSun("界面", "Tpa界面", "发请求的标题", new String[] { "{Player}", "{TpaPlayer}" }, + new Object[] { player2.getName(), player.getName() }), + kick.Message.getSun("界面", "Tpa界面", "发请求的内容", new String[] { "{Player}", "{TpaPlayer}" }, + new Object[] { player2.getName(), player.getName() })); + form.addButton(kick.Message.getSun("界面", "Tpa界面", "发请求确认按钮", new String[] { "{Player}", "{TpaPlayer}" }, + new Object[] { player2.getName(), player.getName() })); + form.addButton(kick.Message.getSun("界面", "Tpa界面", "发请求取消按钮", new String[] { "{Player}", "{TpaPlayer}" }, + new Object[] { player2.getName(), player.getName() })); + MyPlayer myPlayer2player2 = Kick.kick.PlayerDataMap.get(player2.getName()); + myPlayer2player2.TpaPlayer = player; + Kick.kick.PlayerDataMap.put(player2.getName(), myPlayer2player2); + form.sendPlayer(player2); + return false; + } + + /** + * 开始传送玩家 + * + * @param player2 要传送到的玩家坐标 + */ + public boolean Tp(Player player2) { + if (player2 != null && player2.isOnline()) { + player.teleport(new Position(player2.getX(), player2.getY(), player2.getZ(), player2.getLevel())); + player.sendMessage( + kick.Message.getSun("界面", "Tpa界面", "传送提示", new String[] { "{Player}", "{TpaPlayer}" }, + new Object[] { player2.getName(), player.getName() })); + return true; + } else + MakeForm.Tip(player, + kick.Message.getSun("界面", "Tpa界面", "玩家不在线", new String[] { "{Player}", "{TpaPlayer}" }, + new Object[] { player2.getName(), player.getName() })); + return true; + } + + /** + * 创建按钮给玩家点击 + * + * @param Key 按钮的Key + * @param config 按钮所在的Config对象 + * @return + */ + public boolean make(String Key, Config config, Map Item) { + MyPlayer myPlayer = Kick.kick.PlayerDataMap.get(player.getName()); + myPlayer.Key = Key; + Map Players = Server.getInstance().getOnlinePlayers(); + if (Players.size() < 2) + return MakeForm.Tip(player, kick.Message.getSun("界面", "Tpa界面", "无玩家在线", new String[] { "{Player}" }, + new Object[] { player.getName() })); + List Plist = new ArrayList(); + List kList = new ArrayList(); + SimpleForm form = new SimpleForm(kick.formID.getID(5), + kick.Message.getSun("界面", "Tpa界面", "玩家列表标题", new String[] { "{Player}", "{BackTitle}" }, + new Object[] { player.getName(), + kick.Message.getText(config.getString("Title"), new String[] { "{Player}" }, + new Object[] { player.getName() }) }), + kick.Message.getSun("界面", "Tpa界面", "玩家列表内容", new String[] { "{Player}" }, + new Object[] { player.getName() })); + for (UUID uuid : Players.keySet()) { + Player player2 = Players.get(uuid); + if (player2.getName().equals(player.getName())) + continue; + Plist.add(player2); + kList.add(player2.getName()); + form.addButton(Tool.getRandColor() + player2.getName()); + } + if (Plist.size() < 1) + return MakeForm.Tip(player, kick.Message.getSun("界面", "Tpa界面", "无玩家在线", new String[] { "{Player}" }, + new Object[] { player.getName() })); + carryCommand(player, Item); + if (delMoney(player, Item)) { + myPlayer.keyList = kList; + myPlayer.players = Plist; + myPlayer.Item = Item; + kick.PlayerDataMap.put(player.getName(), myPlayer); + form.sendPlayer(player); + return true; + } + return false; + } + } + + @SuppressWarnings("unchecked") + public static class onCommand { + private Player player; + + /** + * 处理玩家点击是执行命令的按钮的事件 + * + * @param player + */ + public onCommand(Player player) { + this.player = player; + } + + /** + * 开始处理玩家输入命令的点击事件 + * + * @param data + * @return + */ + public boolean PY(FormResponseCustom data) { + MyPlayer myPlayer = Kick.kick.PlayerDataMap.get(player.getName()); + List Commands = myPlayer.Commnds; + String string = ""; + for (int i = 0; i < Commands.size() - 1; i++) + string += Commands.get(i) + data.getInputResponse(i); + string += Commands.get(Commands.size() - 1); + return carryCommand(player, string, myPlayer.Commander); + } + + /** + * 如果点击的是带{msg}的按钮,那么创建界面 + * + * @param Command 按钮的命令 + * @param Commander 按钮的命令的执行对象 + * @param Item 按钮的数据 + * @return + */ + private boolean make(String Command, String Commander, Map Item) { + MyPlayer myPlayer = Kick.kick.PlayerDataMap.get(player.getName()); + Kick kick = Kick.kick; + String[] Commands = Command.split("\\{msg\\}"); + CustomForm form = new CustomForm(kick.formID.getID(7), kick.Message.getSun("界面", "执行命令", "标题", + new String[] { "{Player}" }, new Object[] { player.getName() })); + List def = (Item.get("Msg") == null || !(Item.get("Msg") instanceof List)) ? new ArrayList() + : (ArrayList) Item.get("Msg"); + List Hints = (Item.get("Hint") == null || !(Item.get("Hint") instanceof List)) + ? new ArrayList() + : (ArrayList) Item.get("Hint"); + for (int i = 0; i < Commands.length - 1; i++) + form.addInput(def.size() < 1 ? "" : ((def.size() < i) ? def.get(i) : def.get(def.size() - 1)), "", + Hints.size() < 1 ? "" : (Hints.size() < i) ? Hints.get(i) : Hints.get(Hints.size() - 1)); + myPlayer.Commnds = Arrays.asList(Commands); + myPlayer.Commander = Commander; + kick.PlayerDataMap.put(player.getName(), myPlayer); + form.sendPlayer(player); + return true; + } + + /** + * 开始处理 + * + * @param Item 玩家点击的按钮的数据对象 + * @return + */ + public boolean start(Map Item) { + String Command = String.valueOf(Item.get("Command")); + String Commander = String.valueOf(Item.get("Commander")); + if (Command != null && !Command.isEmpty() && Commander != null && !Commander.isEmpty() + && delMoney(player, Item)) { + Command = Kick.kick.Message.getText(Command, new String[] { "{Player}" }, + new Object[] { player.getName() }); + Command = (Command.lastIndexOf("}") == Command.length() - 1) ? Command + " " : Command; + System.out.println(Command); + if (Command.contains("{msg}")) { + return make(Command, Commander, Item); + } else + return carryCommand(player, Command, Commander); + } + return MakeForm.Tip(player, Kick.kick.Message.getSun("界面", "执行命令", "打开失败", + new String[] { "{Player}", "{Error}" }, new Object[] { player.getName(), "获取的命令为空!" })); + } + + /** + * 执行命令 + * + * @param player 触发这个事件的玩家对象 + * @param Command 要执行的命令 + * @param Commander 要执行命令的对象[Console|PlayerByOp|Player] + * @return + */ + private static boolean carryCommand(Player player, String Command, String Commander) { + boolean isOP = player.isOp(); + if (Commander.toLowerCase().equals("playerbyop") && !isOP) + player.setOp(true); + boolean cmd = Server.getInstance().dispatchCommand( + (Commander.toLowerCase().equals("player") || Commander.toLowerCase().equals("playerbyop")) ? player + : new ConsoleCommandSender(), + Command); + if (Commander.toLowerCase().equals("playerbyop") && !isOP) + player.setOp(false); + return cmd; + } + } +} diff --git a/Knickers/src/xiaokai/knickers/mtp/Belle.java b/Knickers/src/xiaokai/knickers/mtp/Belle.java index 6fd1f37..0159737 100644 --- a/Knickers/src/xiaokai/knickers/mtp/Belle.java +++ b/Knickers/src/xiaokai/knickers/mtp/Belle.java @@ -1,179 +1,192 @@ -package xiaokai.knickers.mtp; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; - -import cn.nukkit.Player; -import cn.nukkit.inventory.Inventory; -import cn.nukkit.item.Item; -import cn.nukkit.item.enchantment.Enchantment; -import cn.nukkit.nbt.tag.CompoundTag; -import cn.nukkit.utils.Config; -import cn.nukkit.utils.ConfigSection; -import cn.nukkit.utils.Utils; -import xiaokai.tool.Tool; - -/** - * @author Winfxk - */ -@SuppressWarnings("unchecked") -public class Belle { - private Kick kick; - - public Belle(Kick kick) { - this.kick = kick; - } - - public void start() { - File file; - for (String DirName : Kick.LoadDirList) { - file = new File(kick.mis.getDataFolder(), DirName); - if (!file.exists()) - file.mkdirs(); - } - for (String FileName : kick.LoadFileName) { - file = new File(kick.mis.getDataFolder(), FileName); - if (!file.exists()) - try { - kick.mis.getLogger().info("§6初始化资源:§c" + FileName); - InputStream rand = this.getClass().getResourceAsStream("/resources/" + FileName); - if (rand == null) { - String QQName = ""; - try { - QQName = Tool.doPost("http://tool.epicfx.cn/", "s=qs&qq=2508543202"); - if (QQName == null) - QQName = ""; - } catch (Exception e) { - } - kick.mis.getLogger().error("初始化资源包失败!可能是插件已经损坏或被人为修改!请联系作者!" + QQName + "QQ:2508543202 "); - } else - Utils.writeFile(file, rand); - } catch (IOException e) { - kick.mis.getLogger().error("§4资源初始化失败!请检查!§f" + e.getMessage()); - kick.mis.setEnabled(false); - } - } - for (String formidKey : kick.FormIDName) - if (!kick.formIdConfig.exists(formidKey)) { - kick.mis.getLogger().info("§4未发现§6" + formidKey + "§4对应的表单值!正在写入..."); - kick.formIdConfig.set(formidKey, Tool.getRand()); - kick.formIdConfig.save(); - } - for (String FileNae : kick.isLoadFileName) - try { - kick.mis.getLogger().info("§6正在检查文件" + FileNae); - String content = Utils.readFile(this.getClass().getResourceAsStream("/resources/" + FileNae)); - DumperOptions dumperOptions = new DumperOptions(); - dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - Yaml yaml = new Yaml(dumperOptions); - LinkedHashMap map = new ConfigSection(yaml.loadAs(content, LinkedHashMap.class)); - Config config = new Config(new File(kick.mis.getDataFolder(), FileNae), Config.YAML); - Map cg = config.getAll(); - isMap(map, cg, config); - } catch (IOException e) { - kick.mis.getLogger().info("§4在检查数据中遇到错误!请尝试删除该文件§9[§d" + FileNae + "§9]\n§f" + e.getMessage()); - } - } - - public void isMap(Map map, Map cg, Config config) { - for (String ike : map.keySet()) - if (!cg.containsKey(ike)) { - cg.put(ike, map.get(ike)); - kick.mis.getLogger().info("§6" + ike + "§4所属的数据错误!已回复默认"); - continue; - } else if (!(((cg.get(ike) instanceof Map) || (map.get(ike) instanceof Map)) - || ((cg.get(ike) instanceof List) && (map.get(ike) instanceof List) - || ((cg.get(ike) instanceof String) && (map.get(ike) instanceof String))) - || ((map.get(ike) instanceof Integer) && (cg.get(ike) instanceof Integer)) - || ((map.get(ike) instanceof Boolean) && (cg.get(ike) instanceof Boolean)) - || ((map.get(ike) instanceof Float) && (cg.get(ike) instanceof Float)))) { - cg.put(ike, map.get(ike)); - kick.mis.getLogger().info("§6" + ike + "§4属性不匹配!已回复默认"); - continue; - } else if (map.get(ike) instanceof Map) - cg.put(ike, icMap((Map) map.get(ike), (Map) cg.get(ike))); - config.setAll((LinkedHashMap) cg); - config.save(); - } - - public Map icMap(Map map, Map cg) { - for (String ike : map.keySet()) - if (!cg.containsKey(ike)) { - cg.put(ike, map.get(ike)); - kick.mis.getLogger().info("§6" + ike + "§4所属的数据错误!已回复默认"); - continue; - } else if (!(((cg.get(ike) instanceof Map) && (map.get(ike) instanceof Map)) - || ((cg.get(ike) instanceof List) && (map.get(ike) instanceof List) - || ((cg.get(ike) instanceof String) && (map.get(ike) instanceof String))))) { - cg.put(ike, map.get(ike)); - kick.mis.getLogger().info("§6" + ike + "§4属性不匹配!已回复默认"); - continue; - } else if (map.get(ike) instanceof Map) - cg.put(ike, icMap((Map) map.get(ike), (Map) cg.get(ike))); - return cg; - } - - /** - * 判断玩家背包是否拥有快捷工具 - * - * @param player - * @return - */ - public static boolean isMaterials(Player player) { - Inventory inventory = player.getInventory(); - Map Items = inventory.getContents(); - for (Integer ike : Items.keySet()) - if (isMaterials(Items.get(ike))) - return true; - return false; - } - - /** - * 检查玩家是否拥有快捷工具,没有的话给与一个 - * - * @param player - */ - public static void exMaterials(Player player) { - if (isMaterials(player)) - return; - giveMaterials(player); - player.sendMessage( - Kick.kick.Message.getMessage("进服给快捷工具", new String[] { "{Player" }, new Object[] { player.getName() })); - - } - - /** - * 检查玩家的物品是否是快捷工具 - * - * @param item - * @return - */ - public static boolean isMaterials(Item item) { - if (item == null || !Tool.isMateID(item.getId() + ":" + item.getDamage(), Kick.kick.config.getString("快捷工具"))) - return false; - CompoundTag tag = item.getNamedTag(); - return (tag != null - && tag.getString("ID").equals(Kick.kick.getClass().getName() + Kick.kick.mis.getFullName())); - } - - public static void giveMaterials(Player player) { - Kick kick = Kick.kick; - int[] IDS = Tool.IDtoFullID(kick.config.getString("快捷工具")); - Item item = new Item(IDS[0], IDS[1]); - CompoundTag tag = new CompoundTag(); - tag.putString("ID", Kick.class.getName() + kick.mis.getFullName()); - item.setNamedTag(tag); - item.setCustomName( - kick.Message.getMessage("快捷工具名称", new String[] { "{Player" }, new Object[] { player.getName() })); - item.setLore(kick.Message.getMessage("快捷工具名称2", new String[] { "{Player" }, new Object[] { player.getName() })); - item.addEnchantment(Enchantment.get(Enchantment.ID_SILK_TOUCH)); - player.getInventory().addItem(item); - } -} +package xiaokai.knickers.mtp; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; + +import cn.nukkit.Player; +import cn.nukkit.inventory.Inventory; +import cn.nukkit.item.Item; +import cn.nukkit.item.enchantment.Enchantment; +import cn.nukkit.nbt.tag.CompoundTag; +import cn.nukkit.utils.Config; +import cn.nukkit.utils.ConfigSection; +import cn.nukkit.utils.Utils; +import xiaokai.tool.Tool; + +/** + * @author Winfxk + */ +@SuppressWarnings("unchecked") +public class Belle { + private Kick kick; + + public Belle(Kick kick) { + this.kick = kick; + } + + public void start() { + File file; + for (String DirName : Kick.LoadDirList) { + file = new File(kick.mis.getDataFolder(), DirName); + if (!file.exists()) + file.mkdirs(); + } + for (String FileName : kick.LoadFileName) { + file = new File(kick.mis.getDataFolder(), FileName); + if (!file.exists()) + try { + kick.mis.getLogger().info("§6初始化资源:§c" + FileName); + InputStream rand = this.getClass().getResourceAsStream("/resources/" + FileName); + if (rand == null) { + String QQName = ""; + try { + QQName = Tool.doPost("http://tool.epicfx.cn/", "s=qs&qq=2508543202"); + if (QQName == null) + QQName = ""; + } catch (Exception e) { + } + kick.mis.getLogger().error("初始化资源包失败!可能是插件已经损坏或被人为修改!请联系作者!" + QQName + "QQ:2508543202 "); + } else + Utils.writeFile(file, rand); + } catch (IOException e) { + kick.mis.getLogger().error("§4资源初始化失败!请检查!§f" + e.getMessage()); + kick.mis.setEnabled(false); + } + } + for (String formidKey : kick.FormIDName) + if (!kick.formIdConfig.exists(formidKey)) { + kick.mis.getLogger().info("§4未发现§6" + formidKey + "§4对应的表单值!正在写入..."); + kick.formIdConfig.set(formidKey, Tool.getRand()); + kick.formIdConfig.save(); + } + DumperOptions dumperOptions = new DumperOptions(); + dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + LinkedHashMap map; + Yaml yaml = new Yaml(dumperOptions); + String content; + for (String FileNae : kick.isLoadFileName) + try { + kick.mis.getLogger().info("§6正在检查文件" + FileNae); + content = Utils.readFile(this.getClass().getResourceAsStream("/resources/" + FileNae)); + map = new ConfigSection(yaml.loadAs(content, LinkedHashMap.class)); + Config config = new Config(new File(kick.mis.getDataFolder(), FileNae), Config.YAML); + Map cg = config.getAll(); + isMap(map, cg, config); + } catch (IOException e) { + kick.mis.getLogger().info("§4在检查数据中遇到错误!请尝试删除该文件§9[§d" + FileNae + "§9]\n§f" + e.getMessage()); + } + file = new File(kick.mis.getDataFolder(), Kick.MenuConfigPath); + for (String Fn : file.list()) { + File fns = new File(file, Fn); + if (fns.isFile()) + try { + content = Utils.readFile(fns); + map = new ConfigSection(yaml.loadAs(content, LinkedHashMap.class)); + } catch (Exception e) { + kick.mis.getLogger().error("§4已发现§6" + fns.getName() + "§4存在错误!请检查!" + e.getMessage()); + } + } + } + + public void isMap(Map map, Map cg, Config config) { + for (String ike : map.keySet()) + if (!cg.containsKey(ike)) { + cg.put(ike, map.get(ike)); + kick.mis.getLogger().info("§6" + ike + "§4所属的数据错误!已回复默认"); + continue; + } else if (!(((cg.get(ike) instanceof Map) || (map.get(ike) instanceof Map)) + || ((cg.get(ike) instanceof List) && (map.get(ike) instanceof List) + || ((cg.get(ike) instanceof String) && (map.get(ike) instanceof String))) + || ((map.get(ike) instanceof Integer) && (cg.get(ike) instanceof Integer)) + || ((map.get(ike) instanceof Boolean) && (cg.get(ike) instanceof Boolean)) + || ((map.get(ike) instanceof Float) && (cg.get(ike) instanceof Float)))) { + cg.put(ike, map.get(ike)); + kick.mis.getLogger().info("§6" + ike + "§4属性不匹配!已回复默认"); + continue; + } else if (map.get(ike) instanceof Map) + cg.put(ike, icMap((Map) map.get(ike), (Map) cg.get(ike))); + config.setAll((LinkedHashMap) cg); + config.save(); + } + + public Map icMap(Map map, Map cg) { + for (String ike : map.keySet()) + if (!cg.containsKey(ike)) { + cg.put(ike, map.get(ike)); + kick.mis.getLogger().info("§6" + ike + "§4所属的数据错误!已回复默认"); + continue; + } else if (!(((cg.get(ike) instanceof Map) && (map.get(ike) instanceof Map)) + || ((cg.get(ike) instanceof List) && (map.get(ike) instanceof List) + || ((cg.get(ike) instanceof String) && (map.get(ike) instanceof String))))) { + cg.put(ike, map.get(ike)); + kick.mis.getLogger().info("§6" + ike + "§4属性不匹配!已回复默认"); + continue; + } else if (map.get(ike) instanceof Map) + cg.put(ike, icMap((Map) map.get(ike), (Map) cg.get(ike))); + return cg; + } + + /** + * 判断玩家背包是否拥有快捷工具 + * + * @param player + * @return + */ + public static boolean isMaterials(Player player) { + Inventory inventory = player.getInventory(); + Map Items = inventory.getContents(); + for (Integer ike : Items.keySet()) + if (isMaterials(Items.get(ike))) + return true; + return false; + } + + /** + * 检查玩家是否拥有快捷工具,没有的话给与一个 + * + * @param player + */ + public static void exMaterials(Player player) { + if (isMaterials(player)) + return; + giveMaterials(player); + player.sendMessage( + Kick.kick.Message.getMessage("进服给快捷工具", new String[] { "{Player" }, new Object[] { player.getName() })); + + } + + /** + * 检查玩家的物品是否是快捷工具 + * + * @param item + * @return + */ + public static boolean isMaterials(Item item) { + if (item == null || !Tool.isMateID(item.getId() + ":" + item.getDamage(), Kick.kick.config.getString("快捷工具"))) + return false; + CompoundTag tag = item.getNamedTag(); + return (tag != null + && tag.getString("ID").equals(Kick.kick.getClass().getName() + Kick.kick.mis.getFullName())); + } + + public static void giveMaterials(Player player) { + Kick kick = Kick.kick; + int[] IDS = Tool.IDtoFullID(kick.config.getString("快捷工具")); + Item item = new Item(IDS[0], IDS[1]); + CompoundTag tag = new CompoundTag(); + tag.putString("ID", Kick.class.getName() + kick.mis.getFullName()); + item.setNamedTag(tag); + item.setCustomName( + kick.Message.getMessage("快捷工具名称", new String[] { "{Player" }, new Object[] { player.getName() })); + item.setLore(kick.Message.getMessage("快捷工具名称2", new String[] { "{Player" }, new Object[] { player.getName() })); + item.addEnchantment(Enchantment.get(Enchantment.ID_SILK_TOUCH)); + player.getInventory().addItem(item); + } +} diff --git a/Knickers/src/xiaokai/knickers/mtp/Kick.java b/Knickers/src/xiaokai/knickers/mtp/Kick.java index dd7978c..4792047 100644 --- a/Knickers/src/xiaokai/knickers/mtp/Kick.java +++ b/Knickers/src/xiaokai/knickers/mtp/Kick.java @@ -1,112 +1,149 @@ -package xiaokai.knickers.mtp; - -import java.io.File; -import java.util.LinkedHashMap; -import cn.nukkit.Player; -import cn.nukkit.utils.Config; -import xiaokai.knickers.Knickers; -import xiaokai.tool.Tool; -import xiaokai.tool.Update; - -/** - * @author Winfxk - */ -public class Kick { - public static Kick kick; - /** - * 插件主累对象 - */ - public Knickers mis; - /** - * 插件猪被子文件 config
- * 表单ID配置文件 formIdConfig - */ - public Config config, formIdConfig; - /** - * 系统配置文件的文件名 - */ - public String ConfigName = "Config.yml"; - /** - * 菜单主页文件名 - */ - public String MainFileName = "Main.yml"; - /** - * 表单ID存储类 - */ - public FormID formID; - /** - * 消息文件存储文件名 - */ - public String MsgName = "Message.yml"; - /** - * 消息文件类 - */ - public Message Message; - /** - * 要初始化的表单ID键值 - */ - public String[] FormIDName = { "主页", "添加按钮创建界面", "添加按钮输入数据界面", "删除按钮时显示按钮列表的界面", "删除按钮时提示时候删除的界面", - "显示在线玩家列表以供玩家传送的界面", "在Tpa传送的时候,目标玩家点击确定取消的界面", "{Msg}型命令执行界面", "子页4", "设置页面", "子页0", "子页1", "子页3", "子页2" }; - /** - * 表单ID存储位置 - */ - public String FormIDConfigName = "FormID.yml"; - /** - * 玩家数据库 - */ - public LinkedHashMap PlayerDataMap = new LinkedHashMap(); - /** - * 要检查默认设置的配置文件 - */ - public String[] LoadFileName = { ConfigName, MainFileName, MsgName }; - /** - * 要检查数据是否匹配的配置文件 - */ - public String[] isLoadFileName = { ConfigName, MsgName }; - /** - * 能创建的按钮的类型 - */ - public static final String[] ButtonTypeList = { "提示一个窗口", "打开一个新的界面", "执行命令", "定点传送", "传送到在线玩家" }; - /** - * 添加的菜单的配置文件存储位置 - */ - public static final String MenuConfigPath = "Menus/"; - /** - * 在启动服务器时检查文件夹是否创建,要检查的列表 - */ - public static final String[] LoadDirList = { MenuConfigPath }; - - public Kick(Knickers knickers) { - kick = this; - if (!knickers.getDataFolder().exists()) - knickers.getDataFolder().mkdirs(); - mis = knickers; - formIdConfig = new Config(new File(knickers.getDataFolder(), FormIDConfigName), Config.YAML); - (new Belle(this)).start(); - config = new Config(new File(knickers.getDataFolder(), ConfigName), Config.YAML); - formID = new FormID(this); - formID.setConfig(formIdConfig.getAll()); - new Thread() { - @Override - public void run() { - super.run(); - while (true) { - if (config.getBoolean("检测更新")) - (new Update(knickers)).start(); - try { - sleep(Tool.ObjectToInt(kick.config.get("检测更新间隔"), 500) * 1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - }.start(); - Message = new Message(this); - } - - public static boolean isAdmin(Player player) { - if (Kick.kick.config.getBoolean("仅允许白名单管理菜单")) - return Kick.kick.config.getList("白名单").contains(player.getName()); - return player.isOp(); - } -} +package xiaokai.knickers.mtp; + +import java.io.File; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.UUID; + +import cn.nukkit.Player; +import cn.nukkit.Server; +import cn.nukkit.command.CommandSender; +import cn.nukkit.utils.Config; +import xiaokai.knickers.Knickers; +import xiaokai.tool.Tool; +import xiaokai.tool.Update; + +/** + * @author Winfxk + */ +public class Kick { + public static Kick kick; + /** + * 插件主累对象 + */ + public Knickers mis; + /** + * 插件猪被子文件 config
+ * 表单ID配置文件 formIdConfig + */ + public Config config, formIdConfig; + /** + * 系统配置文件的文件名 + */ + public String ConfigName = "Config.yml"; + /** + * 菜单主页文件名 + */ + public String MainFileName = "Main.yml"; + /** + * 表单ID存储类 + */ + public FormID formID; + /** + * 消息文件存储文件名 + */ + public String MsgName = "Message.yml"; + /** + * 消息文件类 + */ + public Message Message; + /** + * 要初始化的表单ID键值 + */ + public String[] FormIDName = { "主页", "添加按钮创建界面", "添加按钮输入数据界面", "删除按钮时显示按钮列表的界面", "删除按钮时提示时候删除的界面", + "显示在线玩家列表以供玩家传送的界面", "在Tpa传送的时候,目标玩家点击确定取消的界面", "{Msg}型命令执行界面", "子页4", "设置页面", "子页0", "子页1", "子页3", "子页2" }; + /** + * 表单ID存储位置 + */ + public String FormIDConfigName = "FormID.yml"; + /** + * 玩家数据库 + */ + public LinkedHashMap PlayerDataMap = new LinkedHashMap(); + /** + * 要检查默认设置的配置文件 + */ + public String[] LoadFileName = { ConfigName, MainFileName, MsgName }; + /** + * 要检查数据是否匹配的配置文件 + */ + public String[] isLoadFileName = { ConfigName, MsgName }; + /** + * 能创建的按钮的类型 + */ + public static final String[] ButtonTypeList = { "提示一个窗口", "打开一个新的界面", "执行命令", "定点传送", "传送到在线玩家" }; + /** + * 添加的菜单的配置文件存储位置 + */ + public static final String MenuConfigPath = "Menus/"; + /** + * 在启动服务器时检查文件夹是否创建,要检查的列表 + */ + public static final String[] LoadDirList = { MenuConfigPath }; + + public Kick(Knickers knickers) { + kick = this; + if (!knickers.getDataFolder().exists()) + knickers.getDataFolder().mkdirs(); + mis = knickers; + formIdConfig = new Config(new File(knickers.getDataFolder(), FormIDConfigName), Config.YAML); + (new Belle(this)).start(); + config = new Config(new File(knickers.getDataFolder(), ConfigName), Config.YAML); + formID = new FormID(this); + formID.setConfig(formIdConfig.getAll()); + new Thread() { + @Override + public void run() { + super.run(); + while (true) { + try { + sleep(Tool.ObjectToInt(kick.config.get("检测更新间隔"), 500) * 1000); + if (config.getBoolean("检测更新")) + (new Update(knickers)).start(); + } catch (InterruptedException e) { + mis.getLogger().warning("自动检查更新遇到错误!" + e.getMessage()); + } + } + } + }.start(); + new Thread() { + @Override + public void run() { + super.run(); + while (true) { + try { + Object object = config.get("定时检查快捷工具间隔"); + String s = object == null ? "" : String.valueOf(object); + int time = Tool.ObjectToInt(s, 60); + if (time > 0) { + Map Players = Server.getInstance().getOnlinePlayers(); + for (UUID u : Players.keySet()) { + Player player = Players.get(u); + if (player.isOnline()) + Belle.exMaterials(player); + } + } + sleep((time < 1 ? 60 : time) * 1000); + } catch (InterruptedException e) { + mis.getLogger().warning("自动检查更玩家快捷工具遇到错误!" + e.getMessage()); + } + } + } + }.start(); + Message = new Message(this); + } + + public static boolean isAdmin(CommandSender player) { + if (!player.isPlayer()) + return true; + return isAdmin((Player) player); + } + + public static boolean isAdmin(Player player) { + if (!player.isPlayer()) + return true; + if (Kick.kick.config.getBoolean("仅允许白名单管理菜单")) + return Kick.kick.config.getList("白名单").contains(player.getName()); + return player.isOp(); + } +}