From 24e05819c702ce481d7b5fa282f577871658e4d6 Mon Sep 17 00:00:00 2001 From: yuyu <124714592@qq.com> Date: Thu, 25 Jul 2024 22:29:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=92=8C=E5=9B=9E=E7=82=89=E7=9A=84=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yuyu/srdisassemble/SrDisassemble.java | 10 +++ .../srdisassemble/command/DisCommand.java | 3 + .../srdisassemble/command/MeltCommand.java | 47 ++++++++++++ .../srdisassemble/command/RepairCommand.java | 46 ++++++++++++ .../yuyu/srdisassemble/data/JdbcSqlClass.java | 29 +++++--- .../disassemeble/DisassembleManager.java | 39 +++++++--- .../disassemeble/SassembleGuiService.java | 73 ++++++++++++++----- .../disassemeble/TemporarilyBox.java | 25 ++++++- .../com/yuyu/srdisassemble/pojo/PauseBox.java | 53 ++++++++++++++ src/main/resources/plugin.yml | 8 ++ 10 files changed, 296 insertions(+), 37 deletions(-) create mode 100644 src/main/java/com/yuyu/srdisassemble/command/MeltCommand.java create mode 100644 src/main/java/com/yuyu/srdisassemble/command/RepairCommand.java create mode 100644 src/main/java/com/yuyu/srdisassemble/pojo/PauseBox.java diff --git a/src/main/java/com/yuyu/srdisassemble/SrDisassemble.java b/src/main/java/com/yuyu/srdisassemble/SrDisassemble.java index bcf089f..73acc29 100644 --- a/src/main/java/com/yuyu/srdisassemble/SrDisassemble.java +++ b/src/main/java/com/yuyu/srdisassemble/SrDisassemble.java @@ -2,6 +2,8 @@ package com.yuyu.srdisassemble; import com.sakurarealm.sritem.bukkit.command.CommandBase; import com.yuyu.srdisassemble.command.DisCommand; +import com.yuyu.srdisassemble.command.MeltCommand; +import com.yuyu.srdisassemble.command.RepairCommand; import com.yuyu.srdisassemble.config.ConfigManager; import com.yuyu.srdisassemble.data.JdbcSqlClass; import com.yuyu.srdisassemble.disassemeble.TemporarilyBox; @@ -28,6 +30,14 @@ public final class SrDisassemble extends JavaPlugin { commandBase.registerSubCommand("open",new DisCommand()); commandBase.registerSubCommand("reload",new DisCommand()); + this.getCommand("srmeltagain").setExecutor(commandBase); + commandBase.registerSubCommand("open",new MeltCommand()); + commandBase.registerSubCommand("reload",new MeltCommand()); + + this.getCommand("srrepair").setExecutor(commandBase); + commandBase.registerSubCommand("open",new RepairCommand()); + commandBase.registerSubCommand("reload",new RepairCommand()); + //读取暂存箱 JdbcSqlClass.createPauseBoxTable(); // JdbcSqlClass.setPauseBox2UTF(); diff --git a/src/main/java/com/yuyu/srdisassemble/command/DisCommand.java b/src/main/java/com/yuyu/srdisassemble/command/DisCommand.java index b4232c9..c835670 100644 --- a/src/main/java/com/yuyu/srdisassemble/command/DisCommand.java +++ b/src/main/java/com/yuyu/srdisassemble/command/DisCommand.java @@ -1,8 +1,11 @@ package com.yuyu.srdisassemble.command; +import com.germ.germplugin.api.dynamic.gui.GermGuiScreen; import com.sakurarealm.sritem.bukkit.command.SubCommand; import com.yuyu.srdisassemble.SrDisassemble; import com.yuyu.srdisassemble.disassemeble.DisassembleManager; +import com.yuyu.srdisassemble.disassemeble.SassembleGuiService; +import com.yuyu.srdisassemble.disassemeble.TemporarilyBox; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; diff --git a/src/main/java/com/yuyu/srdisassemble/command/MeltCommand.java b/src/main/java/com/yuyu/srdisassemble/command/MeltCommand.java new file mode 100644 index 0000000..dda0803 --- /dev/null +++ b/src/main/java/com/yuyu/srdisassemble/command/MeltCommand.java @@ -0,0 +1,47 @@ +package com.yuyu.srdisassemble.command; + +import com.sakurarealm.sritem.bukkit.command.SubCommand; +import com.yuyu.srdisassemble.SrDisassemble; +import com.yuyu.srdisassemble.disassemeble.DisassembleManager; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * @author 峰。 + * @version 1.0 + * @project SrDisassemble113 + * @date 2024/7/25 20:42:26 + * @description 回炉指令类 + */ +public class MeltCommand implements SubCommand { + + @Override + public void onCommand(CommandSender commandSender, String[] strings) { + if (strings.length == 1) { + if (strings[0].equalsIgnoreCase("reload")){ + commandSender.sendMessage(ChatColor.RED+"分解配置文件重载!"); + //重载文件 + SrDisassemble.getConfigManager().reload(); + return; + } + } + + + if (strings.length < 2){ + commandSender.sendMessage(ChatColor.RED+"正确的格式为:/srmeltagain open 姓名 "); + return; + } + + Player player = Bukkit.getPlayer(strings[1]); + if (player == null){ + commandSender.sendMessage(ChatColor.RED+"玩家"+strings[1]+"不存在!"); + return; + } + + //为玩家打开GUI列表 + DisassembleManager.getInstance().openMeltAgain(player); + + } +} diff --git a/src/main/java/com/yuyu/srdisassemble/command/RepairCommand.java b/src/main/java/com/yuyu/srdisassemble/command/RepairCommand.java new file mode 100644 index 0000000..ff83e70 --- /dev/null +++ b/src/main/java/com/yuyu/srdisassemble/command/RepairCommand.java @@ -0,0 +1,46 @@ +package com.yuyu.srdisassemble.command; + +import com.sakurarealm.sritem.bukkit.command.SubCommand; +import com.yuyu.srdisassemble.SrDisassemble; +import com.yuyu.srdisassemble.disassemeble.DisassembleManager; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * @author 峰。 + * @version 1.0 + * @project SrDisassemble113 + * @date 2024/7/25 20:55:21 + * @description 维修指令 + */ +public class RepairCommand implements SubCommand { + @Override + public void onCommand(CommandSender commandSender, String[] strings) { + if (strings.length == 1) { + if (strings[0].equalsIgnoreCase("reload")){ + commandSender.sendMessage(ChatColor.RED+"分解配置文件重载!"); + //重载文件 + SrDisassemble.getConfigManager().reload(); + return; + } + } + + + if (strings.length < 2){ + commandSender.sendMessage(ChatColor.RED+"正确的格式为:/srrepair open 姓名 "); + return; + } + + Player player = Bukkit.getPlayer(strings[1]); + if (player == null){ + commandSender.sendMessage(ChatColor.RED+"玩家"+strings[1]+"不存在!"); + return; + } + + //为玩家打开GUI列表 + DisassembleManager.getInstance().openRepair(player); + + } +} diff --git a/src/main/java/com/yuyu/srdisassemble/data/JdbcSqlClass.java b/src/main/java/com/yuyu/srdisassemble/data/JdbcSqlClass.java index c7063e5..c423c65 100644 --- a/src/main/java/com/yuyu/srdisassemble/data/JdbcSqlClass.java +++ b/src/main/java/com/yuyu/srdisassemble/data/JdbcSqlClass.java @@ -1,10 +1,7 @@ package com.yuyu.srdisassemble.data; -import com.google.common.annotations.VisibleForTesting; -import com.yuyu.srdisassemble.SrDisassemble; import com.yuyu.srdisassemble.pojo.DisassembleData; import com.yuyu.srdisassemble.pojo.PauseBox; -import org.bukkit.ChatColor; import java.sql.*; import java.time.LocalDateTime; @@ -157,8 +154,9 @@ public class JdbcSqlClass { " slotnumber int null comment '槽位',\n" + " nums int null comment '数量',\n" + " productindex varchar(255) null comment '原胚索引',\n" + - " guiname varchar(255) null comment 'gui的姓名'\n" + - ") CHARACTER SET utf8mb4 COLLATE utf8mb4_bin"; + " guiname varchar(255) null comment 'gui的姓名',\n" + + " lores text null comment '材料的lores'\n" + + " ) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin"; boolean rs = connection.execute(createTable); @@ -176,6 +174,7 @@ public class JdbcSqlClass { columns.add("nums"); columns.add("productindex"); columns.add("guiname"); + columns.add("lores"); try { ResultSet resultSet = connection.executeQuery(sql); @@ -210,17 +209,19 @@ public class JdbcSqlClass { /** * 插入数据 + * * @param username * @param slotNumber * @param nums * @param productindex * @param guiname + * @param lore */ - public static void insertPauseBoxData(String username,int slotNumber,int nums,String productindex,String guiname){ + public static void insertPauseBoxData(String username, int slotNumber, int nums, String productindex, String guiname, String lore){ try { - String sql = "insert into pausebox(username, slotnumber, nums, productindex, guiname)" + - " VALUES ('"+username+"',"+slotNumber+","+nums+",'"+productindex+"','"+guiname+"')"; + String sql = "insert into pausebox(username, slotnumber, nums, productindex, guiname,lores)" + + " VALUES ('"+username+"',"+slotNumber+","+nums+",'"+productindex+"','"+guiname+"','"+lore+"')"; Statement statement = getConnection(); @@ -271,6 +272,9 @@ public class JdbcSqlClass { } else if (columns.equals("guiname")) { sql = "ALTER TABLE pausebox\n" + "ADD guiname varchar(255) null comment 'gui的姓名'"; + }else if (columns.equals("lores")) { + sql = "ALTER TABLE pausebox\n" + + "ADD lores text null comment '材料的lores'"; } if (sql != null) { @@ -507,11 +511,18 @@ public class JdbcSqlClass { try { ResultSet resultSet = statement.executeQuery(sql); while (resultSet.next()){ + String lore = resultSet.getString("lores"); + List lores = new ArrayList<>(); + String[] split = lore.split("\\|"); + for (String s : split) { + lores.add(s); + } + PauseBox pauseBox = new PauseBox(resultSet.getString("username"), resultSet.getInt("slotnumber"), resultSet.getInt("nums"), resultSet.getString("productindex"), - resultSet.getString("guiname")); + resultSet.getString("guiname"),lores); pauseBoxList.add(pauseBox); } diff --git a/src/main/java/com/yuyu/srdisassemble/disassemeble/DisassembleManager.java b/src/main/java/com/yuyu/srdisassemble/disassemeble/DisassembleManager.java index 936bdbd..86852e1 100644 --- a/src/main/java/com/yuyu/srdisassemble/disassemeble/DisassembleManager.java +++ b/src/main/java/com/yuyu/srdisassemble/disassemeble/DisassembleManager.java @@ -55,21 +55,40 @@ public class DisassembleManager { //用于打开gui public void open(Player player) { -// SassembleGuiService sassembleGuiService = (SassembleGuiService) TemporarilyBox.getGermGuiScreen(player.getName(), "disassemble"); -// if (sassembleGuiService == null) { - //获取分解gui - SassembleGuiService sassembleGuiService = new SassembleGuiService(getDisassembleGui(), "disassemble", player); -// TemporarilyBox.addGuiScreen(player.getName(), "disassemble", sassembleGuiService); -// } -// GermGuiScreen packscreen = TemporarilyBox.getGermGuiScreen(player.getName(), "player_inventory-disassemble"); -// if (packscreen == null) { + if (TemporarilyBox.isHasGui(player.getName(), "disassemble")){ + SassembleGuiService germGuiScreen = (SassembleGuiService) TemporarilyBox.getGermGuiScreen(player.getName(), "disassemble"); + GermGuiScreen packscreen = GermGuiScreen.getGermGuiScreen("player_inventory-disassemble", this.getDisassemblePlayerInventory()); + if (germGuiScreen != null) { + germGuiScreen.openGui(player); + packscreen.openChildGui(player); + return; + } + } + + + //分解gui + SassembleGuiService sassembleGuiService = new SassembleGuiService(getDisassembleGui(), "disassemble", player); + GermGuiScreen packscreen = GermGuiScreen.getGermGuiScreen("player_inventory-disassemble", this.getDisassemblePlayerInventory()); -// TemporarilyBox.addGuiScreen(player.getName(), "player_inventory-disassemble",packscreen); -// } sassembleGuiService.openGui(player); packscreen.openChildGui(player); } + /** + * 用于打开回炉gui + * @param player + */ + public void openMeltAgain(Player player) { + + } + + /** + * 用于打开维修gui + * @param player + */ + public void openRepair(Player player) { + + } } diff --git a/src/main/java/com/yuyu/srdisassemble/disassemeble/SassembleGuiService.java b/src/main/java/com/yuyu/srdisassemble/disassemeble/SassembleGuiService.java index 684a95b..24dd41d 100644 --- a/src/main/java/com/yuyu/srdisassemble/disassemeble/SassembleGuiService.java +++ b/src/main/java/com/yuyu/srdisassemble/disassemeble/SassembleGuiService.java @@ -37,7 +37,7 @@ public class SassembleGuiService extends GermGuiScreen { private DisassembleData data; private String name; private Random random ; - private boolean disassembleFlag = true; +// private boolean disassembleFlag = true; private Player playerHost; private GermGuiScreen temporarilyBoxScreen; private List guiSlots = new ArrayList<>(); @@ -83,9 +83,9 @@ public class SassembleGuiService extends GermGuiScreen { } synchronized public void setItemToPauseBox(ItemStack item){ - if (!this.disassembleFlag){ - return; - } +// if (!this.disassembleFlag){ +// return; +// } for (int i = 0; i <= 15 ; i++){ GermGuiSlot germGuiSlot = guiSlots.get(i); if (germGuiSlot.getItemStack().getType() == Material.AIR){ @@ -107,6 +107,7 @@ public class SassembleGuiService extends GermGuiScreen { */ public void saveTemporarilyBox(){ TemporarilyBox.addGuiScreen(playerHost.getName(), "TemporarilyBox",this.temporarilyBoxScreen); + TemporarilyBox.addGuiScreen(playerHost.getName(),"disassemble",this); } public void boolGui(){ @@ -122,6 +123,7 @@ public class SassembleGuiService extends GermGuiScreen { GermGuiButton men1 = (GermGuiButton) bgCanvas.getGuiPart("men1"); GermGuiTexture doorPause = (GermGuiTexture) bgCanvas.getGuiPart("doorPause"); GermGuiGif door = (GermGuiGif) bgCanvas.getGuiPart("door"); + GermGuiLabel label = (GermGuiLabel) bgCanvas.getGuiPart("label"); men1.setEnable(false); fire.setEnable(true); @@ -144,16 +146,25 @@ public class SassembleGuiService extends GermGuiScreen { }else { ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); - - + List texts = new ArrayList<>(); + texts.add("#C80800FF距离分解完成"); + texts.add("#ACDA70D6还有"+calculateMinutesDifference+"分钟"); + label.setTexts(texts); + label.setEnable(true); executor.scheduleWithFixedDelay(() -> { int nums = MinUtil.calculateMinutesDifference(data.getDisassembleTime()); + + String text = "##ACDA70D6还有"+nums+"分钟"; + texts.remove(1); + texts.add(text); + label.setTexts(texts); + if (nums <= 0) { - if(!this.disassembleFlag){ - executor.shutdown(); - return; - } +// if(!this.disassembleFlag){ +// executor.shutdown(); +// return; +// } //执行语句说明分解完成 this.disassembleComplete(); @@ -167,6 +178,7 @@ public class SassembleGuiService extends GermGuiScreen { door.setEnable(false); men1.setEnable(true); doorPause.setEnable(false); + label.setEnable(false); this.temporarilyBoxScreen.openChildGui(this.playerHost); executor.shutdown(); } @@ -278,6 +290,7 @@ public class SassembleGuiService extends GermGuiScreen { //上方if语句通过表示该物品可以分解 //假如启动按钮是油壶, GermGuiGif door = (GermGuiGif) bgCanvas.getGuiPart("door"); + GermGuiTexture doorPause = (GermGuiTexture) bgCanvas.getGuiPart("doorPause"); door.setCycle(1); door.setPause(14); if ((boolean)door.getEnable() == true){ @@ -299,21 +312,35 @@ public class SassembleGuiService extends GermGuiScreen { this.closeTemporaryBox(); + GermGuiLabel label = (GermGuiLabel) bgCanvas.getGuiPart("label"); + List texts = new ArrayList<>(); + texts.add("#C80800FF距离分解完成"); int minTime = MinUtil.calculateMinutesDifference(data.getDisassembleTime()); + texts.add("#ACDA70D6还有"+minTime+"分钟"); + label.setTexts(texts); + label.setEnable(true); ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); - + executor.schedule(() -> { + if (!doorPause.isEnable()){ + doorPause.setEnable(true); + } + if (door.isEnable()){ + door.setEnable(false); + } + },2,TimeUnit.SECONDS); executor.scheduleWithFixedDelay(() -> { int calculateMinutesDifference = MinUtil.calculateMinutesDifference(data.getDisassembleTime()); + String text = "#ACDA70D6还有"+calculateMinutesDifference+"分钟"; + texts.remove(1); + texts.add(text); + label.setTexts(texts); if (calculateMinutesDifference <= 0) { //执行语句说明分解完成 + label.setEnable(false); + - if (!this.disassembleFlag){ - //disassembleFlag == false 说明gui已经关闭,即已经放弃了,下次打开时会打开新的gui - executor.shutdown(); - return; - } this.disassembleComplete(); if ((boolean)disassembleSlot.getInteract()){ @@ -374,7 +401,7 @@ public class SassembleGuiService extends GermGuiScreen { //遍历gui的所有物品槽,并且返回到玩家背包中 synchronized private void returnItemStacks(Player player) { - this.disassembleFlag = false; +// this.disassembleFlag = false; this.temporarilyBoxScreen.close(); List allGuiParts = this.getAllGuiParts(GermGuiSlot.class); for (GermGuiSlot guiPart : allGuiParts) { @@ -392,6 +419,18 @@ public class SassembleGuiService extends GermGuiScreen { player.sendMessage(ChatColor.GREEN+"暂存箱只能存放RPG物品!"); player.getInventory().addItem(itemStack); guiPart.setItemStack(null); + continue; + } + + String index = srItemHandler.getLore().get(0); + //\\.转义符号 + String[] split = index.split("\\."); + String s = split[1]; + if (s.equals("equip")){ + player.sendMessage(ChatColor.GREEN+"暂存箱只能存放材料和原胚物品!"); + player.getInventory().addItem(itemStack); + guiPart.setItemStack(null); + continue; } } diff --git a/src/main/java/com/yuyu/srdisassemble/disassemeble/TemporarilyBox.java b/src/main/java/com/yuyu/srdisassemble/disassemeble/TemporarilyBox.java index 65228c2..c2e0a88 100644 --- a/src/main/java/com/yuyu/srdisassemble/disassemeble/TemporarilyBox.java +++ b/src/main/java/com/yuyu/srdisassemble/disassemeble/TemporarilyBox.java @@ -6,12 +6,14 @@ import com.germ.germplugin.api.dynamic.gui.GermGuiScroll; import com.germ.germplugin.api.dynamic.gui.GermGuiSlot; import com.sakurarealm.sritem.api.ItemStackHelper; import com.sakurarealm.sritem.api.SrItemAPI; +import com.sakurarealm.sritem.api.SrItemManager; import com.sakurarealm.sritem.api.builder.SrItemHandler; import com.yuyu.srdisassemble.data.JdbcSqlClass; import com.yuyu.srdisassemble.pojo.PauseBox; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import java.util.HashMap; import java.util.List; @@ -56,6 +58,18 @@ public class TemporarilyBox { } + /** + * 用于判断当前服务器缓存中是否存在该gui + */ + public static boolean isHasGui(String playname,String guiName) { + if(temporarilyBoxHashMap.containsKey(playname)) { + return temporarilyBoxHashMap.get(playname).containsKey(guiName); + }else { + return false; + } + } + + /** * 用于插件启动时,读取玩家的数据库存储 */ @@ -81,10 +95,14 @@ public class TemporarilyBox { GermGuiSlot germGuiSlot = (GermGuiSlot) scroll.getGuiPart(slot); ItemStack item = SrItemAPI.getItem(index, new HashMap<>(), null, true, true); + if (item == null){ continue; } item.setAmount(nums); + ItemMeta itemMeta = item.getItemMeta(); + itemMeta.setLore(p.getLores()); + item.setItemMeta(itemMeta); germGuiSlot.setItemStack(item); } @@ -109,7 +127,12 @@ public class TemporarilyBox { SrItemHandler srItemHandler = ItemStackHelper.getSrItemHandler(itemStack); String index = srItemHandler.getLore().get(0); index = index.substring(1); - JdbcSqlClass.insertPauseBoxData(username,i,itemStack.getAmount(),index,"TemporarilyBox"); + List lore = itemStack.getItemMeta().getLore(); + String lores = ""; + for (String s : lore){ + lores = lores+s+"|"; + } + JdbcSqlClass.insertPauseBoxData(username,i,itemStack.getAmount(),index,"TemporarilyBox",lores); } } } diff --git a/src/main/java/com/yuyu/srdisassemble/pojo/PauseBox.java b/src/main/java/com/yuyu/srdisassemble/pojo/PauseBox.java new file mode 100644 index 0000000..3d44dbc --- /dev/null +++ b/src/main/java/com/yuyu/srdisassemble/pojo/PauseBox.java @@ -0,0 +1,53 @@ +package com.yuyu.srdisassemble.pojo; + +import java.util.List; + +/** + * @author 峰。 + * @version 1.0 + * @project SrDisassemble113 + * @date 2024/7/20 13:21:50 + * @description + */ +public class PauseBox { + private String username; + private int slotnumber; + private int nums; + private String productindex; + private String guiname; + private List lores; + + + public PauseBox(String username, int slotnumber, int nums, String productindex, String guiname, List lores) { + this.username = username; + this.slotnumber = slotnumber; + this.nums = nums; + this.productindex = productindex; + this.guiname = guiname; + this.lores = lores; + } + + public List getLores() { + return lores; + } + + public String getUsername() { + return username; + } + + public int getSlotnumber() { + return slotnumber; + } + + public int getNums() { + return nums; + } + + public String getProductindex() { + return productindex; + } + + public String getGuiname() { + return guiname; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 84ba74d..51c878e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -10,3 +10,11 @@ commands: description: srdisassemble command aliases: [ srd ] permission: srdisassemble.command + srmeltagain: + description: srmeltagain command + aliases: [ srm ] + permission: srmeltagain.command + srrepair: + description: srrepair command + aliases: [ srr ] + permission: srrepair.command