Search in sources :

Example 1 with CMDSender

use of com.djrapitops.plan.commands.use.CMDSender in project Plan by plan-player-analytics.

the class LinkCommands method onJson.

public void onJson(CMDSender sender, Arguments arguments) {
    String identifier = arguments.concatenate(" ");
    UUID playerUUID = identifiers.getPlayerUUID(identifier);
    UUID senderUUID = sender.getUUID().orElse(null);
    if (playerUUID == null)
        playerUUID = senderUUID;
    if (playerUUID == null) {
        throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_PLAYER_NOT_FOUND, identifier));
    }
    if (sender.hasPermission(Permissions.JSON_OTHER) || playerUUID.equals(senderUUID)) {
        String address = getAddress(sender) + "/player/" + playerUUID + "/raw";
        sender.buildMessage().addPart(colors.getMainColor() + locale.getString(CommandLang.LINK_JSON)).apply(builder -> linkTo(builder, sender, address)).send();
    } else {
        throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_NO_PERMISSION) + " (" + Permissions.JSON_OTHER.get() + ')');
    }
}
Also used : Permissions(com.djrapitops.plan.settings.Permissions) ServerInfo(com.djrapitops.plan.identification.ServerInfo) CMDSender(com.djrapitops.plan.commands.use.CMDSender) CommandLang(com.djrapitops.plan.settings.locale.lang.CommandLang) Html(com.djrapitops.plan.delivery.rendering.html.Html) MessageBuilder(com.djrapitops.plan.commands.use.MessageBuilder) UUID(java.util.UUID) Singleton(javax.inject.Singleton) Database(com.djrapitops.plan.storage.database.Database) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) Addresses(com.djrapitops.plan.delivery.webserver.Addresses) List(java.util.List) Server(com.djrapitops.plan.identification.Server) WebUserQueries(com.djrapitops.plan.storage.database.queries.objects.WebUserQueries) ColorScheme(com.djrapitops.plan.commands.use.ColorScheme) Identifiers(com.djrapitops.plan.identification.Identifiers) Locale(com.djrapitops.plan.settings.locale.Locale) User(com.djrapitops.plan.delivery.domain.auth.User) Arguments(com.djrapitops.plan.commands.use.Arguments) ServerQueries(com.djrapitops.plan.storage.database.queries.objects.ServerQueries) UUID(java.util.UUID)

Example 2 with CMDSender

use of com.djrapitops.plan.commands.use.CMDSender in project Plan by plan-player-analytics.

the class LinkCommands method onPlayerCommand.

/**
 * Implementation of player command, used to get link to player page.
 *
 * @param sender    Sender of command.
 * @param arguments Given arguments.
 */
public void onPlayerCommand(CMDSender sender, Arguments arguments) {
    String identifier = arguments.concatenate(" ");
    UUID playerUUID = identifiers.getPlayerUUID(identifier);
    UUID senderUUID = sender.getUUID().orElse(null);
    if (playerUUID == null)
        playerUUID = senderUUID;
    if (playerUUID == null) {
        throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_PLAYER_NOT_FOUND, identifier));
    }
    if (sender.hasPermission(Permissions.PLAYER_OTHER) || playerUUID.equals(senderUUID)) {
        String address = getAddress(sender) + "/player/" + playerUUID;
        sender.buildMessage().addPart(colors.getMainColor() + locale.getString(CommandLang.LINK_PLAYER)).apply(builder -> linkTo(builder, sender, address)).send();
    } else {
        throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_NO_PERMISSION) + " (" + Permissions.PLAYER_OTHER.get() + ')');
    }
}
Also used : Permissions(com.djrapitops.plan.settings.Permissions) ServerInfo(com.djrapitops.plan.identification.ServerInfo) CMDSender(com.djrapitops.plan.commands.use.CMDSender) CommandLang(com.djrapitops.plan.settings.locale.lang.CommandLang) Html(com.djrapitops.plan.delivery.rendering.html.Html) MessageBuilder(com.djrapitops.plan.commands.use.MessageBuilder) UUID(java.util.UUID) Singleton(javax.inject.Singleton) Database(com.djrapitops.plan.storage.database.Database) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) Addresses(com.djrapitops.plan.delivery.webserver.Addresses) List(java.util.List) Server(com.djrapitops.plan.identification.Server) WebUserQueries(com.djrapitops.plan.storage.database.queries.objects.WebUserQueries) ColorScheme(com.djrapitops.plan.commands.use.ColorScheme) Identifiers(com.djrapitops.plan.identification.Identifiers) Locale(com.djrapitops.plan.settings.locale.Locale) User(com.djrapitops.plan.delivery.domain.auth.User) Arguments(com.djrapitops.plan.commands.use.Arguments) ServerQueries(com.djrapitops.plan.storage.database.queries.objects.ServerQueries) UUID(java.util.UUID)

Example 3 with CMDSender

use of com.djrapitops.plan.commands.use.CMDSender in project Plan by plan-player-analytics.

the class RegistrationCommands method registerUsingLegacy.

