mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-19 15:09:23 +00:00
2.3.2
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
dependencies {
|
||||
implementation(project(":common"))
|
||||
compileOnly("dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT")
|
||||
compileOnly("me.clip:placeholderapi:2.11.5")
|
||||
implementation(project(":common"))
|
||||
implementation("net.kyori:adventure-api:4.15.0")
|
||||
}
|
||||
|
||||
|
||||
@@ -124,4 +124,12 @@ public interface BubbleManager {
|
||||
* @return keys
|
||||
*/
|
||||
Collection<String> getBubbleKeys();
|
||||
|
||||
/**
|
||||
* Trigger chat
|
||||
*
|
||||
* @param player player
|
||||
* @param text text
|
||||
*/
|
||||
void onChat(Player player, String text);
|
||||
}
|
||||
|
||||
@@ -15,16 +15,20 @@
|
||||
* 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;
|
||||
|
||||
public abstract class AbstractChatListener implements Listener {
|
||||
|
||||
protected BubbleManagerImpl chatBubblesManager;
|
||||
protected BubbleManager chatBubblesManager;
|
||||
|
||||
public AbstractChatListener(BubbleManagerImpl chatBubblesManager) {
|
||||
public AbstractChatListener(BubbleManager chatBubblesManager) {
|
||||
this.chatBubblesManager = chatBubblesManager;
|
||||
}
|
||||
|
||||
public abstract void register();
|
||||
|
||||
public abstract void unregister();
|
||||
}
|
||||
@@ -7,7 +7,7 @@ plugins {
|
||||
|
||||
allprojects {
|
||||
|
||||
version = "2.3.1.0"
|
||||
version = "2.3.1.1-BETA"
|
||||
|
||||
apply<JavaPlugin>()
|
||||
apply(plugin = "java")
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#systemProp.socks.proxyHost=127.0.0.1
|
||||
#systemProp.socks.proxyPort=7890
|
||||
#
|
||||
#systemProp.http.proxyHost=127.0.0.1
|
||||
#systemProp.http.proxyPort=7890
|
||||
#
|
||||
#systemProp.https.proxyHost=127.0.0.1
|
||||
#systemProp.https.proxyPort=7890
|
||||
systemProp.socks.proxyHost=127.0.0.1
|
||||
systemProp.socks.proxyPort=7890
|
||||
|
||||
systemProp.http.proxyHost=127.0.0.1
|
||||
systemProp.http.proxyPort=7890
|
||||
|
||||
systemProp.https.proxyHost=127.0.0.1
|
||||
systemProp.https.proxyPort=7890
|
||||
@@ -34,10 +34,11 @@ dependencies {
|
||||
compileOnly("com.github.FrancoBM12:API-MagicCosmetics:2.2.5")
|
||||
compileOnly("commons-io:commons-io:2.15.1")
|
||||
|
||||
|
||||
// chat channels
|
||||
compileOnly(files("libs/VentureChat-3.7.1.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
|
||||
implementation(project(":api"))
|
||||
|
||||
BIN
paper/libs/carbonchat-paper-3.0.0-beta.26.jar
Normal file
BIN
paper/libs/carbonchat-paper-3.0.0-beta.26.jar
Normal file
Binary file not shown.
@@ -116,7 +116,7 @@ public class CommandManager {
|
||||
for (String availableBubble : bubbles) {
|
||||
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 {
|
||||
AdventureManagerImpl.getInstance().sendMessageWithPrefix(player, CNLocale.MSG_HAVE_NO_BUBBLE);
|
||||
}
|
||||
@@ -340,7 +340,7 @@ public class CommandManager {
|
||||
for (String availableNameplate : nameplates) {
|
||||
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 {
|
||||
AdventureManagerImpl.getInstance().sendMessageWithPrefix(player, CNLocale.MSG_HAVE_NO_NAMEPLATE);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class ActionBarReceiver {
|
||||
}
|
||||
case UPDATE -> {
|
||||
if (controller.isShown()) {
|
||||
controller.initialize();
|
||||
controller.initialize(condition);
|
||||
AdventureManagerImpl.getInstance().sendActionbar(player, controller.getLatestContent());
|
||||
} else {
|
||||
AdventureManagerImpl.getInstance().sendActionbar(player, "");
|
||||
|
||||
@@ -98,7 +98,7 @@ public class BossBarReceiver {
|
||||
if (this.bossBars[j].left().isShown())
|
||||
this.bossBars[j].right().hide();
|
||||
|
||||
controller.initialize();
|
||||
controller.initialize(condition);
|
||||
pair.right().setMiniMessageText(pair.left().getLatestContent());
|
||||
pair.right().show();
|
||||
|
||||
|
||||
@@ -19,11 +19,13 @@ package net.momirealms.customnameplates.paper.mechanic.bubble;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
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.event.BubblesSpawnEvent;
|
||||
import net.momirealms.customnameplates.api.event.NameplateDataLoadEvent;
|
||||
import net.momirealms.customnameplates.api.manager.BubbleManager;
|
||||
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.ConfiguredChar;
|
||||
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.ItemsAdderImageImpl;
|
||||
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.AsyncChatListener;
|
||||
import net.momirealms.customnameplates.paper.mechanic.bubble.listener.TrChatListener;
|
||||
import net.momirealms.customnameplates.paper.mechanic.bubble.listener.VentureChatListener;
|
||||
import net.momirealms.customnameplates.paper.mechanic.bubble.listener.*;
|
||||
import net.momirealms.customnameplates.paper.setting.CNConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -47,7 +46,6 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -97,7 +95,7 @@ public class BubbleManagerImpl implements BubbleManager {
|
||||
public void unload() {
|
||||
this.imageParser = null;
|
||||
this.bubbleMap.clear();
|
||||
if (chatListener != null) HandlerList.unregisterAll(chatListener);
|
||||
if (chatListener != null) chatListener.unregister();
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
@@ -127,15 +125,23 @@ public class BubbleManagerImpl implements BubbleManager {
|
||||
}
|
||||
|
||||
private void registerListener() {
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
if (CNConfig.trChatChannel) {
|
||||
this.chatListener = new TrChatListener(this);
|
||||
} else if (CNConfig.ventureChatChannel) {
|
||||
this.chatListener = new VentureChatListener(this);
|
||||
} else if (CNConfig.huskChatChannel) {
|
||||
this.chatListener = new HuskChatListener(this);
|
||||
} else if (CNConfig.carbonChatChannel) {
|
||||
this.chatListener = new CarbonChatListener(this);
|
||||
} else {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.event.player.AsyncChatEvent");
|
||||
this.chatListener = new PaperAsyncChatListener(this);
|
||||
} catch (ClassNotFoundException e) {
|
||||
this.chatListener = new AsyncChatListener(this);
|
||||
}
|
||||
pluginManager.registerEvents(chatListener, plugin);
|
||||
}
|
||||
this.chatListener.register();
|
||||
}
|
||||
|
||||
private void loadBubbles() {
|
||||
@@ -214,6 +220,12 @@ public class BubbleManagerImpl implements BubbleManager {
|
||||
|| !player.hasPermission("bubbles.use")
|
||||
) return;
|
||||
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
String finalText = text;
|
||||
CustomNameplatesPlugin.get().getScheduler().runTaskAsync(() -> onChat(player, finalText));
|
||||
return;
|
||||
}
|
||||
|
||||
var optionalUser = plugin.getStorageManager().getOnlineUser(player.getUniqueId());
|
||||
if (optionalUser.isEmpty()) {
|
||||
return;
|
||||
|
||||
@@ -18,19 +18,31 @@
|
||||
package net.momirealms.customnameplates.paper.mechanic.bubble.listener;
|
||||
|
||||
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.HandlerList;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public class AsyncChatListener extends AbstractChatListener {
|
||||
|
||||
public AsyncChatListener(BubbleManagerImpl chatBubblesManager) {
|
||||
public AsyncChatListener(BubbleManager 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) {
|
||||
if (event.isCancelled()) return;
|
||||
CustomNameplatesPlugin.get().getScheduler().runTaskAsync(() -> chatBubblesManager.onChat(event.getPlayer(), event.getMessage()));
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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.taboolib.platform.BukkitAdapter;
|
||||
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 java.util.Arrays;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class TrChatListener extends AbstractChatListener {
|
||||
|
||||
private final BukkitAdapter adapter;
|
||||
|
||||
public TrChatListener(BubbleManagerImpl chatBubblesManager) {
|
||||
public TrChatListener(BubbleManager chatBubblesManager) {
|
||||
super(chatBubblesManager);
|
||||
this.adapter = new BukkitAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
Bukkit.getPluginManager().registerEvents(this, CustomNameplatesPlugin.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister() {
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
@EventHandler (ignoreCancelled = true)
|
||||
public void onTrChat(TrChatEvent event) {
|
||||
if (!event.getForward()) return;
|
||||
|
||||
@@ -20,16 +20,29 @@ package net.momirealms.customnameplates.paper.mechanic.bubble.listener;
|
||||
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
|
||||
import mineverse.Aust1n46.chat.api.events.VentureChatEvent;
|
||||
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.HandlerList;
|
||||
|
||||
public class VentureChatListener extends AbstractChatListener {
|
||||
|
||||
public VentureChatListener(BubbleManagerImpl chatBubblesManager) {
|
||||
public VentureChatListener(BubbleManager 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) {
|
||||
String channelName = event.getChannel().getName();
|
||||
for (String channel : chatBubblesManager.getBlacklistChannels()) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.momirealms.customnameplates.api.manager.RequirementManager;
|
||||
import net.momirealms.customnameplates.api.requirement.Condition;
|
||||
import net.momirealms.customnameplates.api.requirement.Requirement;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DisplayController {
|
||||
@@ -35,6 +36,7 @@ public class DisplayController {
|
||||
private int timeLeft;
|
||||
private int index;
|
||||
private final TimeLimitText[] texts;
|
||||
private boolean metAnyCondition;
|
||||
|
||||
public DisplayController(
|
||||
Player player,
|
||||
@@ -44,10 +46,10 @@ public class DisplayController {
|
||||
) {
|
||||
this.owner = player;
|
||||
this.checkFrequency = checkFrequency;
|
||||
this.checkTimer = 0;
|
||||
this.refreshTimer = 0;
|
||||
this.requirements = requirements;
|
||||
this.texts = texts;
|
||||
this.checkTimer = checkFrequency - 1;
|
||||
}
|
||||
|
||||
public NextStage stateCheck(Condition condition) {
|
||||
@@ -78,21 +80,33 @@ public class DisplayController {
|
||||
}
|
||||
|
||||
public boolean updateText(Condition condition) {
|
||||
if (timeLeft > 0)
|
||||
timeLeft--;
|
||||
|
||||
// Definitely goto "if" on init
|
||||
if (timeLeft == 0) {
|
||||
int triedTimes = 0;
|
||||
do {
|
||||
index++;
|
||||
if (index >= texts.length) {
|
||||
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()));
|
||||
|
||||
metAnyCondition = true;
|
||||
timeLeft = texts[index].getDuration();
|
||||
refreshTimer = 0;
|
||||
return updateText(texts[index].getText());
|
||||
}
|
||||
|
||||
if (texts[index].getRefreshFrequency() <= 0) {
|
||||
if (!metAnyCondition || texts[index].getRefreshFrequency() <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -114,12 +128,13 @@ public class DisplayController {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
index = 0;
|
||||
public void initialize(Condition condition) {
|
||||
index = texts.length - 1;
|
||||
checkTimer = 0;
|
||||
refreshTimer = 0;
|
||||
timeLeft = texts[0].getDuration();
|
||||
latestValue = PlaceholderAPI.setPlaceholders(owner, texts[0].getText());
|
||||
timeLeft = 1;
|
||||
// The text would definitely be refreshed
|
||||
updateText(condition);
|
||||
}
|
||||
|
||||
public String getLatestContent() {
|
||||
|
||||
@@ -55,7 +55,6 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
package net.momirealms.customnameplates.paper.mechanic.placeholder;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.api.manager.PlaceholderManager;
|
||||
import net.momirealms.customnameplates.api.mechanic.character.ConfiguredChar;
|
||||
|
||||
@@ -38,7 +38,7 @@ import java.util.Objects;
|
||||
|
||||
public class CNConfig {
|
||||
|
||||
public static String configVersion = "25";
|
||||
public static String configVersion = "26";
|
||||
public static int cacheSize;
|
||||
public static int corePoolSize;
|
||||
public static long keepAliveTime;
|
||||
@@ -83,6 +83,8 @@ public class CNConfig {
|
||||
public static boolean unknownTeam;
|
||||
public static boolean createRealTeam;
|
||||
public static boolean enableShader;
|
||||
public static boolean huskChatChannel;
|
||||
public static boolean carbonChatChannel;
|
||||
|
||||
public static void load() {
|
||||
try {
|
||||
@@ -130,6 +132,8 @@ public class CNConfig {
|
||||
copyPackOraxen = integrationSection.getBoolean("resource-pack.Oraxen", false);
|
||||
trChatChannel = integrationSection.getBoolean("chat.TrChat", 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);
|
||||
cmiTeam = integrationSection.getBoolean("team.CMI", false);
|
||||
velocitab = integrationSection.getBoolean("team.Velocitab", false);
|
||||
|
||||
@@ -38,10 +38,37 @@ public class Migration {
|
||||
updateBubble();
|
||||
updateNameplate();
|
||||
updateCustomPlaceholders();
|
||||
updateLanguages();
|
||||
deleteFiles();
|
||||
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() {
|
||||
try {
|
||||
FileUtils.delete(new File(CustomNameplatesPlugin.get().getDataFolder(), "database.yml"));
|
||||
|
||||
@@ -34,6 +34,9 @@ public class ReflectionUtils {
|
||||
private static Constructor<?> updateConstructor;
|
||||
private static Method iChatComponentMethod;
|
||||
private static Object emptyComponent;
|
||||
private static Method serializeComponentMethod;
|
||||
private static Method keyAsStringMethod;
|
||||
private static Object miniMessageInstance;
|
||||
|
||||
public static void load() {
|
||||
try {
|
||||
@@ -54,6 +57,17 @@ public class ReflectionUtils {
|
||||
LogUtils.severe("Error occurred when loading reflections", exception);
|
||||
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() {
|
||||
@@ -75,4 +89,22 @@ public class ReflectionUtils {
|
||||
public static Object getEmptyComponent() {
|
||||
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 "";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
# Do not change
|
||||
config-version: '25'
|
||||
config-version: '26'
|
||||
|
||||
# Debug mode
|
||||
debug: false
|
||||
@@ -38,6 +38,8 @@ integrations:
|
||||
chat:
|
||||
TrChat: false
|
||||
VentureChat: false
|
||||
HuskChat: false
|
||||
CarbonChat: false
|
||||
|
||||
resource-pack:
|
||||
# disable resource pack generation on server start
|
||||
|
||||
@@ -15,7 +15,7 @@ messages:
|
||||
force-unequip-nameplates: '<white>你已强制卸下玩家 {Player} 的铭牌!</white>'
|
||||
not-exist-nameplates: '<white>那个铭牌不存在!</white>'
|
||||
not-available-nameplates: '<white>你还未拥有这个铭牌!</white>'
|
||||
available-nameplates: '<white>可用铭牌: {Nameplates}</white>'
|
||||
available-nameplates: '<white>可用铭牌: {Nameplate}</white>'
|
||||
have-no-nameplates: '<white>你还没有拥有任何铭牌.</white>'
|
||||
force-preview: '<white>正在强制玩家 {Player} 预览铭牌</white>'
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ messages:
|
||||
force-unequip-nameplates: '<white>Successfully removed {Player}''s nameplate!</white>'
|
||||
not-exist-nameplates: '<white>This nameplate does not exist!</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'
|
||||
force-preview: '<white>Forced {Player} to preview the nameplate</white>'
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ messages:
|
||||
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-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>'
|
||||
force-preview: '<white>Forced {Player} to preview the nameplate</white>'
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ messages:
|
||||
force-unequip-nameplates: '<white>Успешно снят Нэймплейт у {Player}!</white>'
|
||||
not-exist-nameplates: '<white>Такой Нэйплейт не существует!</white>'
|
||||
not-available-nameplates: '<white>Этот Нэймплейт сейчас недоступен!</white>'
|
||||
available-nameplates: '<white>Доступные Нэймплейты: {Nameplates}.</white>'
|
||||
available-nameplates: '<white>Доступные Нэймплейты: {Nameplate}.</white>'
|
||||
have-no-nameplates: '<white>У вас еще нет никаких Нэймплейтов.'
|
||||
force-preview: '<white>Forced {Player} to preview the nameplate</white>'
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ messages:
|
||||
force-unequip-nameplates: '<white>Eliminado con éxito {Player}''s nameplate!</white>'
|
||||
not-exist-nameplates: '<white>Este nameplate no existe!</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'
|
||||
force-preview: '<white>Forced {Player} to preview the nameplate</white>'
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ messages:
|
||||
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-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>'
|
||||
force-preview: '<white>Forced {Player} to preview the nameplate</white>'
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ api-version: 1.17
|
||||
authors: [ XiaoMoMi ]
|
||||
folia-supported: true
|
||||
depend: [ ProtocolLib ,PlaceholderAPI ]
|
||||
softdepend: [ MagicCosmetics, TAB, CMI, TrChat, ItemsAdder, Oraxen ]
|
||||
softdepend: [ MagicCosmetics, TAB, CMI, TrChat, ItemsAdder, Oraxen, CarbonChat, HuskChat ]
|
||||
permissions:
|
||||
nameplates.command.*:
|
||||
description: Gives access to all nameplate user commands
|
||||
|
||||
Reference in New Issue
Block a user