use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class MessageModule method performEnableTasks.
@Override
public void performEnableTasks() {
createSeenModule(SocialSpyCommand.class, (cs, user) -> {
MessageHandler handler = Nucleus.getNucleus().getInternalServiceManager().getServiceUnchecked(MessageHandler.class);
boolean socialSpy = handler.isSocialSpy(user);
boolean msgToggle = Nucleus.getNucleus().getUserDataManager().get(user).map(y -> y.get(MessageUserDataModule.class).isMsgToggle()).orElse(true);
MessageProvider mp = plugin.getMessageProvider();
List<Text> lt = Lists.newArrayList(mp.getTextMessageWithFormat("seen.socialspy", mp.getMessageWithFormat("standard.yesno." + Boolean.toString(socialSpy).toLowerCase())));
getConfigAdapter().ifPresent(x -> lt.add(mp.getTextMessageWithFormat("seen.socialspylevel", String.valueOf(Util.getPositiveIntOptionFromSubject(user, MessageHandler.socialSpyOption).orElse(0)))));
lt.add(mp.getTextMessageWithFormat("seen.msgtoggle", mp.getMessageWithFormat("standard.yesno." + Boolean.toString(msgToggle).toLowerCase())));
return lt;
});
}
use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class SpawnMobCommand method executeWithPlayer.
@Override
public CommandResult executeWithPlayer(CommandSource src, Player pl, CommandContext args, boolean isSelf) throws Exception {
// Get the amount
int amount = args.<Integer>getOne(amountKey).get();
EntityType et = args.<EntityType>getOne(mobTypeKey).get();
if (!Living.class.isAssignableFrom(et.getEntityClass())) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.livingonly", et.getTranslation().get()));
}
String id = et.getId().toLowerCase();
if (this.mobConfig.isPerMobPermission() && !permissions.testSuffix(src, "mob." + id.replace(":", "."))) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.mobnoperm", et.getTranslation().get()));
}
Optional<BlockSpawnsConfig> config = this.mobConfig.getBlockSpawnsConfigForWorld(pl.getWorld());
if (config.isPresent() && (config.get().isBlockVanillaMobs() && id.startsWith("minecraft:") || config.get().getIdsToBlock().contains(id))) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.blockedinconfig", et.getTranslation().get()));
}
Location<World> loc = pl.getLocation();
World w = loc.getExtent();
MessageProvider mp = plugin.getMessageProvider();
// Count the number of entities spawned.
int i = 0;
Entity entityone = null;
do {
Entity e = w.createEntity(et, loc.getPosition());
if (!w.spawnEntity(e)) {
throw ReturnMessageException.fromKeyText("command.spawnmob.fail", Text.of(e));
}
if (entityone == null) {
entityone = e;
}
i++;
} while (i < Math.min(amount, this.mobConfig.getMaxMobsToSpawn()));
if (amount > this.mobConfig.getMaxMobsToSpawn()) {
src.sendMessage(mp.getTextMessageWithFormat("command.spawnmob.limit", String.valueOf(this.mobConfig.getMaxMobsToSpawn())));
}
if (i == 0) {
throw ReturnMessageException.fromKey("command.spawnmob.fail", et.getTranslation().get());
}
if (i == 1) {
src.sendMessage(mp.getTextMessageWithTextFormat("command.spawnmob.success.singular", Text.of(i), Text.of(entityone)));
} else {
src.sendMessage(mp.getTextMessageWithTextFormat("command.spawnmob.success.plural", Text.of(i), Text.of(entityone)));
}
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class SeenCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
User user = args.<User>getOne(uuid).isPresent() ? args.<User>getOne(uuid).get() : args.<User>getOne(playerKey).get();
if (user.isOnline()) {
// Get the player in case the User is displaying the wrong name.
user = user.getPlayer().get();
}
ModularUserService iqsu = Nucleus.getNucleus().getUserDataManager().getUnchecked(user);
CoreUserDataModule coreUserDataModule = iqsu.get(CoreUserDataModule.class);
List<Text> messages = new ArrayList<>();
final MessageProvider messageProvider = plugin.getMessageProvider();
// Everyone gets the last online time.
if (user.isOnline()) {
messages.add(messageProvider.getTextMessageWithFormat("command.seen.iscurrently.online", user.getName()));
coreUserDataModule.getLastLogin().ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.loggedon", Util.getTimeToNow(x))));
} else {
messages.add(messageProvider.getTextMessageWithFormat("command.seen.iscurrently.offline", user.getName()));
coreUserDataModule.getLastLogout().ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.loggedoff", Util.getTimeToNow(x))));
}
messages.add(messageProvider.getTextMessageWithFormat("command.seen.displayname", TextSerializers.FORMATTING_CODE.serialize(plugin.getNameUtil().getName(user))));
if (permissions.testSuffix(src, EXTENDED_SUFFIX)) {
messages.add(notEmpty);
messages.add(messageProvider.getTextMessageWithFormat("command.seen.uuid", user.getUniqueId().toString()));
if (user.isOnline()) {
Player pl = user.getPlayer().get();
messages.add(messageProvider.getTextMessageWithFormat("command.seen.ipaddress", pl.getConnection().getAddress().getAddress().toString()));
messages.add(messageProvider.getTextMessageWithFormat("command.seen.firstplayed", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(src.getLocale()).withZone(ZoneId.systemDefault()).format(pl.getJoinData().firstPlayed().get())));
messages.add(messageProvider.getTextMessageWithFormat("command.seen.speed.walk", String.valueOf(Math.round(pl.get(Keys.WALKING_SPEED).orElse(0.1d) * SpeedCommand.multiplier))));
messages.add(messageProvider.getTextMessageWithFormat("command.seen.speed.fly", String.valueOf(Math.round(pl.get(Keys.FLYING_SPEED).orElse(0.05d) * SpeedCommand.multiplier))));
messages.add(getLocationString("command.seen.currentlocation", pl.getLocation(), src));
messages.add(messageProvider.getTextMessageWithFormat("command.seen.canfly", getYesNo(pl.get(Keys.CAN_FLY).orElse(false))));
messages.add(messageProvider.getTextMessageWithFormat("command.seen.isflying", getYesNo(pl.get(Keys.IS_FLYING).orElse(false))));
messages.add(messageProvider.getTextMessageWithFormat("command.seen.gamemode", pl.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL).getName()));
} else {
coreUserDataModule.getLastIp().ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.lastipaddress", x)));
Optional<Instant> i = user.get(Keys.FIRST_DATE_PLAYED);
if (!i.isPresent()) {
i = coreUserDataModule.getFirstJoin();
}
i.ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.firstplayed", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(src.getLocale()).withZone(ZoneId.systemDefault()).format(x))));
Optional<Location<World>> olw = coreUserDataModule.getLogoutLocation();
olw.ifPresent(worldLocation -> messages.add(getLocationString("command.seen.lastlocation", worldLocation, src)));
user.get(JoinData.class).ifPresent(x -> {
Optional<Instant> oi = x.firstPlayed().getDirect();
oi.ifPresent(instant -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.firstplayed", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(src.getLocale()).withZone(ZoneId.systemDefault()).format(instant))));
});
}
}
// Add the extra module information.
messages.addAll(seenHandler.buildInformation(src, user));
PaginationService ps = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
ps.builder().contents(messages).padding(Text.of(TextColors.GREEN, "-")).title(messageProvider.getTextMessageWithFormat("command.seen.title", user.getName())).sendTo(src);
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class WorthCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
CatalogType type = getCatalogTypeFromHandOrArgs(src, item, args);
String id = type.getId();
// Get the item from the system.
ItemDataNode node = itemDataService.getDataForItem(id);
// Get the current item worth.
MessageProvider provider = plugin.getMessageProvider();
if (!econHelper.economyServiceExists()) {
src.sendMessage(provider.getTextMessageWithFormat("command.setworth.noeconservice"));
}
double buyPrice = node.getServerBuyPrice();
double sellPrice = node.getServerSellPrice();
StringBuilder stringBuilder = new StringBuilder();
if (buyPrice >= 0) {
stringBuilder.append(provider.getMessageWithFormat("command.worth.buy", econHelper.getCurrencySymbol(node.getServerBuyPrice())));
}
if (sellPrice >= 0) {
if (stringBuilder.length() > 0) {
stringBuilder.append(" - ");
}
stringBuilder.append(provider.getMessageWithFormat("command.worth.sell", econHelper.getCurrencySymbol(node.getServerSellPrice())));
}
if (stringBuilder.length() == 0) {
src.sendMessage(provider.getTextMessageWithFormat("command.worth.nothing", Util.getTranslatableIfPresentOnCatalogType(type)));
} else {
src.sendMessage(provider.getTextMessageWithFormat("command.worth.something", Util.getTranslatableIfPresentOnCatalogType(type), stringBuilder.toString()));
}
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class ServerListCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
// Display current information
if (args.hasAny("m")) {
onMessage(src, slc.getMessages(), "command.serverlist.head.messages");
return CommandResult.success();
} else if (args.hasAny("w")) {
onMessage(src, slc.getWhitelist(), "command.serverlist.head.whitelist");
return CommandResult.success();
}
MessageProvider messageProvider = plugin.getMessageProvider();
if (slc.isModifyServerList()) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.modify.true"));
if (!slc.getMessages().isEmpty()) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.messages.click").toBuilder().onClick(TextActions.runCommand("/nucleus:serverlist -m")).toText());
}
if (!slc.getWhitelist().isEmpty()) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.whitelistmessages.click").toBuilder().onClick(TextActions.runCommand("/nucleus:serverlist -w")).toText());
}
} else if (slc.getModifyServerList() == ServerListConfig.ServerListSelection.WHITELIST) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.modify.whitelist"));
if (!slc.getWhitelist().isEmpty()) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.whitelistmessages.click").toBuilder().onClick(TextActions.runCommand("/nucleus:serverlist -w")).toText());
}
} else {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.modify.false"));
}
ServerListGeneralDataModule ss = plugin.getGeneralService().get(ServerListGeneralDataModule.class);
ss.getMessage().ifPresent(t -> {
src.sendMessage(Util.SPACE);
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.tempheader"));
src.sendMessage(t);
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.message.expiry", Util.getTimeToNow(ss.getExpiry().get())));
});
if (slc.isHidePlayerCount()) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.hideplayers"));
} else if (slc.isHideVanishedPlayers()) {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.hidevanished"));
}
return CommandResult.success();
}
Aggregations