use of io.github.nucleuspowered.nucleus.modules.staffchat.StaffChatMessageChannel in project Nucleus by NucleusPowered.
the class StaffChatCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Optional<String> toSend = args.getOne(message);
if (toSend.isPresent()) {
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
frame.addContext(EventContexts.SHOULD_FORMAT_CHANNEL, StaffChatMessageChannel.getInstance().formatMessages());
if (src instanceof Player) {
Player pl = (Player) src;
frame.pushCause(pl);
frame.addContext(EventContextKeys.PLAYER_SIMULATED, pl.getProfile());
MessageChannel mc = pl.getMessageChannel();
pl.setMessageChannel(StaffChatMessageChannel.getInstance());
pl.simulateChat(TextParsingUtils.addUrls(toSend.get()), Sponge.getCauseStackManager().getCurrentCause());
pl.setMessageChannel(mc);
} else {
StaffChatMessageChannel.getInstance().send(src, TextParsingUtils.addUrls(toSend.get()), ChatTypes.CHAT);
}
return CommandResult.success();
}
}
if (!(src instanceof Player)) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.staffchat.consoletoggle"));
}
Player player = (Player) src;
StaffChatTransientModule s = plugin.getUserDataManager().get(player).map(y -> y.getTransient(StaffChatTransientModule.class)).orElseGet(StaffChatTransientModule::new);
boolean result = !(src.getMessageChannel() instanceof StaffChatMessageChannel);
if (result) {
s.setPreviousMessageChannel(player.getMessageChannel());
src.setMessageChannel(StaffChatMessageChannel.getInstance());
} else {
src.setMessageChannel(s.getPreviousMessageChannel().orElse(MessageChannel.TO_ALL));
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.staffchat." + (result ? "on" : "off")));
return CommandResult.success();
}
Aggregations