9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-29 19:59:09 +00:00
This commit is contained in:
XiaoMoMi
2024-11-09 22:56:29 +08:00
parent 366cda6bef
commit 018dc18eee
13 changed files with 241 additions and 24 deletions

View File

@@ -63,7 +63,7 @@ public class BukkitChatManager extends AbstractChatManager {
}
if (Bukkit.getPluginManager().isPluginEnabled("Oraxen")) {
try {
this.emojiProviders.add(new OraxenEmojiProvider());
this.emojiProviders.add(new OraxenEmojiProvider(Bukkit.getPluginManager().getPlugin("Oraxen").getDescription().getVersion().startsWith("1") ? 1 : 2));
} catch (Exception ignore) {
}
}

View File

@@ -40,6 +40,7 @@ import net.momirealms.customnameplates.bukkit.command.BukkitCommandManager;
import net.momirealms.customnameplates.bukkit.compatibility.NameplatesExpansion;
import net.momirealms.customnameplates.bukkit.compatibility.NameplatesExtraExpansion;
import net.momirealms.customnameplates.bukkit.compatibility.cosmetic.MagicCosmeticsHook;
import net.momirealms.customnameplates.bukkit.compatibility.region.WorldGuardRegion;
import net.momirealms.customnameplates.bukkit.requirement.BukkitRequirementManager;
import net.momirealms.customnameplates.bukkit.scheduler.BukkitSchedulerAdapter;
import net.momirealms.customnameplates.bukkit.util.SimpleLocation;
@@ -204,6 +205,12 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
} catch (Exception ignore) {
}
}
if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
try {
WorldGuardRegion.register();
} catch (Exception ignore) {
}
}
boolean downloadFromPolymart = polymart.equals("1");
boolean downloadFromBBB = buildByBit.equals("true");

View File

