Revert "Fixes & add default config for custom display"

This reverts commit 51ccfa92


Former-commit-id: 69bdffe8b9daf39ad39ddb0f20644a93e3c8c286
This commit is contained in:
Ghost_chu committed 2020-01-30 09:53:57 +08:00
1 parent d46614db45
commit e12fecb0e7
4 files changed
+79 -124

No files matched your search

@@ -57,7 +57,7 @@ public class ArmorStandDisplayItem implements DisplayItem {
private DisplayData data;
ArmorStandDisplayItem(@NotNull Shop shop) {
this(shop, new DisplayData(DisplayType.ARMORSTAND, false, false));
this(shop, new DisplayData(DisplayType.ARMORSTAND, false));
}
ArmorStandDisplayItem(@NotNull Shop shop, @NotNull DisplayData data) {
@@ -141,22 +141,35 @@ public class ArmorStandDisplayItem implements DisplayItem {
@SuppressWarnings("unchecked")
private <T> T getAttribute(DisplayAttribute attr, T defaultValue) {
Object value = data.attribute.get(attr);
if (value == ObjectUtils.NULL || value == null)
Object value = data.attribute.get(DisplayAttribute.SMALL);
if (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 (value instanceof Integer) {
if (defaultValue instanceof Double)
return (T) Double.valueOf((int) value);
if (defaultValue instanceof Float)
return (T) Float.valueOf((int) 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;
@@ -304,12 +317,12 @@ public class ArmorStandDisplayItem implements DisplayItem {
break;
}
asloc.setYaw(asloc.getYaw() + getAttribute(DisplayAttribute.OFFSET_YAW, 0f));
asloc.setPitch(asloc.getYaw() + getAttribute(DisplayAttribute.OFFSET_PITCH, 0f));
asloc.setYaw(asloc.getYaw() + getAttribute(DisplayAttribute.OFFSET_YAW, 0));
asloc.setPitch(asloc.getYaw() + getAttribute(DisplayAttribute.OFFSET_PITCH, 0));
asloc.add(
getAttribute(DisplayAttribute.OFFSET_X, 0d),
getAttribute(DisplayAttribute.OFFSET_Y, 0d),
getAttribute(DisplayAttribute.OFFSET_Z, 0d));
getAttribute(DisplayAttribute.OFFSET_X, 0),
getAttribute(DisplayAttribute.OFFSET_Y, 0),
getAttribute(DisplayAttribute.OFFSET_Z, 0));
return asloc;
}
@@ -324,34 +337,34 @@ public class ArmorStandDisplayItem implements DisplayItem {
private void setPoseForArmorStand(ArmorStand armorStand) {
armorStand.setBodyPose(new EulerAngle(
getAttribute(DisplayAttribute.POSE_BODY_X, 0d),
getAttribute(DisplayAttribute.POSE_BODY_Y, 0d),
getAttribute(DisplayAttribute.POSE_BODY_Z, 0d)));
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, 0d),
getAttribute(DisplayAttribute.POSE_HEAD_Y, 0d),
getAttribute(DisplayAttribute.POSE_HEAD_Z, 0d)));
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, 0d),
getAttribute(DisplayAttribute.POSE_ARM_RIGHT_Y, 0d),
getAttribute(DisplayAttribute.POSE_ARM_RIGHT_Z, 0d)));
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, 0d),
getAttribute(DisplayAttribute.POSE_ARM_LEFT_Y, 0d),
getAttribute(DisplayAttribute.POSE_ARM_LEFT_Z, 0d)));
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, 0d),
getAttribute(DisplayAttribute.POSE_LEG_RIGHT_Y, 0d),
getAttribute(DisplayAttribute.POSE_LEG_RIGHT_Z, 0d)));
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, 0d),
getAttribute(DisplayAttribute.POSE_LEG_LEFT_Y, 0d),
getAttribute(DisplayAttribute.POSE_LEG_LEFT_Z, 0d)));
getAttribute(DisplayAttribute.POSE_LEG_LEFT_X, 0),
getAttribute(DisplayAttribute.POSE_LEG_LEFT_Y, 0),
getAttribute(DisplayAttribute.POSE_LEG_LEFT_Z, 0)));
}
@Override
@@ -109,8 +109,7 @@ public class ContainerShop implements Shop {
this.unlimited = unlimited;
if (plugin.isDisplay()) {
DisplayData data = DisplayItem.getNowUsing(this.item);
switch (data.type) {
switch (DisplayItem.getNowUsing(this.item).type) {
case UNKNOWN:
Util.debugLog(
"Failed to create a ContainerShop displayItem, the type is unknown, fallback to RealDisplayItem");
@@ -120,7 +119,7 @@ public class ContainerShop implements Shop {
this.displayItem = new RealDisplayItem(this);
break;
case ARMORSTAND:
this.displayItem = new ArmorStandDisplayItem(this, data);
this.displayItem = new ArmorStandDisplayItem(this);
break;
default:
Util.debugLog(
@@ -27,6 +27,5 @@ import lombok.AllArgsConstructor;
public class DisplayData {
public final DisplayType type;
public final Map<DisplayAttribute, Object> attribute = Maps.newEnumMap(DisplayAttribute.class);
@Deprecated public final boolean needVaildate; // Bad design
public final boolean fixer;
public final boolean needVaildate;
}
@@ -233,9 +233,6 @@ 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");
@@ -243,26 +240,21 @@ public interface DisplayItem {
if (conf != null) {
DisplayData dataArmourStand = matchData(conf, "armor-stand", item, true);
if (dataArmourStand != null && !dataArmourStand.needVaildate)
return dataArmourStand.fixer ?
(def.type == dataArmourStand.type ?
dataArmourStand : def) : dataArmourStand;
return dataArmourStand;
DisplayData dataDroppedItem = matchData(conf, "dropped-item", item, false);
if (dataDroppedItem != null)
return dataDroppedItem.fixer ?
(def.type == dataDroppedItem.type ?
dataDroppedItem : def) : dataDroppedItem;
return dataDroppedItem;
else if (dataArmourStand != null)
return dataArmourStand.fixer ?
(def.type == dataArmourStand.type ?
dataArmourStand : def) : dataArmourStand;
return dataArmourStand;
}
}
return def;
return new DisplayData(
DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type")), false);
} catch (Throwable e) {
e.printStackTrace();
return new DisplayData(DisplayType.REALITEM, false, false);
return new DisplayData(DisplayType.REALITEM, false);
}
}
@@ -275,14 +267,11 @@ 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) {
@@ -294,59 +283,18 @@ 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
temp = attrMap.get("type");
Object type = temp == null ? "TAG:ANY" : temp;
Object temp = attrMap.get("type");
Util.debugLog("Type: " + temp);
Object type = temp == null ? Material.AIR : temp;
boolean needVaildate = false;
if (!type.equals("TAG:ANY")) {
if (type != Material.AIR) {
if (type instanceof Collection) {
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) {
if (!Collection.class.cast(type).contains(item.getType().name())) {
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;
}
@@ -356,16 +304,10 @@ public interface DisplayItem {
}
// Custom Model Data matcher
temp = attrMap.get("strict");
boolean strict = temp == null ? false : (boolean) temp;
temp = attrMap.get("model-data");
if (temp != null) {
if (item.hasItemMeta() && item.getItemMeta().hasCustomModelData()) {
if ((int) temp != item.getItemMeta().getCustomModelData()) {
continue;
}
} else {
Util.debugLog("Type: " + temp);
if (temp != null && item.hasItemMeta() && item.getItemMeta().hasCustomModelData()) {
if ((int) temp != item.getItemMeta().getCustomModelData()) {
continue;
}
} else {
@@ -373,12 +315,17 @@ 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(lore);
Collection<?> specificLore = Collection.class.cast(type);
if (strict) {
if (!specificLore.equals(item.getLore())) {
continue;
@@ -418,22 +365,23 @@ public interface DisplayItem {
}
DisplayData data = new DisplayData(
armorStand ? DisplayType.ARMORSTAND : DisplayType.REALITEM, needVaildate, (boolean) fixer);
armorStand ? DisplayType.ARMORSTAND : DisplayType.REALITEM, needVaildate);
if (armorStand) {
Map<?, ?> attributes = Map.class.cast(attrMap.get("attribute"));
temp = attrMap.get("attribute");
Util.debugLog("Type: " + temp);
if (attributes instanceof Map) {
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 = Map.class.cast(attributes).get(rootKey);
temp = attrMap.get(rootKey);
data.attribute.put(attr,
temp == null ? ObjectUtils.NULL : temp);
} else {
// Nested Map
if ((temp = Map.class.cast(attributes).get(rootKey)) instanceof Map) {
if ((temp = attrMap.get(rootKey)) instanceof Map) {
String subKey = attrKeys[1].toLowerCase(Locale.ROOT);
Object value = Map.class.cast(temp).get(subKey);
@@ -445,15 +393,11 @@ public interface DisplayItem {
}
}
if (needVaildate)
vaildateData = data;
else
return data;
return data;
}
}
}
return vaildateData;
return null;
}
/**