Search in sources :

Example 1 with MessageProvider

use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.

the class TeleportCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    boolean beQuiet = args.<Boolean>getOne(quietKey).orElse(this.isDefaultQuiet);
    Optional<Player> oTo = args.getOne(playerToKey);
    User to;
    Player from;
    if (oTo.isPresent()) {
        // Two player argument.
        from = args.<User>getOne(playerKey).map(x -> x.getPlayer().orElse(null)).orElseThrow(() -> ReturnMessageException.fromKey("command.playeronly"));
        to = oTo.get();
        if (to.equals(src)) {
            throw ReturnMessageException.fromKey("command.teleport.player.noself");
        }
    } else if (src instanceof Player) {
        from = (Player) src;
        to = args.<User>getOne(playerKey).get();
    } else {
        throw ReturnMessageException.fromKey("command.playeronly");
    }
    if (to.getPlayer().isPresent()) {
        if (handler.getBuilder().setSource(src).setFrom(from).setTo(to.getPlayer().get()).setSafe(!args.<Boolean>getOne("f").orElse(false)).setSilentTarget(beQuiet).startTeleport()) {
            return CommandResult.success();
        }
        return CommandResult.empty();
    }
    // We have an offline player.
    permissions.checkSuffix(src, "offline", () -> ReturnMessageException.fromKey("command.teleport.noofflineperms"));
    // Can we get a location?
    Supplier<ReturnMessageException> r = () -> ReturnMessageException.fromKey("command.teleport.nolastknown", to.getName());
    Location<World> l = plugin.getUserDataManager().get(to.getUniqueId()).orElseThrow(r).get(CoreUserDataModule.class).getLogoutLocation().orElseThrow(r);
    MessageProvider provider = plugin.getMessageProvider();
    if (CauseStackHelper.createFrameWithCausesWithReturn(c -> plugin.getTeleportHandler().teleportPlayer(from, l, NucleusTeleportHandler.StandardTeleportMode.FLYING_THEN_SAFE, c).isSuccess(), src)) {
        if (!(src instanceof Player && ((Player) src).getUniqueId().equals(from.getUniqueId()))) {
            src.sendMessage(provider.getTextMessageWithFormat("command.teleport.offline.other", from.getName(), to.getName()));
        }
        from.sendMessage(provider.getTextMessageWithFormat("command.teleport.offline.self", to.getName()));
        return CommandResult.success();
    }
    throw ReturnMessageException.fromKey("command.teleport.error");
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) User(org.spongepowered.api.entity.living.player.User) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) World(org.spongepowered.api.world.World)

Example 2 with MessageProvider

use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.

the class AvailableBaseCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    MessageProvider mp = Nucleus.getNucleus().getMessageProvider();
    List<Text> types = Sponge.getRegistry().getAllOf(this.catalogType).stream().map(x -> mp.getTextMessageWithFormat("command.world.presets.item", x.getId(), x.getName())).collect(Collectors.toList());
    Util.getPaginationBuilder(src).title(mp.getTextMessageWithTextFormat(this.titleKey)).contents(types).sendTo(src);
    return CommandResult.success();
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) CommandSource(org.spongepowered.api.command.CommandSource) CatalogType(org.spongepowered.api.CatalogType) Sponge(org.spongepowered.api.Sponge) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) Collectors(java.util.stream.Collectors) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) Util(io.github.nucleuspowered.nucleus.Util) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Text(org.spongepowered.api.text.Text)

Example 3 with MessageProvider

use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.

the class KittyCannonCommand method permissionSuffixesToRegister.

@Override
protected Map<String, PermissionInformation> permissionSuffixesToRegister() {
    return new HashMap<String, PermissionInformation>() {

        {
            MessageProvider provider = plugin.getMessageProvider();
            put("damage", new PermissionInformation(provider.getMessageWithFormat("permission.kittycannon.damage"), SuggestedLevel.ADMIN));
            put("break", new PermissionInformation(provider.getMessageWithFormat("permission.kittycannon.break"), SuggestedLevel.ADMIN));
            put("fire", new PermissionInformation(provider.getMessageWithFormat("permission.kittycannon.fire"), SuggestedLevel.ADMIN));
        }
    };
}
Also used : MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) HashMap(java.util.HashMap) PermissionInformation(io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation)

Example 4 with MessageProvider

use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.

the class SetupPermissionsCommand method setupGroups.

