-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from TheNextLvl-net/vanish
add vanish command
- Loading branch information
Showing
5 changed files
with
55 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/net/thenextlvl/tweaks/command/player/VanishCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters