geforkt von Mirrors/Paper
SPIGOT-2782: Custom Colors for Potions
Dieser Commit ist enthalten in:
Ursprung
d8c6364c4c
Commit
4f63973ebb
@ -12,7 +12,6 @@ import org.bukkit.configuration.serialization.DelegateDeserialization;
|
|||||||
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
|
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
|
||||||
import org.bukkit.inventory.meta.MapMeta;
|
import org.bukkit.inventory.meta.MapMeta;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
@DelegateDeserialization(SerializableMeta.class)
|
@DelegateDeserialization(SerializableMeta.class)
|
||||||
@ -140,8 +139,6 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLocationName(String name) {
|
public void setLocationName(String name) {
|
||||||
Preconditions.checkArgument(name != null, "name");
|
|
||||||
|
|
||||||
this.locName = name;
|
this.locName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,8 +154,6 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setColor(Color color) {
|
public void setColor(Color color) {
|
||||||
Preconditions.checkArgument(color != null, "color");
|
|
||||||
|
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,11 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.minecraft.server.NBTTagCompound;
|
import net.minecraft.server.NBTTagCompound;
|
||||||
|
import net.minecraft.server.NBTTagInt;
|
||||||
import net.minecraft.server.NBTTagList;
|
import net.minecraft.server.NBTTagList;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.Color;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
@ -29,6 +31,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
|||||||
static final ItemMetaKey DURATION = new ItemMetaKey("Duration", "duration");
|
static final ItemMetaKey DURATION = new ItemMetaKey("Duration", "duration");
|
||||||
static final ItemMetaKey SHOW_PARTICLES = new ItemMetaKey("ShowParticles", "has-particles");
|
static final ItemMetaKey SHOW_PARTICLES = new ItemMetaKey("ShowParticles", "has-particles");
|
||||||
static final ItemMetaKey POTION_EFFECTS = new ItemMetaKey("CustomPotionEffects", "custom-effects");
|
static final ItemMetaKey POTION_EFFECTS = new ItemMetaKey("CustomPotionEffects", "custom-effects");
|
||||||
|
static final ItemMetaKey POTION_COLOR = new ItemMetaKey("CustomPotionColor", "custom-color");
|
||||||
static final ItemMetaKey ID = new ItemMetaKey("Id", "potion-id");
|
static final ItemMetaKey ID = new ItemMetaKey("Id", "potion-id");
|
||||||
static final ItemMetaKey DEFAULT_POTION = new ItemMetaKey("Potion", "potion-type");
|
static final ItemMetaKey DEFAULT_POTION = new ItemMetaKey("Potion", "potion-type");
|
||||||
|
|
||||||
@ -36,6 +39,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
|||||||
// is treated as the empty form of the meta because it represents an empty potion with no effect
|
// is treated as the empty form of the meta because it represents an empty potion with no effect
|
||||||
private PotionData type = new PotionData(PotionType.UNCRAFTABLE, false, false);
|
private PotionData type = new PotionData(PotionType.UNCRAFTABLE, false, false);
|
||||||
private List<PotionEffect> customEffects;
|
private List<PotionEffect> customEffects;
|
||||||
|
private Color color;
|
||||||
|
|
||||||
CraftMetaPotion(CraftMetaItem meta) {
|
CraftMetaPotion(CraftMetaItem meta) {
|
||||||
super(meta);
|
super(meta);
|
||||||
@ -44,6 +48,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
|||||||
}
|
}
|
||||||
CraftMetaPotion potionMeta = (CraftMetaPotion) meta;
|
CraftMetaPotion potionMeta = (CraftMetaPotion) meta;
|
||||||
this.type = potionMeta.type;
|
this.type = potionMeta.type;
|
||||||
|
this.color = potionMeta.color;
|
||||||
if (potionMeta.hasCustomEffects()) {
|
if (potionMeta.hasCustomEffects()) {
|
||||||
this.customEffects = new ArrayList<PotionEffect>(potionMeta.customEffects);
|
this.customEffects = new ArrayList<PotionEffect>(potionMeta.customEffects);
|
||||||
}
|
}
|
||||||
@ -54,6 +59,9 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
|||||||
if (tag.hasKey(DEFAULT_POTION.NBT)) {
|
if (tag.hasKey(DEFAULT_POTION.NBT)) {
|
||||||
type = CraftPotionUtil.toBukkit(tag.getString(DEFAULT_POTION.NBT));
|
type = CraftPotionUtil.toBukkit(tag.getString(DEFAULT_POTION.NBT));
|
||||||
}
|
}
|
||||||
|
if (tag.hasKey(POTION_COLOR.NBT)) {
|
||||||
|
color = Color.fromRGB(tag.getInt(POTION_COLOR.NBT));
|
||||||
|
}
|
||||||
if (tag.hasKey(POTION_EFFECTS.NBT)) {
|
if (tag.hasKey(POTION_EFFECTS.NBT)) {
|
||||||
NBTTagList list = tag.getList(POTION_EFFECTS.NBT, 10);
|
NBTTagList list = tag.getList(POTION_EFFECTS.NBT, 10);
|
||||||
int length = list.size();
|
int length = list.size();
|
||||||
@ -75,6 +83,11 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
|||||||
super(map);
|
super(map);
|
||||||
type = CraftPotionUtil.toBukkit(SerializableMeta.getString(map, DEFAULT_POTION.BUKKIT, true));
|
type = CraftPotionUtil.toBukkit(SerializableMeta.getString(map, DEFAULT_POTION.BUKKIT, true));
|
||||||
|
|
||||||
|
Color color = SerializableMeta.getObject(Color.class, map, POTION_COLOR.BUKKIT, true);
|
||||||
|
if (color != null) {
|
||||||
|
setColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
Iterable<?> rawEffectList = SerializableMeta.getObject(Iterable.class, map, POTION_EFFECTS.BUKKIT, true);
|
Iterable<?> rawEffectList = SerializableMeta.getObject(Iterable.class, map, POTION_EFFECTS.BUKKIT, true);
|
||||||
if (rawEffectList == null) {
|
if (rawEffectList == null) {
|
||||||
return;
|
return;
|
||||||
@ -91,7 +104,13 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
|||||||
@Override
|
@Override
|
||||||
void applyToItem(NBTTagCompound tag) {
|
void applyToItem(NBTTagCompound tag) {
|
||||||
super.applyToItem(tag);
|
super.applyToItem(tag);
|
||||||
|
|
||||||
tag.setString(DEFAULT_POTION.NBT, CraftPotionUtil.fromBukkit(type));
|
tag.setString(DEFAULT_POTION.NBT, CraftPotionUtil.fromBukkit(type));
|
||||||
|
|
||||||
|
if (hasColor()) {
|
||||||
|
tag.setInt(POTION_COLOR.NBT, color.asRGB());
|
||||||
|
}
|
||||||
|
|
||||||
if (customEffects != null) {
|
if (customEffects != null) {
|
||||||
NBTTagList effectList = new NBTTagList();
|
NBTTagList effectList = new NBTTagList();
|
||||||
tag.set(POTION_EFFECTS.NBT, effectList);
|
tag.set(POTION_EFFECTS.NBT, effectList);
|
||||||
@ -114,7 +133,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean isPotionEmpty() {
|
boolean isPotionEmpty() {
|
||||||
return (type.getType() == PotionType.UNCRAFTABLE) && !(hasCustomEffects());
|
return (type.getType() == PotionType.UNCRAFTABLE) && !(hasCustomEffects() || hasColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -245,12 +264,30 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasColor() {
|
||||||
|
return color != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Color getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setColor(Color color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int applyHash() {
|
int applyHash() {
|
||||||
final int original;
|
final int original;
|
||||||
int hash = original = super.applyHash();
|
int hash = original = super.applyHash();
|
||||||
if (type.getType() != PotionType.UNCRAFTABLE) {
|
if (type.getType() != PotionType.UNCRAFTABLE) {
|
||||||
hash = 73 * hash + type.hashCode();
|
hash = 73 * hash + type.hashCode();
|
||||||
|
}
|
||||||
|
if (hasColor()) {
|
||||||
|
hash = 73 * hash + color.hashCode();
|
||||||
}
|
}
|
||||||
if (hasCustomEffects()) {
|
if (hasCustomEffects()) {
|
||||||
hash = 73 * hash + customEffects.hashCode();
|
hash = 73 * hash + customEffects.hashCode();
|
||||||
@ -266,7 +303,9 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
|||||||
if (meta instanceof CraftMetaPotion) {
|
if (meta instanceof CraftMetaPotion) {
|
||||||
CraftMetaPotion that = (CraftMetaPotion) meta;
|
CraftMetaPotion that = (CraftMetaPotion) meta;
|
||||||
|
|
||||||
return type.equals(that.type) && (this.hasCustomEffects() ? that.hasCustomEffects() && this.customEffects.equals(that.customEffects) : !that.hasCustomEffects());
|
return type.equals(that.type)
|
||||||
|
&& (this.hasCustomEffects() ? that.hasCustomEffects() && this.customEffects.equals(that.customEffects) : !that.hasCustomEffects())
|
||||||
|
&& (this.hasColor() ? that.hasColor() && this.color.equals(that.color) : !that.hasColor());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -283,6 +322,10 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
|||||||
builder.put(DEFAULT_POTION.BUKKIT, CraftPotionUtil.fromBukkit(type));
|
builder.put(DEFAULT_POTION.BUKKIT, CraftPotionUtil.fromBukkit(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasColor()) {
|
||||||
|
builder.put(POTION_COLOR.BUKKIT, getColor());
|
||||||
|
}
|
||||||
|
|
||||||
if (hasCustomEffects()) {
|
if (hasCustomEffects()) {
|
||||||
builder.put(POTION_EFFECTS.BUKKIT, ImmutableList.copyOf(this.customEffects));
|
builder.put(POTION_EFFECTS.BUKKIT, ImmutableList.copyOf(this.customEffects));
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren