9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-19 15:09:23 +00:00
This commit is contained in:
XiaoMoMi
2024-02-03 03:25:34 +08:00
parent 180b34f4c8
commit a6b11d1fe7
31 changed files with 422 additions and 57 deletions

View File

@@ -1,7 +1,7 @@
dependencies { dependencies {
implementation(project(":common"))
compileOnly("dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT") compileOnly("dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT")
compileOnly("me.clip:placeholderapi:2.11.5") compileOnly("me.clip:placeholderapi:2.11.5")
implementation(project(":common"))
implementation("net.kyori:adventure-api:4.15.0") implementation("net.kyori:adventure-api:4.15.0")
} }

View File

@@ -124,4 +124,12 @@ public interface BubbleManager {
* @return keys * @return keys
*/ */
Collection<String> getBubbleKeys(); Collection<String> getBubbleKeys();
/**
* Trigger chat
*
* @param player player
* @param text text
*/
void onChat(Player player, String text);
} }

View File

@@ -15,16 +15,20 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.momirealms.customnameplates.paper.mechanic.bubble.listener; package net.momirealms.customnameplates.api.mechanic.bubble.listener;
import net.momirealms.customnameplates.paper.mechanic.bubble.BubbleManagerImpl; import net.momirealms.customnameplates.api.manager.BubbleManager;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
public abstract class AbstractChatListener implements Listener { public abstract class AbstractChatListener implements Listener {
protected BubbleManagerImpl chatBubblesManager; protected BubbleManager chatBubblesManager;
public AbstractChatListener(BubbleManagerImpl chatBubblesManager) { public AbstractChatListener(BubbleManager chatBubblesManager) {
this.chatBubblesManager = chatBubblesManager; this.chatBubblesManager = chatBubblesManager;
} }
public abstract void register();
public abstract void unregister();
} }

View File

