diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 919ce1f..1bec35e 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -1,7 +1,10 @@
-
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
index a55e7a1..79ee123 100644
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 61a8e18..7537e5f 100644
--- a/README.md
+++ b/README.md
@@ -5,13 +5,19 @@
Replace your players' boring old name tags with customizable ones based on
-text displays!
+text displays! (Thanks to [EntityLib](https://github.com/Tofaa2/EntityLib)!)
+
+
+
+
+
+
## Configuration
Currently, you can customize default name tags and create grouped name tags.
-You can also choose if players get to see their own name tags (Disabled by default).
+Install the plugin and access the `plugins/NameTags/config.yml` for more information.
## API
@@ -65,27 +71,65 @@ class MyCustomListener implements Listener {
```
-## Roadmap
+
+ Kotlin example
-- `/feat/rel_placeholders`
- Currently the plugin does not support PlaceholderAPI's
- relational placeholders.
+Here is a brief example of Kotlin usage, and shows that you can use the nametags on entities other than just Players!
+In this example, a dropped item will display a timer of 4 seconds before it is removed from the world, with a timer above it!
-- `/feat/align`
- Ability to specify text align.
-
- e.g We want to align `z` on the right side, `y` on the left.
+```kt
+@EventHandler
+fun onItemSpawn(event: ItemSpawnEvent) = event.apply {
+ entity.isPersistent = false
+
+ // Armour and tools should take longer to despawn
+ val ticksTillRemove = 80 // 4 seconds
+
+ val nameTagEntity = NameTags.getInstance()
+ .entityManager
+ .getOrCreateNameTagEntity(entity)
+
+ nameTagEntity.modify { meta ->
+ meta.isShadow = true
+ meta.viewRange = 90f
+ meta.backgroundColor = NameTags.TRANSPARENT
+ meta.translation = Vector3f(0f, 0.45f, 0f)
+ meta.billboardConstraints = AbstractDisplayMeta.BillboardConstraints.VERTICAL
+ meta.textOpacity = (-180).toByte()
+ }
- ```
- | z |
- | xxxxx |
- | y |
- ```
+ var counter = ticksTillRemove / 20L
+ val update = runAsyncRepeat(20) {
+ counter--
+ nameTagEntity.modify { meta ->
+ meta.text = Component.text(counter.toString()).color(NamedTextColor.RED)
+ }
+ }
+
+ runSyncLater(ticksTillRemove) {
+ update?.cancel()
+
+ NameTags.getInstance()
+ .entityManager
+ .removeEntity(entity)
+ ?.destroy()
+
+ if (entity.isValid) {
+ entity.remove()
+ }
+ }
+}
+```
+
+
- We would want to do this by writing `z` and ``.
+## Roadmap
+- `/feat/rel_placeholders`
+ Currently the plugin does not support PlaceholderAPI's
+ relational placeholders.
- `/feat/customization`
Extension plugin to give players ability to customize their own
- name tags by using a command and customizable GUI interface.
\ No newline at end of file
+ name tags by using a command and customizable GUI interface.
diff --git a/build.gradle.kts b/build.gradle.kts
index f28f447..f8ec70f 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -26,6 +26,9 @@ repositories {
maven("https://repo.codemc.io/repository/maven-releases/")
maven("https://maven.evokegames.gg/snapshots")
maven("https://repo.viaversion.com")
+ maven("https://repo.codemc.org/repository/maven-public/") {
+ name = "codemc"
+ }
}
dependencies {
@@ -36,6 +39,7 @@ dependencies {
compileOnly(libs.packet.events)
implementation(libs.entity.lib)
testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
+ compileOnly("net.skinsrestorer:skinsrestorer-api:15.5.1")
}
tasks {
diff --git a/img b/img
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/img
@@ -0,0 +1 @@
+
diff --git a/nametags.gif b/nametags.gif
new file mode 100644
index 0000000..a295f9f
Binary files /dev/null and b/nametags.gif differ
diff --git a/src/main/java/com/mattmx/nametags/EventsListener.java b/src/main/java/com/mattmx/nametags/EventsListener.java
index 9f3aed6..57f4220 100644
--- a/src/main/java/com/mattmx/nametags/EventsListener.java
+++ b/src/main/java/com/mattmx/nametags/EventsListener.java
@@ -1,12 +1,9 @@
package com.mattmx.nametags;
-import com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent;
import com.mattmx.nametags.entity.NameTagEntity;
import com.mattmx.nametags.entity.trait.SneakTrait;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
-import org.bukkit.event.entity.EntityDeathEvent;
-import org.bukkit.event.entity.EntityRemoveEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
diff --git a/src/main/java/com/mattmx/nametags/NameTags.java b/src/main/java/com/mattmx/nametags/NameTags.java
index 38c3577..3e0a9fb 100644
--- a/src/main/java/com/mattmx/nametags/NameTags.java
+++ b/src/main/java/com/mattmx/nametags/NameTags.java
@@ -6,6 +6,7 @@
import com.mattmx.nametags.config.TextFormatter;
import com.mattmx.nametags.entity.NameTagEntityManager;
import com.mattmx.nametags.hook.NeznamyTABHook;
+import com.mattmx.nametags.hook.SkinRestorerHook;
import me.tofaa.entitylib.APIConfig;
import me.tofaa.entitylib.EntityLib;
import me.tofaa.entitylib.spigot.SpigotEntityLibPlatform;
@@ -56,6 +57,7 @@ public void onEnable() {
// packetEvents.getEventManager().registerListener(new GlowingEffectHook());
NeznamyTABHook.inject(this);
+ SkinRestorerHook.inject(this);
Bukkit.getPluginManager().registerEvents(eventsListener, this);
diff --git a/src/main/java/com/mattmx/nametags/hook/SkinRestorerHook.java b/src/main/java/com/mattmx/nametags/hook/SkinRestorerHook.java
new file mode 100644
index 0000000..b06e5f9
--- /dev/null
+++ b/src/main/java/com/mattmx/nametags/hook/SkinRestorerHook.java
@@ -0,0 +1,69 @@
+package com.mattmx.nametags.hook;
+
+import com.mattmx.nametags.NameTags;
+import com.mattmx.nametags.entity.NameTagEntity;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import net.skinsrestorer.api.SkinsRestorer;
+import net.skinsrestorer.api.SkinsRestorerProvider;
+import net.skinsrestorer.api.event.SkinApplyEvent;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitRunnable;
+import org.jetbrains.annotations.NotNull;
+
+public class SkinRestorerHook {
+
+ public static void inject(@NotNull NameTags plugin) {
+ Bukkit.getScheduler().runTask(plugin, SkinRestorerHook::start);
+ }
+
+ private static void start() {
+ final boolean isSkinRestorer = Bukkit.getPluginManager().isPluginEnabled("SkinsRestorer");
+
+ if (!isSkinRestorer) return;
+
+ NameTags plugin = NameTags.getInstance();
+ SkinsRestorer skinsRestorer = SkinsRestorerProvider.get();
+
+ if (skinsRestorer != null) {
+ plugin.getLogger().info("Registering SkinRestorer event listeners.");
+ skinsRestorer.getEventBus().subscribe(plugin, SkinApplyEvent.class, SkinRestorerHook::onSkinApply);
+ } else {
+ plugin.getLogger().warning("SkinsRestorer is enabled, but the API provider is null.");
+ }
+ }
+
+ private static void onSkinApply(SkinApplyEvent event) {
+ Player player = event.getPlayer(Player.class);
+
+ if (player == null) return;
+
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ NameTags plugin = NameTags.getInstance();
+
+ plugin.getEntityManager().removeLastSentPassengersCache(player.getEntityId());
+
+ NameTagEntity entity = plugin.getEntityManager().removeEntity(player);
+
+ if (entity != null) {
+ entity.destroy();
+ }
+
+ NameTagEntity newEntity = plugin.getEntityManager().getOrCreateNameTagEntity(player);
+ newEntity.updateVisibility();
+ newEntity.updateLocation();
+
+ if (plugin.getConfig().getBoolean("show-self", false)) {
+ newEntity.getPassenger().removeViewer(newEntity.getBukkitEntity().getUniqueId());
+ newEntity.getPassenger().addViewer(newEntity.getBukkitEntity().getUniqueId());
+ newEntity.sendPassengerPacket(event.getPlayer(Player.class));
+
+ player.sendMessage(Component.text("Please re-join for update your nametag!").color(NamedTextColor.GREEN));
+ }
+ }
+ }.runTask(NameTags.getInstance());
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 37e8ff1..9cde327 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -10,7 +10,9 @@ depend:
softdepend:
- PlaceholderAPI
- TAB
+ - SkinsRestorer
commands:
nametags-reload:
- description: Reload the config
\ No newline at end of file
+ description: Reload the config
+ permission: nametags.command.reload