diff --git a/README.md b/README.md index 36f679c..f7b2504 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ The perm-pack to grant all permissions: `tweaks.commands.item` | /ping (player) | see your own or someone else's latency | latency | tweaks.command.ping | player | *.others | | /seen [player] | gives you information about a player | find | tweaks.command.seen | | | | /speed [speed] (player) | change your own or someone else's walk or fly speed | | tweaks.command.speed | player | *.others | -| /tpo [player] (player) | teleport offline-players to others or you to them | | tweaks.command.offline-tp | | | +| /vanish (player) | hide yourself or someone else from others | v | tweaks.command.vanish | | | The perm-pack to grant all permissions: `tweaks.commands.player` diff --git a/src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java b/src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java index 499316b..a6c88ba 100644 --- a/src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java +++ b/src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java @@ -60,8 +60,14 @@ public class TweaksPlugin extends JavaPlugin { 20 ), new VanillaTweaks(0, 0, 0, false), - new ServerConfig(true, "lobby", null) + new ServerConfig(isProxyEnabled(), "lobby", null) )).validate().save(); + + private boolean isProxyEnabled() { + return Bukkit.spigot().getPaperConfig().getBoolean("proxies.velocity.enabled") + || Bukkit.spigot().getSpigotConfig().getBoolean("settings.bungeecord"); + } + private final File translations = new File(getDataFolder(), "translations"); private final ComponentBundle bundle = new ComponentBundle(translations, audience -> audience instanceof Player player ? player.locale() : Locale.US) @@ -119,12 +125,13 @@ private void registerCommands() { registerCommand(new InventoryCommand(this)); registerCommand(new EnderChestCommand(this)); registerCommand(new SpeedCommand(this)); + registerCommand(new VanishCommand(this)); registerCommand(new GameModeCommand(this)); registerCommand(new OfflineTeleportCommand(this)); // Server registerCommand(new BroadcastCommand(this)); - if (isLobbyCommandEnabled()) + if (config().serverConfig().enableLobbyCommand()) registerCommand(new LobbyCommand(this, new PluginMessenger(this))); registerCommand(new MotdCommand(this)); @@ -149,10 +156,6 @@ private void registerCommands() { registerCommand(new WorkbenchCommand()); } - private boolean isLobbyCommandEnabled() { - return config().serverConfig().enableLobbyCommand(); - } - private void registerCommand(CommandExecutor executor) { try { var annotation = executor.getClass().getAnnotation(CommandInfo.class); diff --git a/src/main/java/net/thenextlvl/tweaks/command/player/VanishCommand.java b/src/main/java/net/thenextlvl/tweaks/command/player/VanishCommand.java new file mode 100644 index 0000000..b853d61 --- /dev/null +++ b/src/main/java/net/thenextlvl/tweaks/command/player/VanishCommand.java @@ -0,0 +1,37 @@ +package net.thenextlvl.tweaks.command.player; + +import lombok.RequiredArgsConstructor; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import net.thenextlvl.tweaks.TweaksPlugin; +import net.thenextlvl.tweaks.command.api.CommandInfo; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo( + name = "vanish", + description = "hide yourself or someone else from others", + permission = "tweaks.command.vanish", + aliases = {"v"} +) +@RequiredArgsConstructor +public class VanishCommand extends PlayerCommand { + private final TweaksPlugin plugin; + + @Override + protected void execute(CommandSender sender, Player target) { + target.setVisibleByDefault(!target.isVisibleByDefault()); + Bukkit.getOnlinePlayers().stream() + .filter(player -> !target.equals(player)) + .forEach(player -> { + if (target.isVisibleByDefault()) player.showPlayer(plugin, target); + else player.hidePlayer(plugin, target); + }); + + var messageSelf = target.isVisibleByDefault() ? "vanish.disabled.self" : "vanish.enabled.self"; + var messageOthers = target.isVisibleByDefault() ? "vanish.disabled.others" : "vanish.enabled.others"; + plugin.bundle().sendMessage(target, messageSelf); + if (target != sender) plugin.bundle().sendMessage(sender, messageOthers, + Placeholder.parsed("player", target.getName())); + } +} diff --git a/src/main/resources/tweaks.properties b/src/main/resources/tweaks.properties index 5cb097a..a18bdf2 100644 --- a/src/main/resources/tweaks.properties +++ b/src/main/resources/tweaks.properties @@ -13,6 +13,10 @@ hunger.satisfied.self= Your hunger has been satisfied hunger.satisfied.others= 's hunger has been satisfied health.restored.self= Your health has been restored health.restored.others= 's health has been restored +vanish.enabled.self= You are now invisible to others +vanish.disabled.self= You are now visible to others +vanish.enabled.others= is now invisible to others +vanish.disabled.others= is now visible to others flight.disabled.others= can no longer fly flight.enabled.others= 's is now able to fly flight.disabled.self= You can no longer fly diff --git a/src/main/resources/tweaks_german.properties b/src/main/resources/tweaks_german.properties index 7947bb1..f25c95f 100644 --- a/src/main/resources/tweaks_german.properties +++ b/src/main/resources/tweaks_german.properties @@ -11,6 +11,10 @@ hunger.satisfied.self= Dein Hunger wurde gestillt hunger.satisfied.others= 's Hunger wurde gestillt health.restored.self= Du wurdest vollständig geheilt health.restored.others= wurde vollständig geheilt +vanish.enabled.self= Du bist jetzt unsichtbar für andere +vanish.disabled.self= Du bist wieder sichtbar für andere +vanish.enabled.others= ist jetzt unsichtbar für andere +vanish.disabled.others= ist wieder sichtbar für andere flight.disabled.others= kann nicht länger fliegen flight.enabled.others= 's kann ab jetzt fliegen flight.disabled.self= Du kannst nicht länger fliegen