Fix shops resetting itemstack size to qty 1
This commit is contained in:
parent
49fb85229d
commit
e554e2643d
|
|
@ -88,7 +88,7 @@ public class ManageShopDialog extends AbstractDialog {
|
|||
inputs.add(
|
||||
DialogInput.singleOption("item", MiniMessage.miniMessage().deserialize("<gold>Item</gold>"), itemEntries()).build()
|
||||
);
|
||||
int maxQty = (shop.isInitialized() ? shop.getItemStack().getMaxStackSize() : 64);
|
||||
int maxQty = (shop.isInitialized() && shop.getItemStack() != null ? shop.getItemStack().getMaxStackSize() : 64);
|
||||
int initialQty = (shop.isInitialized() ? Math.min(shop.getAmount(), maxQty) : 1);
|
||||
inputs.add(
|
||||
DialogInput.numberRange("amount", MiniMessage.miniMessage().deserialize("<gold>Change amount</gold>"), 1f, (float) maxQty)
|
||||
|
|
@ -152,12 +152,14 @@ public class ManageShopDialog extends AbstractDialog {
|
|||
if (selection != null) {
|
||||
if (selection.equalsIgnoreCase("reset")) {
|
||||
shop.setItemStack(null);
|
||||
}
|
||||
} else {
|
||||
int slot;
|
||||
try {
|
||||
slot = Integer.parseInt(selection);
|
||||
shop.setItemStack(player.getInventory().getItem(slot));
|
||||
} catch (NumberFormatException ignored) {}
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -200,8 +202,9 @@ public class ManageShopDialog extends AbstractDialog {
|
|||
for (int i = 0; i < getPlayer().getInventory().getSize() ; i++) {
|
||||
ItemStack item = getPlayer().getInventory().getItem(i);
|
||||
if (item == null || item.getType() == Material.AIR) continue;
|
||||
ItemStack itemStack = item.clone();
|
||||
optionEntries.add(
|
||||
SingleOptionDialogInput.OptionEntry.create(String.valueOf(i), ShopUtil.spriteComponent(item), shop.getItemStack() == item)
|
||||
SingleOptionDialogInput.OptionEntry.create(String.valueOf(i), ShopUtil.spriteComponent(itemStack), shop.getItemStack() == itemStack)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,16 @@
|
|||
package com.alttd.playershops.dialog;
|
||||
|
||||
import com.alttd.playershops.PlayerShops;
|
||||
import com.alttd.playershops.config.MessageConfig;
|
||||
import com.alttd.playershops.utils.ShopUtil;
|
||||
import io.papermc.paper.dialog.Dialog;
|
||||
import io.papermc.paper.registry.data.dialog.ActionButton;
|
||||
import io.papermc.paper.registry.data.dialog.DialogBase;
|
||||
import io.papermc.paper.registry.data.dialog.action.DialogAction;
|
||||
import io.papermc.paper.registry.data.dialog.type.DialogType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickCallback;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.object.ObjectContents;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ShopDialog extends AbstractDialog {
|
||||
|
|
@ -111,7 +104,7 @@ public class ShopDialog extends AbstractDialog {
|
|||
)
|
||||
.build()
|
||||
);
|
||||
actions.add(
|
||||
/* actions.add(
|
||||
ActionButton.builder(
|
||||
MiniMessage.miniMessage().deserialize("Settings"))
|
||||
.action(
|
||||
|
|
@ -129,7 +122,7 @@ public class ShopDialog extends AbstractDialog {
|
|||
.build())
|
||||
)
|
||||
.build()
|
||||
);
|
||||
);*/
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ public class PlayerShop {
|
|||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
return type != ShopType.NONE && itemStack != null;
|
||||
return type != ShopType.NONE;
|
||||
}
|
||||
|
||||
public void updateSign() {
|
||||
|
|
@ -368,8 +368,12 @@ public class PlayerShop {
|
|||
if (Util.callCancellableEvent(shopItemChangeEvent))
|
||||
return; // cancelled by another plugin, does this need logging?
|
||||
|
||||
this.itemStack = itemStack;
|
||||
if (itemStack == null) {
|
||||
this.itemStack = null;
|
||||
} else {
|
||||
this.itemStack = itemStack.clone();
|
||||
this.itemStack.setAmount(this.amount != 0 ? this.amount : 1);
|
||||
}
|
||||
setDirty(true);
|
||||
update();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user