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");
}
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();
}
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));
}
};
}
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"));
}
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()));
}
Aggregations