Search in sources :

Example 1 with UserAudience

use of org.geysermc.floodgate.player.UserAudience in project Floodgate by GeyserMC.

the class LinkAccountCommand method execute.

@Override
public void execute(CommandContext<UserAudience> context) {
    UserAudience sender = context.getSender();
    PlayerLink link = api.getPlayerLink();
    // todo make this less hacky
    if (link instanceof GlobalPlayerLinking) {
        if (((GlobalPlayerLinking) link).getDatabaseImpl() != null) {
            sender.sendMessage(CommonCommandMessage.LOCAL_LINKING_NOTICE, Constants.LINK_INFO_URL);
        } else {
            sender.sendMessage(CommonCommandMessage.GLOBAL_LINKING_NOTICE, Constants.LINK_INFO_URL);
            return;
        }
    }
    if (!link.isEnabledAndAllowed()) {
        sender.sendMessage(CommonCommandMessage.LINKING_DISABLED);
        return;
    }
    // when the player is a Bedrock player
    if (api.isFloodgatePlayer(sender.uuid())) {
        if (!context.contains("code")) {
            sender.sendMessage(Message.BEDROCK_USAGE);
            return;
        }
        UserAudience targetUser = context.get("player");
        String targetName = targetUser.username();
        String code = context.get("code");
        link.verifyLinkRequest(sender.uuid(), targetName, sender.username(), code).whenComplete((result, throwable) -> {
            if (throwable != null || result == LinkRequestResult.UNKNOWN_ERROR) {
                sender.sendMessage(Message.LINK_REQUEST_ERROR);
                return;
            }
            switch(result) {
                case ALREADY_LINKED:
                    sender.sendMessage(Message.ALREADY_LINKED);
                    break;
                case NO_LINK_REQUESTED:
                    sender.sendMessage(Message.NO_LINK_REQUESTED);
                    break;
                case INVALID_CODE:
                    sender.sendMessage(Message.INVALID_CODE);
                    break;
                case REQUEST_EXPIRED:
                    sender.sendMessage(Message.LINK_REQUEST_EXPIRED);
                    break;
                case LINK_COMPLETED:
                    sender.disconnect(Message.LINK_REQUEST_COMPLETED, targetName);
                    break;
                default:
                    sender.disconnect(Component.text("Invalid account linking result"));
                    break;
            }
        });
        return;
    }
    if (context.contains("code")) {
        sender.sendMessage(Message.JAVA_USAGE);
        return;
    }
    UserAudience targetUser = context.get("player");
    String targetName = targetUser.username();
    link.createLinkRequest(sender.uuid(), sender.username(), targetName).whenComplete((result, throwable) -> {
        if (throwable != null || result == LinkRequestResult.UNKNOWN_ERROR) {
            sender.sendMessage(Message.LINK_REQUEST_ERROR);
            return;
        }
        if (!(result instanceof String)) {
            logger.error("Expected string code, got {}", result);
            sender.sendMessage(Message.LINK_REQUEST_ERROR);
            return;
        }
        sender.sendMessage(Message.LINK_REQUEST_CREATED, targetName, sender.username(), result);
    });
}
Also used : PlayerLink(org.geysermc.floodgate.api.link.PlayerLink) UserAudience(org.geysermc.floodgate.player.UserAudience) GlobalPlayerLinking(org.geysermc.floodgate.link.GlobalPlayerLinking)

Example 2 with UserAudience

use of org.geysermc.floodgate.player.UserAudience in project Floodgate by GeyserMC.

the class UnlinkAccountCommand method execute.

@Override
public void execute(CommandContext<UserAudience> context) {
    UserAudience sender = context.getSender();
    PlayerLink link = api.getPlayerLink();
    // todo make this less hacky
    if (link instanceof GlobalPlayerLinking) {
        if (((GlobalPlayerLinking) link).getDatabaseImpl() != null) {
            sender.sendMessage(CommonCommandMessage.LOCAL_LINKING_NOTICE, Constants.LINK_INFO_URL);
        } else {
            sender.sendMessage(CommonCommandMessage.GLOBAL_LINKING_NOTICE, Constants.LINK_INFO_URL);
            return;
        }
    }
    if (!link.isEnabledAndAllowed()) {
        sender.sendMessage(CommonCommandMessage.LINKING_DISABLED);
        return;
    }
    link.isLinkedPlayer(sender.uuid()).whenComplete((linked, error) -> {
        if (error != null) {
            sender.sendMessage(CommonCommandMessage.IS_LINKED_ERROR);
            return;
        }
        if (!linked) {
            sender.sendMessage(Message.NOT_LINKED);
            return;
        }
        link.unlinkPlayer(sender.uuid()).whenComplete((unused, error1) -> {
            if (error1 != null) {
                sender.sendMessage(Message.UNLINK_ERROR);
                return;
            }
            sender.sendMessage(Message.UNLINK_SUCCESS);
        });
    });
}
Also used : PlayerLink(org.geysermc.floodgate.api.link.PlayerLink) UserAudience(org.geysermc.floodgate.player.UserAudience) GlobalPlayerLinking(org.geysermc.floodgate.link.GlobalPlayerLinking)

