Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-MX authored Jan 17, 2025
2 parents 07c878b + 8082a4a commit 70728e2
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 25 deletions.
9 changes: 6 additions & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 61 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
</div>

Replace your players' boring old name tags with customizable ones based on
text displays!
text displays! (Thanks to [EntityLib](https://github.com/Tofaa2/EntityLib)!)


<p align="center">
<img width="650px" src=nametags.gif />
</p>


## 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

Expand Down Expand Up @@ -65,27 +71,65 @@ class MyCustomListener implements Listener {

```

## Roadmap
<details>
<summary>Kotlin example</summary>

- `/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()
}
}
}
```

</details>

We would want to do this by writing `<align:right>z` and `<align:left>`.
## 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.
name tags by using a command and customizable GUI interface.
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions img
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file added nametags.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions src/main/java/com/mattmx/nametags/EventsListener.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/mattmx/nametags/NameTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +57,7 @@ public void onEnable() {
// packetEvents.getEventManager().registerListener(new GlowingEffectHook());

NeznamyTABHook.inject(this);
SkinRestorerHook.inject(this);

Bukkit.getPluginManager().registerEvents(eventsListener, this);

Expand Down
69 changes: 69 additions & 0 deletions src/main/java/com/mattmx/nametags/hook/SkinRestorerHook.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
4 changes: 3 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ depend:
softdepend:
- PlaceholderAPI
- TAB
- SkinsRestorer

commands:
nametags-reload:
description: Reload the config
description: Reload the config
permission: nametags.command.reload

0 comments on commit 70728e2

Please sign in to comment.