diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d493ce1..4d8c3df 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,7 +5,14 @@
+
+
+
+
+
+
+
@@ -34,37 +41,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -106,51 +83,51 @@
- {
- "keyToString": {
- "Downloaded.Files.Path.Enabled": "false",
- "Gradle.Build EntityLib.executor": "Run",
- "Gradle.EntityLib [dependencies].executor": "Run",
- "Gradle.EntityLib [publish].executor": "Run",
- "Gradle.EntityLib [runServer] (1).executor": "Run",
- "Gradle.EntityLib [runServer].executor": "Run",
- "Gradle.EntityLib:code-gen [:code-gen:Main.main()].executor": "Run",
- "Gradle.EntityLib:test-plugin [cleanAllRunTaskCaches].executor": "Run",
- "Gradle.EntityLib:test-plugin [cleanCustomServiceCaches].executor": "Run",
- "Gradle.EntityLib:test-plugin [cleanPaperCache].executor": "Run",
- "Gradle.EntityLib:test-plugin [cleanPaperPluginsCache].executor": "Run",
- "Gradle.EntityLib:test-plugin [publish].executor": "Run",
- "Gradle.EntityLib:test-plugin [runServer].executor": "Run",
- "Gradle.EntityLib:test-plugin [shadowJar].executor": "Run",
- "JAR Application.Unnamed.executor": "Run",
- "Repository.Attach.Annotations": "false",
- "Repository.Attach.JavaDocs": "false",
- "Repository.Attach.Sources": "false",
- "RunOnceActivity.OpenProjectViewOnStart": "true",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "WebServerToolWindowFactoryState": "false",
- "git-widget-placeholder": "master",
- "ignore.virus.scanning.warn.message": "true",
- "jdk.selected.JAVA_MODULE": "corretto-17",
- "kotlin-language-version-configured": "true",
- "last_opened_file_path": "/home/tofaa/Github/EntityLib/model-engine-addon",
- "node.js.detected.package.eslint": "true",
- "node.js.detected.package.tslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "node.js.selected.package.tslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "project.structure.last.edited": "Modules",
- "project.structure.proportion": "0.15",
- "project.structure.side.proportion": "0.2",
- "settings.editor.selected.configurable": "preferences.editor",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
@@ -313,8 +290,8 @@
-
-
+
+
@@ -408,6 +385,7 @@
+
@@ -428,7 +406,7 @@
file://$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/LegacyHologram.java
- 33
+ 42
diff --git a/api/src/main/java/me/tofaa/entitylib/utils/Check.java b/api/src/main/java/me/tofaa/entitylib/utils/Check.java
index 82816ea..478ed49 100644
--- a/api/src/main/java/me/tofaa/entitylib/utils/Check.java
+++ b/api/src/main/java/me/tofaa/entitylib/utils/Check.java
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.text.MessageFormat;
+import java.util.List;
import java.util.Objects;
/**
@@ -14,6 +15,18 @@ public final class Check {
private Check() {}
+
+ public static void arrayLength(List lines, int index, T e) {
+ if (index >= lines.size()) {
+ for (int i = lines.size(); i < index; i++) {
+ lines.add(null);
+ }
+ lines.add(e);
+ }
+ else {lines.set(index, e);
+ }
+ }
+
@Contract("null, _ -> fail")
public static void notNull(@Nullable Object object, @NotNull String reason) {
if (Objects.isNull(object)) {
diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/Hologram.java b/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/Hologram.java
index 88ab529..2327d08 100644
--- a/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/Hologram.java
+++ b/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/Hologram.java
@@ -1,5 +1,6 @@
package me.tofaa.entitylib.wrapper.hologram;
+import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.protocol.world.Location;
import me.tofaa.entitylib.meta.display.TextDisplayMeta;
import net.kyori.adventure.text.Component;
@@ -7,24 +8,26 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
+import java.util.UUID;
import java.util.function.Consumer;
-public interface Hologram {
+public interface Hologram {
- static Hologram.@NotNull Legacy legacy(@NotNull Location location) {
- return new LegacyHologram<>(location);
+ static Hologram.@NotNull Legacy legacy(@NotNull Location location) {
+ return new LegacyHologram(location);
}
- static Hologram.@NotNull Legacy legacy(@NotNull Location location, List lines) {
- return new LegacyHologram<>(location, lines);
+ static Hologram.@NotNull Legacy legacy(@NotNull Location location, List lines) {
+ return new LegacyHologram(location, lines);
}
- static Hologram.@NotNull Modern modern(@NotNull Location location) {
- return new ModernHologram<>(location);
+
+ static Hologram.@NotNull Modern modern(@NotNull Location location) {
+ return new ModernHologram(location);
}
- static Hologram.@NotNull Modern modern(@NotNull Location location, List lines) {
- return new ModernHologram<>(location, lines);
+ static Hologram.@NotNull Modern modern(@NotNull Location location, List lines) {
+ return new ModernHologram(location, lines);
}
@NotNull Location getLocation();
@@ -44,13 +47,18 @@ public interface Hologram {
void addLine(@Nullable Component line);
- interface Modern extends Hologram {
+ void addViewer(@NotNull UUID viewer);
+ default void addViewer(@NotNull User user) {
+ addViewer(user.getUUID());
+ }
+
+ interface Modern extends Hologram {
// I got too lazy
void setModifier(@NotNull Consumer consumer);
}
- interface Legacy extends Hologram {
+ interface Legacy extends Hologram {
float getLineOffset(boolean marker);
diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/LegacyHologram.java b/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/LegacyHologram.java
index c501a3d..4062f21 100644
--- a/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/LegacyHologram.java
+++ b/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/LegacyHologram.java
@@ -4,6 +4,7 @@ import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.world.Location;
import me.tofaa.entitylib.EntityLib;
import me.tofaa.entitylib.meta.other.ArmorStandMeta;
+import me.tofaa.entitylib.utils.Check;
import me.tofaa.entitylib.wrapper.WrapperEntity;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
@@ -11,11 +12,12 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
+import java.util.UUID;
-final class LegacyHologram implements Hologram.Legacy {
+final class LegacyHologram implements Hologram.Legacy {
private Location location;
- private List lines = new ArrayList<>(3);
+ private final List lines = new ArrayList<>(3);
private float lineOffset = -0.9875f;
private float markerOffset = -0.40625f;
private boolean marker;
@@ -31,6 +33,13 @@ final class LegacyHologram implements Hologram.Legacy {
}
}
+ @Override
+ public void addViewer(@NotNull UUID viewer) {
+ for (WrapperEntity line : lines) {
+ line.addViewer(viewer);
+ }
+ }
+
@Override
public boolean isMarker() {
return marker;
@@ -95,7 +104,7 @@ final class LegacyHologram implements Hologram.Legacy {
meta.setHasNoGravity(true);
meta.setSmall(true);
meta.setMarker(marker);
- this.lines.set(index, e);
+ Check.arrayLength(lines, index, e);
e.spawn(location);
teleport(location);
}
diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/ModernHologram.java b/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/ModernHologram.java
index c8ebb75..110af16 100644
--- a/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/ModernHologram.java
+++ b/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/ModernHologram.java
@@ -4,6 +4,7 @@ import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.world.Location;
import me.tofaa.entitylib.EntityLib;
import me.tofaa.entitylib.meta.display.TextDisplayMeta;
+import me.tofaa.entitylib.utils.Check;
import me.tofaa.entitylib.wrapper.WrapperEntity;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
@@ -11,13 +12,15 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
+import java.util.UUID;
import java.util.function.Consumer;
-final class ModernHologram implements Hologram.Modern {
+final class ModernHologram implements Hologram.Modern {
private Location location;
- private List lines = new ArrayList<>(3);
+ private final List lines = new ArrayList<>(3);
private Consumer modifier;
+ private boolean spawned = false;
ModernHologram(@NotNull Location location) {
this.location = location;
@@ -36,6 +39,7 @@ final class ModernHologram implements Hologram.Modern {
line.spawn(location);
}
teleport(location);
+ spawned = true;
}
@Override
@@ -43,6 +47,7 @@ final class ModernHologram implements Hologram.Modern {
for (WrapperEntity line : lines) {
line.despawn();
}
+ spawned = false;
}
@Override
@@ -72,10 +77,14 @@ final class ModernHologram implements Hologram.Modern {
meta.setInvisible(true);
meta.setHasNoGravity(true);
meta.setText(line);
- this.modifier.accept(meta);
- this.lines.set(index, e);
- e.spawn(location);
- teleport(location);
+ if (this.modifier != null) {
+ this.modifier.accept(meta);
+ }
+ Check.arrayLength(lines, index, e);
+ if (spawned) {
+ e.spawn(location);
+ teleport(location);
+ }
}
@Override
@@ -83,6 +92,13 @@ final class ModernHologram implements Hologram.Modern {
setLine(lines.size(), line);
}
+ @Override
+ public void addViewer(@NotNull UUID viewer) {
+ for (WrapperEntity line : lines) {
+ line.addViewer(viewer);
+ }
+ }
+
@Override
public int length() {
diff --git a/test-plugin/build.gradle b/test-plugin/build.gradle
index 4d089d7..7552bc9 100644
--- a/test-plugin/build.gradle
+++ b/test-plugin/build.gradle
@@ -34,7 +34,7 @@ dependencies {
compileOnly('org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT')
compileOnly('com.github.retrooper.packetevents:spigot:2.3.0')
// implementation(project(":platforms:spigot"))
- implementation("com.github.Tofaa2.EntityLib:spigot:2.2.0-SNAPSHOT")
+ implementation(project(":platforms:spigot"))
}
diff --git a/test-plugin/src/main/java/me/tofaa/testentitylib/TestEntityLibPlugin.java b/test-plugin/src/main/java/me/tofaa/testentitylib/TestEntityLibPlugin.java
index c8baf17..415de2d 100644
--- a/test-plugin/src/main/java/me/tofaa/testentitylib/TestEntityLibPlugin.java
+++ b/test-plugin/src/main/java/me/tofaa/testentitylib/TestEntityLibPlugin.java
@@ -42,6 +42,7 @@ public class TestEntityLibPlugin extends JavaPlugin {
commandMap = (CommandMap) Bukkit.getServer().getClass().getMethod("getCommandMap").invoke(Bukkit.getServer());
commandMap.register("testapi", new TestTextDisplayCommand());
commandMap.register("testplayer", new TestPlayerCommand());
+ commandMap.register("testholo", new TestHologramsCommand());
}
catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
diff --git a/test-plugin/src/main/java/me/tofaa/testentitylib/TestHologramsCommand.java b/test-plugin/src/main/java/me/tofaa/testentitylib/TestHologramsCommand.java
new file mode 100644
index 0000000..6ee8f0d
--- /dev/null
+++ b/test-plugin/src/main/java/me/tofaa/testentitylib/TestHologramsCommand.java
@@ -0,0 +1,48 @@
+package me.tofaa.testentitylib;
+
+import io.github.retrooper.packetevents.util.SpigotConversionUtil;
+import me.tofaa.entitylib.wrapper.hologram.Hologram;
+import net.kyori.adventure.text.Component;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.defaults.BukkitCommand;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class TestHologramsCommand extends BukkitCommand {
+
+
+ TestHologramsCommand () {
+ super("testholo");
+ }
+
+ @Override
+ public boolean execute(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) {
+ if (strings.length == 0) {
+ commandSender.sendMessage("Usage: /testholo ");
+ return true;
+ }
+ Player player = (Player) commandSender;
+ if (strings[0].equalsIgnoreCase("modern")) {
+ Hologram.Modern holo =Hologram.modern(SpigotConversionUtil.fromBukkitLocation(player.getLocation()));
+ holo.addLine(Component.text("Hello, World!"));
+ holo.show();
+ holo.addViewer(player.getUniqueId());
+ }
+ if (strings[0].equalsIgnoreCase("legacy")) {
+ Hologram.Legacy holo = Hologram.legacy(SpigotConversionUtil.fromBukkitLocation(player.getLocation()));
+ holo.addLine(Component.text("Hello, World!"));
+ holo.show();
+ holo.addViewer(player.getUniqueId());
+ }
+ return true;
+ }
+
+ @NotNull
+ @Override
+ public List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
+ return Arrays.asList("legacy", "modern");
+ }
+}