public void registerUsingLegacy(CMDSender sender, Arguments arguments) {
    String password = arguments.get(0).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 1, "<password>")));
    String passwordHash = PassEncryptUtil.createHash(password);
    int permissionLevel = arguments.getInteger(2).filter(// argument only allowed with register other permission
    arg -> sender.hasPermission(Permissions.REGISTER_OTHER)).orElseGet(() -> getPermissionLevel(sender));
    Optional<UUID> senderUUID = sender.getUUID();
    Optional<String> senderName = sender.getPlayerName();
    if (senderUUID.isPresent() && senderName.isPresent()) {
        String playerName = senderName.get();
        UUID linkedToUUID = senderUUID.get();
        String username = arguments.get(1).orElse(playerName);
        registerUser(new User(username, playerName, linkedToUUID, passwordHash, permissionLevel, Collections.emptyList()), sender, permissionLevel);
    } else {
        String username = arguments.get(1).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 3, "<password> <name> <level>")));
        registerUser(new User(username, "console", null, passwordHash, permissionLevel, Collections.emptyList()), sender, permissionLevel);
    }
}
Also used : CommandLang(com.djrapitops.plan.settings.locale.lang.CommandLang) PluginLogger(net.playeranalytics.plugin.server.PluginLogger) Singleton(javax.inject.Singleton) Database(com.djrapitops.plan.storage.database.Database) FailReason(com.djrapitops.plan.delivery.webserver.auth.FailReason) HelpLang(com.djrapitops.plan.settings.locale.lang.HelpLang) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) RegisterWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction) RemoveWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveWebUserTransaction) ColorScheme(com.djrapitops.plan.commands.use.ColorScheme) User(com.djrapitops.plan.delivery.domain.auth.User) ErrorContext(com.djrapitops.plan.utilities.logging.ErrorContext) ActiveCookieStore(com.djrapitops.plan.delivery.webserver.auth.ActiveCookieStore) Permissions(com.djrapitops.plan.settings.Permissions) CMDSender(com.djrapitops.plan.commands.use.CMDSender) UUID(java.util.UUID) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) WebUserQueries(com.djrapitops.plan.storage.database.queries.objects.WebUserQueries) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) Locale(com.djrapitops.plan.settings.locale.Locale) PassEncryptUtil(com.djrapitops.plan.utilities.PassEncryptUtil) Optional(java.util.Optional) Arguments(com.djrapitops.plan.commands.use.Arguments) Collections(java.util.Collections) RegistrationBin(com.djrapitops.plan.delivery.webserver.auth.RegistrationBin) User(com.djrapitops.plan.delivery.domain.auth.User) UUID(java.util.UUID)

Example 4 with CMDSender

use of com.djrapitops.plan.commands.use.CMDSender in project Plan by plan-player-analytics.

the class LinkCommands method onServerCommand.

/**
 * Implementation of server subcommand, used to get link to server page.
 *
 * @param sender    Sender of command.
 * @param arguments Given arguments.
 */
public void onServerCommand(CMDSender sender, Arguments arguments) {
    Server server;
    String identifier = arguments.concatenate(" ");
    if (arguments.isEmpty()) {
        server = serverInfo.getServer();
    } else {
        server = dbSystem.getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(identifier)).filter(s -> !s.isProxy()).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_SERVER_NOT_FOUND, identifier)));
    }
    String address = getAddress(sender) + "/server/" + Html.encodeToURL(server.getName());
    sender.buildMessage().addPart(colors.getMainColor() + locale.getString(CommandLang.LINK_SERVER)).apply(builder -> linkTo(builder, sender, address)).send();
}
Also used : Permissions(com.djrapitops.plan.settings.Permissions) ServerInfo(com.djrapitops.plan.identification.ServerInfo) CMDSender(com.djrapitops.plan.commands.use.CMDSender) CommandLang(com.djrapitops.plan.settings.locale.lang.CommandLang) Html(com.djrapitops.plan.delivery.rendering.html.Html) MessageBuilder(com.djrapitops.plan.commands.use.MessageBuilder) UUID(java.util.UUID) Singleton(javax.inject.Singleton) Database(com.djrapitops.plan.storage.database.Database) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) Addresses(com.djrapitops.plan.delivery.webserver.Addresses) List(java.util.List) Server(com.djrapitops.plan.identification.Server) WebUserQueries(com.djrapitops.plan.storage.database.queries.objects.WebUserQueries) ColorScheme(com.djrapitops.plan.commands.use.ColorScheme) Identifiers(com.djrapitops.plan.identification.Identifiers) Locale(com.djrapitops.plan.settings.locale.Locale) User(com.djrapitops.plan.delivery.domain.auth.User) Arguments(com.djrapitops.plan.commands.use.Arguments) ServerQueries(com.djrapitops.plan.storage.database.queries.objects.ServerQueries) Server(com.djrapitops.plan.identification.Server)

Aggregations

Arguments (com.djrapitops.plan.commands.use.Arguments)4 CMDSender (com.djrapitops.plan.commands.use.CMDSender)4 ColorScheme (com.djrapitops.plan.commands.use.ColorScheme)4 User (com.djrapitops.plan.delivery.domain.auth.User)4 Permissions (com.djrapitops.plan.settings.Permissions)4 Locale (com.djrapitops.plan.settings.locale.Locale)4 CommandLang (com.djrapitops.plan.settings.locale.lang.CommandLang)4 DBSystem (com.djrapitops.plan.storage.database.DBSystem)4 Database (com.djrapitops.plan.storage.database.Database)4 WebUserQueries (com.djrapitops.plan.storage.database.queries.objects.WebUserQueries)4 UUID (java.util.UUID)4 Inject (javax.inject.Inject)4 Singleton (javax.inject.Singleton)4 MessageBuilder (com.djrapitops.plan.commands.use.MessageBuilder)3 Html (com.djrapitops.plan.delivery.rendering.html.Html)3 Addresses (com.djrapitops.plan.delivery.webserver.Addresses)3 Identifiers (com.djrapitops.plan.identification.Identifiers)3 Server (com.djrapitops.plan.identification.Server)3 ServerInfo (com.djrapitops.plan.identification.ServerInfo)3 ServerQueries (com.djrapitops.plan.storage.database.queries.objects.ServerQueries)3