use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class CoreListener method onGameReload.
@Listener
public void onGameReload(final GameReloadEvent event) {
CommandSource requester = event.getCause().first(CommandSource.class).orElse(Sponge.getServer().getConsole());
if (plugin.reload()) {
requester.sendMessage(Text.of(TextColors.YELLOW, "[Nucleus] ", plugin.getMessageProvider().getTextMessageWithFormat("command.reload.one")));
requester.sendMessage(Text.of(TextColors.YELLOW, "[Nucleus] ", plugin.getMessageProvider().getTextMessageWithFormat("command.reload.two")));
} else {
requester.sendMessage(Text.of(TextColors.RED, "[Nucleus] ", plugin.getMessageProvider().getTextMessageWithFormat("command.reload.errorone")));
}
this.warnOnWildcard = this.plugin.getInternalServiceManager().getServiceUnchecked(CoreConfigAdapter.class).getNodeOrDefault().isCheckForWildcard();
}
use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class ListHomeCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
// args.getOne(subject);
User user = this.getUserFromArgs(User.class, src, player, args);
Text header;
boolean other = src instanceof User && !((User) src).getUniqueId().equals(user.getUniqueId());
if (other && user.hasPermission(this.exempt)) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.listhome.exempt"));
}
List<Home> msw = homeHandler.getHomes(user);
if (msw.isEmpty()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.home.nohomes"));
return CommandResult.empty();
}
if (other) {
header = plugin.getMessageProvider().getTextMessageWithFormat("home.title.name", user.getName());
} else {
header = plugin.getMessageProvider().getTextMessageWithFormat("home.title.normal");
}
List<Text> lt = msw.stream().sorted(Comparator.comparing(NamedLocation::getName)).map(x -> {
Optional<Location<World>> olw = x.getLocation();
if (!olw.isPresent()) {
return Text.builder().append(Text.builder(x.getName()).color(TextColors.RED).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("home.warphoverinvalid", x.getName()))).build()).build();
} else {
final Location<World> lw = olw.get();
return Text.builder().append(Text.builder(x.getName()).color(TextColors.GREEN).style(TextStyles.UNDERLINE).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("home.warphover", x.getName()))).onClick(TextActions.runCommand(other ? "/homeother " + user.getName() + " " + x.getName() : "/home " + x.getName())).build()).append(plugin.getMessageProvider().getTextMessageWithFormat("home.location", lw.getExtent().getName(), String.valueOf(lw.getBlockX()), String.valueOf(lw.getBlockY()), String.valueOf(lw.getBlockZ()))).build();
}
}).collect(Collectors.toList());
PaginationList.Builder pb = Util.getPaginationBuilder(src).title(Text.of(TextColors.YELLOW, header)).padding(Text.of(TextColors.GREEN, "-")).contents(lt);
pb.sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class HatCommand method executeWithPlayer.
@Override
protected CommandResult executeWithPlayer(CommandSource player, Player pl, CommandContext args, boolean isSelf) throws Exception {
Optional<ItemStack> helmetOptional = pl.getHelmet();
ItemStack stack = pl.getItemInHand(HandTypes.MAIN_HAND).orElseThrow(() -> ReturnMessageException.fromKey("command.generalerror.handempty"));
ItemStack hand = stack.copy();
hand.setQuantity(1);
pl.setHelmet(hand);
Text itemName = hand.get(Keys.DISPLAY_NAME).orElseGet(() -> Text.of(stack));
GameMode gameMode = pl.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET);
if (gameMode != GameModes.CREATIVE) {
if (stack.getQuantity() > 1) {
stack.setQuantity(stack.getQuantity() - 1);
pl.setItemInHand(HandTypes.MAIN_HAND, stack);
} else {
pl.setItemInHand(HandTypes.MAIN_HAND, null);
}
}
// If the old item can't be placed back in the subject inventory, drop the item.
helmetOptional.ifPresent(itemStack -> Util.getStandardInventory(pl).offer(itemStack.copy()).getRejectedItems().forEach(x -> Util.dropItemOnFloorAtLocation(x, pl.getWorld(), pl.getLocation().getPosition())));
if (!isSelf) {
player.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.hat.success", plugin.getNameUtil().getName(pl), itemName));
}
pl.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.hat.successself", itemName));
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class MessageHandler method sendMessage.
@Override
public boolean sendMessage(CommandSource sender, CommandSource receiver, String message) {
// Message is about to be sent. Send the event out. If canceled, then that's that.
boolean isBlocked = false;
boolean isCancelled = Sponge.getEventManager().post(new InternalNucleusMessageEvent(sender, receiver, message));
if (isCancelled) {
sender.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("message.cancel"));
// Only continue to show Social Spy messages if the subject is muted.
if (!messageConfig.isShowMessagesInSocialSpyWhileMuted()) {
return false;
}
}
// What about msgtoggle?
if (receiver instanceof Player && !sender.hasPermission(this.msgToggleBypass) && ucl.get((Player) receiver).map(x -> !x.get(MessageUserDataModule.class).isMsgToggle()).orElse(false)) {
isCancelled = true;
isBlocked = true;
sender.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithTextFormat("message.blocked", Nucleus.getNucleus().getNameUtil().getName((Player) receiver)));
if (!messageConfig.isShowMessagesInSocialSpyWhileMuted()) {
return false;
}
}
// Social Spies.
final UUID uuidSender = getUUID(sender);
final UUID uuidReceiver = getUUID(receiver);
final Map<String, Object> variables = Maps.newHashMap();
variables.put("from", sender);
variables.put("to", receiver);
// Create the tokens.
Map<String, Function<CommandSource, Optional<Text>>> tokens = Maps.newHashMap();
tokens.put("from", cs -> getNameFromCommandSource(sender, textParsingUtils::addCommandToName));
tokens.put("to", cs -> getNameFromCommandSource(receiver, textParsingUtils::addCommandToName));
tokens.put("fromdisplay", cs -> getNameFromCommandSource(sender, textParsingUtils::addCommandToDisplayName));
tokens.put("todisplay", cs -> getNameFromCommandSource(receiver, textParsingUtils::addCommandToDisplayName));
Text tm = useMessage(sender, message);
if (!isCancelled) {
sender.sendMessage(constructMessage(sender, tm, messageConfig.getMessageSenderPrefix(), tokens, variables));
receiver.sendMessage(constructMessage(sender, tm, messageConfig.getMessageReceiverPrefix(), tokens, variables));
}
NucleusTextTemplateImpl prefix = messageConfig.getMessageSocialSpyPrefix();
if (isBlocked) {
prefix = NucleusTextTemplateFactory.createFromAmpersandString(messageConfig.getBlockedTag() + prefix.getRepresentation());
}
if (isCancelled) {
prefix = NucleusTextTemplateFactory.createFromAmpersandString(messageConfig.getMutedTag() + prefix.getRepresentation());
}
MessageConfig.Targets targets = messageConfig.spyOn();
if (sender instanceof Player && targets.isPlayer() || sender instanceof ConsoleSource && targets.isCustom() || targets.isCustom()) {
Set<CommandSource> lm = onlinePlayersCanSpyOn(!uuidSender.equals(Util.consoleFakeUUID) && !uuidReceiver.equals(Util.consoleFakeUUID), sender, receiver);
MessageChannel mc = MessageChannel.fixed(lm);
if (!mc.getMembers().isEmpty()) {
mc.send(constructMessage(sender, tm, prefix, tokens, variables));
}
}
// Add the UUIDs to the reply list - the receiver will now reply to the sender.
if (!isCancelled) {
messagesReceived.put(uuidReceiver, uuidSender);
}
return !isCancelled;
}
use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class MessageHandler method getLastMessageFrom.
public Optional<CommandSource> getLastMessageFrom(UUID from) {
Preconditions.checkNotNull(from);
UUID to = messagesReceived.get(from);
if (to == null) {
return Optional.empty();
}
if (to.equals(Util.consoleFakeUUID)) {
return Optional.of(Sponge.getServer().getConsole());
}
if (targets.containsKey(to)) {
Optional<? extends CommandSource> om = targets.get(to).get();
if (om.isPresent()) {
return om.map(x -> x);
}
}
return Sponge.getServer().getOnlinePlayers().stream().filter(x -> x.getUniqueId().equals(to)).map(y -> (CommandSource) y).findFirst();
}
Aggregations