Added client side display names (requires Paper 1.20+)

This commit is contained in:
Will FP
2023-11-28 14:27:48 +00:00
parent 70dd3c0d64
commit 1db2671bc5
7 changed files with 210 additions and 0 deletions

View File

@@ -30,11 +30,13 @@ import com.willfp.eco.core.placeholder.context.PlaceholderContext;
import com.willfp.eco.core.proxy.ProxyFactory;
import com.willfp.eco.core.scheduling.Scheduler;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Mob;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -587,6 +589,19 @@ public interface Eco {
@NotNull String args,
@NotNull PlaceholderContext context);
/**
* Set a client-side entity display name.
*
* @param entity The entity.
* @param player The player.
* @param name The display name.
* @param visible If the display name should be forcibly visible.
*/
void setClientsideDisplayName(@NotNull LivingEntity entity,
@NotNull Player player,
@NotNull Component name,
boolean visible);
/**
* Get the instance of eco; the bridge between the api frontend and the implementation backend.
*

View File

@@ -0,0 +1,31 @@
package com.willfp.eco.util;
import com.willfp.eco.core.Eco;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
/**
* Utilities / API methods for entities.
*/
public final class EntityUtils {
/**
* Set a client-side entity display name.
*
* @param entity The entity.
* @param player The player.
* @param name The display name.
* @param visible If the display name should be forcibly visible.
*/
public static void setClientsideDisplayName(@NotNull final LivingEntity entity,
@NotNull final Player player,
@NotNull final Component name,
final boolean visible) {
Eco.get().setClientsideDisplayName(entity, player, name, visible);
}
private EntityUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
}

View File

@@ -0,0 +1,12 @@
@file:JvmName("EntityUtilsExtensions")
package com.willfp.eco.util
import net.kyori.adventure.text.Component
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player
/** @see EntityUtils.setClientsideDisplayName */
fun LivingEntity.setClientsideDisplayName(player: Player, displayName: Component, visible: Boolean) {
EntityUtils.setClientsideDisplayName(this, player, displayName, visible)
}