use of io.github.nucleuspowered.nucleus.util.PermissionMessageChannel in project Nucleus by NucleusPowered.
the class MuteListener method onChat.
private void onChat(MessageChannelEvent.Chat event, Player player) {
boolean cancel = false;
Optional<MuteData> omd = Util.testForEndTimestamp(handler.getPlayerMuteData(player), () -> handler.unmutePlayer(player));
if (omd.isPresent()) {
this.handler.onMute(omd.get(), player);
MessageChannel.TO_CONSOLE.send(Text.builder().append(Text.of(player.getName() + " (")).append(plugin.getMessageProvider().getTextMessageWithFormat("standard.muted")).append(Text.of("): ")).append(event.getRawMessage()).build());
cancel = true;
}
if (cancelOnGlobalMute(player, false)) {
cancel = true;
}
if (cancel) {
if (this.muteConfig.isShowMutedChat()) {
// Send it to admins only.
String m = this.muteConfig.getCancelledTag();
if (!m.isEmpty()) {
event.getFormatter().setHeader(Text.join(TextSerializers.FORMATTING_CODE.deserialize(m), event.getFormatter().getHeader().toText()));
}
new PermissionMessageChannel(MuteCommand.getMutedChatPermission()).send(player, event.getMessage(), ChatTypes.SYSTEM);
}
event.setCancelled(true);
}
}
use of io.github.nucleuspowered.nucleus.util.PermissionMessageChannel in project Nucleus by NucleusPowered.
the class NoteCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
User user = args.<User>getOne(playerKey).get();
String note = args.<String>getOne(noteKey).get();
UUID noter = Util.consoleFakeUUID;
if (src instanceof Player) {
noter = ((Player) src).getUniqueId();
}
NoteData noteData = new NoteData(Instant.now(), noter, note);
if (noteHandler.addNote(user, noteData)) {
MutableMessageChannel messageChannel = new PermissionMessageChannel(notifyPermission).asMutable();
messageChannel.addMember(src);
messageChannel.send(plugin.getMessageProvider().getTextMessageWithFormat("command.note.success", src.getName(), noteData.getNote(), user.getName()));
return CommandResult.success();
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warn.fail", user.getName()));
return CommandResult.empty();
}
use of io.github.nucleuspowered.nucleus.util.PermissionMessageChannel in project Nucleus by NucleusPowered.
the class HelpOpCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
String message = args.<String>getOne(messageKey).get();
// that's that.
if (Sponge.getEventManager().post(new InternalNucleusHelpOpEvent(src, message))) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("message.cancel"));
return CommandResult.empty();
}
Text prefix = messageConfig.getHelpOpPrefix().getForCommandSource(src);
new PermissionMessageChannel(permissions.getPermissionWithSuffix("receive")).send(src, TextParsingUtils.joinTextsWithColoursFlowing(prefix, Text.of(message)));
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.helpop.success"));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.util.PermissionMessageChannel in project Nucleus by NucleusPowered.
the class BanCommand method executeBan.
private CommandResult executeBan(CommandSource src, GameProfile u, String r) {
BanService service = Sponge.getServiceManager().provideUnchecked(BanService.class);
UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
User user = uss.get(u).get();
if (!user.isOnline() && !permissions.testSuffix(src, "offline")) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.offline.noperms"));
return CommandResult.empty();
}
if (service.isBanned(u)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.alreadyset", u.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown"))));
return CommandResult.empty();
}
// Create the ban.
Ban bp = Ban.builder().type(BanTypes.PROFILE).profile(u).source(src).reason(TextSerializers.FORMATTING_CODE.deserialize(r)).build();
service.addBan(bp);
// Get the permission, "quickstart.ban.notify"
MutableMessageChannel send = new PermissionMessageChannel(notifyPermission).asMutable();
send.addMember(src);
send.send(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.applied", u.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown")), src.getName()));
send.send(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", r));
if (Sponge.getServer().getPlayer(u.getUniqueId()).isPresent()) {
Sponge.getServer().getPlayer(u.getUniqueId()).get().kick(TextSerializers.FORMATTING_CODE.deserialize(r));
}
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.util.PermissionMessageChannel in project Nucleus by NucleusPowered.
the class JailCommand method onJail.
private CommandResult onJail(CommandSource src, CommandContext args, User user) throws ReturnMessageException {
Optional<LocationData> owl = args.getOne(jailKey);
if (!owl.isPresent()) {
throw ReturnMessageException.fromKey("command.jail.jail.nojail");
}
// This might not be there.
Optional<Long> duration = args.getOne(durationKey);
String reason = args.<String>getOne(reasonKey).orElse(plugin.getMessageProvider().getMessageWithFormat("command.jail.reason"));
JailData jd;
Text message;
Text messageTo;
if (duration.isPresent()) {
if (user.isOnline()) {
jd = new JailData(Util.getUUID(src), owl.get().getName(), reason, user.getPlayer().get().getLocation(), Instant.now().plusSeconds(duration.get()));
} else {
jd = new JailData(Util.getUUID(src), owl.get().getName(), reason, null, Duration.of(duration.get(), ChronoUnit.SECONDS));
}
message = plugin.getMessageProvider().getTextMessageWithFormat("command.checkjail.jailedfor", user.getName(), jd.getJailName(), src.getName(), Util.getTimeStringFromSeconds(duration.get()));
messageTo = plugin.getMessageProvider().getTextMessageWithFormat("command.jail.jailedfor", owl.get().getName(), src.getName(), Util.getTimeStringFromSeconds(duration.get()));
} else {
jd = new JailData(Util.getUUID(src), owl.get().getName(), reason, user.getPlayer().map(Locatable::getLocation).orElse(null));
message = plugin.getMessageProvider().getTextMessageWithFormat("command.checkjail.jailedperm", user.getName(), owl.get().getName(), src.getName());
messageTo = plugin.getMessageProvider().getTextMessageWithFormat("command.jail.jailedperm", owl.get().getName(), src.getName());
}
if (handler.jailPlayer(user, jd)) {
MutableMessageChannel mc = new PermissionMessageChannel(permissions.getPermissionWithSuffix("notify")).asMutable();
mc.addMember(src);
mc.send(message);
mc.send(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", reason));
user.getPlayer().ifPresent(x -> {
x.sendMessage(messageTo);
x.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", reason));
});
return CommandResult.success();
}
throw ReturnMessageException.fromKey("command.jail.error");
}
Aggregations