mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Prevent sending requests to vanished players
This commit is contained in:
1 parent
6397d78767
commit
2152ca91f2
4 files changed
+24
-2
No files matched your search
@@ -14,6 +14,7 @@ import net.william278.huskhomes.util.BukkitAdapter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -147,6 +148,16 @@ public class BukkitPlayer extends OnlineUser {
|
||||
return player.getVelocity().length() >= 0.1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVanished() {
|
||||
// Return the value of the player's "vanished" metadata tag if they have it
|
||||
return player.getMetadata("vanished")
|
||||
.stream()
|
||||
.map(MetadataValue::asBoolean)
|
||||
.findFirst()
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a Bukkit plugin message
|
||||
*/
|
||||
|
||||
@@ -102,7 +102,11 @@ public class Cache {
|
||||
});
|
||||
} else {
|
||||
players.clear();
|
||||
players.addAll(plugin.getOnlinePlayers().stream().map(onlineUser -> onlineUser.username).toList());
|
||||
players.addAll(plugin.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(player -> !player.isVanished())
|
||||
.map(onlineUser -> onlineUser.username)
|
||||
.toList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -104,6 +104,13 @@ public abstract class OnlineUser extends User {
|
||||
*/
|
||||
public abstract boolean isMoving();
|
||||
|
||||
/**
|
||||
* Returns if the player is tagged as being "vanished" by a /vanish plugin
|
||||
*
|
||||
* @return {@code true} if the player is tagged as being "vanished" by a /vanish plugin; {@code false} otherwise
|
||||
*/
|
||||
public abstract boolean isVanished();
|
||||
|
||||
/**
|
||||
* Get the maximum number of homes this user may set
|
||||
*
|
||||
|
||||
@@ -132,7 +132,7 @@ public class RequestManager {
|
||||
* @return {@code true} if the request was sent, {@code false} if it was not sent because the recipient is ignoring requests
|
||||
*/
|
||||
public boolean sendLocalTeleportRequest(@NotNull TeleportRequest request, @NotNull OnlineUser recipient) {
|
||||
if (isIgnoringRequests(recipient)) {
|
||||
if (isIgnoringRequests(recipient) || recipient.isVanished()) {
|
||||
request.status = TeleportRequest.RequestStatus.IGNORED;
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user