use of org.spongepowered.api.text.channel.MessageChannel in project Nucleus by NucleusPowered.
the class KickAllCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
String r = args.<String>getOne(reason).orElse(plugin.getMessageProvider().getMessageWithFormat("command.kick.defaultreason"));
Boolean f = args.<Boolean>getOne("w").orElse(false);
if (f) {
Sponge.getServer().setHasWhitelist(true);
}
// Don't kick self
Sponge.getServer().getOnlinePlayers().stream().filter(x -> !(src instanceof Player) || !((Player) src).getUniqueId().equals(x.getUniqueId())).collect(Collectors.toList()).forEach(x -> x.kick(TextSerializers.FORMATTING_CODE.deserialize(r)));
MessageChannel mc = MessageChannel.fixed(Sponge.getServer().getConsole(), src);
mc.send(plugin.getMessageProvider().getTextMessageWithFormat("command.kickall.message"));
mc.send(plugin.getMessageProvider().getTextMessageWithFormat("command.reason", r));
if (f) {
mc.send(plugin.getMessageProvider().getTextMessageWithFormat("command.kickall.whitelist"));
}
return CommandResult.success();
}
use of org.spongepowered.api.text.channel.MessageChannel in project TriggerReactor by wysohn.
the class ScriptEditManager method onChat.
@Listener
public void onChat(MessageChannelEvent.Chat e, @First Player sender) {
SpongeScriptEditorUser editorUser = new SpongeScriptEditorUser(sender);
if (editings.containsKey(editorUser)) {
e.setCancelled(true);
ScriptEditor editor = editings.get(editorUser);
if (viewingUsage.remove(editorUser)) {
editor.printScript(editorUser);
return;
}
Text message = e.getRawMessage();
String arg1 = message.toPlainSingle();
if (arg1.equals("save")) {
try {
editor.save();
} catch (IOException | ScriptException ex) {
plugin.handleException(e, ex);
} finally {
editings.remove(editorUser);
editorUser.sendMessage("&aSaved!");
}
} else if (arg1.equals("exit")) {
if (exitDoublecheck.remove(editorUser)) {
editings.remove(editorUser);
editorUser.sendMessage("&7Done");
} else {
exitDoublecheck.add(editorUser);
editorUser.sendMessage("&6Are you sure to exit? &cUnsaved data will be all discared! " + "&dType &6exit &done more time to confirm.");
}
return;
} else if (arg1.equals("il")) {
editor.insertNewLine();
} else if (arg1.equals("dl")) {
editor.deleteLine();
} else if (arg1.length() > 0 && arg1.charAt(0) == 'u') {
String[] split = arg1.split(" ");
int lines = 1;
try {
lines = split.length > 1 ? Integer.parseInt(split[1]) : 1;
} catch (NumberFormatException ex) {
plugin.handleException(e, ex);
}
editor.up(lines);
} else if (arg1.length() > 0 && arg1.charAt(0) == 'd') {
String[] split = arg1.split(" ");
int lines = 1;
try {
lines = split.length > 1 ? Integer.parseInt(split[1]) : 1;
} catch (NumberFormatException ex) {
plugin.handleException(e, ex);
}
editor.down(lines);
} else {
if (!exitDoublecheck.remove(editorUser)) {
editor.intput(arg1.replaceAll("\\^", " "));
}
}
editor.printScript(editorUser);
} else {
MessageChannel channel = e.getOriginalChannel();
Collection<MessageReceiver> copy = new LinkedList<>();
for (Iterator<MessageReceiver> iter = channel.getMembers().iterator(); iter.hasNext(); ) {
MessageReceiver receiver = iter.next();
if (receiver instanceof Player) {
SpongeScriptEditorUser receivingUser = new SpongeScriptEditorUser((Player) receiver);
if (!editings.containsKey(receivingUser))
copy.add(receiver);
}
}
e.setChannel(MessageChannel.fixed(copy));
}
}
use of org.spongepowered.api.text.channel.MessageChannel in project SpongeVanilla by SpongePowered.
the class NetHandlerPlayServerMixin_Vanilla method vanilla$onProcessChatMessage.
@Inject(method = "processChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;sendMessage(Lnet/minecraft/util/text/ITextComponent;Z)V"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
private void vanilla$onProcessChatMessage(CPacketChatMessage packet, CallbackInfo ci, String s, ITextComponent component) {
ChatFormatter.formatChatComponent((TextComponentTranslation) component);
// safe cast
final Text[] message = SpongeTexts.splitChatMessage((TextComponentTranslation) component);
final MessageChannel originalChannel = ((Player) this.player).getMessageChannel();
Sponge.getCauseStackManager().pushCause(this.player);
final MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat(Sponge.getCauseStackManager().getCurrentCause(), originalChannel, Optional.of(originalChannel), new MessageEvent.MessageFormatter(message[0], message[1]), Text.of(s), false);
if (!SpongeImpl.postEvent(event) && !event.isMessageCancelled()) {
event.getChannel().ifPresent(channel -> channel.send(this.player, event.getMessage(), ChatTypes.CHAT));
} else {
ci.cancel();
}
Sponge.getCauseStackManager().popCause();
}
use of org.spongepowered.api.text.channel.MessageChannel in project SpongeCommon by SpongePowered.
the class MixinEntityPlayerMP method simulateChat.
@Override
public MessageChannelEvent.Chat simulateChat(Text message, Cause cause) {
checkNotNull(message, "message");
TextComponentTranslation component = new TextComponentTranslation("chat.type.text", SpongeTexts.toComponent(this.getDisplayNameText()), SpongeTexts.toComponent(message));
final Text[] messages = SpongeTexts.splitChatMessage(component);
final MessageChannel originalChannel = this.getMessageChannel();
final MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat(cause, originalChannel, Optional.of(originalChannel), new MessageEvent.MessageFormatter(messages[0], messages[1]), message, false);
if (!SpongeImpl.postEvent(event) && !event.isMessageCancelled()) {
event.getChannel().ifPresent(channel -> channel.send(this, event.getMessage(), ChatTypes.CHAT));
}
return event;
}
use of org.spongepowered.api.text.channel.MessageChannel in project SpongeCommon by SpongePowered.
the class MixinNetHandlerPlayServer method onDisconnectHandler.
@Redirect(method = "onDisconnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;sendMessage(Lnet/minecraft/util/text/ITextComponent;)V"))
public void onDisconnectHandler(PlayerList this$0, ITextComponent component) {
// be fired either.
if (this.player.connection == null) {
return;
}
final Player player = ((Player) this.player);
final Text message = SpongeTexts.toText(component);
final MessageChannel originalChannel = player.getMessageChannel();
Sponge.getCauseStackManager().pushCause(player);
final ClientConnectionEvent.Disconnect event = SpongeEventFactory.createClientConnectionEventDisconnect(Sponge.getCauseStackManager().getCurrentCause(), originalChannel, Optional.of(originalChannel), new MessageEvent.MessageFormatter(message), player, false);
SpongeImpl.postEvent(event);
Sponge.getCauseStackManager().popCause();
if (!event.isMessageCancelled()) {
event.getChannel().ifPresent(channel -> channel.send(player, event.getMessage()));
}
((IMixinEntityPlayerMP) this.player).getWorldBorderListener().onPlayerDisconnect();
}
Aggregations