9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-31 04:36:29 +00:00
This commit is contained in:
XiaoMoMi
2024-03-17 16:26:26 +08:00
parent abcece373f
commit c2c1b703b7
8 changed files with 33 additions and 12 deletions

View File

@@ -38,7 +38,7 @@ dependencies {
compileOnly("commons-io:commons-io:2.15.1")
compileOnly("org.geysermc.geyser:api:2.2.0-SNAPSHOT")
compileOnly("LibsDisguises:LibsDisguises:10.0.42")
compileOnly("com.github.Xiao-MoMi:BiomeAPI:0.3")
implementation("com.github.Xiao-MoMi:BiomeAPI:0.3")
// chat channels
compileOnly(files("libs/VentureChat-3.7.1.jar"))

View File

@@ -85,8 +85,7 @@ public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin implement
Dependency.SQLITE_DRIVER,
Dependency.BSTATS_BASE,
Dependency.HIKARI,
Dependency.BSTATS_BUKKIT,
Dependency.BIOME_API
Dependency.BSTATS_BUKKIT
)
));
ReflectionUtils.load();

View File

@@ -294,7 +294,7 @@ public enum Dependency {
BIOME_API(
"com{}github{}Xiao-MoMi",
"BiomeAPI",
"0.2",
"0.3",
"jitpack",
"biome-api",
Relocation.of("biomeapi", "net{}momirealms{}biomeapi")

View File

@@ -35,6 +35,7 @@ import net.momirealms.customnameplates.paper.mechanic.actionbar.listener.SystemC
import net.momirealms.customnameplates.paper.mechanic.misc.DisplayController;
import net.momirealms.customnameplates.paper.setting.CNConfig;
import net.momirealms.customnameplates.paper.util.ConfigUtils;
import net.momirealms.customnameplates.paper.util.ReflectionUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -176,13 +177,24 @@ public class ActionBarManagerImpl implements ActionBarManager, Listener {
if (receiver != null) {
event.setCancelled(true);
String json = packet.getStrings().readSafely(0);
if (json != null && !json.equals("")) {
if (json != null && !json.isEmpty()) {
System.out.println(json);
Component component = GsonComponentSerializer.gson().deserialize(json);
if (component instanceof TranslatableComponent) {
// We can't get TranslatableComponent's width :(
return;
}
receiver.setOtherPluginText(AdventureManagerImpl.getInstance().getMiniMessageFormat(component), System.currentTimeMillis());
} else {
WrappedChatComponent wrappedChatComponent = packet.getChatComponents().readSafely(0);
if (wrappedChatComponent != null) {
json = wrappedChatComponent.getJson();
Component component = GsonComponentSerializer.gson().deserialize(json);
if (component instanceof TranslatableComponent) {
return;
}
receiver.setOtherPluginText(AdventureManagerImpl.getInstance().getMiniMessageFormat(component), System.currentTimeMillis());
}
}
}
}
@@ -212,10 +224,10 @@ public class ActionBarManagerImpl implements ActionBarManager, Listener {
public void onReceiveActionBarPacket(PacketEvent event) {
PacketContainer packet = event.getPacket();
WrappedChatComponent wrappedChatComponent = packet.getChatComponents().read(0);
if (wrappedChatComponent != null) {
ActionBarReceiver receiver = getReceiver(event.getPlayer().getUniqueId());
if (receiver != null) {
ActionBarReceiver receiver = getReceiver(event.getPlayer().getUniqueId());
if (receiver != null) {
WrappedChatComponent wrappedChatComponent = packet.getChatComponents().read(0);
if (wrappedChatComponent != null) {
String strJson = wrappedChatComponent.getJson();
// for better performance
if (strJson.contains("\"name\":\"np\",\"objective\":\"ab\"")) {
@@ -227,6 +239,12 @@ public class ActionBarManagerImpl implements ActionBarManager, Listener {
GsonComponentSerializer.gson().deserialize(strJson)
), System.currentTimeMillis()
);
} else if (ReflectionUtils.isPaper()) {
Object adventureComponent = packet.getModifier().readSafely(1);
if (adventureComponent != null) {
String other = ReflectionUtils.getMiniMessageTextFromNonShadedComponent(adventureComponent);
receiver.setOtherPluginText(other, System.currentTimeMillis());
}
}
}
}

View File

@@ -29,7 +29,6 @@ import net.kyori.adventure.text.minimessage.internal.parser.node.ElementNode;
import net.kyori.adventure.text.minimessage.internal.parser.node.TagNode;
import net.kyori.adventure.text.minimessage.internal.parser.node.ValueNode;
import net.kyori.adventure.text.minimessage.tag.Inserting;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.api.manager.WidthManager;
import net.momirealms.customnameplates.api.mechanic.background.BackGround;

View File

@@ -32,7 +32,6 @@ import net.momirealms.customnameplates.paper.util.ClassUtils;
import net.momirealms.customnameplates.paper.util.ConfigUtils;
import net.momirealms.customnameplates.paper.util.DisguiseUtils;
import net.momirealms.customnameplates.paper.util.GeyserUtils;
import org.bson.types.Binary;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;

View File

@@ -39,6 +39,7 @@ public class ReflectionUtils {
private static Method keyFromStringMethod;
private static Object miniMessageInstance;
private static Class<?> keyClass;
private static boolean isPaper;
public static void load() {
try {
@@ -68,6 +69,7 @@ public class ReflectionUtils {
keyClass = Class.forName("net;kyori;adventure;key;Key".replace(";", "."));
keyAsStringMethod = keyClass.getMethod("asString");
keyFromStringMethod = keyClass.getMethod("key", String.class);
isPaper = true;
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
IllegalAccessException ignored) {
}
@@ -97,6 +99,10 @@ public class ReflectionUtils {
return keyClass;
}
public static boolean isPaper() {
return isPaper;
}
public static String getKeyAsString(Object key) {
try {
return (String) keyAsStringMethod.invoke(key);