Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct stone inlay index misalignment #6

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file removed lib/MagicItem-1.1.0.jar
Binary file not shown.
Binary file added lib/MagicItem-1.1.2.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>RcRPG.RcRPGMain</groupId>
<artifactId>RcRPG</artifactId>
<version>1.1.2-MOT</version>
<version>1.1.3-MOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -156,7 +156,7 @@
<artifactId>MagicItem</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/lib/MagicItem-1.1.0.jar</systemPath>
<systemPath>${pom.basedir}/lib/MagicItem-1.1.2.jar</systemPath>
</dependency>

<dependency>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/RcRPG/RPG/Armour.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ public static boolean canInlay(Item item){
public static void setStone(Player player,Item item,LinkedList<Stone> list){
ListTag<StringTag> 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();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/RcRPG/RPG/Suit.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Suit {
public static Map<String, SuitConfig> 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);
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/RcRPG/RPG/Weapon.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public class Weapon extends ItemAttr {

private String message;

/**
* 宝石槽列表
*/
private ArrayList<String> stoneList = new ArrayList<>();

private ArrayList<String> loreList = new ArrayList<>();
Expand Down Expand Up @@ -276,7 +279,10 @@ public static boolean canInlay(Item item) {
public static void setStone(Player player, Item item, LinkedList<Stone> list) {
ListTag<StringTag> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package RcRPG.RPG.Forging;
package RcRPG.RPG.forging;

import RcRPG.RcRPGMain;
import cn.ankele.plugin.MagicItem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package RcRPG.RPG.Forging;
package RcRPG.RPG.forging;

import RcRPG.RcRPGMain;
import cn.nukkit.Player;
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/RcRPG/RcRPGMain.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -118,6 +118,7 @@ public void init() {
Suit.init();

this.getLogger().info("开始读取武器信息");
loadWeapon.clear();
for (String name : Handle.getDefaultFiles("Weapon")) {
Weapon weapon = null;
try {
Expand All @@ -133,6 +134,7 @@ public void init() {
}
}
this.getLogger().info("开始读取盔甲信息");
loadArmour.clear();
for (String name : Handle.getDefaultFiles("Armour")) {
Armour armour = null;
try {
Expand All @@ -148,6 +150,7 @@ public void init() {
}
}
this.getLogger().info("开始读取宝石信息");
loadStone.clear();
for (String name : Handle.getDefaultFiles("Stone")) {
Stone stone = null;
try {
Expand All @@ -163,6 +166,7 @@ public void init() {
}
}
this.getLogger().info("开始读取箱子信息");
loadBox.clear();
for (String name : Handle.getDefaultFiles("Box")) {
Box box = null;
try {
Expand All @@ -178,6 +182,7 @@ public void init() {
}
}
this.getLogger().info("开始读取饰品信息");
loadOrnament.clear();
for (String name : Handle.getDefaultFiles("Ornament")) {
Ornament ornament = null;
try {
Expand All @@ -193,6 +198,7 @@ public void init() {
}
}
this.getLogger().info("开始读取锻造图信息");
loadForgingPaper.clear();
for (String name : Handle.getDefaultFiles("Forging" + File.separator + "Paper")) {
ForgingPaper forgingPaper;
try {
Expand All @@ -208,6 +214,7 @@ public void init() {
}
}
this.getLogger().info("开始读取锻造石信息");
loadForgingStone.clear();
for (String name : Handle.getDefaultFiles("Forging" + File.separator + "Stone")) {
ForgingStone forgingStone;
try {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/RcRPG/command/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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":
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
74 changes: 42 additions & 32 deletions src/main/java/RcRPG/panel/form/inlayForm.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,25 +19,31 @@
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;
private Weapon weaponItem = null;
private Armour armourItem = null;
private LinkedList<Stone> 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;
}
Expand All @@ -52,7 +56,9 @@ public void makeInlayForm(Player player, Item item) {

private FormWindowSimple getStateWindow() {
String label = "";
// 镶嵌在装备上的宝石列表
LinkedList<Stone> stones = new LinkedList<>();
// 装备可镶嵌的宝石类型列表
ArrayList<String> stoneSlots = new ArrayList<>();
if (weaponItem != null) {
stones = Weapon.getStones(handItem);
Expand All @@ -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()));
Expand Down Expand Up @@ -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_);
Expand All @@ -124,6 +134,7 @@ private FormWindowCustom getStoneWindow(String yamlName, LinkedList<String> ston
}

private void handleStoneWindowResponse(FormWindowCustom form, Player player) {
// 装备 yamlName 名字
String itemName = "";
LinkedList<Stone> stones = new LinkedList<>();
if (weaponItem != null) {
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package RcRPG.Task;
package RcRPG.task;

import RcRPG.RcRPGMain;
import RcRPG.PlayerStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package RcRPG.Task;
package RcRPG.task;

import RcRPG.AttrManager.PlayerAttr;
import RcRPG.Events;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package RcRPG.Task;
package RcRPG.task;

import RcRPG.Handle;
import RcRPG.RcRPGMain;
Expand All @@ -11,9 +11,9 @@
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.scheduler.PluginTask;

public class Tip extends PluginTask<RcRPGMain> {
public class PlayerTipTask extends PluginTask<RcRPGMain> {

public Tip(RcRPGMain rcRPGMain){
public PlayerTipTask(RcRPGMain rcRPGMain){
super(rcRPGMain);
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/language/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading
Loading