@@ -7,7 +7,7 @@ plugins {
allprojects { allprojects {
version = "2.3.1.0" version = "2.3.1.1-BETA"
apply<JavaPlugin>() apply<JavaPlugin>()
apply(plugin = "java") apply(plugin = "java")

View File

@@ -1,8 +1,8 @@
#systemProp.socks.proxyHost=127.0.0.1 systemProp.socks.proxyHost=127.0.0.1
#systemProp.socks.proxyPort=7890 systemProp.socks.proxyPort=7890
#
#systemProp.http.proxyHost=127.0.0.1 systemProp.http.proxyHost=127.0.0.1
#systemProp.http.proxyPort=7890 systemProp.http.proxyPort=7890
#
#systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyHost=127.0.0.1
#systemProp.https.proxyPort=7890 systemProp.https.proxyPort=7890

View File

@@ -34,10 +34,11 @@ dependencies {
compileOnly("com.github.FrancoBM12:API-MagicCosmetics:2.2.5") compileOnly("com.github.FrancoBM12:API-MagicCosmetics:2.2.5")
compileOnly("commons-io:commons-io:2.15.1") compileOnly("commons-io:commons-io:2.15.1")
// chat channels // chat channels
compileOnly(files("libs/VentureChat-3.7.1.jar")) compileOnly(files("libs/VentureChat-3.7.1.jar"))
compileOnly(files("libs/TrChat-2.0.11.jar")) compileOnly(files("libs/TrChat-2.0.11.jar"))
compileOnly(files("libs/carbonchat-paper-3.0.0-beta.26.jar"))
compileOnly("net.william278:huskchat:2.7.1")
// api module // api module
implementation(project(":api")) implementation(project(":api"))

Binary file not shown.

View File

@@ -116,7 +116,7 @@ public class CommandManager {
for (String availableBubble : bubbles) { for (String availableBubble : bubbles) {
stringJoiner.add(availableBubble); stringJoiner.add(availableBubble);
} }
AdventureManagerImpl.getInstance().sendMessageWithPrefix(player, CNLocale.MSG_AVAILABLE_BUBBLE.replace("{Bubble}", stringJoiner.toString())); AdventureManagerImpl.getInstance().sendMessageWithPrefix(player, CNLocale.MSG_AVAILABLE_BUBBLE.replace("{Bubble}", stringJoiner.toString()).replace("{Bubbles}", stringJoiner.toString()));
} else { } else {
AdventureManagerImpl.getInstance().sendMessageWithPrefix(player, CNLocale.MSG_HAVE_NO_BUBBLE); AdventureManagerImpl.getInstance().sendMessageWithPrefix(player, CNLocale.MSG_HAVE_NO_BUBBLE);
} }
@@ -340,7 +340,7 @@ public class CommandManager {
for (String availableNameplate : nameplates) { for (String availableNameplate : nameplates) {
stringJoiner.add(availableNameplate); stringJoiner.add(availableNameplate);
} }
AdventureManagerImpl.getInstance().sendMessageWithPrefix(player, CNLocale.MSG_AVAILABLE_NAMEPLATE.replace("{Nameplates}", stringJoiner.toString())); AdventureManagerImpl.getInstance().sendMessageWithPrefix(player, CNLocale.MSG_AVAILABLE_NAMEPLATE.replace("{Nameplates}", stringJoiner.toString()).replace("{Nameplate}", stringJoiner.toString()));
} else { } else {
AdventureManagerImpl.getInstance().sendMessageWithPrefix(player, CNLocale.MSG_HAVE_NO_NAMEPLATE); AdventureManagerImpl.getInstance().sendMessageWithPrefix(player, CNLocale.MSG_HAVE_NO_NAMEPLATE);
} }

View File

@@ -62,7 +62,7 @@ public class ActionBarReceiver {
} }
case UPDATE -> { case UPDATE -> {
if (controller.isShown()) { if (controller.isShown()) {
controller.initialize(); controller.initialize(condition);
AdventureManagerImpl.getInstance().sendActionbar(player, controller.getLatestContent()); AdventureManagerImpl.getInstance().sendActionbar(player, controller.getLatestContent());
} else { } else {
AdventureManagerImpl.getInstance().sendActionbar(player, ""); AdventureManagerImpl.getInstance().sendActionbar(player, "");

View File

@@ -98,7 +98,7 @@ public class BossBarReceiver {
if (this.bossBars[j].left().isShown()) if (this.bossBars[j].left().isShown())
this.bossBars[j].right().hide(); this.bossBars[j].right().hide();
controller.initialize(); controller.initialize(condition);
pair.right().setMiniMessageText(pair.left().getLatestContent()); pair.right().setMiniMessageText(pair.left().getLatestContent());
pair.right().show(); pair.right().show();

View File

@@ -19,11 +19,13 @@ package net.momirealms.customnameplates.paper.mechanic.bubble;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.api.data.OnlineUser; import net.momirealms.customnameplates.api.data.OnlineUser;
import net.momirealms.customnameplates.api.event.BubblesSpawnEvent; import net.momirealms.customnameplates.api.event.BubblesSpawnEvent;
import net.momirealms.customnameplates.api.event.NameplateDataLoadEvent; import net.momirealms.customnameplates.api.event.NameplateDataLoadEvent;
import net.momirealms.customnameplates.api.manager.BubbleManager; import net.momirealms.customnameplates.api.manager.BubbleManager;
import net.momirealms.customnameplates.api.mechanic.bubble.Bubble; import net.momirealms.customnameplates.api.mechanic.bubble.Bubble;
import net.momirealms.customnameplates.api.mechanic.bubble.listener.AbstractChatListener;
import net.momirealms.customnameplates.api.mechanic.character.CharacterArranger; import net.momirealms.customnameplates.api.mechanic.character.CharacterArranger;
import net.momirealms.customnameplates.api.mechanic.character.ConfiguredChar; import net.momirealms.customnameplates.api.mechanic.character.ConfiguredChar;
import net.momirealms.customnameplates.api.mechanic.tag.unlimited.EntityTagPlayer; import net.momirealms.customnameplates.api.mechanic.tag.unlimited.EntityTagPlayer;
@@ -36,10 +38,7 @@ import net.momirealms.customnameplates.paper.adventure.AdventureManagerImpl;
import net.momirealms.customnameplates.paper.mechanic.bubble.image.ImageParser; import net.momirealms.customnameplates.paper.mechanic.bubble.image.ImageParser;
import net.momirealms.customnameplates.paper.mechanic.bubble.image.ItemsAdderImageImpl; import net.momirealms.customnameplates.paper.mechanic.bubble.image.ItemsAdderImageImpl;
import net.momirealms.customnameplates.paper.mechanic.bubble.image.OraxenImageImpl; import net.momirealms.customnameplates.paper.mechanic.bubble.image.OraxenImageImpl;
import net.momirealms.customnameplates.paper.mechanic.bubble.listener.AbstractChatListener; import net.momirealms.customnameplates.paper.mechanic.bubble.listener.*;
import net.momirealms.customnameplates.paper.mechanic.bubble.listener.AsyncChatListener;
import net.momirealms.customnameplates.paper.mechanic.bubble.listener.TrChatListener;
import net.momirealms.customnameplates.paper.mechanic.bubble.listener.VentureChatListener;
import net.momirealms.customnameplates.paper.setting.CNConfig; import net.momirealms.customnameplates.paper.setting.CNConfig;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@@ -47,7 +46,6 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -97,7 +95,7 @@ public class BubbleManagerImpl implements BubbleManager {
public void unload() { public void unload() {
this.imageParser = null; this.imageParser = null;
this.bubbleMap.clear(); this.bubbleMap.clear();
if (chatListener != null) HandlerList.unregisterAll(chatListener); if (chatListener != null) chatListener.unregister();
} }
private void loadConfig() { private void loadConfig() {
@@ -127,15 +125,23 @@ public class BubbleManagerImpl implements BubbleManager {
} }
private void registerListener() { private void registerListener() {
PluginManager pluginManager = Bukkit.getPluginManager();
if (CNConfig.trChatChannel) { if (CNConfig.trChatChannel) {
this.chatListener = new TrChatListener(this); this.chatListener = new TrChatListener(this);
} else if (CNConfig.ventureChatChannel) { } else if (CNConfig.ventureChatChannel) {
this.chatListener = new VentureChatListener(this); this.chatListener = new VentureChatListener(this);
} else if (CNConfig.huskChatChannel) {
this.chatListener = new HuskChatListener(this);
} else if (CNConfig.carbonChatChannel) {
this.chatListener = new CarbonChatListener(this);
} else { } else {
try {
Class.forName("io.papermc.paper.event.player.AsyncChatEvent");
this.chatListener = new PaperAsyncChatListener(this);
} catch (ClassNotFoundException e) {
this.chatListener = new AsyncChatListener(this); this.chatListener = new AsyncChatListener(this);
} }
pluginManager.registerEvents(chatListener, plugin); }
this.chatListener.register();
} }
private void loadBubbles() { private void loadBubbles() {
@@ -214,6 +220,12 @@ public class BubbleManagerImpl implements BubbleManager {
|| !player.hasPermission("bubbles.use") || !player.hasPermission("bubbles.use")
) return; ) return;
if (Bukkit.isPrimaryThread()) {
String finalText = text;
CustomNameplatesPlugin.get().getScheduler().runTaskAsync(() -> onChat(player, finalText));
return;
}
var optionalUser = plugin.getStorageManager().getOnlineUser(player.getUniqueId()); var optionalUser = plugin.getStorageManager().getOnlineUser(player.getUniqueId());
if (optionalUser.isEmpty()) { if (optionalUser.isEmpty()) {
return; return;

View File

@@ -18,19 +18,31 @@
package net.momirealms.customnameplates.paper.mechanic.bubble.listener; package net.momirealms.customnameplates.paper.mechanic.bubble.listener;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin; import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.paper.mechanic.bubble.BubbleManagerImpl; import net.momirealms.customnameplates.api.manager.BubbleManager;
import net.momirealms.customnameplates.api.mechanic.bubble.listener.AbstractChatListener;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
public class AsyncChatListener extends AbstractChatListener { public class AsyncChatListener extends AbstractChatListener {
public AsyncChatListener(BubbleManagerImpl chatBubblesManager) { public AsyncChatListener(BubbleManager chatBubblesManager) {
super(chatBubblesManager); super(chatBubblesManager);
} }
@EventHandler @Override
public void register() {
Bukkit.getPluginManager().registerEvents(this, CustomNameplatesPlugin.get());
}
@Override
public void unregister() {
HandlerList.unregisterAll(this);
}
@EventHandler (ignoreCancelled = true)
public void onChat(AsyncPlayerChatEvent event) { public void onChat(AsyncPlayerChatEvent event) {
if (event.isCancelled()) return;
CustomNameplatesPlugin.get().getScheduler().runTaskAsync(() -> chatBubblesManager.onChat(event.getPlayer(), event.getMessage())); CustomNameplatesPlugin.get().getScheduler().runTaskAsync(() -> chatBubblesManager.onChat(event.getPlayer(), event.getMessage()));
} }
} }

View File

@@ -0,0 +1,98 @@
/*
* 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.paper.mechanic.bubble.listener;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.event.CarbonEventSubscription;
import net.draycia.carbon.api.event.events.CarbonChatEvent;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.api.manager.BubbleManager;
import net.momirealms.customnameplates.api.mechanic.bubble.listener.AbstractChatListener;
import net.momirealms.customnameplates.paper.util.ReflectionUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class CarbonChatListener extends AbstractChatListener {
private final CarbonChat api;
private CarbonEventSubscription<CarbonChatEvent> subscription;
private Method originalMessageMethod;
private Method channelKeyMethod;
public CarbonChatListener(BubbleManager chatBubblesManager) {
super(chatBubblesManager);
this.api = CarbonChatProvider.carbonChat();
try {
this.originalMessageMethod = CarbonChatEvent.class.getMethod("originalMessage");
this.channelKeyMethod = ChatChannel.class.getMethod("key");
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void register() {
subscription = api.eventHandler().subscribe(CarbonChatEvent.class, event -> {
if (event.cancelled())
return;
ChatChannel chatChannel = event.chatChannel();
Object key = getChannelKey(chatChannel);
if (key == null) return;
String channel = ReflectionUtils.getKeyAsString(key);
for (String black : chatBubblesManager.getBlacklistChannels()) {
if (channel.equals(black)) return;
}
Player player = Bukkit.getPlayer(event.sender().uuid());
if (player == null || !player.isOnline())
return;
Object component = getComponentFromEvent(event);
String message = ReflectionUtils.getMiniMessageTextFromNonShadedComponent(component);
CustomNameplatesPlugin.get().getScheduler().runTaskAsync(() -> chatBubblesManager.onChat(player, message));
});
}
@Override
public void unregister() {
if (subscription != null) {
subscription.dispose();
}
}
private Object getChannelKey(ChatChannel channel) {
try {
return this.channelKeyMethod.invoke(channel);
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
private Object getComponentFromEvent(CarbonChatEvent event) {
try {
return this.originalMessageMethod.invoke(event);
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
return ReflectionUtils.getEmptyComponent();
}
}

View File

@@ -0,0 +1,58 @@
/*
* 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.paper.mechanic.bubble.listener;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.api.manager.BubbleManager;
import net.momirealms.customnameplates.api.mechanic.bubble.listener.AbstractChatListener;
import net.william278.huskchat.bukkit.event.ChatMessageEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
public class HuskChatListener extends AbstractChatListener {
public HuskChatListener(BubbleManager chatBubblesManager) {
super(chatBubblesManager);
}
@Override
public void register() {
Bukkit.getPluginManager().registerEvents(this, CustomNameplatesPlugin.get());
}
@Override
public void unregister() {
HandlerList.unregisterAll(this);
}
@EventHandler (ignoreCancelled = true)
public void onHuskChat(ChatMessageEvent event) {
String channel = event.getChannelId();
for (String black : chatBubblesManager.getBlacklistChannels()) {
if (channel.equals(black)) return;
}
Player player = Bukkit.getPlayer(event.getSender().getUuid());
if (player == null || !player.isOnline())
return;
CustomNameplatesPlugin.get().getScheduler().runTaskAsync(() -> {
chatBubblesManager.onChat(player, event.getMessage());
});
}
}

View File

@@ -0,0 +1,70 @@
/*
* 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.paper.mechanic.bubble.listener;
import io.papermc.paper.event.player.AsyncChatEvent;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.api.manager.BubbleManager;
import net.momirealms.customnameplates.api.mechanic.bubble.listener.AbstractChatListener;
import net.momirealms.customnameplates.paper.util.ReflectionUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class PaperAsyncChatListener extends AbstractChatListener {
private Method messageMethod;
public PaperAsyncChatListener(BubbleManager chatBubblesManager) {
super(chatBubblesManager);
try {
this.messageMethod = AsyncChatEvent.class.getMethod("message");
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void register() {
Bukkit.getPluginManager().registerEvents(this, CustomNameplatesPlugin.get());
}
@Override
public void unregister() {
HandlerList.unregisterAll(this);
}
@EventHandler (ignoreCancelled = true)
public void onChat(AsyncChatEvent event) {
Object component = getComponentFromEvent(event);
String message = ReflectionUtils.getMiniMessageTextFromNonShadedComponent(component);
CustomNameplatesPlugin.get().getScheduler().runTaskAsync(() -> chatBubblesManager.onChat(event.getPlayer(), message));
}
private Object getComponentFromEvent(AsyncChatEvent event) {
try {
return this.messageMethod.invoke(event);
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
return ReflectionUtils.getEmptyComponent();
}
}

View File

@@ -23,20 +23,31 @@ import me.arasple.mc.trchat.module.display.channel.Channel;
import me.arasple.mc.trchat.module.internal.filter.FilteredObject; import me.arasple.mc.trchat.module.internal.filter.FilteredObject;
import me.arasple.mc.trchat.taboolib.platform.BukkitAdapter; import me.arasple.mc.trchat.taboolib.platform.BukkitAdapter;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin; import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.paper.mechanic.bubble.BubbleManagerImpl; import net.momirealms.customnameplates.api.manager.BubbleManager;
import net.momirealms.customnameplates.api.mechanic.bubble.listener.AbstractChatListener;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import java.util.Arrays;
public class TrChatListener extends AbstractChatListener { public class TrChatListener extends AbstractChatListener {
private final BukkitAdapter adapter; private final BukkitAdapter adapter;
public TrChatListener(BubbleManagerImpl chatBubblesManager) { public TrChatListener(BubbleManager chatBubblesManager) {
super(chatBubblesManager); super(chatBubblesManager);
this.adapter = new BukkitAdapter(); this.adapter = new BukkitAdapter();
} }
@Override
public void register() {
Bukkit.getPluginManager().registerEvents(this, CustomNameplatesPlugin.get());
}
@Override
public void unregister() {
HandlerList.unregisterAll(this);
}
@EventHandler (ignoreCancelled = true) @EventHandler (ignoreCancelled = true)
public void onTrChat(TrChatEvent event) { public void onTrChat(TrChatEvent event) {
if (!event.getForward()) return; if (!event.getForward()) return;

View File

@@ -20,16 +20,29 @@ package net.momirealms.customnameplates.paper.mechanic.bubble.listener;
import mineverse.Aust1n46.chat.api.MineverseChatPlayer; import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
import mineverse.Aust1n46.chat.api.events.VentureChatEvent; import mineverse.Aust1n46.chat.api.events.VentureChatEvent;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin; import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.paper.mechanic.bubble.BubbleManagerImpl; import net.momirealms.customnameplates.api.manager.BubbleManager;
import net.momirealms.customnameplates.api.mechanic.bubble.listener.AbstractChatListener;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
public class VentureChatListener extends AbstractChatListener { public class VentureChatListener extends AbstractChatListener {
public VentureChatListener(BubbleManagerImpl chatBubblesManager) { public VentureChatListener(BubbleManager chatBubblesManager) {
super(chatBubblesManager); super(chatBubblesManager);
} }
@EventHandler @Override
public void register() {
Bukkit.getPluginManager().registerEvents(this, CustomNameplatesPlugin.get());
}
@Override
public void unregister() {
HandlerList.unregisterAll(this);
}
@EventHandler (ignoreCancelled = true)
public void onVentureChat(VentureChatEvent event) { public void onVentureChat(VentureChatEvent event) {
String channelName = event.getChannel().getName(); String channelName = event.getChannel().getName();
for (String channel : chatBubblesManager.getBlacklistChannels()) { for (String channel : chatBubblesManager.getBlacklistChannels()) {

View File

@@ -21,6 +21,7 @@ import me.clip.placeholderapi.PlaceholderAPI;
import net.momirealms.customnameplates.api.manager.RequirementManager; import net.momirealms.customnameplates.api.manager.RequirementManager;
import net.momirealms.customnameplates.api.requirement.Condition; import net.momirealms.customnameplates.api.requirement.Condition;
import net.momirealms.customnameplates.api.requirement.Requirement; import net.momirealms.customnameplates.api.requirement.Requirement;
import net.momirealms.customnameplates.api.util.LogUtils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class DisplayController { public class DisplayController {
@@ -35,6 +36,7 @@ public class DisplayController {
private int timeLeft; private int timeLeft;
private int index; private int index;
private final TimeLimitText[] texts; private final TimeLimitText[] texts;
private boolean metAnyCondition;
public DisplayController( public DisplayController(
Player player, Player player,
@@ -44,10 +46,10 @@ public class DisplayController {
) { ) {
this.owner = player; this.owner = player;
this.checkFrequency = checkFrequency; this.checkFrequency = checkFrequency;
this.checkTimer = 0;
this.refreshTimer = 0; this.refreshTimer = 0;
this.requirements = requirements; this.requirements = requirements;
this.texts = texts; this.texts = texts;
this.checkTimer = checkFrequency - 1;
} }
public NextStage stateCheck(Condition condition) { public NextStage stateCheck(Condition condition) {
@@ -78,21 +80,33 @@ public class DisplayController {
} }
public boolean updateText(Condition condition) { public boolean updateText(Condition condition) {
if (timeLeft > 0)
timeLeft--; timeLeft--;
// Definitely goto "if" on init
if (timeLeft == 0) { if (timeLeft == 0) {
int triedTimes = 0;
do { do {
index++; index++;
if (index >= texts.length) { if (index >= texts.length) {
index = 0; index = 0;
} }
if (triedTimes == texts.length) {
timeLeft = Math.max(checkFrequency, 1);
metAnyCondition = false;
LogUtils.warn("No text is available for player " + owner.getName() + ". Please check your conditions.");
return updateText("");
}
triedTimes++;
} while (!RequirementManager.isRequirementMet(condition, texts[index].getRequirements())); } while (!RequirementManager.isRequirementMet(condition, texts[index].getRequirements()));
metAnyCondition = true;
timeLeft = texts[index].getDuration(); timeLeft = texts[index].getDuration();
refreshTimer = 0; refreshTimer = 0;
return updateText(texts[index].getText()); return updateText(texts[index].getText());
} }
if (texts[index].getRefreshFrequency() <= 0) { if (!metAnyCondition || texts[index].getRefreshFrequency() <= 0) {
return false; return false;
} }
@@ -114,12 +128,13 @@ public class DisplayController {
return true; return true;
} }
public void initialize() { public void initialize(Condition condition) {
index = 0; index = texts.length - 1;
checkTimer = 0; checkTimer = 0;
refreshTimer = 0; refreshTimer = 0;
timeLeft = texts[0].getDuration(); timeLeft = 1;
latestValue = PlaceholderAPI.setPlaceholders(owner, texts[0].getText()); // The text would definitely be refreshed
updateText(condition);
} }
public String getLatestContent() { public String getLatestContent() {

View File

@@ -55,7 +55,6 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;

View File

@@ -17,7 +17,6 @@
package net.momirealms.customnameplates.paper.mechanic.placeholder; package net.momirealms.customnameplates.paper.mechanic.placeholder;
import me.clip.placeholderapi.PlaceholderAPI;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin; import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.api.manager.PlaceholderManager; import net.momirealms.customnameplates.api.manager.PlaceholderManager;
import net.momirealms.customnameplates.api.mechanic.character.ConfiguredChar; import net.momirealms.customnameplates.api.mechanic.character.ConfiguredChar;

View File

@@ -38,7 +38,7 @@ import java.util.Objects;
public class CNConfig { public class CNConfig {
public static String configVersion = "25"; public static String configVersion = "26";
public static int cacheSize; public static int cacheSize;
public static int corePoolSize; public static int corePoolSize;
public static long keepAliveTime; public static long keepAliveTime;
@@ -83,6 +83,8 @@ public class CNConfig {
public static boolean unknownTeam; public static boolean unknownTeam;
public static boolean createRealTeam; public static boolean createRealTeam;
public static boolean enableShader; public static boolean enableShader;
public static boolean huskChatChannel;
public static boolean carbonChatChannel;
public static void load() { public static void load() {
try { try {
@@ -130,6 +132,8 @@ public class CNConfig {
copyPackOraxen = integrationSection.getBoolean("resource-pack.Oraxen", false); copyPackOraxen = integrationSection.getBoolean("resource-pack.Oraxen", false);
trChatChannel = integrationSection.getBoolean("chat.TrChat", false); trChatChannel = integrationSection.getBoolean("chat.TrChat", false);
ventureChatChannel = integrationSection.getBoolean("chat.VentureChat", false); ventureChatChannel = integrationSection.getBoolean("chat.VentureChat", false);
huskChatChannel = integrationSection.getBoolean("chat.HuskChat", false);
carbonChatChannel = integrationSection.getBoolean("chat.CarbonChat", false);
tabTeam = integrationSection.getBoolean("team.TAB", false); tabTeam = integrationSection.getBoolean("team.TAB", false);
cmiTeam = integrationSection.getBoolean("team.CMI", false); cmiTeam = integrationSection.getBoolean("team.CMI", false);
velocitab = integrationSection.getBoolean("team.Velocitab", false); velocitab = integrationSection.getBoolean("team.Velocitab", false);

View File

@@ -38,10 +38,37 @@ public class Migration {
updateBubble(); updateBubble();
updateNameplate(); updateNameplate();
updateCustomPlaceholders(); updateCustomPlaceholders();
updateLanguages();
deleteFiles(); deleteFiles();
return true; return true;
} }
private static void updateLanguages() {
File messageFolder = new File(CustomNameplatesPlugin.get().getDataFolder(), "messages");
if (messageFolder.exists()) {
File[] files = messageFolder.listFiles();
if (files == null)
return;
for (File file : files) {
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
ConfigurationSection messageSection = config.getConfigurationSection("messages");
if (messageSection != null) {
for (String key : messageSection.getKeys(false)) {
String original = messageSection.getString(key);
if (original != null && original.contains("{Bubbles}")) {
messageSection.set(key, original.replace("{Bubbles}", "{Bubble}"));
}
}
}
try {
config.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private static void deleteFiles() { private static void deleteFiles() {
try { try {
FileUtils.delete(new File(CustomNameplatesPlugin.get().getDataFolder(), "database.yml")); FileUtils.delete(new File(CustomNameplatesPlugin.get().getDataFolder(), "database.yml"));

View File

@@ -34,6 +34,9 @@ public class ReflectionUtils {
private static Constructor<?> updateConstructor; private static Constructor<?> updateConstructor;
private static Method iChatComponentMethod; private static Method iChatComponentMethod;
private static Object emptyComponent; private static Object emptyComponent;
private static Method serializeComponentMethod;
private static Method keyAsStringMethod;
private static Object miniMessageInstance;
public static void load() { public static void load() {
try { try {
@@ -54,6 +57,17 @@ public class ReflectionUtils {
LogUtils.severe("Error occurred when loading reflections", exception); LogUtils.severe("Error occurred when loading reflections", exception);
exception.printStackTrace(); exception.printStackTrace();
} }
try {
Class<?> componentClass = Class.forName("net;kyori;adventure;text;Component".replace(";", "."));
Class<?> miniMessageClass = Class.forName("net;kyori;adventure;text;minimessage;MiniMessage".replace(";", "."));
Method miniMessageInstanceGetMethod = miniMessageClass.getMethod("miniMessage");
miniMessageInstance = miniMessageInstanceGetMethod.invoke(null);
serializeComponentMethod = miniMessageClass.getMethod("serialize", componentClass);
Class<?> keyClass = Class.forName("net;kyori;adventure;key;Key".replace(";", "."));
keyAsStringMethod = keyClass.getMethod("asString");
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
IllegalAccessException ignored) {
}
} }
public static Object getRemoveBossBarPacket() { public static Object getRemoveBossBarPacket() {
@@ -75,4 +89,22 @@ public class ReflectionUtils {
public static Object getEmptyComponent() { public static Object getEmptyComponent() {
return emptyComponent; return emptyComponent;
} }
public static String getKeyAsString(Object key) {
try {
return (String) keyAsStringMethod.invoke(key);
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
return "";
}
public static String getMiniMessageTextFromNonShadedComponent(Object component) {
try {
return (String) serializeComponentMethod.invoke(miniMessageInstance, component);
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
return "";
}
} }

View File

@@ -1,5 +1,5 @@
# Do not change # Do not change
config-version: '25' config-version: '26'
# Debug mode # Debug mode
debug: false debug: false
@@ -38,6 +38,8 @@ integrations:
chat: chat:
TrChat: false TrChat: false
VentureChat: false VentureChat: false
HuskChat: false
CarbonChat: false
resource-pack: resource-pack:
# disable resource pack generation on server start # disable resource pack generation on server start

View File

@@ -15,7 +15,7 @@ messages:
force-unequip-nameplates: '<white>你已强制卸下玩家 {Player} 的铭牌!</white>' force-unequip-nameplates: '<white>你已强制卸下玩家 {Player} 的铭牌!</white>'
not-exist-nameplates: '<white>那个铭牌不存在!</white>' not-exist-nameplates: '<white>那个铭牌不存在!</white>'
not-available-nameplates: '<white>你还未拥有这个铭牌!</white>' not-available-nameplates: '<white>你还未拥有这个铭牌!</white>'
available-nameplates: '<white>可用铭牌: {Nameplates}</white>' available-nameplates: '<white>可用铭牌: {Nameplate}</white>'
have-no-nameplates: '<white>你还没有拥有任何铭牌.</white>' have-no-nameplates: '<white>你还没有拥有任何铭牌.</white>'
force-preview: '<white>正在强制玩家 {Player} 预览铭牌</white>' force-preview: '<white>正在强制玩家 {Player} 预览铭牌</white>'

View File

@@ -15,7 +15,7 @@ messages:
force-unequip-nameplates: '<white>Successfully removed {Player}''s nameplate!</white>' force-unequip-nameplates: '<white>Successfully removed {Player}''s nameplate!</white>'
not-exist-nameplates: '<white>This nameplate does not exist!</white>' not-exist-nameplates: '<white>This nameplate does not exist!</white>'
not-available-nameplates: '<white>This nameplate is currently not available!</white>' not-available-nameplates: '<white>This nameplate is currently not available!</white>'
available-nameplates: '<white>Available nameplates: {Nameplates}.</white>' available-nameplates: '<white>Available nameplates: {Nameplate}.</white>'
have-no-nameplates: '<white>You don''t have any nameplate yet' have-no-nameplates: '<white>You don''t have any nameplate yet'
force-preview: '<white>Forced {Player} to preview the nameplate</white>' force-preview: '<white>Forced {Player} to preview the nameplate</white>'

View File

@@ -15,7 +15,7 @@ messages:
force-unequip-nameplates: '<white>La plaque de nom de {Player} a été retirée avec succès !</white>' force-unequip-nameplates: '<white>La plaque de nom de {Player} a été retirée avec succès !</white>'
not-exist-nameplates: '<white>Cette plaque de nom n'existe pas !</white>' not-exist-nameplates: '<white>Cette plaque de nom n'existe pas !</white>'
not-available-nameplates: '<white>Cette plaque de nom n'est actuellement pas disponible !</white>' not-available-nameplates: '<white>Cette plaque de nom n'est actuellement pas disponible !</white>'
available-nameplates: '<white>Plaques de nom disponibles : {Nameplates}.</white>' available-nameplates: '<white>Plaques de nom disponibles : {Nameplate}.</white>'
have-no-nameplates: '<white>Vous n'avez pas encore de plaque de nom</white>' have-no-nameplates: '<white>Vous n'avez pas encore de plaque de nom</white>'
force-preview: '<white>Forced {Player} to preview the nameplate</white>' force-preview: '<white>Forced {Player} to preview the nameplate</white>'

View File

@@ -15,7 +15,7 @@ messages:
force-unequip-nameplates: '<white>Успешно снят Нэймплейт у {Player}!</white>' force-unequip-nameplates: '<white>Успешно снят Нэймплейт у {Player}!</white>'
not-exist-nameplates: '<white>Такой Нэйплейт не существует!</white>' not-exist-nameplates: '<white>Такой Нэйплейт не существует!</white>'
not-available-nameplates: '<white>Этот Нэймплейт сейчас недоступен!</white>' not-available-nameplates: '<white>Этот Нэймплейт сейчас недоступен!</white>'
available-nameplates: '<white>Доступные Нэймплейты: {Nameplates}.</white>' available-nameplates: '<white>Доступные Нэймплейты: {Nameplate}.</white>'
have-no-nameplates: '<white>У вас еще нет никаких Нэймплейтов.' have-no-nameplates: '<white>У вас еще нет никаких Нэймплейтов.'
force-preview: '<white>Forced {Player} to preview the nameplate</white>' force-preview: '<white>Forced {Player} to preview the nameplate</white>'

View File

@@ -15,7 +15,7 @@ messages:
force-unequip-nameplates: '<white>Eliminado con éxito {Player}''s nameplate!</white>' force-unequip-nameplates: '<white>Eliminado con éxito {Player}''s nameplate!</white>'
not-exist-nameplates: '<white>Este nameplate no existe!</white>' not-exist-nameplates: '<white>Este nameplate no existe!</white>'
not-available-nameplates: '<white>Este nameplate no esta actualmente disponible!</white>' not-available-nameplates: '<white>Este nameplate no esta actualmente disponible!</white>'
available-nameplates: '<white>Nameplates Disponibles: {Nameplates}.</white>' available-nameplates: '<white>Nameplates Disponibles: {Nameplate}.</white>'
have-no-nameplates: '<white>No tienes ningun nameplate aun' have-no-nameplates: '<white>No tienes ningun nameplate aun'
force-preview: '<white>Forced {Player} to preview the nameplate</white>' force-preview: '<white>Forced {Player} to preview the nameplate</white>'

View File

@@ -16,7 +16,7 @@ messages:
force-unequip-nameplates: '<white>{Player} oyuncusunun isim etiketi başarıyla kaldırıldı!</white>' force-unequip-nameplates: '<white>{Player} oyuncusunun isim etiketi başarıyla kaldırıldı!</white>'
not-exist-nameplates: '<white>Bu isim etiketi mevcut değil!</white>' not-exist-nameplates: '<white>Bu isim etiketi mevcut değil!</white>'
not-available-nameplates: '<white>Bu isim etiketi şu anda kullanılabilir değil!</white>' not-available-nameplates: '<white>Bu isim etiketi şu anda kullanılabilir değil!</white>'
available-nameplates: '<white>Mevcut isim etiketleri: {Nameplates}.</white>' available-nameplates: '<white>Mevcut isim etiketleri: {Nameplate}.</white>'
have-no-nameplates: '<white>Henüz hiç isim etiketiniz yok</white>' have-no-nameplates: '<white>Henüz hiç isim etiketiniz yok</white>'
force-preview: '<white>Forced {Player} to preview the nameplate</white>' force-preview: '<white>Forced {Player} to preview the nameplate</white>'

View File

@@ -5,7 +5,7 @@ api-version: 1.17
authors: [ XiaoMoMi ] authors: [ XiaoMoMi ]
folia-supported: true folia-supported: true
depend: [ ProtocolLib ,PlaceholderAPI ] depend: [ ProtocolLib ,PlaceholderAPI ]
softdepend: [ MagicCosmetics, TAB, CMI, TrChat, ItemsAdder, Oraxen ] softdepend: [ MagicCosmetics, TAB, CMI, TrChat, ItemsAdder, Oraxen, CarbonChat, HuskChat ]
permissions: permissions:
nameplates.command.*: nameplates.command.*:
description: Gives access to all nameplate user commands description: Gives access to all nameplate user commands