mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 06:28:53 +00:00
vanish support and suggestions overhaul
This commit is contained in:
1 parent
de118017eb
commit
12b40f8150
10 files changed
+126
-19
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
package net.draycia.carbon.api;
|
package net.draycia.carbon.api;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
@@ -31,7 +32,7 @@ public interface CarbonServer extends Audience {
|
|||||||
* @return the online players
|
* @return the online players
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
Iterable<? extends CarbonPlayer> players();
|
List<? extends CarbonPlayer> players();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains a {@link CarbonPlayer} instance for the specified uuid.
|
* Obtains a {@link CarbonPlayer} instance for the specified uuid.
|
||||||
|
|||||||
@@ -270,4 +270,23 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
*/
|
*/
|
||||||
void lastWhisperTarget(final @Nullable UUID uuid);
|
void lastWhisperTarget(final @Nullable UUID uuid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this player is vanished in another supported plugin.
|
||||||
|
* Other players will be unaware of this player.
|
||||||
|
* There is no way to set this state through Carbon, we do not store this information; but merely bridge it.
|
||||||
|
*
|
||||||
|
* @return If this player is vanished in another plugin.
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
boolean vanished();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this player can see the other player.
|
||||||
|
*
|
||||||
|
* @param other the other, potentially vanished, player
|
||||||
|
* @return if this player is aware of the other player
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
boolean awareOf(final CarbonPlayer other);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ package net.draycia.carbon.bukkit;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@@ -50,7 +51,7 @@ public final class CarbonServerBukkit implements CarbonServer, ForwardingAudienc
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<? extends CarbonPlayer> players() {
|
public List<? extends CarbonPlayer> players() {
|
||||||
final var players = new ArrayList<CarbonPlayer>();
|
final var players = new ArrayList<CarbonPlayer>();
|
||||||
|
|
||||||
for (final var player : this.chatBukkitEntry.getServer().getOnlinePlayers()) {
|
for (final var player : this.chatBukkitEntry.getServer().getOnlinePlayers()) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
import net.draycia.carbon.bukkit.util.BukkitCapabilities;
|
import net.draycia.carbon.bukkit.util.BukkitCapabilities;
|
||||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||||
import net.draycia.carbon.common.users.WrappedCarbonPlayer;
|
import net.draycia.carbon.common.users.WrappedCarbonPlayer;
|
||||||
@@ -15,6 +16,7 @@ import net.milkbowl.vault.permission.Permission;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.metadata.MetadataValue;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
@@ -179,6 +181,31 @@ public final class CarbonPlayerBukkit extends WrappedCarbonPlayer implements For
|
|||||||
return this.player() != null;
|
return this.player() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean vanished() {
|
||||||
|
return this.hasVanishMeta();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Supported by PremiumVanish, SuperVanish, VanishNoPacket
|
||||||
|
private boolean hasVanishMeta() {
|
||||||
|
for (final MetadataValue meta : this.player().getMetadata("vanished")) {
|
||||||
|
if (meta.asBoolean()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean awareOf(final CarbonPlayer other) {
|
||||||
|
if (other.vanished()) {
|
||||||
|
return this.hasPermission("carbon.seevanished");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable ChatChannel selectedChannel() {
|
public @Nullable ChatChannel selectedChannel() {
|
||||||
return this.carbonPlayerCommon.selectedChannel();
|
return this.carbonPlayerCommon.selectedChannel();
|
||||||
|
|||||||
+58
-13
@@ -7,12 +7,17 @@ import cloud.commandframework.context.CommandContext;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.function.BiPredicate;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import net.draycia.carbon.api.CarbonServer;
|
import net.draycia.carbon.api.CarbonServer;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
import net.draycia.carbon.common.command.Commander;
|
import net.draycia.carbon.common.command.Commander;
|
||||||
|
import net.draycia.carbon.common.command.PlayerCommander;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
public class CarbonPlayerArgument {
|
public class CarbonPlayerArgument {
|
||||||
|
|
||||||
private final CarbonServer server;
|
private final CarbonServer server;
|
||||||
@@ -22,13 +27,34 @@ public class CarbonPlayerArgument {
|
|||||||
this.server = server;
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandArgument<Commander, CarbonPlayer> newInstance(boolean required, final String name) {
|
public static BiPredicate<CarbonPlayer, CarbonPlayer> NO_FILTER = (sender, target) -> true;
|
||||||
return new CarbonPlayerArgumentImpl(required, name, new CarbonPlayerArgumentParser(this.server), CarbonPlayer.class);
|
public static BiPredicate<CarbonPlayer, CarbonPlayer> NO_SENDER = (sender, target) -> !sender.equals(target);
|
||||||
|
|
||||||
|
public CommandArgument<Commander, CarbonPlayer> newInstance(
|
||||||
|
final boolean required,
|
||||||
|
final String name,
|
||||||
|
final BiPredicate<CarbonPlayer, CarbonPlayer> filter
|
||||||
|
) {
|
||||||
|
return new CarbonPlayerArgumentImpl(required, name,
|
||||||
|
new CarbonPlayerArgumentParser(this.server, filter), CarbonPlayer.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandArgument<Commander, CarbonPlayer> newInstance(
|
||||||
|
final boolean required,
|
||||||
|
final String name
|
||||||
|
) {
|
||||||
|
return new CarbonPlayerArgumentImpl(required, name,
|
||||||
|
new CarbonPlayerArgumentParser(this.server, NO_FILTER), CarbonPlayer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class CarbonPlayerArgumentImpl extends CommandArgument<Commander, CarbonPlayer> {
|
public static final class CarbonPlayerArgumentImpl extends CommandArgument<Commander, CarbonPlayer> {
|
||||||
|
|
||||||
CarbonPlayerArgumentImpl(boolean required, @NonNull String name, @NonNull ArgumentParser<Commander, CarbonPlayer> parser, @NonNull Class<CarbonPlayer> valueType) {
|
CarbonPlayerArgumentImpl(
|
||||||
|
final boolean required,
|
||||||
|
final String name,
|
||||||
|
final ArgumentParser<Commander, CarbonPlayer> parser,
|
||||||
|
final Class<CarbonPlayer> valueType
|
||||||
|
) {
|
||||||
super(required, name, parser, valueType);
|
super(required, name, parser, valueType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,15 +63,23 @@ public class CarbonPlayerArgument {
|
|||||||
private static final class CarbonPlayerArgumentParser implements ArgumentParser<Commander, CarbonPlayer> {
|
private static final class CarbonPlayerArgumentParser implements ArgumentParser<Commander, CarbonPlayer> {
|
||||||
|
|
||||||
final CarbonServer server;
|
final CarbonServer server;
|
||||||
|
final BiPredicate<CarbonPlayer, CarbonPlayer> filter;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public CarbonPlayerArgumentParser(final CarbonServer carbonServer) {
|
public CarbonPlayerArgumentParser(
|
||||||
|
final CarbonServer carbonServer,
|
||||||
|
final BiPredicate<CarbonPlayer, CarbonPlayer> filter
|
||||||
|
) {
|
||||||
this.server = carbonServer;
|
this.server = carbonServer;
|
||||||
|
this.filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull ArgumentParseResult<@NonNull CarbonPlayer> parse(@NonNull CommandContext<@NonNull Commander> commandContext, @NonNull Queue<@NonNull String> inputQueue) {
|
public ArgumentParseResult<CarbonPlayer> parse(
|
||||||
final String input = inputQueue.peek();
|
final CommandContext<Commander> commandContext,
|
||||||
|
final Queue<String> inputQueue
|
||||||
|
) {
|
||||||
|
final @Nullable String input = inputQueue.peek();
|
||||||
|
|
||||||
for (var player : this.server.players()) {
|
for (var player : this.server.players()) {
|
||||||
if (player.username().equalsIgnoreCase(input)) {
|
if (player.username().equalsIgnoreCase(input)) {
|
||||||
@@ -58,10 +92,21 @@ public class CarbonPlayerArgument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull List<@NonNull String> suggestions(@NonNull CommandContext<Commander> commandContext, @NonNull String input) {
|
public List<String> suggestions(
|
||||||
return StreamSupport.stream(this.server.players().spliterator(), false)
|
final CommandContext<Commander> commandContext,
|
||||||
.map(CarbonPlayer::username)
|
final String input
|
||||||
.toList();
|
) {
|
||||||
|
if (commandContext.getSender() instanceof PlayerCommander sender) {
|
||||||
|
return this.server.players().stream()
|
||||||
|
.filter(it -> filter.test(sender.carbonPlayer(), it))
|
||||||
|
.filter(sender.carbonPlayer()::awareOf)
|
||||||
|
.map(CarbonPlayer::username)
|
||||||
|
.toList();
|
||||||
|
} else {
|
||||||
|
return this.server.players().stream()
|
||||||
|
.map(CarbonPlayer::username)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -72,12 +117,12 @@ public class CarbonPlayerArgument {
|
|||||||
private final String input;
|
private final String input;
|
||||||
|
|
||||||
public PlayerParseException(
|
public PlayerParseException(
|
||||||
final @NonNull String input
|
final String input
|
||||||
) {
|
) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull String input() {
|
public String input() {
|
||||||
return this.input;
|
return this.input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class MuteCommand {
|
|||||||
this.commandManager = commandManager;
|
this.commandManager = commandManager;
|
||||||
|
|
||||||
var command = commandManager.commandBuilder("mute")
|
var command = commandManager.commandBuilder("mute")
|
||||||
.argument(carbonPlayerArgument.newInstance(false, "player"))
|
.argument(carbonPlayerArgument.newInstance(false, "player", CarbonPlayerArgument.NO_SENDER))
|
||||||
.flag(commandManager.flagBuilder("uuid")
|
.flag(commandManager.flagBuilder("uuid")
|
||||||
.withAliases("u")
|
.withAliases("u")
|
||||||
.withArgument(UUIDArgument.optional("uuid"))
|
.withArgument(UUIDArgument.optional("uuid"))
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import net.draycia.carbon.common.command.arguments.OptionValueParser;
|
|||||||
import net.draycia.carbon.common.messages.CarbonMessageService;
|
import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
|
|
||||||
public class NicknameCommand {
|
public class NicknameCommand {
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import cloud.commandframework.arguments.standard.UUIDArgument;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
import net.draycia.carbon.common.command.Commander;
|
import net.draycia.carbon.common.command.Commander;
|
||||||
@@ -25,7 +26,11 @@ public class UnmuteCommand {
|
|||||||
final CarbonPlayerArgument carbonPlayerArgument
|
final CarbonPlayerArgument carbonPlayerArgument
|
||||||
) {
|
) {
|
||||||
final var command = commandManager.commandBuilder("unmute")
|
final var command = commandManager.commandBuilder("unmute")
|
||||||
.argument(carbonPlayerArgument.newInstance(false, "player"))
|
// TODO: only suggest muted players :D
|
||||||
|
.argument(carbonPlayerArgument.newInstance(false, "player",
|
||||||
|
CarbonPlayerArgument.NO_SENDER.and((sender, player) -> {
|
||||||
|
return !player.muteEntries().isEmpty();
|
||||||
|
})))
|
||||||
.flag(commandManager.flagBuilder("uuid")
|
.flag(commandManager.flagBuilder("uuid")
|
||||||
.withAliases("u")
|
.withAliases("u")
|
||||||
.withArgument(UUIDArgument.optional("uuid"))
|
.withArgument(UUIDArgument.optional("uuid"))
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class WhisperCommand {
|
|||||||
final CarbonPlayerArgument carbonPlayerArgument
|
final CarbonPlayerArgument carbonPlayerArgument
|
||||||
) {
|
) {
|
||||||
var command = commandManager.commandBuilder("whisper", "w", "message", "msg")
|
var command = commandManager.commandBuilder("whisper", "w", "message", "msg")
|
||||||
.argument(carbonPlayerArgument.newInstance(true, "recipient"))
|
.argument(carbonPlayerArgument.newInstance(true, "recipient", CarbonPlayerArgument.NO_SENDER))
|
||||||
.argument(StringArgument.greedy("message"))
|
.argument(StringArgument.greedy("message"))
|
||||||
.permission("carbon.whisper.send") // TODO: carbon.whisper.spy
|
.permission("carbon.whisper.send") // TODO: carbon.whisper.spy
|
||||||
.senderType(PlayerCommander.class)
|
.senderType(PlayerCommander.class)
|
||||||
|
|||||||
@@ -202,6 +202,16 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
this.lastWhisperTarget = uuid;
|
this.lastWhisperTarget = uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean vanished() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean awareOf(CarbonPlayer other) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identity identity() {
|
public Identity identity() {
|
||||||
return Identity.identity(this.uuid);
|
return Identity.identity(this.uuid);
|
||||||
|
|||||||
Reference in new issue
Block a user