From 0d1d0ea4385fbdbf7f05c671601579d530a5058a Mon Sep 17 00:00:00 2001 From: lbenav8095 Date: Fri, 22 Mar 2024 16:36:49 -0600 Subject: [PATCH] Moves DisplayOperator and DisplayOperatorReader from BlobDesign to BlobLib ObjectManager now implements CommandTarget for their asset --- .../bloblib/entities/ObjectManager.java | 18 ++++++--- .../bloblib/entities/display/DisplayData.java | 20 ++++++++-- .../entities/display/DisplayOperator.java | 39 ++++++++++++++++++ .../display/DisplayOperatorReader.java | 40 +++++++++++++++++++ 4 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 src/main/java/us/mytheria/bloblib/entities/display/DisplayOperator.java create mode 100644 src/main/java/us/mytheria/bloblib/entities/display/DisplayOperatorReader.java diff --git a/src/main/java/us/mytheria/bloblib/entities/ObjectManager.java b/src/main/java/us/mytheria/bloblib/entities/ObjectManager.java index 8059a4db..60c7b061 100644 --- a/src/main/java/us/mytheria/bloblib/entities/ObjectManager.java +++ b/src/main/java/us/mytheria/bloblib/entities/ObjectManager.java @@ -1,6 +1,7 @@ package us.mytheria.bloblib.entities; import me.anjoismysign.anjo.entities.Result; +import me.anjoismysign.skeramidcommands.command.CommandTarget; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; import us.mytheria.bloblib.entities.logger.BlobPluginLogger; @@ -8,10 +9,7 @@ import us.mytheria.bloblib.managers.ManagerDirector; import java.io.File; -import java.util.Collection; -import java.util.Map; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadLocalRandom; import java.util.function.Consumer; @@ -22,7 +20,8 @@ * @author An ObjectManager will handle objects that are loaded in * random access memory and tracked by a key. */ -public abstract class ObjectManager extends Manager { +public abstract class ObjectManager extends Manager + implements CommandTarget { private final File loadFilesDirectory; private final Supplier> objectsSupplier; private final Supplier> fileSupplier; @@ -223,4 +222,13 @@ public void whenFilesLoad(Consumer> consumer) { consumer.accept(this); }); } + + public List get() { + return new ArrayList<>(objects.keySet()); + } + + @Nullable + public T parse(String key) { + return getObject(key); + } } \ No newline at end of file diff --git a/src/main/java/us/mytheria/bloblib/entities/display/DisplayData.java b/src/main/java/us/mytheria/bloblib/entities/display/DisplayData.java index bb6a4aaf..554d4ac2 100644 --- a/src/main/java/us/mytheria/bloblib/entities/display/DisplayData.java +++ b/src/main/java/us/mytheria/bloblib/entities/display/DisplayData.java @@ -26,12 +26,16 @@ public record DisplayData(Display.Brightness brightness, float displayWidth, float displayHeight, @Nullable Color glowColorOverride, - boolean applyBrightness) { + boolean applyBrightness, + int interpolationDuration, + int interpolationDelay, + int teleportDuration) { public static DisplayData DEFAULT = new DisplayData(new Display.Brightness(15, 15), Display.Billboard.FIXED, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, - null, false); + null, false, + 1, 0, 1); /** * Will apply the DisplayData to the given Display. @@ -48,6 +52,12 @@ public void apply(Display display) { display.setDisplayWidth(displayWidth); display.setDisplayHeight(displayHeight); display.setGlowColorOverride(glowColorOverride); + display.setInterpolationDuration(interpolationDuration); + display.setInterpolationDelay(interpolationDelay); + try { + display.setTeleportDuration(teleportDuration); + } catch (Throwable ignored) { + } } /** @@ -79,8 +89,12 @@ public static DisplayData of(ConfigurationSection section) { int b = Integer.parseInt(split[2]); color = Color.fromRGB(r, g, b); } + int interpolationDuration = section.getInt("Interpolation-Duration", 1); + int interpolationDelay = section.getInt("Interpolation-Delay", 0); + int teleportDuration = section.getInt("Teleport-Duration", 1); return new DisplayData(brightness, billboard, shadowRadius, shadowStrength, - viewRange, displayWidth, displayHeight, color, applyBrightness); + viewRange, displayWidth, displayHeight, color, applyBrightness, + interpolationDuration, interpolationDelay, teleportDuration); } /** diff --git a/src/main/java/us/mytheria/bloblib/entities/display/DisplayOperator.java b/src/main/java/us/mytheria/bloblib/entities/display/DisplayOperator.java new file mode 100644 index 00000000..078827cc --- /dev/null +++ b/src/main/java/us/mytheria/bloblib/entities/display/DisplayOperator.java @@ -0,0 +1,39 @@ +package us.mytheria.bloblib.entities.display; + +import org.bukkit.entity.Display; +import org.bukkit.util.Transformation; +import org.jetbrains.annotations.NotNull; +import us.mytheria.bloblib.entities.BukkitPluginOperator; + +/** + * Represents an object that can hold Display entities + * using initial displayData and a transformation. + */ +public interface DisplayOperator extends BukkitPluginOperator { + + /** + * The initial DisplayData held by this DisplayOperator. + * + * @return The initial DisplayData held by this DisplayOperator. + */ + DisplayData getDisplayData(); + + /** + * The initial transformation held by this DisplayOperator. + * + * @return The initial transformation held by this DisplayOperator. + */ + Transformation getTransformation(); + + /** + * Applies the DisplayData and Transformation to the given Display. + * + * @param display the Display to apply the DisplayData and Transformation to + */ + default void apply(@NotNull Display display) { + if (getDisplayData() != null) + getDisplayData().apply(display); + if (getTransformation() != null) + display.setTransformation(getTransformation()); + } +} diff --git a/src/main/java/us/mytheria/bloblib/entities/display/DisplayOperatorReader.java b/src/main/java/us/mytheria/bloblib/entities/display/DisplayOperatorReader.java new file mode 100644 index 00000000..75ca92e7 --- /dev/null +++ b/src/main/java/us/mytheria/bloblib/entities/display/DisplayOperatorReader.java @@ -0,0 +1,40 @@ +package us.mytheria.bloblib.entities.display; + +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.util.Transformation; + +public class DisplayOperatorReader { + + public static DisplayOperator READ(ConfigurationSection section, String path, JavaPlugin plugin) { + DisplayData displayData; + try { + displayData = DisplayData.of(section); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException(e.getMessage() + " in file " + path); + } + Transformation transformation; + try { + transformation = DisplayReader.TRANSFORMATION_FAIL_FAST(section); + } catch (Exception e) { + throw new IllegalArgumentException(e.getMessage() + " in file " + path); + } + return new DisplayOperator() { + @Override + public DisplayData getDisplayData() { + return displayData; + } + + @Override + public Transformation getTransformation() { + return transformation; + } + + @Override + public Plugin getPlugin() { + return plugin; + } + }; + } +}