diff --git a/README.MD b/README.MD
index 934f865..9f8eba6 100644
--- a/README.MD
+++ b/README.MD
@@ -4,7 +4,7 @@
HoloEasy is a simple, modern and high-performant Java and Kotlin Minecraft Hologram library for 1.8-1.20.4 servers.
-
+
## Quickstart
@@ -78,7 +78,7 @@ fun addHologram(location: Location) {
From 3.1.0 version, the parameters of text lines and item lines **_can also be reactive_**. This means that you can update the line by simply calling the 'set' method to these.
-
+
> [!WARNING]
diff --git a/api/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketD.kt b/api/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketD.kt
new file mode 100644
index 0000000..60093ad
--- /dev/null
+++ b/api/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketD.kt
@@ -0,0 +1,47 @@
+package org.holoeasy.packet.metadata.item
+
+import com.comphenix.protocol.PacketType
+import com.comphenix.protocol.events.PacketContainer
+import com.comphenix.protocol.utility.MinecraftVersion
+import com.comphenix.protocol.wrappers.WrappedChatComponent
+import com.comphenix.protocol.wrappers.WrappedDataValue
+import com.comphenix.protocol.wrappers.WrappedDataWatcher
+import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject
+import com.google.common.collect.Lists
+import org.bukkit.inventory.ItemStack
+import org.holoeasy.ext.bukkitGeneric
+import org.holoeasy.ext.parse119
+import org.holoeasy.ext.setBool
+import org.holoeasy.util.BOOL_SERIALIZER
+import org.holoeasy.util.ITEM_SERIALIZER
+import org.holoeasy.util.VersionEnum
+import java.util.*
+
+
+object MetadataItemPacketD : IMetadataItemPacket {
+ override val versionSupport: Array>
+ get() = arrayOf(VersionEnum.V1_19..VersionEnum.V1_19)
+
+ override fun metadata(entityId: Int, item: ItemStack): PacketContainer {
+ val packet = PacketContainer(PacketType.Play.Server.ENTITY_METADATA)
+ packet.integers.write(0, entityId)
+
+ val watcher = WrappedDataWatcher()
+
+ val gravity = WrappedDataWatcherObject(
+ 5, BOOL_SERIALIZER
+ )
+ watcher.setObject(gravity,true)
+
+ val itemSer = WrappedDataWatcherObject(
+ 8, ITEM_SERIALIZER
+ )
+ watcher.setObject(itemSer, item.bukkitGeneric())
+
+ // https://www.spigotmc.org/threads/unable-to-modify-entity-metadata-packet-using-protocollib-1-19-3.582442/#post-4517187
+ packet.parse119(watcher)
+
+ return packet
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/metadata/item/MetadataItemPacketD.kt b/api/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketE.kt
similarity index 89%
rename from src/main/java/org/holoeasy/packet/metadata/item/MetadataItemPacketD.kt
rename to api/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketE.kt
index 8f84721..1f9a9e8 100644
--- a/src/main/java/org/holoeasy/packet/metadata/item/MetadataItemPacketD.kt
+++ b/api/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketE.kt
@@ -10,9 +10,9 @@ import org.holoeasy.util.ITEM_SERIALIZER
import org.holoeasy.util.VersionEnum
-object MetadataItemPacketD : IMetadataItemPacket {
+object MetadataItemPacketE : IMetadataItemPacket {
override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_20..VersionEnum.V1_20)
+ get() = arrayOf(VersionEnum.V1_19..VersionEnum.V1_20)
override fun metadata(entityId: Int, item: ItemStack): PacketContainer {
val packet = PacketContainer(PacketType.Play.Server.ENTITY_METADATA)
diff --git a/src/main/java/org/holoeasy/packet/metadata/text/MetadataTextPacketC.kt b/api/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketD.kt
similarity index 60%
rename from src/main/java/org/holoeasy/packet/metadata/text/MetadataTextPacketC.kt
rename to api/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketD.kt
index 265874f..d447c72 100644
--- a/src/main/java/org/holoeasy/packet/metadata/text/MetadataTextPacketC.kt
+++ b/api/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketD.kt
@@ -3,18 +3,18 @@ package org.holoeasy.packet.metadata.text
import com.comphenix.protocol.PacketType
import com.comphenix.protocol.events.PacketContainer
import com.comphenix.protocol.wrappers.WrappedDataWatcher
-import org.holoeasy.ext.set
-import org.holoeasy.ext.setBool
-import org.holoeasy.ext.setByte
-import org.holoeasy.ext.setChatComponent
+import org.holoeasy.ext.*
import org.holoeasy.packet.packet
import org.holoeasy.util.VersionEnum
-object MetadataTextPacketC : IMetadataTextPacket {
+object MetadataTextPacketD : IMetadataTextPacket {
override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_13..VersionEnum.V1_19)
+ get() = arrayOf(VersionEnum.V1_19..VersionEnum.V1_19)
override fun metadata(entityId: Int, nameTag: String?, invisible : Boolean): PacketContainer {
+ val packet = PacketContainer(PacketType.Play.Server.ENTITY_METADATA)
+ packet.integers.write(0, entityId)
+
val watcher = WrappedDataWatcher()
if(invisible)
@@ -24,10 +24,11 @@ object MetadataTextPacketC : IMetadataTextPacket {
watcher.setChatComponent(2, nameTag)
watcher.setBool(3, true)
}
- return packet(PacketType.Play.Server.ENTITY_METADATA) {
- integers[0] = entityId
- watchableCollectionModifier[0] = watcher.watchableObjects
- }
+
+ // https://www.spigotmc.org/threads/unable-to-modify-entity-metadata-packet-using-protocollib-1-19-3.582442/#post-4517187
+ packet.parse119(watcher)
+
+ return packet
}
diff --git a/src/main/java/org/holoeasy/packet/metadata/text/MetadataTextPacketD.kt b/api/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketE.kt
similarity index 97%
rename from src/main/java/org/holoeasy/packet/metadata/text/MetadataTextPacketD.kt
rename to api/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketE.kt
index 297dac5..8938480 100644
--- a/src/main/java/org/holoeasy/packet/metadata/text/MetadataTextPacketD.kt
+++ b/api/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketE.kt
@@ -10,7 +10,7 @@ import org.holoeasy.util.BYTE_SERIALIZER
import org.holoeasy.util.VersionEnum
import java.util.*
-object MetadataTextPacketD : IMetadataTextPacket {
+object MetadataTextPacketE : IMetadataTextPacket {
override val versionSupport: Array>
get() = arrayOf(VersionEnum.V1_20..VersionEnum.V1_20)
diff --git a/build.gradle.kts b/build.gradle.kts
new file mode 100644
index 0000000..c27a1de
--- /dev/null
+++ b/build.gradle.kts
@@ -0,0 +1,20 @@
+plugins {
+ kotlin("jvm") version "1.9.21"
+}
+
+group = "org.holoeasy"
+version = "3.1.1"
+
+repositories {
+}
+
+dependencies {
+ testImplementation("org.jetbrains.kotlin:kotlin-test")
+}
+
+tasks.test {
+ useJUnitPlatform()
+}
+kotlin {
+ jvmToolchain(8)
+}
\ No newline at end of file
diff --git a/example-plugin/src/main/java/org/holoeasy/plugin/ExamplePlugin.java b/example-plugin/src/main/java/org/holoeasy/plugin/ExamplePlugin.java
new file mode 100644
index 0000000..7b15d3d
--- /dev/null
+++ b/example-plugin/src/main/java/org/holoeasy/plugin/ExamplePlugin.java
@@ -0,0 +1,36 @@
+package org.holoeasy.plugin;
+
+
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.holoeasy.HoloEasy;
+import org.holoeasy.config.HologramKey;
+import org.holoeasy.pool.IHologramPool;
+import org.holoeasy.reactive.MutableState;
+import org.jetbrains.annotations.NotNull;
+import static org.holoeasy.builder.HologramBuilder.*;
+public class ExamplePlugin extends JavaPlugin {
+
+ @Override
+ public void onEnable() {
+ IHologramPool pool = HoloEasy.startInteractivePool(this, 60, 0.5f, 5f);
+ getCommand("hologram").setExecutor((sender, cmd, s, args) -> {
+
+ Player player = (Player) sender;
+ MutableState clickCount = mutableStateOf(0); // can be any type
+
+ hologram(new HologramKey(pool, "unique-id-holo"), player.getLocation(), () -> {
+ textline("Hello");
+ textline("Count {}", clickCount);
+ clickable("Click me").onClick(p -> clickCount.set(clickCount.get() + 1));
+ item(new ItemStack(Material.APPLE));
+ });
+
+ return true;
+ });
+ }
+
+
+}
diff --git a/example-plugin/src/main/resources/plugin.yml b/example-plugin/src/main/resources/plugin.yml
new file mode 100644
index 0000000..1516954
--- /dev/null
+++ b/example-plugin/src/main/resources/plugin.yml
@@ -0,0 +1,7 @@
+name: ExamplePlugin
+main: org.holoeasy.plugin.ExamplePlugin
+version: 1.0
+depend: [ProtocolLib]
+api-version: 1.8
+commands:
+ hologram:
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index 5450c8b..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,176 +0,0 @@
-
-
-
-
- 4.0.0
-
- org.holoeasy
- holoeasy
- 3.1.0
-
-
- 1.8
- 1.8
-
-
-
-
- dmulloy2-repo
- https://repo.dmulloy2.net/repository/public/
-
-
- placeholderapi
- https://repo.extendedclip.com/content/repositories/placeholderapi/
-
-
-
- papermc
- https://repo.papermc.io/repository/maven-public/
-
-
-
-
-
- com.comphenix.protocol
- ProtocolLib
- 5.1.0
- provided
-
-
- org.spigotmc
- spigot-api
- 1.16.5-R0.1-SNAPSHOT
- provided
-
-
- org.jetbrains.kotlin
- kotlin-stdlib
- 1.9.21
- compile
-
-
- org.jetbrains
- annotations
- 24.0.1
- provided
-
-
- me.clip
- placeholderapi
- 2.11.3
- provided
-
-
-
-
-
- src/main/java
- src/test/kotlin
-
-
- org.jetbrains.kotlin
- kotlin-maven-plugin
- 1.9.21
-
-
- compile
- process-sources
-
- compile
-
-
-
- test-compile
- test-compile
-
- test-compile
-
-
-
-
-
-
-
-
-
-
-
-
- maven-surefire-plugin
- 2.22.2
-
-
- maven-failsafe-plugin
- 2.22.2
-
-
- org.codehaus.mojo
- exec-maven-plugin
- 1.6.0
-
- MainKt
-
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- 3.3.0
-
- C:\Users\mehil\OneDrive\Desktop\Spigot 1.16.5\plugins
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-shade-plugin
- 3.2.4
-
-
-
- kotlin.
- org.holoeasy.shaded.kotlin.
-
-
-
-
-
- package
-
- shade
-
-
-
-
-
-
-
diff --git a/gif.gif b/preview/gif.gif
similarity index 100%
rename from gif.gif
rename to preview/gif.gif
diff --git a/state.gif b/preview/state.gif
similarity index 100%
rename from state.gif
rename to preview/state.gif
diff --git a/src/main/java/org/holoeasy/HoloEasy.kt b/src/main/java/org/holoeasy/HoloEasy.kt
deleted file mode 100644
index b5d14b4..0000000
--- a/src/main/java/org/holoeasy/HoloEasy.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.holoeasy
-
-
-import org.bukkit.plugin.Plugin
-import org.holoeasy.pool.HologramPool
-import org.holoeasy.pool.IHologramPool
-import org.holoeasy.pool.InteractiveHologramPool
-
-object HoloEasy {
-
- @JvmField
- var useLastSupportedVersion: Boolean = false
-
- @JvmStatic
- fun startPool(plugin: Plugin, spawnDistance: Double): IHologramPool {
- val simplepool = HologramPool(plugin, spawnDistance)
- return simplepool
- }
-
- @JvmStatic
- fun startInteractivePool(
- plugin: Plugin, spawnDistance: Double,
- minHitDistance: Float, maxHitDistance: Float
- ): IHologramPool {
- val simplepool = HologramPool(plugin, spawnDistance)
- val interactivepool = InteractiveHologramPool(simplepool, minHitDistance, maxHitDistance)
- return interactivepool
- }
-
-
-}
diff --git a/src/main/java/org/holoeasy/builder/HologramBuilder.java b/src/main/java/org/holoeasy/builder/HologramBuilder.java
deleted file mode 100644
index c51c222..0000000
--- a/src/main/java/org/holoeasy/builder/HologramBuilder.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package org.holoeasy.builder;
-
-import org.holoeasy.builder.interfaces.HologramConfigGroup;
-import org.holoeasy.builder.interfaces.HologramSetupGroup;
-import org.holoeasy.config.HologramKey;
-import org.bukkit.Location;
-import org.bukkit.inventory.ItemStack;
-import org.holoeasy.hologram.Hologram;
-import org.holoeasy.line.ILine;
-import org.holoeasy.line.ITextLine;
-import org.holoeasy.pool.IHologramPool;
-import org.holoeasy.reactive.MutableState;
-import org.jetbrains.annotations.NotNull;
-
-public class HologramBuilder {
-
- static Service getInstance() {
- return Service.INSTANCE;
- }
-
- public static Hologram hologram(
- @NotNull HologramKey key, @NotNull Location location, @NotNull HologramSetupGroup setupGroup) {
- HologramConfig holoConfig = new HologramConfig(key, location);
- getInstance().getStaticHologram().set(holoConfig);
- setupGroup.setup();
- getInstance().getStaticHologram().remove();
-
- Hologram holo = new Hologram(key, holoConfig.location, holoConfig.loader);
- holo.load(holoConfig.lines.toArray(new ILine[0]));
- return holo;
- }
-
- public static void config(@NotNull HologramConfigGroup configGroup) {
- getInstance().config(configGroup);
- }
-
-
- public static void textline(@NotNull String text, @NotNull Object... args) {
- getInstance().textline(
- text,
- false,
- null,
- null,
- args.length == 0 ? null : args
- );
- }
-
- public static ITextLine clickable(@NotNull String text, @NotNull Object... args) {
- return getInstance().textline(
- text,
- true,
- null,
- null,
- args.length == 0 ? null : args
-
- );
- }
-
- public static ITextLine clickable(@NotNull String text, float minHitDistance, float maxHitDistance,
- @NotNull Object... args) {
- return getInstance().textline(
- text,
- true,
- minHitDistance,
- maxHitDistance,
- args.length == 0 ? null : args
- );
- }
-
- public static void item(@NotNull ItemStack block) {
- getInstance().itemline(block);
- }
-
- public static void item(@NotNull MutableState block) {
- getInstance().itemline(block);
- }
-
- public static void customline(@NotNull ILine> customLine) {
- getInstance().customLine(customLine);
- }
-
- public static MutableState mutableStateOf(@NotNull T initialValue) {
- return new MutableState<>(initialValue);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/builder/HologramConfig.java b/src/main/java/org/holoeasy/builder/HologramConfig.java
deleted file mode 100644
index 36089a3..0000000
--- a/src/main/java/org/holoeasy/builder/HologramConfig.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.holoeasy.builder;
-
-import org.holoeasy.config.HologramKey;
-import org.bukkit.Location;
-import org.holoeasy.hologram.IHologramLoader;
-import org.holoeasy.hologram.TextBlockStandardLoader;
-import org.holoeasy.line.ILine;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-public class HologramConfig {
-
- @NotNull
- final HologramKey key;
- @NotNull
- final Location location;
- final List> lines = new ArrayList<>();
- public IHologramLoader loader = new TextBlockStandardLoader();
-
- HologramConfig(@NotNull HologramKey key, @NotNull Location location) {
- this.key = key;
- this.location = location;
- }
-
-
-}
diff --git a/src/main/java/org/holoeasy/builder/Service.kt b/src/main/java/org/holoeasy/builder/Service.kt
deleted file mode 100644
index 8e9e322..0000000
--- a/src/main/java/org/holoeasy/builder/Service.kt
+++ /dev/null
@@ -1,69 +0,0 @@
-package org.holoeasy.builder
-
-
-import org.bukkit.inventory.ItemStack
-import org.holoeasy.builder.interfaces.HologramConfigGroup
-import org.holoeasy.hologram.TextBlockStandardLoader
-import org.holoeasy.line.*
-import org.holoeasy.reactive.MutableState
-import kotlin.math.min
-
-object Service {
-
- val staticHologram: ThreadLocal = ThreadLocal()
-
- private fun getStaticHolo(): HologramConfig {
- val holo = staticHologram.get() ?: throw RuntimeException("You must call config() inside hologram block")
- return holo
- }
-
- fun config(configGroup: HologramConfigGroup) {
- val config = getStaticHolo()
-
- configGroup.configure(config)
-
-
- config.loader = config.loader ?: TextBlockStandardLoader()
- }
-
- @JvmOverloads
- fun textline(
- text: String, clickable: Boolean = false, minHitDistance: Float? = null,
- maxHitDistance: Float? = null, args: Array<*>? = null
- ) : ITextLine {
- val holo = getStaticHolo()
-
- if (minHitDistance == null || maxHitDistance == null) {
- if(holo.key.pool == null && clickable) {
- throw IllegalStateException("This hologram is not in a pool,so use the method #clickable(text, minHitDistance, maxHitDistance)")
- }
-
- val textLine = TextLine(holo.key.plugin, text, clickable = clickable, args = args)
- holo.lines.add(textLine)
- return textLine
-
- }
- val textLine = TextLine(holo.key.plugin, text, clickable = false, args = args)
- val clickableTextLine = ClickableTextLine(textLine, minHitDistance, maxHitDistance)
- holo.lines.add(clickableTextLine)
- return clickableTextLine
- }
-
- fun itemline(block: ItemStack) {
- val holo = getStaticHolo()
- val blockline = BlockLine(holo.key.plugin, block)
- holo.lines.add(blockline)
- }
-
- fun itemline(block: MutableState) {
- val holo = getStaticHolo()
- val blockline = BlockLine(holo.key.plugin, block)
- holo.lines.add(blockline)
- }
-
- fun customLine(customLine: ILine<*>) {
- val holo = getStaticHolo()
- holo.lines.add(customLine)
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/builder/interfaces/HologramConfigGroup.java b/src/main/java/org/holoeasy/builder/interfaces/HologramConfigGroup.java
deleted file mode 100644
index d56646b..0000000
--- a/src/main/java/org/holoeasy/builder/interfaces/HologramConfigGroup.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.holoeasy.builder.interfaces;
-
-import org.holoeasy.builder.HologramConfig;
-import org.jetbrains.annotations.NotNull;
-
-@FunctionalInterface
-public interface HologramConfigGroup {
- void configure(@NotNull HologramConfig context);
-}
diff --git a/src/main/java/org/holoeasy/builder/interfaces/HologramSetupGroup.java b/src/main/java/org/holoeasy/builder/interfaces/HologramSetupGroup.java
deleted file mode 100644
index 8e61aa8..0000000
--- a/src/main/java/org/holoeasy/builder/interfaces/HologramSetupGroup.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.holoeasy.builder.interfaces;
-
-@FunctionalInterface
-public interface HologramSetupGroup {
- void setup();
-
-}
diff --git a/src/main/java/org/holoeasy/config/HologramKey.java b/src/main/java/org/holoeasy/config/HologramKey.java
deleted file mode 100644
index a8535ef..0000000
--- a/src/main/java/org/holoeasy/config/HologramKey.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.holoeasy.config;
-
-import org.bukkit.plugin.Plugin;
-import org.holoeasy.pool.IHologramPool;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.Objects;
-
-public class HologramKey {
-
- private final Plugin plugin;
- private final String id;
-
- private final IHologramPool pool;
-
-
- public HologramKey(@NotNull Plugin plugin, @NotNull String id, @Nullable IHologramPool pool) {
- this.plugin = plugin;
- this.id = id;
- this.pool = pool;
- }
-
- public HologramKey(@NotNull Plugin plugin, @NotNull String id) {
- this(plugin, id, null);
- }
-
- public HologramKey(@NotNull IHologramPool pool, @NotNull String id) {
- this(pool.getPlugin(), id, pool);
- }
-
- @NotNull
- public Plugin getPlugin() {
- return plugin;
- }
-
- @NotNull
- public String getId() {
- return id;
- }
-
- @Nullable
- public IHologramPool getPool() {
- return pool;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(plugin, id, pool);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- HologramKey that = (HologramKey) o;
- return Objects.equals(plugin, that.plugin) && Objects.equals(id, that.id) && Objects.equals(pool, that.pool);
- }
-}
diff --git a/src/main/java/org/holoeasy/ext/DoubleExt.kt b/src/main/java/org/holoeasy/ext/DoubleExt.kt
deleted file mode 100644
index 651fbd2..0000000
--- a/src/main/java/org/holoeasy/ext/DoubleExt.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.holoeasy.ext
-
-import kotlin.math.floor
-
-val Double.compressAngle: Byte
- get() = (this * 256f / 360f).toInt().toByte()
-
-val Double.fixCoordinate: Int
- get() = floor(this * 32.0).toInt()
diff --git a/src/main/java/org/holoeasy/ext/ItemStackExt.kt b/src/main/java/org/holoeasy/ext/ItemStackExt.kt
deleted file mode 100644
index da025ef..0000000
--- a/src/main/java/org/holoeasy/ext/ItemStackExt.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.holoeasy.ext
-
-import com.comphenix.protocol.wrappers.BukkitConverters
-import org.bukkit.inventory.ItemStack
-
-
-fun ItemStack.bukkitGeneric() : Any {
- return BukkitConverters.getItemStackConverter().getGeneric(this)
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/ext/PacketContainerExt.kt b/src/main/java/org/holoeasy/ext/PacketContainerExt.kt
deleted file mode 100644
index f854115..0000000
--- a/src/main/java/org/holoeasy/ext/PacketContainerExt.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.holoeasy.ext
-
-import com.comphenix.protocol.ProtocolLibrary
-import com.comphenix.protocol.events.PacketContainer
-import org.bukkit.entity.Player
-
-fun PacketContainer.send(player: Player) {
- ProtocolLibrary.getProtocolManager().sendServerPacket(player, this)
-}
-
-operator fun PacketContainer.invoke(player: Player) {
- send(player)
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/ext/StructureModifierExt.kt b/src/main/java/org/holoeasy/ext/StructureModifierExt.kt
deleted file mode 100644
index 3c39ff7..0000000
--- a/src/main/java/org/holoeasy/ext/StructureModifierExt.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.holoeasy.ext
-
-import com.comphenix.protocol.reflect.StructureModifier
-
-operator fun StructureModifier.set(index: Int, value: T) {
- write(index, value)
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/ext/WrappedDataWatcherExt.kt b/src/main/java/org/holoeasy/ext/WrappedDataWatcherExt.kt
deleted file mode 100644
index e5c3317..0000000
--- a/src/main/java/org/holoeasy/ext/WrappedDataWatcherExt.kt
+++ /dev/null
@@ -1,60 +0,0 @@
-package org.holoeasy.ext
-
-import com.comphenix.protocol.wrappers.WrappedChatComponent
-import com.comphenix.protocol.wrappers.WrappedDataWatcher
-import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject
-import org.bukkit.inventory.ItemStack
-import org.holoeasy.util.BOOL_SERIALIZER
-import org.holoeasy.util.BYTE_SERIALIZER
-import org.holoeasy.util.ITEM_SERIALIZER
-import org.holoeasy.util.STRING_SERIALIZER
-import java.util.*
-
-
-fun WrappedDataWatcher.setByte(index: Int, value: Byte) {
- val obj = WrappedDataWatcherObject(
- index,
- BYTE_SERIALIZER
- )
- this.setObject(obj, value)
-}
-
-fun WrappedDataWatcher.setString(index: Int, value: String) {
- this.setObject(
- WrappedDataWatcherObject(
- index,
- STRING_SERIALIZER
- ), value
- )
-}
-
-fun WrappedDataWatcher.setBool(index: Int, value: Boolean) {
- val obj = WrappedDataWatcherObject(
- index,
- BOOL_SERIALIZER
- )
- this.setObject(obj, value)
-}
-
-fun WrappedDataWatcher.setVectorSerializer(index: Int, value: Any) {
- val obj = WrappedDataWatcherObject(
- index,
- WrappedDataWatcher.Registry.getVectorSerializer()
- )
- this.setObject(obj, value)
-}
-
-fun WrappedDataWatcher.setChatComponent(index: Int, value: String) {
- val opt: Optional<*> = Optional.of(WrappedChatComponent.fromChatMessage(value)[0].handle)
- this.setObject(
- WrappedDataWatcherObject(
- index,
- WrappedDataWatcher.Registry.getChatComponentSerializer(true)
- ), opt
- )
-}
-
-fun WrappedDataWatcher.setItemStack(index: Int, value: ItemStack) {
- val obj = WrappedDataWatcherObject(index, ITEM_SERIALIZER)
- this.setObject(obj, value.bukkitGeneric())
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/hologram/HideEvent.java b/src/main/java/org/holoeasy/hologram/HideEvent.java
deleted file mode 100644
index d789bbb..0000000
--- a/src/main/java/org/holoeasy/hologram/HideEvent.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.holoeasy.hologram;
-
-import org.bukkit.entity.Player;
-import org.jetbrains.annotations.NotNull;
-
-@FunctionalInterface
-public interface HideEvent {
-
- void onHide(@NotNull Player player);
-
-}
diff --git a/src/main/java/org/holoeasy/hologram/Hologram.kt b/src/main/java/org/holoeasy/hologram/Hologram.kt
deleted file mode 100644
index cf19c1e..0000000
--- a/src/main/java/org/holoeasy/hologram/Hologram.kt
+++ /dev/null
@@ -1,92 +0,0 @@
-package org.holoeasy.hologram
-
-import org.holoeasy.config.HologramKey
-import org.bukkit.Location
-import org.bukkit.entity.Player
-import org.holoeasy.line.ILine
-import java.util.*
-import java.util.concurrent.ConcurrentHashMap
-import java.util.concurrent.CopyOnWriteArrayList
-
-class Hologram(val key: HologramKey, location: Location, val loader: IHologramLoader) {
- init {
- key.pool?.takeCareOf(key, this)
- }
-
- var location: Location = location
- private set
-
- private val hLines: MutableList> =
- CopyOnWriteArrayList() // writes are slow and Iterators are fast and consistent.
-
- val lines: MutableList>
- get() = hLines
-
- val seeingPlayers: MutableSet = ConcurrentHashMap.newKeySet() // faster writes
-
- private var showEvent: ShowEvent? = null
- private var hideEvent : HideEvent? = null
-
- fun onShow(showEvent: ShowEvent) : Hologram {
- this.showEvent = showEvent
- return this
- }
-
- fun onHide(hideEvent: HideEvent) : Hologram {
- this.hideEvent = hideEvent
- return this
- }
-
- fun load(vararg lines: ILine<*>) {
- hLines.clear()
- lines.forEach { it.pvt.hologram = this }
- loader.load(this, lines)
- }
-
- fun teleport(to: Location) {
- this.location = to.clone()
- loader.teleport(this)
- }
-
- fun isShownFor(player: Player): Boolean {
- return seeingPlayers.contains(player)
- }
-
- fun show(player: Player) {
- seeingPlayers.add(player)
- for (line in this.hLines) {
- line.show(player)
- }
-
- showEvent?.onShow(player)
- }
-
- fun hide(player: Player) {
- for (line in this.hLines) {
- line.hide(player)
- }
- seeingPlayers.remove(player)
-
- hideEvent?.onHide(player)
- }
-
- override fun hashCode(): Int {
- return key.hashCode()
- }
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
- if (other == null || javaClass != other.javaClass) {
- return false
- }
- val hologram = other as Hologram
-
- return Objects.equals(key, hologram.key)
- }
-
- override fun toString(): String {
- return "Hologram[key=${key.id}]"
- }
-}
diff --git a/src/main/java/org/holoeasy/hologram/IHologramLoader.kt b/src/main/java/org/holoeasy/hologram/IHologramLoader.kt
deleted file mode 100644
index 5de7083..0000000
--- a/src/main/java/org/holoeasy/hologram/IHologramLoader.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.holoeasy.hologram
-
-import org.holoeasy.line.ILine
-
-
-interface IHologramLoader {
- fun load(hologram: Hologram, lines: Array>)
-
- fun teleport(hologram: Hologram)
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/hologram/ShowEvent.java b/src/main/java/org/holoeasy/hologram/ShowEvent.java
deleted file mode 100644
index 89d8e33..0000000
--- a/src/main/java/org/holoeasy/hologram/ShowEvent.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.holoeasy.hologram;
-
-import org.bukkit.entity.Player;
-import org.jetbrains.annotations.NotNull;
-
-@FunctionalInterface
-public interface ShowEvent {
-
- void onShow(@NotNull Player player);
-
-}
diff --git a/src/main/java/org/holoeasy/hologram/SingletonLoader.kt b/src/main/java/org/holoeasy/hologram/SingletonLoader.kt
deleted file mode 100644
index df7c8d0..0000000
--- a/src/main/java/org/holoeasy/hologram/SingletonLoader.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.holoeasy.hologram
-
-import org.holoeasy.line.ILine
-
-
-class SingletonLoader : IHologramLoader {
- override fun load(hologram: Hologram, lines: Array>) {
- if (lines.size > 1) {
- throw RuntimeException("Hologram '${hologram.key}' has more than 1 line.")
- }
-
- val cloned = hologram.location.clone()
-
- val line: ILine<*> = lines[0]
-
- line.setLocation(cloned)
- hologram.lines.add(line)
- }
-
- override fun teleport(hologram: Hologram) {
- val line: ILine<*> = hologram.lines[0]
-
- line.setLocation(hologram.location.clone())
- hologram.seeingPlayers.forEach(line::teleport)
- }
-}
diff --git a/src/main/java/org/holoeasy/hologram/TextBlockStandardLoader.kt b/src/main/java/org/holoeasy/hologram/TextBlockStandardLoader.kt
deleted file mode 100644
index 58423b7..0000000
--- a/src/main/java/org/holoeasy/hologram/TextBlockStandardLoader.kt
+++ /dev/null
@@ -1,90 +0,0 @@
-package org.holoeasy.hologram
-
-import org.holoeasy.line.ILine
-import kotlin.math.abs
-
-class TextBlockStandardLoader : IHologramLoader {
- override fun load(hologram: Hologram, lines: Array>) {
- val cloned = hologram.location.clone()
-
- if (lines.size == 1) {
- val line: ILine<*> = lines[0]
-
- line.setLocation(cloned)
- hologram.lines.add(line)
- return
- }
-
- // reverse A - B - C to C - B - A
- lines.reverse()
-
- cloned.subtract(0.0, 0.28, 0.0)
-
- for (j in lines.indices) {
- val line: ILine<*> = lines[j]
- var up = 0.28
-
- if (j > 0) {
- val before: ILine.Type = lines[j - 1].type
- when (before) {
- ILine.Type.BLOCK_LINE -> up = -1.5
- ILine.Type.EXTERNAL -> {}
- ILine.Type.TEXT_LINE -> {}
- ILine.Type.CLICKABLE_TEXT_LINE -> {}
- }
- }
-
- when (line.type) {
- ILine.Type.TEXT_LINE, ILine.Type.CLICKABLE_TEXT_LINE -> {
- line.setLocation(cloned.add(0.0, up, 0.0).clone())
- hologram.lines.add(0, line)
- }
-
- ILine.Type.BLOCK_LINE -> {
- line.setLocation(cloned.add(0.0, 0.6, 0.0).clone())
- hologram.lines.add(0, line)
- }
-
- else -> throw RuntimeException("This method load does not support line type " + line.type.name)
- }
- }
- }
-
- override fun teleport(hologram: Hologram) {
- val lines: List> = hologram.lines
- val firstLine: ILine<*> = lines[0]
- // Obtain the Y position of the first line and then calculate the distance to all lines to maintain this distance
- val baseY: Double = firstLine.location?.y ?: throw RuntimeException("First line has not a location")
- // Get position Y where to teleport the first line
- var destY = (hologram.location.y - 0.28)
-
- destY += when (firstLine.type) {
- ILine.Type.TEXT_LINE, ILine.Type.CLICKABLE_TEXT_LINE -> 0.28
- else -> 0.6
- }
-
- // Teleport the first line
- this.teleportLine(hologram, destY, firstLine)
- var tempLine: ILine<*>
- for (j in 1 until lines.size) {
- tempLine = lines[j]
- /*
- Teleport from the second line onwards.
- The final height is found by adding to that of the first line the difference that was present when it was already spawned
- */
- this.teleportLine(
- hologram, destY + abs(
- baseY -
- (tempLine.location?.y ?: throw RuntimeException("Missing location of line $tempLine"))
- ), tempLine
- )
- }
- }
-
- private fun teleportLine(hologram: Hologram, destY: Double, tempLine: ILine<*>) {
- val dest = hologram.location.clone()
- dest.y = destY
- tempLine.setLocation(dest)
- hologram.seeingPlayers.forEach(tempLine::teleport)
- }
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/hologram/TextSequentialLoader.kt b/src/main/java/org/holoeasy/hologram/TextSequentialLoader.kt
deleted file mode 100644
index 7b8d445..0000000
--- a/src/main/java/org/holoeasy/hologram/TextSequentialLoader.kt
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.holoeasy.hologram
-
-
-import org.holoeasy.line.ILine
-import org.holoeasy.line.ITextLine
-import org.jetbrains.annotations.ApiStatus
-
-@ApiStatus.Experimental
-class TextSequentialLoader : IHologramLoader {
- override fun load(hologram: Hologram, lines: Array>) {
- set(hologram, lines, true)
- }
-
- override fun teleport(hologram: Hologram) {
- set(hologram, hologram.lines.toTypedArray(), false)
- // TODO: When teleporting, the holograms unexpectedly become distant. Understand why.
- }
-
- private fun set(hologram: Hologram, lines: Array>, add: Boolean) {
- val cloned = hologram.location.clone()
- for (line in lines) {
- when (line.type) {
- ILine.Type.TEXT_LINE, ILine.Type.CLICKABLE_TEXT_LINE -> {
- val tL = (line as ITextLine).textLine
-
- // add to lines
- tL.setLocation(cloned.clone())
-
- if (add) {
- hologram.lines.add(0, tL)
- } else {
- hologram.seeingPlayers.forEach { tL.teleport(it) }
- }
- cloned.z += 0.175 * tL.obj.length
- }
-
- else -> throw RuntimeException("This method load supports only TextLine & TextALine & ClickableTextLine.")
- }
- }
- }
-}
diff --git a/src/main/java/org/holoeasy/line/BlockLine.kt b/src/main/java/org/holoeasy/line/BlockLine.kt
deleted file mode 100644
index 84043aa..0000000
--- a/src/main/java/org/holoeasy/line/BlockLine.kt
+++ /dev/null
@@ -1,65 +0,0 @@
-package org.holoeasy.line
-
-
-import org.bukkit.Location
-import org.bukkit.entity.EntityType
-import org.bukkit.entity.Player
-import org.bukkit.inventory.ItemStack
-import org.bukkit.plugin.Plugin
-import org.holoeasy.ext.send
-import org.holoeasy.packet.IPacket
-import org.holoeasy.reactive.MutableState
-
-class BlockLine(plugin: Plugin, obj: MutableState) : ILine {
-
-
- private val line: Line = Line(plugin, EntityType.DROPPED_ITEM)
- private val resetVelocity = IPacket.get(IPacket.Type.VELOCITY).velocity(line.entityID, 0, 0,0)
-
- private val _mutableStateOf = obj.also { it.addObserver(pvt) }
-
- constructor(plugin: Plugin, obj: ItemStack) : this(plugin, MutableState(obj)){
- }
-
- override val plugin: Plugin
- get() = line.plugin
-
- override val type: ILine.Type
- get() = ILine.Type.BLOCK_LINE
-
- override val entityId: Int
- get() = line.entityID
-
- override val location: Location?
- get() = line.location
-
- override var obj : ItemStack
- get() = _mutableStateOf.get()
- set(value) = _mutableStateOf.set(value)
-
- override var pvt = ILine.PrivateConfig(this)
-
- override fun setLocation(value: Location) {
- line.location = value
- }
-
- override fun hide(player: Player) {
- line.destroy(player)
- }
-
- override fun teleport(player: Player) {
- line.teleport(player)
- }
-
- override fun show(player: Player) {
- line.spawn(player)
- this.update(player)
-
- resetVelocity.send(player)
- }
-
- override fun update(player: Player) {
- IPacket.get(IPacket.Type.METADATA_ITEM)
- .metadata(entityId, obj).send(player)
- }
-}
diff --git a/src/main/java/org/holoeasy/line/ClickEvent.java b/src/main/java/org/holoeasy/line/ClickEvent.java
deleted file mode 100644
index 1fe2f3f..0000000
--- a/src/main/java/org/holoeasy/line/ClickEvent.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.holoeasy.line;
-
-import org.bukkit.entity.Player;
-import org.jetbrains.annotations.NotNull;
-
-@FunctionalInterface
-public interface ClickEvent {
-
- void onClick(@NotNull Player player);
-
-}
diff --git a/src/main/java/org/holoeasy/line/ClickableTextLine.kt b/src/main/java/org/holoeasy/line/ClickableTextLine.kt
deleted file mode 100644
index db84a32..0000000
--- a/src/main/java/org/holoeasy/line/ClickableTextLine.kt
+++ /dev/null
@@ -1,127 +0,0 @@
-package org.holoeasy.line
-
-import org.bukkit.Bukkit
-import org.bukkit.Location
-import org.bukkit.entity.Player
-import org.bukkit.event.EventHandler
-import org.bukkit.event.Listener
-import org.bukkit.event.block.Action
-import org.bukkit.event.player.PlayerInteractEvent
-import org.bukkit.plugin.Plugin
-import org.holoeasy.util.AABB
-import org.holoeasy.util.AABB.Vec3D.Companion.fromLocation
-
-class ClickableTextLine(private val line: TextLine, minHitDistance: Float, maxHitDistance: Float) : Listener,
- ITextLine {
- private val minHitDistance: Float
- private val maxHitDistance: Float
- private var hitbox: AABB? = null
-
- private val playersClickable = mutableSetOf()
-
- init {
- require(!(minHitDistance < 0)) { "minHitDistance must be positive" }
- require(!(maxHitDistance > 120)) { "maxHitDistance cannot be greater than 120" }
- this.minHitDistance = minHitDistance
- this.maxHitDistance = maxHitDistance
-
- if (line.location != null) {
- this.updateHitBox()
- }
-
- Bukkit.getPluginManager().registerEvents(this, line.plugin)
- }
-
- override val clickable: Boolean
- get() = false
-
- override val textLine: TextLine
- get() = line
-
- override val args: Array<*>?
- get() = textLine.args
-
-
- override fun parse(player: Player): String {
- return line.parse(player)
- }
-
- override fun onClick(clickEvent: ClickEvent) {
- line.onClick(clickEvent)
- }
-
- override val plugin: Plugin
- get() = line.plugin
-
- override val type: ILine.Type
- get() = ILine.Type.CLICKABLE_TEXT_LINE
-
- override val entityId: Int
- get() = line.entityId
-
- override val location: Location?
- get() = line.location
-
- override var obj: String
- get() = line.obj
- set(value) {
- line.obj = value
- }
-
- override var pvt = ILine.PrivateConfig(this)
-
- override fun setLocation(value: Location) {
- line.setLocation(value)
- this.updateHitBox()
- }
-
- override fun hide(player: Player) {
- line.hide(player)
-
- playersClickable.remove(player.entityId)
- }
-
- override fun teleport(player: Player) {
- line.teleport(player)
- }
-
- override fun show(player: Player) {
- line.show(player)
-
- playersClickable.add(player.entityId)
- }
-
- override fun update(player: Player) {
- line.update(player)
- }
-
- @EventHandler
- fun handleInteract(e: PlayerInteractEvent) {
- val player = e.player
- if (e.action != Action.LEFT_CLICK_AIR) {
- return
- }
- if (hitbox == null) {
- return
- }
-
- if (!playersClickable.contains(player.entityId)) {
- return
- }
-
- val intersects = hitbox!!.intersectsRay(AABB.Ray3D(player.eyeLocation), minHitDistance, maxHitDistance) ?: return
- line.clickEvent?.onClick(player)
- }
-
- private fun updateHitBox() {
- val chars = obj.length.toDouble()
- val size = 0.105
- val dist = size * (chars / 2.0)
-
- hitbox = AABB(
- AABB.Vec3D(-dist, -0.040, -dist),
- AABB.Vec3D(dist, +0.040, dist)
- )
- hitbox!!.translate(fromLocation(location!!.clone().add(0.0, 2.35, 0.0)))
- }
-}
diff --git a/src/main/java/org/holoeasy/line/ILine.kt b/src/main/java/org/holoeasy/line/ILine.kt
deleted file mode 100644
index d03d303..0000000
--- a/src/main/java/org/holoeasy/line/ILine.kt
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.holoeasy.line
-
-import org.bukkit.Location
-import org.bukkit.entity.Player
-import org.bukkit.plugin.Plugin
-import org.holoeasy.hologram.Hologram
-import org.holoeasy.reactive.Observer
-import org.jetbrains.annotations.ApiStatus
-
-interface ILine {
-
- data class PrivateConfig(private val line: ILine<*>) : Observer {
-
- lateinit var hologram: Hologram
- override fun observerUpdate() {
- hologram.let {
- line.update(it.seeingPlayers)
- }
- }
- }
-
- val plugin: Plugin
-
- val type: Type
-
- val entityId: Int
-
- val location: Location?
-
- var obj: T
-
- var pvt : PrivateConfig
-
- fun setLocation(value: Location)
-
- fun hide(player: Player)
-
- fun teleport(player: Player)
-
- fun show(player: Player)
-
- fun update(player: Player)
-
- fun update(seeingPlayers: Collection) {
- for (player in seeingPlayers) {
- update(player)
- }
- }
-
- enum class Type {
- EXTERNAL,
- TEXT_LINE,
- @ApiStatus.Experimental
- CLICKABLE_TEXT_LINE,
-
- BLOCK_LINE,
-
- }
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/line/ITextLine.kt b/src/main/java/org/holoeasy/line/ITextLine.kt
deleted file mode 100644
index 6427de0..0000000
--- a/src/main/java/org/holoeasy/line/ITextLine.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.holoeasy.line
-
-import org.bukkit.entity.Player
-
-interface ITextLine : ILine {
-
- val clickable: Boolean
-
- val textLine: TextLine
-
- val args: Array<*>?
-
- fun parse(player: Player): String
-
- fun onClick(clickEvent: ClickEvent)
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/line/Line.kt b/src/main/java/org/holoeasy/line/Line.kt
deleted file mode 100644
index e193462..0000000
--- a/src/main/java/org/holoeasy/line/Line.kt
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.holoeasy.line
-
-import com.comphenix.protocol.events.PacketContainer
-import org.bukkit.Location
-import org.bukkit.entity.EntityType
-import org.bukkit.entity.Player
-import org.bukkit.plugin.Plugin
-import org.holoeasy.ext.invoke
-import org.holoeasy.packet.IPacket
-import java.util.*
-import java.util.concurrent.atomic.AtomicInteger
-
-class Line(val plugin: Plugin, private val entityType: EntityType, var location: Location? = null) {
-
- companion object {
- val IDs_COUNTER = AtomicInteger(Random().nextInt())
- }
-
- val entityID: Int = IDs_COUNTER.getAndIncrement()
- private val entityDestroyPacket : PacketContainer = IPacket.get(IPacket.Type.DELETE).delete(entityID)
-
- fun destroy(player: Player) {
- entityDestroyPacket(player)
- }
-
- fun spawn(player: Player) {
- val packet = IPacket.get(IPacket.Type.SPAWN)
- .spawn(entityID, entityType, location ?: throw RuntimeException("Forgot the location?"), plugin)
- packet(player)
- }
-
- fun teleport(player: Player) {
-
- val packet = IPacket.get(IPacket.Type.TELEPORT)
- .teleport(entityID, location ?: throw RuntimeException("Forgot the location?"))
- packet(player)
-
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/line/TextLine.kt b/src/main/java/org/holoeasy/line/TextLine.kt
deleted file mode 100644
index fda70c0..0000000
--- a/src/main/java/org/holoeasy/line/TextLine.kt
+++ /dev/null
@@ -1,138 +0,0 @@
-package org.holoeasy.line
-
-import org.bukkit.Location
-import org.bukkit.entity.EntityType
-import org.bukkit.entity.Player
-import org.bukkit.plugin.Plugin
-import org.holoeasy.ext.send
-import org.holoeasy.packet.IPacket
-import org.holoeasy.reactive.MutableState
-import org.holoeasy.util.AABB
-
-class TextLine(
- plugin: Plugin,
- obj: String,
- override val args: Array<*>? = null,
- override val clickable: Boolean = false
-) : ITextLine {
-
- private val line: Line = Line(plugin, EntityType.ARMOR_STAND)
- override var obj: String = ""
- var clickEvent : ClickEvent? = null
- private var firstRender = true
-
- init {
- if (args == null) {
- this.obj = obj
- } else {
- this.obj = obj.replace("{}", "%s")
- }
- }
-
- var hitbox: AABB? = null
- private set
- private var isEmpty = false
-
- override val textLine: TextLine
- get() = this
-
- override fun parse(player: Player): String {
- if (args == null) {
- return obj
- }
- val res = arrayOfNulls(args.size)
- for (i in args.indices) {
- val tmp = args[i]
- if(tmp is MutableState<*>) {
- res[i] = tmp.get()
- if(firstRender) {
- firstRender = false
- tmp.addObserver(pvt)
- }
- } else {
- res[i] = tmp
- }
- }
-
- return String.format(obj, args = res)
- }
-
- override fun onClick(clickEvent: ClickEvent) {
- this.clickEvent = clickEvent
- }
-
- override val plugin: Plugin
- get() = line.plugin
- override val type: ILine.Type
- get() = ILine.Type.TEXT_LINE
- override val entityId: Int
- get() = line.entityID
- override val location: Location?
- get() = line.location
-
-
- override var pvt = ILine.PrivateConfig(this)
-
- override fun setLocation(value: Location) {
- line.location = value
- if (clickable) {
- val chars = obj.length.toDouble()
- val size = 0.105
- val dist = size * (chars / 2.0)
-
- hitbox = AABB(
- AABB.Vec3D(-dist, -0.040, -dist),
- AABB.Vec3D(dist, +0.040, dist)
- ).also {
- it.translate(AABB.Vec3D.fromLocation(value.clone().add(0.0, 2.35, 0.0)))
- }
- }
- }
-
- override fun hide(player: Player) {
- line.destroy(player)
- }
-
- override fun teleport(player: Player) {
- line.teleport(player)
- }
-
- override fun show(player: Player) {
- isEmpty = obj.isEmpty()
- if (!isEmpty) {
- line.spawn(player)
- val packet = IPacket.get(IPacket.Type.METADATA_TEXT)
- .metadata(entityId, parse(player))
- packet.send(player)
- }
- }
-
- override fun update(player: Player) {
- val spawnBefore = ((if (isEmpty) 1 else 0) or ((if (obj.isEmpty()) 1 else 0) shl 1))
- /* 0x00 = is already showed
- 0x01 = is hided but now has changed
- 0x02 = is already showed but is empty
- 0x03 = is hided and isn't changed */
- when (spawnBefore) {
- 0x03 -> {}
- 0x02 -> {
- line.destroy(player)
- isEmpty = true
- }
-
- 0x01 -> {
- line.spawn(player)
- isEmpty = false
- IPacket.get(IPacket.Type.METADATA_TEXT)
- .metadata(entityId, parse(player)).send(player)
- }
-
- 0x00 ->
- IPacket.get(IPacket.Type.METADATA_TEXT)
- .metadata(entityId, parse(player), invisible = false)
- .send(player)
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/IPacket.kt b/src/main/java/org/holoeasy/packet/IPacket.kt
deleted file mode 100644
index cb8637d..0000000
--- a/src/main/java/org/holoeasy/packet/IPacket.kt
+++ /dev/null
@@ -1,102 +0,0 @@
-package org.holoeasy.packet
-
-
-import org.holoeasy.HoloEasy
-import org.holoeasy.packet.delete.DeletePacketA
-import org.holoeasy.packet.delete.DeletePacketB
-import org.holoeasy.packet.delete.IDeletePacket
-import org.holoeasy.packet.metadata.item.*
-import org.holoeasy.packet.metadata.text.*
-import org.holoeasy.packet.spawn.*
-import org.holoeasy.packet.teleport.ITeleportPacket
-import org.holoeasy.packet.teleport.TeleportPacketA
-import org.holoeasy.packet.teleport.TeleportPacketB
-import org.holoeasy.packet.velocity.IVelocityPacket
-import org.holoeasy.packet.velocity.VelocityPacketA
-import org.holoeasy.util.VersionEnum
-import org.holoeasy.util.VersionUtil
-import kotlin.reflect.KClass
-
-interface IPacket {
-
- val versionSupport: Array>
-
- private fun isCurrentVersion(): Boolean {
- for (range in versionSupport) {
- if (VersionUtil.CLEAN_VERSION in range) {
- return true
- }
- }
- return false
- }
-
- companion object {
-
- private val cache = mutableMapOf, IPacket>()
-
- @JvmStatic
- fun get(type: Type): T {
- val cached = cache[type]
- if (cached != null) {
- return cached as T
- }
-
- val rightImpl = type.impls.firstOrNull(IPacket::isCurrentVersion)
- if (rightImpl != null) {
- cache[type] = rightImpl
- return rightImpl as T
- }
-
- if (HoloEasy.useLastSupportedVersion) {
- return type.impls.last() as T
- }
-
- throw RuntimeException(
- """
- No version support for ${type.abs.simpleName} packet
- Set HologramLib.useLastSupportedVersion to true or
- open an issue at https://github.com/unldenis/Hologram-Lib
- """.trimIndent()
- )
- }
-
- }
-
- class Type(internal val abs: KClass, vararg val impls: IPacket) {
-
- companion object {
- @JvmField
- val DELETE = Type(IDeletePacket::class, DeletePacketA, DeletePacketB)
-
- @JvmField
- val METADATA_TEXT = Type(
- IMetadataTextPacket::class,
- MetadataTextPacketA,
- MetadataTextPacketB,
- MetadataTextPacketC,
- MetadataTextPacketD
- )
-
- @JvmField
- val METADATA_ITEM = Type(
- IMetadataItemPacket::class,
- MetadataItemPacketA,
- MetadataItemPacketB,
- MetadataItemPacketC,
- MetadataItemPacketD
- )
-
- @JvmField
- val SPAWN = Type(ISpawnPacket::class, SpawnPacketA, SpawnPacketB, SpawnPacketC, SpawnPacketD)
-
- @JvmField
- val TELEPORT = Type(ITeleportPacket::class, TeleportPacketA, TeleportPacketB)
-
- @JvmField
- val VELOCITY = Type(IVelocityPacket::class, VelocityPacketA)
- }
-
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/PacketBuilder.kt b/src/main/java/org/holoeasy/packet/PacketBuilder.kt
deleted file mode 100644
index 6025e6f..0000000
--- a/src/main/java/org/holoeasy/packet/PacketBuilder.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.holoeasy.packet
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-
-
-fun packet(type: PacketType, initializer: PacketContainer.() -> Unit): PacketContainer {
- return PacketContainer(type).apply(initializer)
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/delete/DeletePacketA.kt b/src/main/java/org/holoeasy/packet/delete/DeletePacketA.kt
deleted file mode 100644
index 147975f..0000000
--- a/src/main/java/org/holoeasy/packet/delete/DeletePacketA.kt
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.holoeasy.packet.delete
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import org.holoeasy.ext.set
-import org.holoeasy.packet.packet
-import org.holoeasy.util.VersionEnum
-
-object DeletePacketA : IDeletePacket {
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_8..VersionEnum.V1_16)
-
- override fun delete(entityId: Int): PacketContainer {
- return packet(PacketType.Play.Server.ENTITY_DESTROY) {
- integerArrays[0] = intArrayOf(entityId)
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/delete/DeletePacketB.kt b/src/main/java/org/holoeasy/packet/delete/DeletePacketB.kt
deleted file mode 100644
index 8acdcf2..0000000
--- a/src/main/java/org/holoeasy/packet/delete/DeletePacketB.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.holoeasy.packet.delete
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import org.holoeasy.ext.set
-import org.holoeasy.packet.packet
-import org.holoeasy.util.VersionEnum
-
-object DeletePacketB : IDeletePacket {
-
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_17..VersionEnum.V1_20)
-
- override fun delete(entityId: Int): PacketContainer {
- return packet(PacketType.Play.Server.ENTITY_DESTROY) {
- intLists[0] = listOf(entityId)
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/delete/IDeletePacket.kt b/src/main/java/org/holoeasy/packet/delete/IDeletePacket.kt
deleted file mode 100644
index d657b5f..0000000
--- a/src/main/java/org/holoeasy/packet/delete/IDeletePacket.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.holoeasy.packet.delete
-
-import com.comphenix.protocol.events.PacketContainer
-import org.holoeasy.packet.IPacket
-
-interface IDeletePacket : IPacket {
-
- fun delete(entityId: Int): PacketContainer
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/metadata/item/IMetadataItemPacket.kt b/src/main/java/org/holoeasy/packet/metadata/item/IMetadataItemPacket.kt
deleted file mode 100644
index f47b735..0000000
--- a/src/main/java/org/holoeasy/packet/metadata/item/IMetadataItemPacket.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.holoeasy.packet.metadata.item
-
-import com.comphenix.protocol.events.PacketContainer
-import org.bukkit.inventory.ItemStack
-import org.holoeasy.packet.IPacket
-
-interface IMetadataItemPacket : IPacket {
- fun metadata(entityId: Int, item: ItemStack): PacketContainer
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/metadata/item/MetadataItemPacketA.kt b/src/main/java/org/holoeasy/packet/metadata/item/MetadataItemPacketA.kt
deleted file mode 100644
index 800a20b..0000000
--- a/src/main/java/org/holoeasy/packet/metadata/item/MetadataItemPacketA.kt
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.holoeasy.packet.metadata.item
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import com.comphenix.protocol.wrappers.WrappedDataWatcher
-import org.bukkit.inventory.ItemStack
-import org.holoeasy.ext.bukkitGeneric
-import org.holoeasy.ext.set
-import org.holoeasy.packet.packet
-import org.holoeasy.util.VersionEnum
-
-
-object MetadataItemPacketA : IMetadataItemPacket {
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_8..VersionEnum.V1_8)
-
- override fun metadata(entityId: Int, item: ItemStack): PacketContainer {
- val watcher = WrappedDataWatcher()
-
-
- watcher.setObject(5, true)
- watcher.setObject(10, item.bukkitGeneric())
-
-
- return packet(PacketType.Play.Server.ENTITY_METADATA) {
- integers[0] = entityId
- watchableCollectionModifier[0] = watcher.watchableObjects
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/metadata/item/MetadataItemPacketB.kt b/src/main/java/org/holoeasy/packet/metadata/item/MetadataItemPacketB.kt
deleted file mode 100644
index 7906c60..0000000
--- a/src/main/java/org/holoeasy/packet/metadata/item/MetadataItemPacketB.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.holoeasy.packet.metadata.item
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import com.comphenix.protocol.wrappers.WrappedDataWatcher
-import org.bukkit.inventory.ItemStack
-import org.holoeasy.ext.set
-import org.holoeasy.ext.setBool
-import org.holoeasy.ext.setItemStack
-import org.holoeasy.packet.packet
-import org.holoeasy.util.VersionEnum
-
-
-object MetadataItemPacketB : IMetadataItemPacket {
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_9..VersionEnum.V1_12)
-
- override fun metadata(entityId: Int, item: ItemStack): PacketContainer {
- val watcher = WrappedDataWatcher()
-
- watcher.setBool(5, true)
- watcher.setItemStack(6, item)
-
- return packet(PacketType.Play.Server.ENTITY_METADATA) {
- integers[0] = entityId
- watchableCollectionModifier[0] = watcher.watchableObjects
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/metadata/item/MetadataItemPacketC.kt b/src/main/java/org/holoeasy/packet/metadata/item/MetadataItemPacketC.kt
deleted file mode 100644
index 37afe46..0000000
--- a/src/main/java/org/holoeasy/packet/metadata/item/MetadataItemPacketC.kt
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.holoeasy.packet.metadata.item
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import com.comphenix.protocol.wrappers.EnumWrappers.EntityPose
-import com.comphenix.protocol.wrappers.WrappedDataWatcher
-import org.bukkit.inventory.ItemStack
-import org.holoeasy.ext.set
-import org.holoeasy.ext.setBool
-import org.holoeasy.ext.setItemStack
-import org.holoeasy.packet.packet
-import org.holoeasy.util.VersionEnum
-
-
-object MetadataItemPacketC : IMetadataItemPacket {
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_13..VersionEnum.V1_19)
-
- override fun metadata(entityId: Int, item: ItemStack): PacketContainer {
- val watcher = WrappedDataWatcher()
-
- watcher.setBool(5, true)
- watcher.setItemStack(7, item)
-
- return packet(PacketType.Play.Server.ENTITY_METADATA) {
- integers[0] = entityId
- watchableCollectionModifier[0] = watcher.watchableObjects
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/metadata/text/IMetadataTextPacket.kt b/src/main/java/org/holoeasy/packet/metadata/text/IMetadataTextPacket.kt
deleted file mode 100644
index c8562c5..0000000
--- a/src/main/java/org/holoeasy/packet/metadata/text/IMetadataTextPacket.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.holoeasy.packet.metadata.text
-
-import com.comphenix.protocol.events.PacketContainer
-import org.holoeasy.packet.IPacket
-
-interface IMetadataTextPacket : IPacket {
-
- fun metadata(entityId: Int, nameTag: String?, invisible : Boolean = true): PacketContainer
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/metadata/text/MetadataTextPacketA.kt b/src/main/java/org/holoeasy/packet/metadata/text/MetadataTextPacketA.kt
deleted file mode 100644
index cecd647..0000000
--- a/src/main/java/org/holoeasy/packet/metadata/text/MetadataTextPacketA.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-package org.holoeasy.packet.metadata.text
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import com.comphenix.protocol.wrappers.WrappedDataWatcher
-import org.holoeasy.ext.set
-import org.holoeasy.packet.packet
-import org.holoeasy.util.VersionEnum
-
-object MetadataTextPacketA : IMetadataTextPacket {
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_8..VersionEnum.V1_8)
-
- override fun metadata(entityId: Int, nameTag: String?, invisible: Boolean): PacketContainer {
- val watcher = WrappedDataWatcher()
-
- if (invisible)
- watcher.setObject(0, 0x20.toByte())
-
- if(nameTag != null) {
- watcher.setObject(2, nameTag)
- watcher.setObject(3, 1.toByte())
- }
-
-
- return packet(PacketType.Play.Server.ENTITY_METADATA) {
- integers[0] = entityId
- watchableCollectionModifier[0] = watcher.watchableObjects
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/metadata/text/MetadataTextPacketB.kt b/src/main/java/org/holoeasy/packet/metadata/text/MetadataTextPacketB.kt
deleted file mode 100644
index 42114e9..0000000
--- a/src/main/java/org/holoeasy/packet/metadata/text/MetadataTextPacketB.kt
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.holoeasy.packet.metadata.text
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import com.comphenix.protocol.wrappers.WrappedDataWatcher
-import org.holoeasy.ext.set
-import org.holoeasy.ext.setBool
-import org.holoeasy.ext.setByte
-import org.holoeasy.ext.setString
-import org.holoeasy.packet.packet
-import org.holoeasy.util.VersionEnum
-
-object MetadataTextPacketB : IMetadataTextPacket {
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_9..VersionEnum.V1_12)
-
- override fun metadata(entityId: Int, nameTag: String?, invisible : Boolean): PacketContainer {
- val watcher = WrappedDataWatcher()
-
- if(invisible)
- watcher.setByte(0, 0x20.toByte())
-
- if(nameTag != null) {
- watcher.setString(2, nameTag)
- watcher.setBool(3, true)
- }
-
- return packet(PacketType.Play.Server.ENTITY_METADATA) {
- modifier.writeDefaults()
- integers[0] = entityId
- watchableCollectionModifier[0] = watcher.watchableObjects
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/spawn/ISpawnPacket.kt b/src/main/java/org/holoeasy/packet/spawn/ISpawnPacket.kt
deleted file mode 100644
index d5ecf10..0000000
--- a/src/main/java/org/holoeasy/packet/spawn/ISpawnPacket.kt
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.holoeasy.packet.spawn
-
-import com.comphenix.protocol.events.PacketContainer
-import org.bukkit.Location
-import org.bukkit.entity.EntityType
-import org.bukkit.plugin.Plugin
-import org.holoeasy.packet.IPacket
-
-interface ISpawnPacket : IPacket {
-
- fun spawn(
- entityId: Int, entityType: EntityType, location: Location,
- plugin: Plugin? = null
- ): PacketContainer
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/spawn/SpawnPacketA.kt b/src/main/java/org/holoeasy/packet/spawn/SpawnPacketA.kt
deleted file mode 100644
index d69979e..0000000
--- a/src/main/java/org/holoeasy/packet/spawn/SpawnPacketA.kt
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.holoeasy.packet.spawn
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import com.comphenix.protocol.wrappers.WrappedDataWatcher
-
-import org.bukkit.Bukkit
-import org.bukkit.Location
-import org.bukkit.entity.EntityType
-import org.bukkit.plugin.Plugin
-import org.holoeasy.ext.set
-import org.holoeasy.packet.packet
-import org.holoeasy.util.BukkitFuture
-import org.holoeasy.util.VersionEnum
-import org.holoeasy.util.VersionUtil
-import java.util.concurrent.CompletableFuture
-
-object SpawnPacketA : ISpawnPacket {
-
- private fun loadDefaultWatcher(plugin: Plugin): CompletableFuture {
- return BukkitFuture.runSync(plugin) {
- val world = Bukkit.getWorlds()[0]
- val entity =
- world.spawnEntity(Location(world, 0.0, 256.0, 0.0), EntityType.ARMOR_STAND)
- defaultDataWatcher = WrappedDataWatcher.getEntityWatcher(entity).deepClone()
- entity.remove()
- }
- }
-
- private var defaultDataWatcher: WrappedDataWatcher? = null
-
-
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_8..VersionEnum.V1_8)
-
- override fun spawn(entityId: Int, entityType: EntityType, location: Location, plugin: Plugin?): PacketContainer {
- return packet(PacketType.Play.Server.SPAWN_ENTITY) {
- integers[0] = entityId
- integers[1] = if(entityType == EntityType.ARMOR_STAND) VersionUtil.CLEAN_VERSION.armorstandId else VersionUtil.CLEAN_VERSION.droppedItemId
- integers[2] = (location.x * 32).toInt()
- integers[3] = (location.y * 32).toInt()
- integers[4] = (location.z * 32).toInt()
-
- if (defaultDataWatcher == null) {
-
- loadDefaultWatcher(
- plugin ?: throw RuntimeException("Plugin cannot be null")
- ).join()
- }
-
- dataWatcherModifier[0] = defaultDataWatcher
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/spawn/SpawnPacketB.kt b/src/main/java/org/holoeasy/packet/spawn/SpawnPacketB.kt
deleted file mode 100644
index 9538982..0000000
--- a/src/main/java/org/holoeasy/packet/spawn/SpawnPacketB.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.holoeasy.packet.spawn
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import org.bukkit.Location
-import org.bukkit.entity.EntityType
-import org.bukkit.plugin.Plugin
-import org.holoeasy.ext.set
-import org.holoeasy.packet.packet
-import org.holoeasy.util.VersionEnum
-import org.holoeasy.util.VersionUtil
-import java.util.*
-
-object SpawnPacketB : ISpawnPacket {
-
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_9..VersionEnum.V1_15)
-
- override fun spawn(entityId: Int, entityType: EntityType, location: Location, plugin: Plugin?): PacketContainer {
- val extraData = 1
-
- return packet(PacketType.Play.Server.SPAWN_ENTITY_LIVING) {
- modifier.writeDefaults()
-
- integers[0] = entityId
- integers[1] = if(entityType == EntityType.ARMOR_STAND)
- VersionUtil.CLEAN_VERSION.armorstandId else VersionUtil.CLEAN_VERSION.droppedItemId
- integers[2] = extraData
-
- uuiDs[0] = UUID.randomUUID()
-
- doubles[0] = location.x
- doubles[1] = location.y
- doubles[2] = location.z
- }
-
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/spawn/SpawnPacketC.kt b/src/main/java/org/holoeasy/packet/spawn/SpawnPacketC.kt
deleted file mode 100644
index 9774b13..0000000
--- a/src/main/java/org/holoeasy/packet/spawn/SpawnPacketC.kt
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.holoeasy.packet.spawn
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import org.bukkit.Location
-import org.bukkit.entity.EntityType
-import org.bukkit.plugin.Plugin
-import org.holoeasy.ext.set
-import org.holoeasy.packet.packet
-import org.holoeasy.util.VersionEnum
-import org.holoeasy.util.VersionUtil
-import java.util.*
-import kotlin.math.max
-import kotlin.math.min
-
-object SpawnPacketC : ISpawnPacket {
-
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_16..VersionEnum.V1_18)
-
- override fun spawn(entityId: Int, entityType: EntityType, location: Location, plugin: Plugin?): PacketContainer {
- val extraData = 1
-
- if(entityType == EntityType.ARMOR_STAND) {
- return packet(PacketType.Play.Server.SPAWN_ENTITY_LIVING) {
- modifier.writeDefaults()
-
- integers[0] = entityId
- integers[1] = VersionUtil.CLEAN_VERSION.armorstandId
- integers[2] = extraData
-
- uuiDs[0] = UUID.randomUUID()
-
- doubles[0] = location.x
- doubles[1] = location.y
- doubles[2] = location.z
- }
- } else {
- return packet(PacketType.Play.Server.SPAWN_ENTITY) {
- modifier.writeDefaults()
-
- integers[0] = entityId
-
- entityTypeModifier[0] = EntityType.DROPPED_ITEM
-
- uuiDs[0] = UUID.randomUUID()
-
- doubles[0] = location.x
- doubles[1] = location.y
- doubles[2] = location.z
-
- integers[2] = convertVelocity(0.0)
- integers[3] = convertVelocity(0.0)
- integers[4] = convertVelocity(0.0)
- }
- }
-
- }
-
- private fun convertVelocity(velocity: Double): Int {
- /*
- Minecraft represents a velocity within 4 blocks per second, in any direction,
- by using the entire Short range, meaning you can only move up to 4 blocks/second
- on any given direction
- */
- return (clamp(velocity, -3.9, 3.9) * 8000).toInt()
- }
- private fun clamp(targetNum: Double, min: Double, max: Double): Double {
- // Makes sure a number is within a range
- return max(min, min(targetNum, max))
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/spawn/SpawnPacketD.kt b/src/main/java/org/holoeasy/packet/spawn/SpawnPacketD.kt
deleted file mode 100644
index c8ab4a3..0000000
--- a/src/main/java/org/holoeasy/packet/spawn/SpawnPacketD.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-package org.holoeasy.packet.spawn
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import org.bukkit.Location
-import org.bukkit.entity.EntityType
-import org.bukkit.plugin.Plugin
-import org.holoeasy.ext.set
-import org.holoeasy.packet.packet
-import org.holoeasy.util.VersionEnum
-import java.util.*
-
-object SpawnPacketD : ISpawnPacket {
-
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_19..VersionEnum.V1_20)
-
- override fun spawn(entityId: Int, entityType: EntityType, location: Location, plugin: Plugin?): PacketContainer {
- return packet(PacketType.Play.Server.SPAWN_ENTITY) {
- integers[0] = entityId
-
- entityTypeModifier[0] = entityType
-
- uuiDs[0] = UUID.randomUUID()
-
- doubles[0] = location.x
- doubles[1] = location.y
- doubles[2] = location.z
-
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/teleport/ITeleportPacket.kt b/src/main/java/org/holoeasy/packet/teleport/ITeleportPacket.kt
deleted file mode 100644
index d52a7e6..0000000
--- a/src/main/java/org/holoeasy/packet/teleport/ITeleportPacket.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.holoeasy.packet.teleport
-
-import com.comphenix.protocol.events.PacketContainer
-import org.bukkit.Location
-import org.holoeasy.packet.IPacket
-
-interface ITeleportPacket : IPacket {
- fun teleport(entityId: Int, location: Location): PacketContainer
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/teleport/TeleportPacketA.kt b/src/main/java/org/holoeasy/packet/teleport/TeleportPacketA.kt
deleted file mode 100644
index fe54d83..0000000
--- a/src/main/java/org/holoeasy/packet/teleport/TeleportPacketA.kt
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.holoeasy.packet.teleport
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import org.bukkit.Location
-import org.holoeasy.ext.compressAngle
-import org.holoeasy.ext.fixCoordinate
-import org.holoeasy.ext.set
-import org.holoeasy.packet.packet
-import org.holoeasy.util.VersionEnum
-
-object TeleportPacketA : ITeleportPacket {
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_8..VersionEnum.V1_8)
-
- override fun teleport(entityId: Int, location: Location): PacketContainer {
- return packet(PacketType.Play.Server.ENTITY_TELEPORT) {
- integers[0] = entityId
- integers[1] = location.x.fixCoordinate
- integers[2] = location.y.fixCoordinate
- integers[3] = location.z.fixCoordinate
- bytes[0] = location.yaw.toDouble().compressAngle
- bytes[1] = location.pitch.toDouble().compressAngle
- booleans[0] = false
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/teleport/TeleportPacketB.kt b/src/main/java/org/holoeasy/packet/teleport/TeleportPacketB.kt
deleted file mode 100644
index 4a83051..0000000
--- a/src/main/java/org/holoeasy/packet/teleport/TeleportPacketB.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-package org.holoeasy.packet.teleport
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import org.bukkit.Location
-import org.holoeasy.ext.compressAngle
-import org.holoeasy.ext.set
-import org.holoeasy.packet.packet
-import org.holoeasy.util.VersionEnum
-
-object TeleportPacketB : ITeleportPacket {
-
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_9..VersionEnum.V1_20)
-
- override fun teleport(entityId: Int, location: Location): PacketContainer {
- val teleportPacket = packet(PacketType.Play.Server.ENTITY_TELEPORT) {
- integers[0] = entityId
-
- doubles[0] = location.x
- doubles[1] = location.y
- doubles[2] = location.z
-
- bytes[0] = location.yaw.toDouble().compressAngle
- bytes[1] = location.pitch.toDouble().compressAngle
-
- booleans[0] = false
- }
-
- return teleportPacket
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/velocity/IVelocityPacket.kt b/src/main/java/org/holoeasy/packet/velocity/IVelocityPacket.kt
deleted file mode 100644
index ba54d34..0000000
--- a/src/main/java/org/holoeasy/packet/velocity/IVelocityPacket.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.holoeasy.packet.velocity
-
-import com.comphenix.protocol.events.PacketContainer
-import org.holoeasy.packet.IPacket
-
-interface IVelocityPacket : IPacket {
- fun velocity(entityId: Int, x: Int, y : Int, z : Int): PacketContainer
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/packet/velocity/VelocityPacketA.kt b/src/main/java/org/holoeasy/packet/velocity/VelocityPacketA.kt
deleted file mode 100644
index 06e7967..0000000
--- a/src/main/java/org/holoeasy/packet/velocity/VelocityPacketA.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-package org.holoeasy.packet.velocity
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.events.PacketContainer
-import org.holoeasy.ext.set
-import org.holoeasy.packet.packet
-import org.holoeasy.util.VersionEnum
-
-object VelocityPacketA : IVelocityPacket {
-
- override val versionSupport: Array>
- get() = arrayOf(VersionEnum.V1_8..VersionEnum.V1_20)
-
- override fun velocity(entityId: Int, x: Int, y: Int, z: Int): PacketContainer {
- return packet(PacketType.Play.Server.ENTITY_VELOCITY) {
- integers[0] = entityId
- integers[1] = x
- integers[2] = y
- integers[3] = z
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/pool/HologramPool.kt b/src/main/java/org/holoeasy/pool/HologramPool.kt
deleted file mode 100644
index f1dd245..0000000
--- a/src/main/java/org/holoeasy/pool/HologramPool.kt
+++ /dev/null
@@ -1,118 +0,0 @@
-package org.holoeasy.pool
-
-import org.holoeasy.config.HologramKey
-import com.google.common.collect.ImmutableList
-import org.bukkit.Bukkit
-import org.bukkit.Location
-import org.bukkit.event.EventHandler
-import org.bukkit.event.Listener
-import org.bukkit.event.player.PlayerQuitEvent
-import org.bukkit.event.player.PlayerRespawnEvent
-import org.bukkit.plugin.Plugin
-import org.holoeasy.hologram.Hologram
-import java.util.concurrent.ConcurrentHashMap
-
-class KeyAlreadyExistsException(key: HologramKey) : IllegalStateException("Key '$key' already exists")
-class NoValueForKeyException(key: String) : IllegalStateException("No value for key '$key'")
-
-class HologramPool(override val plugin: Plugin, private val spawnDistance: Double) : Listener, IHologramPool {
-
- val holograms: MutableMap = ConcurrentHashMap()
-
- init {
- Bukkit.getPluginManager().registerEvents(this, plugin)
-
- hologramTick()
- }
-
- override fun get(key: HologramKey): Hologram {
- return holograms[key] ?: throw NoValueForKeyException(key.id)
- }
-
- override fun get(keyId: String) : Hologram {
- for((key, holo) in holograms) {
- if(key.id == keyId) {
- return holo
- }
- }
- throw NoValueForKeyException(keyId)
- }
-
- override fun takeCareOf(key: HologramKey, value: Hologram) {
- if (holograms.containsKey(key)) {
- throw KeyAlreadyExistsException(key)
- }
- holograms[key] = value
- }
-
- /**
- * Removes the given hologram by from the handled Holograms of this pool.
- *
- * @param hologram the hologram of the pool to remove.
- * @return true if any elements were removed
- */
- override fun remove(key: HologramKey): Hologram? {
- // if removed
- val removed = holograms.remove(key)
- removed?.let {
- for (player in it.seeingPlayers) {
- it.hide(player)
- }
- return it
- }
- return null
- }
-
- @EventHandler
- fun handleRespawn(event: PlayerRespawnEvent) {
- val player = event.player
- holograms
- .values
- .filter { it.isShownFor(player) }
- .forEach { it.hide(player) }
- }
-
- @EventHandler
- fun handleQuit(event: PlayerQuitEvent) {
- val player = event.player
- holograms
- .values
- .filter { it.isShownFor(player) }
- .forEach { it.seeingPlayers.remove(player) }
- }
-
- /**
- * Starts the hologram tick.
- */
- private fun hologramTick() {
- Bukkit.getScheduler().runTaskTimerAsynchronously(this.plugin, Runnable {
- for (player in ImmutableList.copyOf(Bukkit.getOnlinePlayers())) {
- for (hologram in this.holograms.values) {
- val holoLoc = hologram.location
- val playerLoc: Location = player.location
- val isShown = hologram.isShownFor(player)
-
- if (holoLoc.world != playerLoc.world) {
- if (isShown) {
- hologram.hide(player)
- }
- continue
- } else if (!holoLoc.world
- // todo: log
- !!.isChunkLoaded(holoLoc.blockX shr 4, holoLoc.blockZ shr 4) && isShown
- ) {
- hologram.hide(player)
- continue
- }
- val inRange = holoLoc.distanceSquared(playerLoc) <= this.spawnDistance
-
- if (!inRange && isShown) {
- hologram.hide(player)
- } else if (inRange && !isShown) {
- hologram.show(player)
- }
- }
- }
- }, 20L, 2L)
- }
-}
diff --git a/src/main/java/org/holoeasy/pool/IHologramPool.kt b/src/main/java/org/holoeasy/pool/IHologramPool.kt
deleted file mode 100644
index 3fd26c4..0000000
--- a/src/main/java/org/holoeasy/pool/IHologramPool.kt
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.holoeasy.pool
-
-import org.holoeasy.config.HologramKey
-import org.bukkit.plugin.Plugin
-import org.holoeasy.hologram.Hologram
-import org.jetbrains.annotations.ApiStatus.Experimental
-
-interface IHologramPool {
-
- val plugin: Plugin
-
- fun get(key: HologramKey): Hologram
-
- @Experimental
- fun get(keyId: String) : Hologram
-
- fun takeCareOf(key: HologramKey, value: Hologram)
-
- fun remove(key: HologramKey): Hologram?
-
-}
diff --git a/src/main/java/org/holoeasy/pool/InteractiveHologramPool.kt b/src/main/java/org/holoeasy/pool/InteractiveHologramPool.kt
deleted file mode 100644
index ea7ec51..0000000
--- a/src/main/java/org/holoeasy/pool/InteractiveHologramPool.kt
+++ /dev/null
@@ -1,94 +0,0 @@
-package org.holoeasy.pool
-
-import org.holoeasy.config.HologramKey
-import org.bukkit.Bukkit
-import org.bukkit.event.EventHandler
-import org.bukkit.event.Listener
-import org.bukkit.event.block.Action
-import org.bukkit.event.player.PlayerInteractEvent
-import org.bukkit.plugin.Plugin
-import org.holoeasy.hologram.Hologram
-import org.holoeasy.line.ILine
-import org.holoeasy.line.ITextLine
-import org.holoeasy.util.AABB
-
-class InteractiveHologramPool(private val pool: HologramPool, minHitDistance: Float, maxHitDistance: Float) : Listener,
- IHologramPool {
-
- override val plugin: Plugin
- get() = pool.plugin
-
- override fun get(key: HologramKey): Hologram {
- return pool.get(key)
- }
-
- override fun get(keyId: String): Hologram {
- return pool.get(keyId)
- }
-
- override fun takeCareOf(key: HologramKey, value: Hologram) {
- pool.takeCareOf(key, value)
- }
-
- override fun remove(key: HologramKey): Hologram? {
- return pool.remove(key)
- }
-
-
- val minHitDistance: Float
- val maxHitDistance: Float
-
- init {
- require(!(minHitDistance < 0)) { "minHitDistance must be positive" }
- require(!(maxHitDistance > 120)) { "maxHitDistance cannot be greater than 120" }
- this.minHitDistance = minHitDistance
- this.maxHitDistance = maxHitDistance
-
- Bukkit.getPluginManager().registerEvents(this, plugin)
- }
-
-
- @EventHandler
- fun handleInteract(e: PlayerInteractEvent) {
- Bukkit.getScheduler().runTaskAsynchronously(plugin, Runnable {
- val player = e.player
- if (e.action != Action.LEFT_CLICK_AIR) {
- return@Runnable
- }
- FST@ for (hologram in pool.holograms.values) {
- if (!hologram.isShownFor(player)) {
- continue
- }
- for (line in hologram.lines) {
- when (line.type) {
- ILine.Type.TEXT_LINE -> {
- val iTextLine = line as ITextLine
- if (!iTextLine.clickable) {
- continue
- }
-
- val tL = iTextLine.textLine
- if (tL.hitbox == null) {
- continue
- }
-
- val intersects = tL.hitbox!!.intersectsRay(
- AABB.Ray3D(player.eyeLocation), minHitDistance, maxHitDistance
- )
- if (intersects == null) {
- continue
- }
-
- tL.clickEvent?.onClick(player)
- break@FST
- }
-
- ILine.Type.EXTERNAL -> {}
- ILine.Type.CLICKABLE_TEXT_LINE -> {}
- ILine.Type.BLOCK_LINE -> {}
- }
- }
- }
- })
- }
-}
diff --git a/src/main/java/org/holoeasy/reactive/MutableState.kt b/src/main/java/org/holoeasy/reactive/MutableState.kt
deleted file mode 100644
index 8816d72..0000000
--- a/src/main/java/org/holoeasy/reactive/MutableState.kt
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.holoeasy.reactive
-
-data class MutableState(private var value : T) {
-
- private val observers= mutableListOf()
-
- fun get() : T {
- return value
- }
-
- fun set(newValue : T) {
- value = newValue
- this.notifyObservers()
- }
-
- fun addObserver(observer: Observer) {
- observers.add(observer)
- }
-
- fun removeObserver(observer: Observer) {
- observers.remove(observer)
- }
-
- private fun notifyObservers() {
- for (observer in observers) {
- observer.observerUpdate()
- }
- }
-}
diff --git a/src/main/java/org/holoeasy/reactive/Observer.kt b/src/main/java/org/holoeasy/reactive/Observer.kt
deleted file mode 100644
index 162dfbb..0000000
--- a/src/main/java/org/holoeasy/reactive/Observer.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.holoeasy.reactive
-
-interface Observer {
- fun observerUpdate()
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/util/AABB.kt b/src/main/java/org/holoeasy/util/AABB.kt
deleted file mode 100644
index c8a21e2..0000000
--- a/src/main/java/org/holoeasy/util/AABB.kt
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * Hologram-Lib - Asynchronous, high-performance Minecraft Hologram
- * library for 1.8-1.18 servers.
- * Copyright (C) unldenis
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package org.holoeasy.util
-
-import org.bukkit.Location
-import org.bukkit.util.Vector
-import java.util.*
-import kotlin.math.sqrt
-
-/**
- * Represents an axix-aligned bounding box.
- *
- * @author Kristian
- * @author unldenis
- */
-class AABB
-/**
- * Creates a new instance from a minimum point and a maximum point.
- */(private var min: Vec3D, private var max: Vec3D) {
- /**
- * Create a new com.github.unldenis.hologram.util.AABB from a given block.
- *
- * @param block - the block.
- */
- constructor(block: Location) : this(Vec3D.fromLocation(block), Vec3D.fromLocation(block).add(Vec3D.UNIT_MAX))
-
- /**
- * Translate this AABB to a given point.
- *
- * @param vec - the point.
- */
- fun translate(vec: Vec3D) {
- this.min = min.add(vec)
- this.max = max.add(vec)
- }
-
- /**
- * Calculates intersection with the given ray between a certain distance interval.
- *
- *
- * Ray-box intersection is using IEEE numerical properties to ensure the test is both robust and
- * efficient, as described in:
- *
- * `Amy Williams, Steve Barrus, R. Keith Morley, and Peter Shirley: "An
- * Efficient and Robust Ray-Box Intersection Algorithm" Journal of graphics tools, 10(1):49-54,
- * 2005`
- *
- * @param ray incident ray
- * @return intersection point on the bounding box (only the first is returned) or null if no
- * intersection
- */
- fun intersectsRay(ray: Ray3D, minDist: Float, maxDist: Float): Vec3D? {
- val invDir = Vec3D(1f / ray.direction.x, 1f / ray.direction.y, 1f / ray.direction.z)
-
- val signDirX = invDir.x < 0
- val signDirY = invDir.y < 0
- val signDirZ = invDir.z < 0
-
- var bbox = if (signDirX) max else min
- var tmin = (bbox.x - ray.x) * invDir.x
- bbox = if (signDirX) min else max
- var tmax = (bbox.x - ray.x) * invDir.x
- bbox = if (signDirY) max else min
- val tymin = (bbox.y - ray.y) * invDir.y
- bbox = if (signDirY) min else max
- val tymax = (bbox.y - ray.y) * invDir.y
-
- if ((tmin > tymax) || (tymin > tmax)) {
- return null
- }
- if (tymin > tmin) {
- tmin = tymin
- }
- if (tymax < tmax) {
- tmax = tymax
- }
-
- bbox = if (signDirZ) max else min
- val tzmin = (bbox.z - ray.z) * invDir.z
- bbox = if (signDirZ) min else max
- val tzmax = (bbox.z - ray.z) * invDir.z
-
- if ((tmin > tzmax) || (tzmin > tmax)) {
- return null
- }
- if (tzmin > tmin) {
- tmin = tzmin
- }
- if (tzmax < tmax) {
- tmax = tzmax
- }
- if ((tmin < maxDist) && (tmax > minDist)) {
- return ray.getPointAtDistance(tmin)
- }
- return null
- }
-
- open class Vec3D {
- /**
- * X coordinate.
- */
- val x: Double
-
- /**
- * Y coordinate.
- */
- val y: Double
-
- /**
- * Z coordinate.
- */
- val z: Double
-
- /**
- * Creates a new vector with the given coordinates.
- *
- * @param x the x
- * @param y the y
- * @param z the z
- */
- constructor(x: Double, y: Double, z: Double) {
- this.x = x
- this.y = y
- this.z = z
- }
-
- /**
- * Creates a new vector with the coordinates of the given vector.
- *
- * @param v vector to copy.
- */
- constructor(v: Vec3D) {
- this.x = v.x
- this.y = v.y
- this.z = v.z
- }
-
- /**
- * Add vector v and returns result as new vector.
- *
- * @param v vector to add
- * @return result as new vector
- */
- fun add(v: Vec3D): Vec3D {
- return Vec3D(x + v.x, y + v.y, z + v.z)
- }
-
- /**
- * Scales vector uniformly and returns result as new vector.
- *
- * @param s scale factor
- * @return new vector
- */
- fun scale(s: Double): Vec3D {
- return Vec3D(x * s, y * s, z * s)
- }
-
- /**
- * Normalizes the vector so that its magnitude = 1.
- *
- * @return The normalized vector.
- */
- fun normalize(): Vec3D {
- val mag = sqrt(x * x + y * y + z * z)
-
- if (mag > 0) {
- return scale(1.0 / mag)
- }
- return this
- }
-
- override fun equals(obj: Any?): Boolean {
- if (obj is Vec3D) {
- val v = obj
- return x == v.x && y == v.y && z == v.z
- }
- return false
- }
-
- override fun hashCode(): Int {
- return Objects.hash(x, y, z)
- }
-
- override fun toString(): String {
- return String.format("{x: %g, y: %g, z: %g}", x, y, z)
- }
-
- companion object {
- /**
- * Point with the coordinate (1, 1, 1).
- */
- val UNIT_MAX: Vec3D = Vec3D(1.0, 1.0, 1.0)
-
- /**
- * Construct a vector from a Bukkit location.
- *
- * @param loc - the Bukkit location.
- */
- @JvmStatic
- fun fromLocation(loc: Location): Vec3D {
- return Vec3D(loc.x, loc.y, loc.z)
- }
-
- /**
- * Construct a copy of our immutable vector from Bukkit's mutable vector.
- *
- * @param v - Bukkit vector.
- * @return A copy of the given vector.
- */
- fun fromVector(v: Vector): Vec3D {
- return Vec3D(v.x, v.y, v.z)
- }
- }
- }
-
- class Ray3D(origin: Vec3D, direction: Vec3D) : Vec3D(origin) {
- val direction: Vec3D = direction.normalize()
-
- /**
- * Construct a 3D ray from a location.
- *
- * @param loc - the Bukkit location.
- */
- constructor(loc: Location) : this(fromLocation(loc), fromVector(loc.direction))
-
- fun getPointAtDistance(dist: Double): Vec3D {
- return add(direction.scale(dist))
- }
-
- override fun toString(): String {
- return "origin: " + super.toString() + " dir: " + direction
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/java/org/holoeasy/util/BukkitFuture.kt b/src/main/java/org/holoeasy/util/BukkitFuture.kt
deleted file mode 100644
index af0e233..0000000
--- a/src/main/java/org/holoeasy/util/BukkitFuture.kt
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Hologram-Lib - Asynchronous, high-performance Minecraft Hologram
- * library for 1.8-1.18 servers.
- * Copyright (C) unldenis
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package org.holoeasy.util
-
-import org.bukkit.Bukkit
-import org.bukkit.plugin.Plugin
-import java.util.concurrent.CompletableFuture
-import java.util.function.BiConsumer
-import java.util.function.Supplier
-
-object BukkitFuture {
- /**
- * Returns a new CompletableFuture that is asynchronously completed by Bukkit schedule with the
- * value obtained by calling the given Supplier.
- *
- * @param supplier a function returning the value to be used to complete the returned
- * CompletableFuture
- * @param the function's return type
- */
- fun supplyAsync(
- plugin: Plugin,
- supplier: Supplier
- ): CompletableFuture {
- val future = CompletableFuture()
- Bukkit.getScheduler().runTaskAsynchronously(plugin, Runnable {
- try {
- future.complete(supplier.get())
- } catch (t: Throwable) {
- future.completeExceptionally(t)
- }
- })
- return future
- }
-
- /**
- * Returns a new CompletableFuture that is asynchronously completed by Bukkit schedule after it
- * runs the given action.
- *
- * @param runnable the action to run before completing the returned CompletableFuture
- */
- fun runAsync(
- plugin: Plugin,
- runnable: Runnable
- ): CompletableFuture {
- val future = CompletableFuture()
- Bukkit.getScheduler().runTaskAsynchronously(plugin, Runnable {
- try {
- runnable.run()
- future.complete(null)
- } catch (t: Throwable) {
- future.completeExceptionally(t)
- }
- })
- return future
- }
-
- /**
- * Returns a new CompletableFuture that is synchronously completed by Bukkit schedule with the
- * value obtained by calling the given Supplier.
- *
- * @param supplier a function returning the value to be used to complete the returned
- * CompletableFuture
- * @param the function's return type
- */
- fun supplySync(
- plugin: Plugin,
- supplier: Supplier
- ): CompletableFuture {
- val future = CompletableFuture()
- if (Bukkit.isPrimaryThread()) {
- try {
- future.complete(supplier.get())
- } catch (t: Throwable) {
- future.completeExceptionally(t)
- }
- } else {
- Bukkit.getScheduler().runTask(plugin, Runnable {
- try {
- future.complete(supplier.get())
- } catch (t: Throwable) {
- future.completeExceptionally(t)
- }
- })
- }
- return future
- }
-
- /**
- * Returns a new CompletableFuture that is synchronously completed by Bukkit schedule after it
- * runs the given action.
- *
- * @param runnable the action to run before completing the returned CompletableFuture
- */
- fun runSync(
- plugin: Plugin,
- runnable: Runnable
- ): CompletableFuture {
- val future = CompletableFuture()
- if (Bukkit.isPrimaryThread()) {
- try {
- runnable.run()
- future.complete(null)
- } catch (t: Throwable) {
- future.completeExceptionally(t)
- }
- } else {
- Bukkit.getScheduler().runTask(plugin, Runnable {
- try {
- runnable.run()
- future.complete(null)
- } catch (t: Throwable) {
- future.completeExceptionally(t)
- }
- })
- }
- return future
- }
-
- /**
- * Helper method to avoid boilerplate in CompletableFuture#whenComplete .
- *
- * @param action the BiConsumer of the whenComplete method that will be executed in the runnable
- * synchronously.
- * @param the function's return type
- */
- fun sync(
- plugin: Plugin,
- action: BiConsumer
- ): BiConsumer {
- return BiConsumer { t: T, throwable: Throwable? ->
- runSync(
- plugin
- ) { action.accept(t, throwable) }
- }
- }
-}
diff --git a/src/main/java/org/holoeasy/util/Serializers.kt b/src/main/java/org/holoeasy/util/Serializers.kt
deleted file mode 100644
index d8a5484..0000000
--- a/src/main/java/org/holoeasy/util/Serializers.kt
+++ /dev/null
@@ -1,16 +0,0 @@
-package org.holoeasy.util
-
-import com.comphenix.protocol.wrappers.WrappedDataWatcher
-
-val BYTE_SERIALIZER : WrappedDataWatcher.Serializer
- get() = WrappedDataWatcher.Registry.get(java.lang.Byte::class.java)
-
-val BOOL_SERIALIZER : WrappedDataWatcher.Serializer
- get() = WrappedDataWatcher.Registry.get(java.lang.Boolean::class.java)
-
-val STRING_SERIALIZER : WrappedDataWatcher.Serializer
- get() = WrappedDataWatcher.Registry.get(java.lang.String::class.java)
-
-val ITEM_SERIALIZER : WrappedDataWatcher.Serializer
- get() = WrappedDataWatcher.Registry.getItemStackSerializer(false)
-
diff --git a/src/main/java/org/holoeasy/util/VersionUtil.kt b/src/main/java/org/holoeasy/util/VersionUtil.kt
deleted file mode 100644
index c8d4395..0000000
--- a/src/main/java/org/holoeasy/util/VersionUtil.kt
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Hologram-Lib - Asynchronous, high-performance Minecraft Hologram
- * library for 1.8-1.18 servers.
- * Copyright (C) unldenis
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package org.holoeasy.util
-
-import org.bukkit.Bukkit
-import java.util.*
-
-object VersionUtil {
- private val VERSION: String
-
- val CLEAN_VERSION: VersionEnum
-
- init {
- val bpName = Bukkit.getServer().javaClass.getPackage().name
- VERSION = bpName.substring(bpName.lastIndexOf(".") + 1)
- val clean = VERSION.substring(0, VERSION.length - 3)
- CLEAN_VERSION = VersionEnum.valueOf(clean.uppercase(Locale.getDefault()))
- }
-
- fun isCompatible(ve: VersionEnum): Boolean {
- return VERSION.lowercase(Locale.getDefault()).contains(ve.toString().lowercase(Locale.getDefault()))
- }
-
- fun isAbove(ve: VersionEnum): Boolean {
- return CLEAN_VERSION.ordinal >= ve.ordinal
- }
-
- fun isBelow(ve: VersionEnum): Boolean {
- return CLEAN_VERSION.ordinal <= ve.ordinal
- }
-
- fun isBetween(ve1: VersionEnum, ve2: VersionEnum): Boolean {
- return isAbove(ve1) && isBelow(ve2)
- }
-
-}
-
-
-enum class VersionEnum(armorstandId: Int, droppedItemId : Int) : Comparable {
- MOCKBUK, // MockBukkit Test
-
- V1_8(30, 1),
- V1_9,
- V1_10,
- V1_11,
- V1_12,
- V1_13(1, 32),
- V1_14(1, 34),
- V1_15(1, 35),
- V1_16(1, 37),
- V1_17(1, 41),
- V1_18,
- V1_19(2, 55),
- V1_20,
-
- // for non breaking in future
- V1_21,
- V1_22
- ;
-
- var armorstandId : Int
- private set
- get() {
- if(field == -1) {
- field = entries
- .last { it.newNMS && it.ordinal < ordinal }
- .armorstandId
- }
- return field
- }
- var droppedItemId : Int
- private set
- get() {
- if(field == -1) {
- field = entries
- .last { it.newNMS && it.ordinal < ordinal }
- .droppedItemId
- }
- return field
- }
-
- private var newNMS : Boolean
-
- init {
- this.armorstandId = armorstandId
- this.droppedItemId = droppedItemId
- this.newNMS = true
- }
-
- constructor() : this(-1, -1) {
- newNMS = false
- }
-
-
- // retrieved with https://www.spigotmc.org/threads/entity-id-fetcher-for-protocol-use.444784/
- // var versions: Array = arrayOf(
- // "1.8.9",
- // "1.9.4",
- // "1.10.2",
- // "1.11.2",
- // "1.12.2",
- // "1.13.2",
- // "1.14.4",
- // "1.15.2",
- // "1.16.5",
- // "1.17.1",
- // "1.18.2",
- // "1.19.4",
- // "1.20.4"
- // )
-}
\ No newline at end of file