9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-30 20:29:07 +00:00
This commit is contained in:
Xiao-MoMi
2023-03-29 19:34:32 +08:00
parent f3c08658bd
commit ebd4f44f50
52 changed files with 433 additions and 325 deletions

View File

@@ -29,7 +29,7 @@ import net.momirealms.customnameplates.manager.NameplateManager;
import net.momirealms.customnameplates.object.nameplate.NameplateConfig;
import net.momirealms.customnameplates.object.nameplate.mode.DisplayMode;
import net.momirealms.customnameplates.utils.AdventureUtils;
import net.momirealms.customnameplates.utils.HoloUtils;
import net.momirealms.customnameplates.utils.ArmorStandUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -50,36 +50,30 @@ public class ForcePreviewCommand extends AbstractSubCommand {
Player player = Bukkit.getPlayer(args.get(0));
assert player != null;
NameplateManager nameplateManager = CustomNameplates.getInstance().getNameplateManager();
if (nameplateManager.isInCoolDown(player)) {
AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.coolDown);
return true;
}
String nameplate = args.size() >= 2 ? args.get(1) : nameplateManager.getEquippedNameplate(player);
NameplateConfig nameplateConfig = nameplateManager.getNameplateConfig(nameplate);
if (nameplateConfig == null) {
AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.np_not_exist);
return true;
}
if (nameplateManager.getMode() == DisplayMode.TEAM) {
String nameplate = args.size() >= 2 ? args.get(1) : nameplateManager.getEquippedNameplate(player);
NameplateConfig nameplateConfig = nameplateManager.getNameplateConfig(nameplate);
if (nameplateConfig == null) {
AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.np_not_exist);
return true;
}
String playerPrefix = AdventureUtils.replaceLegacy(PlaceholderAPI.setPlaceholders(player, nameplateManager.getPrefix()));
String playerSuffix = AdventureUtils.replaceLegacy(PlaceholderAPI.setPlaceholders(player, nameplateManager.getSuffix()));
String prefixImage = nameplateManager.getNameplatePrefix(
AdventureUtils.stripAllTags(playerPrefix),
player.getName(),
AdventureUtils.stripAllTags(playerSuffix),
nameplateConfig
);
String suffixImage = nameplateManager.getNameplateSuffix(AdventureUtils.stripAllTags(playerPrefix) + player.getName() + AdventureUtils.stripAllTags(playerSuffix));
String text = AdventureUtils.stripAllTags(playerPrefix) + player.getName() + AdventureUtils.stripAllTags(playerSuffix);
String prefixImage = nameplateManager.getNameplatePrefixWithFont(text, nameplateConfig);
String suffixImage = CustomNameplates.getInstance().getFontManager().getSuffixStringWithFont(text);
Component holoComponent = MiniMessage.miniMessage().deserialize(prefixImage)
.append(Component.text(player.getName()).color(TextColor.color(AdventureUtils.colorToDecimal(nameplateConfig.color()))).font(Key.key("minecraft:default"))
.append(MiniMessage.miniMessage().deserialize(suffixImage)));
HoloUtils.showHolo(holoComponent, player, (int) nameplateManager.getPreview_time());
ArmorStandUtils.preview(holoComponent, player, (int) nameplateManager.getPreview_time());
}
else {
if (!nameplateManager.showPlayerArmorStandTags(player)) {
}
else {
}
nameplateManager.showPlayerArmorStandTags(player, nameplate);
}
return true;
}
@@ -88,7 +82,7 @@ public class ForcePreviewCommand extends AbstractSubCommand {
if (args.size() == 1) {
return filterStartingWith(online_players(), args.get(0));
}
if (args.size() == 2 && CustomNameplates.getInstance().getNameplateManager().getMode() == DisplayMode.TEAM) {
if (args.size() == 2) {
return filterStartingWith(allNameplates(), args.get(1));
}
return null;

View File

@@ -39,20 +39,20 @@ public class HelpCommand extends AbstractSubCommand {
AdventureUtils.sendMessage(sender, "<#3CB371>/nameplates");
AdventureUtils.sendMessage(sender, " <gray>├─<white>help");
AdventureUtils.sendMessage(sender, " <gray>├─<white>about");
AdventureUtils.sendMessage(sender, " <gray>├─<white>reload <#87CEFA>Reload the plugin");
AdventureUtils.sendMessage(sender, " <gray>├─<white>list <#87CEFA>Show a list of available nameplates");
AdventureUtils.sendMessage(sender, " <gray>├─<white>equip <#FFFACD><nameplate><#87CEFA>Equip a nameplate");
AdventureUtils.sendMessage(sender, " <gray>├─<white>forceequip <#FFFACD><player> <nameplate><#87CEFA>Force a player to equip a nameplate");
AdventureUtils.sendMessage(sender, " <gray>├─<white>unequip <#87CEFA>Unequip the current nameplate");
AdventureUtils.sendMessage(sender, " <gray>├─<white>forceunequip <#FFFACD><player> <#87CEFA>Force a player to unequip his nameplate");
AdventureUtils.sendMessage(sender, " <gray>├─<white>preview <#87CEFA>Preview your current nameplate");
AdventureUtils.sendMessage(sender, " <gray>└─<white>forcepreview <player> <#87CEFA>Force a player to preview the nameplate");
AdventureUtils.sendMessage(sender, " <gray>├─<white>reload <#98FB98>Reload the plugin");
AdventureUtils.sendMessage(sender, " <gray>├─<white>list <#98FB98>Show a list of available nameplates");
AdventureUtils.sendMessage(sender, " <gray>├─<white>equip <#FFFACD><nameplate> <#98FB98>Equip a nameplate");
AdventureUtils.sendMessage(sender, " <gray>├─<white>forceequip <#FFFACD><player> <nameplate> <#98FB98>Force a player to equip a nameplate");
AdventureUtils.sendMessage(sender, " <gray>├─<white>unequip <#98FB98>Unequip the current nameplate");
AdventureUtils.sendMessage(sender, " <gray>├─<white>forceunequip <#FFFACD><player> <#98FB98>Force a player to unequip his nameplate");
AdventureUtils.sendMessage(sender, " <gray>├─<white>preview <#98FB98>Preview your current nameplate");
AdventureUtils.sendMessage(sender, " <gray>└─<white>forcepreview <player> <#E1FFFF>[nameplate] <#98FB98>Force a player to preview the nameplate");
AdventureUtils.sendMessage(sender, "<#3CB371>/bubbles");
AdventureUtils.sendMessage(sender, " <gray>├─<white>list <#87CEFA>Show a list of available bubbles");
AdventureUtils.sendMessage(sender, " <gray>├─<white>equip <#FFFACD><nameplate><#87CEFA>Equip a bubble");
AdventureUtils.sendMessage(sender, " <gray>├─<white>forceequip <#FFFACD><player> <nameplate><#87CEFA>Force a player to equip a bubble");
AdventureUtils.sendMessage(sender, " <gray>├─<white>unequip <#87CEFA>Unequip the current bubble");
AdventureUtils.sendMessage(sender, " <gray>└─<white>forceunequip <#FFFACD><player> <#87CEFA>Force a player to unequip his bubble");
AdventureUtils.sendMessage(sender, " <gray>├─<white>list <#98FB98>Show a list of available bubbles");
AdventureUtils.sendMessage(sender, " <gray>├─<white>equip <#FFFACD><nameplate><#98FB98>Equip a bubble");
AdventureUtils.sendMessage(sender, " <gray>├─<white>forceequip <#FFFACD><player> <nameplate><#98FB98>Force a player to equip a bubble");
AdventureUtils.sendMessage(sender, " <gray>├─<white>unequip <#98FB98>Unequip the current bubble");
AdventureUtils.sendMessage(sender, " <gray>└─<white>forceunequip <#FFFACD><player> <#98FB98>Force a player to unequip his bubble");
return true;
}
}

View File

@@ -27,7 +27,7 @@ import net.momirealms.customnameplates.manager.NameplateManager;
import net.momirealms.customnameplates.object.nameplate.NameplatesTeam;
import net.momirealms.customnameplates.object.nameplate.mode.DisplayMode;
import net.momirealms.customnameplates.utils.AdventureUtils;
import net.momirealms.customnameplates.utils.HoloUtils;
import net.momirealms.customnameplates.utils.ArmorStandUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -45,13 +45,17 @@ public class PreviewCommand extends AbstractSubCommand {
if (noConsoleExecute(sender)) return true;
Player player = (Player) sender;
NameplateManager nameplateManager = CustomNameplates.getInstance().getNameplateManager();
if (nameplateManager.isInCoolDown(player)) {
AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.coolDown);
return true;
}
if (nameplateManager.getMode() == DisplayMode.TEAM) {
NameplatesTeam team = CustomNameplates.getInstance().getTeamManager().getNameplateTeam(player.getUniqueId());
if (team != null) {
Component full = team.getNameplatePrefixComponent()
.append(Component.text(player.getName()).color(TextColor.color(AdventureUtils.colorToDecimal(team.getColor()))).font(Key.key("minecraft:default"))
.append(team.getNameplateSuffixComponent()));
HoloUtils.showHolo(full, player, (int) nameplateManager.getPreview_time());
ArmorStandUtils.preview(full, player, (int) nameplateManager.getPreview_time());
}
}
else {

View File

@@ -49,11 +49,11 @@ public class VersionHelper {
inputStream.close();
isLatest = !compareVer(newest, current);
if (isLatest) {
AdventureUtils.consoleMessage(ConfigManager.lang.equalsIgnoreCase("cn") ? "[CustomNameplates] 当前已是最新版本" : "[CustomNameplates] You are using the latest version.");
AdventureUtils.consoleMessage(ConfigManager.lang.equalsIgnoreCase("chinese") ? "[CustomNameplates] 当前已是最新版本" : "[CustomNameplates] You are using the latest version.");
return;
}
if (ConfigManager.lang.equalsIgnoreCase("cn")) {
if (ConfigManager.lang.equalsIgnoreCase("chinese")) {
AdventureUtils.consoleMessage("[CustomNameplates] 当前版本: <red>" + current);
AdventureUtils.consoleMessage("[CustomNameplates] 最新版本: <green>" + newest);
AdventureUtils.consoleMessage("[CustomNameplates] 请到 <u>售后群<!u> 或 <u>https://polymart.org/resource/customnameplates.2543<!u> 获取最新版本.");

View File

@@ -0,0 +1,41 @@
/*
* 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.packet;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.manager.ActionBarManager;
import net.momirealms.customnameplates.object.nameplate.mode.PacketsHandler;
public class ActionBarListener extends PacketAdapter {
private final ActionBarManager actionBarManager;
public ActionBarListener(ActionBarManager actionBarManager) {
super(CustomNameplates.getInstance(), ListenerPriority.HIGHEST, PacketType.Play.Server.SET_ACTION_BAR_TEXT);
this.actionBarManager = actionBarManager;
}
public void onPacketSending(PacketEvent event) {
actionBarManager.onReceivePacket(event);
}
}

View File

@@ -17,8 +17,16 @@
package net.momirealms.customnameplates.manager;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ScoreComponent;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.listener.JoinQuitListener;
import net.momirealms.customnameplates.listener.packet.ActionBarListener;
import net.momirealms.customnameplates.object.Function;
import net.momirealms.customnameplates.object.actionbar.ActionBarConfig;
import net.momirealms.customnameplates.object.actionbar.ActionBarTask;
@@ -29,6 +37,7 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.LinkedHashMap;
@@ -39,6 +48,7 @@ public class ActionBarManager extends Function {
private final LinkedHashMap<String, ActionBarConfig> actionBarConfigMap;
private final ConcurrentHashMap<UUID, ActionBarTask> actionBarTaskMap;
private final ActionBarListener actionBarListener;
private final JoinQuitListener joinQuitListener;
private final CustomNameplates plugin;
@@ -47,6 +57,7 @@ public class ActionBarManager extends Function {
this.actionBarConfigMap = new LinkedHashMap<>();
this.actionBarTaskMap = new ConcurrentHashMap<>();
this.joinQuitListener = new JoinQuitListener(this);
this.actionBarListener = new ActionBarListener(this);
}
@Override
@@ -54,6 +65,7 @@ public class ActionBarManager extends Function {
if (!ConfigManager.enableActionBar) return;
this.loadConfig();
Bukkit.getPluginManager().registerEvents(joinQuitListener, plugin);
CustomNameplates.getProtocolManager().addPacketListener(actionBarListener);
for (Player player : Bukkit.getOnlinePlayers()) {
onJoin(player);
}
@@ -65,6 +77,7 @@ public class ActionBarManager extends Function {
actionBarTask.stop();
}
actionBarConfigMap.clear();
CustomNameplates.getProtocolManager().removePacketListener(actionBarListener);
HandlerList.unregisterAll(joinQuitListener);
}
@@ -81,6 +94,11 @@ public class ActionBarManager extends Function {
if (actionBarTask != null) actionBarTask.stop();
}
@Nullable
public ActionBarTask getActionBarTask(UUID uuid) {
return actionBarTaskMap.get(uuid);
}
private void loadConfig() {
YamlConfiguration config = ConfigUtils.getConfig("configs" + File.separator + "actionbar.yml");
for (String key : config.getKeys(false)) {
@@ -94,4 +112,30 @@ public class ActionBarManager extends Function {
}
AdventureUtils.consoleMessage("[CustomNameplates] Loaded <green>" + actionBarConfigMap.size() + " <gray>actionbars");
}
public void onReceivePacket(PacketEvent event) {
PacketContainer packet = event.getPacket();
WrappedChatComponent wrappedChatComponent = packet.getChatComponents().read(0);
if (wrappedChatComponent != null) {
ActionBarTask actionBarTask = getActionBarTask(event.getPlayer().getUniqueId());
if (actionBarTask != null) {
Component component = GsonComponentSerializer.gson().deserialize(wrappedChatComponent.getJson());
if (component instanceof ScoreComponent scoreComponent) {
if (scoreComponent.name().equals("nameplates") && scoreComponent.objective().equals("actionbar")) {
return;
}
}
event.setCancelled(true);
actionBarTask.setOtherText(AdventureUtils.getMiniMessageFormat(component), System.currentTimeMillis());
}
}
}
public String getOtherPluginActionBarText(Player player) {
ActionBarTask actionBarTask = getActionBarTask(player.getUniqueId());
if (actionBarTask != null) {
return actionBarTask.getOtherText();
}
return "";
}
}

View File

@@ -5,7 +5,7 @@ import net.momirealms.customnameplates.object.Function;
import net.momirealms.customnameplates.object.SimpleChar;
import net.momirealms.customnameplates.object.background.BackGroundConfig;
import net.momirealms.customnameplates.object.font.OffsetFont;
import net.momirealms.customnameplates.placeholders.BackGroundText;
import net.momirealms.customnameplates.object.placeholders.BackGroundText;
import net.momirealms.customnameplates.utils.AdventureUtils;
import org.bukkit.configuration.file.YamlConfiguration;

View File

@@ -34,6 +34,7 @@ import net.momirealms.customnameplates.object.bubble.BubbleConfig;
import net.momirealms.customnameplates.object.emoji.ImageParser;
import net.momirealms.customnameplates.object.emoji.ItemsAdderImpl;
import net.momirealms.customnameplates.object.emoji.OraxenImpl;
import net.momirealms.customnameplates.object.font.OffsetFont;
import net.momirealms.customnameplates.object.nameplate.mode.EntityTag;
import net.momirealms.customnameplates.utils.AdventureUtils;
import net.momirealms.customnameplates.utils.ConfigUtils;
@@ -220,6 +221,48 @@ public class ChatBubblesManager extends EntityTag {
return false;
}
public String getBubblePrefix(String text, BubbleConfig bubble) {
int totalWidth = plugin.getFontManager().getTotalWidth(text);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(plugin.getFontManager().getShortestNegChars(totalWidth % 2 == 0 ? totalWidth + bubble.left().getWidth() : totalWidth + bubble.left().getWidth() + 1))
.append(bubble.left().getChars()).append(OffsetFont.NEG_1.getCharacter());
int mid_amount;
if (totalWidth - 1 <= bubble.tail().getWidth() ) {
mid_amount = -1;
}
else {
mid_amount = (totalWidth - 1 - bubble.tail().getWidth()) / (bubble.middle().getWidth());
}
if (mid_amount == -1) {
stringBuilder.append(bubble.tail().getChars()).append(OffsetFont.NEG_1.getCharacter());
}
else if (mid_amount == 0) {
stringBuilder.append(bubble.tail().getChars()).append(OffsetFont.NEG_1.getCharacter());
stringBuilder.append(
plugin.getFontManager().getShortestNegChars(
bubble.middle().getWidth() - (totalWidth - 1 - bubble.tail().getWidth()) % bubble.middle().getWidth()
)
);
stringBuilder.append(bubble.middle().getChars()).append(OffsetFont.NEG_1.getCharacter());
}
else {
stringBuilder.append(bubble.middle().getChars()).append(OffsetFont.NEG_1.getCharacter());
for (int i = 0; i < mid_amount; i++) {
if (i == mid_amount / 2) stringBuilder.append(bubble.tail().getChars()).append(OffsetFont.NEG_1.getCharacter());
else stringBuilder.append(bubble.middle().getChars()).append(OffsetFont.NEG_1.getCharacter());
}
stringBuilder.append(
plugin.getFontManager().getShortestNegChars(
bubble.middle().getWidth() - (totalWidth - 1 - bubble.tail().getWidth()) % bubble.middle().getWidth()
)
);
stringBuilder.append(bubble.middle().getChars()).append(OffsetFont.NEG_1.getCharacter());
}
stringBuilder.append(bubble.right().getChars());
stringBuilder.append(plugin.getFontManager().getShortestNegChars(totalWidth + bubble.right().getWidth()));
return stringBuilder.toString();
}
public void onChat(Player player, String text) {
if (player.getGameMode() == GameMode.SPECTATOR || !player.hasPermission("bubbles.use")) return;
@@ -255,8 +298,9 @@ public class ChatBubblesManager extends EntityTag {
String parsedSuffix = PlaceholderAPI.setPlaceholders(player, suffix);
String strippedPrefix = AdventureUtils.stripAllTags(parsedPrefix);
String strippedSuffix = AdventureUtils.stripAllTags(parsedSuffix);
String bubbleImage = plugin.getNameplateManager().makeCustomBubble(strippedPrefix, text, strippedSuffix, bubbleConfig);
String suffixImage = plugin.getNameplateManager().getNameplateSuffix(strippedPrefix + text + strippedSuffix);
String all = strippedPrefix + text + strippedSuffix;
String bubbleImage = getBubblePrefix(all, bubbleConfig);
String suffixImage = plugin.getFontManager().getSuffixStringWithFont(all);
String finalStr = ConfigManager.surroundWithFont(bubbleImage) + bubbleConfig.startFormat() + parsedPrefix + text + parsedSuffix + bubbleConfig.endFormat() + ConfigManager.surroundWithFont(suffixImage);
json = GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(finalStr));
}

View File

@@ -1,6 +1,5 @@
package net.momirealms.customnameplates.manager;
import net.kyori.adventure.key.Key;
import net.momirealms.customnameplates.object.Function;
import net.momirealms.customnameplates.utils.ConfigUtils;
import org.bukkit.Bukkit;
@@ -24,7 +23,8 @@ public class ConfigManager extends Function {
public static boolean oraxenHook;
public static boolean trChat_Hook;
public static boolean ventureChat_Hook;
public static boolean extract;
public static boolean extractShader;
public static boolean extractBars;
public static char start_char;
public static boolean checkUpdate;
public static boolean enableBStats;
@@ -71,7 +71,8 @@ public class ConfigManager extends Function {
space_split_folder_path = section.getString("image-path.space-split","font\\base\\");
images_folder_path = section.getString("image-path.images","font\\images\\");
thin_font = section.getBoolean("use-thin-font",false);
extract = section.getBoolean("extract-shader",true);
extractShader = section.getBoolean("extract-shader",true);
extractBars = section.getBoolean("extract-bar-image",true);
}
}

View File

@@ -65,6 +65,7 @@ public class DataManager extends Function {
}
else {
playerDataMap.put(uuid, playerData);
if (!ConfigManager.enableNameplates) return;
plugin.getTeamManager().getTeamNameInterface().onJoin(player);
plugin.getTeamManager().createTeam(uuid);
}

View File

@@ -1,11 +1,13 @@
package net.momirealms.customnameplates.manager;
import me.clip.placeholderapi.PlaceholderAPI;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.object.Function;
import net.momirealms.customnameplates.object.SimpleChar;
import net.momirealms.customnameplates.object.font.ASCIIWidth;
import net.momirealms.customnameplates.object.font.OffsetFont;
import net.momirealms.customnameplates.object.font.UnicodeWidth;
import net.momirealms.customnameplates.utils.AdventureUtils;
import net.momirealms.customnameplates.utils.ConfigUtils;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -49,10 +51,19 @@ public class FontManager extends Function {
}
YamlConfiguration config = ConfigUtils.getConfig("configs" + File.separator + "image-width.yml");
for (String image : config.getKeys(false)) {
customImageWidth.put(image.charAt(0), config.getInt(image, 8));
customImageWidth.put(AdventureUtils.stripAllTags(PlaceholderAPI.setPlaceholders(null, image)).charAt(0), config.getInt(image, 8));
}
}
public String getSuffixStringWithFont(String text) {
return ConfigManager.surroundWithFont(getSuffixString(text));
}
public String getSuffixString(String text) {
int totalWidth = plugin.getFontManager().getTotalWidth(text);
return plugin.getFontManager().getShortestNegChars(totalWidth + totalWidth % 2 + 1);
}
public int getCharWidth(char c) {
return Objects.requireNonNullElse(customImageWidth.get(c), 8);
}

View File

@@ -3,16 +3,13 @@ package net.momirealms.customnameplates.manager;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.object.Function;
import net.momirealms.customnameplates.object.SimpleChar;
import net.momirealms.customnameplates.object.nameplate.NameplateConfig;
import net.momirealms.customnameplates.utils.AdventureUtils;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Objects;
public class ImageManager extends Function {

View File

@@ -11,8 +11,8 @@ import net.momirealms.customnameplates.object.nameplate.NameplateConfig;
import net.momirealms.customnameplates.object.nameplate.mode.AbstractNameplateTag;
import net.momirealms.customnameplates.object.nameplate.mode.DisplayMode;
import net.momirealms.customnameplates.object.nameplate.mode.EntityTag;
import net.momirealms.customnameplates.object.nameplate.mode.team.TeamTag;
import net.momirealms.customnameplates.object.nameplate.mode.armorstand.ArmorStandTag;
import net.momirealms.customnameplates.object.nameplate.mode.team.TeamTag;
import net.momirealms.customnameplates.object.requirements.Requirement;
import net.momirealms.customnameplates.utils.AdventureUtils;
import net.momirealms.customnameplates.utils.ConfigUtils;
@@ -22,7 +22,6 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
@@ -84,7 +83,6 @@ public class NameplateManager extends Function {
}
File[] np_config_files = np_file.listFiles(file -> file.getName().endsWith(".yml"));
if (np_config_files == null) return;
nameplateConfigMap.put("none", NameplateConfig.EMPTY);
for (File np_config_file : np_config_files) {
char left = ConfigManager.start_char;
char middle;
@@ -117,7 +115,7 @@ public class NameplateManager extends Function {
ChatColor color = ChatColor.valueOf(Objects.requireNonNull(config.getString("color", "WHITE")).toUpperCase());
nameplateConfigMap.put(key, new NameplateConfig(color, config.getString("display-display_name"), leftChar, middleChar, rightChar));
}
AdventureUtils.consoleMessage("[CustomNameplates] Loaded <green>" + (nameplateConfigMap.size() -1) + " <gray>nameplates");
AdventureUtils.consoleMessage("[CustomNameplates] Loaded <green>" + nameplateConfigMap.size() + " <gray>nameplates");
}
private void saveDefaultNameplates() {
@@ -157,71 +155,32 @@ public class NameplateManager extends Function {
return contentMap;
}
public String getNameplatePrefix(String parsed, String nameplate) {
NameplateConfig nameplateConfig = nameplateConfigMap.get(nameplate);
if (nameplateConfig == null) return nameplate + " NOT FOUND";
return getNameplatePrefix("", parsed, "", nameplateConfig);
public String getNameplatePrefixWithFont(String text, NameplateConfig nameplate) {
return ConfigManager.surroundWithFont(getNameplatePrefix(text, nameplate));
}
public String getNameplatePrefix(String prefix, String name, String suffix, NameplateConfig nameplate) {
int totalWidth = plugin.getFontManager().getTotalWidth(prefix + name + suffix);
char middle = nameplate.middle().getChars();
char neg_1 = OffsetFont.NEG_1.getCharacter();
int offset_2 = nameplate.right().getWidth() - nameplate.middle().getWidth();
int left_offset = totalWidth + (nameplate.left().getWidth() + nameplate.right().getWidth())/2 + 1;
public String getNameplatePrefix(String text, NameplateConfig nameplate) {
int totalWidth = plugin.getFontManager().getTotalWidth(text);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(plugin.getFontManager().getShortestNegChars(totalWidth % 2 == 0 ? left_offset : left_offset + 1 ));
stringBuilder.append(nameplate.left().getChars()).append(neg_1);
int mid_amount = (totalWidth + 1 + offset_2) / (nameplate.middle().getWidth());
stringBuilder.append(plugin.getFontManager().getShortestNegChars(totalWidth % 2 == 0 ? totalWidth + nameplate.left().getWidth() : totalWidth + nameplate.left().getWidth() + 1))
.append(nameplate.left().getChars()).append(OffsetFont.NEG_1.getCharacter());
int mid_amount = (totalWidth - 1) / (nameplate.middle().getWidth());
if (mid_amount == 0) {
stringBuilder.append(middle).append(neg_1);
stringBuilder.append(nameplate.middle().getChars()).append(OffsetFont.NEG_1.getCharacter());
}
else {
for (int i = 0; i < mid_amount; i++) {
stringBuilder.append(middle).append(neg_1);
stringBuilder.append(nameplate.middle().getChars()).append(OffsetFont.NEG_1.getCharacter());
}
stringBuilder.append(
plugin.getFontManager().getShortestNegChars(
nameplate.middle().getWidth() - (totalWidth - 1) % nameplate.middle().getWidth()
)
);
stringBuilder.append(nameplate.middle().getChars()).append(OffsetFont.NEG_1.getCharacter());
}
return getString(totalWidth, middle, neg_1, offset_2, left_offset, stringBuilder, nameplate.right(), nameplate.middle());
}
public String getNameplateSuffix(String text) {
int totalWidth = plugin.getFontManager().getTotalWidth(text);
return plugin.getFontManager().getShortestNegChars(totalWidth + totalWidth % 2 + 1);
}
public String makeCustomBubble(String prefix, String name, String suffix, BubbleConfig bubble) {
int totalWidth = plugin.getFontManager().getTotalWidth(ChatColor.stripColor(prefix + name + suffix));
char middle = bubble.middle().getChars();
char tail = bubble.tail().getChars();
char neg_1 = OffsetFont.NEG_1.getCharacter();
int offset = bubble.middle().getWidth() - bubble.tail().getWidth();
int left_offset = totalWidth + bubble.left().getWidth() + 1;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(plugin.getFontManager().getShortestNegChars(totalWidth % 2 == 0 ? left_offset - offset : left_offset + 1 - offset));
stringBuilder.append(bubble.left().getChars()).append(neg_1);
int mid_amount = (totalWidth + 1 - bubble.tail().getWidth()) / (bubble.middle().getWidth());
if (mid_amount == 0) {
stringBuilder.append(tail).append(neg_1);
}
else {
for (int i = 0; i <= mid_amount; i++) {
if (i == mid_amount/2) {
stringBuilder.append(tail).append(neg_1);
}
else {
stringBuilder.append(middle).append(neg_1);
}
}
}
return getString(totalWidth, middle, neg_1, offset, left_offset, stringBuilder, bubble.right(), bubble.middle());
}
@NotNull
protected String getString(int totalWidth, char middle, char neg_1, int offset, int left_offset, StringBuilder stringBuilder, SimpleChar right, SimpleChar middle2) {
stringBuilder.append(plugin.getFontManager().getShortestNegChars(right.getWidth() - ((totalWidth + 1 + offset) % middle2.getWidth() + (totalWidth % 2 == 0 ? 0 : -1))));
stringBuilder.append(middle).append(neg_1);
stringBuilder.append(right.getChars()).append(neg_1);
stringBuilder.append(plugin.getFontManager().getShortestNegChars(left_offset - 1));
stringBuilder.append(nameplate.right().getChars());
stringBuilder.append(plugin.getFontManager().getShortestNegChars(totalWidth + nameplate.right().getWidth()));
return stringBuilder.toString();
}
@@ -239,15 +198,16 @@ public class NameplateManager extends Function {
return nameplates;
}
// return false if in cool down
public boolean showPlayerArmorStandTags(Player player) {
public boolean isInCoolDown(Player player) {
long time = System.currentTimeMillis();
if (time - (previewCoolDown.getOrDefault(player.getUniqueId(), time - this.getPreview_time() * 1050)) < this.getPreview_time() * 1050) {
AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.coolDown);
return false;
return true;
}
previewCoolDown.put(player.getUniqueId(), time);
return false;
}
public void showPlayerArmorStandTags(Player player) {
EntityTag entityTag = (EntityTag) this.getNameplateTag();
ArmorStandManager asm = entityTag.getArmorStandManager(player);
asm.spawn(player);
@@ -259,7 +219,15 @@ public class NameplateManager extends Function {
Bukkit.getScheduler().runTaskLater(CustomNameplates.getInstance(), ()-> {
asm.destroy(player);
},this.getPreview_time() * 20);
return true;
}
public void showPlayerArmorStandTags(Player player, String nameplate) {
String current = getEquippedNameplate(player);
if (!nameplate.equals(current)) {
plugin.getDataManager().equipNameplate(player, nameplate);
Bukkit.getScheduler().runTaskLater(CustomNameplates.getInstance(), ()-> plugin.getDataManager().equipNameplate(player, current),this.getPreview_time() * 20);
}
showPlayerArmorStandTags(player);
}
public boolean existNameplate(String nameplate) {

View File

@@ -23,14 +23,16 @@ import net.momirealms.customnameplates.object.ConditionalText;
import net.momirealms.customnameplates.object.Function;
import net.momirealms.customnameplates.object.StaticText;
import net.momirealms.customnameplates.object.font.OffsetFont;
import net.momirealms.customnameplates.placeholders.*;
import net.momirealms.customnameplates.utils.AdventureUtils;
import net.momirealms.customnameplates.object.placeholders.*;
import net.momirealms.customnameplates.utils.ConfigUtils;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -147,7 +149,7 @@ public class PlaceholderManager extends Function {
private void loadStaticText(ConfigurationSection section) {
for (String key : section.getKeys(false)) {
stringStaticTextMap.put(key, new StaticText(section.getString(key + ".text"), section.getInt(key + ".value"), section.getString(key + ".position", "left").equalsIgnoreCase("left")));
stringStaticTextMap.put(key, new StaticText(section.getString(key + ".text"), section.getInt(key + ".value"), StaticText.StaticState.valueOf(section.getString(key + ".position", "left").toUpperCase())));
}
}

View File

@@ -26,7 +26,6 @@ import net.momirealms.customnameplates.object.background.BackGroundConfig;
import net.momirealms.customnameplates.object.bubble.BubbleConfig;
import net.momirealms.customnameplates.object.font.OffsetFont;
import net.momirealms.customnameplates.object.nameplate.NameplateConfig;
import net.momirealms.customnameplates.object.nameplate.mode.DisplayMode;
import net.momirealms.customnameplates.utils.AdventureUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
@@ -64,7 +63,7 @@ public class ResourceManager {
this.loadBubbles(fontJsonArray, textures_folder);
this.loadBackgrounds(fontJsonArray, textures_folder);
this.loadImages(fontJsonArray, textures_folder);
this.extractShaders();
this.extractDefault();
this.saveOffsets();
this.saveSplit(textures_folder.getPath());
try (FileWriter fileWriter = new FileWriter(
@@ -102,7 +101,6 @@ public class ResourceManager {
private void loadNameplates(JsonArray jsonArray, File textures_file) {
if (!ConfigManager.enableNameplates) return;
for (NameplateConfig nameplateConfig : plugin.getNameplateManager().getNameplateConfigMap().values()) {
if (nameplateConfig == NameplateConfig.EMPTY) continue;
for (SimpleChar simpleChar : new SimpleChar[]{nameplateConfig.left(), nameplateConfig.middle(), nameplateConfig.right()}) {
JsonObject jo_np = new JsonObject();
jo_np.add("type", new JsonPrimitive("bitmap"));
@@ -168,13 +166,17 @@ public class ResourceManager {
jsonArray.add(jsonObject);
}
private void extractShaders() {
if (ConfigManager.extract) {
private void extractDefault() {
if (ConfigManager.extractShader) {
String path = "ResourcePack" + File.separator + "assets" + File.separator + "minecraft" + File.separator + "shaders" + File.separator + "core" + File.separator;
plugin.saveResource(path + "rendertype_text.fsh", true);
plugin.saveResource(path + "rendertype_text.json", true);
plugin.saveResource(path + "rendertype_text.vsh", true);
}
if (ConfigManager.extractBars) {
String path = "ResourcePack" + File.separator + "assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "gui" + File.separator;
plugin.saveResource(path + "bars.png", true);
}
}
private void saveOffsets() {
@@ -183,12 +185,14 @@ public class ResourceManager {
JsonArray jsonArray_offset = new JsonArray();
jsonObject_offset.add("providers", jsonArray_offset);
JsonObject jo_providers = new JsonObject();
jo_providers.add("type", new JsonPrimitive("space"));
JsonObject jo_space = new JsonObject();
jo_space.add(" ", new JsonPrimitive(4));
jo_space.add("\\u200c", new JsonPrimitive(0));
jo_providers.add("advances", jo_space);
jsonArray_offset.add(jo_providers);
JsonObject jo_ascii = new JsonObject();
jo_ascii.add("type", new JsonPrimitive("bitmap"));
jo_ascii.add("file", new JsonPrimitive("minecraft:font/ascii.png"));
@@ -213,6 +217,13 @@ public class ResourceManager {
ja_ascii.add("\\u2261\\u00b1\\u2265\\u2264\\u2320\\u2321\\u00f7\\u2248\\u00b0\\u2219\\u0000\\u221a\\u207f\\u00b2\\u25a0\\u0000");
jo_ascii.add("chars", ja_ascii);
jsonArray_offset.add(jo_ascii);
JsonObject legacy_unicode = new JsonObject();
legacy_unicode.add("type", new JsonPrimitive("legacy_unicode"));
legacy_unicode.add("sizes", new JsonPrimitive("minecraft:font/glyph_sizes.bin"));
legacy_unicode.add("template", new JsonPrimitive("minecraft:font/unicode_page_%s.png"));
jsonArray_offset.add(legacy_unicode);
try (FileWriter fileWriter = new FileWriter(
plugin.getDataFolder() +
File.separator + "ResourcePack" +

View File

@@ -34,7 +34,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

View File

@@ -19,8 +19,6 @@ package net.momirealms.customnameplates.object;
public class SimpleChar {
public static SimpleChar NONE = new SimpleChar(16, 12, 16,'默', "none.png");
private final int height;
private final int ascent;
private final char chars;

View File

@@ -1,4 +1,11 @@
package net.momirealms.customnameplates.object;
public record StaticText(String text, int value, boolean left) {
public record StaticText(String text, int value, StaticState staticState) {
public enum StaticState {
LEFT,
MIDDLE,
RIGHT
}
}

View File

@@ -1,5 +1,8 @@
package net.momirealms.customnameplates.object.actionbar;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ScoreComponent;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.momirealms.customnameplates.object.DynamicText;
import net.momirealms.customnameplates.object.requirements.PlayerCondition;
import net.momirealms.customnameplates.object.requirements.Requirement;
@@ -14,8 +17,10 @@ public class ActionBarSender {
private int current_text_id;
private final DynamicText[] dynamicTexts;
private final Requirement[] requirements;
private final ActionBarTask actionBarTask;
public ActionBarSender(int switch_interval, String[] texts, Requirement[] requirements, Player player) {
public ActionBarSender(int switch_interval, String[] texts, Requirement[] requirements, Player player, ActionBarTask actionBarTask) {
this.actionBarTask = actionBarTask;
this.player = player;
this.switch_interval = switch_interval;
this.requirements = requirements;
@@ -26,8 +31,8 @@ public class ActionBarSender {
this.current_text_id = 0;
}
public boolean canSend() {
PlayerCondition playerCondition = new PlayerCondition(player);
public boolean canSend(PlayerCondition playerCondition) {
if (requirements.length == 0) return true;
for (Requirement requirement : requirements) {
if (!requirement.isConditionMet(playerCondition)) {
return false;
@@ -46,6 +51,8 @@ public class ActionBarSender {
}
}
dynamicTexts[current_text_id].update();
AdventureUtils.playerActionbar(player, dynamicTexts[current_text_id].getLatestValue());
ScoreComponent.Builder builder = Component.score().name("nameplates").objective("actionbar");
builder.append(AdventureUtils.getComponentFromMiniMessage(dynamicTexts[current_text_id].getLatestValue()));
AdventureUtils.playerActionbar(player, builder.build());
}
}
}

View File

@@ -1,6 +1,7 @@
package net.momirealms.customnameplates.object.actionbar;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.object.requirements.PlayerCondition;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
@@ -9,16 +10,22 @@ public class ActionBarTask {
private BukkitTask timerTask;
private final ActionBarSender[] actionBarSenders;
private String otherText;
private long expireTime;
private final Player player;
public ActionBarTask(Player player, ActionBarConfig[] configs) {
this.player = player;
this.actionBarSenders = new ActionBarSender[configs.length];
this.otherText = "";
for (int i = 0; i < configs.length; i++) {
ActionBarConfig actionBarConfig = configs[i];
this.actionBarSenders[i] = new ActionBarSender(
actionBarConfig.getInterval(),
actionBarConfig.getTexts(),
actionBarConfig.getConditions(),
player
player,
this
);
}
}
@@ -29,12 +36,29 @@ public class ActionBarTask {
public void start() {
this.timerTask = Bukkit.getScheduler().runTaskTimerAsynchronously(CustomNameplates.getInstance(), () -> {
if (System.currentTimeMillis() > getExpireTime()) {
this.otherText = "";
}
PlayerCondition playerCondition = new PlayerCondition(player);
for (ActionBarSender actionBarSender : actionBarSenders) {
if (actionBarSender.canSend()) {
if (actionBarSender.canSend(playerCondition)) {
actionBarSender.send();
return;
}
}
}, 1, 1);
}
public String getOtherText() {
return otherText;
}
public void setOtherText(String otherText, long time) {
this.otherText = otherText;
this.expireTime = time + 4000;
}
public long getExpireTime() {
return expireTime;
}
}

View File

@@ -17,14 +17,11 @@
package net.momirealms.customnameplates.object.armorstand;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.object.ConditionalText;
import net.momirealms.customnameplates.object.DynamicText;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Map;
import java.util.Set;

View File

@@ -53,9 +53,10 @@ public class BossBarSender {
return isShown;
}
public boolean canSend() {
public boolean canSend(PlayerCondition playerCondition) {
if (requirements.length == 0) return true;
for (Requirement requirement : requirements) {
if (!requirement.isConditionMet(new PlayerCondition(player))) {
if (!requirement.isConditionMet(playerCondition)) {
return false;
}
}

View File

@@ -1,6 +1,7 @@
package net.momirealms.customnameplates.object.bossbar;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.object.requirements.PlayerCondition;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
@@ -9,9 +10,11 @@ public class BossBarTask {
private BukkitTask timerTask;
private final BossBarSender[] bossBarSenders;
private final Player player;
public BossBarTask(Player player, BossBarConfig[] configs) {
this.bossBarSenders = new BossBarSender[configs.length];
this.player = player;
for (int i = 0; i < configs.length; i++) {
BossBarConfig bossBarConfig = configs[i];
this.bossBarSenders[i] = new BossBarSender(
@@ -34,8 +37,9 @@ public class BossBarTask {
public void start() {
this.timerTask = Bukkit.getScheduler().runTaskTimerAsynchronously(CustomNameplates.getInstance(), () -> {
PlayerCondition playerCondition = new PlayerCondition(player);
for (BossBarSender bossBarSender : bossBarSenders) {
if (!bossBarSender.canSend()) {
if (!bossBarSender.canSend(playerCondition)) {
if (bossBarSender.isShown()) {
bossBarSender.hide();
return;

View File

@@ -22,5 +22,4 @@ import org.bukkit.ChatColor;
public record NameplateConfig(ChatColor color, String display_name, SimpleChar left, SimpleChar middle, SimpleChar right) {
public static NameplateConfig EMPTY = new NameplateConfig(ChatColor.WHITE, "none", SimpleChar.NONE, SimpleChar.NONE, SimpleChar.NONE);
}

View File

@@ -20,6 +20,7 @@ package net.momirealms.customnameplates.object.nameplate;
import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.manager.ConfigManager;
import net.momirealms.customnameplates.manager.NameplateManager;
import net.momirealms.customnameplates.object.DynamicText;
@@ -66,17 +67,11 @@ public class NameplatesTeam {
String name = PlaceholderAPI.setPlaceholders(player, nameplateManager.getPlayer_name_papi());
if (updated) {
nameplate = newNameplate;
this.nameplate_prefix = ConfigManager.surroundWithFont(nameplateManager.getNameplatePrefix(
AdventureUtils.stripAllTags(prefix.getLatestValue()),
name,
AdventureUtils.stripAllTags(suffix.getLatestValue()),
nameplateConfig
)) + prefix.getLatestValue();
this.nameplate_suffix = ConfigManager.surroundWithFont(nameplateManager.getNameplateSuffix(
AdventureUtils.stripAllTags(prefix.getLatestValue()) +
name +
AdventureUtils.stripAllTags(suffix.getLatestValue())
)) + suffix.getLatestValue();
String text = AdventureUtils.stripAllTags(prefix.getLatestValue())
+ name +
AdventureUtils.stripAllTags(suffix.getLatestValue());
this.nameplate_prefix = nameplateManager.getNameplatePrefixWithFont(text, nameplateConfig) + prefix.getLatestValue();
this.nameplate_suffix = CustomNameplates.getInstance().getFontManager().getSuffixStringWithFont(text) + suffix.getLatestValue();
}
}
return updated;

View File

@@ -17,7 +17,6 @@
package net.momirealms.customnameplates.object.nameplate.mode;
import com.comphenix.protocol.events.PacketContainer;
import net.momirealms.customnameplates.object.Function;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.placeholders;
package net.momirealms.customnameplates.object.placeholders;
public record BackGroundText(String text, String background, boolean remove_shadow) {
}

View File

@@ -1,4 +1,4 @@
package net.momirealms.customnameplates.placeholders;
package net.momirealms.customnameplates.object.placeholders;
import net.momirealms.customnameplates.object.ConditionalText;
import net.momirealms.customnameplates.object.requirements.PlayerCondition;

View File

@@ -0,0 +1,4 @@
package net.momirealms.customnameplates.object.placeholders;
public record DescentText(String text, int ascent) {
}

View File

@@ -15,21 +15,26 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.placeholders;
package net.momirealms.customnameplates.object.placeholders;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.manager.ConfigManager;
import net.momirealms.customnameplates.manager.FontManager;
import net.momirealms.customnameplates.manager.NameplateManager;
import net.momirealms.customnameplates.manager.PlaceholderManager;
import net.momirealms.customnameplates.object.SimpleChar;
import net.momirealms.customnameplates.object.StaticText;
import net.momirealms.customnameplates.object.nameplate.NameplateConfig;
import net.momirealms.customnameplates.object.nameplate.NameplatesTeam;
import net.momirealms.customnameplates.utils.AdventureUtils;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
public class NameplatePlaceholders extends PlaceholderExpansion {
private final PlaceholderManager placeholderManager;
@@ -103,10 +108,17 @@ public class NameplatePlaceholders extends PlaceholderExpansion {
case "checkupdate" -> {
return String.valueOf(!plugin.getVersionHelper().isLatest());
}
case "actionbar" -> {
return getOtherActionBar(player);
}
}
return null;
}
private String getOtherActionBar(Player player) {
return plugin.getActionBarManager().getOtherPluginActionBarText(player);
}
private String getOffset(String s) {
return ConfigManager.surroundWithFont(plugin.getFontManager().getOffset(Integer.parseInt(s)));
}
@@ -115,7 +127,11 @@ public class NameplatePlaceholders extends PlaceholderExpansion {
NameplateText nameplateText = placeholderManager.getNameplateText(param);
if (nameplateText == null) return param + " NOT FOUND";
String parsed = PlaceholderAPI.setPlaceholders(player, nameplateText.text());
return plugin.getNameplateManager().getNameplatePrefix(parsed, nameplateText.nameplate());
NameplateManager nameplateManager = plugin.getNameplateManager();
NameplateConfig nameplateConfig = nameplateManager.getNameplateConfig(nameplateText.nameplate());
if (nameplateConfig == null) return nameplateText.nameplate() + " NOT FOUND";
String text = AdventureUtils.stripAllTags(parsed);
return nameplateManager.getNameplatePrefixWithFont(text, nameplateConfig) + parsed + plugin.getFontManager().getSuffixStringWithFont(text);
}
private String getEquipped(String param, Player player) {
@@ -164,14 +180,20 @@ public class NameplatePlaceholders extends PlaceholderExpansion {
private String getStatic(String param, Player player) {
StaticText staticText = placeholderManager.getStaticText(param);
if (staticText == null) return param + " NOT FOUND";
FontManager fontManager = plugin.getFontManager();
String parsed = PlaceholderAPI.setPlaceholders(player, staticText.text());
int parsedWidth = plugin.getFontManager().getTotalWidth(AdventureUtils.stripAllTags(parsed));
if (staticText.left()) {
return parsed + ConfigManager.surroundWithFont(plugin.getFontManager().getOffset(staticText.value() - parsedWidth));
int parsedWidth = fontManager.getTotalWidth(AdventureUtils.stripAllTags(parsed));
if (staticText.staticState() == StaticText.StaticState.LEFT) {
return parsed + ConfigManager.surroundWithFont(fontManager.getOffset(staticText.value() - parsedWidth));
}
else if (staticText.staticState() == StaticText.StaticState.RIGHT) {
return ConfigManager.surroundWithFont(fontManager.getOffset(staticText.value() - parsedWidth)) + parsed;
}
else {
return ConfigManager.surroundWithFont(plugin.getFontManager().getOffset(staticText.value() - parsedWidth)) + parsed;
int half = (staticText.value() - parsedWidth) / 2;
String left = ConfigManager.surroundWithFont(fontManager.getOffset(half));
String right = ConfigManager.surroundWithFont(fontManager.getOffset(staticText.value() - parsedWidth - half));
return left + parsed + right;
}
}

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.placeholders;
package net.momirealms.customnameplates.object.placeholders;
public record NameplateText(String text, String nameplate) {

View File

@@ -1,4 +1,4 @@
package net.momirealms.customnameplates.placeholders;
package net.momirealms.customnameplates.object.placeholders;
public record VanillaHud(String empty, String half, String full, String papi, String max) {
}

View File

@@ -8,7 +8,7 @@ public record DateImpl(HashSet<String> dates) implements Requirement {
@Override
public boolean isConditionMet(PlayerCondition playerCondition) {
Calendar calendar = Calendar.getInstance();
String current = calendar.get(Calendar.MONTH) + "/" + calendar.get(Calendar.DATE);
String current = (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.DATE);
return dates.contains(current);
}
}

View File

@@ -18,7 +18,6 @@
package net.momirealms.customnameplates.object.requirements;
import me.clip.placeholderapi.PlaceholderAPI;
import net.momirealms.customnameplates.CustomNameplates;
import org.bukkit.entity.Player;
import java.util.HashMap;

View File

@@ -1,4 +0,0 @@
package net.momirealms.customnameplates.placeholders;
public record DescentText(String text, int ascent) {
}

View File

@@ -19,6 +19,8 @@ package net.momirealms.customnameplates.utils;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.momirealms.customnameplates.CustomNameplates;
import org.bukkit.Bukkit;
@@ -50,10 +52,9 @@ public class AdventureUtils {
au.sendMessage(getComponentFromMiniMessage(s));
}
public static void playerActionbar(Player player, String s) {
if (s == null) return;
public static void playerActionbar(Player player, Component component) {
Audience au = CustomNameplates.getAdventure().player(player);
au.sendActionBar(getComponentFromMiniMessage(s));
au.sendActionBar(component);
}
public static String replaceLegacy(String str) {
@@ -120,4 +121,8 @@ public class AdventureUtils {
public static String stripAllTags(String text) {
return MiniMessage.miniMessage().stripTags(replaceLegacy(text));
}
public static String getMiniMessageFormat(Component component) {
return MiniMessage.miniMessage().serialize(component);
}
}

View File

@@ -32,16 +32,26 @@ import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
public class HoloUtils {
public class ArmorStandUtils {
public static void showHolo(Component component, Player player, int duration){
public static void preview(Component component, Player player, int duration) {
int id = new Random().nextInt(Integer.MAX_VALUE);
sendSpawnPacket(player, id);
sendMetaPacket(player, id, component);
for (int i = 1; i < duration * 20 - 1; i++){
Bukkit.getScheduler().runTaskLater(CustomNameplates.getInstance(), ()->{
sendTeleportPacket(player, id);
}, i);
}
Bukkit.getScheduler().runTaskLater(CustomNameplates.getInstance(), ()->{
sendDestroyPacket(player, id);
}, duration * 20L);
}
public static void sendSpawnPacket(Player player, int id) {
PacketContainer spawnPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
int id = new Random().nextInt(1000000000);
spawnPacket.getModifier().write(0, id);
spawnPacket.getModifier().write(1, UUID.randomUUID());
spawnPacket.getEntityTypeModifier().write(0, EntityType.ARMOR_STAND);
@@ -49,9 +59,11 @@ public class HoloUtils {
spawnPacket.getDoubles().write(0, location.getX());
spawnPacket.getDoubles().write(1, location.getY()+0.8);
spawnPacket.getDoubles().write(2, location.getZ());
ProtocolLibrary.getProtocolManager().sendServerPacket(player, spawnPacket);
}
PacketContainer packet2 = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
public static void sendMetaPacket(Player player, int id, Component component) {
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher();
WrappedDataWatcher.Serializer serializer1 = WrappedDataWatcher.Registry.get(Boolean.class);
WrappedDataWatcher.Serializer serializer2 = WrappedDataWatcher.Registry.get(Byte.class);
@@ -62,38 +74,23 @@ public class HoloUtils {
byte mask2 = 0x01;
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, serializer2), mask1);
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, serializer2), mask2);
packet2.getModifier().write(0,id);
metaPacket.getModifier().write(0, id);
if (CustomNameplates.getInstance().getVersionHelper().isVersionNewerThan1_19_R2()) {
List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
wrappedDataWatcher.getWatchableObjects().stream().filter(Objects::nonNull).forEach(entry -> {
final WrappedDataWatcher.WrappedDataWatcherObject dataWatcherObject = entry.getWatcherObject();
wrappedDataValueList.add(new WrappedDataValue(dataWatcherObject.getIndex(), dataWatcherObject.getSerializer(), entry.getRawValue()));
});
packet2.getDataValueCollectionModifier().write(0, wrappedDataValueList);
metaPacket.getDataValueCollectionModifier().write(0, wrappedDataValueList);
} else {
packet2.getWatchableCollectionModifier().write(0, wrappedDataWatcher.getWatchableObjects());
metaPacket.getWatchableCollectionModifier().write(0, wrappedDataWatcher.getWatchableObjects());
}
ProtocolLibrary.getProtocolManager().sendServerPacket(player, spawnPacket);
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet2);
for (int i = 1; i < duration * 20 - 1; i++){
Bukkit.getScheduler().runTaskLater(CustomNameplates.getInstance(), ()->{
updatePosition(player, id);
}, i);
}
Bukkit.getScheduler().runTaskLater(CustomNameplates.getInstance(), ()->{
removeHolo(player, id);
}, duration * 20L);
ProtocolLibrary.getProtocolManager().sendServerPacket(player, metaPacket);
}
public static void updatePosition(Player player, int entityId){
public static void sendTeleportPacket(Player player, int id){
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
packet.getIntegers().write(0, entityId);
packet.getIntegers().write(0, id);
Location location = player.getLocation();
packet.getDoubles().write(0, location.getX());
packet.getDoubles().write(1, location.getY()+0.8);
@@ -101,9 +98,9 @@ public class HoloUtils {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
}
public static void removeHolo(Player player, int entityId) {
public static void sendDestroyPacket(Player player, int id) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
packet.getIntLists().write(0, List.of(entityId));
packet.getIntLists().write(0, List.of(id));
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
}
}

View File

@@ -16,21 +16,17 @@ out vec2 texCoord0;
void main(){
vec4 vertex=vec4(Position, 1.0);
if(Color.xyz==vec3(255., 255., 254.)/ 255.){
//Rainbow
(gl_Position=ProjMat*ModelViewMat*vertex);
(vertexColor=((.6+.6*cos(6.*(gl_Position.x+GameTime*1000.)+vec4(0, 23, 21, 1)))+vec4(0., 0., 0., 1.))*texelFetch(Sampler2, UV2 / 16, 0));
}else if(Color.xyz==vec3(255., 255., 253.)/ 255.){
//Shake
(gl_Position=ProjMat*ModelViewMat*vertex);
(vertexColor=Color*texelFetch(Sampler2, UV2 / 16, 0));
(gl_Position.y=gl_Position.y+sin(GameTime*12000.+(gl_Position.x*6))/ 150.);
}else if(Color.xyz==vec3(255., 255., 252.)/ 255.){
//Rainbow shake
(gl_Position=ProjMat*ModelViewMat*vertex);
(vertexColor=((.6+.6*cos(6.*(gl_Position.x+GameTime*1000.)+vec4(0, 23, 21, 1)))+vec4(0., 0., 0., 1.))*texelFetch(Sampler2, UV2 / 16, 0));
(gl_Position.y=gl_Position.y+sin(GameTime*12000.+(gl_Position.x*6))/ 150.);
}else if(Color.xyz==vec3(255., 255., 251.)/ 255.){
//Jump
(vertexColor=Color*texelFetch(Sampler2, UV2 / 16, 0));
float vertexId = mod(gl_VertexID, 4.0);
if(vertex.z <= 0.){
@@ -42,7 +38,6 @@ void main(){
}
(gl_Position=ProjMat*ModelViewMat*vertex);
}else if(Color.xyz==vec3(255., 254., 254.)/ 255.){
//Rainbow jump
float vertexId = mod(gl_VertexID, 4.0);
if(vertex.z <= 0.){
if(vertexId==3.||vertexId==0.)vertex.y += cos(GameTime*12000. / 4)*0.1;
@@ -54,31 +49,11 @@ void main(){
(vertexColor=((.6+.6*cos(6.*(gl_Position.x+GameTime*1000.)+vec4(0, 23, 21, 1)))+vec4(0., 0., 0., 1.))*texelFetch(Sampler2, UV2 / 16, 0));
(gl_Position=ProjMat*ModelViewMat*vertex);
}else if(Color.xyz==vec3(255., 254., 253.)/ 255.){
//Remove shadow
(vertexColor=Color*texelFetch(Sampler2, UV2 / 16, 0));
vertex.y+= 1;
vertex.x+= 1;
(gl_Position=ProjMat*ModelViewMat*vertex);
}else if(Color.xyz==vec3(255., 254., 250.)/ 255.){
//Shake2
(gl_Position=ProjMat*ModelViewMat*vertex);
(vertexColor=Color*texelFetch(Sampler2, UV2 / 16, 0));
(gl_Position.x=gl_Position.x+sin(GameTime*12000.+(gl_Position.y*6))/ 150.);
}else if(Color.xyz==vec3(255., 254., 251.)/ 255.){
//Light
(gl_Position=ProjMat*ModelViewMat*vertex);
if (sin(GameTime*1000) > 0){
vertexColor=((sin(GameTime*1000)))*texelFetch(Sampler2, UV2 / 16, 0);
}else{
vertexColor=((-sin(GameTime*1000)))*texelFetch(Sampler2, UV2 / 16, 0);
}
}else if(Color.xyz==vec3(255., 254., 252.)/ 255.){
//Remove
(gl_Position=ProjMat*ModelViewMat*vertex);
(vertexColor=Color*texelFetch(Sampler2, UV2 / 16, 0)*(-1));
}
else{
//Default
}else{
(gl_Position=ProjMat*ModelViewMat*vertex);
(vertexColor=Color*texelFetch(Sampler2, UV2 / 16, 0));
}

View File

@@ -1,20 +0,0 @@
#version 150
uniform sampler2D Sampler0;
uniform sampler2D Sampler2;
uniform vec4 ColorModulator;
in vec4 vertexColor;
in vec2 texCoord0;
in vec2 texCoord2;
out vec4 fragColor;
void main() {
vec4 color = texture(Sampler0, texCoord0) * vertexColor;
if (color.a < 0.1) {
discard;
}
fragColor = vec4(0.0,0.0,0.0,0.0);
}

View File

@@ -1,22 +0,0 @@
{
"blend": {
"func": "add",
"srcrgb": "srcalpha",
"dstrgb": "1-srcalpha"
},
"vertex": "rendertype_text_see_through",
"fragment": "rendertype_text_see_through",
"attributes": [
"Position",
"Color",
"UV0"
],
"samplers": [
{ "name": "Sampler0" }
],
"uniforms": [
{ "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] }
]
}

View File

@@ -1,18 +0,0 @@
#version 150
in vec3 Position;
in vec4 Color;
in vec2 UV0;
uniform mat4 ModelViewMat;
uniform mat4 ProjMat;
out vec4 vertexColor;
out vec2 texCoord0;
void main() {
gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0);
vertexColor = Color;
texCoord0 = UV0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -8,8 +8,8 @@ metrics: true
update-checker: true
# Language
# en/cn/es
lang: en
# english/chinese/spanish
lang: english
# Modules
modules:
@@ -45,6 +45,8 @@ integrations:
resource-pack:
# extract the shader
extract-shader: true
# extract the minecraft bars.png
extract-bar-image: true
# Your namespace
namespace: "nameplates"
# Font Name
@@ -59,5 +61,5 @@ resource-pack:
space-split: 'font\base\'
# The initial character of a font
initial-char: '뀁'
# Thin-font support
# Thin-font support for ASCII
thin-font: false

View File

@@ -1,21 +1,10 @@
actionbar_1:
text: '%nameplates_offset_94% %nameplates_vanilla_stamina_hud% %nameplates_offset_-183%%nameplates_static_money_hud%'
text: '%nameplates_conditional_stamina%%nameplates_static_money_hud%%nameplates_conditional_income_actionbar%'
conditions:
papi-condition:
'&&':
condition_1:
type: '=='
papi: '%player_remaining_air%'
value: 300
condition_2:
type: '=='
papi: '%player_gamemode%'
value: 'SURVIVAL'
condition_2:
type: '=='
papi: '%player_gamemode%'
value: 'SURVIVAL'
actionbar_2:
text: '%nameplates_static_money_hud%'
conditions:
papi-condition:
condition_1:
type: '!='
papi: '%player_remaining_air%'
value: 300
text: '%nameplates_actionbar%'

View File

@@ -34,7 +34,7 @@ conditional-text:
- rainstorm
prefix:
priority_1:
text: '%nameplates_background_prefix% '
text: '%nameplates_background_prefix%'
conditions:
papi-condition:
condition_1:
@@ -43,12 +43,34 @@ conditional-text:
value: ""
priority_2:
text: ''
stamina:
priority_1:
text: '%nameplates_offset_98%%nameplates_vanilla_stamina_hud%%nameplates_offset_-179%'
conditions:
papi-condition:
condition_1:
type: '=='
papi: '%player_remaining_air%'
value: "300"
priority_2:
text: ''
income_actionbar:
priority_1:
text: '%nameplates_offset_-180%%nameplates_static_income_actionbar%'
conditions:
papi-condition:
condition_1:
type: '!='
papi: '%nameplates_actionbar%'
value: ""
priority_2:
text: ''
# %nameplates_nameplate_{0}%
nameplate-text:
halloween:
nameplate: halloween
text: 'Today is Halloween! Trick or treat!'
text: '<gradient:#FFD700:#FFA500:#FFD700>Today is Halloween! Trick or treat!</gradient>'
# %nameplates_background_{0}%
background-text:
@@ -79,12 +101,16 @@ background-text:
# %nameplates_static_{0}%
static-text:
money_hud:
# left/right
# left/right/middle
position: right
text: '<#FFFEFD>%nameplates_image_coin%</#FFFEFD> %nameplates_descent_money%'
value: 180
# Only ASCII characters are allowed here
income_actionbar:
position: middle
text: '%nameplates_actionbar%'
value: 180
# Only ASCII characters are supported here
# Read the wiki to learn how to make all the unicodes work
# %nameplates_descent_{0}%
descent-text:
player:
@@ -107,7 +133,7 @@ descent-text:
descent: 3
money:
text: "%vault_eco_balance%"
descent: 12
descent: 13
# %nameplates_vanilla_{0}%
vanilla-hud:

View File

@@ -0,0 +1,2 @@
'%img_coin%': 10
'뀁': 8

View File

@@ -1,32 +1,35 @@
# mode: Team / Armor_Stand
# 模式 队伍/盔甲架
mode: Team
# Disable this when you are running a BungeeCord server
# You can also install BungeeTabListPlus or TAB on BungeeCord side to fix
# 当你使用BungeeCord服务端的时候请禁用此选项或在bc上安装BungeeTabListPlus或TAB
create-fake-team: true
# This decides what %nameplates_prefix/suffix% would return
# 玩家名变量,这会影响铭牌的长度判断
player-name: '%player_name%'
# The duration (in seconds) that the nameplate preview will last for.
# 预览持续时间
preview-duration: 5
# If your nameplate's text is static, disable refresh for better performance
refresh: true
# The default nameplate.
# 默认铭牌, none代表无
# "none" represents no default nameplate.
default-nameplate: 'none'
# Prefix & Suffix
# Rejoin the server to apply the changes
# 前缀和后缀,重新进入服务器以应用更改
prefix: ''
suffix: ''
armor_stand:
text_1:
text: '%nameplates_prefix%%player_name%%nameplates_suffix%'
vertical-offset: -1
vertical-offset: -0.99
text_2:
text: '%vault_prefix%'
vertical-offset: -0.7

View File

@@ -17,7 +17,7 @@ right:
image: chat_right
height: 13
ascent: 9
width: 5
width: 3
tail:
image: chat_tail
height: 13

View File

@@ -1,4 +1,4 @@
image: coin
height: 10
ascent: -1
ascent: -2
width: 10

View File

@@ -4,7 +4,7 @@ messages:
lack-args: '<white>参数不足!</white>'
none-args: '<white>非空参数'
invalid-args: '<white>无效参数'
reload: '<white>插件已重载!</white>'
reload: '<white>插件已重载! 请不要忘记重载你的资源包.</white>'
not-online: '<white>玩家 {Player} 不在线!</white>'
no-console: '<white>这个指令不能由控制台执行!</white>'
cooldown: '<white>上一个预览还没结束!</white>'

View File

@@ -2,7 +2,7 @@ messages:
prefix: '<gradient:#2E8B57:#48D1CC>[CustomNameplates] </gradient>'
no-perm: '<red>No Permission!</red>'
lack-args: '<white>Insufficient parameters!</white>'
reload: '<white>Reloaded!</white>'
reload: '<white>Reloaded! Don''t forget to reinstall your resource pack.</white>'
none-args: '<white>Non arguments'
invalid-args: '<white>Invalid arguments'
not-online: '<white>Player {Player} is not online!</white>'

View File

@@ -2,7 +2,7 @@ messages:
prefix: '<gradient:#2E8B57:#48D1CC>[CustomNameplates] </gradient>'
no-perm: '<red>No tienes permisos!</red>'
lack-args: '<white>¡Parámetros insuficientes!</white>'
reload: '<white>Recargado!</white>'
reload: '<white>Recargado! No olvides reinstalar el paquete de recursos.</white>'
none-args: '¡Ningún argumento!'
invalid-args: 'Argumentos no válidos'
not-online: '<white>Jugador {Player} no está en línea!</white>'