mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-19 15:09:23 +00:00
fix name() NPE
This commit is contained in:
@@ -53,12 +53,7 @@ public class VentureChatProvider extends AbstractChatMessageProvider implements
|
||||
if (cnPlayer == null) {
|
||||
return;
|
||||
}
|
||||
String chatMessage;
|
||||
if (ConfigManager.stripChatColorTags()) {
|
||||
chatMessage = AdventureHelper.stripTags(AdventureHelper.legacyToMiniMessage(event.getChat()));
|
||||
} else {
|
||||
chatMessage = event.getChat();
|
||||
}
|
||||
String chatMessage = event.getChat();
|
||||
plugin.getScheduler().async().execute(() -> {
|
||||
manager.onChat(cnPlayer, chatMessage, channelName);
|
||||
});
|
||||
|
||||
@@ -48,6 +48,10 @@ public class BukkitCNPlayer extends AbstractCNPlayer<Player> {
|
||||
super.name = player.getName();
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return this.player != null;
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
|
||||
package net.momirealms.customnameplates.bukkit;
|
||||
|
||||
import net.momirealms.customnameplates.api.CNPlayer;
|
||||
import net.momirealms.customnameplates.api.ConfigManager;
|
||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||
import net.momirealms.customnameplates.api.helper.AdventureHelper;
|
||||
import net.momirealms.customnameplates.api.helper.VersionHelper;
|
||||
import net.momirealms.customnameplates.backend.feature.chat.AbstractChatManager;
|
||||
import net.momirealms.customnameplates.bukkit.compatibility.chat.*;
|
||||
@@ -78,4 +80,13 @@ public class BukkitChatManager extends AbstractChatManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CNPlayer player, String message, String channel) {
|
||||
if (ConfigManager.stripChatColorTags()) {
|
||||
super.onChat(player, AdventureHelper.stripTags(AdventureHelper.legacyToMiniMessage(message)), channel);
|
||||
} else {
|
||||
super.onChat(player, message, channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +142,19 @@ public class BukkitPlatform implements Platform {
|
||||
event.cancelled(true);
|
||||
}, "ClientboundSetActionBarTextPacket");
|
||||
|
||||
registerPacketConsumer((player, event, packet) -> {
|
||||
try {
|
||||
Object gameProfile = Reflections.field$ClientboundLoginFinishedPacket$gameProfile.get(packet);
|
||||
if (gameProfile != null) {
|
||||
String name = (String) Reflections.field$GameProfile$name.get(gameProfile);
|
||||
BukkitCNPlayer bukkitCNPlayer = (BukkitCNPlayer) player;
|
||||
bukkitCNPlayer.setName(name);
|
||||
}
|
||||
} catch (ReflectiveOperationException e) {
|
||||
CustomNameplates.getInstance().getPluginLogger().severe("Failed to handle ClientboundGameProfilePacket", e);
|
||||
}
|
||||
}, "PacketLoginOutSuccess", "ClientboundLoginFinishedPacket", "ClientboundGameProfilePacket");
|
||||
|
||||
registerPacketConsumer((player, event, packet) -> {
|
||||
if (!ConfigManager.actionbarModule()) return;
|
||||
if (!ConfigManager.catchOtherActionBar()) return;
|
||||
|
||||
@@ -1231,4 +1231,24 @@ public class Reflections {
|
||||
clazz$ComponentSerializer, Object.class, new String[] {"deserialize"}, Object.class
|
||||
)
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$ClientboundLoginFinishedPacket = requireNonNull(
|
||||
ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass("network.protocol.login.PacketLoginOutSuccess"),
|
||||
BukkitReflectionUtils.assembleMCClass("network.protocol.login.ClientboundLoginFinishedPacket"),
|
||||
BukkitReflectionUtils.assembleMCClass("network.protocol.login.ClientboundGameProfilePacket")
|
||||
)
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$GameProfile = requireNonNull(
|
||||
ReflectionUtils.getClazz("com.mojang.authlib.GameProfile")
|
||||
);
|
||||
|
||||
public static final Field field$ClientboundLoginFinishedPacket$gameProfile = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(clazz$ClientboundLoginFinishedPacket, clazz$GameProfile, 0)
|
||||
);
|
||||
|
||||
public static final Field field$GameProfile$name = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(clazz$GameProfile, String.class, 0)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user