mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 11:44:25 +00:00
Fix trader edits being lost on an existing linked market
Closing the setup GUI saved the market from the server''s stale role and then re-read that market over the edits it had just applied, so stock and currency cost changes never survived. The role now saves first and the market is written from it, and relinking to another market no longer pushes pre-link data over it.
This commit is contained in:
1 parent
17f61de57a
commit
68b5191db6
3 files changed
+29
-2
No files matched your search
@@ -21,6 +21,7 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
|
||||
private final ResourceLocation slot = new ResourceLocation("customnpcs", "textures/gui/slot.png");
|
||||
private RoleTrader role;
|
||||
private boolean marketRelinked = false;
|
||||
|
||||
// Currency cost textfield IDs start at 100 (100-117 for slots 0-17)
|
||||
private static final int CURRENCY_FIELD_ID_START = 100;
|
||||
@@ -116,8 +117,14 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
PacketClient.sendClient(new TraderMarketSavePacket(role.marketName, false));
|
||||
// Linking to a different market already replaced the server's role with that market's
|
||||
// data. Pushing this GUI's pre-link state back would overwrite the market being linked to.
|
||||
if (marketRelinked)
|
||||
return;
|
||||
|
||||
// Save the role first so the market is written from the edited data, not the stale data.
|
||||
PacketClient.sendClient(new RoleSavePacket(role.writeToNBT(new NBTTagCompound())));
|
||||
PacketClient.sendClient(new TraderMarketSavePacket(role.marketName, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,6 +136,7 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
String name = guiNpcTextField.getText();
|
||||
if (!name.equalsIgnoreCase(role.marketName)) {
|
||||
role.marketName = name;
|
||||
marketRelinked = true;
|
||||
PacketClient.sendClient(new TraderMarketSavePacket(role.marketName, true));
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user