mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-23 08:59:30 +00:00
fix name() NPE
This commit is contained in:
@@ -671,7 +671,7 @@ public abstract class AbstractCNPlayer<P> implements CNPlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String name() {
|
public String name() {
|
||||||
return this.name;
|
return Optional.ofNullable(this.name).orElse("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public class ConfiguredCharacter {
|
|||||||
}
|
}
|
||||||
advance = (float) Math.round((i + 1) * scale) + 1f;
|
advance = (float) Math.round((i + 1) * scale) + 1f;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException("Failed to load " + imageFile.toPath(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
|||||||
import net.kyori.adventure.util.TriState;
|
import net.kyori.adventure.util.TriState;
|
||||||
import net.kyori.examination.Examinable;
|
import net.kyori.examination.Examinable;
|
||||||
import net.kyori.examination.ExaminableProperty;
|
import net.kyori.examination.ExaminableProperty;
|
||||||
|
import net.momirealms.customnameplates.api.helper.AdventureHelper;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -94,6 +95,9 @@ public class MiniMessageTranslationRegistryImpl implements Examinable, MiniMessa
|
|||||||
if (miniMessageString.isEmpty()) {
|
if (miniMessageString.isEmpty()) {
|
||||||
return Component.empty();
|
return Component.empty();
|
||||||
}
|
}
|
||||||
|
if (AdventureHelper.legacySupport) {
|
||||||
|
miniMessageString = AdventureHelper.legacyToMiniMessage(miniMessageString);
|
||||||
|
}
|
||||||
final Component resultingComponent;
|
final Component resultingComponent;
|
||||||
if (component.arguments().isEmpty()) {
|
if (component.arguments().isEmpty()) {
|
||||||
resultingComponent = this.miniMessage.deserialize(miniMessageString);
|
resultingComponent = this.miniMessage.deserialize(miniMessageString);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import net.kyori.adventure.text.renderer.TranslatableComponentRenderer;
|
|||||||
import net.kyori.adventure.translation.Translator;
|
import net.kyori.adventure.translation.Translator;
|
||||||
import net.kyori.adventure.util.TriState;
|
import net.kyori.adventure.util.TriState;
|
||||||
import net.kyori.examination.ExaminableProperty;
|
import net.kyori.examination.ExaminableProperty;
|
||||||
|
import net.momirealms.customnameplates.api.ConfigManager;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -64,7 +65,9 @@ public class MiniMessageTranslatorImpl implements MiniMessageTranslator {
|
|||||||
public @Nullable Component translate(@NotNull TranslatableComponent component, @NotNull Locale locale) {
|
public @Nullable Component translate(@NotNull TranslatableComponent component, @NotNull Locale locale) {
|
||||||
for (final Translator source : this.sources) {
|
for (final Translator source : this.sources) {
|
||||||
final Component translation = source.translate(component, locale);
|
final Component translation = source.translate(component, locale);
|
||||||
if (translation != null) return translation;
|
if (translation != null) {
|
||||||
|
return translation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Project settings
|
# Project settings
|
||||||
# Rule: [major update].[feature update].[bug fix]
|
# Rule: [major update].[feature update].[bug fix]
|
||||||
project_version=3.0.31
|
project_version=3.0.32
|
||||||
config_version=38
|
config_version=38
|
||||||
project_group=net.momirealms
|
project_group=net.momirealms
|
||||||
|
|
||||||
|
|||||||
@@ -53,12 +53,7 @@ public class VentureChatProvider extends AbstractChatMessageProvider implements
|
|||||||
if (cnPlayer == null) {
|
if (cnPlayer == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String chatMessage;
|
String chatMessage = event.getChat();
|
||||||
if (ConfigManager.stripChatColorTags()) {
|
|
||||||
chatMessage = AdventureHelper.stripTags(AdventureHelper.legacyToMiniMessage(event.getChat()));
|
|
||||||
} else {
|
|
||||||
chatMessage = event.getChat();
|
|
||||||
}
|
|
||||||
plugin.getScheduler().async().execute(() -> {
|
plugin.getScheduler().async().execute(() -> {
|
||||||
manager.onChat(cnPlayer, chatMessage, channelName);
|
manager.onChat(cnPlayer, chatMessage, channelName);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ public class BukkitCNPlayer extends AbstractCNPlayer<Player> {
|
|||||||
super.name = player.getName();
|
super.name = player.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
return this.player != null;
|
return this.player != null;
|
||||||
|
|||||||
@@ -17,8 +17,10 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.bukkit;
|
package net.momirealms.customnameplates.bukkit;
|
||||||
|
|
||||||
|
import net.momirealms.customnameplates.api.CNPlayer;
|
||||||
import net.momirealms.customnameplates.api.ConfigManager;
|
import net.momirealms.customnameplates.api.ConfigManager;
|
||||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||||
|
import net.momirealms.customnameplates.api.helper.AdventureHelper;
|
||||||
import net.momirealms.customnameplates.api.helper.VersionHelper;
|
import net.momirealms.customnameplates.api.helper.VersionHelper;
|
||||||
import net.momirealms.customnameplates.backend.feature.chat.AbstractChatManager;
|
import net.momirealms.customnameplates.backend.feature.chat.AbstractChatManager;
|
||||||
import net.momirealms.customnameplates.bukkit.compatibility.chat.*;
|
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);
|
event.cancelled(true);
|
||||||
}, "ClientboundSetActionBarTextPacket");
|
}, "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) -> {
|
registerPacketConsumer((player, event, packet) -> {
|
||||||
if (!ConfigManager.actionbarModule()) return;
|
if (!ConfigManager.actionbarModule()) return;
|
||||||
if (!ConfigManager.catchOtherActionBar()) return;
|
if (!ConfigManager.catchOtherActionBar()) return;
|
||||||
|
|||||||
@@ -1231,4 +1231,24 @@ public class Reflections {
|
|||||||
clazz$ComponentSerializer, Object.class, new String[] {"deserialize"}, Object.class
|
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