add getItemProperty
This commit is contained in:
parent
1e95177a3c
commit
7605841694
4 changed files with 26 additions and 0 deletions
|
@ -43,6 +43,14 @@ public interface PropertyHolder {
|
|||
*/
|
||||
void setItemProperty(EntityProperty<?> key, ItemStack value);
|
||||
|
||||
/**
|
||||
* Weird fix which is sadly required in order to not decrease performance
|
||||
* when using item properties, read https://github.com/Pyrbu/ZNPCsPlus/pull/129#issuecomment-1948777764
|
||||
*
|
||||
* @param key Unique key representing a property
|
||||
*/
|
||||
ItemStack getItemProperty(EntityProperty<?> key);
|
||||
|
||||
/**
|
||||
* Method used to get a set of all of the property keys that this holder has a value for
|
||||
*
|
||||
|
|
|
@ -107,6 +107,11 @@ public class PacketEntity implements PropertyHolder {
|
|||
properties.setItemProperty(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemProperty(EntityProperty<?> key) {
|
||||
return properties.getItemProperty(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<EntityProperty<?>> getAppliedProperties() {
|
||||
return properties.getAppliedProperties();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package lol.pyr.znpcsplus.hologram;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
|
||||
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
|
||||
import lol.pyr.znpcsplus.api.entity.EntityProperty;
|
||||
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
|
||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||
|
@ -76,6 +77,12 @@ public class HologramLine<M> implements PropertyHolder {
|
|||
throw new UnsupportedOperationException("Can't set properties on a hologram line");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ItemStack getItemProperty(EntityProperty<?> key) {
|
||||
return SpigotConversionUtil.toBukkitItemStack(((EntityProperty<com.github.retrooper.packetevents.protocol.item.ItemStack>) key).getDefaultValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<EntityProperty<?>> getAppliedProperties() {
|
||||
return properties;
|
||||
|
|
|
@ -164,6 +164,12 @@ public class NpcImpl extends Viewable implements Npc {
|
|||
setProperty((EntityPropertyImpl<com.github.retrooper.packetevents.protocol.item.ItemStack>) key, SpigotConversionUtil.fromBukkitItemStack(value));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ItemStack getItemProperty(EntityProperty<?> key) {
|
||||
return SpigotConversionUtil.toBukkitItemStack(getProperty((EntityProperty<com.github.retrooper.packetevents.protocol.item.ItemStack>) key));
|
||||
}
|
||||
|
||||
public <T> void setProperty(EntityPropertyImpl<T> key, T value) {
|
||||
if (key == null) return;
|
||||
if (value == null || value.equals(key.getDefaultValue())) propertyMap.remove(key);
|
||||
|
|
Loading…
Reference in a new issue