diff --git a/api/src/main/java/net/donnypz/displayentityutils/utils/DisplayEntities/DisplayEntityGroup.java b/api/src/main/java/net/donnypz/displayentityutils/utils/DisplayEntities/DisplayEntityGroup.java index a1d5fa85..cd24b3d7 100644 --- a/api/src/main/java/net/donnypz/displayentityutils/utils/DisplayEntities/DisplayEntityGroup.java +++ b/api/src/main/java/net/donnypz/displayentityutils/utils/DisplayEntities/DisplayEntityGroup.java @@ -14,7 +14,6 @@ import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; -import java.util.List; public final class DisplayEntityGroup implements Serializable{ private final ArrayList displayEntities = new ArrayList<>(); diff --git a/api/src/main/java/net/donnypz/displayentityutils/utils/DisplayEntities/GroupSpawnSettings.java b/api/src/main/java/net/donnypz/displayentityutils/utils/DisplayEntities/GroupSpawnSettings.java index 28159d6f..be848b56 100644 --- a/api/src/main/java/net/donnypz/displayentityutils/utils/DisplayEntities/GroupSpawnSettings.java +++ b/api/src/main/java/net/donnypz/displayentityutils/utils/DisplayEntities/GroupSpawnSettings.java @@ -34,7 +34,7 @@ public class GroupSpawnSettings { /** * Set the teleportation duration for all display entities that will be spawned from {@link DisplayEntityGroup#spawn(Location, GroupSpawnedEvent.SpawnReason, GroupSpawnSettings)}. * This has no effect on Interaction entities. - * @param teleportationDuration how long display entities should interpolate when teleporting, in ticks + * @param teleportationDuration how long display entities should interpolate when teleporting or changing their looking direction, in ticks * @return this */ public GroupSpawnSettings setTeleportationDuration(int teleportationDuration) { @@ -163,7 +163,12 @@ boolean applyVisibility(PacketDisplayEntityPart part, Player player){ } } - boolean applyAttributes(PacketDisplayEntityPart part){ + /** + * Apply this {@link GroupSpawnSettings} properties to a {@link PacketDisplayEntityPart}. This should generally not be used + * @param part the {@link PacketDisplayEntityPart} + */ + public void applyAttributes(PacketDisplayEntityPart part){ + if (part == null) return; if (part.isDisplay()){ //Teleport Duration part.attributeContainer.setAttribute(DisplayAttributes.TELEPORTATION_DURATION, teleportationDuration); @@ -204,11 +209,15 @@ boolean applyAttributes(PacketDisplayEntityPart part){ } } } - return true; } - void apply(Display display){ + /** + * Apply this {@link GroupSpawnSettings} properties to a {@link Display} entity. This should generally not be used + * @param display a display entity + */ + public void apply(Display display){ + if (display == null) return; //Determine Visibility if (!visibleByDefault){ display.setVisibleByDefault(false); @@ -271,7 +280,12 @@ void apply(Display display){ display.setPersistent(persistentByDefault); } - void apply(Interaction interaction){ + /** + * Apply this {@link GroupSpawnSettings} properties to an {@link Interaction} entity. This should generally not be used + * @param interaction an interaction entity + */ + public void apply(Interaction interaction){ + if (interaction == null) return; //Determine Visibility if (!visibleByDefault || hideInteractions){ interaction.setVisibleByDefault(false); @@ -295,7 +309,12 @@ void apply(Interaction interaction){ interaction.setPersistent(persistentByDefault); } - void apply(Mannequin mannequin){ + /** + * Apply this {@link GroupSpawnSettings} properties to an {@link Mannequin} entity. This should generally not be used + * @param mannequin a mannequin entity + */ + public void apply(Mannequin mannequin){ + if (mannequin == null) return; //Determine Visibility if (!visibleByDefault){ mannequin.setVisibleByDefault(false); diff --git a/api/src/main/java/net/donnypz/displayentityutils/utils/DisplayEntities/PacketDisplayEntityGroup.java b/api/src/main/java/net/donnypz/displayentityutils/utils/DisplayEntities/PacketDisplayEntityGroup.java index 5e5c9900..916e4c71 100644 --- a/api/src/main/java/net/donnypz/displayentityutils/utils/DisplayEntities/PacketDisplayEntityGroup.java +++ b/api/src/main/java/net/donnypz/displayentityutils/utils/DisplayEntities/PacketDisplayEntityGroup.java @@ -10,14 +10,13 @@ import net.donnypz.displayentityutils.managers.holders.AsyncGroupHolder; import net.donnypz.displayentityutils.utils.*; import net.donnypz.displayentityutils.utils.DisplayEntities.machine.DisplayStateMachine; +import net.donnypz.displayentityutils.utils.bdengine.convert.file.BDEModel; import net.donnypz.displayentityutils.utils.controller.DisplayControllerManager; import net.donnypz.displayentityutils.utils.packet.DisplayAttributeMap; +import net.donnypz.displayentityutils.utils.packet.PacketAttributeContainer; import net.donnypz.displayentityutils.utils.packet.attributes.DisplayAttributes; import net.donnypz.displayentityutils.utils.version.folia.Scheduler; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Transformation; @@ -44,6 +43,32 @@ public class PacketDisplayEntityGroup extends ActiveGroup resettedParts = new HashSet<>(); @@ -1186,14 +1193,12 @@ public PacketDisplayEntityGroup toPacket(@NotNull Location location, boolean pla location.setYaw(0); PacketDisplayEntityGroup packetGroup; - if (persistent){ - packetGroup = DisplayGroupManager.addPersistentPacketGroup(location, savedGroup, autoShow, GroupSpawnedEvent.SpawnReason.INTERNAL); + if (settings.persistentByDefault){ + packetGroup = DisplayGroupManager + .addPersistentPacketGroup(location, savedGroup, settings, GroupSpawnedEvent.SpawnReason.INTERNAL); } else{ - packetGroup = savedGroup.createPacketGroup(location, GroupSpawnedEvent.SpawnReason.INTERNAL, - new GroupSpawnSettings() - .visibleByDefault(autoShow, null) - .playSpawnAnimation(playSpawnAnimation)); + packetGroup = savedGroup.createPacketGroup(location, GroupSpawnedEvent.SpawnReason.INTERNAL, settings); } //Restore pivot diff --git a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEBlockDisplay.java b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEBlockDisplay.java index 012d5da8..c4f04fc8 100644 --- a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEBlockDisplay.java +++ b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEBlockDisplay.java @@ -1,6 +1,13 @@ package net.donnypz.displayentityutils.utils.bdengine.convert.file; +import net.donnypz.displayentityutils.utils.DisplayEntities.GroupSpawnSettings; +import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityGroup; +import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityPart; +import net.donnypz.displayentityutils.utils.DisplayEntities.SpawnedDisplayEntityPart; +import net.donnypz.displayentityutils.utils.packet.PacketAttributeContainer; +import net.donnypz.displayentityutils.utils.packet.attributes.DisplayAttributes; import net.donnypz.displayentityutils.utils.version.VersionUtils; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.entity.BlockDisplay; @@ -25,8 +32,16 @@ class BDEBlockDisplay extends BDEDisplay{ } } + @Override + PacketDisplayEntityPart createPart(Location spawnLocation) { + return new PacketAttributeContainer() + .setAttribute(DisplayAttributes.BlockDisplay.BLOCK_STATE, blockData != null ? blockData : Material.AIR.createBlockData()) + .createPart(SpawnedDisplayEntityPart.PartType.BLOCK_DISPLAY, spawnLocation); + } + @Override void apply(BlockDisplay display) { if (blockData != null) display.setBlock(blockData); } + } diff --git a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDECollection.java b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDECollection.java index 87c1ac9c..6bf883b4 100644 --- a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDECollection.java +++ b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDECollection.java @@ -1,5 +1,7 @@ package net.donnypz.displayentityutils.utils.bdengine.convert.file; +import net.donnypz.displayentityutils.utils.DisplayEntities.GroupSpawnSettings; +import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityGroup; import org.bukkit.Location; import org.bukkit.entity.BlockDisplay; @@ -47,9 +49,16 @@ class BDECollection extends BDEObject{ } @Override - void spawn(Location spawnLoc, BlockDisplay parent, BDECollection parentCollection) { + void spawn(Location spawnLoc, BlockDisplay parent, BDECollection parentCollection, GroupSpawnSettings settings) { for (BDEObject obj : children){ - obj.spawn(spawnLoc, parent, this); + obj.spawn(spawnLoc, parent, this, settings); + } + } + + @Override + void spawnPacket(Location spawnLoc, PacketDisplayEntityGroup packetGroup, BDECollection parentCollection, GroupSpawnSettings settings) { + for (BDEObject obj : children){ + obj.spawnPacket(spawnLoc, packetGroup, this, settings); } } diff --git a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEDisplay.java b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEDisplay.java index cf94a915..87aa2dc7 100644 --- a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEDisplay.java +++ b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEDisplay.java @@ -1,5 +1,8 @@ package net.donnypz.displayentityutils.utils.bdengine.convert.file; +import net.donnypz.displayentityutils.utils.DisplayEntities.GroupSpawnSettings; +import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityGroup; +import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityPart; import net.donnypz.displayentityutils.utils.DisplayUtils; import org.bukkit.Location; import org.bukkit.entity.BlockDisplay; @@ -23,19 +26,38 @@ abstract class BDEDisplay extends BDEObject{ abstract void apply(T display); + abstract PacketDisplayEntityPart createPart(Location spawnLocation); + @Override - void spawn(Location spawnLoc, BlockDisplay parent, BDECollection parentCollection){ + void spawn(Location spawnLoc, BlockDisplay parent, BDECollection parentCollection, GroupSpawnSettings settings){ Display display = spawnLoc.getWorld().spawn(spawnLoc, displayClass, d -> { d.setBrightness(new Display.Brightness(brightness[0], brightness[1])); + settings.apply(d); d.setTransformationMatrix(transformationMatrix); - d.setPersistent(false); if (!parentCollection.isMaster){ DisplayUtils.addTags(d, parentCollection.upperCollections); DisplayUtils.addTag(d, parentCollection.name); } apply(d); + }); parent.addPassenger(display); } + + @Override + void spawnPacket(Location spawnLoc, PacketDisplayEntityGroup packetGroup, BDECollection parentCollection, GroupSpawnSettings settings){ + PacketDisplayEntityPart part = createPart(spawnLoc); + + part.setBrightness(new Display.Brightness(brightness[0], brightness[1])); + settings.applyAttributes(part); + part.setTransformationMatrix(transformationMatrix); + + if (!parentCollection.isMaster){ + part.addTags(parentCollection.upperCollections); + part.addTag(parentCollection.name); + } + + packetGroup.addPart(part); + } } diff --git a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEItemDisplay.java b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEItemDisplay.java index 30bf14d5..a98dbb73 100644 --- a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEItemDisplay.java +++ b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEItemDisplay.java @@ -2,10 +2,11 @@ import com.destroystokyo.paper.profile.PlayerProfile; import com.destroystokyo.paper.profile.ProfileProperty; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.Registry; +import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityPart; +import net.donnypz.displayentityutils.utils.DisplayEntities.SpawnedDisplayEntityPart; +import net.donnypz.displayentityutils.utils.packet.PacketAttributeContainer; +import net.donnypz.displayentityutils.utils.packet.attributes.DisplayAttributes; +import org.bukkit.*; import org.bukkit.entity.ItemDisplay; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; @@ -34,6 +35,19 @@ class BDEItemDisplay extends BDEDisplay { @Override void apply(ItemDisplay display) { + display.setItemStack(getItem()); + display.setItemDisplayTransform(transform); + } + + @Override + PacketDisplayEntityPart createPart(Location spawnLocation) { + return new PacketAttributeContainer() + .setAttribute(DisplayAttributes.ItemDisplay.ITEMSTACK, getItem()) + .setAttribute(DisplayAttributes.ItemDisplay.ITEM_DISPLAY_TRANSFORM, transform) + .createPart(SpawnedDisplayEntityPart.PartType.ITEM_DISPLAY, spawnLocation); + } + + private ItemStack getItem(){ Material material = Registry.MATERIAL.get(NamespacedKey.minecraft(name.toLowerCase())); if (material != null){ ItemStack item = new ItemStack(material); @@ -46,11 +60,10 @@ void apply(ItemDisplay display) { meta.setPlayerProfile(profile); item.setItemMeta(meta); } - display.setItemStack(item); + return item; } else{ - display.setItemStack(ItemStack.empty()); + return ItemStack.empty(); } - display.setItemDisplayTransform(transform); } } diff --git a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEModel.java b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEModel.java index e9ecb874..3a3bd3f3 100644 --- a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEModel.java +++ b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEModel.java @@ -1,16 +1,21 @@ package net.donnypz.displayentityutils.utils.bdengine.convert.file; import net.donnypz.displayentityutils.events.GroupSpawnedEvent; +import net.donnypz.displayentityutils.events.PrePacketGroupCreateEvent; import net.donnypz.displayentityutils.managers.DisplayGroupManager; -import net.donnypz.displayentityutils.utils.DisplayEntities.SpawnedDisplayEntityGroup; +import net.donnypz.displayentityutils.utils.DisplayEntities.*; import net.donnypz.displayentityutils.utils.GroupResult; +import net.donnypz.displayentityutils.utils.packet.PacketAttributeContainer; +import net.donnypz.displayentityutils.utils.packet.attributes.DisplayAttributes; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.entity.BlockDisplay; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import java.util.Map; -public class BDEModel extends BDECollection{ +public class BDEModel extends BDECollection { //Map animations = new TreeMap<>(); //id, anim String groupTag; //String animationPrefix; @@ -22,11 +27,13 @@ public class BDEModel extends BDECollection{ //this.animationPrefix = animationPrefix; } - public @NotNull SpawnedDisplayEntityGroup spawn(@NotNull Location spawnLoc, @NotNull GroupSpawnedEvent.SpawnReason spawnReason){ - BlockDisplay parentDisplay = spawnLoc.getWorld().spawn(spawnLoc, BlockDisplay.class, bd -> { - bd.setPersistent(false); - }); - super.spawn(spawnLoc, parentDisplay, null); + public @NotNull SpawnedDisplayEntityGroup spawn(@NotNull Location spawnLoc, @NotNull GroupSpawnedEvent.SpawnReason spawnReason) { + return spawn(spawnLoc, spawnReason, new GroupSpawnSettings().persistentByDefault(false)); + } + + public @NotNull SpawnedDisplayEntityGroup spawn(@NotNull Location spawnLoc, @NotNull GroupSpawnedEvent.SpawnReason spawnReason, @NotNull GroupSpawnSettings settings) { + BlockDisplay parentDisplay = spawnLoc.getWorld().spawn(spawnLoc, BlockDisplay.class, settings::apply); + super.spawn(spawnLoc, parentDisplay, null, settings); GroupResult result = DisplayGroupManager.getOrCreateSpawnedGroup(parentDisplay); SpawnedDisplayEntityGroup group = result.group(); @@ -35,11 +42,24 @@ public class BDEModel extends BDECollection{ return group; } - public String getGroupTag(){ + public @NotNull PacketDisplayEntityGroup createPacketGroup(@NotNull Location spawnLoc) { + return createPacketGroup(spawnLoc, new GroupSpawnSettings().persistentByDefault(false)); + } + + public @NotNull PacketDisplayEntityGroup createPacketGroup(@NotNull Location spawnLoc, @NotNull GroupSpawnSettings settings){ + return new PacketDisplayEntityGroup(this, spawnLoc, settings); + } + + @ApiStatus.Internal + public void addEntities(@NotNull PacketDisplayEntityGroup packetDisplayEntityGroup, Location spawnLocation, GroupSpawnSettings settings) { + super.spawnPacket(spawnLocation, packetDisplayEntityGroup, null, settings); + } + + public String getGroupTag() { return groupTag; } // public String getAnimationPrefix(){ // return animationPrefix; // } -} +} \ No newline at end of file diff --git a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEObject.java b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEObject.java index 0dc77809..64436776 100644 --- a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEObject.java +++ b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDEObject.java @@ -1,5 +1,8 @@ package net.donnypz.displayentityutils.utils.bdengine.convert.file; +import net.donnypz.displayentityutils.utils.DisplayEntities.GroupSpawnSettings; +import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityGroup; +import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityPart; import org.bukkit.Location; import org.bukkit.entity.BlockDisplay; import org.joml.Matrix4f; @@ -50,5 +53,7 @@ private void readCommon(Map bdeObject){ - abstract void spawn(Location spawnLoc, BlockDisplay parent, BDECollection parentCollection); + abstract void spawn(Location spawnLoc, BlockDisplay parent, BDECollection parentCollection, GroupSpawnSettings settings); + + abstract void spawnPacket(Location spawnLoc, PacketDisplayEntityGroup packetGroup, BDECollection parentCollection, GroupSpawnSettings settings); } diff --git a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDETextDisplay.java b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDETextDisplay.java index 26821dba..93ae8da7 100644 --- a/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDETextDisplay.java +++ b/api/src/main/java/net/donnypz/displayentityutils/utils/bdengine/convert/file/BDETextDisplay.java @@ -1,10 +1,16 @@ package net.donnypz.displayentityutils.utils.bdengine.convert.file; import net.donnypz.displayentityutils.utils.ConversionUtils; +import net.donnypz.displayentityutils.utils.DisplayEntities.PacketDisplayEntityPart; +import net.donnypz.displayentityutils.utils.DisplayEntities.SpawnedDisplayEntityPart; +import net.donnypz.displayentityutils.utils.packet.PacketAttributeContainer; +import net.donnypz.displayentityutils.utils.packet.attributes.DisplayAttributes; +import net.donnypz.displayentityutils.utils.packet.attributes.TextDisplayOptions; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextDecoration; import org.bukkit.Color; +import org.bukkit.Location; import org.bukkit.entity.TextDisplay; import org.joml.Matrix4f; @@ -46,4 +52,15 @@ void apply(TextDisplay display) { display.setLineWidth(lineLength); display.setAlignment(alignment); } + + @Override + PacketDisplayEntityPart createPart(Location spawnLocation) { + return new PacketAttributeContainer() + .setAttribute(DisplayAttributes.TextDisplay.TEXT, text) + .setAttribute(DisplayAttributes.TextDisplay.TEXT_OPACITY_PERCENTAGE, textAlpha) + .setAttribute(DisplayAttributes.TextDisplay.BACKGROUND_COLOR, backgroundColor) + .setAttribute(DisplayAttributes.TextDisplay.LINE_WIDTH, lineLength) + .setAttribute(DisplayAttributes.TextDisplay.EXTRA_TEXT_OPTIONS, new TextDisplayOptions(false, false, false, alignment)) + .createPart(SpawnedDisplayEntityPart.PartType.TEXT_DISPLAY, spawnLocation); + } } diff --git a/plugin/src/main/java/net/donnypz/displayentityutils/skript/active/expressions/ExprActiveDirection.java b/plugin/src/main/java/net/donnypz/displayentityutils/skript/active/expressions/ExprActiveDirection.java index 9678ef95..be3b8ed3 100644 --- a/plugin/src/main/java/net/donnypz/displayentityutils/skript/active/expressions/ExprActiveDirection.java +++ b/plugin/src/main/java/net/donnypz/displayentityutils/skript/active/expressions/ExprActiveDirection.java @@ -23,7 +23,7 @@ "set {_activegroup}'s deu yaw to 73", "set {_activegroup}'s deu yaw with interaction pivot to 25", "", - "3.4.3 and earlier", + "#3.4.3 and earlier", "deu set {_activegroup}'s yaw with interaction pivot to 35", "deu set {_activepart}'s pitch to -90"}) @Since("2.6.2, 3.0.0 (Packet)") @@ -61,8 +61,8 @@ public Class getReturnType() { @Override public void change(Event event, Object[] delta, Changer.ChangeMode mode){ - Active[] active = getExpr().getArray(event); - if (active == null){ + Object[] arr = getExpr().getArray(event); + if (arr == null){ return; } @@ -74,7 +74,8 @@ public void change(Event event, Object[] delta, Changer.ChangeMode mode){ if (value == null) return; float rotVal = value.floatValue(); - for (Active a : getExpr().getArray(event)){ + for (Object o : arr){ + if (!(o instanceof Active a)) continue; if (pitch){ a.setPitch(rotVal); } @@ -84,7 +85,8 @@ public void change(Event event, Object[] delta, Changer.ChangeMode mode){ } } case RESET -> { - for (Active a : getExpr().getArray(event)){ + for (Object o : arr){ + if (!(o instanceof Active a)) continue; if (pitch){ a.setPitch(0); } diff --git a/plugin/src/main/java/net/donnypz/displayentityutils/skript/group/activegroup/effects/EffActiveGroupRespectEntity.java b/plugin/src/main/java/net/donnypz/displayentityutils/skript/group/activegroup/effects/EffActiveGroupRespectEntity.java index 90d9da32..70c34f15 100644 --- a/plugin/src/main/java/net/donnypz/displayentityutils/skript/group/activegroup/effects/EffActiveGroupRespectEntity.java +++ b/plugin/src/main/java/net/donnypz/displayentityutils/skript/group/activegroup/effects/EffActiveGroupRespectEntity.java @@ -87,14 +87,14 @@ protected void execute(Event event) { ActiveGroup[] gs = group.getArray(event); Entity e = entity.getSingle(event); FollowType type = followType; - int tpDur = tpDuration == null ? 0 : tpDuration.getSingle(event).intValue(); + int tpDur = tpDuration == null ? Integer.MIN_VALUE : tpDuration.getSingle(event).intValue(); int despawn = despawnTimespan == null ? -1 : (int) despawnTimespan.getSingle(event).getAs(Timespan.TimePeriod.TICK); if (gs == null || e == null || type == null) return; for (ActiveGroup g : gs){ g.followEntityDirection(e, GroupFollowProperties.builder(type) .setFlip(flip) - .setTeleportationDuration(tpDur) + .setTeleportationDuration(tpDur == Integer.MIN_VALUE ? g.getTeleportDuration() : tpDur) .setUnregisterDelay(despawn) .build()); } diff --git a/plugin/src/main/java/net/donnypz/displayentityutils/skript/group/activegroup/expressions/ExprActiveGroupRideOffset.java b/plugin/src/main/java/net/donnypz/displayentityutils/skript/group/activegroup/expressions/ExprActiveGroupRideOffset.java index d4847498..a6f70581 100644 --- a/plugin/src/main/java/net/donnypz/displayentityutils/skript/group/activegroup/expressions/ExprActiveGroupRideOffset.java +++ b/plugin/src/main/java/net/donnypz/displayentityutils/skript/group/activegroup/expressions/ExprActiveGroupRideOffset.java @@ -8,7 +8,6 @@ import ch.njol.skript.expressions.base.SimplePropertyExpression; import ch.njol.util.coll.CollectionUtils; import net.donnypz.displayentityutils.utils.DisplayEntities.*; -import org.bukkit.Location; import org.bukkit.event.Event; import org.bukkit.util.Vector; import org.jetbrains.annotations.Nullable; @@ -18,9 +17,12 @@ @Name("Active Group Ride Offset") @Description("Get or set the translation offset to apply to a group when its riding an entity. " + "This should be used before making a group ride any entities") -@Examples({"set {_offsetvector} to {_activegroup}'s deu ride offset", - "", - "set {_activegroup}'s deu ride offset to vector(0,1,0)"}) +@Examples({ + "#This should be set BEFORE a group rides an entity", + "set {_offsetvector} to {_activegroup}'s deu ride offset", + "", + "set {_activegroup}'s deu ride offset to vector(0,1,0)" +}) @Since("3.4.1") public class ExprActiveGroupRideOffset extends SimplePropertyExpression { diff --git a/plugin/src/main/java/net/donnypz/displayentityutils/skript/group/activegroup/sections/SecSpawnGroup.java b/plugin/src/main/java/net/donnypz/displayentityutils/skript/group/activegroup/sections/SecSpawnGroup.java index ec19d26a..5762bcaa 100644 --- a/plugin/src/main/java/net/donnypz/displayentityutils/skript/group/activegroup/sections/SecSpawnGroup.java +++ b/plugin/src/main/java/net/donnypz/displayentityutils/skript/group/activegroup/sections/SecSpawnGroup.java @@ -38,6 +38,8 @@ "`visible` = whether the group should be visible. True by default", "`brightness` = the brightness of display entities in the group. Use `-1 and -1` for default brightness", "`spawnanimation` = whether the group should play its spawn animation. True by default", + "", + "\"If a group is packet-based it's persistence cannot be set within the \\nsection and must be set afterwards.\"" }) @Examples({"deu spawn {_savedgroup} at {_location}", "deu spawn {_savedgroup} at {_location} and store the result in {_activegroup}", diff --git a/plugin/src/main/java/net/donnypz/displayentityutils/skript/io/IOModule.java b/plugin/src/main/java/net/donnypz/displayentityutils/skript/io/IOModule.java index b1cbba6f..f57b2e5d 100644 --- a/plugin/src/main/java/net/donnypz/displayentityutils/skript/io/IOModule.java +++ b/plugin/src/main/java/net/donnypz/displayentityutils/skript/io/IOModule.java @@ -1,8 +1,8 @@ package net.donnypz.displayentityutils.skript.io; import net.donnypz.displayentityutils.skript.SkriptUtil; -import net.donnypz.displayentityutils.skript.io.effects.EffBDEModelToSpawned; import net.donnypz.displayentityutils.skript.io.expressions.ExprSavedFromLoadMethod; +import net.donnypz.displayentityutils.skript.io.sections.SecSpawnBDEModel; import org.skriptlang.skript.addon.AddonModule; import org.skriptlang.skript.addon.SkriptAddon; @@ -11,8 +11,8 @@ public class IOModule implements AddonModule { @Override public void load(SkriptAddon skriptAddon) { SkriptUtil.registerModules(skriptAddon.syntaxRegistry(), - EffBDEModelToSpawned::register, - ExprSavedFromLoadMethod::register + ExprSavedFromLoadMethod::register, + SecSpawnBDEModel::register ); } diff --git a/plugin/src/main/java/net/donnypz/displayentityutils/skript/io/effects/EffBDEModelToSpawned.java b/plugin/src/main/java/net/donnypz/displayentityutils/skript/io/effects/EffBDEModelToSpawned.java deleted file mode 100644 index 5bdb1e00..00000000 --- a/plugin/src/main/java/net/donnypz/displayentityutils/skript/io/effects/EffBDEModelToSpawned.java +++ /dev/null @@ -1,92 +0,0 @@ -package net.donnypz.displayentityutils.skript.io.effects; - -import ch.njol.skript.classes.Changer; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.Since; -import ch.njol.skript.lang.Effect; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser; -import ch.njol.util.Kleenean; -import net.donnypz.displayentityutils.command.bdengine.BDEngineSpawnModelCMD; -import net.donnypz.displayentityutils.events.GroupSpawnedEvent; -import net.donnypz.displayentityutils.managers.PluginFolders; -import net.donnypz.displayentityutils.utils.DisplayEntities.ActiveGroup; -import net.donnypz.displayentityutils.utils.DisplayEntities.SpawnedDisplayEntityGroup; -import net.donnypz.displayentityutils.utils.bdengine.BDEngineUtils; -import net.donnypz.displayentityutils.utils.bdengine.convert.file.BDEModel; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.event.Event; -import org.jetbrains.annotations.Nullable; -import org.skriptlang.skript.registration.SyntaxInfo; -import org.skriptlang.skript.registration.SyntaxRegistry; - -import java.io.File; - -@Name("BDEngine Model to Spawned Group") -@Description("Spawn a model from a \".bdengine\" file, stored in DisplayEntityUtils' \"bdenginefiles\" folder") -@Examples({ - "deu spawn bde model \"mymodel\" at {_location}", - "deu spawn bde model \"mymodel\" at {_location} stored in {_newgroup}", - "", - "3.4.3 and earlier", - "set {_spawnedgroup} to bdengine model \"mymodel\" spawned at {_location}", - "set {_spawnedgroup} to bde model \"model.bdengine\" spawned at {_location}" -}) -@Since("3.3.0") -public class EffBDEModelToSpawned extends Effect { - - private Expression fileName; - Expression location; - private Expression store; - - - public static void register(SyntaxRegistry registry){ - registry.register(SyntaxRegistry.EFFECT, - SyntaxInfo.builder(EffBDEModelToSpawned.class) - .addPattern("deu spawn bde[ngine] model %string% at %location% [store:[and] store[d] [it |the result] in %-objects%]") - .supplier(EffBDEModelToSpawned::new) - .build() - ); - } - - - @Override - protected void execute(Event event) { - String file = fileName.getSingle(event); - Location loc = location.getSingle(event); - if (file == null || loc == null){ - Bukkit.broadcastMessage("?"); - return; - } - BDEModel model = BDEngineUtils.readFile(new File(PluginFolders.bdeFilesFolder, BDEngineSpawnModelCMD.fileExtension(file))); - if (model == null){ - Bukkit.broadcastMessage("NM"); - return; - } - SpawnedDisplayEntityGroup g = model.spawn(loc, GroupSpawnedEvent.SpawnReason.SKRIPT); - - if (this.store != null){ - store.change(event, new ActiveGroup[]{g}, Changer.ChangeMode.SET); - } - } - - @Override - public String toString(@Nullable Event event, boolean debug) { - return "bdengine file \""+fileName.toString(event,debug)+"\" to spawned group"; - } - - @Override - public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { - fileName = (Expression) expressions[0]; - location = (Expression) expressions[1]; - if (parseResult.hasTag("store")){ - this.store = expressions[2]; - } - return true; - } - - -} diff --git a/plugin/src/main/java/net/donnypz/displayentityutils/skript/io/sections/SecSpawnBDEModel.java b/plugin/src/main/java/net/donnypz/displayentityutils/skript/io/sections/SecSpawnBDEModel.java new file mode 100644 index 00000000..2a4e7694 --- /dev/null +++ b/plugin/src/main/java/net/donnypz/displayentityutils/skript/io/sections/SecSpawnBDEModel.java @@ -0,0 +1,218 @@ +package net.donnypz.displayentityutils.skript.io.sections; + +import ch.njol.skript.classes.Changer; +import ch.njol.skript.config.SectionNode; +import ch.njol.skript.doc.*; +import ch.njol.skript.lang.EffectSection; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.TriggerItem; +import ch.njol.util.Kleenean; +import net.donnypz.displayentityutils.command.bdengine.BDEngineSpawnModelCMD; +import net.donnypz.displayentityutils.events.GroupSpawnedEvent; +import net.donnypz.displayentityutils.managers.PluginFolders; +import net.donnypz.displayentityutils.utils.DisplayEntities.*; +import net.donnypz.displayentityutils.utils.bdengine.BDEngineUtils; +import net.donnypz.displayentityutils.utils.bdengine.convert.file.BDEModel; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Display; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.lang.entry.EntryContainer; +import org.skriptlang.skript.lang.entry.EntryValidator; +import org.skriptlang.skript.lang.entry.util.ExpressionEntryData; +import org.skriptlang.skript.registration.SyntaxInfo; +import org.skriptlang.skript.registration.SyntaxRegistry; + +import java.io.File; +import java.util.List; + + +@Name("Spawn BDEngine Model from File") +@Description({"Spawn a BDEngine Model, from a file, at a location, with specified options", + "**Entries**", + "`packet` = whether the group should be packet-based. False by default", + "`teleport-duration` = the teleport-duration of display entities in the group. 0 by default", + "`billboard` = the billboard of display entities in the group. FIXED by default", + "`persistent` = the persistence of **all** entities in the group. True by default", + "`visible` = whether the group should be visible. True by default", + "`brightness` = the brightness of display entities in the group. Use `-1 and -1` for default brightness", + "`spawnanimation` = whether the group should play its spawn animation. True by default", + "", + "If a group is packet-based it's persistence cannot be set within the \nsection and must be set afterwards." +}) +@Examples({ + "deu spawn bde model \"mymodel\" at {_location}", + "deu spawn bde model \"mymodel\" at {_location} stored in {_activegroup}", + "", + "deu spawn bde model \"mymodel\" at {_location} stored in {_activegroup}:", + "\tpacket: false", + "\tteleport-duration: 2", + "\tbillboard: VERTICAL", + "\tpersistent: true", + "\tvisible: true", + "\tbrightness: 10 and 5 #Block and Sky, -1 and -1 to reset", + "\tspawnanimation: true", + "", + "", + "#3.4.3 and earlier", + "set {_activegroup} to bdengine model \"mymodel\" spawned at {_location}", + "set {_activegroup} to bde model \"model.bdengine\" spawned at {_location}" +}) +@Since("3.3.0, 3.5.0 (New Syntax), 3.5.1 (Section)") +@DocumentationId("EffBDEModelToSpawned") +public class SecSpawnBDEModel extends EffectSection { + + private Expression fileName; + Expression location; + private Expression store; + + private Expression packetExpr; + private Expression teleportDurationExpr; + private Expression billboardExpr; + private Expression persistentExpr; + private Expression visibleExpr; + private Expression brightnessExpr; + private Expression spawnAnimationExpr; + + private static EntryValidator VALIDATOR; + + public static void register(SyntaxRegistry registry){ + VALIDATOR = EntryValidator.builder() + .addEntryData(new ExpressionEntryData<>("packet", null, true, Boolean.class)) + .addEntryData(new ExpressionEntryData<>("teleport-duration", null, true, Integer.class)) + .addEntryData(new ExpressionEntryData<>("billboard", null, true, Display.Billboard.class)) + .addEntryData(new ExpressionEntryData<>("persistent", null, true, Boolean.class)) + .addEntryData(new ExpressionEntryData<>("visible", null, true, Boolean.class)) + .addEntryData(new ExpressionEntryData<>("brightness", null, true, Number.class)) + .addEntryData(new ExpressionEntryData<>("spawnanimation", null, true, Boolean.class)) + .build(); + + registry.register(SyntaxRegistry.SECTION, + SyntaxInfo.builder(SecSpawnBDEModel.class) + .addPattern("deu spawn bde[ngine] model %string% at %location% [store:[and] store[d] [it |the result] in %-objects%]") + .supplier(SecSpawnBDEModel::new) + .build() + ); + } + + @Override + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult, @Nullable SectionNode sectionNode, @Nullable List triggerItems) { + this.fileName = (Expression) expressions[0]; + this.location = (Expression) expressions[1]; + if (parseResult.hasTag("store")){ + this.store = expressions[2]; + } + + if (sectionNode == null) return true; + + EntryContainer container = VALIDATOR.validate(sectionNode); + if (container != null) { + this.packetExpr = (Expression) container.getOptional("packet",false); + this.teleportDurationExpr = (Expression) container.getOptional("teleport-duration",false); + this.billboardExpr = (Expression) container.getOptional("billboard",false); + this.persistentExpr = (Expression) container.getOptional("persistent",false); + this.visibleExpr = (Expression) container.getOptional("visible",false); + this.brightnessExpr = (Expression) container.getOptional("brightness",false); + this.spawnAnimationExpr = (Expression) container.getOptional("spawnanimation",false); + } + + return true; + } + + @Nullable + @Override + protected TriggerItem walk(Event event) { + String fileName = this.fileName.getSingle(event); + if (fileName == null){ + error("File/Model name is missing"); + return super.walk(event, false); + } + + Location loc = location.getSingle(event); + if (loc == null){ + error("Location is missing"); + return super.walk(event, false); + } + GroupSpawnSettings settings = new GroupSpawnSettings(); + + if (teleportDurationExpr != null){ + Integer tpDur = teleportDurationExpr.getSingle(event); + if (tpDur != null) settings.setTeleportationDuration(tpDur); + } + + if (billboardExpr != null){ + Display.Billboard billboard = billboardExpr.getSingle(event); + if (billboard != null) settings.addBillboard(billboard, null); + } + + if (visibleExpr != null){ + Boolean visible = visibleExpr.getSingle(event); + if (visible != null) settings.visibleByDefault(visible, null); + } + + if (brightnessExpr != null){ + Number[] brightnessArr = brightnessExpr.getArray(event); + if (brightnessArr != null){ + int block = brightnessArr[1].intValue(); + int sky = brightnessArr[0].intValue(); + if (block == -1 && sky == -1){ + settings.addBrightness(null, null); + } + else{ + settings.addBrightness(new Display.Brightness(block, sky), null); + } + } + } + + boolean isPacket; + if (packetExpr != null){ + Boolean packet = packetExpr.getSingle(event); + isPacket = packet != null && packet; + } + else isPacket = false; + + if (persistentExpr != null){ + Boolean persist = persistentExpr.getSingle(event); + if (persist != null){ + settings.persistentByDefault(persist); + } + else{ + settings.persistentByDefault(!isPacket); + } + } + + + if (spawnAnimationExpr != null){ + Boolean play = spawnAnimationExpr.getSingle(event); + boolean playSpawnAnim = play != null && play; + settings.playSpawnAnimation(playSpawnAnim); + } + + BDEModel model = BDEngineUtils.readFile(new File(PluginFolders.bdeFilesFolder, BDEngineSpawnModelCMD.fileExtension(fileName))); + if (model == null){ + return super.walk(event, false); + } + + + ActiveGroup activeGroup; + if (isPacket){ + activeGroup = model.createPacketGroup(loc, settings); + } + else{ + activeGroup = model.spawn(loc, GroupSpawnedEvent.SpawnReason.SKRIPT, settings); + } + + if (this.store != null){ + store.change(event, new ActiveGroup[]{activeGroup}, Changer.ChangeMode.SET); + } + + return super.walk(event, false); + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "spawn bdengine model from file \""+fileName.toString(event,debug); + } +}