9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-26 02:19:28 +00:00
This commit is contained in:
Xiao-MoMi
2022-08-07 23:08:23 +08:00
parent 9b6f40d894
commit 9c696a9578
29 changed files with 237 additions and 200 deletions

View File

@@ -4,7 +4,7 @@ plugins {
}
group = 'net.momirealms'
version = '1.8.1'
version = '1.8.4'
repositories {
mavenCentral()
@@ -44,7 +44,7 @@ dependencies {
implementation('net.kyori:adventure-api:4.11.0')
implementation('net.kyori:adventure-platform-bukkit:4.1.1')
implementation('net.kyori:adventure-text-minimessage:4.11.0')
implementation("net.kyori:adventure-text-serializer-gson:4.11.0")
implementation('net.kyori:adventure-text-serializer-gson:4.11.0')
}
def targetJavaVersion = 16

View File

@@ -41,6 +41,7 @@ public class ConfigManager {
public static TreeMap<String, BossBarConfigP> bossbarsP = new TreeMap<>();
public static HashMap<String, BGInfo> papiBG = new HashMap<>();
public static HashMap<String, NPInfo> papiNP = new HashMap<>();
public static HashMap<Character, Integer> fontWidth = new HashMap<>();
public static YamlConfiguration getConfig(String configName) {
File file = new File(CustomNameplates.instance.getDataFolder(), configName);
@@ -65,6 +66,18 @@ public class ConfigManager {
useAdventure = bossbarmode.getString("mode").equalsIgnoreCase("Adventure");
}
public static void loadWidth(){
fontWidth.clear();
YamlConfiguration config = getConfig("char-width.yml");
config.getConfigurationSection("").getKeys(false).forEach(key -> {
fontWidth.put(key.charAt(0), config.getInt(key));
});
AdventureManager.consoleMessage("<gradient:#2E8B57:#48D1CC>[CustomNameplates]</gradient> <color:#baffd1>Loaded <white>" + fontWidth.size() + " <color:#baffd1>custom char width");
}
public static class MainConfig{
public static String namespace;
public static String fontName;

View File

@@ -30,7 +30,6 @@ import net.momirealms.customnameplates.data.SqlHandler;
import net.momirealms.customnameplates.helper.LibraryLoader;
import net.momirealms.customnameplates.hook.Placeholders;
import net.momirealms.customnameplates.listener.PlayerListener;
import net.momirealms.customnameplates.listener.PacketsListener;
import net.momirealms.customnameplates.resource.ResourceManager;
import net.momirealms.customnameplates.scoreboard.ScoreBoardManager;
import org.bukkit.Bukkit;
@@ -48,11 +47,10 @@ public final class CustomNameplates extends JavaPlugin {
private ResourceManager resourceManager;
private DataManager dataManager;
private ScoreBoardManager scoreBoardManager;
private Placeholders placeholders;
private Timer timer;
public ResourceManager getResourceManager() {
return this.resourceManager;
}
public ResourceManager getResourceManager() {return this.resourceManager;}
public DataManager getDataManager() { return this.dataManager; }
public ScoreBoardManager getScoreBoardManager() { return this.scoreBoardManager; }
@@ -71,6 +69,7 @@ public final class CustomNameplates extends JavaPlugin {
ConfigManager.loadModule();
ConfigManager.MainConfig.ReloadConfig();
ConfigManager.Message.ReloadConfig();
ConfigManager.loadWidth();
if (ConfigManager.bossbar){
ConfigManager.loadBossBar();
if (ConfigManager.useAdventure){
@@ -89,17 +88,17 @@ public final class CustomNameplates extends JavaPlugin {
if (ConfigManager.nameplate){
ConfigManager.DatabaseConfig.LoadConfig();
Bukkit.getPluginManager().registerEvents(new PlayerListener(this),this);
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketsListener(this));
}
if (ConfigManager.MainConfig.placeholderAPI){
new Placeholders().register();
placeholders = new Placeholders();
placeholders.register();
AdventureManager.consoleMessage("<gradient:#2E8B57:#48D1CC>[CustomNameplates]</gradient> <color:#baffd1>PlaceholderAPI Hooked!");
}
if (ConfigManager.MainConfig.tab){
AdventureManager.consoleMessage("<gradient:#2E8B57:#48D1CC>[CustomNameplates]</gradient> <color:#baffd1>TAB Hooked!");
}
Objects.requireNonNull(Bukkit.getPluginCommand("customnameplates")).setExecutor(new Execute(this));
Objects.requireNonNull(Bukkit.getPluginCommand("customnameplates")).setTabCompleter(new TabComplete(this));
Objects.requireNonNull(Bukkit.getPluginCommand("customnameplates")).setTabCompleter(new TabComplete());
this.resourceManager = new ResourceManager(this);
this.dataManager = new DataManager(this);
this.scoreBoardManager = new ScoreBoardManager(this);
@@ -122,9 +121,27 @@ public final class CustomNameplates extends JavaPlugin {
if (timer != null){
timer.stopTimer(timer.getTaskID());
}
if(adventure != null) {
if (adventure != null) {
adventure.close();
adventure = null;
}
if (protocolManager != null){
protocolManager = null;
}
if (placeholders != null){
placeholders.unregister();
}
if (resourceManager != null){
resourceManager = null;
}
if (scoreBoardManager != null){
scoreBoardManager = null;
}
if (dataManager != null){
dataManager = null;
}
if (instance != null){
instance = null;
}
}
}

View File

@@ -21,7 +21,6 @@ import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.momirealms.customnameplates.ConfigManager;
import net.momirealms.customnameplates.CustomNameplates;

View File

@@ -37,9 +37,9 @@ public class BossBarSenderP extends BukkitRunnable {
public void showBossbar(){
this.packet = new PacketContainer(PacketType.Play.Server.BOSS);
packet.setMeta("id", UUID.randomUUID());
this.overlay = bossbarConfig.getOverlay();
this.barColor = bossbarConfig.getColor();
packet.getModifier().write(0, UUID.randomUUID());
InternalStructure internalStructure = packet.getStructures().read(1);
if (ConfigManager.MainConfig.placeholderAPI){
this.text = PlaceholderAPI.setPlaceholders(player, bossbarConfig.getText());

View File

@@ -31,10 +31,11 @@ import net.momirealms.customnameplates.AdventureManager;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.data.DataManager;
import net.momirealms.customnameplates.font.FontCache;
import net.momirealms.customnameplates.hook.ParsePapi;
import net.momirealms.customnameplates.hook.PapiHook;
import net.momirealms.customnameplates.hook.TABHook;
import net.momirealms.customnameplates.nameplates.NameplateUtil;
import net.momirealms.customnameplates.scoreboard.NameplatesTeam;
import net.momirealms.customnameplates.scoreboard.ScoreBoardManager;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -80,6 +81,7 @@ public class Execute implements CommandExecutor {
if (sender.hasPermission("customnameplates.reload") || sender.isOp()) {
ConfigManager.MainConfig.ReloadConfig();
ConfigManager.Message.ReloadConfig();
ConfigManager.loadWidth();
if (ConfigManager.actionbar){
ConfigManager.ActionbarConfig.LoadConfig();
}
@@ -123,9 +125,9 @@ public class Execute implements CommandExecutor {
}
DataManager.cache.get(player.getUniqueId()).equipNameplate(args[1]);
if (ConfigManager.MainConfig.tab){
this.plugin.getScoreBoardManager().getTeam(TABHook.getTABTeam(player.getName())).updateNameplates();
ScoreBoardManager.teams.get(TABHook.getTABTeam(player.getName())).updateNameplates();
}else {
this.plugin.getScoreBoardManager().getTeam(player.getName()).updateNameplates();
ScoreBoardManager.teams.get(player.getName()).updateNameplates();
}
this.plugin.getDataManager().savePlayer(player.getUniqueId());
AdventureManager.playerMessage((Player) sender, ConfigManager.Message.prefix + ConfigManager.Message.equip.replace("{Nameplate}", plugin.getResourceManager().getNameplateInfo(args[1]).getConfig().getName()));
@@ -160,9 +162,9 @@ public class Execute implements CommandExecutor {
}
DataManager.cache.get(player.getUniqueId()).equipNameplate(args[2]);
if (ConfigManager.MainConfig.tab){
this.plugin.getScoreBoardManager().getTeam(TABHook.getTABTeam(args[1])).updateNameplates();
ScoreBoardManager.teams.get(TABHook.getTABTeam(args[1])).updateNameplates();
}else {
this.plugin.getScoreBoardManager().getTeam(args[1]).updateNameplates();
ScoreBoardManager.teams.get(args[1]).updateNameplates();
}
this.plugin.getDataManager().savePlayer(player.getUniqueId());
if (sender instanceof Player){
@@ -187,9 +189,9 @@ public class Execute implements CommandExecutor {
if (sender instanceof Player player){
DataManager.cache.get(player.getUniqueId()).equipNameplate("none");
if (ConfigManager.MainConfig.tab){
this.plugin.getScoreBoardManager().getTeam(TABHook.getTABTeam(player.getName())).updateNameplates();
ScoreBoardManager.teams.get(TABHook.getTABTeam(player.getName())).updateNameplates();
}else {
this.plugin.getScoreBoardManager().getTeam(player.getName()).updateNameplates();
ScoreBoardManager.teams.get(player.getName()).updateNameplates();
}
this.plugin.getDataManager().savePlayer(player.getUniqueId());
AdventureManager.playerMessage(player, ConfigManager.Message.prefix + ConfigManager.Message.unequip);
@@ -212,9 +214,9 @@ public class Execute implements CommandExecutor {
Player player = Bukkit.getPlayer(args[1]);
DataManager.cache.get(player.getUniqueId()).equipNameplate("none");
if (ConfigManager.MainConfig.tab){
this.plugin.getScoreBoardManager().getTeam(TABHook.getTABTeam(args[1])).updateNameplates();
ScoreBoardManager.teams.get(TABHook.getTABTeam(args[1])).updateNameplates();
}else {
this.plugin.getScoreBoardManager().getTeam(args[1]).updateNameplates();
ScoreBoardManager.teams.get(args[1]).updateNameplates();
}
this.plugin.getDataManager().savePlayer(player.getUniqueId());
if (sender instanceof Player){
@@ -293,8 +295,8 @@ public class Execute implements CommandExecutor {
String playerPrefix;
String playerSuffix;
if (ConfigManager.MainConfig.placeholderAPI) {
playerPrefix = ParsePapi.parsePlaceholders(player, ConfigManager.MainConfig.player_prefix);
playerSuffix = ParsePapi.parsePlaceholders(player, ConfigManager.MainConfig.player_suffix);
playerPrefix = PapiHook.parsePlaceholders(player, ConfigManager.MainConfig.player_prefix);
playerSuffix = PapiHook.parsePlaceholders(player, ConfigManager.MainConfig.player_suffix);
}else {
playerPrefix = ConfigManager.MainConfig.player_prefix;
playerSuffix = ConfigManager.MainConfig.player_suffix;
@@ -345,6 +347,7 @@ public class Execute implements CommandExecutor {
AdventureManager.playerMessage(player,"<color:#87CEFA>/nameplates preview - <color:#7FFFAA>preview your nameplate");
AdventureManager.playerMessage(player,"<color:#87CEFA>/nameplates forcepreview <player> <nameplate> - <color:#7FFFAA>force a player to preview a nameplate");
AdventureManager.playerMessage(player,"<color:#87CEFA>/nameplates list - <color:#7FFFAA>list your available nameplates");
AdventureManager.playerMessage(player,"<color:#87CEFA>/nameplates generate - <color:#7FFFAA>generate the RP");
}
}else {
AdventureManager.consoleMessage("<color:#87CEFA>/nameplates help - <color:#7FFFAA>show the command list");
@@ -356,6 +359,7 @@ public class Execute implements CommandExecutor {
AdventureManager.consoleMessage("<color:#87CEFA>/nameplates preview - <color:#7FFFAA>preview your nameplate");
AdventureManager.consoleMessage("<color:#87CEFA>/nameplates forcepreview <player> <nameplate> - <color:#7FFFAA>force a player to preview a nameplate");
AdventureManager.consoleMessage("<color:#87CEFA>/nameplates list - <color:#7FFFAA>list your available nameplates");
AdventureManager.consoleMessage("<color:#87CEFA>/nameplates generate - <color:#7FFFAA>generate the RP");
}
return true;
}
@@ -364,6 +368,7 @@ public class Execute implements CommandExecutor {
}
private void showNameplate(Player player, Component component) {
ArmorStand entity = player.getWorld().spawn(player.getLocation().add(0,0.8,0), ArmorStand.class, a -> {
a.setInvisible(true);
a.setCollidable(false);

View File

@@ -17,7 +17,7 @@
package net.momirealms.customnameplates.commands;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.resource.ResourceManager;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
@@ -33,12 +33,6 @@ import java.util.List;
public class TabComplete implements TabCompleter {
private final CustomNameplates plugin;
public TabComplete(CustomNameplates plugin){
this.plugin = plugin;
}
@Override
@ParametersAreNonnullByDefault
public @Nullable List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
@@ -95,7 +89,7 @@ public class TabComplete implements TabCompleter {
String permission = info.getPermission().toLowerCase();
if (permission.startsWith("customnameplates.equip.")) {
permission = StringUtils.replace(permission, "customnameplates.equip.", "");
if (this.plugin.getResourceManager().caches.get(permission) != null){
if (ResourceManager.caches.get(permission) != null){
availableNameplates.add(permission);
}
}
@@ -105,6 +99,6 @@ public class TabComplete implements TabCompleter {
}
private List<String> nameplates(){
return new ArrayList<>(this.plugin.getResourceManager().caches.keySet());
return new ArrayList<>(ResourceManager.caches.keySet());
}
}

View File

@@ -17,6 +17,8 @@
package net.momirealms.customnameplates.font;
import net.momirealms.customnameplates.ConfigManager;
public enum FontWidth {
A('A', 5), a('a', 5), B('B', 5), b('b', 5),
@@ -72,13 +74,18 @@ public enum FontWidth {
/*
获取每个字符的像素宽度
*/
public static FontWidth getInfo(char c) {
public static int getInfo(char c) {
for (FontWidth minecraftFontWidth : values()) {
if (minecraftFontWidth.getCharacter() == c) {
return minecraftFontWidth;
return minecraftFontWidth.length;
}
}
return FontWidth.DEFAULT;
int custom = ConfigManager.fontWidth.get(c);
if (custom != 0){
return custom;
}else {
return 8;
}
}
/*
@@ -88,8 +95,8 @@ public enum FontWidth {
int length = s.length();
int n = 0;
for (int i = 0; i < length; i++) {
n += getInfo(s.charAt(i)).getLength();
n += getInfo(s.charAt(i));
}
return n + FontWidth.IN_BETWEEN.getLength() * (length - 1); //总长还需加上字符间距
return n + length - 1; //总长还需加上字符间距
}
}

View File

@@ -17,6 +17,8 @@
package net.momirealms.customnameplates.font;
import net.momirealms.customnameplates.ConfigManager;
public enum FontWidthThin {
A('A', 3), a('a', 3), B('B', 3), b('b', 3),
@@ -72,13 +74,18 @@ public enum FontWidthThin {
/*
获取每个字符的像素宽度
*/
public static FontWidthThin getInfo(char c) {
public static int getInfo(char c) {
for (FontWidthThin minecraftFontWidth : values()) {
if (minecraftFontWidth.getCharacter() == c) {
return minecraftFontWidth;
return minecraftFontWidth.length;
}
}
return FontWidthThin.DEFAULT;
int custom = ConfigManager.fontWidth.get(c);
if (custom != 0){
return custom;
}else {
return 8;
}
}
/*
@@ -88,8 +95,8 @@ public enum FontWidthThin {
int length = s.length();
int n = 0;
for (int i = 0; i < length; i++) {
n += getInfo(s.charAt(i)).getLength();
n += getInfo(s.charAt(i));
}
return n + FontWidthThin.IN_BETWEEN.getLength() * (length - 1); //总长还需加上字符间距
return n + length - 1; //总长还需加上字符间距
}
}

View File

@@ -18,13 +18,11 @@
package net.momirealms.customnameplates.hook;
import me.clip.placeholderapi.PlaceholderAPI;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Player;
public class ParsePapi {
public class PapiHook {
public static String parsePlaceholders(Player player, String papi) {
String s = StringUtils.replace(StringUtils.replace(papi, "%player_name%", player.getName()), "%player_displayname%", player.getDisplayName());
return PlaceholderAPI.setPlaceholders(player, s);
return PlaceholderAPI.setPlaceholders(player, papi);
}
}

View File

@@ -1,81 +0,0 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* 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
* 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 <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.listener;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.InternalStructure;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.momirealms.customnameplates.ConfigManager;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.data.DataManager;
import net.momirealms.customnameplates.scoreboard.NameplatesTeam;
import org.bukkit.ChatColor;
import java.util.Optional;
public class PacketsListener extends PacketAdapter {
private final CustomNameplates plugin;
public PacketsListener(CustomNameplates plugin) {
super(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.SCOREBOARD_TEAM);
this.plugin = plugin;
}
public void onPacketSending(PacketEvent event) {
Integer n = event.getPacket().getIntegers().read(0);
if (n != 2) {
return;
}
//if (n == 0) System.out.println("对玩家" + event.getPlayer().getName() + "发送team创建包");
//if (n == 2) System.out.println("对玩家"+ event.getPlayer().getName() + "发送team更新包");
Optional<InternalStructure> optional = event.getPacket().getOptionalStructures().read(0);
if (optional.isEmpty()) {
return;
}
InternalStructure internalStructure = optional.get();
String teamName = event.getPacket().getStrings().read(0);
//System.out.println("本次创建/更新的队伍名是" + teamName);
NameplatesTeam team = this.plugin.getScoreBoardManager().getTeam(teamName);
if (team == null) {
//System.out.println("但是这个队伍不存在于缓存中哦,说明那个玩家还没上线");
return;
}
//System.out.println("这个队伍确实存在于缓存中呢!");
if (ConfigManager.MainConfig.show_after && (DataManager.cache.get(event.getPlayer().getUniqueId()) == null || DataManager.cache.get(event.getPlayer().getUniqueId()).getAccepted() == 0)) {
//System.out.println("玩家" +event.getPlayer().getName() +"因为没有接受资源包所以没有被显示铭牌");
internalStructure.getChatComponents().write(1, WrappedChatComponent.fromJson("{\"text\":\"\"}"));
internalStructure.getChatComponents().write(2, WrappedChatComponent.fromJson("{\"text\":\"\"}"));
internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,ChatColor.WHITE);
return;
}
//System.out.println("玩家" +event.getPlayer().getName() +"可以看见队伍" + teamName + "的铭牌");
if (team.getPrefix() != null) {
internalStructure.getChatComponents().write(1, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(team.getPrefix())));
}
if (team.getSuffix() != null) {
internalStructure.getChatComponents().write(2, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(team.getSuffix())));
}
internalStructure.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,team.getColor());
}
}

View File

@@ -17,20 +17,31 @@
package net.momirealms.customnameplates.listener;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.InternalStructure;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.momirealms.customnameplates.ConfigManager;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.data.DataManager;
import net.momirealms.customnameplates.data.PlayerData;
import net.momirealms.customnameplates.hook.TABHook;
import net.momirealms.customnameplates.scoreboard.NameplatesTeam;
import net.momirealms.customnameplates.scoreboard.ScoreBoardManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.Optional;
public record PlayerListener(CustomNameplates plugin) implements Listener {
@@ -38,30 +49,20 @@ public record PlayerListener(CustomNameplates plugin) implements Listener {
public void onJoin(PlayerJoinEvent event) {
this.plugin.getDataManager().loadData(event.getPlayer());
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomNameplates.instance, ()-> {
if (ConfigManager.MainConfig.tab){
Bukkit.getOnlinePlayers().forEach(player -> this.plugin.getScoreBoardManager().getTeam(TABHook.getTABTeam(player.getName())).updateNameplates());
}else {
Bukkit.getOnlinePlayers().forEach(player -> this.plugin.getScoreBoardManager().getTeam(player.getName()).updateNameplates());
}
}, 50);
sendPacketsToPlayer(event.getPlayer());
}, 40);
}
@EventHandler
public void onQuit(PlayerQuitEvent event) {
this.plugin.getDataManager().unloadPlayer(event.getPlayer().getUniqueId());
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
Team team;
String teamName;
if (ConfigManager.MainConfig.tab){
teamName = TABHook.getTABTeam(event.getPlayer().getName());
}else {
teamName = event.getPlayer().getName();
}
team = scoreboard.getTeam(teamName);
ScoreBoardManager.teams.remove(teamName);
if (team != null){
team.unregister();
}
}
@EventHandler
@@ -73,19 +74,58 @@ public record PlayerListener(CustomNameplates plugin) implements Listener {
}
if (event.getStatus() == PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED) {
playerData.setAccepted(1);
if (ConfigManager.MainConfig.tab){
Bukkit.getOnlinePlayers().forEach(player -> this.plugin.getScoreBoardManager().getTeam(TABHook.getTABTeam(player.getName())).updateNameplates());
}else {
Bukkit.getOnlinePlayers().forEach(player -> this.plugin.getScoreBoardManager().getTeam(player.getName()).updateNameplates());
}
} else if(event.getStatus() == PlayerResourcePackStatusEvent.Status.DECLINED || event.getStatus() == PlayerResourcePackStatusEvent.Status.FAILED_DOWNLOAD) {
playerData.setAccepted(0);
if (ConfigManager.MainConfig.tab){
Bukkit.getOnlinePlayers().forEach(player -> this.plugin.getScoreBoardManager().getTeam(TABHook.getTABTeam(player.getName())).updateNameplates());
}else {
Bukkit.getOnlinePlayers().forEach(player -> this.plugin.getScoreBoardManager().getTeam(player.getName()).updateNameplates());
}
}
else if(event.getStatus() == PlayerResourcePackStatusEvent.Status.DECLINED || event.getStatus() == PlayerResourcePackStatusEvent.Status.FAILED_DOWNLOAD) {
playerData.setAccepted(0);
}
sendPacketsToPlayer(event.getPlayer());
}, 20);
}
private void sendPacketsToPlayer(Player player){
if (ConfigManager.MainConfig.show_after && DataManager.cache.get(player.getUniqueId()).getAccepted() != 1) return;
Bukkit.getOnlinePlayers().forEach(onlinePlayer -> {
String teamName;
if (ConfigManager.MainConfig.tab){
teamName = TABHook.getTABTeam(onlinePlayer.getName());
}else {
teamName = onlinePlayer.getName();
}
NameplatesTeam team = ScoreBoardManager.teams.get(teamName);
if (team == null) return;
PacketContainer packetContainer = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
packetContainer.getStrings().write(0, teamName);
Optional<InternalStructure> optional = packetContainer.getOptionalStructures().read(0);
if (optional.isEmpty()) {
return;
}
InternalStructure internalStructure1 = optional.get();
internalStructure1.getChatComponents().write(0, WrappedChatComponent.fromJson("{\"text\":\" "+ onlinePlayer.getName() +" \"}"));
if (team.getPrefix() != null){
internalStructure1.getChatComponents().write(1, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(team.getPrefix())));
}
if (team.getSuffix() != null){
internalStructure1.getChatComponents().write(2, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(team.getSuffix())));
}
internalStructure1.getEnumModifier(ChatColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0,team.getColor());
packetContainer.getModifier().write(2, Collections.singletonList(onlinePlayer.getName()));
try {
CustomNameplates.protocolManager.sendServerPacket(player, packetContainer);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
});
}
}

View File

@@ -96,6 +96,14 @@ public class ResourceManager {
if (ConfigManager.MainConfig.anotherFont){
JsonObject jsonObject_3 = new JsonObject();
jsonObject_3.add("type", new JsonPrimitive("space"));
JsonObject jsonObject_4 = new JsonObject();
jsonObject_4.add(" ", new JsonPrimitive(4));
jsonObject_4.add("\\u200c", new JsonPrimitive(0));
jsonObject_3.add("advances", jsonObject_4);
jsonArray_1.add(jsonObject_3);
JsonObject jsonObject_2 = new JsonObject();
jsonObject_2.add("type", new JsonPrimitive("bitmap"));
jsonObject_2.add("file", new JsonPrimitive("minecraft:font/ascii.png"));
@@ -120,14 +128,6 @@ public class ResourceManager {
jsonArray_2.add("\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000");
jsonObject_2.add("chars", jsonArray_2);
jsonArray_1.add(jsonObject_2);
JsonObject jsonObject_3 = new JsonObject();
jsonObject_3.add("type", new JsonPrimitive("space"));
JsonObject jsonObject_4 = new JsonObject();
jsonObject_4.add(" ", new JsonPrimitive(4));
jsonObject_4.add("", new JsonPrimitive(0));
jsonObject_3.add("advances", jsonObject_4);
jsonArray_1.add(jsonObject_3);
}
if (ConfigManager.nameplate){

View File

@@ -24,14 +24,11 @@ import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.data.DataManager;
import net.momirealms.customnameplates.data.PlayerData;
import net.momirealms.customnameplates.font.FontCache;
import net.momirealms.customnameplates.hook.ParsePapi;
import net.momirealms.customnameplates.hook.PapiHook;
import net.momirealms.customnameplates.hook.TABHook;
import net.momirealms.customnameplates.nameplates.NameplateUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import java.util.Optional;
@@ -39,7 +36,6 @@ public class NameplatesTeam {
private final CustomNameplates plugin;
private final Player player;
private final Team team;
private Component prefix;
private Component suffix;
private String prefixText;
@@ -58,16 +54,11 @@ public class NameplatesTeam {
this.color = ChatColor.WHITE;
this.plugin = plugin;
this.player = player;
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
String name = player.getName();
if (ConfigManager.MainConfig.tab){
this.teamName = TABHook.getTABTeam(name);
this.team = Optional.ofNullable(Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName)).orElseGet(() -> scoreboard.registerNewTeam(teamName));
team.addEntry(player.getName());
}else {
this.teamName = name;
this.team = Optional.ofNullable(Bukkit.getScoreboardManager().getMainScoreboard().getTeam(name)).orElseGet(() -> scoreboard.registerNewTeam(name));
team.addEntry(player.getName());
}
}
@@ -81,8 +72,8 @@ public class NameplatesTeam {
}
if (nameplate.equals("none")) {
if (ConfigManager.MainConfig.placeholderAPI) {
this.prefix = MiniMessage.miniMessage().deserialize(ParsePapi.parsePlaceholders(this.player, ConfigManager.MainConfig.player_prefix));
this.suffix = MiniMessage.miniMessage().deserialize(ParsePapi.parsePlaceholders(this.player, ConfigManager.MainConfig.player_suffix));
this.prefix = MiniMessage.miniMessage().deserialize(PapiHook.parsePlaceholders(this.player, ConfigManager.MainConfig.player_prefix));
this.suffix = MiniMessage.miniMessage().deserialize(PapiHook.parsePlaceholders(this.player, ConfigManager.MainConfig.player_suffix));
this.prefixText = "";
this.suffixText = "";
} else {
@@ -92,7 +83,6 @@ public class NameplatesTeam {
this.suffixText = "";
}
this.color = ChatColor.WHITE;
this.team.setPrefix("");
return;
}
FontCache fontCache = this.plugin.getResourceManager().getNameplateInfo(nameplate);
@@ -100,7 +90,6 @@ public class NameplatesTeam {
this.prefix = Component.text("");
this.suffix = Component.text("");
this.color = ChatColor.WHITE;
this.team.setPrefix("");
DataManager.cache.get(player.getUniqueId()).equipNameplate("none");
return;
}
@@ -110,16 +99,17 @@ public class NameplatesTeam {
String playerSuffix;
if (ConfigManager.MainConfig.placeholderAPI) {
if (!ConfigManager.MainConfig.hidePrefix){
playerPrefix = ParsePapi.parsePlaceholders(this.player, ConfigManager.MainConfig.player_prefix);
playerPrefix = PapiHook.parsePlaceholders(this.player, ConfigManager.MainConfig.player_prefix);
}else {
playerPrefix = "";
}
if (!ConfigManager.MainConfig.hideSuffix){
playerSuffix = ParsePapi.parsePlaceholders(this.player, ConfigManager.MainConfig.player_suffix);
playerSuffix = PapiHook.parsePlaceholders(this.player, ConfigManager.MainConfig.player_suffix);
}else {
playerSuffix = "";
}
}else {
}
else {
if (!ConfigManager.MainConfig.hidePrefix){
playerPrefix = ConfigManager.MainConfig.player_prefix;
}else {
@@ -135,11 +125,6 @@ public class NameplatesTeam {
this.suffixText = nameplateUtil.getSuffixLength(MiniMessage.miniMessage().stripTags(playerPrefix) + name + MiniMessage.miniMessage().stripTags(playerSuffix));
this.prefix = Component.text(nameplateUtil.makeCustomNameplate(MiniMessage.miniMessage().stripTags(playerPrefix), name, MiniMessage.miniMessage().stripTags(playerSuffix))).font(ConfigManager.MainConfig.key).append(MiniMessage.miniMessage().deserialize(playerPrefix));
this.suffix = MiniMessage.miniMessage().deserialize(playerSuffix).append(Component.text(nameplateUtil.getSuffixLength(MiniMessage.miniMessage().stripTags(playerPrefix) + name + MiniMessage.miniMessage().stripTags(playerSuffix))).font(ConfigManager.MainConfig.key));
// this.prefixText = nameplateUtil.makeCustomNameplate(playerPrefix, name, playerSuffix) + playerPrefix;
// this.suffixText = playerSuffix + nameplateUtil.getSuffixLength(playerPrefix + name + playerSuffix);
// this.prefix = Component.text(nameplateUtil.makeCustomNameplate(playerPrefix, name, playerSuffix)).font(ConfigManager.MainConfig.key).append(Component.text(playerPrefix).font(Key.key("default")));
// this.suffix = Component.text(playerSuffix).append(Component.text(nameplateUtil.getSuffixLength(playerPrefix + name + playerSuffix)).font(ConfigManager.MainConfig.key));
this.color = nameplateUtil.getColor();
this.team.setPrefix("");
}
}

View File

@@ -35,22 +35,15 @@ public record ScoreBoardManager(CustomNameplates plugin) {
if (!teams.containsKey(tabTeamName)) {
teams.put(tabTeamName, new NameplatesTeam(this.plugin, player));
}
this.getTeam(tabTeamName).updateNameplates();
teams.get(tabTeamName).updateNameplates();
return teams.get(tabTeamName);
} else {
}
else {
if (!teams.containsKey(player.getName())) {
teams.put(player.getName(), new NameplatesTeam(this.plugin, player));
}
this.getTeam(player.getName()).updateNameplates();
teams.get(player.getName()).updateNameplates();
return teams.get(player.getName());
}
}
public void removeTeam(String teamName) {
teams.remove(teamName);
}
public NameplatesTeam getTeam(String teamName) {
return teams.get(teamName);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -4,12 +4,11 @@
# mode: Adventure / ProtocolLib
# There's a bug that font can't be applied to Adventure bossbar. This is an Adventure API bug that I can't fix for the moment.
# So I made the ProtocolLib mode and I will remove ProtocolLib mode when Adventure API is fixed!
# ProtocolLib mode doesn't support multiple bossbars for the moment.
# It requires a restart to change mode
mode: ProtocolLib
bossbar:
example:
example_1:
text: '<font:nameplates:default><color:#FFFEFD>%nameplates_bg_player%Hello! %player_name%</font> <font:nameplates:default><color:#FFFEFD>%nameplates_bg_pos%You are now at: %player_x%, %player_y%, %player_z%</font>'
refresh-rate: 5
# PINK
@@ -25,4 +24,21 @@ bossbar:
# NOTCHED_10
# NOTCHED_12
# NOTCHED_20
overlay: PROGRESS
overlay: PROGRESS
example_2:
text: 'Another BossBar'
refresh-rate: 5
# PINK
# YELLOW
# WHITE
# RED
# PURPLE
# GREEN
# BLUE
color: RED
# PROGRESS
# NOTCHED_6
# NOTCHED_10
# NOTCHED_12
# NOTCHED_20
overlay: NOTCHED_10

View File

@@ -0,0 +1,6 @@
# Font is processed by client
# Server side doesn't know the width of you custom font
# So you can tell the plugin each character's width here
: 8
: 8
: 8

View File

@@ -56,7 +56,10 @@ config:
# Placeholder based prefix and suffix system. When enabled, it is recommended
# to use PlaceholderAPI to be able to use this feature to the fullest extent.
# keep it empty if you don't want to enable this feature.
prefix: '<font:default><rainbow>Hello!</rainbow></font> '
# You should make sure the papi doesn't contain "&" (legacy color code)
# Nameplates work on the custom font system where legacy color code is not supported!
# Please use minimessage format: https://docs.adventure.kyori.net/minimessage/format.html
prefix: '<font:default><rainbow>Hello! </rainbow></font>'
suffix: ''
# should prefix/suffix be hidden when player is equipping a nameplate

View File

@@ -13,6 +13,9 @@ papi:
pos:
text: 'You are now at: %player_x%, %player_y%, %player_z%'
background: bedrock_1
text:
text: 'Thanks for your purchase!'
background: bedrock_2
#This papi will not return text with nameplate
#It will only return the nameplate

View File

@@ -12,6 +12,38 @@ softdepend:
- Oraxen
commands:
customnameplates:
usage: /customnameplates help
usage: /customnameplates
aliases:
- nameplates
- nameplates
permissions:
nameplates.*:
description: Gives access to all nameplates commands
children:
nameplates.generate: true
nameplates.reload: true
nameplates.forceequip: true
nameplates.forceunequip: true
nameplates.help: true
nameplates.unequip: true
nameplates.preview: true
nameplates.list: true
nameplates.generate:
default: op
nameplates.reload:
default: op
nameplates.forceequip:
default: op
nameplates.forceunequip:
default: op
nameplates.help:
default: op
nameplates.unequip:
default: true
nameplates.preview:
default: true
nameplates.list:
default: true
nameplates.equip:
default: true