diff --git a/build.gradle b/build.gradle index cfa5de8..9fbca0c 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '2.0-PRE-9-HOTFIX' +version = '2.0-PRE-11' repositories { mavenCentral() @@ -48,6 +48,7 @@ dependencies { compileOnly 'dev.dejvokep:boosted-yaml:1.3' compileOnly 'net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT' compileOnly 'codecrafter47.bungeetablistplus:bungeetablistplus-api-bungee:3.5.2' + compileOnly 'com.github.LoneDev6:api-itemsadder:3.2.3c' implementation('net.kyori:adventure-api:4.11.0') implementation('net.kyori:adventure-platform-bukkit:4.1.2') implementation('net.kyori:adventure-text-minimessage:4.11.0') diff --git a/libs/BungeeTabListPlus-3.5.2.jar b/libs/BungeeTabListPlus-3.5.2.jar new file mode 100644 index 0000000..b004557 Binary files /dev/null and b/libs/BungeeTabListPlus-3.5.2.jar differ diff --git a/libs/TrChat-2.0.0-PRE-35.jar b/libs/TrChat-2.0.0-PRE-35.jar new file mode 100644 index 0000000..1859ce8 Binary files /dev/null and b/libs/TrChat-2.0.0-PRE-35.jar differ diff --git a/src/main/java/net/momirealms/customnameplates/ConfigManager.java b/src/main/java/net/momirealms/customnameplates/ConfigManager.java index f0f8697..18c4e51 100644 --- a/src/main/java/net/momirealms/customnameplates/ConfigManager.java +++ b/src/main/java/net/momirealms/customnameplates/ConfigManager.java @@ -114,6 +114,7 @@ public class ConfigManager { public static boolean tab_bc; public static boolean oraxen; public static boolean extract; + public static boolean trChat; public static List offsets; public static char start; public static Key key; @@ -142,6 +143,7 @@ public class ConfigManager { tab = config.getBoolean("config.integrations.TAB",false); tab_bc = config.getBoolean("config.integrations.TAB-BC",false); oraxen = config.getBoolean("config.integrations.Oraxen",false); + trChat = config.getBoolean("config.integrations.TrChat",false); offsets = config.getIntegerList("config.ascii-y-offset.offset"); if(config.getBoolean("config.extract-shader",true)) { @@ -162,6 +164,10 @@ public class ConfigManager { CustomNameplates.instance.getLogger().warning("Failed to initialize Oraxen!"); oraxen = false; } + if (trChat && CustomNameplates.instance.getServer().getPluginManager().getPlugin("TrChat") == null){ + CustomNameplates.instance.getLogger().warning("Failed to initialize TrChat!"); + trChat = false; + } } } @@ -354,6 +360,8 @@ public class ConfigManager { public static double lineSpace; public static double yOffset; public static int stayTime; + public static int coolDown; + public static int maxChar; public static void load() { YamlConfiguration config = getConfig("bubble.yml"); defaultBubble = config.getString("bubble.default-bubbles", "none"); @@ -363,6 +371,8 @@ public class ConfigManager { defaultFormat = config.getString("bubble.default-format", ""); yOffset = config.getDouble("bubble.bottom-line-Y-offset"); stayTime = config.getInt("bubble.stay-time", 5); + coolDown = config.getInt("bubble.cool-down", 1) * 1000; + maxChar = config.getInt("bubble.max-char-length", 35); } } diff --git a/src/main/java/net/momirealms/customnameplates/CustomNameplates.java b/src/main/java/net/momirealms/customnameplates/CustomNameplates.java index 41888c4..7f53113 100644 --- a/src/main/java/net/momirealms/customnameplates/CustomNameplates.java +++ b/src/main/java/net/momirealms/customnameplates/CustomNameplates.java @@ -29,6 +29,9 @@ import net.momirealms.customnameplates.commands.np.TabCompleteN; import net.momirealms.customnameplates.data.DataManager; import net.momirealms.customnameplates.data.SqlHandler; import net.momirealms.customnameplates.helper.LibraryLoader; +import net.momirealms.customnameplates.hook.IAImageHook; +import net.momirealms.customnameplates.hook.ImageParser; +import net.momirealms.customnameplates.hook.OXImageHook; import net.momirealms.customnameplates.hook.PlaceholderManager; import net.momirealms.customnameplates.nameplates.ProxyDataListener; import net.momirealms.customnameplates.nameplates.TeamManager; @@ -66,6 +69,7 @@ public final class CustomNameplates extends JavaPlugin { private NameplateManager nameplateManager; private ChatBubblesManager chatBubblesManager; private ProxyDataListener proxyDataListener; + private ImageParser imageParser; @Override public void onLoad(){ @@ -116,12 +120,12 @@ public final class CustomNameplates extends JavaPlugin { if (bossBarManager != null) { bossBarManager.unload(); } - if (placeholderManager != null) { - placeholderManager.unload(); - } if (chatBubblesManager != null) { chatBubblesManager.unload(); } + if (placeholderManager != null) { + placeholderManager.unload(); + } if (adventure != null) { adventure.close(); } @@ -236,6 +240,12 @@ public final class CustomNameplates extends JavaPlugin { ConfigManager.Bubbles.load(); this.chatBubblesManager = new ChatBubblesManager("BUBBLE"); this.chatBubblesManager.load(); + if (ConfigManager.Main.itemsAdder) { + this.imageParser = new IAImageHook(); + } + if (ConfigManager.Main.oraxen) { + this.imageParser = new OXImageHook(); + } } else if (this.chatBubblesManager != null) { this.chatBubblesManager.unload(); @@ -281,4 +291,8 @@ public final class CustomNameplates extends JavaPlugin { public NameplateManager getNameplateManager() { return nameplateManager; } + + public ImageParser getImageParser() { + return imageParser; + } } diff --git a/src/main/java/net/momirealms/customnameplates/hook/IAImageHook.java b/src/main/java/net/momirealms/customnameplates/hook/IAImageHook.java new file mode 100644 index 0000000..87d5ae7 --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/hook/IAImageHook.java @@ -0,0 +1,12 @@ +package net.momirealms.customnameplates.hook; + +import dev.lone.itemsadder.api.FontImages.FontImageWrapper; +import org.bukkit.entity.Player; + +public class IAImageHook implements ImageParser{ + + @Override + public String parse(Player player, String text) { + return FontImageWrapper.replaceFontImages(player, text).replace("§f","").replace("§r",""); + } +} diff --git a/src/main/java/net/momirealms/customnameplates/hook/ImageParser.java b/src/main/java/net/momirealms/customnameplates/hook/ImageParser.java new file mode 100644 index 0000000..d18334c --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/hook/ImageParser.java @@ -0,0 +1,8 @@ +package net.momirealms.customnameplates.hook; + +import org.bukkit.entity.Player; + +public interface ImageParser { + + String parse(Player player, String text); +} diff --git a/src/main/java/net/momirealms/customnameplates/hook/OXImageHook.java b/src/main/java/net/momirealms/customnameplates/hook/OXImageHook.java new file mode 100644 index 0000000..2b00fbc --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/hook/OXImageHook.java @@ -0,0 +1,27 @@ +package net.momirealms.customnameplates.hook; + +import io.th0rgal.oraxen.OraxenPlugin; +import io.th0rgal.oraxen.font.FontManager; +import io.th0rgal.oraxen.font.Glyph; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class OXImageHook implements ImageParser{ + + private final FontManager fontManager; + + public OXImageHook() { + this.fontManager = OraxenPlugin.get().getFontManager(); + } + + @Override + public String parse(Player player, String text) { + for (Map.Entry entry : this.fontManager.getGlyphByPlaceholderMap().entrySet()) { + if (entry.getValue().hasPermission(player)) { + text = text.replace(entry.getKey(), "" + entry.getValue().getCharacter() + ""); + } + } + return text; + } +} diff --git a/src/main/java/net/momirealms/customnameplates/nameplates/mode/bubbles/ChatBubblesManager.java b/src/main/java/net/momirealms/customnameplates/nameplates/mode/bubbles/ChatBubblesManager.java index 235ca11..ed9f246 100644 --- a/src/main/java/net/momirealms/customnameplates/nameplates/mode/bubbles/ChatBubblesManager.java +++ b/src/main/java/net/momirealms/customnameplates/nameplates/mode/bubbles/ChatBubblesManager.java @@ -19,6 +19,7 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; +import java.util.HashMap; import java.util.UUID; public class ChatBubblesManager extends EntityTag { @@ -26,6 +27,9 @@ public class ChatBubblesManager extends EntityTag { private BBPacketsHandle packetsHandle; private ChatListener chatListener; + private TrChatListener trChatListener; + + private final HashMap coolDown = new HashMap<>(); public ChatBubblesManager(String name) { super(name); @@ -37,9 +41,14 @@ public class ChatBubblesManager extends EntityTag { this.packetsHandle = new BBPacketsHandle("BUBBLES", this); this.packetsHandle.load(); - this.chatListener = new ChatListener(this); - Bukkit.getPluginManager().registerEvents(chatListener, CustomNameplates.instance); - + if (ConfigManager.Main.trChat) { + this.trChatListener = new TrChatListener(this); + Bukkit.getPluginManager().registerEvents(trChatListener, CustomNameplates.instance); + } + else { + this.chatListener = new ChatListener(this); + Bukkit.getPluginManager().registerEvents(chatListener, CustomNameplates.instance); + } for (Player all : Bukkit.getOnlinePlayers()) { armorStandManagerMap.put(all, new ArmorStandManager(all)); for (Player player : Bukkit.getOnlinePlayers()) @@ -50,7 +59,8 @@ public class ChatBubblesManager extends EntityTag { @Override public void unload() { this.packetsHandle.unload(); - HandlerList.unregisterAll(chatListener); + if (chatListener != null) HandlerList.unregisterAll(chatListener); + if (trChatListener != null) HandlerList.unregisterAll(trChatListener); super.unload(); } @@ -86,18 +96,28 @@ public class ChatBubblesManager extends EntityTag { if (asm != null) { asm.destroy(); } + coolDown.remove(player); } public void onChat(Player player, String text) { + + long time = System.currentTimeMillis(); + if (time - (coolDown.getOrDefault(player, time - ConfigManager.Bubbles.coolDown)) < ConfigManager.Bubbles.coolDown) return; + coolDown.put(player, time); + PlayerData playerData = CustomNameplates.instance.getDataManager().getOrEmpty(player); String bubbles = playerData.getBubbles(); BubbleConfig bubbleConfig = ResourceManager.BUBBLES.get(bubbles); WrappedChatComponent wrappedChatComponent; + if (CustomNameplates.instance.getImageParser() != null) { + text = CustomNameplates.instance.getImageParser().parse(player, text); + } if (bubbleConfig == null || bubbles.equals("none")) { text = ConfigManager.Main.placeholderAPI ? CustomNameplates.instance.getPlaceholderManager().parsePlaceholders(player, ConfigManager.Bubbles.prefix) + ConfigManager.Bubbles.defaultFormat + text + CustomNameplates.instance.getPlaceholderManager().parsePlaceholders(player, ConfigManager.Bubbles.suffix) : ConfigManager.Bubbles.prefix + text + ConfigManager.Bubbles.suffix; + if (text.length() > ConfigManager.Bubbles.maxChar) return; wrappedChatComponent = WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(text))); } else { @@ -106,6 +126,7 @@ public class ChatBubblesManager extends EntityTag { : ConfigManager.Bubbles.prefix + text + ConfigManager.Bubbles.suffix; String stripped = MiniMessage.miniMessage().stripTags(text); + if (stripped.length() > ConfigManager.Bubbles.maxChar) return; String bubble = NameplateUtil.makeCustomBubble("", stripped, "", bubbleConfig); String suffix = NameplateUtil.getSuffixChar(stripped); Component armorStand_Name = Component.text(bubble).font(ConfigManager.Main.key) diff --git a/src/main/java/net/momirealms/customnameplates/nameplates/mode/bubbles/ChatListener.java b/src/main/java/net/momirealms/customnameplates/nameplates/mode/bubbles/ChatListener.java index fded5a2..6bc7870 100644 --- a/src/main/java/net/momirealms/customnameplates/nameplates/mode/bubbles/ChatListener.java +++ b/src/main/java/net/momirealms/customnameplates/nameplates/mode/bubbles/ChatListener.java @@ -11,7 +11,8 @@ public record ChatListener( @EventHandler public void onChat(AsyncPlayerChatEvent event) { - if (!event.isCancelled()) + if (!event.isCancelled()) { chatBubblesManager.onChat(event.getPlayer(), MiniMessage.miniMessage().stripTags(ChatColor.stripColor(event.getMessage()))); + } } } diff --git a/src/main/java/net/momirealms/customnameplates/nameplates/mode/bubbles/TrChatListener.java b/src/main/java/net/momirealms/customnameplates/nameplates/mode/bubbles/TrChatListener.java new file mode 100644 index 0000000..89477d8 --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/nameplates/mode/bubbles/TrChatListener.java @@ -0,0 +1,16 @@ +package net.momirealms.customnameplates.nameplates.mode.bubbles; + +import me.arasple.mc.trchat.api.event.TrChatEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public record TrChatListener( + ChatBubblesManager chatBubblesManager) implements Listener { + + @EventHandler + public void onTrChat(TrChatEvent event) { + if (event.isCancelled()) return; + if (!event.getForward()) return; + chatBubblesManager.onChat(event.getSession().getPlayer(), event.getMessage()); + } +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customnameplates/nameplates/mode/tmpackets/TeamPacketA.java b/src/main/java/net/momirealms/customnameplates/nameplates/mode/tmpackets/TeamPacketA.java index c001922..4dec888 100644 --- a/src/main/java/net/momirealms/customnameplates/nameplates/mode/tmpackets/TeamPacketA.java +++ b/src/main/java/net/momirealms/customnameplates/nameplates/mode/tmpackets/TeamPacketA.java @@ -76,7 +76,7 @@ public class TeamPacketA implements TeamPacketManager { NameplatesTeam nameplatesTeam = teamManager.getTeams().get(teamName); String newInfo = nameplatesTeam.getDynamic(); String oldInfo = teamInfoCache.get(player); - if (newInfo.equals(oldInfo) && !force) { + if (newInfo != null && newInfo.equals(oldInfo) && !force) { return; } teamInfoCache.put(player, newInfo); diff --git a/src/main/java/net/momirealms/customnameplates/resource/ResourceManager.java b/src/main/java/net/momirealms/customnameplates/resource/ResourceManager.java index 0f4e5b6..fd2115b 100644 --- a/src/main/java/net/momirealms/customnameplates/resource/ResourceManager.java +++ b/src/main/java/net/momirealms/customnameplates/resource/ResourceManager.java @@ -539,7 +539,7 @@ public class ResourceManager { } if (ConfigManager.Main.oraxen){ try { - FileUtils.copyDirectory(generated, new File(Bukkit.getPluginManager().getPlugin("Oraxen").getDataFolder() + File.separator + "pack"+ File.separator + "assets")); + FileUtils.copyDirectory(new File(generated, File.separator + ConfigManager.Main.namespace), new File(Bukkit.getPluginManager().getPlugin("Oraxen").getDataFolder() + File.separator + "pack"+ File.separator + "assets" + File.separator + ConfigManager.Main.namespace)); AdventureUtil.consoleMessage("[CustomNameplates] Detected Oraxen! Automatically sent rp to Oraxen folder!"); } catch (IOException e){ diff --git a/src/main/resources/bubble.yml b/src/main/resources/bubble.yml index 1277676..0bfbcf5 100644 --- a/src/main/resources/bubble.yml +++ b/src/main/resources/bubble.yml @@ -1,10 +1,10 @@ # Do not change -config-version: '7' +config-version: '8' bubble: # Player's default chatting bubbles - default-bubbles: 'none' + default-bubbles: 'chat' # Text format when no bubbles equipped default-format: '' @@ -18,8 +18,15 @@ bubble: line-spacing: 0.5 # This decides where the bottom line is - bottom-line-Y-offset: 0.6 + bottom-line-Y-offset: -1.5 # Seconds # This decides how long will the chat hologram remains - stay-time: 5 \ No newline at end of file + stay-time: 5 + + # Plugin would ignore player's chat message when its length is over a certain value + max-char-length: 35 + + # Cool Down (seconds) + # Plugin would ignore player's chat message when it is still in cool down + cool-down: 1 \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6dfde8d..63c8794 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,5 @@ # Do not change -config-version: '9' +config-version: '10' config: # Language @@ -13,6 +13,7 @@ config: PlaceholderAPI: true # When enabled, the plugin will automatically place the resource pack # folder into the resource pack generated by ItemsAdder/Oraxen. + # And players would be able to use emoji in chatting bubbles ItemsAdder: false Oraxen: false # When enabled, the plugin will hook into TAB's team management @@ -21,7 +22,8 @@ config: # When enabled, plugin will receive team data from TAB on proxy server # You need to install CustomNameplates on BungeeCord too, otherwise you might be kicked from the server if you enabled "create-fake-team" in nameplate.yml TAB-BC: false - + # TrChat + TrChat: false # Your namespace # If you don't know how font works, don't change this diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 2374b7f..4bd1680 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -10,6 +10,7 @@ softdepend: - PlaceholderAPI - TAB - Oraxen + - TrChat commands: customnameplates: usage: /customnameplates @@ -54,6 +55,7 @@ permissions: children: bubbles.unequip: true bubbles.equip: true + bubbles.help: true bubbles.forceequip: true bubbles.forceunequip: true bubbles.list: true