Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vanish command #15

Merged
merged 5 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
15 changes: 9 additions & 6 deletions src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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()));
}
}
4 changes: 4 additions & 0 deletions src/main/resources/tweaks.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ hunger.satisfied.self=<prefix> <white>Your hunger has been satisfied
hunger.satisfied.others=<prefix> <green><player>'s<white> hunger has been satisfied
health.restored.self=<prefix> <white>Your health has been restored
health.restored.others=<prefix> <green><player>'s<white> health has been restored
vanish.enabled.self=<prefix> <white>You are now invisible to others
vanish.disabled.self=<prefix> <white>You are now visible to others
vanish.enabled.others=<prefix> <green><player> <white>is now invisible to others
vanish.disabled.others=<prefix> <green><player> <white>is now visible to others
flight.disabled.others=<prefix> <green><player><white> can no longer fly
flight.enabled.others=<prefix> <green><player>'s<white> is now able to fly
flight.disabled.self=<prefix> <white>You can no longer fly
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/tweaks_german.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ hunger.satisfied.self=<prefix> <white>Dein Hunger wurde gestillt
hunger.satisfied.others=<prefix> <green><player>'s<white> Hunger wurde gestillt
health.restored.self=<prefix> <white>Du wurdest vollständig geheilt
health.restored.others=<prefix> <green><player><white> wurde vollständig geheilt
vanish.enabled.self=<prefix> <white>Du bist jetzt unsichtbar für andere
vanish.disabled.self=<prefix> <white>Du bist wieder sichtbar für andere
vanish.enabled.others=<prefix> <green><player> <white>ist jetzt unsichtbar für andere
vanish.disabled.others=<prefix> <green><player> <white>ist wieder sichtbar für andere
flight.disabled.others=<prefix> <green><player><white> kann nicht länger fliegen
flight.enabled.others=<prefix> <green><player>'s<white> kann ab jetzt fliegen
flight.disabled.self=<prefix> <white>Du kannst nicht länger fliegen
Expand Down
Loading