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:
@@ -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