Update shop change item option to use the item in the players mainhand.
This commit is contained in:
parent
c209e0098a
commit
46dec9a933
|
|
@ -4,29 +4,21 @@ import com.alttd.playershops.shop.PlayerShop;
|
||||||
import com.alttd.playershops.shop.ShopType;
|
import com.alttd.playershops.shop.ShopType;
|
||||||
import com.alttd.playershops.utils.EconomyUtils;
|
import com.alttd.playershops.utils.EconomyUtils;
|
||||||
import com.alttd.playershops.utils.ShopUtil;
|
import com.alttd.playershops.utils.ShopUtil;
|
||||||
import com.alttd.playershops.utils.Util;
|
|
||||||
import io.papermc.paper.dialog.Dialog;
|
import io.papermc.paper.dialog.Dialog;
|
||||||
import io.papermc.paper.registry.data.dialog.ActionButton;
|
import io.papermc.paper.registry.data.dialog.ActionButton;
|
||||||
import io.papermc.paper.registry.data.dialog.DialogBase;
|
import io.papermc.paper.registry.data.dialog.DialogBase;
|
||||||
import io.papermc.paper.registry.data.dialog.action.DialogAction;
|
import io.papermc.paper.registry.data.dialog.action.DialogAction;
|
||||||
import io.papermc.paper.registry.data.dialog.body.DialogBody;
|
|
||||||
import io.papermc.paper.registry.data.dialog.input.DialogInput;
|
import io.papermc.paper.registry.data.dialog.input.DialogInput;
|
||||||
import io.papermc.paper.registry.data.dialog.input.SingleOptionDialogInput;
|
import io.papermc.paper.registry.data.dialog.input.SingleOptionDialogInput;
|
||||||
import io.papermc.paper.registry.data.dialog.type.DialogType;
|
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.event.ClickCallback;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ManageShopDialog extends AbstractDialog {
|
public class ManageShopDialog extends AbstractDialog {
|
||||||
|
|
@ -85,9 +77,6 @@ public class ManageShopDialog extends AbstractDialog {
|
||||||
.initial(false)
|
.initial(false)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
inputs.add(
|
|
||||||
DialogInput.singleOption("item", MiniMessage.miniMessage().deserialize("<gold>Item</gold>"), itemEntries()).build()
|
|
||||||
);
|
|
||||||
int maxQty = (shop.isInitialized() && shop.getItemStack() != null ? 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);
|
int initialQty = (shop.isInitialized() ? Math.min(shop.getAmount(), maxQty) : 1);
|
||||||
inputs.add(
|
inputs.add(
|
||||||
|
|
@ -148,19 +137,21 @@ public class ManageShopDialog extends AbstractDialog {
|
||||||
|
|
||||||
// Change Item
|
// Change Item
|
||||||
if (Boolean.TRUE.equals(view.getBoolean("changeitem"))) {
|
if (Boolean.TRUE.equals(view.getBoolean("changeitem"))) {
|
||||||
String selection = view.getText("item");
|
ItemStack itemStack = player.getInventory().getItemInMainHand().clone();
|
||||||
if (selection != null) {
|
shop.setItemStack(itemStack);
|
||||||
if (selection.equalsIgnoreCase("reset")) {
|
// String selection = view.getText("item");
|
||||||
shop.setItemStack(null);
|
// if (selection != null) {
|
||||||
} else {
|
// if (selection.equalsIgnoreCase("reset")) {
|
||||||
int slot;
|
// shop.setItemStack(null);
|
||||||
try {
|
// } else {
|
||||||
slot = Integer.parseInt(selection);
|
// int slot;
|
||||||
shop.setItemStack(player.getInventory().getItem(slot));
|
// try {
|
||||||
} catch (NumberFormatException ignored) {
|
// slot = Integer.parseInt(selection);
|
||||||
}
|
// shop.setItemStack(player.getInventory().getItem(slot));
|
||||||
}
|
// } catch (NumberFormatException ignored) {
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change Amount
|
// Change Amount
|
||||||
|
|
@ -188,27 +179,27 @@ public class ManageShopDialog extends AbstractDialog {
|
||||||
actions.add(saveButton);
|
actions.add(saveButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SingleOptionDialogInput.OptionEntry> itemEntries() {
|
// List<SingleOptionDialogInput.OptionEntry> itemEntries() {
|
||||||
List<SingleOptionDialogInput.OptionEntry> optionEntries = new ArrayList<>();
|
// List<SingleOptionDialogInput.OptionEntry> optionEntries = new ArrayList<>();
|
||||||
|
//
|
||||||
if (getPlayer() == null) {
|
// if (getPlayer() == null) {
|
||||||
return optionEntries;
|
// return optionEntries;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
optionEntries.add(
|
// optionEntries.add(
|
||||||
SingleOptionDialogInput.OptionEntry.create("reset", MiniMessage.miniMessage().deserialize("<gold>Reset"), false)
|
// SingleOptionDialogInput.OptionEntry.create("reset", MiniMessage.miniMessage().deserialize("<gold>Reset"), false)
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
for (int i = 0; i < getPlayer().getInventory().getSize() ; i++) {
|
// for (int i = 0; i < getPlayer().getInventory().getSize() ; i++) {
|
||||||
ItemStack item = getPlayer().getInventory().getItem(i);
|
// ItemStack item = getPlayer().getInventory().getItem(i);
|
||||||
if (item == null || item.getType() == Material.AIR) continue;
|
// if (item == null || item.getType() == Material.AIR) continue;
|
||||||
ItemStack itemStack = item.clone();
|
// ItemStack itemStack = item.clone();
|
||||||
optionEntries.add(
|
// optionEntries.add(
|
||||||
SingleOptionDialogInput.OptionEntry.create(String.valueOf(i), ShopUtil.spriteComponent(itemStack), shop.getItemStack() == itemStack)
|
// SingleOptionDialogInput.OptionEntry.create(String.valueOf(i), ShopUtil.spriteComponent(itemStack), shop.getItemStack() == itemStack)
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return optionEntries;
|
// return optionEntries;
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user