From b5e7d05315be05fbb34366e9ef78ee83af69b7f6 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Mon, 29 Mar 2021 20:06:26 +0200 Subject: [PATCH] Fixed #124 and whitelist command only works on non-proxies. --- .../floodgate/util/BungeeCommandUtil.java | 14 ++------------ .../floodgate/command/WhitelistCommand.java | 7 +++++++ .../platform/command/CommandUtil.java | 19 ++++++++++++------- .../floodgate/util/SpigotCommandUtil.java | 4 ++-- .../floodgate/util/VelocityCommandUtil.java | 14 ++------------ 5 files changed, 25 insertions(+), 33 deletions(-) diff --git a/bungee/src/main/java/org/geysermc/floodgate/util/BungeeCommandUtil.java b/bungee/src/main/java/org/geysermc/floodgate/util/BungeeCommandUtil.java index 07260609..2dc31d41 100644 --- a/bungee/src/main/java/org/geysermc/floodgate/util/BungeeCommandUtil.java +++ b/bungee/src/main/java/org/geysermc/floodgate/util/BungeeCommandUtil.java @@ -135,8 +135,8 @@ public final class BungeeCommandUtil implements CommandUtil { } @Override - public void sendMessage(Object player, String locale, CommandMessage message, Object... args) { - cast(player).sendMessage(translateAndTransform(locale, message, args)); + public void sendMessage(Object target, String locale, CommandMessage message, Object... args) { + ((CommandSender) target).sendMessage(translateAndTransform(locale, message, args)); } @Override @@ -144,16 +144,6 @@ public final class BungeeCommandUtil implements CommandUtil { cast(player).disconnect(translateAndTransform(locale, message, args)); } - @Override - public boolean whitelistPlayer(String xuid, String username) { - return false; // todo - } - - @Override - public boolean removePlayerFromWhitelist(String xuid, String username) { - return false; // todo - } - public BaseComponent[] translateAndTransform(String locale, CommandMessage message, Object... args) { return TextComponent.fromLegacyText(message.translateMessage(manager, locale, args)); diff --git a/common/src/main/java/org/geysermc/floodgate/command/WhitelistCommand.java b/common/src/main/java/org/geysermc/floodgate/command/WhitelistCommand.java index 606a25dd..11f91441 100644 --- a/common/src/main/java/org/geysermc/floodgate/command/WhitelistCommand.java +++ b/common/src/main/java/org/geysermc/floodgate/command/WhitelistCommand.java @@ -36,6 +36,7 @@ import com.google.inject.Inject; import lombok.Getter; import org.geysermc.floodgate.api.logger.FloodgateLogger; import org.geysermc.floodgate.config.FloodgateConfig; +import org.geysermc.floodgate.config.ProxyFloodgateConfig; import org.geysermc.floodgate.platform.command.CommandMessage; import org.geysermc.floodgate.platform.command.CommandUtil; import org.geysermc.floodgate.platform.command.FloodgateCommand; @@ -139,6 +140,12 @@ public class WhitelistCommand implements FloodgateCommand { // ignored, all the logic is in the other method } + @Override + public boolean shouldRegister(FloodgateConfig config) { + // currently only Spigot (our only non-Proxy platform) has a whitelist build-in. + return config instanceof ProxyFloodgateConfig; + } + @Getter public enum Message implements CommandMessage { INVALID_USERNAME("floodgate.command.fwhitelist.invalid_username"), diff --git a/common/src/main/java/org/geysermc/floodgate/platform/command/CommandUtil.java b/common/src/main/java/org/geysermc/floodgate/platform/command/CommandUtil.java index e7f1a333..4161f6f4 100644 --- a/common/src/main/java/org/geysermc/floodgate/platform/command/CommandUtil.java +++ b/common/src/main/java/org/geysermc/floodgate/platform/command/CommandUtil.java @@ -50,14 +50,14 @@ public interface CommandUtil { @NonNull Collection getOnlineUsernames(final @NonNull PlayerType limitTo); /** - * Send a message to the specified player, no matter what platform Floodgate is running on. + * Send a message to the specified target, no matter what platform Floodgate is running on. * - * @param player the player to send the message to + * @param target the target to send the message to * @param message the command message * @param locale the locale of the player * @param args the arguments */ - void sendMessage(Object player, String locale, CommandMessage message, Object... args); + void sendMessage(Object target, String locale, CommandMessage message, Object... args); /** * Same as {@link CommandUtil#sendMessage(Object, String, CommandMessage, Object...)} except it @@ -75,9 +75,12 @@ public interface CommandUtil { * * @param xuid the xuid of the username to be whitelisted * @param username the username to be whitelisted - * @return true if the player has been whitelisted, false if the player was already whitelisted + * @return true if the player has been whitelisted, false if the player was already whitelisted. + * Defaults to false when this platform doesn't support whitelisting. */ - boolean whitelistPlayer(String xuid, String username); + default boolean whitelistPlayer(String xuid, String username) { + return false; + } /** * Removes the given Bedrock player from the whitelist. @@ -85,7 +88,9 @@ public interface CommandUtil { * @param xuid the xuid of the username to be removed from the whitelist * @param username the username to be removed from the whitelist * @return true if the player has been removed from the whitelist, false if the player wasn't - * whitelisted + * whitelisted. Defaults to false when this platform doesn't support whitelisting. */ - boolean removePlayerFromWhitelist(String xuid, String username); + default boolean removePlayerFromWhitelist(String xuid, String username) { + return false; + } } diff --git a/spigot/src/main/java/org/geysermc/floodgate/util/SpigotCommandUtil.java b/spigot/src/main/java/org/geysermc/floodgate/util/SpigotCommandUtil.java index 08e3781b..4349b462 100644 --- a/spigot/src/main/java/org/geysermc/floodgate/util/SpigotCommandUtil.java +++ b/spigot/src/main/java/org/geysermc/floodgate/util/SpigotCommandUtil.java @@ -136,8 +136,8 @@ public final class SpigotCommandUtil implements CommandUtil { } @Override - public void sendMessage(Object player, String locale, CommandMessage message, Object... args) { - cast(player).sendMessage(translateAndTransform(locale, message, args)); + public void sendMessage(Object target, String locale, CommandMessage message, Object... args) { + ((CommandSender) target).sendMessage(translateAndTransform(locale, message, args)); } @Override diff --git a/velocity/src/main/java/org/geysermc/floodgate/util/VelocityCommandUtil.java b/velocity/src/main/java/org/geysermc/floodgate/util/VelocityCommandUtil.java index 0467c929..65e6cd6f 100644 --- a/velocity/src/main/java/org/geysermc/floodgate/util/VelocityCommandUtil.java +++ b/velocity/src/main/java/org/geysermc/floodgate/util/VelocityCommandUtil.java @@ -134,8 +134,8 @@ public final class VelocityCommandUtil implements CommandUtil { } @Override - public void sendMessage(Object player, String locale, CommandMessage message, Object... args) { - cast(player).sendMessage(translateAndTransform(locale, message, args)); + public void sendMessage(Object target, String locale, CommandMessage message, Object... args) { + ((CommandSource) target).sendMessage(translateAndTransform(locale, message, args)); } @Override @@ -143,16 +143,6 @@ public final class VelocityCommandUtil implements CommandUtil { cast(player).disconnect(translateAndTransform(locale, message, args)); } - @Override - public boolean whitelistPlayer(String xuid, String username) { - return false; // todo - } - - @Override - public boolean removePlayerFromWhitelist(String xuid, String username) { - return false; // todo - } - public Component translateAndTransform(String locale, CommandMessage message, Object... args) { return Component.text(message.translateMessage(manager, locale, args));