From 5b3cedf3ff57005b05f65e883c9ca9eddb63654b Mon Sep 17 00:00:00 2001 From: Sotr Date: Wed, 29 Jan 2020 03:29:16 +0700 Subject: [PATCH] Full configurable display Former-commit-id: 23289dda40676be19cf90377504360096b497fbb --- .../Event/ShopDisplayItemDespawnEvent.java | 3 +- .../Event/ShopDisplayItemSpawnEvent.java | 2 +- .../Listeners/DisplayBugFixListener.java | 2 +- .../quickshop/Shop/ArmorStandDisplayItem.java | 113 +++++- .../quickshop/Shop/ContainerShop.java | 2 +- .../quickshop/Shop/DisplayAttribute.java | 56 +++ .../maxgamer/quickshop/Shop/DisplayData.java | 31 ++ .../maxgamer/quickshop/Shop/DisplayItem.java | 352 ++++++++++-------- src/main/resources/config.yml | 17 +- 9 files changed, 393 insertions(+), 185 deletions(-) create mode 100644 src/main/java/org/maxgamer/quickshop/Shop/DisplayAttribute.java create mode 100644 src/main/java/org/maxgamer/quickshop/Shop/DisplayData.java diff --git a/src/main/java/org/maxgamer/quickshop/Event/ShopDisplayItemDespawnEvent.java b/src/main/java/org/maxgamer/quickshop/Event/ShopDisplayItemDespawnEvent.java index c565ddd1e..d90c5cd77 100644 --- a/src/main/java/org/maxgamer/quickshop/Event/ShopDisplayItemDespawnEvent.java +++ b/src/main/java/org/maxgamer/quickshop/Event/ShopDisplayItemDespawnEvent.java @@ -23,6 +23,7 @@ import lombok.Getter; import org.bukkit.event.Cancellable; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Shop.DisplayItem; import org.maxgamer.quickshop.Shop.DisplayType; import org.maxgamer.quickshop.Shop.Shop; @@ -60,7 +61,7 @@ public class ShopDisplayItemDespawnEvent extends QSEvent implements Cancellable */ @Deprecated public ShopDisplayItemDespawnEvent(@NotNull Shop shop, @NotNull ItemStack itemStack) { - this(shop, itemStack, DisplayItem.getNowUsing(itemStack)); + this(shop, itemStack, DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type"))); } @Override diff --git a/src/main/java/org/maxgamer/quickshop/Event/ShopDisplayItemSpawnEvent.java b/src/main/java/org/maxgamer/quickshop/Event/ShopDisplayItemSpawnEvent.java index 93e9f2401..32f896dbf 100644 --- a/src/main/java/org/maxgamer/quickshop/Event/ShopDisplayItemSpawnEvent.java +++ b/src/main/java/org/maxgamer/quickshop/Event/ShopDisplayItemSpawnEvent.java @@ -60,7 +60,7 @@ public class ShopDisplayItemSpawnEvent extends QSEvent implements Cancellable { */ @Deprecated public ShopDisplayItemSpawnEvent(@NotNull Shop shop, @NotNull ItemStack itemStack) { - this(shop, itemStack, DisplayItem.getNowUsing(itemStack)); + this(shop, itemStack, DisplayItem.getNowUsing(itemStack).type); } @Override diff --git a/src/main/java/org/maxgamer/quickshop/Listeners/DisplayBugFixListener.java b/src/main/java/org/maxgamer/quickshop/Listeners/DisplayBugFixListener.java index e305e4979..b5c4314e5 100644 --- a/src/main/java/org/maxgamer/quickshop/Listeners/DisplayBugFixListener.java +++ b/src/main/java/org/maxgamer/quickshop/Listeners/DisplayBugFixListener.java @@ -40,7 +40,7 @@ public class DisplayBugFixListener implements Listener { @EventHandler(ignoreCancelled = true) public void canBuild(BlockCanBuildEvent e) { if (!plugin.isDisplay() - || DisplayItem.getNowUsing(null) != DisplayType.ARMORSTAND + //|| DisplayItem.getNowUsing(null) != DisplayType.ARMORSTAND || e.isBuildable()) { return; } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java index 22dbba862..cd495b9b4 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java @@ -21,6 +21,7 @@ package org.maxgamer.quickshop.Shop; import java.util.Objects; import lombok.ToString; +import org.apache.commons.lang.ObjectUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -45,16 +46,25 @@ import com.bekvon.bukkit.residence.commands.contract; public class ArmorStandDisplayItem implements DisplayItem { boolean pendingRemoval; - @Nullable private volatile ArmorStand armorStand; - @Nullable private ItemStack guardedIstack; + @Nullable + private volatile ArmorStand armorStand; + @Nullable + private ItemStack guardedIstack; private ItemStack originalItemStack; private QuickShop plugin = QuickShop.instance; private Shop shop; + @NotNull + private DisplayData data; ArmorStandDisplayItem(@NotNull Shop shop) { + this(shop, new DisplayData(DisplayType.ARMORSTAND, false)); + } + + ArmorStandDisplayItem(@NotNull Shop shop, @NotNull DisplayData data) { this.shop = shop; this.originalItemStack = new ItemStack(shop.getItem()); this.originalItemStack.setAmount(1); + this.data = data; } private static boolean isTool(Material material) { @@ -113,21 +123,64 @@ public class ArmorStandDisplayItem implements DisplayItem { armorStand.setVisible(false); armorStand.setMarker(true); armorStand.setCollidable(false); - armorStand.setSmall(true); + armorStand.setSmall(getAttribute(DisplayAttribute.SMALL, true)); armorStand.setArms(false); armorStand.setBasePlate(false); armorStand.setSilent(true); armorStand.setAI(false); armorStand.setCanMove(false); armorStand.setCanPickupItems(false); - // Set pose (this is for hand while we use helmet) - // setPoseForArmorStand(); + // Set pose + setPoseForArmorStand(armorStand); }); // Set safeGuard Util.debugLog("Spawned armor stand @ " + this.armorStand.getLocation() + " with UUID " + this.armorStand.getUniqueId()); safeGuard(this.armorStand); // Helmet must be set after spawning } } + + @SuppressWarnings("unchecked") + private T getAttribute(DisplayAttribute attr, T defaultValue) { + Object value = data.attribute.get(DisplayAttribute.SMALL); + if (value == null) + return defaultValue; + try { + if (value.equals(ObjectUtils.NULL)) + return defaultValue; + + if (defaultValue instanceof String) { + return (T) String.class.cast(value); + } + + if (defaultValue instanceof EquipmentSlot) { + return (T) EquipmentSlot.valueOf(String.class.cast(value)); + } + + if (defaultValue instanceof Boolean) { + return (T) Boolean.valueOf(String.class.cast(value)); + } + + if (defaultValue instanceof Integer) { + return (T) Integer.valueOf(String.class.cast(value)); + } + + if (defaultValue instanceof Float) { + return (T) Float.valueOf(String.class.cast(value)); + } + + if (defaultValue instanceof Double) { + return (T) Double.valueOf(String.class.cast(value)); + } + + return (T) value; + } catch (Throwable t) { + plugin.getLogger().warning("Error when processing attribute for " + + attr.name() + " with unexpected value " + + value.toString() + ", please check your config before reporting!"); + t.printStackTrace(); + return defaultValue; + } + } @Override public boolean removeDupe() { @@ -168,7 +221,7 @@ public class ArmorStandDisplayItem implements DisplayItem { ArmorStand armorStand = (ArmorStand) entity; // Set item protect in the armorstand's hand this.guardedIstack = DisplayItem.createGuardItemStack(this.originalItemStack, this.shop); - armorStand.setHelmet(guardedIstack); + armorStand.setItem(getAttribute(DisplayAttribute.SLOT, EquipmentSlot.HEAD), guardedIstack); try { armorStand .getPersistentDataContainer() @@ -213,6 +266,7 @@ public class ArmorStandDisplayItem implements DisplayItem { ((Directional) this.shop.getLocation().getBlock().getBlockData()) .getFacing(); // Replace by container face. } + // Fix specific block facing Material type = this.shop.getLocation().getBlock().getType(); if (type.name().contains("ANVIL") || type.name().contains("FENCE") || type.name().contains("WALL") ) { @@ -233,9 +287,11 @@ public class ArmorStandDisplayItem implements DisplayItem { Location asloc = getCenter(this.shop.getLocation()); Util.debugLog("containerBlockFace " + containerBlockFace); + if (this.originalItemStack.getType().isBlock()) { asloc.add(0, 0.5, 0); } + switch (containerBlockFace) { case SOUTH: asloc.add(0, -0.5, 0); @@ -260,6 +316,14 @@ public class ArmorStandDisplayItem implements DisplayItem { default: break; } + + asloc.setYaw(asloc.getYaw() + getAttribute(DisplayAttribute.OFFSET_YAW, 0)); + asloc.setPitch(asloc.getYaw() + getAttribute(DisplayAttribute.OFFSET_PITCH, 0)); + asloc.add( + getAttribute(DisplayAttribute.OFFSET_X, 0), + getAttribute(DisplayAttribute.OFFSET_Y, 0), + getAttribute(DisplayAttribute.OFFSET_Z, 0)); + return asloc; } @@ -271,13 +335,36 @@ public class ArmorStandDisplayItem implements DisplayItem { loc.getBlockZ() + .5); } - @Deprecated // no use, will be removed soon - private void setPoseForArmorStand() { - if (this.originalItemStack.getType().isBlock()) { - Objects.requireNonNull(armorStand).setRightArmPose(new EulerAngle(-0.2, 0, 0)); - } else { - Objects.requireNonNull(armorStand).setRightArmPose(new EulerAngle(-89.5, 0, 0)); - } + private void setPoseForArmorStand(ArmorStand armorStand) { + armorStand.setBodyPose(new EulerAngle( + getAttribute(DisplayAttribute.POSE_BODY_X, 0), + getAttribute(DisplayAttribute.POSE_BODY_Y, 0), + getAttribute(DisplayAttribute.POSE_BODY_Z, 0))); + + armorStand.setHeadPose(new EulerAngle( + getAttribute(DisplayAttribute.POSE_HEAD_X, 0), + getAttribute(DisplayAttribute.POSE_HEAD_Y, 0), + getAttribute(DisplayAttribute.POSE_HEAD_Z, 0))); + + armorStand.setRightArmPose(new EulerAngle( + getAttribute(DisplayAttribute.POSE_ARM_RIGHT_X, 0), + getAttribute(DisplayAttribute.POSE_ARM_RIGHT_Y, 0), + getAttribute(DisplayAttribute.POSE_ARM_RIGHT_Z, 0))); + + armorStand.setLeftArmPose(new EulerAngle( + getAttribute(DisplayAttribute.POSE_ARM_LEFT_X, 0), + getAttribute(DisplayAttribute.POSE_ARM_LEFT_Y, 0), + getAttribute(DisplayAttribute.POSE_ARM_LEFT_Z, 0))); + + armorStand.setRightLegPose(new EulerAngle( + getAttribute(DisplayAttribute.POSE_LEG_RIGHT_X, 0), + getAttribute(DisplayAttribute.POSE_LEG_RIGHT_Y, 0), + getAttribute(DisplayAttribute.POSE_LEG_RIGHT_Z, 0))); + + armorStand.setLeftLegPose(new EulerAngle( + getAttribute(DisplayAttribute.POSE_LEG_LEFT_X, 0), + getAttribute(DisplayAttribute.POSE_LEG_LEFT_Y, 0), + getAttribute(DisplayAttribute.POSE_LEG_LEFT_Z, 0))); } @Override diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index 4f2e599b9..a35b233b2 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -109,7 +109,7 @@ public class ContainerShop implements Shop { this.unlimited = unlimited; if (plugin.isDisplay()) { - switch (DisplayItem.getNowUsing(this.item)) { + switch (DisplayItem.getNowUsing(this.item).type) { case UNKNOWN: Util.debugLog( "Failed to create a ContainerShop displayItem, the type is unknown, fallback to RealDisplayItem"); diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayAttribute.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayAttribute.java new file mode 100644 index 000000000..560ea5874 --- /dev/null +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayAttribute.java @@ -0,0 +1,56 @@ +/* + * This file is a part of project QuickShop, the name is DisplayType.java + * Copyright (C) Ghost_chu + * Copyright (C) Bukkit Commons Studio and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.maxgamer.quickshop.Shop; + +public enum DisplayAttribute { + SMALL, + SLOT, + + OFFSET_YAW, + OFFSET_PITCH, + + OFFSET_X, + OFFSET_Y, + OFFSET_Z, + + POSE_HEAD_X, + POSE_HEAD_Y, + POSE_HEAD_Z, + + POSE_BODY_X, + POSE_BODY_Y, + POSE_BODY_Z, + + POSE_ARM_LEFT_X, + POSE_ARM_LEFT_Y, + POSE_ARM_LEFT_Z, + + POSE_ARM_RIGHT_X, + POSE_ARM_RIGHT_Y, + POSE_ARM_RIGHT_Z, + + POSE_LEG_LEFT_X, + POSE_LEG_LEFT_Y, + POSE_LEG_LEFT_Z, + + POSE_LEG_RIGHT_X, + POSE_LEG_RIGHT_Y, + POSE_LEG_RIGHT_Z; +} diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayData.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayData.java new file mode 100644 index 000000000..f9429ea36 --- /dev/null +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayData.java @@ -0,0 +1,31 @@ +/* + * This file is a part of project QuickShop, the name is DisplayData.java + * Copyright (C) Ghost_chu + * Copyright (C) Bukkit Commons Studio and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.maxgamer.quickshop.Shop; + +import java.util.Map; +import com.google.common.collect.Maps; +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public class DisplayData { + public final DisplayType type; + public final Map attribute = Maps.newEnumMap(DisplayAttribute.class); + public final boolean needVaildate; +} diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java index ac8682f74..3687a0042 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java @@ -19,16 +19,24 @@ package org.maxgamer.quickshop.Shop; +import com.bekvon.bukkit.residence.commands.contract; +import com.google.common.base.Objects; import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; +import java.time.Year; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Map.Entry; +import org.apache.commons.lang.ObjectUtils; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Entity; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -180,184 +188,216 @@ public interface DisplayItem { * * @return Using displayType. */ - static DisplayType getNowUsing(@Nullable ItemStack item) { + static DisplayData getNowUsing(@Nullable ItemStack item) { try { - if (item != null) { /* - * The below codes are massy like a shit (but not bad at function), need to cleanup - * * Nest structure as: - * 1: - * small_: - * specific: - * type: DEBUG_STICK - * lore: - * - mysterious item - * - gift - * strict: true - * yaw: 180 - * pitch: 0 - * small: false - * item-slot: HELMET - * offset: - * x: 1 - * y: 0.1 - * z: -1.1 - * pose-head: - * x: 1 - * pose-body: - * y: 0.2 - * pose-arm: - * left: - * z: 0.5 - * pose-leg: - * left: - * x: 0.14 - * right: - * x: 0.3 + * armor-stand: + * - myStick: + * type: DEBUG_STICK + * lore: + * - mysterious item + * - gift + * strict: true + * attribute: + * yaw: 180 + * pitch: 0 + * small: false + * item-slot: HELMET + * offset: + * x: 1 * y: 0.1 - * z: 0.3 - * small2: - * specific: + * z: -1.1 + * pose-head: + * x: 1 + * pose-body: + * y: 0.2 + * pose-arm: + * left: + * z: 0.5 + * pose-leg: + * left: + * x: 0.14 + * right: + * x: 0.3 + * y: 0.1 + * z: 0.3 + * - grasses: * type: * - GLASS * - GRASS * - GRASS_BLOCK - * 0: - * small: - * specific: - * type: BOW - * lore: common mark - */ - // type id such as 0, 1, 2, 3. - List typeSections = - QuickShop.instance.getConfig().getList("shop.display-type-specifics", Lists.newArrayList()); - if (typeSections.isEmpty()) { - return DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type")); - } - for (Object typeSection : typeSections) { - if (typeSection == null) { - continue; + * real-item: + * - 0: + * type: BOW + * lore: common mark + */ + + if (item != null) { + ConfigurationSection conf = + QuickShop.instance.getConfig().getConfigurationSection("shop.display-type-specifics"); + + if (conf != null) { + DisplayData dataArmourStand = matchData(conf, "armor-stand", item, true); + if (dataArmourStand != null && !dataArmourStand.needVaildate) + return dataArmourStand; + + DisplayData dataDroppedItem = matchData(conf, "dropped-item", item, false); + if (dataDroppedItem != null) + return dataDroppedItem; + else if (dataArmourStand != null) + return dataArmourStand; } - // id as key - Util.debugLog(typeSection.toString() + " @ LEVEL 1, " + typeSection.getClass().getName()); - if (typeSection instanceof Map) { - Map itemSections = Map.class.cast(typeSection); - for (Entry itemSection : itemSections.entrySet()) { - if (itemSection == null) { + } + + return new DisplayData( + DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type")), false); + } catch (Throwable e) { + e.printStackTrace(); + return new DisplayData(DisplayType.REALITEM, false); + } + } + + @Nullable + static DisplayData matchData(@NotNull ConfigurationSection conf, @NotNull String rootType, @NotNull ItemStack item, boolean armorStand) { + List specifics = conf.getList(rootType); + // + // Value: Specific Map + + if (specifics instanceof List) { + return matchData0(specifics, item, armorStand); + } + return null; + } + + @Nullable + static DisplayData matchData0(@NotNull List specifics, @NotNull ItemStack item, boolean armorStand) { + for (Object o : specifics) { + Util.debugLog("Specific: " + o); + if (o instanceof Map) { + Map specificMap = Map.class.cast(o); + // > + // Key: Custom name of Specific + // Value: Attribute Map + + for (Object o_ : specificMap.values()) { + Map attrMap = Map.class.cast(o_); + + // Type matcher + Object temp = attrMap.get("type"); + Util.debugLog("Type: " + temp); + Object type = temp == null ? Material.AIR : temp; + boolean needVaildate = false; + + if (type != Material.AIR) { + if (type instanceof Collection) { + if (!Collection.class.cast(type).contains(item.getType().name())) { + continue; + } + } else if (type instanceof String) { + if (!item.getType().name().equals((type))) { + continue; + } + } + } else { + needVaildate = true; + } + + // Custom Model Data matcher + temp = attrMap.get("model-data"); + Util.debugLog("Type: " + temp); + if (temp != null && item.hasItemMeta() && item.getItemMeta().hasCustomModelData()) { + if ((int) temp != item.getItemMeta().getCustomModelData()) { continue; } - // list - Util.debugLog(itemSection+ " @ LEVEL 2, " + itemSection.getClass().getName()); - if (itemSection.getValue() instanceof List) { - List infoSections = (List) itemSection.getValue(); - for (Object $infoSection : infoSections) { - if ($infoSection == null) { + } else { + needVaildate = true; + } + + // Lore matcher + temp = attrMap.get("strict"); + Util.debugLog("Type: " + temp); + boolean strict = temp == null ? false : (boolean) temp; + + temp = attrMap.get("lore"); + Util.debugLog("Type: " + temp); + Object lore = temp == null ? "" : temp; + + if (!lore.equals("") && item.hasItemMeta() && item.getItemMeta().hasLore()) { + if (lore instanceof Collection) { + Collection specificLore = Collection.class.cast(type); + if (strict) { + if (!specificLore.equals(item.getLore())) { continue; } - // custom name as key - Util.debugLog($infoSection.toString() + " @ LEVEL 3, " + $infoSection.getClass().getName()); - if ($infoSection instanceof Map) { - for (Object infoSectiont : Map.class.cast($infoSection).values()) { - if (infoSectiont == null) { - continue; - } - Map infoSection = Map.class.cast(infoSectiont); - Util.debugLog(infoSection.toString() + " @ LEVEL 4, " + infoSection.getClass().getName()); - List type = Lists.newArrayList(); - boolean strictMeta = (boolean) infoSection.getOrDefault("strict", false); - String name = ""; - List lore = Lists.newArrayList(); - int customModelData = -1; - - Object strOrListType = infoSection.getOrDefault("type", Lists.newArrayList()); - if (strOrListType instanceof List) { - for (Object s : (List) strOrListType) { - if (s instanceof String) { - type.add(Material.valueOf((String) s)); - } - } - } else { - type = Collections.singletonList(Material.valueOf((String) strOrListType)); - } - - name = (String) infoSection.getOrDefault("name", ""); - - Object strOrListLore = infoSection.getOrDefault("lore", Lists.newArrayList()); - if (strOrListLore instanceof List) { - for (Object s : (List) strOrListLore) { - if (s instanceof String) { - lore.add((String) s); - } - } - } else { - lore = Collections.singletonList((String) strOrListLore); - } - - customModelData = (int) infoSection.getOrDefault("custom-model-data", -1); - - boolean meta = !name.isEmpty() || !lore.isEmpty() || customModelData != -1; - if (type.isEmpty() || type.contains(item.getType())) { - if (meta) { - if (item.hasItemMeta()) { - ItemMeta itemMeta = item.getItemMeta(); - - if (!name.isEmpty()) { - if (!(itemMeta.hasDisplayName() && name.equals(itemMeta.getDisplayName()))) { - Util.debugLog("getNowUsing failed in name"); - return - DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type")); - } - } - - if (!lore.isEmpty()) { - boolean loreCheck = strictMeta ? lore.equals(itemMeta.getLore()) : - lore.containsAll(itemMeta.getLore()); - if (!(itemMeta.hasLore() && loreCheck)) { - Util.debugLog("getNowUsing failed in lore"); - return - DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type")); - } - } - - try { - if (customModelData != -1) { - if (!(itemMeta.hasCustomModelData() && - customModelData == itemMeta.getCustomModelData())) { - Util.debugLog("getNowUsing failed in CMD"); - return - DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type")); - } - } - } catch (Exception e) { - ; - } - - Util.debugLog("getNowUsing passed thorough meta"); - return DisplayType.fromID((Integer) itemSection.getKey()); - } else { - ; - } - - } else { - Util.debugLog("getNowUsing passed without meta"); - return DisplayType.fromID((Integer) itemSection.getKey()); - } + } else { + boolean hasAny = false; + + LOOP_LORE: + for (String s : item.getLore()) { + if (specificLore.contains(s)) { + hasAny = true; + break LOOP_LORE; } } + + if (!hasAny) { + continue; + } else { + needVaildate = true; + } + } + } else if (lore instanceof String) { + if (strict) { + if (!item.getLore().equals(lore)) { + continue; + } + } else { + if (!item.getLore().contains((lore))) { + continue; + } else { + needVaildate = true; + } + } + } + } else { + needVaildate = true; + } + + DisplayData data = new DisplayData( + armorStand ? DisplayType.ARMORSTAND : DisplayType.REALITEM, needVaildate); + if (armorStand) { + temp = attrMap.get("attribute"); + Util.debugLog("Type: " + temp); + + if (temp instanceof Map) { + for (DisplayAttribute attr : DisplayAttribute.values()) { + String[] attrKeys = attr.name().split("_"); + String rootKey = attrKeys[0].toLowerCase(Locale.ROOT); + + if (attrKeys.length == 1) { + temp = attrMap.get(rootKey); + data.attribute.put(attr, + temp == null ? ObjectUtils.NULL : temp); + } else { + // Nested Map + if ((temp = attrMap.get(rootKey)) instanceof Map) { + String subKey = attrKeys[1].toLowerCase(Locale.ROOT); + Object value = Map.class.cast(temp).get(subKey); + + data.attribute.put(attr, + value == null ? ObjectUtils.NULL : value); + } } } } } + + return data; } } } - - return DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type")); - } catch (Throwable e) { - e.printStackTrace(); - return DisplayType.REALITEM; - } + return null; } /** diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 14c363f24..59c9866ca 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -179,21 +179,14 @@ shop: # Custom display type depending on item meta display-type-specifics: - - 0: - - customType0: - type: AIR - lore: [] - strict: true - - customType1: + armor-stand: + - demo: type: - - AIR - - AIR - - 1: + - BOW + - GRASS + dropped-item: - demo: type: AIR - lore: - - A demo item lore - - Another demo lore #Allow quickshop auto despawn-spawn the display when no-player or player close the shop. display-auto-despawn: false