本文整理汇总了Java中org.spongepowered.api.event.message.MessageChannelEvent.Chat方法的典型用法代码示例。如果您正苦于以下问题:Java MessageChannelEvent.Chat方法的具体用法?Java MessageChannelEvent.Chat怎么用?Java MessageChannelEvent.Chat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.event.message.MessageChannelEvent
的用法示例。
在下文中一共展示了MessageChannelEvent.Chat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendChat
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
private void sendChat(Player player, Text message) {
Text rawMessage = Text.of(message);
MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat(
Cause.source(player).named(NamedCause.notifier(player)).build(),
player.getMessageChannel(),
Optional.of(player.getMessageChannel()),
new MessageEvent.MessageFormatter(
Text.builder(player.getName()).build(), rawMessage
),
rawMessage,
false
);
if (!Sponge.getEventManager().post(event)) {
MessageEvent.MessageFormatter formatter = event.getFormatter();
player.getMessageChannel().send(player, chatTemplate.apply(
ImmutableMap.of(MessageEvent.PARAM_MESSAGE_HEADER, formatter.getHeader(),
MessageEvent.PARAM_MESSAGE_BODY, formatter.getBody(),
MessageEvent.PARAM_MESSAGE_FOOTER, formatter.getFooter())).build());
}
}
示例2: onMessageChannelChat
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
@Listener(order = Order.LATE)
public void onMessageChannelChat(MessageChannelEvent.Chat event) {
if (event.isCancelled()) {
return;
}
Optional<Player> playerOpt = event.getCause().first(Player.class);
if (!playerOpt.isPresent()) {
return;
}
Player player = playerOpt.get();
ClanPlayerImpl clanPlayer = ClansImpl.getInstance().getClanPlayer(player.getUniqueId());
if (clanPlayer != null && clanPlayer.getClan() != null) {
PlayerChatState chatState = clanPlayer.getChatState();
PlayerChatState tempChatState = clanPlayer.getTempChatState();
if (tempChatState == null) {
handleChat(player, clanPlayer, chatState, event);
} else {
handleChat(player, clanPlayer, tempChatState, event);
clanPlayer.setTempChatState(null);
}
}
}
示例3: sendPreTell
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
private void sendPreTell(CommandSource sender, CommandSource receiver, Text msg){
CommandSource src = sender;
if (sender instanceof ConsoleSource){
src = receiver;
}
UChat.get().getLogger().timings(UCLogger.timingType.START, "UCListener#sendPreTell()|Fire AsyncPlayerChatEvent");
MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat(
UChat.get().getVHelper().getCause(src),
src.getMessageChannel(),
Optional.of(src.getMessageChannel()),
new MessageEvent.MessageFormatter(Text.builder("<" + src.getName() + "> ")
.onShiftClick(TextActions.insertText(src.getName()))
.onClick(TextActions.suggestCommand("/msg " + src.getName()))
.build(), msg),
msg,
false);
Sponge.getEventManager().post(event);
}
示例4: onMessageChannelEventChat
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
@Listener(order = Order.LAST)
public void onMessageChannelEventChat(MessageChannelEvent.Chat event, @First Player player) {
String mode = ConfigManager.get().getConfig().getNode("mode").getString();
Text tag;
if (mode.equalsIgnoreCase("default")) {
tag = defaultTag(player);
} else if (mode.equalsIgnoreCase("advanced")) {
tag = advancedTag(player);
} else {
return;
}
MessageFormatter formatter = event.getFormatter();
Text prefix = Text.join(tag, formatter.getHeader().toText());
formatter.setHeader(TextTemplate.of(prefix));
}
示例5: onPlayerChat
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
@Listener(order = Order.LATE)
public void onPlayerChat(MessageChannelEvent.Chat e, @First Player p)
{
Nation nation = DataHandler.getNationOfPlayer(p.getUniqueId());
if (nation == null)
{
return;
}
MessageChannel chan = MessageChannel.TO_ALL;
Optional<MessageChannel> channel = e.getChannel();
if (channel.isPresent())
{
chan = channel.get();
}
if (chan.equals(MessageChannel.TO_ALL) && ConfigHandler.getNode("others", "enableNationTag").getBoolean(true))
{
e.setMessage(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "publicChatFormat").getString().replaceAll("\\{NATION\\}", nation.getTag()).replaceAll("\\{TITLE\\}", DataHandler.getCitizenTitle(p.getUniqueId()))), e.getMessage());
}
else if (chan instanceof NationMessageChannel)
{
e.setMessage(Text.of(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationChatFormat").getString().replaceAll("\\{NATION\\}", nation.getTag()).replaceAll("\\{TITLE\\}", DataHandler.getCitizenTitle(p.getUniqueId()))), TextColors.YELLOW, e.getMessage()));
DataHandler.getSpyChannel().send(p, Text.of(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationSpyChatTag").getString()), TextColors.RESET, e.getMessage()));
}
}
示例6: onPlayerWriteChat
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerWriteChat(MessageChannelEvent.Chat event, @First Player player_sponge) {
EPlayer player = this.plugin.getEServer().getEPlayer(player_sponge);
// AFK
player.updateLastActivated();
// Ignore
Collection<MessageReceiver> members = event.getChannel().orElse(event.getOriginalChannel()).getMembers();
List<MessageReceiver> list = Lists.newArrayList(members);
list.removeIf(others_sponge -> {
if(others_sponge instanceof Player) {
EPlayer others = this.plugin.getEServer().getEPlayer((Player) others_sponge);
return others.ignore(player);
}
return false;
});
if (list.size() != members.size()) {
event.setChannel(MessageChannel.fixed(list));
}
}
示例7: onPlayerChat
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerChat(MessageChannelEvent.Chat event) {
String rawText = event.getRawMessage().toPlain();
if (rawText.matches("\\./.*")) {
// Remove the comment
String rawCommand = rawText.replaceFirst("//.*", "");
// Replace the "./" with "/" and then trim the string
String command = rawCommand.replaceFirst("\\./", "/").trim();
// Remove the command, and the comment block, as well as its spaces
String message = rawText.replace(rawCommand, "").replaceFirst("// *", "").trim();
// Send a composite message of the command, a space, and then the comment text
event.getFormatter().setBody(Text.of(
Text.of(
TextColors.DARK_GREEN,
TextActions.showText(Text.of("Click to type:\n", command)),
TextActions.suggestCommand(command),
command
),
" ",
message
));
}
}
示例8: onPlayerChat
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerChat(MessageChannelEvent.Chat event, @First Player player) {
String message = event.getRawMessage().toPlain();
if (player.getUniqueId().equals(getParent().getUUID())) {
// Verify the data
Optional<Integer> iOpt = verifyInteger(message);
if (iOpt.isPresent() && iOpt.get() > 0) {
// Set the data
getParent().setData(new MaxLevelData(iOpt.get()));
// Send confirmation
player.sendMessage(messages.getMessage("creation.registered.maxlevel", "level", iOpt.get().toString()));
// Move to the next task
getParent().nextTask();
// Remove the listener
Sponge.getEventManager().unregisterListeners(this);
} else {
player.sendMessage(messages.getMessage("creation.validnumber"));
}
event.setCancelled(true);
}
}
示例9: onPlayerChat
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerChat(MessageChannelEvent.Chat event, @First Player player) {
String message = event.getRawMessage().toPlain();
if (player.getUniqueId().equals(getParent().getUUID())) {
String name = message.toLowerCase().replaceAll(" ", "-");
// Verify the data
if (!JobsLite.getJobManager().jobExists(name)) {
// Set the data
getParent().setData(new NameData(message.toLowerCase().replaceFirst(" ", "-")));
getParent().setData(new DisplayNameData(message));
// Send confirmation
player.sendMessage(messages.getMessage("creation.registered.name", "name", message));
// Move to the next task
getParent().nextTask();
// Remove the listener
Sponge.getEventManager().unregisterListeners(this);
} else {
player.sendMessage(messages.getMessage("creation.inuse"));
}
event.setCancelled(true);
}
}
示例10: onChat
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
@Listener
public void onChat(MessageChannelEvent.Chat event, @First Player source)
{
// muted?
Date muted = muteCmd.getMuted(source);
if (muted != null && System.currentTimeMillis() < muted.getTime())
{
event.setCancelled(true);
i18n.send(source, NEGATIVE, "You try to speak but nothing happens!");
return;
}
// ignored?
for (Iterator<MessageReceiver> iterator = event.getChannel().get().getMembers().iterator(); iterator.hasNext(); )
{
final MessageReceiver player = iterator.next();
if (player instanceof Player)
{
if (this.ignoreCmd.checkIgnored(((Player) player), source))
{
iterator.remove();
}
}
}
}
示例11: onChat
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
@Listener
public void onChat(MessageChannelEvent.Chat event) {
String message = event.getRawMessage().toPlain();
for (Player p : Sponge.getServer().getOnlinePlayers()) {
if (message.contains(p.getName())) {
ModuleConfig config = Modules.POKE.get().getConfig().get();
CommentedConfigurationNode node = config.get();
String soundname = node.getNode("sound", "sound").getString();
String categoryname = node.getNode("sound", "category").getString();
Double volume = node.getNode("sound", "volume").getDouble();
Double pitch = node.getNode("sound", "pitch").getDouble();
Double minVolume = node.getNode("sound", "minVolume").getDouble();
SoundType type = Sponge.getRegistry().getType(CatalogTypes.SOUND_TYPE, soundname.toUpperCase()).get();
//TODO wait for CatalogTypes.SOUND_CATEGORY to be added
SoundCategory category;
try {
category = Sponge.getRegistry().getType(CatalogTypes.SOUND_CATEGORY, categoryname.toUpperCase()).get();
} catch (Error ex) {
category = SoundCategories.PLAYER;
}
p.playSound(type, category, p.getLocation().getPosition(), volume, pitch, minVolume);
}
}
}
示例12: onPlayerSendChat
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerSendChat(MessageChannelEvent.Chat event, @Root Player player) {
CallBackBuffer callBackBuffer = CallBackBuffer.getInstance();
if (callBackBuffer.hasCallBack(player)) {
callBackBuffer.executeCallBack(player, event.getRawMessage().toPlain());
event.setCancelled(true);
}
}
示例13: onIncomingMessage
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
@Listener(order = Order.PRE, beforeModifications = true)
@IsCancelled(Tristate.UNDEFINED)
public void onIncomingMessage(MessageChannelEvent.Chat event, @Root Player player) {
if (getView(player).handleIncoming(event.getRawMessage())) {
// No plugins should interpret this as chat
event.setCancelled(true);
event.setChannel(MessageChannel.TO_NONE);
}
}
示例14: sendMessage
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
/** Send a message from a channel as player.
* @param src {@code Player}
* @param message {@code Text} - Message to send.
* @param direct {@code boolean} - Send message direct to players on channel.
*/
public void sendMessage(Player src, Text message, boolean direct){
if (direct){
for (Player p:Sponge.getServer().getOnlinePlayers()){
UCChannel chp = UChat.get().getPlayerChannel(p);
if (UChat.get().getPerms().channelReadPerm(p, this) && !this.isIgnoring(p.getName()) && (!this.neeFocus() || chp.equals(this))){
UChat.get().getLogger().timings(timingType.START, "UCChannel#sendMessage()|Direct Message");
p.sendMessage(message);
}
}
src.sendMessage(message);
} else {
MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat(
UChat.get().getVHelper().getCause(src),
src.getMessageChannel(),
Optional.of(src.getMessageChannel()),
new MessageEvent.MessageFormatter(Text.builder("<" + src.getName() + "> ")
.onShiftClick(TextActions.insertText(src.getName()))
.onClick(TextActions.suggestCommand("/msg " + src.getName()))
.build(), message),
message,
false);
UChat.get().getLogger().timings(timingType.START, "UCChannel#sendMessage()|Fire MessageChannelEvent");
if (!Sponge.getEventManager().post(event)){
UChat.tempChannels.put(src.getName(), this.getAlias());
}
}
}
示例15: onChat
import org.spongepowered.api.event.message.MessageChannelEvent; //导入方法依赖的package包/类
@Listener
public void onChat(MessageChannelEvent.Chat evt, @Root Player player) {
PlayerChatsScriptEvent event = (PlayerChatsScriptEvent) clone();
event.internal = evt;
event.player = new PlayerTag(player);
event.message = new FormattedTextTag(evt.getRawMessage());
event.cancelled = evt.isCancelled();
event.run();
evt.setCancelled(event.cancelled);
}