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