From 315e16488b4949f28a4d31503b10ac0726c563ea Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Sat, 27 Apr 2024 22:24:03 -0500 Subject: [PATCH] adds support for vanish plugins --- build.gradle.kts | 1 + server/build.gradle.kts | 10 ++++++ .../java/dev/plex/command/impl/ListCMD.java | 2 ++ .../plex/listener/impl/PlayerListener.java | 4 +-- .../plex/listener/impl/VanishListener.java | 32 +++++++++++++++++++ .../main/java/dev/plex/meta/PlayerMeta.java | 19 +++++++++++ .../main/java/dev/plex/util/PlexUtils.java | 11 ++++++- 7 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 server/src/main/java/dev/plex/listener/impl/VanishListener.java diff --git a/build.gradle.kts b/build.gradle.kts index 79754b7..bd0c7b6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -34,6 +34,7 @@ subprojects { url = uri("https://jitpack.io") content { includeGroup("com.github.MilkBowl") + includeGroup("com.github.LeonMangler") } } diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 746cd1a..dea3c12 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -33,6 +33,8 @@ dependencies { implementation("org.bstats:bstats-base:3.0.2") implementation("org.bstats:bstats-bukkit:3.0.2") + implementation("com.github.LeonMangler:SuperVanish:6.2.18-3") + annotationProcessor("org.projectlombok:lombok:1.18.30") } @@ -73,10 +75,18 @@ paper { required = false load = PaperPluginDescription.RelativeLoadOrder.BEFORE } + register("PremiumVanish") { + required = false + load = PaperPluginDescription.RelativeLoadOrder.BEFORE + } register("SlimeWorldManager") { required = false load = PaperPluginDescription.RelativeLoadOrder.AFTER } + register("SuperVanish") { + required = false + load = PaperPluginDescription.RelativeLoadOrder.BEFORE + } register("Vault") { required = false load = PaperPluginDescription.RelativeLoadOrder.BEFORE diff --git a/server/src/main/java/dev/plex/command/impl/ListCMD.java b/server/src/main/java/dev/plex/command/impl/ListCMD.java index 3c9c46c..809d857 100644 --- a/server/src/main/java/dev/plex/command/impl/ListCMD.java +++ b/server/src/main/java/dev/plex/command/impl/ListCMD.java @@ -5,6 +5,7 @@ import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.hook.VaultHook; +import dev.plex.meta.PlayerMeta; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Bukkit; @@ -24,6 +25,7 @@ public class ListCMD extends PlexCommand protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) { List players = Lists.newArrayList(Bukkit.getOnlinePlayers()); + players.removeIf(PlayerMeta::isVanished); Component list = Component.empty(); Component header = Component.text("There " + (players.size() == 1 ? "is" : "are") + " currently").color(NamedTextColor.GRAY) .append(Component.space()) diff --git a/server/src/main/java/dev/plex/listener/impl/PlayerListener.java b/server/src/main/java/dev/plex/listener/impl/PlayerListener.java index 87019c0..ebe8a51 100644 --- a/server/src/main/java/dev/plex/listener/impl/PlayerListener.java +++ b/server/src/main/java/dev/plex/listener/impl/PlayerListener.java @@ -19,7 +19,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -public class PlayerListener extends PlexListener +public class PlayerListener extends PlexListener { // setting up a player's data @EventHandler(priority = EventPriority.HIGHEST) @@ -62,7 +62,7 @@ public class PlayerListener extends PlexListener } String loginMessage = PlayerMeta.getLoginMessage(plexPlayer); - if (!loginMessage.isEmpty()) + if (!loginMessage.isEmpty() && !PlayerMeta.isVanished(player)) { PlexUtils.broadcast(PlexUtils.stringToComponent(loginMessage)); } diff --git a/server/src/main/java/dev/plex/listener/impl/VanishListener.java b/server/src/main/java/dev/plex/listener/impl/VanishListener.java new file mode 100644 index 0000000..bbfd5a6 --- /dev/null +++ b/server/src/main/java/dev/plex/listener/impl/VanishListener.java @@ -0,0 +1,32 @@ +package dev.plex.listener.impl; + +import de.myzelyam.api.vanish.PlayerShowEvent; +import dev.plex.cache.DataUtils; +import dev.plex.listener.PlexListener; +import dev.plex.meta.PlayerMeta; +import dev.plex.player.PlexPlayer; +import dev.plex.util.PlexUtils; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +public class VanishListener extends PlexListener +{ + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerUnvanish(PlayerShowEvent event) + { + if (!PlexUtils.hasVanishPlugin()) + { + return; + } + if (event.isSilent()) + { + return; + } + PlexPlayer plexPlayer = DataUtils.getPlayer(event.getPlayer().getUniqueId()); + String loginMessage = PlayerMeta.getLoginMessage(plexPlayer); + if (!loginMessage.isEmpty()) + { + PlexUtils.broadcast(PlexUtils.stringToComponent(loginMessage)); + } + } +} diff --git a/server/src/main/java/dev/plex/meta/PlayerMeta.java b/server/src/main/java/dev/plex/meta/PlayerMeta.java index 18e8b87..4bf90b6 100644 --- a/server/src/main/java/dev/plex/meta/PlayerMeta.java +++ b/server/src/main/java/dev/plex/meta/PlayerMeta.java @@ -10,9 +10,28 @@ import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.metadata.MetadataValue; public class PlayerMeta { + public static boolean isVanished(Player player) + { + for (MetadataValue meta : player.getMetadata("vanished")) + { + if (meta.asBoolean()) + { + return true; + } + } + return false; + } + + public static boolean isVanished(PlexPlayer player) + { + return isVanished(player.getPlayer()); + } + public static Component getPrefix(PlexPlayer plexPlayer) { if (plexPlayer.getPrefix() != null && !plexPlayer.getPrefix().isEmpty()) diff --git a/server/src/main/java/dev/plex/util/PlexUtils.java b/server/src/main/java/dev/plex/util/PlexUtils.java index dd9755a..1137201 100644 --- a/server/src/main/java/dev/plex/util/PlexUtils.java +++ b/server/src/main/java/dev/plex/util/PlexUtils.java @@ -118,6 +118,15 @@ public class PlexUtils implements PlexBase return true; } + public static boolean hasVanishPlugin() + { + if (Bukkit.getPluginManager().isPluginEnabled("SuperVanish") || Bukkit.getPluginManager().isPluginEnabled("PremiumVanish")) + { + return true; + } + return false; + } + public static boolean isPluginCMD(String cmd, String pluginName) { Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginName); @@ -157,7 +166,7 @@ public class PlexUtils implements PlexBase return LEGACY_FORMATTING_PATTERN.matcher(input).find() ? LegacyComponentSerializer.legacyAmpersand().deserialize(input.replaceAll("([ยง&]+)(k+)", "") // Ugly hack, but it tries to prevent &k and any attempts to bypass it. - ).decoration(TextDecoration.OBFUSCATED, TextDecoration.State.FALSE) : + ).decoration(TextDecoration.OBFUSCATED, TextDecoration.State.FALSE) : SafeMiniMessage.mmDeserializeWithoutEvents(input); }