From 018dc18eeea7c8fa52830d0305af01dea64d8889 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Sat, 9 Nov 2024 22:56:29 +0800 Subject: [PATCH] 3.0.9 --- .../feature/tag/UnlimitedTagManagerImpl.java | 2 + backend/src/main/resources/config.yml | 15 ++-- .../bukkit/BukkitChatManager.java | 2 +- .../bukkit/BukkitCustomNameplates.java | 7 ++ .../bukkit/BukkitPlatform.java | 63 ++++++++++++--- .../feature/NameplatesPreviewCommand.java | 2 + .../bukkit/util/Reflections.java | 22 +++++- bukkit/src/main/resources/plugin.yml | 1 + compatibility/build.gradle.kts | 5 ++ .../emoji/OraxenEmojiProvider.java | 14 +++- .../region/RegionRequirement.java | 79 +++++++++++++++++++ .../region/WorldGuardRegion.java | 51 ++++++++++++ gradle.properties | 2 +- 13 files changed, 241 insertions(+), 24 deletions(-) create mode 100644 compatibility/src/main/java/net/momirealms/customnameplates/bukkit/compatibility/region/RegionRequirement.java create mode 100644 compatibility/src/main/java/net/momirealms/customnameplates/bukkit/compatibility/region/WorldGuardRegion.java diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/UnlimitedTagManagerImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/UnlimitedTagManagerImpl.java index 59bd4fa..684f71f 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/UnlimitedTagManagerImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/UnlimitedTagManagerImpl.java @@ -148,6 +148,8 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager, JoinQuitLis } if (isAlwaysShow()) { setTempPreviewing(player, isAlwaysShow()); + } else if (player.isLoaded() && player.isTempPreviewing()) { + setTempPreviewing(player, false); } } diff --git a/backend/src/main/resources/config.yml b/backend/src/main/resources/config.yml index b45d392..3e88682 100644 --- a/backend/src/main/resources/config.yml +++ b/backend/src/main/resources/config.yml @@ -167,13 +167,14 @@ other-settings: unicode: file: unicode_page_%02x.png # Default Unicode characters sizes: glyph_sizes.bin # Glyph size configuration - ttf: - example: - generate: false # Should this TTF file be included in the generated pack - file: example.ttf # Define the TTF file to load the font from - size: 10.0 # Set font size - oversample: 8.0 # Oversample rate for TTF rendering - skip: [] # Skipped characters in list format + ttf: {} +# ttf: +# example: +# generate: false # Should this TTF file be included in the generated pack +# file: example.ttf # Define the TTF file to load the font from +# size: 10.0 # Set font size +# oversample: 8.0 # Oversample rate for TTF rendering +# skip: [] # Skipped characters in list format shift-fonts: shift_0: - space diff --git a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitChatManager.java b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitChatManager.java index 625ec70..790115f 100644 --- a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitChatManager.java +++ b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitChatManager.java @@ -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) { } } diff --git a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitCustomNameplates.java b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitCustomNameplates.java index c31a19f..d8c4476 100644 --- a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitCustomNameplates.java +++ b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitCustomNameplates.java @@ -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"); diff --git a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitPlatform.java b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitPlatform.java index 30dcb09..7d7ddc0 100644 --- a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitPlatform.java +++ b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitPlatform.java @@ -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 uuids = (List) 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 entries = (List) 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 entries = (List) 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) { diff --git a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesPreviewCommand.java b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesPreviewCommand.java index d169462..a85b1e5 100644 --- a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesPreviewCommand.java +++ b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesPreviewCommand.java @@ -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 { 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"); diff --git a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/util/Reflections.java b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/util/Reflections.java index 1f0e2c7..9712feb 100644 --- a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/util/Reflections.java +++ b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/util/Reflections.java @@ -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) clazz$ClientboundPlayerInfoUpdatePacket$Action, "c"); } enum$ClientboundPlayerInfoUpdatePacket$Action$UPDATE_GAME_MODE = updateGameMode; + + Enum addPlayer; + try { + addPlayer = Enum.valueOf((Class) clazz$ClientboundPlayerInfoUpdatePacket$Action, "ADD_PLAYER"); + } catch (Exception e) { + addPlayer = Enum.valueOf((Class) clazz$ClientboundPlayerInfoUpdatePacket$Action, "a"); + } + enum$ClientboundPlayerInfoUpdatePacket$Action$ADD_PLAYER = addPlayer; } public static final Class clazz$ClientboundPlayerInfoUpdatePacket$Entry = requireNonNull( diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index f87d7bd..204aad0 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -15,6 +15,7 @@ softdepend: - AdvancedChat - VentureChat - EssentialsChat + - WorldGuard permissions: nameplates.command.equip: default: true diff --git a/compatibility/build.gradle.kts b/compatibility/build.gradle.kts index bd3a16f..afc768b 100644 --- a/compatibility/build.gradle.kts +++ b/compatibility/build.gradle.kts @@ -11,11 +11,16 @@ repositories { maven("https://repo.essentialsx.net/releases/") // ess maven("https://repo.md-5.net/content/groups/public/") // disguise maven("https://repo.opencollab.dev/main/") // geyser + maven("https://maven.enginehub.org/repo/") // worldguard worldedit } dependencies { compileOnly(project(":api")) compileOnly(project(":common")) + compileOnly(project(":backend")) + compileOnly("dev.dejvokep:boosted-yaml:${rootProject.properties["boosted_yaml_version"]}") + // WorldGuard + compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.9") // Platform compileOnly("dev.folia:folia-api:${rootProject.properties["paper_version"]}-R0.1-SNAPSHOT") // Chat diff --git a/compatibility/src/main/java/net/momirealms/customnameplates/bukkit/compatibility/emoji/OraxenEmojiProvider.java b/compatibility/src/main/java/net/momirealms/customnameplates/bukkit/compatibility/emoji/OraxenEmojiProvider.java index dc17ca9..30c52d2 100644 --- a/compatibility/src/main/java/net/momirealms/customnameplates/bukkit/compatibility/emoji/OraxenEmojiProvider.java +++ b/compatibility/src/main/java/net/momirealms/customnameplates/bukkit/compatibility/emoji/OraxenEmojiProvider.java @@ -24,14 +24,24 @@ import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.feature.chat.emoji.EmojiProvider; import org.bukkit.entity.Player; +import java.lang.reflect.Method; import java.util.Map; public class OraxenEmojiProvider implements EmojiProvider { private final FontManager fontManager; - public OraxenEmojiProvider() { - this.fontManager = OraxenPlugin.get().getFontManager(); + public OraxenEmojiProvider(int version) { + if (version == 1) { + this.fontManager = OraxenPlugin.get().getFontManager(); + } else { + try { + Method fm = OraxenPlugin.class.getMethod("fontManager"); + this.fontManager = (FontManager) fm.invoke(OraxenPlugin.get()); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } } @Override diff --git a/compatibility/src/main/java/net/momirealms/customnameplates/bukkit/compatibility/region/RegionRequirement.java b/compatibility/src/main/java/net/momirealms/customnameplates/bukkit/compatibility/region/RegionRequirement.java new file mode 100644 index 0000000..f4acd49 --- /dev/null +++ b/compatibility/src/main/java/net/momirealms/customnameplates/bukkit/compatibility/region/RegionRequirement.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) <2024> + * + * 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 . + */ + +package net.momirealms.customnameplates.bukkit.compatibility.region; + +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import net.momirealms.customnameplates.api.CNPlayer; +import net.momirealms.customnameplates.backend.requirement.AbstractRequirement; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class RegionRequirement extends AbstractRequirement { + + private final List regions; + private final int mode; + + public RegionRequirement(int refreshInterval, int mode, Collection regions) { + super(refreshInterval); + this.regions = new ArrayList<>(regions); + this.mode = mode; + } + + @Override + public boolean isSatisfied(CNPlayer p1, CNPlayer p2) { + Location location = ((Player) p1.player()).getLocation(); + RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(location.getWorld())); + if (regionManager != null) { + ApplicableRegionSet set = regionManager.getApplicableRegions(BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ())); + if (mode == 1) { + for (ProtectedRegion region : set) { + if (regions.contains(region.getId())) { + return true; + } + } + } else if (mode == 2) { + outer: { + Set ids = set.getRegions().stream().map(ProtectedRegion::getId).collect(Collectors.toSet()); + for (String region : regions) { + if (!ids.contains(region)) { + break outer; + } + } + return true; + } + } + } + return false; + } + + @Override + public String type() { + return "region"; + } +} diff --git a/compatibility/src/main/java/net/momirealms/customnameplates/bukkit/compatibility/region/WorldGuardRegion.java b/compatibility/src/main/java/net/momirealms/customnameplates/bukkit/compatibility/region/WorldGuardRegion.java new file mode 100644 index 0000000..ea2db99 --- /dev/null +++ b/compatibility/src/main/java/net/momirealms/customnameplates/bukkit/compatibility/region/WorldGuardRegion.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) <2024> + * + * 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 . + */ + +package net.momirealms.customnameplates.bukkit.compatibility.region; + +import dev.dejvokep.boostedyaml.block.implementation.Section; +import net.momirealms.customnameplates.api.CustomNameplates; +import net.momirealms.customnameplates.api.requirement.EmptyRequirement; + +import java.util.HashSet; +import java.util.List; + +public class WorldGuardRegion { + + public static void register() { + CustomNameplates.getInstance().getRequirementManager().registerRequirement((args, interval) -> { + HashSet regions = new HashSet<>(); + int mode = 1; + if (args instanceof Section section) { + mode = section.getInt("mode", 1); + regions.addAll(section.getStringList("values")); + } else { + if (args instanceof List list) { + for (Object o : list) { + if (o instanceof String) { + regions.add((String) o); + } + } + } else { + CustomNameplates.getInstance().getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at region requirement which is expected be `Section` or `StringList`"); + return EmptyRequirement.instance(); + } + } + return new RegionRequirement(interval, mode, regions); + }, "region"); + } +} diff --git a/gradle.properties b/gradle.properties index a72087f..4bce444 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=3.0.8 +project_version=3.0.9 config_version=32 project_group=net.momirealms