Example 3 with UserAudience

use of org.geysermc.floodgate.player.UserAudience in project Floodgate by GeyserMC.

the class WhitelistCommand method performCommand.

public void performCommand(CommandContext<UserAudience> context, boolean add) {
    UserAudience sender = context.getSender();
    UserAudience player = context.get("player");
    UUID uuid = player.uuid();
    String name = player.username();
    if (name == null && uuid == null) {
        sender.sendMessage(Message.UNEXPECTED_ERROR);
        return;
    }
    if (uuid != null) {
        if (!FloodgateApi.getInstance().isFloodgateId(uuid)) {
            sender.sendMessage(Message.INVALID_USERNAME);
            return;
        }
        CommandUtil commandUtil = context.get("CommandUtil");
        if (add) {
            if (commandUtil.whitelistPlayer(uuid, "unknown")) {
                sender.sendMessage(Message.PLAYER_ADDED, uuid.toString());
            } else {
                sender.sendMessage(Message.PLAYER_ALREADY_WHITELISTED, uuid.toString());
            }
        } else {
            if (commandUtil.removePlayerFromWhitelist(uuid, "unknown")) {
                sender.sendMessage(Message.PLAYER_REMOVED, uuid.toString());
            } else {
                sender.sendMessage(Message.PLAYER_NOT_WHITELISTED, uuid.toString());
            }
        }
        return;
    }
    if (name.startsWith(config.getUsernamePrefix())) {
        name = name.substring(config.getUsernamePrefix().length());
    }
    if (name.length() < 1 || name.length() > 16) {
        sender.sendMessage(Message.INVALID_USERNAME);
        return;
    }
    // todo let it use translations
    String tempName = name;
    if (config.isReplaceSpaces()) {
        tempName = tempName.replace(' ', '_');
    }
    final String correctName = config.getUsernamePrefix() + tempName;
    final String strippedName = name;
    // We need to get the UUID of the player if it's not manually specified
    HttpUtils.asyncGet(Constants.GET_XUID_URL + name).whenComplete((result, error) -> {
        if (error != null) {
            sender.sendMessage(Message.API_UNAVAILABLE);
            error.printStackTrace();
            return;
        }
        JsonObject response = result.getResponse();
        if (!result.isCodeOk()) {
            sender.sendMessage(Message.UNEXPECTED_ERROR);
            logger.error("Got an error from requesting the xuid of a Bedrock player: {}", response.get("message").getAsString());
        }
        JsonElement xuidElement = response.get("xuid");
        if (xuidElement == null) {
            sender.sendMessage(Message.USER_NOT_FOUND);
            return;
        }
        String xuid = xuidElement.getAsString();
        CommandUtil commandUtil = context.get("CommandUtil");
        try {
            if (add) {
                if (commandUtil.whitelistPlayer(xuid, correctName)) {
                    sender.sendMessage(Message.PLAYER_ADDED, strippedName);
                } else {
                    sender.sendMessage(Message.PLAYER_ALREADY_WHITELISTED, strippedName);
                }
            } else {
                if (commandUtil.removePlayerFromWhitelist(xuid, correctName)) {
                    sender.sendMessage(Message.PLAYER_REMOVED, strippedName);
                } else {
                    sender.sendMessage(Message.PLAYER_NOT_WHITELISTED, strippedName);
                }
            }
        } catch (Exception exception) {
            logger.error("An unexpected error happened while executing the whitelist command", exception);
        }
    });
}
Also used : UserAudience(org.geysermc.floodgate.player.UserAudience) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) UUID(java.util.UUID) CommandUtil(org.geysermc.floodgate.platform.command.CommandUtil)

Example 4 with UserAudience

use of org.geysermc.floodgate.player.UserAudience in project Floodgate by GeyserMC.

the class FirewallCheckSubcommand method executeFirewall.

static void executeFirewall(CommandContext<UserAudience> context) {
    UserAudience sender = context.getSender();
    executeChecks(globalApiCheck(sender)).whenComplete((response, $) -> sender.sendMessage(String.format(COLOR_CHAR + "eThe checks have finished. %s/%s were successful", response.left(), response.left() + response.right())));
}
Also used : UserAudience(org.geysermc.floodgate.player.UserAudience)

Example 5 with UserAudience

use of org.geysermc.floodgate.player.UserAudience in project Floodgate by GeyserMC.

the class VelocityPlatformModule method configure.

