Skip to content

Commit

Permalink
修复无法正确处理MOD药水
Browse files Browse the repository at this point in the history
  • Loading branch information
Luohuayu committed Aug 10, 2019
1 parent a1adbd7 commit 2339ba2
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
private List<PotionEffect> customEffects;
private Color color;

private String rawType = null; // CatServer

CraftMetaPotion(CraftMetaItem meta) {
super(meta);
if (!(meta instanceof CraftMetaPotion)) {
Expand All @@ -57,6 +59,8 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
super(tag);
if (tag.hasKey(DEFAULT_POTION.NBT)) {
type = CraftPotionUtil.toBukkit(tag.getString(DEFAULT_POTION.NBT));
if (type.getType() == PotionType.UNCRAFTABLE)
rawType = tag.getString(DEFAULT_POTION.NBT);
}
if (tag.hasKey(POTION_COLOR.NBT)) {
color = Color.fromRGB(tag.getInteger(POTION_COLOR.NBT));
Expand Down Expand Up @@ -85,6 +89,8 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
CraftMetaPotion(Map<String, Object> map) {
super(map);
type = CraftPotionUtil.toBukkit(SerializableMeta.getString(map, DEFAULT_POTION.BUKKIT, true));
if (type.getType() == PotionType.UNCRAFTABLE)
rawType = SerializableMeta.getString(map, DEFAULT_POTION.BUKKIT + "-raw", true);

Color color = SerializableMeta.getObject(Color.class, map, POTION_COLOR.BUKKIT, true);
if (color != null) {
Expand All @@ -108,7 +114,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
void applyToItem(NBTTagCompound tag) {
super.applyToItem(tag);

tag.setString(DEFAULT_POTION.NBT, CraftPotionUtil.fromBukkit(type));
tag.setString(DEFAULT_POTION.NBT, type.getType() == PotionType.UNCRAFTABLE && rawType != null ? rawType : CraftPotionUtil.fromBukkit(type)); // CatServer

if (hasColor()) {
tag.setInteger(POTION_COLOR.NBT, color.asRGB());
Expand Down Expand Up @@ -136,7 +142,7 @@ boolean isEmpty() {
}

boolean isPotionEmpty() {
return (type.getType() == PotionType.UNCRAFTABLE) && !(hasCustomEffects() || hasColor());
return (type.getType() == PotionType.UNCRAFTABLE) && !(hasCustomEffects() || hasColor()) && rawType == null;
}

@Override
Expand Down Expand Up @@ -288,6 +294,8 @@ int applyHash() {
int hash = original = super.applyHash();
if (type.getType() != PotionType.UNCRAFTABLE) {
hash = 73 * hash + type.hashCode();
} else if (rawType != null) {
hash = 73 * hash + rawType.hashCode();
}
if (hasColor()) {
hash = 73 * hash + color.hashCode();
Expand Down Expand Up @@ -323,6 +331,8 @@ Builder<String, Object> serialize(Builder<String, Object> builder) {
super.serialize(builder);
if (type.getType() != PotionType.UNCRAFTABLE) {
builder.put(DEFAULT_POTION.BUKKIT, CraftPotionUtil.fromBukkit(type));
} else if (rawType != null) {
builder.put(DEFAULT_POTION.BUKKIT + "-raw", rawType);
}

if (hasColor()) {
Expand Down

0 comments on commit 2339ba2

Please sign in to comment.