diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java index cd495b9b4..0e5be4131 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java @@ -57,7 +57,7 @@ public class ArmorStandDisplayItem implements DisplayItem { private DisplayData data; ArmorStandDisplayItem(@NotNull Shop shop) { - this(shop, new DisplayData(DisplayType.ARMORSTAND, false)); + this(shop, new DisplayData(DisplayType.ARMORSTAND, false, false)); } ArmorStandDisplayItem(@NotNull Shop shop, @NotNull DisplayData data) { @@ -141,35 +141,22 @@ public class ArmorStandDisplayItem implements DisplayItem { @SuppressWarnings("unchecked") private T getAttribute(DisplayAttribute attr, T defaultValue) { - Object value = data.attribute.get(DisplayAttribute.SMALL); - if (value == null) + Object value = data.attribute.get(attr); + if (value == ObjectUtils.NULL || value == null) return defaultValue; + Util.debugLog("Attribute to cast: " + value); + 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)); + if (value instanceof Integer) { + if (defaultValue instanceof Double) + return (T) Double.valueOf((int) value); + + if (defaultValue instanceof Float) + return (T) Float.valueOf((int) value); } return (T) value; @@ -317,12 +304,12 @@ public class ArmorStandDisplayItem implements DisplayItem { break; } - asloc.setYaw(asloc.getYaw() + getAttribute(DisplayAttribute.OFFSET_YAW, 0)); - asloc.setPitch(asloc.getYaw() + getAttribute(DisplayAttribute.OFFSET_PITCH, 0)); + asloc.setYaw(asloc.getYaw() + getAttribute(DisplayAttribute.OFFSET_YAW, 0f)); + asloc.setPitch(asloc.getYaw() + getAttribute(DisplayAttribute.OFFSET_PITCH, 0f)); asloc.add( - getAttribute(DisplayAttribute.OFFSET_X, 0), - getAttribute(DisplayAttribute.OFFSET_Y, 0), - getAttribute(DisplayAttribute.OFFSET_Z, 0)); + getAttribute(DisplayAttribute.OFFSET_X, 0d), + getAttribute(DisplayAttribute.OFFSET_Y, 0d), + getAttribute(DisplayAttribute.OFFSET_Z, 0d)); return asloc; } @@ -337,34 +324,34 @@ public class ArmorStandDisplayItem implements DisplayItem { 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))); + getAttribute(DisplayAttribute.POSE_BODY_X, 0d), + getAttribute(DisplayAttribute.POSE_BODY_Y, 0d), + getAttribute(DisplayAttribute.POSE_BODY_Z, 0d))); armorStand.setHeadPose(new EulerAngle( - getAttribute(DisplayAttribute.POSE_HEAD_X, 0), - getAttribute(DisplayAttribute.POSE_HEAD_Y, 0), - getAttribute(DisplayAttribute.POSE_HEAD_Z, 0))); + getAttribute(DisplayAttribute.POSE_HEAD_X, 0d), + getAttribute(DisplayAttribute.POSE_HEAD_Y, 0d), + getAttribute(DisplayAttribute.POSE_HEAD_Z, 0d))); 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))); + getAttribute(DisplayAttribute.POSE_ARM_RIGHT_X, 0d), + getAttribute(DisplayAttribute.POSE_ARM_RIGHT_Y, 0d), + getAttribute(DisplayAttribute.POSE_ARM_RIGHT_Z, 0d))); 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))); + getAttribute(DisplayAttribute.POSE_ARM_LEFT_X, 0d), + getAttribute(DisplayAttribute.POSE_ARM_LEFT_Y, 0d), + getAttribute(DisplayAttribute.POSE_ARM_LEFT_Z, 0d))); 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))); + getAttribute(DisplayAttribute.POSE_LEG_RIGHT_X, 0d), + getAttribute(DisplayAttribute.POSE_LEG_RIGHT_Y, 0d), + getAttribute(DisplayAttribute.POSE_LEG_RIGHT_Z, 0d))); 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))); + getAttribute(DisplayAttribute.POSE_LEG_LEFT_X, 0d), + getAttribute(DisplayAttribute.POSE_LEG_LEFT_Y, 0d), + getAttribute(DisplayAttribute.POSE_LEG_LEFT_Z, 0d))); } @Override diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index a35b233b2..c87cf7313 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -109,7 +109,8 @@ public class ContainerShop implements Shop { this.unlimited = unlimited; if (plugin.isDisplay()) { - switch (DisplayItem.getNowUsing(this.item).type) { + DisplayData data = DisplayItem.getNowUsing(this.item); + switch (data.type) { case UNKNOWN: Util.debugLog( "Failed to create a ContainerShop displayItem, the type is unknown, fallback to RealDisplayItem"); @@ -119,7 +120,7 @@ public class ContainerShop implements Shop { this.displayItem = new RealDisplayItem(this); break; case ARMORSTAND: - this.displayItem = new ArmorStandDisplayItem(this); + this.displayItem = new ArmorStandDisplayItem(this, data); break; default: Util.debugLog( diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayData.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayData.java index f9429ea36..d850fecfa 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayData.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayData.java @@ -27,5 +27,6 @@ import lombok.AllArgsConstructor; public class DisplayData { public final DisplayType type; public final Map attribute = Maps.newEnumMap(DisplayAttribute.class); - public final boolean needVaildate; + @Deprecated public final boolean needVaildate; // Bad design + public final boolean fixer; } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java index 3687a0042..cdff5572e 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java @@ -233,6 +233,9 @@ public interface DisplayItem { * lore: common mark */ + DisplayData def = new DisplayData( + DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type")), false, false); + if (item != null) { ConfigurationSection conf = QuickShop.instance.getConfig().getConfigurationSection("shop.display-type-specifics"); @@ -240,21 +243,26 @@ public interface DisplayItem { if (conf != null) { DisplayData dataArmourStand = matchData(conf, "armor-stand", item, true); if (dataArmourStand != null && !dataArmourStand.needVaildate) - return dataArmourStand; + return dataArmourStand.fixer ? + (def.type == dataArmourStand.type ? + dataArmourStand : def) : dataArmourStand; DisplayData dataDroppedItem = matchData(conf, "dropped-item", item, false); if (dataDroppedItem != null) - return dataDroppedItem; + return dataDroppedItem.fixer ? + (def.type == dataDroppedItem.type ? + dataDroppedItem : def) : dataDroppedItem; else if (dataArmourStand != null) - return dataArmourStand; + return dataArmourStand.fixer ? + (def.type == dataArmourStand.type ? + dataArmourStand : def) : dataArmourStand; } } - return new DisplayData( - DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type")), false); + return def; } catch (Throwable e) { e.printStackTrace(); - return new DisplayData(DisplayType.REALITEM, false); + return new DisplayData(DisplayType.REALITEM, false, false); } } @@ -267,11 +275,14 @@ public interface DisplayItem { if (specifics instanceof List) { return matchData0(specifics, item, armorStand); } + Util.debugLog("Specifics Is Not A List: " + specifics); return null; } @Nullable static DisplayData matchData0(@NotNull List specifics, @NotNull ItemStack item, boolean armorStand) { + DisplayData vaildateData = null; + boolean needVaildate = false; for (Object o : specifics) { Util.debugLog("Specific: " + o); if (o instanceof Map) { @@ -283,18 +294,59 @@ public interface DisplayItem { for (Object o_ : specificMap.values()) { Map attrMap = Map.class.cast(o_); + // Mode + Object temp = attrMap.get("fixer"); + Object fixer = temp == null ? false : true; + // Type matcher - Object temp = attrMap.get("type"); - Util.debugLog("Type: " + temp); - Object type = temp == null ? Material.AIR : temp; - boolean needVaildate = false; + temp = attrMap.get("type"); + Object type = temp == null ? "TAG:ANY" : temp; - if (type != Material.AIR) { + if (!type.equals("TAG:ANY")) { if (type instanceof Collection) { - if (!Collection.class.cast(type).contains(item.getType().name())) { + Collection c = Collection.class.cast(type); + boolean containsType = c.contains(item.getType().name()); + + if (c.contains("TYPE:!".concat(item.getType().name()))) { + continue; + } + if (c.contains("TAG:BLOCK") && !containsType) { + if (!item.getType().isBlock()) { + continue; + } + needVaildate = true; + break; + } + if (c.contains("TAG:!BLOCK") && !containsType) { + if (item.getType().isBlock()) { + continue; + } + needVaildate = true; + break; + } + + if (!containsType) { continue; } } else if (type instanceof String) { + if (type.equals("TYPE:!".concat(item.getType().name()))) { + continue; + } + if (type.equals("TAG:BLOCK")) { + if (!item.getType().isBlock()) { + continue; + } + needVaildate = true; + break; + } + if (type.equals("TAG:!BLOCK")) { + if (item.getType().isBlock()) { + continue; + } + needVaildate = true; + break; + } + if (!item.getType().name().equals((type))) { continue; } @@ -304,10 +356,16 @@ public interface DisplayItem { } // Custom Model Data matcher + temp = attrMap.get("strict"); + boolean strict = temp == null ? false : (boolean) temp; + temp = attrMap.get("model-data"); - Util.debugLog("Type: " + temp); - if (temp != null && item.hasItemMeta() && item.getItemMeta().hasCustomModelData()) { - if ((int) temp != item.getItemMeta().getCustomModelData()) { + if (temp != null) { + if (item.hasItemMeta() && item.getItemMeta().hasCustomModelData()) { + if ((int) temp != item.getItemMeta().getCustomModelData()) { + continue; + } + } else { continue; } } else { @@ -315,17 +373,12 @@ public interface DisplayItem { } // 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); + Collection specificLore = Collection.class.cast(lore); if (strict) { if (!specificLore.equals(item.getLore())) { continue; @@ -365,23 +418,22 @@ public interface DisplayItem { } DisplayData data = new DisplayData( - armorStand ? DisplayType.ARMORSTAND : DisplayType.REALITEM, needVaildate); + armorStand ? DisplayType.ARMORSTAND : DisplayType.REALITEM, needVaildate, (boolean) fixer); if (armorStand) { - temp = attrMap.get("attribute"); - Util.debugLog("Type: " + temp); + Map attributes = Map.class.cast(attrMap.get("attribute")); - if (temp instanceof Map) { + if (attributes 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); + temp = Map.class.cast(attributes).get(rootKey); data.attribute.put(attr, temp == null ? ObjectUtils.NULL : temp); } else { // Nested Map - if ((temp = attrMap.get(rootKey)) instanceof Map) { + if ((temp = Map.class.cast(attributes).get(rootKey)) instanceof Map) { String subKey = attrKeys[1].toLowerCase(Locale.ROOT); Object value = Map.class.cast(temp).get(subKey); @@ -393,11 +445,15 @@ public interface DisplayItem { } } - return data; + if (needVaildate) + vaildateData = data; + else + return data; } } } - return null; + + return vaildateData; } /** diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 078e0c6a5..d32375678 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -179,7 +179,122 @@ shop: # Custom display type depending on item meta display-type-specifics: - armor-stand: [] + armor-stand: + - vanilla-fixes: + fixer: true + type: + - TAG:!BLOCK + - TYPE:!BONE + - TYPE:!CHAINMAIL_HELMET + - TYPE:!COD + - TYPE:!DIAMOND_HELMET + - TYPE:!LEAD + - TYPE:!SHIELD + - TYPE:!TRIDENT + - TYPE:!TURTLE_HELMET + - OAK_SAPLING + - SPRUCE_SAPLING + - BIRCH_SAPLING + - JUNGLE_SAPLING + - ACACIA_SAPLING + - DARK_OAK_SAPLING + - ACACIA_DOOR + - DARK_OAK_DOOR + - DARK_OAK_SAPLING + - DARK_OAK_SIGN + - IRON_DOOR + - OAK_DOOR + - BIRCH_DOOR + - JUNGLE_DOOR + - ACACIA_SIGN + - ACACIA_SAPLING + - ACTIVATOR_RAIL + - ALLIUM + - AZURE_BLUET + - BAMBOO + - BARRIER + - BELL + - BLUE_STAINED_GLASS_PANE + - BLUE_BANNER + - BLUE_ORCHID + - BRAIN_CORAL + - BRAIN_CORAL_FAN + - BREWING_STAND + - BROWN_MUSHROOM + - BUBBLE_CORAL + - BUBBLE_CORAL_FAN + - CAKE + - CAMPFIRE + - CAULDRON + - COBWEB + - COMPARATOR + - CORNFLOWER + - DANCELION + - DEAD_BRAIN_CORAL + - DEAD_BRAIN_CORAL_FAN + - DEAD_FIRE_CORAL + - DEAD_FIRE_CORAL_FAN + - DETECTOR_RAIL + - DRAGON_HEAD + - END_ROD + - FERN + - FIRE_CORAL + - DEAD_BUSH + - FIRE_CORAL_FAN + - FLOWER_POT + - GRASS + - HOPPER + - HORN_CORAL + - HORN_CORAL_FAN + - IRON_BARS + - KELP + - LADDER + - LIGHT_BLUE_BANNER + - NETHER_WART + - ORANGE_TULIP + - OXEYE_DAISY + - PEONY + - PINK_BANNER + - POPPY + - REDSTONE_TORCH + - RED_MUSHROOM + - REPEATER + - ROSE_BUSH + - STRUCTURE_VOID + - SUGAR_CANE + - SUNFLOWER + - BERRY_BUSH + - TORCH + - RIPWIRE_HOOK + - TURTLE_EGG + - VINE + - WHEAT + - WITHER_ROSE + attribute: + offset: + y: -0.5 + - demo: + fixer: false + type: AIR + lore: [] + model-data: 114514 + attribute: + small: true + slot: HEAD + offset: + x: 0 + y: 0 + z: 0 + pose: + head: [] + body: [] + arm: + left: + x: 0 + y: 0 + z: 0 + right: [] + leg: [] dropped-item: [] #Allow quickshop auto despawn-spawn the display when no-player or player close the shop.