diff --git a/Javadoc.zip b/Javadoc.zip index 2103a6a..6d42e55 100644 Binary files a/Javadoc.zip and b/Javadoc.zip differ diff --git a/MiniatureS/plugin.yml b/MiniatureS/plugin.yml index 4f19d14..49884c5 100644 --- a/MiniatureS/plugin.yml +++ b/MiniatureS/plugin.yml @@ -2,7 +2,7 @@ name: MiniatureS main: cn.xiaokai.mis.MiniatureS api: - 1.0.0 -version: 2.2.0 +version: 2.3.0 load: POSTWORLD website: http://EpicFX.cn description: 支持多功能商店,如经验,物品的出售回收,物品的交换以及命令的购买使用等!并且支持多功能菜单,如传送、命令、提示等功能,并且支持多功能个人商店!并且支持自定义商品搜索等!后期还会加入更多功能哦! diff --git a/MiniatureS/resources/Config.yml b/MiniatureS/resources/Config.yml index efb48e9..e7afc05 100644 --- a/MiniatureS/resources/Config.yml +++ b/MiniatureS/resources/Config.yml @@ -1,7 +1,7 @@ #Mis配置文件 #帅帅的凯凯~ #请不要修改这个数据! -文件版本: 2019-6-5 +文件版本: 2019-6-9 #配置开始================== #每个玩家进服的时候都会给一个,当拿着这个玩意右键的时候打开菜单主页,特殊值可以不限定,当特殊值为x时默认匹配所有,特殊值默认为0,当这个值为空(null{在Yml文件内用~表示})时不适用快捷工具! 快捷工具: '347:0' @@ -12,4 +12,5 @@ 个人商店: true #上架每个物品到个人商店的价格 上架耗资: 0 -个人商店介绍修改费用: 1000 \ No newline at end of file +个人商店介绍修改费用: 1000 +检测更新: true \ No newline at end of file diff --git a/MiniatureS/resources/Message.yml b/MiniatureS/resources/Message.yml index a0a4d07..462e21f 100644 --- a/MiniatureS/resources/Message.yml +++ b/MiniatureS/resources/Message.yml @@ -1,5 +1,5 @@ #请不要修改这个数据! -文件版本: 2019-6-5 +文件版本: 2019-6-9 #各种可以自定义的内容 #注:若是可以使用变量,变量一律用{}包围,如{Server_Name} #注:变量对大小写敏感! diff --git "a/MiniatureS/resources/MiniatureS\350\207\252\345\256\232\344\271\211\346\216\247\344\273\266\344\273\213\347\273\215.docx" "b/MiniatureS/resources/MiniatureS\350\207\252\345\256\232\344\271\211\346\216\247\344\273\266\344\273\213\347\273\215.docx" new file mode 100644 index 0000000..b849ce5 Binary files /dev/null and "b/MiniatureS/resources/MiniatureS\350\207\252\345\256\232\344\271\211\346\216\247\344\273\266\344\273\213\347\273\215.docx" differ diff --git a/MiniatureS/src/cn/xiaokai/mis/EfficacyConfig.java b/MiniatureS/src/cn/xiaokai/mis/EfficacyConfig.java index ce9b6ba..afa76ae 100644 --- a/MiniatureS/src/cn/xiaokai/mis/EfficacyConfig.java +++ b/MiniatureS/src/cn/xiaokai/mis/EfficacyConfig.java @@ -3,7 +3,6 @@ import java.io.File; import cn.nukkit.utils.Config; -import cn.nukkit.utils.TextFormat; /** * @author Winfxk @@ -26,13 +25,10 @@ public static void startPY() { File file = new File(dirFile, fileName); try { new Config(file, Config.YAML); - MiniatureS.mis.getLogger().info(MiniatureS.Title + TextFormat.YELLOW + "文件" + TextFormat.GREEN - + dirFile.getName() + "/" + fileName + TextFormat.YELLOW + "效验成功!"); + MiniatureS.mis.getLogger().info("§e文件§6" + dirFile.getName() + "/" + fileName + "§e效验成功!"); } catch (Exception e) { - MiniatureS.mis.getLogger() - .info(MiniatureS.Title + TextFormat.RED + "文件" + TextFormat.GREEN + dirFile.getName() - + "/" + fileName + TextFormat.RED + "效验不通过!请检查!" + TextFormat.WHITE - + e.getMessage()); + MiniatureS.mis.getLogger().info( + "§4文件§6" + dirFile.getName() + "§4/§6" + fileName + "§4效验不通过!请检查!§f" + e.getMessage()); } } } diff --git a/MiniatureS/src/cn/xiaokai/mis/MiniatureS.java b/MiniatureS/src/cn/xiaokai/mis/MiniatureS.java index e3e3098..c867b6d 100644 --- a/MiniatureS/src/cn/xiaokai/mis/MiniatureS.java +++ b/MiniatureS/src/cn/xiaokai/mis/MiniatureS.java @@ -50,6 +50,7 @@ import cn.xiaokai.mis.cmd.ShopCommand; import cn.xiaokai.mis.event.FormCallback; import cn.xiaokai.mis.event.PlayerEvent; +import cn.xiaokai.mis.event.yousb.SBPlayerData; import cn.xiaokai.mis.form.MakeForm; import cn.xiaokai.mis.form.custom.CustomData; import cn.xiaokai.mis.form.openbt.HandsomeXiaoKai; @@ -59,6 +60,7 @@ import cn.xiaokai.mis.shop.ShopData; import cn.xiaokai.mis.shop.ShopMakeForm; import cn.xiaokai.mis.tool.Tool; +import cn.xiaokai.mis.tool.up.Update; /** * @author Winfxk @@ -187,7 +189,7 @@ public class MiniatureS extends PluginBase { * 存储自定义界面的数据 */ public LinkedHashMap Custom; - public LinkedHashMap MakeFormTime = new LinkedHashMap<>(); + public LinkedHashMap MakeFormTime = new LinkedHashMap<>(); /** * 明人不说暗话!这就是插件启动事件 @@ -247,12 +249,12 @@ public void onLoad() { try { file = new File(this.getDataFolder(), ConfigNameList[i]); if (!file.exists()) { - this.getServer().getLogger().info(TextFormat.RED + "初始化资源:" + TextFormat.GREEN + ConfigNameList[i]); + this.getServer().getLogger().info("§6初始化资源:§c" + ConfigNameList[i]); Utils.writeFile(file, this.getClass().getResourceAsStream("/resources/" + ConfigNameList[i])); } } catch (IOException e) { - this.getServer().getLogger().info(TextFormat.RED + "资源:" + TextFormat.GREEN + ConfigNameList[i] - + TextFormat.RED + "加载错误!\n" + TextFormat.WHITE + "错误详情:" + e.getMessage()); + this.getServer().getLogger() + .info("§4资源:§6" + ConfigNameList[i] + "§4加载错误!\n" + "§f错误详情:" + e.getMessage()); this.getServer().getPluginManager().disablePlugin(this); } ReloadConfig.start(); @@ -281,6 +283,14 @@ public void onLoad() { AdminCommand = new AdminCommand(this); Custom = new LinkedHashMap<>(); EfficacyConfig.startPY(); + if (config.getBoolean("检测更新")) + (new Update(this)).start(); + file = new File(getDataFolder(), "MiniatureS自定义控件介绍.docx"); + try { + Utils.writeFile(file, mis.getClass().getResourceAsStream("/resources/MiniatureS自定义控件介绍.docx")); + getLogger().info("§6帮助文件已导出至§4" + file.getName()); + } catch (IOException e) { + } super.onLoad(); } diff --git a/MiniatureS/src/cn/xiaokai/mis/cmd/MainCommand.java b/MiniatureS/src/cn/xiaokai/mis/cmd/MainCommand.java index 2d920f3..55a93b8 100644 --- a/MiniatureS/src/cn/xiaokai/mis/cmd/MainCommand.java +++ b/MiniatureS/src/cn/xiaokai/mis/cmd/MainCommand.java @@ -6,15 +6,12 @@ import cn.nukkit.Player; import cn.nukkit.command.CommandSender; -import cn.nukkit.inventory.Inventory; -import cn.nukkit.item.Item; -import cn.nukkit.item.enchantment.Enchantment; import cn.nukkit.utils.Config; import cn.nukkit.utils.TextFormat; import cn.xiaokai.mis.MiniatureS; +import cn.xiaokai.mis.event.yousb.FFFSB; import cn.xiaokai.mis.form.openbt.MakeWindow; import cn.xiaokai.mis.form.openbt.OpenButton; -import cn.xiaokai.mis.tool.Tool; /** * @author Winfxk @@ -36,34 +33,12 @@ public MainCommand(MiniatureS mis) { * @return */ public boolean onCommand(CommandSender player, String label, String[] a) { - if (a.length < 1 || a[0].toLowerCase().equals("get") || a[0].toLowerCase().equals("获取")) { + if (a.length < 1 || a[0].toLowerCase().equals("get")) { if (player.isPlayer()) { String makeTool = mis.config.getString("快捷工具", null); - if (makeTool != null && !makeTool.equals("")) { - Inventory inventory = ((Player) player).getInventory(); - Map map = inventory.getContents(); - Item item; - boolean Mate = false; - for (int site : map.keySet()) { - item = map.get(site); - if (Mate = Tool.isMateID(item.getId() + ":" + item.getDamage(), makeTool)) - break; - } - if (!Mate) { - int[] ID = Tool.IDtoFullID(makeTool); - item = new Item(ID[0], ID[1]); - item.addEnchantment(Enchantment.get(Enchantment.ID_SILK_TOUCH)); - item.setCustomName( - mis.getMessage().getMessage("快捷工具名称", new String[] { "{Player}", "{Server_Name}" }, - new String[] { player.getName(), mis.getServer().getMotd() })); - item.setLore( - mis.getMessage().getMessage("快捷工具名称2", new String[] { "{Player}", "{Server_Name}" }, - new String[] { player.getName(), mis.getServer().getMotd() })); - inventory.addItem(item); - player.sendMessage( - mis.getMessage().getMessage("进服给快捷工具", new String[] { "{Player}", "{Server_Name}" }, - new String[] { player.getName(), mis.getServer().getMotd() })); - } + if (makeTool != null && !makeTool.isEmpty()) { + FFFSB sb = new FFFSB((Player) player); + sb.getMis(); } mis.makeForm.makeMain((Player) player); } else @@ -89,26 +64,22 @@ public boolean onCommand(CommandSender player, String label, String[] a) { (new MakeWindow((Player) player, fxFile)).MakeForm(); else player.sendMessage(mis.getMessage().getSon("Main", "SBPlayerFileNot")); - } else { - if (fxFile.exists()) { - try { - Config config = new Config(fxFile, Config.YAML); - if (config.get("Buttons") instanceof Map) { - HashMap map = (HashMap) config.get("Buttons"); - if (map.containsKey(a[2])) { - (new OpenButton((Player) player, (HashMap) map.get(a[2]))).Switch(); - } else { - player.sendMessage(mis.getMessage().getSon("Main", "NotIsButtons")); - } - } else { - player.sendMessage(mis.getMessage().getSon("Main", "NotButtons")); - } - } catch (Exception e) { - player.sendMessage(mis.getMessage().getSon("Main", "SBOPFileError")); - } - } else - player.sendMessage(mis.getMessage().getSon("Main", "SBPlayerFileNot")); - } + } else if (fxFile.exists()) { + try { + Config config = new Config(fxFile, Config.YAML); + if (config.get("Buttons") instanceof Map) { + HashMap map = (HashMap) config.get("Buttons"); + if (map.containsKey(a[2])) { + (new OpenButton((Player) player, (HashMap) map.get(a[2]))).Switch(); + } else + player.sendMessage(mis.getMessage().getSon("Main", "NotIsButtons")); + } else + player.sendMessage(mis.getMessage().getSon("Main", "NotButtons")); + } catch (Exception e) { + player.sendMessage(mis.getMessage().getSon("Main", "SBOPFileError")); + } + } else + player.sendMessage(mis.getMessage().getSon("Main", "SBPlayerFileNot")); return true; case "help": default: diff --git a/MiniatureS/src/cn/xiaokai/mis/event/FormCallback.java b/MiniatureS/src/cn/xiaokai/mis/event/FormCallback.java index be08ff4..b8c7d76 100644 --- a/MiniatureS/src/cn/xiaokai/mis/event/FormCallback.java +++ b/MiniatureS/src/cn/xiaokai/mis/event/FormCallback.java @@ -11,6 +11,7 @@ import cn.nukkit.form.response.FormResponseSimple; import cn.nukkit.utils.Config; import cn.xiaokai.mis.MiniatureS; +import cn.xiaokai.mis.event.yousb.SBPlayerData; import cn.xiaokai.mis.form.MakeID; import cn.xiaokai.mis.form.custom.TheForce; import cn.xiaokai.mis.form.custom.sc.CustomReceive; @@ -55,114 +56,120 @@ public FormCallback(MiniatureS mis) { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) public void onPlayerForm(PlayerFormRespondedEvent e) { Player player = e.getPlayer(); - if (mis.MakeFormTime.containsKey(player.getName())) - mis.MakeFormTime.remove(player.getName()); - if (e.wasClosed() || e.getResponse() == null - || (!(e.getResponse() instanceof FormResponseCustom) && !(e.getResponse() instanceof FormResponseSimple) - && !(e.getResponse() instanceof FormResponseModal)) - || e.getPlayer() == null || MakeID.getByID(e.getFormID()) == null) - return; - mis.Menus = new Config(mis.getDataFolder() + "/Main.yml", 2); - FormResponse data = e.getResponse(); - switch (MakeID.getByID(e.getFormID())) { - case CustomTypeForm: - (new CustomReceive(player, (FormResponseCustom) data)).startPY(); - break; - case ModalTypeForm: - (new ModalReceive(player, (FormResponseModal) data)).startPY(); - break; - case SimpleTypeForm: - (new SimpleReceive(player, (FormResponseSimple) data)).startPY(); - break; - case MakeCustom: - (new TheForce(player)).startPY((FormResponseCustom) data); - break; - case SettingConfig: - (new ManagerProcessing(mis)).SettingConfig(player, (FormResponseCustom) data); - break; - case MyShopFormSeek: - (new BnsoxK(player, (FormResponseSimple) data)).Switch(); - break; - case startMyShopItem: - (new MyShop(player)).Switch((FormResponseCustom) data); - break; - case MyShopItem: - (new MyShopD(player)).MyShopItem((FormResponseSimple) data); - break; - case MyShopSeekMain: - (new MyShopD(player)).SeekMain((FormResponseCustom) data); - break; - case newMyShopItem: - (new MyShopD(player)).newMyShopItem((FormResponseCustom) data); - break; - case MyShopMain: - (new MyShopD(player)).Main((FormResponseSimple) data); - break; - case SonAddOpenWindow: - (new SonDisposeSwitch(mis, player)).addOpenWindow((FormResponseCustom) data); - break; - case SonAddOpenShow: - (new SonDisposeSwitch(mis, player)).addOpenShop((FormResponseCustom) data); - break; - case SonAddTransferForm: - (new SonDisposeSwitch(mis, player)).addTransfer((FormResponseCustom) data); - break; - case SonAddCommadnForm: - (new SonDisposeSwitch(mis, player)).addCommand((FormResponseCustom) data); - break; - case SonAddTipForm: - (new SonDisposeSwitch(mis, player)).addTip((FormResponseCustom) data); - break; - case SonAddButtonByType: - (new SonDispose()).Switch(player, (FormResponseSimple) data); - break; - case HeadIntoTheWater: - (new DonFiddle(player, (FormResponseCustom) data)).Rape(); - break; - case ShowWindow: - (new DealWith(player, (FormResponseSimple) data)).startPy(); - break; - case MakeRemoveButton: - (new MakeManagFrom(mis)).MakeIsRemoveButton(player, (FormResponseSimple) data); - break; - case MakeIsRemoveButton: - (new ManagerProcessing(mis)).RemoveButton(player, (FormResponseModal) data); - break; - case PlayerShopInteract: - (new ItemCallback(mis, player, (FormResponseCustom) data)).start(); - break; - case AddItemToItem: - shopDispose.AddItemToItem(player, (FormResponseCustom) data); - break; - case AddExpShop: - shopDispose.AddExpShop(player, (FormResponseCustom) data); - break; - case AddExpSell: - shopDispose.AddExpSell(player, (FormResponseCustom) data); - break; - case AddItemShop: - shopDispose.AddItemShop(player, (FormResponseCustom) data); - break; - case AddItemSell: - shopDispose.AddItemSell(player, (FormResponseCustom) data); - break; - case AddShopType: - shopDispose.SelectShopType(player, ((FormResponseSimple) data).getClickedButtonId()); - break; - case Shop: - shopDispose.Shop(player, (FormResponseSimple) data); - break; - case ShopAddShop: - shopDispose.addShopShow(player, (FormResponseCustom) data); - break; - case ShopMain: - shopDispose.Main(player, (FormResponseSimple) data); - break; - case MainFormID: - dispose.Main(player, (FormResponseSimple) data); - break; - default: - break; + if (MakeID.getByID(e.getFormID()) != null && e.getPlayer() != null) { + SBPlayerData sb = mis.MakeFormTime.containsKey(player.getName()) + ? mis.MakeFormTime.get(player.getName()) == null ? new SBPlayerData() + : mis.MakeFormTime.get(player.getName()) + : new SBPlayerData(); + sb.Open = false; + mis.MakeFormTime.put(player.getName(), sb); + if (e.wasClosed() || e.getResponse() == null + || (!(e.getResponse() instanceof FormResponseCustom) + && !(e.getResponse() instanceof FormResponseSimple) + && !(e.getResponse() instanceof FormResponseModal))) + return; + mis.Menus = new Config(mis.getDataFolder() + "/Main.yml", 2); + FormResponse data = e.getResponse(); + switch (MakeID.getByID(e.getFormID())) { + case CustomTypeForm: + (new CustomReceive(player, (FormResponseCustom) data)).startPY(); + break; + case ModalTypeForm: + (new ModalReceive(player, (FormResponseModal) data)).startPY(); + break; + case SimpleTypeForm: + (new SimpleReceive(player, (FormResponseSimple) data)).startPY(); + break; + case MakeCustom: + (new TheForce(player)).startPY((FormResponseCustom) data); + break; + case SettingConfig: + (new ManagerProcessing(mis)).SettingConfig(player, (FormResponseCustom) data); + break; + case MyShopFormSeek: + (new BnsoxK(player, (FormResponseSimple) data)).Switch(); + break; + case startMyShopItem: + (new MyShop(player)).Switch((FormResponseCustom) data); + break; + case MyShopItem: + (new MyShopD(player)).MyShopItem((FormResponseSimple) data); + break; + case MyShopSeekMain: + (new MyShopD(player)).SeekMain((FormResponseCustom) data); + break; + case newMyShopItem: + (new MyShopD(player)).newMyShopItem((FormResponseCustom) data); + break; + case MyShopMain: + (new MyShopD(player)).Main((FormResponseSimple) data); + break; + case SonAddOpenWindow: + (new SonDisposeSwitch(mis, player)).addOpenWindow((FormResponseCustom) data); + break; + case SonAddOpenShow: + (new SonDisposeSwitch(mis, player)).addOpenShop((FormResponseCustom) data); + break; + case SonAddTransferForm: + (new SonDisposeSwitch(mis, player)).addTransfer((FormResponseCustom) data); + break; + case SonAddCommadnForm: + (new SonDisposeSwitch(mis, player)).addCommand((FormResponseCustom) data); + break; + case SonAddTipForm: + (new SonDisposeSwitch(mis, player)).addTip((FormResponseCustom) data); + break; + case SonAddButtonByType: + (new SonDispose()).Switch(player, (FormResponseSimple) data); + break; + case HeadIntoTheWater: + (new DonFiddle(player, (FormResponseCustom) data)).Rape(); + break; + case ShowWindow: + (new DealWith(player, (FormResponseSimple) data)).startPy(); + break; + case MakeRemoveButton: + (new MakeManagFrom(mis)).MakeIsRemoveButton(player, (FormResponseSimple) data); + break; + case MakeIsRemoveButton: + (new ManagerProcessing(mis)).RemoveButton(player, (FormResponseModal) data); + break; + case PlayerShopInteract: + (new ItemCallback(mis, player, (FormResponseCustom) data)).start(); + break; + case AddItemToItem: + shopDispose.AddItemToItem(player, (FormResponseCustom) data); + break; + case AddExpShop: + shopDispose.AddExpShop(player, (FormResponseCustom) data); + break; + case AddExpSell: + shopDispose.AddExpSell(player, (FormResponseCustom) data); + break; + case AddItemShop: + shopDispose.AddItemShop(player, (FormResponseCustom) data); + break; + case AddItemSell: + shopDispose.AddItemSell(player, (FormResponseCustom) data); + break; + case AddShopType: + shopDispose.SelectShopType(player, ((FormResponseSimple) data).getClickedButtonId()); + break; + case Shop: + shopDispose.Shop(player, (FormResponseSimple) data); + break; + case ShopAddShop: + shopDispose.addShopShow(player, (FormResponseCustom) data); + break; + case ShopMain: + shopDispose.Main(player, (FormResponseSimple) data); + break; + case MainFormID: + dispose.Main(player, (FormResponseSimple) data); + break; + default: + break; + } } } } diff --git a/MiniatureS/src/cn/xiaokai/mis/event/PlayerEvent.java b/MiniatureS/src/cn/xiaokai/mis/event/PlayerEvent.java index 54308cd..0a02315 100644 --- a/MiniatureS/src/cn/xiaokai/mis/event/PlayerEvent.java +++ b/MiniatureS/src/cn/xiaokai/mis/event/PlayerEvent.java @@ -1,6 +1,7 @@ package cn.xiaokai.mis.event; -import java.util.Map; +import java.time.Duration; +import java.time.Instant; import cn.nukkit.Player; import cn.nukkit.event.EventHandler; @@ -12,13 +13,12 @@ import cn.nukkit.event.player.PlayerJoinEvent; import cn.nukkit.event.player.PlayerQuitEvent; import cn.nukkit.event.player.PlayerRespawnEvent; -import cn.nukkit.inventory.Inventory; import cn.nukkit.item.Item; -import cn.nukkit.item.enchantment.Enchantment; -import cn.nukkit.utils.Config; +import cn.nukkit.nbt.tag.CompoundTag; import cn.xiaokai.mis.MiniatureS; +import cn.xiaokai.mis.event.yousb.FFFSB; import cn.xiaokai.mis.event.yousb.Fuck; -import cn.xiaokai.mis.myshop.CPlayer; +import cn.xiaokai.mis.event.yousb.SBPlayerData; import cn.xiaokai.mis.tool.Tool; /** @@ -76,13 +76,22 @@ public void onPlayerBreak(BlockBreakEvent e) { if (makeTool == null || makeTool.equals("")) return; Item item = e.getItem(); + Player player = e.getPlayer(); + SBPlayerData data = mis.MakeFormTime.containsKey(player.getName()) + ? mis.MakeFormTime.get(player.getName()) == null ? new SBPlayerData() + : mis.MakeFormTime.get(player.getName()) + : new SBPlayerData(); if (item != null && Tool.isMateID(item.getId() + ":" + item.getDamage(), makeTool) - && e.getPlayer().getGamemode() == 1) { + && (data == null || data.Open != true + || ((float) (Duration.between(data.OpenTime, Instant.now()).toMillis()) / 1000) > 1)) { e.setCancelled(); + data.Open = true; + data.OpenTime = Instant.now(); + mis.MakeFormTime.put(player.getName(), data); if (!mis.config.getBoolean("快捷打开为商店")) - mis.makeForm.makeMain(e.getPlayer()); + mis.makeForm.makeMain(player); else - mis.shopMakeForm.MakeMain(e.getPlayer()); + mis.shopMakeForm.MakeMain(player); } } @@ -97,15 +106,27 @@ public void onPlayerInteract(PlayerInteractEvent e) { if (makeTool == null || makeTool.equals("")) return; Item item = e.getItem(); - if (item != null && e.getAction() != null - && (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) - && Tool.isMateID(item.getId() + ":" + item.getDamage(), makeTool) && e.getPlayer().getGamemode() != 1 - && item.getEnchantments().length > 0) { + CompoundTag Tag = item.getNamedTag(); + Action action = e.getAction(); + Player player = e.getPlayer(); + SBPlayerData data = mis.MakeFormTime.containsKey(player.getName()) + ? mis.MakeFormTime.get(player.getName()) == null ? new SBPlayerData() + : mis.MakeFormTime.get(player.getName()) + : new SBPlayerData(); + if (item != null && Tool.isMateID(makeTool, item.getId() + ":" + item.getDamage()) + && Tag.getString("快捷工具名称").equals(mis.getMessage().getMessage("快捷工具名称")) && action != null + && (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK + || action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) + && (data == null || data.Open != true + || ((float) (Duration.between(data.OpenTime, Instant.now()).toMillis()) / 1000) > 1)) { e.setCancelled(); + data.Open = true; + data.OpenTime = Instant.now(); + mis.MakeFormTime.put(player.getName(), data); if (!mis.config.getBoolean("快捷打开为商店")) - mis.makeForm.makeMain(e.getPlayer()); + mis.makeForm.makeMain(player); else - mis.shopMakeForm.MakeMain(e.getPlayer()); + mis.shopMakeForm.MakeMain(player); } } @@ -119,28 +140,8 @@ public void onPlayerSpawn(PlayerRespawnEvent e) { String makeTool = mis.config.getString("快捷工具", null); if (makeTool == null || makeTool.equals("")) return; - Player player = e.getPlayer(); - Inventory inventory = player.getInventory(); - Map map = inventory.getContents(); - Item item; - boolean Mate = false; - for (int site : map.keySet()) { - item = map.get(site); - if (Mate = Tool.isMateID(item.getId() + ":" + item.getDamage(), makeTool)) - break; - } - if (!Mate) { - int[] ID = Tool.IDtoFullID(makeTool); - item = new Item(ID[0], ID[1]); - item.addEnchantment(Enchantment.get(Enchantment.ID_SILK_TOUCH)); - item.setCustomName(mis.getMessage().getMessage("快捷工具名称", new String[] { "{Player}", "{Server_Name}" }, - new String[] { player.getName(), mis.getServer().getMotd() })); - item.setLore(mis.getMessage().getMessage("快捷工具名称2", new String[] { "{Player}", "{Server_Name}" }, - new String[] { player.getName(), mis.getServer().getMotd() })); - inventory.addItem(item); - player.sendMessage(mis.getMessage().getMessage("进服给快捷工具", new String[] { "{Player}", "{Server_Name}" }, - new String[] { player.getName(), mis.getServer().getMotd() })); - } + FFFSB sb = new FFFSB(e.getPlayer()); + sb.getMis(); } /** @@ -150,37 +151,12 @@ public void onPlayerSpawn(PlayerRespawnEvent e) { */ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false) public void onJoin(PlayerJoinEvent e) { + Player player = e.getPlayer(); String makeTool = mis.config.getString("快捷工具", null); + (new Fuck()).Switch(player); if (makeTool == null || makeTool.equals("")) return; - Player player = e.getPlayer(); - Inventory inventory = player.getInventory(); - Map map = inventory.getContents(); - if (!CPlayer.isPlayerConfig(player)) { - Config cp = CPlayer.getPlayerConfig(player); - player.sendMessage(mis.getMessage().getMessage("玩家加入提示1")); - cp.setAll(CPlayer.getConfig()); - cp.save(); - } - Item item; - boolean Mate = false; - for (int site : map.keySet()) { - item = map.get(site); - if (Mate = Tool.isMateID(item.getId() + ":" + item.getDamage(), makeTool)) - break; - } - if (!Mate) { - int[] ID = Tool.IDtoFullID(makeTool); - item = new Item(ID[0], ID[1]); - item.addEnchantment(Enchantment.get(Enchantment.ID_SILK_TOUCH)); - item.setCustomName(mis.getMessage().getMessage("快捷工具名称", new String[] { "{Player}", "{Server_Name}" }, - new String[] { player.getName(), mis.getServer().getMotd() })); - item.setLore(mis.getMessage().getMessage("快捷工具名称2", new String[] { "{Player}", "{Server_Name}" }, - new String[] { player.getName(), mis.getServer().getMotd() })); - inventory.addItem(item); - player.sendMessage(mis.getMessage().getMessage("进服给快捷工具", new String[] { "{Player}", "{Server_Name}" }, - new String[] { player.getName(), mis.getServer().getMotd() })); - } - (new Fuck()).Switch(player); + FFFSB sb = new FFFSB(player); + sb.getMis(); } } diff --git a/MiniatureS/src/cn/xiaokai/mis/event/yousb/FFFSB.java b/MiniatureS/src/cn/xiaokai/mis/event/yousb/FFFSB.java new file mode 100644 index 0000000..d77bed1 --- /dev/null +++ b/MiniatureS/src/cn/xiaokai/mis/event/yousb/FFFSB.java @@ -0,0 +1,86 @@ +package cn.xiaokai.mis.event.yousb; + +import java.util.Map; + +import cn.nukkit.Player; +import cn.nukkit.inventory.PlayerInventory; +import cn.nukkit.item.Item; +import cn.nukkit.item.enchantment.Enchantment; +import cn.nukkit.nbt.tag.CompoundTag; +import cn.xiaokai.mis.MiniatureS; +import cn.xiaokai.mis.tool.ItemIDSunName; +import cn.xiaokai.mis.tool.Tool; + +/** + * @author Winfxk + */ +public class FFFSB { + private Player player; + private MiniatureS mis; + private PlayerInventory inventory; + + /** + * 玩家快捷工具检查类 + * + * @param player + */ + public FFFSB(Player player) { + this.player = player; + mis = MiniatureS.mis; + inventory = player.getInventory(); + } + + /** + * 检测并判断玩家是否有快捷工具,没有的话给与一个 + */ + public void getMis() { + if (!isSB()) { + inventory.addItem(getItem()); + player.sendMessage(mis.getMessage().getMessage("进服给快捷工具")); + } + } + + /** + * 获取一个配置完毕的快捷工具的物品对象 + * + * @return + */ + public static Item getItem() { + String idString = ItemIDSunName.UnknownToID(MiniatureS.mis.config.getString("快捷工具")); + String[] strings = idString.split(":"); + int ID = Integer.valueOf(strings[0]); + int Meta = Integer.valueOf(strings[1]); + Item item = new Item(ID, Meta); + item.setCustomName(MiniatureS.mis.getMessage().getMessage("快捷工具名称")); + item.setLore(MiniatureS.mis.getMessage().getMessage("快捷工具名称2")); + CompoundTag Tag = item.getNamedTag() == null ? new CompoundTag() : item.getNamedTag(); + Tag.putString("快捷工具名称", MiniatureS.mis.getMessage().getMessage("快捷工具名称")); + item.setNamedTag(Tag); + item.addEnchantment(Enchantment.get(Enchantment.ID_SILK_TOUCH)); + return item; + } + + /** + * 判断玩家背包是否有快捷工具 + * + * @return + */ + public boolean isSB() { + Map items = inventory.getContents(); + MiniatureS mis = MiniatureS.mis; + String ID = ItemIDSunName.UnknownToID(mis.config.getString("快捷工具")); + for (Integer ike : items.keySet()) { + Item item = items.get(ike); + if (Tool.isMateID(ID, item.getId() + ":" + item.getDamage())) { + CompoundTag Tag = item.getNamedTag(); + if (Tag != null) { + String string = Tag.getString("快捷工具名称"); + if (string != null && string.equals(mis.getMessage().getMessage("快捷工具名称"))) + return true; + } + } + } + return false; + } + +} diff --git a/MiniatureS/src/cn/xiaokai/mis/event/yousb/SBPlayerData.java b/MiniatureS/src/cn/xiaokai/mis/event/yousb/SBPlayerData.java new file mode 100644 index 0000000..71b259a --- /dev/null +++ b/MiniatureS/src/cn/xiaokai/mis/event/yousb/SBPlayerData.java @@ -0,0 +1,11 @@ +package cn.xiaokai.mis.event.yousb; + +import java.time.Instant; + +/** + * @author Winfxk + */ +public class SBPlayerData { + public boolean Open = false; + public Instant OpenTime = Instant.now(); +} diff --git a/MiniatureS/src/cn/xiaokai/mis/form/MakeForm.java b/MiniatureS/src/cn/xiaokai/mis/form/MakeForm.java index 994a7e5..8714e73 100644 --- a/MiniatureS/src/cn/xiaokai/mis/form/MakeForm.java +++ b/MiniatureS/src/cn/xiaokai/mis/form/MakeForm.java @@ -37,10 +37,6 @@ public MakeForm(MiniatureS mis) { */ @SuppressWarnings("unchecked") public void makeMain(Player player) { - Boolean loadTime = mis.MakeFormTime.get(player.getName()); - if (loadTime != null) - return; - mis.MakeFormTime.put(player.getName(), true); Config Menus = new Config(mis.getDataFolder() + "/Main.yml", 2); HashMap AllMap = (Menus.get("Buttons") instanceof Map) ? (HashMap) (Menus.get("Buttons")) diff --git a/MiniatureS/src/cn/xiaokai/mis/form/openbt/OpenButton.java b/MiniatureS/src/cn/xiaokai/mis/form/openbt/OpenButton.java index 3c8540a..3bc3052 100644 --- a/MiniatureS/src/cn/xiaokai/mis/form/openbt/OpenButton.java +++ b/MiniatureS/src/cn/xiaokai/mis/form/openbt/OpenButton.java @@ -151,7 +151,7 @@ private void PlayerClickCommandType() { } else if (ePlugin == null || !ePlugin.isEnabled()) mis.getLogger().info("§4警告:§6EconomyAPI§4未安装或未启用!本次忽略§9" + player.getName() + "§4的扣费!"); if (Command != null && !Command.isEmpty()) - if (!String.valueOf(Button.get("Commander")).toLowerCase().equals("player")) + if (String.valueOf(Button.get("Commander")).toLowerCase().equals("console")) Server.getInstance().dispatchCommand(new ConsoleCommandSender(), Command); else Server.getInstance().dispatchCommand(player, Command); diff --git a/MiniatureS/src/cn/xiaokai/mis/form/openbt/overfed/DonFiddle.java b/MiniatureS/src/cn/xiaokai/mis/form/openbt/overfed/DonFiddle.java index 0822a46..5296e0a 100644 --- a/MiniatureS/src/cn/xiaokai/mis/form/openbt/overfed/DonFiddle.java +++ b/MiniatureS/src/cn/xiaokai/mis/form/openbt/overfed/DonFiddle.java @@ -63,7 +63,7 @@ public void Rape() { new String[] { "{Money}" }, new Object[] { Money })); } if (SX != null && !SX.isEmpty()) - if (String.valueOf(kai.Button.get("Commander")).toLowerCase() == "player") + if (!String.valueOf(kai.Button.get("Commander")).toLowerCase().equals("console")) Server.getInstance().dispatchCommand(player, SX); else Server.getInstance().dispatchCommand(new ConsoleCommandSender(), SX); diff --git a/MiniatureS/src/cn/xiaokai/mis/msg/ReloadConfig.java b/MiniatureS/src/cn/xiaokai/mis/msg/ReloadConfig.java index 6a1a634..9ff684a 100644 --- a/MiniatureS/src/cn/xiaokai/mis/msg/ReloadConfig.java +++ b/MiniatureS/src/cn/xiaokai/mis/msg/ReloadConfig.java @@ -2,10 +2,6 @@ import java.io.File; import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import cn.nukkit.utils.Config; import cn.nukkit.utils.TextFormat; import cn.nukkit.utils.Utils; @@ -14,9 +10,8 @@ /** * @author Winfxk */ -@SuppressWarnings("unchecked") public class ReloadConfig { - public static final String V = "2019-6-5"; + public static final String V = "2019-6-9"; public static final String[] Files = { "Config.yml", "Message.yml" }; public static final String V_Key = "文件版本"; @@ -29,34 +24,11 @@ public static void start() { for (String name : Files) { file = new File(mis.getDataFolder(), name); Config config = new Config(file, Config.YAML); - HashMap map = (config.getAll() instanceof Map) ? (HashMap) config.getAll() - : new HashMap<>(); - if (config.getString(V_Key) != V) { + if (!config.getString(V_Key).equals(V)) { file.delete(); try { - if (!file.exists()) { - mis.getServer().getLogger().info(TextFormat.RED + "更新资源:" + TextFormat.GREEN + name); - Utils.writeFile(file, mis.getClass().getResourceAsStream("/resources/" + name)); - file = new File(mis.getDataFolder(), name); - config = new Config(file, Config.YAML); - config.set(V_Key, V); - config.save(); - for (String key : map.keySet()) { - if (!key.equals(V_Key) && !(map.get(key) instanceof Map) && !(map.get(key) instanceof List) - && config.get(key) != null - && config.get(key).getClass().equals(map.get(key).getClass()) - && !map.get(key).equals(config.get(key))) { - config.set(key, map.get(key)); - mis.getServer().getLogger().info(TextFormat.RED + "正在还原数据:" + key); - } - if ((map.get(key) instanceof Map) && !map.get(key).equals(config.get(key)) - && config.get(key) != null) { - mis.getServer().getLogger().info(TextFormat.RED + "正在还原数据列:" + key); - config.set(key, reloadMap(config.getSection(key), map)); - } - } - config.save(); - } + mis.getServer().getLogger().info(TextFormat.RED + "更新资源:" + TextFormat.GREEN + name); + Utils.writeFile(file, mis.getClass().getResourceAsStream("/resources/" + name)); } catch (IOException e) { mis.getServer().getLogger().info(TextFormat.RED + "资源:" + TextFormat.GREEN + name + TextFormat.RED + "加载错误!\n" + TextFormat.WHITE + "错误详情:" + e.getMessage()); @@ -65,28 +37,4 @@ public static void start() { } } } - - /** - * 还原配置 - * - * @param config_map 新的配置数据 - * @param l_map 原来的配置数据 - * @return - */ - public static Map reloadMap(Map config_map, Map l_map) { - for (String key : l_map.keySet()) { - if (!(config_map.get(key) instanceof Map) && l_map.get(key) != null) { - if (config_map.get(key) != null && config_map.get(key).getClass().equals(l_map.get(key).getClass()) - && !l_map.get(key).equals(config_map.get(key))) { - config_map.put(key, l_map.get(key)); - MiniatureS.mis.getServer().getLogger().info(TextFormat.RED + "正在还原数据:" + key); - } - } else if ((l_map.get(key) instanceof Map) && !l_map.get(key).equals(config_map.get(key))) { - MiniatureS.mis.getServer().getLogger().info(TextFormat.RED + "正在还原数据列:" + key); - config_map.put(key, - reloadMap((Map) config_map.get(key), (Map) l_map.get(key))); - } - } - return config_map; - } } diff --git a/MiniatureS/src/cn/xiaokai/mis/shop/DataDispose.java b/MiniatureS/src/cn/xiaokai/mis/shop/DataDispose.java index 20dd9f0..7733b88 100644 --- a/MiniatureS/src/cn/xiaokai/mis/shop/DataDispose.java +++ b/MiniatureS/src/cn/xiaokai/mis/shop/DataDispose.java @@ -1,6 +1,7 @@ package cn.xiaokai.mis.shop; import java.util.ArrayList; +import java.util.HashMap; import cn.nukkit.Player; import cn.nukkit.form.response.FormResponseCustom; @@ -84,22 +85,92 @@ public void AddItemToItem(Player player, FormResponseCustom data) { int Min = Float.valueOf(String.valueOf(data.getResponse(3))).intValue(); int Max = Float.valueOf(String.valueOf(data.getResponse(4))).intValue(); int ItemCount = Float.valueOf(String.valueOf(data.getResponse(5))).intValue(); - ArrayList BlockIDs = new ArrayList(); + HashMap BlockIDs = new HashMap(); if (BlockID.contains(";")) { String[] BlockIDx = BlockID.split(";"); for (String B : BlockIDx) if (B != null && !B.isEmpty()) - BlockIDs.add(ItemIDSunName.UnknownToID(B)); + if (B.contains("=>")) { + String[] Bs = B.split("=>"); + B = ItemIDSunName.UnknownToID(Bs[0]); + if (Bs[1] == null || Bs[1].isEmpty()) { + MakeForm.makeTip(player, "§4请输入§6" + ItemIDSunName.getIDByName(B) + "§4的物品数量"); + return; + } + if (!Tool.isInteger(Bs[1])) { + MakeForm.makeTip(player, "§6" + ItemIDSunName.getIDByName(B) + "§4的物品数量仅能为大于零的纯整数!"); + return; + } + int isCount = Float.valueOf(Bs[1]).intValue(); + if (isCount < 1) { + MakeForm.makeTip(player, "§6" + ItemIDSunName.getIDByName(B) + "§4的物品数量仅能为大于零的纯整数!"); + return; + } + BlockIDs.put(B, isCount); + } else + BlockIDs.put(ItemIDSunName.UnknownToID(B), 1); + } else if (BlockID.contains("=>")) { + String[] Bs = BlockID.split("=>"); + BlockID = ItemIDSunName.UnknownToID(Bs[0]); + if (Bs[1] == null || Bs[1].isEmpty()) { + MakeForm.makeTip(player, "§4请输入§6" + ItemIDSunName.getIDByName(BlockID) + "§4的物品数量"); + return; + } + if (!Tool.isInteger(Bs[1])) { + MakeForm.makeTip(player, "§6" + ItemIDSunName.getIDByName(BlockID) + "§4的物品数量仅能为大于零的纯整数!"); + return; + } + int isCount = Float.valueOf(Bs[1]).intValue(); + if (isCount < 1) { + MakeForm.makeTip(player, "§6" + ItemIDSunName.getIDByName(BlockID) + "§4的物品数量仅能为大于零的纯整数!"); + return; + } + BlockIDs.put(BlockID, isCount); } else - BlockIDs.add(ItemIDSunName.UnknownToID(BlockID)); - ArrayList ToBlockIDs = new ArrayList<>(); + BlockIDs.put(ItemIDSunName.UnknownToID(BlockID), 1); + HashMap ToBlockIDs = new HashMap(); if (ToBlockID.contains(";")) { String[] ToBlockIDx = ToBlockID.split(";"); for (String I : ToBlockIDx) if (I != null && !I.isEmpty()) - ToBlockIDs.add(ItemIDSunName.UnknownToID(I)); + if (I.contains("=>")) { + String[] Bs = I.split("=>"); + I = ItemIDSunName.UnknownToID(Bs[0]); + if (Bs[1] == null || Bs[1].isEmpty()) { + MakeForm.makeTip(player, "§4请输入§6" + ItemIDSunName.getIDByName(I) + "§4的物品数量"); + return; + } + if (!Tool.isInteger(Bs[1])) { + MakeForm.makeTip(player, "§6" + ItemIDSunName.getIDByName(I) + "§4的物品数量仅能为大于零的纯整数!"); + return; + } + int isCount = Float.valueOf(Bs[1]).intValue(); + if (isCount < 1) { + MakeForm.makeTip(player, "§6" + ItemIDSunName.getIDByName(I) + "§4的物品数量仅能为大于零的纯整数!"); + return; + } + ToBlockIDs.put(I, isCount); + } else + ToBlockIDs.put(ItemIDSunName.UnknownToID(I), 1); + } else if (ToBlockID.contains("=>")) { + String[] Bs = ToBlockID.split("=>"); + ToBlockID = ItemIDSunName.UnknownToID(Bs[0]); + if (Bs[1] == null || Bs[1].isEmpty()) { + MakeForm.makeTip(player, "§4请输入§6" + ItemIDSunName.getIDByName(ToBlockID) + "§4的物品数量"); + return; + } + if (!Tool.isInteger(Bs[1])) { + MakeForm.makeTip(player, "§6" + ItemIDSunName.getIDByName(ToBlockID) + "§4的物品数量仅能为大于零的纯整数!"); + return; + } + int isCount = Float.valueOf(Bs[1]).intValue(); + if (isCount < 1) { + MakeForm.makeTip(player, "§6" + ItemIDSunName.getIDByName(ToBlockID) + "§4的物品数量仅能为大于零的纯整数!"); + return; + } + ToBlockIDs.put(ToBlockID, isCount); } else - ToBlockIDs.add(ItemIDSunName.UnknownToID(ToBlockID)); + ToBlockIDs.put(ItemIDSunName.UnknownToID(ToBlockID), 1); (new Shop(mis)).AddItemToItem(mis.PlayerMenuBack.get(player.getName()), player, Money, BlockIDs, ToBlockIDs, Min, Max, ItemCount); } diff --git a/MiniatureS/src/cn/xiaokai/mis/shop/ItemCallback.java b/MiniatureS/src/cn/xiaokai/mis/shop/ItemCallback.java index fc66add..001af35 100644 --- a/MiniatureS/src/cn/xiaokai/mis/shop/ItemCallback.java +++ b/MiniatureS/src/cn/xiaokai/mis/shop/ItemCallback.java @@ -208,7 +208,6 @@ private void ItemToItem() { + mis.config.getString("货币单位")) : ""); player.sendMessage(sssss); - this.remove(); } /** @@ -256,7 +255,6 @@ private void SellExp() { player.setExperience(player.getExperience(), (player.getExperienceLevel() - Count)); player.sendMessage(mis.getMessage().getSon("Shop", "ExpPyOKNotSB", new String[] { "{Count}", "{Money}" }, new Object[] { Count, Money })); - this.remove(); } /** @@ -306,7 +304,6 @@ private void ShopExp() { player.setExperience(player.getExperience(), (player.getExperienceLevel() + Count)); player.sendMessage(mis.getMessage().getSon("Shop", "ExpPyOKNotSbShop", new String[] { "{Count}", "{Money}" }, new Object[] { Count, Money })); - this.remove(); } /** @@ -359,7 +356,6 @@ private void ShopItem() { EconomyAPI.getInstance().reduceMoney(player, Money); player.sendMessage(mis.getMessage().getSon("Shop", "ShopItemOKNotSB", new String[] { "{ItemName}", "{Money}" }, new Object[] { ItemIDSunName.getIDByName(IDi), Money })); - this.remove(); } /** @@ -405,7 +401,9 @@ private void SellItem() { .valueOf(((HashMap) mis.ShopListConfig.get("Buttons")).get(value.ShopKey)); Config config = new Config(new File(mis.getDataFolder() + MiniatureS.ShopConfigPath, ShopConfigName), Config.YAML); - HashMap ppap = (HashMap) config.get("Buttons"); + HashMap ppap = (config.get("Buttons") != null && config.get("Buttons") instanceof Map) + ? (HashMap) config.get("Buttons") + : new HashMap<>(); ppap.put(value.itemKey, map); config.set("Buttons", ppap); config.save(); @@ -418,19 +416,5 @@ private void SellItem() { player.sendMessage(mis.getMessage().getSon("Shop", "PYItemOKNotSB", new String[] { "{Count}", "{ItemName}", "{Money}" }, new Object[] { Count, ItemIDSunName.getIDByName(IDi), (Count * Float.valueOf(String.valueOf(map.get("Money")))) })); - this.remove(); - } - - private void remove() { - if (mis.PlayerShopInteract.get(player.getName()) != null) - mis.PlayerShopInteract.remove(player.getName()); - if (mis.PlayerMenuBack.get(player.getName()) != null) - mis.PlayerMenuBack.remove(player.getName()); - if (mis.shopList.get(player.getName()) != null) - mis.shopList.remove(player.getName()); - if (mis.PlayerMenu.get(player.getName()) != null) - mis.PlayerMenu.remove(player.getName()); - if (mis.PlayerShopItemData.get(player.getName()) != null) - mis.PlayerShopItemData.remove(player.getName()); } } diff --git a/MiniatureS/src/cn/xiaokai/mis/shop/Shop.java b/MiniatureS/src/cn/xiaokai/mis/shop/Shop.java index e2e8013..91bc9c9 100644 --- a/MiniatureS/src/cn/xiaokai/mis/shop/Shop.java +++ b/MiniatureS/src/cn/xiaokai/mis/shop/Shop.java @@ -41,8 +41,8 @@ public Shop(MiniatureS mis) { * @param Max 每次最多能兑换多少个 * @param ItemCount 库存 */ - public void AddItemToItem(String Key, Player player, int Money, ArrayList BlockID, - ArrayList ToBlockID, int Min, int Max, int ItemCount) { + public void AddItemToItem(String Key, Player player, int Money, HashMap BlockID, + HashMap ToBlockID, int Min, int Max, int ItemCount) { boolean Astrict = (ItemCount > 0); ItemCount = ItemCount >= 0 ? ItemCount : 0; HashMap map = new HashMap<>(); @@ -77,16 +77,16 @@ public void AddItemToItem(String Key, Player player, int Money, ArrayList 1 - ? ItemIDSunName.getIDByName(BlockID.get(Tool.getRand(0, BlockID.size() - 1))) + "§6等§f" - + BlockID.size() + "§6个物品" - : ItemIDSunName.getIDByName(BlockID.get(0))) + + (BlockID.size() > 1 ? ItemIDSunName.getIDByName(BlockID.get(Keys1[Tool.getRand(0, Keys1.length - 1)])) + + "§6等§f" + BlockID.size() + "§6个物品" : ItemIDSunName.getIDByName(BlockID.get(Keys1[0]))) + "§6兑换§4" + (ToBlockID.size() > 1 - ? ItemIDSunName.getIDByName(ToBlockID.get(Tool.getRand(0, ToBlockID.size() - 1))) + "§6等§4" + ? ItemIDSunName.getIDByName(ToBlockID.get(Keys2[Tool.getRand(0, Keys2.length - 1)])) + "§6等§4" + ToBlockID.size() + "§6个物品" - : ItemIDSunName.getIDByName(ToBlockID.get(0))) + : ItemIDSunName.getIDByName(ToBlockID.get(Keys2[0]))) + "§6" + (Money > 0 ? ("并扣除§9" + Money + "§6" + mis.config.getString("货币单位")) : "") + (Astrict ? (",限制库存§9" + ItemCount) : ",不限制库存")); } @@ -369,12 +369,16 @@ private String getShopConfigName() { * @return 商店kye */ private String getShopItemKey(HashMap buttons) { + return getShopItemKey(buttons, 1); + } + + private String getShopItemKey(HashMap buttons, int JJLeng) { String nameString = ""; - int length = Tool.getRand(5, 20); + int length = JJLeng; for (int i = 0; i < length; i++) nameString += Tool.getRandString(); if (buttons.containsKey(nameString)) - return getShopItemKey(buttons); + return getShopItemKey(buttons, JJLeng++); return nameString; } } diff --git a/MiniatureS/src/cn/xiaokai/mis/shop/ShopMakeForm.java b/MiniatureS/src/cn/xiaokai/mis/shop/ShopMakeForm.java index d5400e9..83c5192 100644 --- a/MiniatureS/src/cn/xiaokai/mis/shop/ShopMakeForm.java +++ b/MiniatureS/src/cn/xiaokai/mis/shop/ShopMakeForm.java @@ -47,11 +47,15 @@ public void AddItemToItem(Player player) { return; } List list = new ArrayList<>(); - list.add( - new ElementInput(TextFormat.GREEN + "请输入商店可以换的物品ID/物品名称 " + TextFormat.WHITE + "多个使用;分割(物品数量请在配置文件修改)", - "玩家将会换得什么", "钻石")); - list.add(new ElementInput(TextFormat.GREEN + "请输入玩家换物所需的物品ID/物品名称" + TextFormat.WHITE + "多个使用;分割(物品数量请在配置文件修改)", - "玩家需要用什么来还", + String FFF_PY_FFFF = "------------------------------"; + list.add(new ElementInput( + "§6请输入商店可以换的物品ID/物品名称 \n§5多个使用;分割\n\n§a格式:\n" + Tool.getColorFont(FFF_PY_FFFF) + + "\n物品ID或名称=>物品数量;物品ID或名称=>物品数量\n§4如 泥土=>64;圆石=>64\n" + Tool.getColorFont(FFF_PY_FFFF), + "物品ID或名称=>物品数量;物品ID或名称=>物品数量 如 泥土=>64;圆石=>64")); + list.add(new ElementInput( + "§6请输入玩家换物所需的物品ID/物品名称 \n§5多个使用;分割\n\n§a格式:\n" + Tool.getColorFont(FFF_PY_FFFF) + + "\n物品ID或名称=>物品数量;物品ID或名称=>物品数量\n§4如 泥土=>64;圆石=>64\n" + Tool.getColorFont(FFF_PY_FFFF), + "物品ID或名称=>物品数量;物品ID或名称=>物品数量 如 泥土=>64;圆石=>64", player.getInventory().getItemInHand().getId() != 0 ? (player.getInventory().getItemInHand().getId() + ":" + player.getInventory().getItemInHand().getDamage()) diff --git a/MiniatureS/src/cn/xiaokai/mis/tool/Tool.java b/MiniatureS/src/cn/xiaokai/mis/tool/Tool.java index b7c5054..f300fdb 100644 --- a/MiniatureS/src/cn/xiaokai/mis/tool/Tool.java +++ b/MiniatureS/src/cn/xiaokai/mis/tool/Tool.java @@ -1,5 +1,13 @@ package cn.xiaokai.mis.tool; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.time.Duration; @@ -296,4 +304,89 @@ public static double Double2(double d, int length) { DecimalFormat df = new DecimalFormat(s); return Double.valueOf(df.format(d)); } + + /** + * 发送HTTP请求 + * + * @param httpUrl 请求地址 + * @param param 请求的内容 + * @return + */ + public static String doPost(String httpUrl, String param) { + HttpURLConnection connection = null; + InputStream is = null; + OutputStream os = null; + BufferedReader br = null; + String result = null; + try { + URL url = new URL(httpUrl); + connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setConnectTimeout(15000); + connection.setReadTimeout(60000); + connection.setDoOutput(true); + connection.setDoInput(true); + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + connection.setRequestProperty("Authorization", "Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0"); + os = connection.getOutputStream(); + os.write(param.getBytes()); + if (connection.getResponseCode() == 200) { + is = connection.getInputStream(); + br = new BufferedReader(new InputStreamReader(is, "UTF-8")); + StringBuffer sbf = new StringBuffer(); + String temp = null; + while ((temp = br.readLine()) != null) { + sbf.append(temp); + sbf.append("\r\n"); + } + result = sbf.toString(); + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (null != br) + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + if (null != os) + try { + os.close(); + } catch (IOException e) { + e.printStackTrace(); + } + if (null != is) + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + connection.disconnect(); + } + return result; + } + + /** + * 从一段字符内截取另一段字符 + * + * @param Context 要截取字符的原文 + * @param text1 要截取的第一段文字 + * @param text2 要截取的第二段文字 + * @return 截取完毕的内容 + */ + public static String cutString(String Context, String strStart, String strEnd) { + int strStartIndex = Context.indexOf(strStart); + int strEndIndex = Context.lastIndexOf(strEnd); + if (strStartIndex < 0) { + return null; + } + if (strEndIndex < 0) { + return null; + } + return Context.substring(strStartIndex, strEndIndex).substring(strStart.length()); + } + } diff --git a/MiniatureS/src/cn/xiaokai/mis/tool/up/AreYouSB.java b/MiniatureS/src/cn/xiaokai/mis/tool/up/AreYouSB.java new file mode 100644 index 0000000..b3ffde0 --- /dev/null +++ b/MiniatureS/src/cn/xiaokai/mis/tool/up/AreYouSB.java @@ -0,0 +1,11 @@ +package cn.xiaokai.mis.tool.up; + +/** + * @author Winfxk + */ +public class AreYouSB { + public String Msg; + public String V; + public String Update; + public String Http; +} diff --git a/MiniatureS/src/cn/xiaokai/mis/tool/up/Update.java b/MiniatureS/src/cn/xiaokai/mis/tool/up/Update.java new file mode 100644 index 0000000..3c96674 --- /dev/null +++ b/MiniatureS/src/cn/xiaokai/mis/tool/up/Update.java @@ -0,0 +1,61 @@ +package cn.xiaokai.mis.tool.up; + +import java.util.LinkedHashMap; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import cn.nukkit.plugin.PluginBase; +import cn.nukkit.utils.Config; +import cn.xiaokai.mis.tool.Tool; + +/** + * @author Winfxk + */ +public class Update { + private PluginBase mis; + protected static final String Url = "http://pluginsupdate.epicfx.cn"; + protected static final int V = 0; + protected static final String ConfigName = "/Update.yml"; + + public Update(PluginBase mis) { + this.mis = mis; + } + + public void start() { + try { + mis.getLogger().info("§6检查更新各种!若不想使用该功能或出现问题,请关闭该功能."); + GsonBuilder builder = new GsonBuilder(); + Gson gson = builder.create(); + JsonParser parser = new JsonParser(); + String strByJson = Tool.doPost(Url, "s=isup&n=" + mis.getName() + "&v=" + V); + if (strByJson != null && !strByJson.isEmpty()) { + if (strByJson.contains("") && strByJson.contains("") + && Tool.cutString(strByJson, "", "") != null + && !Tool.cutString(strByJson, "", "").isEmpty()) { + strByJson = Tool.cutString(strByJson, "", ""); + JsonElement jsonArray = parser.parse(strByJson).getAsJsonObject(); + AreYouSB userBean = gson.fromJson(jsonArray, AreYouSB.class); + if (Boolean.valueOf(userBean.Update)) { + mis.getLogger().info("§6已检测到更新!" + userBean.Msg + " §2下载地址:§9" + userBean.Http + " §4相关数据以储存到§5" + + ConfigName); + LinkedHashMap map = new LinkedHashMap(); + map.put("下载地址", userBean.Http); + map.put("更新内容", userBean.Msg); + map.put("更新版本", userBean.V); + map.put("当前版本", V); + Config config = new Config(mis.getDataFolder() + ConfigName, Config.YAML); + config.setAll(map); + config.save(); + } else + mis.getLogger().info("§6暂无更新!"); + } else + mis.getLogger().info("§4更新数据错误!"); + } else + mis.getLogger().info("§4无法连接到更新服务器!"); + } catch (Exception e) { + mis.getLogger().info("§4更新出现错误!请检查!§f" + e.getMessage()); + } + } +} diff --git a/Miniatures_v2.3.0.jar b/Miniatures_v2.3.0.jar new file mode 100644 index 0000000..13c2a5c Binary files /dev/null and b/Miniatures_v2.3.0.jar differ diff --git a/README.md b/README.md index c4bd0ff..abe3d36 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,8 @@ > - [x] 使用命令模拟玩家点击按钮 命令:/mis open > - [x] 物品兑换支持多个物品兑换多个物品,并且可以设置每个物品兑换需要的数量并且允许每个物品所需或所得数量不同 > - [x] 可以再添加兑换项目时设置多个物品(用英文分号;分割多个物品) -> - [ ] 可以直接设置每个物品的数量 +> - [x] 可以直接设置每个物品的数量 +> - [x] 插件以后将自动检测更新 ## 问题反馈 #### 在使用中有任何问题,欢迎反馈给我,可以用以下联系方式跟我交流