From f3b202edb3a9bfa779cdfa3f294a3ef13aa61648 Mon Sep 17 00:00:00 2001 From: Ste3et_C0st Date: Sun, 14 Jan 2024 21:38:14 +0100 Subject: [PATCH] update upstream --- .../ModelLoader/ModelHandler.java | 16 +++--- .../FurnitureLib/NBT/NBTTagCompound.java | 2 +- .../FurnitureLib/Utilitis/BoundingBox.java | 38 ++++++++++++++ .../FurnitureLib/Utilitis/EntitySize.java | 51 +++++++++++++++---- .../exception/WrongVersionException.java | 10 ---- .../FurnitureLib/main/Furniture.java | 29 ++++++++--- .../FurnitureLib/main/FurnitureHelper.java | 6 +++ .../FurnitureLib/main/ObjectID.java | 1 - .../main/entity/SizeableEntity.java | 11 ++++ .../FurnitureLib/main/entity/fArmorStand.java | 9 +++- .../main/entity/fBlock_display.java | 1 - .../FurnitureLib/main/entity/fDisplay.java | 44 ++++++++-------- .../FurnitureLib/main/entity/fEntity.java | 31 +++++------ .../FurnitureLib/main/entity/fSize.java | 4 +- .../main/entity/fText_display.java | 24 +++------ 15 files changed, 183 insertions(+), 94 deletions(-) delete mode 100644 FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/Utilitis/exception/WrongVersionException.java create mode 100644 FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/SizeableEntity.java diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/ModelLoader/ModelHandler.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/ModelLoader/ModelHandler.java index 12a4f196..955b8e66 100644 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/ModelLoader/ModelHandler.java +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/ModelLoader/ModelHandler.java @@ -94,13 +94,15 @@ public HashSet getEntityMap(Location startLocation, BlockFace direction locationList.add(entity); String customName = entity.getCustomName(); - if (customName.equalsIgnoreCase("#ITEM#") - || customName.equalsIgnoreCase("#BLOCK#") - || customName.equalsIgnoreCase("#SITZ#") - || customName.startsWith("#Light") - || customName.startsWith("/") - || customName.toUpperCase().startsWith("#DYE_")) { - entity.setNameVisibility(false); + if(entity.hasCustomName()) { + if (customName.equalsIgnoreCase("#ITEM#") + || customName.equalsIgnoreCase("#BLOCK#") + || customName.equalsIgnoreCase("#SITZ#") + || customName.startsWith("#Light") + || customName.startsWith("/") + || customName.toUpperCase().startsWith("#DYE_")) { + entity.setNameVisibility(false); + } } }); FurnitureLib.debug("FurnitureLib {ModelHandler} -> Calculate Entities Finish"); diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/NBT/NBTTagCompound.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/NBT/NBTTagCompound.java index f6f56c83..6ad62c46 100644 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/NBT/NBTTagCompound.java +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/NBT/NBTTagCompound.java @@ -233,7 +233,7 @@ public String getString(String key, String defaultValue) { return defaultValue; } - return str.replaceAll("\"", ""); + return str != null ? str.replaceAll("\"", "") : str; } @Override diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/Utilitis/BoundingBox.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/Utilitis/BoundingBox.java index 58a7edba..aacffcd1 100644 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/Utilitis/BoundingBox.java +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/Utilitis/BoundingBox.java @@ -2,20 +2,27 @@ import org.apache.commons.lang.Validate; import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.Particle.DustOptions; import org.bukkit.block.Block; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.SerializableAs; import org.bukkit.inventory.ItemStack; import org.bukkit.util.EulerAngle; import org.bukkit.util.NumberConversions; +import org.bukkit.util.RayTraceResult; import org.bukkit.util.Vector; import de.Ste3et_C0st.FurnitureLib.main.Type.BodyPart; import de.Ste3et_C0st.FurnitureLib.main.entity.fArmorStand; import de.Ste3et_C0st.FurnitureLib.main.entity.fInventory.EquipmentSlot; +import java.awt.Color; +import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Objects; @@ -602,4 +609,35 @@ public Map serialize() { result.put("maxZ", this.maxZ); return result; } + + public void debugParticle(World world) { + final Location startLocation = new Vector(this.minX, this.minY, this.minZ).toLocation(world); + final Location endLocation = new Vector(this.maxX, this.maxY, this.maxZ).toLocation(world); + + final List locationList = showCuboid(startLocation, endLocation, .25); + final Color color = Color.magenta; + final DustOptions option = new DustOptions(org.bukkit.Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue()), 1f); + + locationList.stream().forEach(loc -> { + world.spawnParticle(Particle.REDSTONE, loc.toLocation(world), 1, option); + }); + } + + private List showCuboid(Location aLoc, Location bLoc, double step) { + List result = new ArrayList(); + double[] xArr = {Math.min(aLoc.getX(), bLoc.getX()), Math.max(aLoc.getX(), bLoc.getX())}; + double[] yArr = {Math.min(aLoc.getY(), bLoc.getY()), Math.max(aLoc.getY(), bLoc.getY())}; + double[] zArr = {Math.min(aLoc.getZ(), bLoc.getZ()), Math.max(aLoc.getZ(), bLoc.getZ())}; + + for (double x = xArr[0]; x < xArr[1]; x += step) for (double y : yArr) for (double z : zArr) { + result.add(new Vector(x, y, z)); + } + for (double y = yArr[0]; y < yArr[1]; y += step) for (double x : xArr) for (double z : zArr) { + result.add(new Vector(x, y, z)); + } + for (double z = zArr[0]; z < zArr[1]; z += step) for (double y : yArr) for (double x : xArr) { + result.add(new Vector(x, y, z)); + } + return result; + } } diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/Utilitis/EntitySize.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/Utilitis/EntitySize.java index 0ebf6455..26893f77 100644 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/Utilitis/EntitySize.java +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/Utilitis/EntitySize.java @@ -3,21 +3,34 @@ import org.bukkit.util.Vector; import org.joml.Vector3f; +import de.Ste3et_C0st.FurnitureLib.main.entity.fBlock_display; +import de.Ste3et_C0st.FurnitureLib.main.entity.fDisplay; +import de.Ste3et_C0st.FurnitureLib.main.entity.fEntity; + public class EntitySize { - private final double x, y, z; - - + private double x, y, z; + public EntitySize(double width, double height) { - this.x = width; - this.z = width; - this.y = height; + this(width, height, width); + } + + public EntitySize(double x, double y, double z) { + this.x = x; + this.z = y; + this.y = z; } public EntitySize(Vector3f vector3f) { - this.x = vector3f.x; - this.y = vector3f.y; - this.z = vector3f.z; + this(vector3f.x, vector3f.y, vector3f.z); + } + + public static EntitySize of(double x, double y, double z) { + return new EntitySize(x, y, z); + } + + public static EntitySize of(Vector3f vector3f) { + return new EntitySize(vector3f.x, vector3f.y, vector3f.z); } public double getWidth() { @@ -48,7 +61,25 @@ public Vector toVector() { return new Vector((float) this.x,(float) this.y,(float) this.z); } - public BoundingBox getBoundingBox(Vector vector) { + public BoundingBox getBoundingBox(Vector vector) { return BoundingBox.of(vector, toVector()); } + + public BoundingBox toBoundingBox(fEntity entity) { + return BoundingBox.of(entity.getLocation(), x, y, z); + } + + public void write(Vector3f scale) { + this.write(scale.x, scale.y, scale.z); + } + + public void write(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + public String toString() { + return "EntitySize {" + this.x +", " + this.y +", " + this.z +"}"; + } } diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/Utilitis/exception/WrongVersionException.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/Utilitis/exception/WrongVersionException.java deleted file mode 100644 index 3df69ce4..00000000 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/Utilitis/exception/WrongVersionException.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.Ste3et_C0st.FurnitureLib.Utilitis.exception; - -public class WrongVersionException extends Exception { - - //this exception is called if you use an unsupported version - public WrongVersionException(String errorMessage) { - super(errorMessage); - } - -} \ No newline at end of file diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/Furniture.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/Furniture.java index 03fd879f..0df9d962 100644 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/Furniture.java +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/Furniture.java @@ -4,9 +4,14 @@ import de.Ste3et_C0st.FurnitureLib.Crafting.Project; import de.Ste3et_C0st.FurnitureLib.SchematicLoader.functions.functionManager; import de.Ste3et_C0st.FurnitureLib.SchematicLoader.functions.projectFunction; +import de.Ste3et_C0st.FurnitureLib.main.entity.SizeableEntity; import de.Ste3et_C0st.FurnitureLib.main.entity.fArmorStand; +import de.Ste3et_C0st.FurnitureLib.main.entity.fBlock_display; import de.Ste3et_C0st.FurnitureLib.main.entity.fContainerEntity; +import de.Ste3et_C0st.FurnitureLib.main.entity.fDisplay; import de.Ste3et_C0st.FurnitureLib.main.entity.fEntity; +import de.Ste3et_C0st.FurnitureLib.main.entity.fItem_display; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -88,9 +93,14 @@ public boolean runFunction(Player p) { } public boolean runOldFunctions(Player p) { +// getObjID().getPacketList().stream().filter(fBlock_display.class::isInstance).map(fBlock_display.class::cast).forEach(entry -> { +// entry.getBoundingBox().debugParticle(getWorld()); +// }); + ItemStack stack = p.getInventory().getItemInMainHand(); if (stack != null) { Material m = stack.getType(); + if (m.equals(Material.AIR) || !m.isBlock()) { for (fEntity stand : getfAsList()) { if (stand.getName().startsWith("#ITEM")) { @@ -102,17 +112,22 @@ public boolean runOldFunctions(Player p) { is.setAmount(1); getWorld().dropItem(getLocation(), is); } - if (p.getInventory().getItemInMainHand() != null) { - ItemStack is = p.getInventory().getItemInMainHand().clone(); - if (is.getAmount() <= 0) { - is.setAmount(0); - } else { - is.setAmount(1); - } + if (Objects.nonNull(stack)) { + ItemStack is = stack.clone(); + is.setAmount(1); container.setItemInMainHand(is); stand.update(); consumeItem(p); } + }else if(stand instanceof fItem_display) { + fItem_display item_display = fItem_display.class.cast(stand); + if (Objects.nonNull(stack)) { + ItemStack is = stack.clone(); + is.setAmount(1); + item_display.setItemStack(is); + stand.update(); + consumeItem(p); + } } return true; } diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/FurnitureHelper.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/FurnitureHelper.java index a9a91d2f..ce0d9b98 100644 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/FurnitureHelper.java +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/FurnitureHelper.java @@ -9,6 +9,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.BlockFace; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; @@ -40,7 +41,12 @@ public FurnitureHelper(ObjectID id) { this.plugin = id.getProjectOBJ().getPlugin(); this.obj = id; } + + public fEntity spawnEntity(Location location, EntityType type) { + return getManager().spawnEntity(type, location, obj); + } + @Deprecated public fArmorStand spawnArmorStand(Location loc) { return getManager().createArmorStand(getObjID(), loc); } diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/ObjectID.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/ObjectID.java index ca5db27b..98d621d0 100644 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/ObjectID.java +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/ObjectID.java @@ -421,5 +421,4 @@ public void setFunctionObject(Object obj) { this.functionObject = Furniture.class.cast(obj); } } - } diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/SizeableEntity.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/SizeableEntity.java new file mode 100644 index 00000000..8f530d5a --- /dev/null +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/SizeableEntity.java @@ -0,0 +1,11 @@ +package de.Ste3et_C0st.FurnitureLib.main.entity; + +import de.Ste3et_C0st.FurnitureLib.Utilitis.BoundingBox; +import de.Ste3et_C0st.FurnitureLib.Utilitis.EntitySize; + +public interface SizeableEntity { + + public BoundingBox getBoundingBox(); + public EntitySize getEntitySize(); + +} diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fArmorStand.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fArmorStand.java index d37f0a02..a5d512d5 100644 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fArmorStand.java +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fArmorStand.java @@ -6,6 +6,7 @@ import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagCompound; import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagList; +import de.Ste3et_C0st.FurnitureLib.Utilitis.BoundingBox; import de.Ste3et_C0st.FurnitureLib.Utilitis.DefaultKey; import de.Ste3et_C0st.FurnitureLib.Utilitis.EntitySize; import de.Ste3et_C0st.FurnitureLib.Utilitis.Relative; @@ -23,7 +24,7 @@ import java.util.HashMap; import java.util.Objects; -public class fArmorStand extends fContainerEntity{ +public class fArmorStand extends fContainerEntity implements SizeableEntity{ public static EntityType type = EntityType.ARMOR_STAND; private int armorstandID; @@ -278,5 +279,9 @@ protected Material getDestroyMaterial() { } return Material.AIR; } - + + @Override + public BoundingBox getBoundingBox() { + return this.entitySize.getOrDefault().toBoundingBox(this); + } } diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fBlock_display.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fBlock_display.java index 30730175..74dfc368 100644 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fBlock_display.java +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fBlock_display.java @@ -15,7 +15,6 @@ import de.Ste3et_C0st.FurnitureLib.NBT.CraftBlockData; import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagCompound; import de.Ste3et_C0st.FurnitureLib.Utilitis.DefaultKey; -import de.Ste3et_C0st.FurnitureLib.Utilitis.EntitySize; import de.Ste3et_C0st.FurnitureLib.main.ObjectID; public class fBlock_display extends fDisplay{ diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fDisplay.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fDisplay.java index 4161128a..82709b77 100644 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fDisplay.java +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fDisplay.java @@ -20,12 +20,13 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagCompound; +import de.Ste3et_C0st.FurnitureLib.Utilitis.BoundingBox; import de.Ste3et_C0st.FurnitureLib.Utilitis.DefaultKey; import de.Ste3et_C0st.FurnitureLib.main.FurnitureLib; import de.Ste3et_C0st.FurnitureLib.main.ObjectID; import de.Ste3et_C0st.FurnitureLib.main.Type.ProtocolFieldsDisplay; -public abstract class fDisplay extends fSize{ +public abstract class fDisplay extends fSize implements SizeableEntity{ private DefaultKey translation = new DefaultKey(new Vector3f()), scale = new DefaultKey(new Vector3f()); private DefaultKey leftRotation = new DefaultKey(new Quaternionf()), rightRotation = new DefaultKey(new Quaternionf()); @@ -201,6 +202,8 @@ public fDisplay setInterpolationDuration(int var0) { private void writeTransformation() { final Transformation transformation = getTransformation(); + + this.entitySize.getOrDefault().write(transformation.getScale()); getWatcher().setObject(new WrappedDataWatcherObject(displayField.getVersionIndex() + 10, Registry.get(Vector3f.class)), transformation.getTranslation()); getWatcher().setObject(new WrappedDataWatcherObject(displayField.getVersionIndex() + 11, Registry.get(Vector3f.class)), transformation.getScale()); getWatcher().setObject(new WrappedDataWatcherObject(displayField.getVersionIndex() + 12, Registry.get(Quaternionf.class)), transformation.getLeftRotation()); @@ -265,29 +268,22 @@ protected void writeDisplaySaveData() { NBTTagCompound transformation = new NBTTagCompound(); - if(this.translation.isDefault() == false) { - final NBTTagCompound translation = new NBTTagCompound(); - final Vector3f vector = this.translation.getOrDefault(); - translation.setFloat("x", vector.x); - translation.setFloat("y", vector.y); - translation.setFloat("z", vector.z); - transformation.set("translation", translation); - } - - if(this.scale.isDefault() == false) { - final NBTTagCompound scale = new NBTTagCompound(); - final Vector3f vector = this.scale.getOrDefault(); - scale.setFloat("x", vector.x); - scale.setFloat("y", vector.y); - scale.setFloat("z", vector.z); - transformation.set("scale", scale); - } + if(this.translation.isDefault() == false) this.writeVector(this.translation.getOrDefault(), transformation, "translation"); + if(this.scale.isDefault() == false) this.writeVector(this.scale.getOrDefault(), transformation, "scale"); - this.writeRotation(getLeftRotationObj(), transformation, "left_Rotation"); - this.writeRotation(getRightRotationObj(), transformation, "right_Rotation"); + if(this.leftRotation.isDefault() == false) this.writeRotation(getLeftRotationObj(), transformation, "left_Rotation"); + if(this.rightRotation.isDefault() == false) this.writeRotation(getRightRotationObj(), transformation, "right_Rotation"); - if(!transformation.isEmpty()) set("transformation", transformation); + if(transformation.isEmpty() == false) set("transformation", transformation); } + + private void writeVector(final Vector3f vector, final NBTTagCompound transformation, final String name) { + final NBTTagCompound rotation = new NBTTagCompound(); + rotation.setFloat("x", vector.x); + rotation.setFloat("y", vector.y); + rotation.setFloat("z", vector.z); + transformation.set(name, rotation); + } private void writeRotation(final Quaternionf quaternionf, final NBTTagCompound transformation, final String name) { final NBTTagCompound rotation = new NBTTagCompound(); @@ -368,4 +364,10 @@ protected int widthField() { protected int heightField() { return displayField.getVersionIndex() + 20; } + + @Override + public BoundingBox getBoundingBox() { + System.out.println(this.entitySize.getOrDefault().toString()); + return this.entitySize.getOrDefault().toBoundingBox(this); + } } diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fEntity.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fEntity.java index 857acfa9..1642852c 100644 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fEntity.java +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fEntity.java @@ -12,6 +12,7 @@ import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagCompound; import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagList; +import de.Ste3et_C0st.FurnitureLib.Utilitis.BoundingBox; import de.Ste3et_C0st.FurnitureLib.Utilitis.DefaultKey; import de.Ste3et_C0st.FurnitureLib.Utilitis.EntityID; import de.Ste3et_C0st.FurnitureLib.Utilitis.LanguageConverter; @@ -29,6 +30,7 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; + import java.util.*; import java.util.function.BiFunction; @@ -56,9 +58,10 @@ public abstract class fEntity extends fSerializer implements Cloneable { private Location location; private DefaultKey customName = new DefaultKey(""); - protected DefaultKey fire = new DefaultKey(false), nameVisible = new DefaultKey(false), isPlayed = new DefaultKey(false); protected DefaultKey glowing = new DefaultKey(false), invisible = new DefaultKey(false), gravity = new DefaultKey(false); + //protected DefaultKey boundingBox = new DefaultKey(new BoundingBox(0, 0, 0, 0, 0, 0)); + private List passengerIDs = new ArrayList<>(); @@ -162,7 +165,6 @@ public void setLocation(Location loc) { this.positionZ = loc.getZ(); this.yaw = ((byte) (int) (loc.getYaw() * 256.0F / 360.0F)); this.pitch = ((byte) (int) (loc.getPitch() * 256.0F / 360.0F)); - /* < 1.19 * this.yaw = ((byte) (int) (loc.getYaw() * 256.0F / 360.0F)); * this.pitch = ((byte) (int) (loc.getPitch() * 256.0F / 360.0F)); @@ -205,13 +207,15 @@ public String getName() { } public fEntity setName(String str) { - if (str == null) return this; - if (str.equalsIgnoreCase("")) setNameVisibility(false); if (FurnitureLib.isNewVersion()) { - final String workString = LanguageConverter.serializeLegacyColors(str); - final Component textComponent = MiniMessage.miniMessage().deserialize(workString); - final WrappedChatComponent wrappedChat = WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(textComponent)); - getWatcher().setObject(new WrappedDataWatcherObject(2, Registry.getChatComponentSerializer(true)), Optional.of(wrappedChat.getHandle())); + if(str == null || str.isEmpty()) { + getWatcher().setObject(new WrappedDataWatcherObject(2, Registry.getChatComponentSerializer(true)), Optional.empty()); + }else { + final String workString = LanguageConverter.serializeLegacyColors(str); + final Component textComponent = MiniMessage.miniMessage().deserialize(workString); + final WrappedChatComponent wrappedChat = WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(textComponent)); + getWatcher().setObject(new WrappedDataWatcherObject(2, Registry.getChatComponentSerializer(true)), Optional.of(wrappedChat.getHandle())); + } } else { getWatcher().setObject(new WrappedDataWatcherObject(2, Registry.get(String.class)), str); } @@ -224,17 +228,16 @@ public List getPassenger() { } public void setPassenger(Entity e) { + if (FurnitureConfig.getFurnitureConfig().canSitting() == false) return; setPassenger(Collections.singletonList(e.getEntityId())); - if (!FurnitureConfig.getFurnitureConfig().isRotateOnSitEnable()) { - return; - } + final boolean rotate = FurnitureConfig.getFurnitureConfig().isRotateOnSitEnable(); if (e.getType().equals(EntityType.PLAYER)) { PacketContainer container = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK); container.getIntegers().write(0, e.getEntityId()); container.getBytes().write(0, ((byte) (int) (getLocation().getYaw() * 256.0F / 360.0F))); try { for (Player p : getObjID().getPlayerList()) { - getManager().sendServerPacket(p, container); + if(rotate) getManager().sendServerPacket(p, container); getManager().sendServerPacket(p, this.mountPacketContainer); } } catch (Exception ex) { @@ -248,9 +251,7 @@ public void setPassenger(Integer EntityID) { } public void setPassenger(final List entityIDs) { - if (!FurnitureConfig.getFurnitureConfig().canSitting()) { - return; - } + if (!FurnitureConfig.getFurnitureConfig().canSitting()) {return;} if (entityIDs == null) {return;} this.passengerIDs.addAll(entityIDs); int[] passengerID = this.passengerIDs.stream().mapToInt(Integer::intValue).toArray(); diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fSize.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fSize.java index 68d71c4a..679402d5 100644 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fSize.java +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fSize.java @@ -2,7 +2,6 @@ import org.bukkit.Location; import org.bukkit.entity.EntityType; - import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry; import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; @@ -14,7 +13,7 @@ public abstract class fSize extends fEntity { private final DefaultKey width, height; - private final DefaultKey entitySize = new DefaultKey(new EntitySize(0, 0)); + protected final DefaultKey entitySize = new DefaultKey(new EntitySize(0, 0, 0)); public fSize(Location loc, EntityType type, int entityID, ObjectID id, float width, float height) { super(loc, type, entityID, id); @@ -60,5 +59,4 @@ protected void readSizeData(NBTTagCompound metadata) { this.setWidth(metadata.getFloat("width", this.width.getDefault())); this.setHeight(metadata.getFloat("height", this.height.getDefault())); } - } diff --git a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fText_display.java b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fText_display.java index 832b182a..218a13c0 100644 --- a/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fText_display.java +++ b/FurnitureLib-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/main/entity/fText_display.java @@ -152,22 +152,14 @@ public void setDefaultBackground(boolean defaultBackground) { @Override protected void writeAdditionalSaveData() { super.writeDisplaySaveData(); - if (!this.lineWitdth.isDefault()) - setMetadata("line_width", this.lineWitdth.getOrDefault()); - if (!this.background_color.isDefault()) - setMetadata("background", this.background_color.getOrDefault()); - if (!this.text_opacity.isDefault()) - setMetadata("text_opacity", this.text_opacity.getOrDefault()); - if (!this.style_flags.isDefault()) - setMetadata("alignment", this.style_flags.getOrDefault().name()); - if (!this.text.isDefault()) - setMetadata("text", this.text.getOrDefault()); - if (!this.shadowed.isDefault()) - setMetadata("shadow", this.shadowed.getOrDefault()); - if (!this.seeThrough.isDefault()) - setMetadata("see_through", this.seeThrough.getOrDefault()); - if (!this.defaultBackground.isDefault()) - setMetadata("default_background", this.defaultBackground.getOrDefault()); + if (!this.lineWitdth.isDefault()) setMetadata("line_width", this.lineWitdth.getOrDefault()); + if (!this.background_color.isDefault()) setMetadata("background", this.background_color.getOrDefault()); + if (!this.text_opacity.isDefault()) setMetadata("text_opacity", this.text_opacity.getOrDefault()); + if (!this.style_flags.isDefault()) setMetadata("alignment", this.style_flags.getOrDefault().name()); + if (!this.text.isDefault()) setMetadata("text", this.text.getOrDefault()); + if (!this.shadowed.isDefault()) setMetadata("shadow", this.shadowed.getOrDefault()); + if (!this.seeThrough.isDefault()) setMetadata("see_through", this.seeThrough.getOrDefault()); + if (!this.defaultBackground.isDefault()) setMetadata("default_background", this.defaultBackground.getOrDefault()); } protected void readAdditionalSaveData(NBTTagCompound metadata) {