mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-19 15:09:23 +00:00
3.0.26
This commit is contained in:
@@ -26,6 +26,8 @@ import net.momirealms.customnameplates.common.plugin.feature.Reloadable;
|
||||
*/
|
||||
public interface ChatManager extends Reloadable {
|
||||
|
||||
String replaceEmojis(CNPlayer player, String text);
|
||||
|
||||
/**
|
||||
* Sets a custom chat message provider.
|
||||
*
|
||||
|
||||
@@ -32,7 +32,9 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.momirealms.customnameplates.api.CNPlayer;
|
||||
import net.momirealms.customnameplates.api.ConfigManager;
|
||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||
import net.momirealms.customnameplates.api.feature.*;
|
||||
import net.momirealms.customnameplates.api.feature.ChatListener;
|
||||
import net.momirealms.customnameplates.api.feature.ConfiguredCharacter;
|
||||
import net.momirealms.customnameplates.api.feature.OffsetFont;
|
||||
import net.momirealms.customnameplates.api.feature.bubble.Bubble;
|
||||
import net.momirealms.customnameplates.api.feature.bubble.BubbleConfig;
|
||||
import net.momirealms.customnameplates.api.feature.bubble.BubbleManager;
|
||||
@@ -302,7 +304,7 @@ public class BubbleManagerImpl implements BubbleManager, ChatListener {
|
||||
return;
|
||||
}
|
||||
|
||||
String fullText = config.textPrefix().fastCreate(player).render(player) + AdventureHelper.stripTags(message.replace("\\", "\\\\")) + config.textSuffix().fastCreate(player).render(player);
|
||||
String fullText = config.textPrefix().fastCreate(player).render(player) + message.replace("\\", "\\\\") + config.textSuffix().fastCreate(player).render(player);
|
||||
int lines = plugin.getAdvanceManager().getLines(fullText, config.lineWidth());
|
||||
if (lines > config.maxLines()) return;
|
||||
if (lines <= 0) return;
|
||||
|
||||
@@ -67,6 +67,14 @@ public abstract class AbstractChatManager implements ChatManager {
|
||||
|
||||
protected abstract void setUpPlatformEmojiProviders();
|
||||
|
||||
@Override
|
||||
public String replaceEmojis(CNPlayer player, String text) {
|
||||
for (EmojiProvider emojiProvider : emojiProviders) {
|
||||
text = emojiProvider.replace(player, text);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setCustomChatProvider(ChatMessageProvider provider) {
|
||||
if (this.customProvider != null)
|
||||
|
||||
@@ -33,7 +33,6 @@ import net.momirealms.customnameplates.api.feature.image.Animation;
|
||||
import net.momirealms.customnameplates.api.feature.image.Image;
|
||||
import net.momirealms.customnameplates.api.feature.nameplate.Nameplate;
|
||||
import net.momirealms.customnameplates.api.feature.pack.ResourcePackManager;
|
||||
import net.momirealms.customnameplates.api.helper.VersionHelper;
|
||||
import net.momirealms.customnameplates.api.util.CharacterUtils;
|
||||
import net.momirealms.customnameplates.api.util.ZipUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=3.0.25
|
||||
project_version=3.0.26
|
||||
config_version=37
|
||||
project_group=net.momirealms
|
||||
|
||||
@@ -13,12 +13,12 @@ jetbrains_annotations_version=24.0.0
|
||||
slf4j_version=2.0.16
|
||||
log4j_version=2.24.1
|
||||
gson_version=2.11.0
|
||||
asm_version=9.7.1
|
||||
asm_commons_version=9.7.1
|
||||
asm_version=9.8
|
||||
asm_commons_version=9.8
|
||||
jar_relocator_version=1.7
|
||||
h2_driver_version=2.3.232
|
||||
sqlite_driver_version=3.48.0.0
|
||||
adventure_bundle_version=4.19.0
|
||||
adventure_bundle_version=4.20.0
|
||||
adventure_platform_version=4.3.5-SNAPSHOT
|
||||
cloud_core_version=2.0.0
|
||||
cloud_services_version=2.0.0
|
||||
@@ -27,7 +27,7 @@ cloud_bukkit_version=2.0.0-beta.10
|
||||
cloud_paper_version=2.0.0-beta.10
|
||||
cloud_minecraft_extras_version=2.0.0-beta.10
|
||||
boosted_yaml_version=1.3.7
|
||||
byte_buddy_version=1.15.10
|
||||
byte_buddy_version=1.17.5
|
||||
mojang_brigadier_version=1.0.18
|
||||
mongodb_driver_version=5.3.1
|
||||
mariadb_driver_version=3.5.1
|
||||
|
||||
@@ -66,15 +66,15 @@ artifacts {
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(17)
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
options.encoding = "UTF-8"
|
||||
options.release.set(17)
|
||||
options.release.set(21)
|
||||
dependsOn(tasks.clean)
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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.bukkit.compatibility.chat;
|
||||
|
||||
import io.papermc.paper.event.player.AbstractChatEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import net.momirealms.customnameplates.api.CNPlayer;
|
||||
import net.momirealms.customnameplates.api.ConfigManager;
|
||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||
import net.momirealms.customnameplates.api.feature.chat.AbstractChatMessageProvider;
|
||||
import net.momirealms.customnameplates.api.feature.chat.ChatManager;
|
||||
import net.momirealms.customnameplates.common.util.ReflectionUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Objects;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public class PaperAsyncChatProvider extends AbstractChatMessageProvider implements Listener {
|
||||
private Field field$AbstractChatEvent$message;
|
||||
private Method method$ComponentSerializer$serialize;
|
||||
private Object miniMessage;
|
||||
|
||||
public PaperAsyncChatProvider(CustomNameplates plugin, ChatManager manager) {
|
||||
super(plugin, manager);
|
||||
try {
|
||||
this.field$AbstractChatEvent$message = AbstractChatEvent.class.getDeclaredField("message");
|
||||
this.field$AbstractChatEvent$message.setAccessible(true);
|
||||
Class<?> clazz$ComponentSerializer = requireNonNull(ReflectionUtils.getClazz("net{}kyori{}adventure{}text{}serializer{}ComponentSerializer".replace("{}", ".")));
|
||||
Class<?> clazz$AdventureComponent = requireNonNull(ReflectionUtils.getClazz("net{}kyori{}adventure{}text{}Component".replace("{}", ".")));
|
||||
this.method$ComponentSerializer$serialize = requireNonNull(ReflectionUtils.getMethod(clazz$ComponentSerializer, Object.class, new String[] {"serialize"}, clazz$AdventureComponent));
|
||||
Class<?> clazz$MiniMessage = requireNonNull(ReflectionUtils.getClazz("net{}kyori{}adventure{}text{}minimessage{}MiniMessage".replace("{}", ".")));
|
||||
Method method$MiniMessage$builder = clazz$MiniMessage.getMethod("builder");
|
||||
Class<?> clazz$MiniMessage$Builder = requireNonNull(ReflectionUtils.getClazz("net{}kyori{}adventure{}text{}minimessage{}MiniMessage$Builder".replace("{}", ".")));
|
||||
Method method$MiniMessage$Builder$strict = clazz$MiniMessage$Builder.getMethod("strict", boolean.class);
|
||||
Method method$MiniMessage$Builder$build = clazz$MiniMessage$Builder.getMethod("build");
|
||||
Object builder = method$MiniMessage$builder.invoke(null);
|
||||
builder = method$MiniMessage$Builder$strict.invoke(builder, true);
|
||||
this.miniMessage = method$MiniMessage$Builder$build.invoke(builder);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
plugin.getPluginLogger().warn("Failed to init PaperAsyncChatProvider", e);
|
||||
}
|
||||
}
|
||||
|
||||
// This event is not async sometimes
|
||||
@EventHandler
|
||||
public void onChat(AsyncChatEvent event) {
|
||||
if (!ConfigManager.chatUnsafe() && event.isCancelled()) return;
|
||||
CNPlayer player = plugin.getPlayer(event.getPlayer().getUniqueId());
|
||||
if (player == null) return;
|
||||
try {
|
||||
Object component = field$AbstractChatEvent$message.get(event);
|
||||
String miniMessage = (String) method$ComponentSerializer$serialize.invoke(this.miniMessage, component);
|
||||
plugin.getScheduler().async().execute(() -> {
|
||||
manager.onChat(player, miniMessage, "global");
|
||||
});
|
||||
} catch (Exception e) {
|
||||
plugin.getPluginLogger().warn("Failed to handle AsyncChatEvent", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasJoinedChannel(CNPlayer player, String channelID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canJoinChannel(CNPlayer player, String channelID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIgnoring(CNPlayer sender, CNPlayer receiver) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
Bukkit.getPluginManager().registerEvents(this, Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("CustomNameplates")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister() {
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,6 @@ import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class OraxenEmojiProvider implements EmojiProvider {
|
||||
|
||||
private final FontManager fontManager;
|
||||
private final Function<Glyph, String> characterFunction;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package net.momirealms.customnameplates.bukkit;
|
||||
|
||||
import net.momirealms.customnameplates.api.ConfigManager;
|
||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||
import net.momirealms.customnameplates.api.helper.VersionHelper;
|
||||
import net.momirealms.customnameplates.backend.feature.chat.AbstractChatManager;
|
||||
import net.momirealms.customnameplates.bukkit.compatibility.chat.*;
|
||||
import net.momirealms.customnameplates.bukkit.compatibility.emoji.ItemsAdderEmojiProvider;
|
||||
@@ -57,6 +58,8 @@ public class BukkitChatManager extends AbstractChatManager {
|
||||
} else if (ConfigManager.chatChatty() && Bukkit.getPluginManager().isPluginEnabled("Chatty")) {
|
||||
this.chatProvider = new ChattyProvider(plugin, this);
|
||||
plugin.getPluginLogger().info("Chatty hooked!");
|
||||
} else if (VersionHelper.isPaperOrItsForks()) {
|
||||
this.chatProvider = new PaperAsyncChatProvider(plugin, this);
|
||||
} else {
|
||||
this.chatProvider = new AsyncChatProvider(plugin, this);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package net.momirealms.customnameplates.bukkit;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customnameplates.api.CNPlayer;
|
||||
import net.momirealms.customnameplates.api.ConfigManager;
|
||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||
|
||||
Reference in New Issue
Block a user