Search in sources :

Example 26 with ReturnMessageException

use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.

the class MessagesUpdateCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // First, reload the messages.
    boolean reload = this.plugin.reloadMessages();
    if (!reload) {
        // There was a failure loading a custom file
        throw ReturnMessageException.fromKey("command.nucleus.messageupdate.couldnotload");
    }
    MessageProvider messageProvider = plugin.getMessageProvider();
    if (!(messageProvider instanceof ConfigMessageProvider)) {
        throw new ReturnMessageException(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.notfile"));
    }
    ConfigMessageProvider cmp = (ConfigMessageProvider) messageProvider;
    List<String> keys = cmp.checkForMigration();
    src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.reloaded"));
    if (keys.isEmpty()) {
        return CommandResult.success();
    }
    if (args.hasAny("y")) {
        cmp.reset(keys);
        src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.reset"));
    } else {
        src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.sometoupdate", String.valueOf(keys.size())));
        keys.forEach(x -> src.sendMessage(Text.of(TextColors.YELLOW, x)));
        src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.confirm", "/nucleus update-messages -y").toBuilder().onClick(TextActions.runCommand("/nucleus update-messages -y")).build());
    }
    return CommandResult.success();
}
Also used : MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) ConfigMessageProvider(io.github.nucleuspowered.nucleus.internal.messages.ConfigMessageProvider) ConfigMessageProvider(io.github.nucleuspowered.nucleus.internal.messages.ConfigMessageProvider) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)

Example 27 with ReturnMessageException

use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.

the class BanCommand method executeCommand.

@Override
public CommandResult executeCommand(final CommandSource src, CommandContext args) throws Exception {
    final String r = args.<String>getOne(reason).orElse(plugin.getMessageProvider().getMessageWithFormat("ban.defaultreason"));
    Optional<GameProfile> ou = Optional.ofNullable(args.<GameProfile>getOne(uuid).orElseGet(() -> args.<GameProfile>getOne(user).orElse(null)));
    if (ou.isPresent()) {
        Optional<User> optionalUser = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(ou.get());
        if ((!optionalUser.isPresent() || !optionalUser.get().isOnline()) && !permissions.testSuffix(src, "offline")) {
            throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.offline.noperms"));
        }
        if (optionalUser.isPresent() && permissions.testSuffix(optionalUser.get(), "exempt.target", src, false)) {
            throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.exempt", optionalUser.get().getName()));
        }
        return executeBan(src, ou.get(), r);
    }
    if (!permissions.testSuffix(src, "offline")) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.offline.noperms"));
    }
    final String userToFind = args.<String>getOne(name).get();
    // Get the profile async.
    Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
        GameProfileManager gpm = Sponge.getServer().getGameProfileManager();
        try {
            GameProfile gp = gpm.get(userToFind).get();
            // Ban the user sync.
            Sponge.getScheduler().createSyncExecutor(plugin).execute(() -> {
                // Create the user.
                UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
                User user = uss.getOrCreate(gp);
                src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("gameprofile.new", user.getName()));
                try {
                    executeBan(src, gp, r);
                } catch (Exception e) {
                    Nucleus.getNucleus().printStackTraceIfDebugMode(e);
                }
            });
        } catch (Exception e) {
            Nucleus.getNucleus().printStackTraceIfDebugMode(e);
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.profileerror", userToFind));
        }
    });
    return CommandResult.empty();
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) User(org.spongepowered.api.entity.living.player.User) GameProfile(org.spongepowered.api.profile.GameProfile) GameProfileManager(org.spongepowered.api.profile.GameProfileManager) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)

Example 28 with ReturnMessageException

use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.

