use of org.spongepowered.api.text.channel.MutableMessageChannel in project Nucleus by NucleusPowered.
the class TempBanCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
User u = args.<User>getOne(user).get();
Long time = args.<Long>getOne(duration).get();
String reason = args.<String>getOne(reasonKey).orElse(plugin.getMessageProvider().getMessageWithFormat("ban.defaultreason"));
if (permissions.testSuffix(u, "exempt.target", src, false)) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.tempban.exempt", u.getName()));
}
if (!u.isOnline() && !permissions.testSuffix(src, "offline")) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.tempban.offline.noperms"));
}
if (time > banConfig.getMaximumTempBanLength() && banConfig.getMaximumTempBanLength() != -1 && !permissions.testSuffix(src, "exempt.length")) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tempban.length.toolong", Util.getTimeStringFromSeconds(this.banConfig.getMaximumTempBanLength())));
return CommandResult.success();
}
BanService service = Sponge.getServiceManager().provideUnchecked(BanService.class);
if (service.isBanned(u.getProfile())) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.alreadyset", u.getName()));
return CommandResult.empty();
}
// Expiration date
Instant date = Instant.now().plus(time, ChronoUnit.SECONDS);
// Create the ban.
Ban bp = Ban.builder().type(BanTypes.PROFILE).profile(u.getProfile()).source(src).expirationDate(date).reason(TextSerializers.FORMATTING_CODE.deserialize(reason)).build();
service.addBan(bp);
MutableMessageChannel send = new PermissionMessageChannel(BanCommand.notifyPermission).asMutable();
send.addMember(src);
send.send(plugin.getMessageProvider().getTextMessageWithFormat("command.tempban.applied", u.getName(), Util.getTimeStringFromSeconds(time), src.getName()));
send.send(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", reason));
if (Sponge.getServer().getPlayer(u.getUniqueId()).isPresent()) {
Sponge.getServer().getPlayer(u.getUniqueId()).get().kick(TextSerializers.FORMATTING_CODE.deserialize(reason));
}
return CommandResult.success();
}
use of org.spongepowered.api.text.channel.MutableMessageChannel in project Nucleus by NucleusPowered.
the class UnbanCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
GameProfile gp;
if (args.hasAny(key)) {
gp = args.<GameProfile>getOne(key).get();
} else {
gp = args.<GameProfile>getOne(key2).get();
}
BanService service = Sponge.getServiceManager().provideUnchecked(BanService.class);
Optional<Ban.Profile> obp = service.getBanFor(gp);
if (!obp.isPresent()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checkban.notset", gp.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown"))));
return CommandResult.empty();
}
service.removeBan(obp.get());
MutableMessageChannel notify = new PermissionMessageChannel(BanCommand.notifyPermission).asMutable();
notify.addMember(src);
notify.send(plugin.getMessageProvider().getTextMessageWithFormat("command.unban.success", obp.get().getProfile().getName().orElse("standard.unknown"), src.getName()));
return CommandResult.success();
}
use of org.spongepowered.api.text.channel.MutableMessageChannel in project Nucleus by NucleusPowered.
the class MuteCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
// Get the user.
User user = args.<User>getOne(playerArgument).get();
Optional<Long> time = args.getOne(timespanArgument);
Optional<MuteData> omd = handler.getPlayerMuteData(user);
Optional<String> reas = args.getOne(reason);
if (permissions.testSuffix(user, "exempt.target", src, false)) {
throw ReturnMessageException.fromKey("command.mute.exempt", user.getName());
}
// No time, no reason, but is muted, unmute
if (omd.isPresent() && !time.isPresent() && !reas.isPresent()) {
if (!this.requireUnmutePermission || this.permissions.testSuffix(src, "unmute")) {
// Unmute.
this.handler.unmutePlayer(user, CauseStackHelper.createCause(src), false);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.unmute.success", user.getName(), src.getName()));
return CommandResult.success();
}
throw ReturnMessageException.fromKey("command.unmute.perm");
}
// Do we have a reason?
String rs = reas.orElse(plugin.getMessageProvider().getMessageWithFormat("command.mute.defaultreason"));
UUID ua = Util.consoleFakeUUID;
if (src instanceof Player) {
ua = ((Player) src).getUniqueId();
}
if (this.maxMute > 0 && time.orElse(Long.MAX_VALUE) > this.maxMute && !permissions.testSuffix(src, "exempt.length")) {
throw ReturnMessageException.fromKey("command.mute.length.toolong", Util.getTimeStringFromSeconds(this.maxMute));
}
MuteData data;
if (time.isPresent()) {
if (!user.isOnline()) {
data = new MuteData(ua, rs, Duration.ofSeconds(time.get()));
} else {
data = new MuteData(ua, rs, Instant.now().plus(time.get(), ChronoUnit.SECONDS));
}
} else {
data = new MuteData(ua, rs);
}
if (handler.mutePlayer(user, data)) {
// Success.
MutableMessageChannel mc = new PermissionMessageChannel(permissions.getPermissionWithSuffix("notify")).asMutable();
mc.addMember(src);
if (time.isPresent()) {
timedMute(src, user, data, time.get(), mc);
} else {
permMute(src, user, data, mc);
}
return CommandResult.success();
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.mute.fail", user.getName()));
return CommandResult.empty();
}
use of org.spongepowered.api.text.channel.MutableMessageChannel in project Nucleus by NucleusPowered.
the class VoiceCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
if (!muteHandler.isGlobalMuteEnabled()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.globaloff"));
return CommandResult.empty();
}
Player pl = args.<Player>getOne(player).get();
if (permissions.testSuffix(pl, "auto")) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.autovoice", pl.getName()));
return CommandResult.empty();
}
boolean turnOn = args.<Boolean>getOne(on).orElse(!muteHandler.isVoiced(pl.getUniqueId()));
UUID voice = pl.getUniqueId();
if (turnOn == muteHandler.isVoiced(voice)) {
if (turnOn) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.alreadyvoiced", pl.getName()));
} else {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.alreadynotvoiced", pl.getName()));
}
return CommandResult.empty();
}
MutableMessageChannel mmc = new PermissionMessageChannel(permissions.getPermissionWithSuffix("notify")).asMutable();
mmc.addMember(src);
if (turnOn) {
muteHandler.addVoice(pl.getUniqueId());
mmc.send(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.voiced.source", pl.getName()));
pl.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.voiced.target"));
} else {
muteHandler.removeVoice(pl.getUniqueId());
mmc.send(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.voiced.source", pl.getName()));
pl.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.voiced.target"));
}
return CommandResult.success();
}
use of org.spongepowered.api.text.channel.MutableMessageChannel 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();
}
Aggregations