@@ -204,22 +204,61 @@ public class BukkitPlatform implements Platform {
}
}, "PacketPlayOutEntityDestroy", "ClientboundRemoveEntitiesPacket");
// for skin plugin compatibility
registerPacketConsumer((player, event, packet) -> {
try {
UUID pUUID = player.uuid();
@SuppressWarnings("unchecked")
List<UUID> uuids = (List<UUID>) Reflections.field$ClientboundPlayerInfoRemovePacket$profileIds.get(packet);
for (UUID uuid : uuids) {
if (uuid.equals(pUUID)) {
CNPlayer removed = CustomNameplates.getInstance().getPlayer(uuid);
if (removed != null) {
removed.removePlayerFromTracker(player);
CustomNameplates.getInstance().getUnlimitedTagManager().onRemovePlayer(removed, player);
}
}
}
} catch (ReflectiveOperationException e) {
CustomNameplates.getInstance().getPluginLogger().severe("Failed to handle ClientboundPlayerInfoRemovePacket", e);
}
}, "ClientboundPlayerInfoRemovePacket");
registerPacketConsumer((player, event, packet) -> {
try {
EnumSet<?> enums = (EnumSet<?>) Reflections.field$ClientboundPlayerInfoUpdatePacket$actions.get(packet);
if (enums == null) return;
if (!enums.contains(Reflections.enum$ClientboundPlayerInfoUpdatePacket$Action$UPDATE_GAME_MODE)) return;
List<Object> entries = (List<Object>) Reflections.field$ClientboundPlayerInfoUpdatePacket$entries.get(packet);
for (Object entry : entries) {
UUID uuid = (UUID) Reflections.field$ClientboundPlayerInfoUpdatePacket$Entry$profileId.get(entry);
if (uuid == null) continue;
Object gameType = Reflections.field$ClientboundPlayerInfoUpdatePacket$Entry$gameMode.get(entry);
if (gameType == null) continue;
int mode = (int) Reflections.method$GameType$getId.invoke(gameType);
boolean isSpectator = mode == 3;
CNPlayer another = CustomNameplates.getInstance().getPlayer(uuid);
if (another != null) {
CustomNameplates.getInstance().getUnlimitedTagManager().onPlayerGameModeChange(another, player, isSpectator);
UUID pUUID = player.uuid();
boolean add_player = enums.contains(Reflections.enum$ClientboundPlayerInfoUpdatePacket$Action$ADD_PLAYER);
boolean update_gamemode = enums.contains(Reflections.enum$ClientboundPlayerInfoUpdatePacket$Action$UPDATE_GAME_MODE);
if (add_player || update_gamemode) {
@SuppressWarnings("unchecked")
List<Object> entries = (List<Object>) Reflections.field$ClientboundPlayerInfoUpdatePacket$entries.get(packet);
for (Object entry : entries) {
UUID uuid = (UUID) Reflections.field$ClientboundPlayerInfoUpdatePacket$Entry$profileId.get(entry);
if (uuid == null) continue;
// for skin plugin compatibility
if (add_player && uuid.equals(pUUID)) {
if (player.isTempPreviewing() || player.isToggleablePreviewing() || CustomNameplates.getInstance().getUnlimitedTagManager().isAlwaysShow()) {
Tracker tracker = player.addPlayerToTracker(player);
tracker.setScale(player.scale());
tracker.setCrouching(player.isCrouching());
tracker.setSpectator(player.isSpectator());
CustomNameplates.getInstance().getUnlimitedTagManager().onAddPlayer(player, player);
}
}
CNPlayer another = CustomNameplates.getInstance().getPlayer(uuid);
if (update_gamemode) {
Object gameType = Reflections.field$ClientboundPlayerInfoUpdatePacket$Entry$gameMode.get(entry);
if (gameType == null) continue;
int mode = (int) Reflections.method$GameType$getId.invoke(gameType);
boolean isSpectator = mode == 3;
if (another != null) {
CustomNameplates.getInstance().getUnlimitedTagManager().onPlayerGameModeChange(another, player, isSpectator);
}
}
}
}
} catch (ReflectiveOperationException e) {

View File

@@ -19,6 +19,7 @@ package net.momirealms.customnameplates.bukkit.command.feature;
import net.momirealms.customnameplates.api.CNPlayer;
import net.momirealms.customnameplates.api.ConfigManager;
import net.momirealms.customnameplates.api.CustomNameplates;
import net.momirealms.customnameplates.api.feature.JoinQuitListener;
import net.momirealms.customnameplates.bukkit.BukkitCustomNameplates;
import net.momirealms.customnameplates.bukkit.command.BukkitCommandFeature;
@@ -45,6 +46,7 @@ public class NameplatesPreviewCommand extends BukkitCommandFeature<CommandSender
.senderType(Player.class)
.handler(context -> {
if (!ConfigManager.nametagModule()) return;
if (CustomNameplates.getInstance().getUnlimitedTagManager().isAlwaysShow()) return;
CNPlayer player = plugin.getPlayer(context.sender().getUniqueId());
if (player == null) {
throw new RuntimeException("Player should not be null");

View File

@@ -429,6 +429,18 @@ public class Reflections {
)
);
public static final Class<?> clazz$ClientboundPlayerInfoRemovePacket = requireNonNull(
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleMCClass("network.protocol.game.ClientboundPlayerInfoRemovePacket")
)
);
public static final Field field$ClientboundPlayerInfoRemovePacket$profileIds = requireNonNull(
ReflectionUtils.getInstanceDeclaredField(
clazz$ClientboundPlayerInfoRemovePacket, 0
)
);
public static final Field field$ClientboundRemoveEntitiesPacket$entityIds = requireNonNull(
ReflectionUtils.getInstanceDeclaredField(
clazz$ClientboundRemoveEntitiesPacket, 0
@@ -819,7 +831,7 @@ public class Reflections {
);
public static final Enum<?> enum$ClientboundPlayerInfoUpdatePacket$Action$UPDATE_GAME_MODE;
public static final Enum<?> enum$ClientboundPlayerInfoUpdatePacket$Action$ADD_PLAYER;
static {
Enum<?> updateGameMode;
@@ -829,6 +841,14 @@ public class Reflections {
updateGameMode = Enum.valueOf((Class<Enum>) clazz$ClientboundPlayerInfoUpdatePacket$Action, "c");
}
enum$ClientboundPlayerInfoUpdatePacket$Action$UPDATE_GAME_MODE = updateGameMode;
Enum<?> addPlayer;
try {
addPlayer = Enum.valueOf((Class<Enum>) clazz$ClientboundPlayerInfoUpdatePacket$Action, "ADD_PLAYER");
} catch (Exception e) {
addPlayer = Enum.valueOf((Class<Enum>) clazz$ClientboundPlayerInfoUpdatePacket$Action, "a");
}
enum$ClientboundPlayerInfoUpdatePacket$Action$ADD_PLAYER = addPlayer;
}
public static final Class<?> clazz$ClientboundPlayerInfoUpdatePacket$Entry = requireNonNull(

View File

@@ -15,6 +15,7 @@ softdepend:
- AdvancedChat
- VentureChat
- EssentialsChat
- WorldGuard
permissions:
nameplates.command.equip:
default: true