the class KitGiveCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Kit kit = args.<Kit>getOne(KIT_PARAMETER).get();
    Player player = args.<Player>getOne(playerKey).get();
    boolean skip = args.hasAny("i");
    if (src instanceof Player && player.getUniqueId().equals(((Player) src).getUniqueId())) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.give.self"));
    }
    Text playerName = Nucleus.getNucleus().getNameUtil().getName(player);
    Text kitName = Text.of(kit.getName());
    try {
        NucleusKitService.RedeemResult redeemResult = KIT_HANDLER.redeemKit(kit, player, !skip, this.mustGetAll);
        if (!redeemResult.rejected().isEmpty()) {
            // If we drop them, tell the user
            if (this.isDrop) {
                player.sendMessage(this.plugin.getMessageProvider().getTextMessageWithTextFormat("command.kit.give.itemsdropped", playerName));
                redeemResult.rejected().forEach(x -> Util.dropItemOnFloorAtLocation(x, player.getLocation()));
            } else {
                player.sendMessage(this.plugin.getMessageProvider().getTextMessageWithTextFormat("command.kit.give.fullinventory", playerName));
            }
        }
        src.sendMessage(this.plugin.getMessageProvider().getTextMessageWithTextFormat("command.kit.give.spawned", playerName, kitName));
        if (kit.isDisplayMessageOnRedeem()) {
            player.sendMessage(this.plugin.getMessageProvider().getTextMessageWithFormat("command.kit.spawned", kit.getName()));
        }
        return CommandResult.success();
    } catch (KitRedeemException ex) {
        switch(ex.getReason()) {
            case ALREADY_REDEEMED:
                throw ReturnMessageException.fromKeyText("command.kit.give.onetime.alreadyredeemed", kitName, playerName);
            case COOLDOWN_NOT_EXPIRED:
                KitRedeemException.Cooldown kre = (KitRedeemException.Cooldown) ex;
                throw ReturnMessageException.fromKeyText("command.kit.give.cooldown", playerName, Text.of(Util.getTimeStringFromSeconds(kre.getTimeLeft().getSeconds())), kitName);
            case PRE_EVENT_CANCELLED:
                KitRedeemException.PreCancelled krepe = (KitRedeemException.PreCancelled) ex;
                throw new ReturnMessageException(krepe.getCancelMessage().orElseGet(() -> (Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.kit.cancelledpre", kit.getName()))));
            case NO_SPACE:
                throw ReturnMessageException.fromKeyText("command.kit.give.fullinventorynosave", playerName);
            case UNKNOWN:
            default:
                throw ReturnMessageException.fromKeyText("command.kit.give.fail", playerName, kitName);
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) NucleusKitService(io.github.nucleuspowered.nucleus.api.service.NucleusKitService) Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit) Text(org.spongepowered.api.text.Text) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) KitRedeemException(io.github.nucleuspowered.nucleus.api.exceptions.KitRedeemException)

Example 29 with ReturnMessageException

use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.

the class JailTeleportCommand method executeCommand.

@Override
protected CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    NamedLocation location = args.<NamedLocation>getOne(jailKey).get();
    Transform<World> location1 = location.getTransform().orElseThrow(() -> new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.jails.tp.noworld", location.getName())));
    src.setTransform(location1);
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.jails.tp.success", location.getName()));
    return CommandResult.success();
}
Also used : NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) World(org.spongepowered.api.world.World)

Example 30 with ReturnMessageException

use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.

the class KickCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Player pl = args.<Player>getOne(player).get();
    String r = args.<String>getOne(reason).orElse(plugin.getMessageProvider().getMessageWithFormat("command.kick.defaultreason"));
    if (permissions.testSuffix(pl, "exempt.target", src, false)) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.kick.exempt", pl.getName()));
    }
    pl.kick(TextSerializers.FORMATTING_CODE.deserialize(r));
    MessageChannel mc = new PermissionMessageChannel(permissions.getPermissionWithSuffix("notify"));
    mc.send(plugin.getMessageProvider().getTextMessageWithFormat("command.kick.message", pl.getName(), src.getName()));
    mc.send(plugin.getMessageProvider().getTextMessageWithFormat("command.reason", r));
    return CommandResult.success();
}
Also used : PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) Player(org.spongepowered.api.entity.living.player.Player) PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)

Aggregations

ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)45 Player (org.spongepowered.api.entity.living.player.Player)14 World (org.spongepowered.api.world.World)14 Text (org.spongepowered.api.text.Text)11 User (org.spongepowered.api.entity.living.player.User)9 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)9 CommandResult (org.spongepowered.api.command.CommandResult)7 Inventory (org.spongepowered.api.item.inventory.Inventory)6 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)5 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)5 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)5 SuggestedLevel (io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel)5 Optional (java.util.Optional)5 CommandContext (org.spongepowered.api.command.args.CommandContext)5 CommandElement (org.spongepowered.api.command.args.CommandElement)5 GenericArguments (org.spongepowered.api.command.args.GenericArguments)5 Home (io.github.nucleuspowered.nucleus.api.nucleusdata.Home)4 Warp (io.github.nucleuspowered.nucleus.api.nucleusdata.Warp)4 NoModifiers (io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers)4 NucleusTeleportHandler (io.github.nucleuspowered.nucleus.internal.teleport.NucleusTeleportHandler)4