diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 8a02f67..79b34f7 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -45,7 +45,7 @@ jobs: # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 - name: Upload build artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: nukkit-plugins path: ${{ github.workspace }}/nukkit-plugins/*.jar diff --git a/lib/MagicItem-1.1.0.jar b/lib/MagicItem-1.1.0.jar deleted file mode 100644 index 5f90f00..0000000 Binary files a/lib/MagicItem-1.1.0.jar and /dev/null differ diff --git a/lib/MagicItem-1.1.2.jar b/lib/MagicItem-1.1.2.jar new file mode 100644 index 0000000..81c3170 Binary files /dev/null and b/lib/MagicItem-1.1.2.jar differ diff --git a/pom.xml b/pom.xml index 0ed5a37..4e6ee2b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ RcRPG.RcRPGMain RcRPG - 1.1.2-MOT + 1.1.3-MOT UTF-8 @@ -156,7 +156,7 @@ MagicItem 1.0.0 system - ${pom.basedir}/lib/MagicItem-1.1.0.jar + ${pom.basedir}/lib/MagicItem-1.1.2.jar diff --git a/src/main/java/RcRPG/RPG/Armour.java b/src/main/java/RcRPG/RPG/Armour.java index 3ba764e..b797b09 100644 --- a/src/main/java/RcRPG/RPG/Armour.java +++ b/src/main/java/RcRPG/RPG/Armour.java @@ -280,7 +280,10 @@ public static boolean canInlay(Item item){ public static void setStone(Player player,Item item,LinkedList list){ ListTag stoneList = new ListTag<>("stone"); for(Stone stone : list){ - if(stone == null) continue; + if (stone == null) { + stoneList.add(new StringTag("", "")); + continue; + } stoneList.add(new StringTag(stone.getLabel(),stone.getLabel())); } CompoundTag tag = item.getNamedTag(); diff --git a/src/main/java/RcRPG/RPG/Suit.java b/src/main/java/RcRPG/RPG/Suit.java index c91f03b..1f9fb8b 100644 --- a/src/main/java/RcRPG/RPG/Suit.java +++ b/src/main/java/RcRPG/RPG/Suit.java @@ -15,6 +15,7 @@ public class Suit { public static Map suitInfo = new HashMap<>(); public static void init() { + suitInfo.clear(); Config cfg = new Config(RcRPGMain.getInstance().getDataFolder() + "/SuitPlan.yml"); cfg.getAll().keySet().forEach(suitName -> { RcRPGMain.getInstance().getLogger().info("suitName: "+suitName); diff --git a/src/main/java/RcRPG/RPG/Weapon.java b/src/main/java/RcRPG/RPG/Weapon.java index 309f31d..4c9c826 100644 --- a/src/main/java/RcRPG/RPG/Weapon.java +++ b/src/main/java/RcRPG/RPG/Weapon.java @@ -77,6 +77,9 @@ public class Weapon extends ItemAttr { private String message; + /** + * 宝石槽列表 + */ private ArrayList stoneList = new ArrayList<>(); private ArrayList loreList = new ArrayList<>(); @@ -276,7 +279,10 @@ public static boolean canInlay(Item item) { public static void setStone(Player player, Item item, LinkedList list) { ListTag stoneList = new ListTag<>("stone"); for (Stone stone : list) { - if (stone == null) continue; + if (stone == null) { + stoneList.add(new StringTag("", "")); + continue; + } stoneList.add(new StringTag(stone.getName(), stone.getName())); } CompoundTag tag = item.getNamedTag(); diff --git a/src/main/java/RcRPG/RPG/Forging/ForgingPaper.java b/src/main/java/RcRPG/RPG/forging/ForgingPaper.java similarity index 99% rename from src/main/java/RcRPG/RPG/Forging/ForgingPaper.java rename to src/main/java/RcRPG/RPG/forging/ForgingPaper.java index 5059a44..86b166f 100644 --- a/src/main/java/RcRPG/RPG/Forging/ForgingPaper.java +++ b/src/main/java/RcRPG/RPG/forging/ForgingPaper.java @@ -1,4 +1,4 @@ -package RcRPG.RPG.Forging; +package RcRPG.RPG.forging; import RcRPG.RcRPGMain; import cn.ankele.plugin.MagicItem; diff --git a/src/main/java/RcRPG/RPG/Forging/ForgingStone.java b/src/main/java/RcRPG/RPG/forging/ForgingStone.java similarity index 99% rename from src/main/java/RcRPG/RPG/Forging/ForgingStone.java rename to src/main/java/RcRPG/RPG/forging/ForgingStone.java index 27d9818..7239ae8 100644 --- a/src/main/java/RcRPG/RPG/Forging/ForgingStone.java +++ b/src/main/java/RcRPG/RPG/forging/ForgingStone.java @@ -1,4 +1,4 @@ -package RcRPG.RPG.Forging; +package RcRPG.RPG.forging; import RcRPG.RcRPGMain; import cn.nukkit.Player; diff --git a/src/main/java/RcRPG/RcRPGMain.java b/src/main/java/RcRPG/RcRPGMain.java index cd7cf81..657d73f 100644 --- a/src/main/java/RcRPG/RcRPGMain.java +++ b/src/main/java/RcRPG/RcRPGMain.java @@ -1,11 +1,11 @@ package RcRPG; import RcRPG.RPG.*; -import RcRPG.RPG.Forging.ForgingPaper; -import RcRPG.RPG.Forging.ForgingStone; -import RcRPG.Task.BoxTimeTask; -import RcRPG.Task.PlayerAttrUpdateTask; -import RcRPG.Task.Tip; +import RcRPG.RPG.forging.ForgingPaper; +import RcRPG.RPG.forging.ForgingStone; +import RcRPG.task.BoxTimeTask; +import RcRPG.task.PlayerAttrUpdateTask; +import RcRPG.task.PlayerTipTask; import RcRPG.command.Commands; import RcRPG.config.MainConfig; import RcRPG.floatingtext.TextEntity; @@ -83,7 +83,7 @@ public void onEnable() { // 底部显示不为空时 if (!MainConfig.getBottomFormat().isEmpty()) { - this.getServer().getScheduler().scheduleRepeatingTask(new Tip(this), 20); + this.getServer().getScheduler().scheduleRepeatingTask(new PlayerTipTask(this), 20); } this.getServer().getScheduler().scheduleRepeatingTask(new BoxTimeTask(this), 20); //this.getServer().getScheduler().scheduleRepeatingTask(new loadHealth(this), 10); @@ -118,6 +118,7 @@ public void init() { Suit.init(); this.getLogger().info("开始读取武器信息"); + loadWeapon.clear(); for (String name : Handle.getDefaultFiles("Weapon")) { Weapon weapon = null; try { @@ -133,6 +134,7 @@ public void init() { } } this.getLogger().info("开始读取盔甲信息"); + loadArmour.clear(); for (String name : Handle.getDefaultFiles("Armour")) { Armour armour = null; try { @@ -148,6 +150,7 @@ public void init() { } } this.getLogger().info("开始读取宝石信息"); + loadStone.clear(); for (String name : Handle.getDefaultFiles("Stone")) { Stone stone = null; try { @@ -163,6 +166,7 @@ public void init() { } } this.getLogger().info("开始读取箱子信息"); + loadBox.clear(); for (String name : Handle.getDefaultFiles("Box")) { Box box = null; try { @@ -178,6 +182,7 @@ public void init() { } } this.getLogger().info("开始读取饰品信息"); + loadOrnament.clear(); for (String name : Handle.getDefaultFiles("Ornament")) { Ornament ornament = null; try { @@ -193,6 +198,7 @@ public void init() { } } this.getLogger().info("开始读取锻造图信息"); + loadForgingPaper.clear(); for (String name : Handle.getDefaultFiles("Forging" + File.separator + "Paper")) { ForgingPaper forgingPaper; try { @@ -208,6 +214,7 @@ public void init() { } } this.getLogger().info("开始读取锻造石信息"); + loadForgingStone.clear(); for (String name : Handle.getDefaultFiles("Forging" + File.separator + "Stone")) { ForgingStone forgingStone; try { diff --git a/src/main/java/RcRPG/command/Commands.java b/src/main/java/RcRPG/command/Commands.java index 71c7607..7b9ad50 100644 --- a/src/main/java/RcRPG/command/Commands.java +++ b/src/main/java/RcRPG/command/Commands.java @@ -2,8 +2,8 @@ import RcRPG.AttrManager.PlayerAttr; import RcRPG.RPG.*; -import RcRPG.RPG.Forging.ForgingPaper; -import RcRPG.RPG.Forging.ForgingStone; +import RcRPG.RPG.forging.ForgingPaper; +import RcRPG.RPG.forging.ForgingStone; import RcRPG.RcRPGMain; import RcRPG.Society.Money; import RcRPG.Society.Points; @@ -314,7 +314,7 @@ public boolean execute(CommandSender sender, String label, String[] args) { sender.sendMessage(TextFormat.RED + "请手持有效装备"); return false; } - new inlayForm().makeInlayForm((Player) sender, item); + new inlayForm((Player) sender).makeInlayForm(item); return true; } case "check": diff --git a/src/main/java/RcRPG/panel/container/forging/ForgingPanel.java b/src/main/java/RcRPG/panel/container/forging/ForgingPanel.java index ee2e21d..4c77b86 100644 --- a/src/main/java/RcRPG/panel/container/forging/ForgingPanel.java +++ b/src/main/java/RcRPG/panel/container/forging/ForgingPanel.java @@ -1,6 +1,6 @@ package RcRPG.panel.container.forging; -import RcRPG.RPG.Forging.ForgingPaper; +import RcRPG.RPG.forging.ForgingPaper; import RcRPG.RcRPGMain; import cn.nukkit.Player; import cn.nukkit.Server; diff --git a/src/main/java/RcRPG/panel/container/forging/ForgingSubPanel.java b/src/main/java/RcRPG/panel/container/forging/ForgingSubPanel.java index 48effba..d8ff854 100644 --- a/src/main/java/RcRPG/panel/container/forging/ForgingSubPanel.java +++ b/src/main/java/RcRPG/panel/container/forging/ForgingSubPanel.java @@ -1,7 +1,7 @@ package RcRPG.panel.container.forging; -import RcRPG.RPG.Forging.ForgingPaper; -import RcRPG.RPG.Forging.ForgingStone; +import RcRPG.RPG.forging.ForgingPaper; +import RcRPG.RPG.forging.ForgingStone; import RcRPG.RcRPGMain; import cn.nukkit.Player; import cn.nukkit.inventory.Inventory; diff --git a/src/main/java/RcRPG/panel/form/inlayForm.java b/src/main/java/RcRPG/panel/form/inlayForm.java index fd72eb9..f7033e0 100644 --- a/src/main/java/RcRPG/panel/form/inlayForm.java +++ b/src/main/java/RcRPG/panel/form/inlayForm.java @@ -1,16 +1,14 @@ package RcRPG.panel.form; import RcRPG.Handle; -import RcRPG.RcRPGMain; import RcRPG.RPG.Armour; import RcRPG.RPG.Stone; import RcRPG.RPG.Weapon; +import RcRPG.RcRPGMain; import cn.nukkit.Player; import cn.nukkit.form.element.ElementButton; import cn.nukkit.form.element.ElementDropdown; import cn.nukkit.form.handler.FormResponseHandler; -import cn.nukkit.form.response.FormResponseCustom; -import cn.nukkit.form.response.FormResponseData; import cn.nukkit.form.response.FormResponseSimple; import cn.nukkit.form.window.FormWindowCustom; import cn.nukkit.form.window.FormWindowSimple; @@ -21,9 +19,12 @@ import java.util.LinkedList; import java.util.stream.Collectors; +import static RcRPG.RcRPGMain.i18n; + public class inlayForm { - private static final String NO_STONE = "无"; - private static final String SUCCESS_MESSAGE = "宝石操作成功!"; + private final Player player; + private final String NO_STONE; + private final String SUCCESS_MESSAGE; private Stone beforeStone; private int beforeClick; private Item handItem = null; @@ -31,15 +32,18 @@ public class inlayForm { private Armour armourItem = null; private LinkedList originStones = new LinkedList<>(); - public void makeInlayForm(Player player, Item item) { + public inlayForm(Player player) { + this.player = player; + this.NO_STONE = i18n.tr(player.getLanguageCode(), "rcrpg.window.inlay.no_stone"); + this.SUCCESS_MESSAGE = i18n.tr(player.getLanguageCode(), "rcrpg.window.inlay.success_message"); + } + + public void makeInlayForm(Item item) { handItem = item; - //Object state; if (Weapon.isWeapon(item)) { weaponItem = RcRPGMain.loadWeapon.get(item.getNamedTag().getString("name")); - //state = weaponItem; } else if (Armour.isArmour(item)) { armourItem = RcRPGMain.loadArmour.get(item.getNamedTag().getString("name")); - //state = armourItem; } else { return; } @@ -52,7 +56,9 @@ public void makeInlayForm(Player player, Item item) { private FormWindowSimple getStateWindow() { String label = ""; + // 镶嵌在装备上的宝石列表 LinkedList stones = new LinkedList<>(); + // 装备可镶嵌的宝石类型列表 ArrayList stoneSlots = new ArrayList<>(); if (weaponItem != null) { stones = Weapon.getStones(handItem); @@ -76,8 +82,8 @@ private FormWindowSimple getStateWindow() { } this.originStones = stones; return new FormWindowSimple( - "§f"+label + "宝石列表", - stoneCount > 0 ? "装备拥有 " + stoneCount + " 个宝石槽:\n"+slotShow : "本装备没有宝石槽", + i18n.tr(player.getLanguageCode(), "rcrpg.window.inlay.title", label), + stoneCount > 0 ? i18n.tr(player.getLanguageCode(), "rcrpg.window.inlay.title.hasSlot", stoneCount, slotShow).replace("\\n", "\n") : i18n.tr(player.getLanguageCode(), "rcrpg.window.inlay.title.notSlot"), stones.stream() .map(stone -> new ElementButton(stone == null ? NO_STONE : stone.getShowName())) .collect(Collectors.toList())); @@ -111,7 +117,11 @@ private void handleStateWindowResponse(FormWindowSimple form, Player player) { FormWindowCustom form_ = getStoneWindow(yamlName, playerStones); form_.addHandler(FormResponseHandler.withoutPlayer(ignored -> { - if (form_.wasClosed()) return; + if (form_.wasClosed()) { + // 若玩家点了 X 则返回上一级表单 + makeInlayForm(player.getInventory().getItemInHand()); + return; + } handleStoneWindowResponse(form_, player); })); player.showFormWindow(form_); @@ -124,6 +134,7 @@ private FormWindowCustom getStoneWindow(String yamlName, LinkedList ston } private void handleStoneWindowResponse(FormWindowCustom form, Player player) { + // 装备 yamlName 名字 String itemName = ""; LinkedList stones = new LinkedList<>(); if (weaponItem != null) { @@ -134,34 +145,33 @@ private void handleStoneWindowResponse(FormWindowCustom form, Player player) { itemName = armourItem.getName(); } - FormResponseCustom response = form.getResponse(); - FormResponseData responseData = response.getDropdownResponse(0); - // 选择的是 yamlName 还是 NO_STONE - String responseContent = responseData.getElementContent(); + // 选择的宝石是 yamlName 还是 NO_STONE + String selectedStoneName = form.getResponse().getDropdownResponse(0).getElementContent(); + // 检查手持装备是否变动 Item item = player.getInventory().getItemInHand(); if (item.getNamedTag() == null) return; if (!itemName.equals(item.getNamedTag().getString("name"))) return; - player.sendMessage(SUCCESS_MESSAGE); - - int clickedButtonId = beforeClick; - Stone newStone = NO_STONE.equals(responseContent) ? null : Handle.getStoneViaName(responseContent); - - for (int i = 0; i < stones.size(); i++) { - if (i == clickedButtonId) { - if (newStone != null) { - stones.set(i, newStone); - } else { - stones.remove(i); - } - break; - } + + // 先发送成功提示 + if (NO_STONE.equals(selectedStoneName) && stones.get(beforeClick) == null) { + // ignored + } else { + player.sendMessage(SUCCESS_MESSAGE); } + Stone newStone = NO_STONE.equals(selectedStoneName) ? null : Handle.getStoneViaName(selectedStoneName); + + // 扣除新宝石 if (newStone != null) { - Handle.removeStoneViaName(player, responseContent); + stones.set(beforeClick, newStone); + Handle.removeStoneViaName(player, selectedStoneName); + } else { + stones.set(beforeClick, null); } - if (beforeStone != null) {// 过去的宝石 + + // 返还原有的宝石 + if (beforeStone != null) { Stone.giveStone(player, beforeStone.getName(), 1); } diff --git a/src/main/java/RcRPG/Task/BoxTimeTask.java b/src/main/java/RcRPG/task/BoxTimeTask.java similarity index 98% rename from src/main/java/RcRPG/Task/BoxTimeTask.java rename to src/main/java/RcRPG/task/BoxTimeTask.java index a67a3ff..75e2c64 100644 --- a/src/main/java/RcRPG/Task/BoxTimeTask.java +++ b/src/main/java/RcRPG/task/BoxTimeTask.java @@ -1,4 +1,4 @@ -package RcRPG.Task; +package RcRPG.task; import RcRPG.RcRPGMain; import RcRPG.PlayerStatus; diff --git a/src/main/java/RcRPG/Task/PlayerAttrUpdateTask.java b/src/main/java/RcRPG/task/PlayerAttrUpdateTask.java similarity index 99% rename from src/main/java/RcRPG/Task/PlayerAttrUpdateTask.java rename to src/main/java/RcRPG/task/PlayerAttrUpdateTask.java index 846f291..25de3e0 100644 --- a/src/main/java/RcRPG/Task/PlayerAttrUpdateTask.java +++ b/src/main/java/RcRPG/task/PlayerAttrUpdateTask.java @@ -1,4 +1,4 @@ -package RcRPG.Task; +package RcRPG.task; import RcRPG.AttrManager.PlayerAttr; import RcRPG.Events; diff --git a/src/main/java/RcRPG/Task/Tip.java b/src/main/java/RcRPG/task/PlayerTipTask.java similarity index 96% rename from src/main/java/RcRPG/Task/Tip.java rename to src/main/java/RcRPG/task/PlayerTipTask.java index 9058413..c3b9ca0 100644 --- a/src/main/java/RcRPG/Task/Tip.java +++ b/src/main/java/RcRPG/task/PlayerTipTask.java @@ -1,4 +1,4 @@ -package RcRPG.Task; +package RcRPG.task; import RcRPG.Handle; import RcRPG.RcRPGMain; @@ -11,9 +11,9 @@ import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.scheduler.PluginTask; -public class Tip extends PluginTask { +public class PlayerTipTask extends PluginTask { - public Tip(RcRPGMain rcRPGMain){ + public PlayerTipTask(RcRPGMain rcRPGMain){ super(rcRPGMain); } diff --git a/src/main/resources/language/en_US.lang b/src/main/resources/language/en_US.lang index 253e7e9..f5b12a9 100644 --- a/src/main/resources/language/en_US.lang +++ b/src/main/resources/language/en_US.lang @@ -46,3 +46,9 @@ rcrpg.manage.window.armour.title=§fRcRPG Management - Armor List rcrpg.manage.window.ornament.title=§fRcRPG Management - Ornament List rcrpg.manage.window.stone.title=§fRcRPG Management - Gem List rcrpg.manage.window.weapon.title=§fRcRPG Management - Weapon List + +rcrpg.window.inlay.no_stone=Null +rcrpg.window.inlay.success_message=Gem operation successful! +rcrpg.window.inlay.title=§f{%0} Gem List +rcrpg.window.inlay.title.hasSlot=Equipment has {%0} gem slots:\n{%1} +rcrpg.window.inlay.title.notSlot=This equipment has no gem slots \ No newline at end of file diff --git a/src/main/resources/language/zh_CN.lang b/src/main/resources/language/zh_CN.lang index fb02d69..9a344e0 100644 --- a/src/main/resources/language/zh_CN.lang +++ b/src/main/resources/language/zh_CN.lang @@ -46,3 +46,9 @@ rcrpg.manage.window.armour.title=§fRcRPG管理 - 护甲列表 rcrpg.manage.window.ornament.title=§fRcRPG管理 - 饰品列表 rcrpg.manage.window.stone.title=§fRcRPG管理 - 宝石列表 rcrpg.manage.window.weapon.title=§fRcRPG管理 - 武器列表 + +rcrpg.window.inlay.no_stone=无 +rcrpg.window.inlay.success_message=宝石操作成功! +rcrpg.window.inlay.title=§f{%0}宝石列表 +rcrpg.window.inlay.title.hasSlot=装备拥有 {%0} 个宝石槽:\n{%1} +rcrpg.window.inlay.title.notSlot=本装备没有宝石槽 \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9810b6d..aa181a4 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: RcRPG main: RcRPG.RcRPGMain -version: 1.1.2 +version: 1.1.3 author: 若尘 authors: ["若尘", "Mcayear"] api: 1.0.8