@Override
protected void configure() {
    VelocityCommandUtil commandUtil = new VelocityCommandUtil();
    requestInjection(commandUtil);
    bind(CommandUtil.class).to(VelocityCommandUtil.class);
    bind(VelocityCommandUtil.class).toInstance(commandUtil);
    Injector child = guice.createChildInjector(new CloudInjectionModule<>(UserAudience.class, CommandExecutionCoordinator.simpleCoordinator(), commandUtil::getAudience, audience -> (CommandSource) audience.source()));
    CommandManager<UserAudience> commandManager = child.getInstance(new Key<VelocityCommandManager<UserAudience>>() {
    });
    bind(new Key<CommandManager<UserAudience>>() {
    }).toInstance(commandManager);
    commandManager.registerCommandPreProcessor(new FloodgateCommandPreprocessor<>(commandUtil));
}
Also used : CommandExecutionCoordinator(cloud.commandframework.execution.CommandExecutionCoordinator) VelocityCommandUtil(org.geysermc.floodgate.util.VelocityCommandUtil) VelocityInjector(org.geysermc.floodgate.inject.velocity.VelocityInjector) VelocityPluginMessageRegistration(org.geysermc.floodgate.pluginmessage.VelocityPluginMessageRegistration) LanguageManager(org.geysermc.floodgate.util.LanguageManager) CommandUtil(org.geysermc.floodgate.platform.command.CommandUtil) ListenerRegistration(org.geysermc.floodgate.platform.listener.ListenerRegistration) Key(com.google.inject.Key) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CommandManager(cloud.commandframework.CommandManager) CloudInjectionModule(cloud.commandframework.velocity.CloudInjectionModule) VelocitySkinApplier(org.geysermc.floodgate.util.VelocitySkinApplier) UserAudience(org.geysermc.floodgate.player.UserAudience) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) VelocityCommandManager(cloud.commandframework.velocity.VelocityCommandManager) PluginMessageManager(org.geysermc.floodgate.pluginmessage.PluginMessageManager) VelocityPlugin(org.geysermc.floodgate.VelocityPlugin) FloodgateCommandPreprocessor(org.geysermc.floodgate.player.FloodgateCommandPreprocessor) Logger(org.slf4j.Logger) CommonPlatformInjector(org.geysermc.floodgate.inject.CommonPlatformInjector) VelocityListenerRegistration(org.geysermc.floodgate.listener.VelocityListenerRegistration) PluginMessageRegistration(org.geysermc.floodgate.pluginmessage.PluginMessageRegistration) Injector(com.google.inject.Injector) FloodgateLogger(org.geysermc.floodgate.api.logger.FloodgateLogger) Provides(com.google.inject.Provides) VelocityPluginMessageUtils(org.geysermc.floodgate.pluginmessage.VelocityPluginMessageUtils) PluginMessageUtils(org.geysermc.floodgate.platform.pluginmessage.PluginMessageUtils) Named(com.google.inject.name.Named) Slf4jFloodgateLogger(org.geysermc.floodgate.logger.Slf4jFloodgateLogger) SkinApplier(org.geysermc.floodgate.skin.SkinApplier) CommandSource(com.velocitypowered.api.command.CommandSource) EventManager(com.velocitypowered.api.event.EventManager) AbstractModule(com.google.inject.AbstractModule) Singleton(com.google.inject.Singleton) UserAudience(org.geysermc.floodgate.player.UserAudience) VelocityInjector(org.geysermc.floodgate.inject.velocity.VelocityInjector) CommonPlatformInjector(org.geysermc.floodgate.inject.CommonPlatformInjector) Injector(com.google.inject.Injector) VelocityCommandUtil(org.geysermc.floodgate.util.VelocityCommandUtil) CommandUtil(org.geysermc.floodgate.platform.command.CommandUtil) CommandSource(com.velocitypowered.api.command.CommandSource) VelocityCommandUtil(org.geysermc.floodgate.util.VelocityCommandUtil) VelocityCommandManager(cloud.commandframework.velocity.VelocityCommandManager) Key(com.google.inject.Key)

Aggregations

UserAudience (org.geysermc.floodgate.player.UserAudience)5 PlayerLink (org.geysermc.floodgate.api.link.PlayerLink)2 GlobalPlayerLinking (org.geysermc.floodgate.link.GlobalPlayerLinking)2 CommandUtil (org.geysermc.floodgate.platform.command.CommandUtil)2 CommandManager (cloud.commandframework.CommandManager)1 CommandExecutionCoordinator (cloud.commandframework.execution.CommandExecutionCoordinator)1 CloudInjectionModule (cloud.commandframework.velocity.CloudInjectionModule)1 VelocityCommandManager (cloud.commandframework.velocity.VelocityCommandManager)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 Key (com.google.inject.Key)1 Provides (com.google.inject.Provides)1 Singleton (com.google.inject.Singleton)1 Named (com.google.inject.name.Named)1 CommandSource (com.velocitypowered.api.command.CommandSource)1 EventManager (com.velocitypowered.api.event.EventManager)1 ProxyServer (com.velocitypowered.api.proxy.ProxyServer)1 UUID (java.util.UUID)1