Hey guys,
How can I change the prefix shownig up, when a player sends a message in the chat?
I think I have to use something in combination with a chat event, right?
Greets
Here is an example :
@Listener
public void onPlayerChat(MessageSinkEvent.Chat e) {
Optional<Player> sp = e.getCause().first(Player.class);
if (sp.isPresent()) {
Player p = sp.get();
String rawMsg = Texts.toPlain(e.getRawMessage());
Text msg = Texts.of("[" + p.getName() + "] ", rawMsg.replace("badwords", ""));
if (p.hasPermission("myplugin.imvip")) {
e.setMessage(Texts.of(TextColors.AQUA, "[ImVIP] ", msg));
} else {
e.setMessage(msg);
}
}
}
I hope it helped you
sorry, but the event does not fire, when i type something in the chat…
Don’t forget to register your listener during your plugin initialization.
game.getEventManager().registerListeners(myPlugin, new MyListener());
https://docs.spongepowered.org/en/plugin/events.html
https://docs.spongepowered.org/en/plugin/lifecycle.html
Event was already registered…
So can you say me, if the problem occurs because i am using spongevanilla?
Yep, something wrong with SpongeVanilla
For some reason they are firing the parent MessageSinkEvent
and not the MessageSinkEvent.Chat
Okey, …
Another question: should I create a new topic? I found out, that the “ClientConnectionEvent.Join” event fires 2 times (on a player join).
On SpongeForge, my plugin does not do that (this event does not do that there)…
Is there a problem with my plugin or is there something wrong in SpongeVanilla?
I don’t think there’s something wrong in SpongeVanilla there. If you are able to reproduce on the latest SpongeVanilla commit then post a new topic.
Make sure you are not registering the event handler twice (note the main plugin class doesn’t need to be registered)
No I did not do that!
Like I said before, the event fires once in SpongeForge and twice in SpongeVanilla…
My Code was the same when I testet both systems!
I wrote:
@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event) { logger.info("a player joined"); }
So when I join (SpongeVanilla) I can clearly see “a player joined” coming up twice in my console…
I’m using the latest build …
Greets
I tested ClientConnectionEvent.Join
with the latest SpongeVanilla
commit in a development environment in eclipse.
Could not reproduce.
How are you testing this? Could it be that you’ve got two copies of your plugin loaded?
no, as I said, I tested exactly the thing using SpongeForge… I will give it another try today when I’m at home