private void setupGroups(CommandSource src) throws Exception {
    String ownerGroup = "owner";
    String adminGroup = "admin";
    String modGroup = "mod";
    String defaultGroup = "default";
    MessageProvider messageProvider = Nucleus.getNucleus().getMessageProvider();
    // Create groups
    PermissionService permissionService = Sponge.getServiceManager().provide(PermissionService.class).orElseThrow(() -> ReturnMessageException.fromKey("args.permissiongroup.noservice"));
    // check for admin
    Subject owner = getSubject(ownerGroup, src, permissionService, messageProvider);
    Subject admin = getSubject(adminGroup, src, permissionService, messageProvider);
    Subject mod = getSubject(modGroup, src, permissionService, messageProvider);
    Subject defaults = getSubject(defaultGroup, src, permissionService, messageProvider);
    src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.inherit", adminGroup, ownerGroup));
    owner.getSubjectData().addParent(ImmutableSet.of(), admin.asSubjectReference());
    src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.inherit", modGroup, adminGroup));
    admin.getSubjectData().addParent(ImmutableSet.of(), mod.asSubjectReference());
    src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.inherit", defaultGroup, modGroup));
    mod.getSubjectData().addParent(ImmutableSet.of(), defaults.asSubjectReference());
    src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.perms"));
    setupPerms(src, owner, SuggestedLevel.OWNER, false, false);
    setupPerms(src, admin, SuggestedLevel.ADMIN, false, false);
    setupPerms(src, mod, SuggestedLevel.MOD, false, false);
    setupPerms(src, defaults, SuggestedLevel.USER, false, false);
    src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.completegroups"));
}
Also used : PermissionService(org.spongepowered.api.service.permission.PermissionService) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Subject(org.spongepowered.api.service.permission.Subject)

Example 5 with MessageProvider

use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.

the class SetupPermissionsCommand method setupPerms.

private void setupPerms(CommandSource src, Subject group, SuggestedLevel level, boolean reset, boolean inherit) throws Exception {
    if (inherit && level.getLowerLevel() != null) {
        setupPerms(src, group, level.getLowerLevel(), reset, inherit);
    }
    Set<Context> globalContext = Sets.newHashSet();
    SubjectData data = group.getSubjectData();
    Set<String> definedPermissions = data.getPermissions(ImmutableSet.of()).keySet();
    Logger logger = Nucleus.getNucleus().getLogger();
    MessageProvider messageProvider = Nucleus.getNucleus().getMessageProvider();
    // Register all the permissions, but only those that have yet to be assigned.
    permissionRegistry.getPermissions().entrySet().stream().filter(x -> x.getValue().level == level).filter(x -> reset || !definedPermissions.contains(x.getKey())).forEach(x -> {
        logger.info(messageProvider.getMessageWithFormat("command.nucleus.permission.added", x.getKey(), group.getIdentifier()));
        data.setPermission(globalContext, x.getKey(), Tristate.TRUE);
    });
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.permission.complete", level.toString().toLowerCase(), group.getIdentifier()));
}
Also used : CommandContext(org.spongepowered.api.command.args.CommandContext) Context(org.spongepowered.api.service.context.Context) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) ArgumentParseException(org.spongepowered.api.command.args.ArgumentParseException) CommandArgs(org.spongepowered.api.command.args.CommandArgs) GenericArguments(org.spongepowered.api.command.args.GenericArguments) PermissionService(org.spongepowered.api.service.permission.PermissionService) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) Subject(org.spongepowered.api.service.permission.Subject) Nullable(javax.annotation.Nullable) NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) SubjectData(org.spongepowered.api.service.permission.SubjectData) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) CommandSource(org.spongepowered.api.command.CommandSource) Context(org.spongepowered.api.service.context.Context) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Tristate(org.spongepowered.api.util.Tristate) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Optional(java.util.Optional) Collections(java.util.Collections) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) SubjectData(org.spongepowered.api.service.permission.SubjectData) Logger(org.slf4j.Logger)

Aggregations

MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)33 Text (org.spongepowered.api.text.Text)18 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)10 List (java.util.List)10 Util (io.github.nucleuspowered.nucleus.Util)8 Collectors (java.util.stream.Collectors)8 CommandSource (org.spongepowered.api.command.CommandSource)8 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)7 Nullable (javax.annotation.Nullable)7 CommandResult (org.spongepowered.api.command.CommandResult)7 CommandContext (org.spongepowered.api.command.args.CommandContext)7 NonnullByDefault (org.spongepowered.api.util.annotation.NonnullByDefault)7 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)6 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)6 Optional (java.util.Optional)6 Sponge (org.spongepowered.api.Sponge)6 User (org.spongepowered.api.entity.living.player.User)6 TextActions (org.spongepowered.api.text.action.TextActions)6 RunAsync (io.github.nucleuspowered.nucleus.internal.annotations.RunAsync)5 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)5