Jump to content

Getting the player from a ClientChatEvent.


acaiberii

Recommended Posts

private void handlePower(String power, boolean isFromCo, ClientChatEvent event) {
  switch (power) {
  	case "immortality":
    	event.setCanceled(true);
    	if (isFromCo) {
    		Minecraft.getInstance().gui.getChat().addMessage(new TextComponent("[HellSchool] " + event.getPlayer() + " went immortal!"));
///                                                                                                    ^ not a method, so how do I get the player sending the message?
    	}
  }
}

@SubscribeEvent
private void onChatMessage(ClientChatEvent event) {
	boolean isFromCo = event.getOriginalMessage().contains("[CO-OWNER]");

	Pattern pattern = Pattern.compile("\\*uses (.*?)\\*");

	if (pattern.matcher(event.getOriginalMessage()).find()) {
		String power = pattern.matcher(event.getOriginalMessage()).replaceAll("$1").replace("*uses ", "").replace("*", "");

		this.handlePower(power, isFromCo, event);
	}
}

These are the methods I'm using to subscribe to the ClientChatEvent, the comments explain what's going on.

I need to get the player to identify the chat message's sender and add that message to the player's personal chat messages.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Are you playing with mods? This usually happens to me when certain mods clash. I would recommend looking through the game logs (found in the file of the modpack) to see what errors have occurred. I hope this helps!
    • For the HoneyBottleItem class, would I just copy/paste my Lemon Juice item into the class or would I have to make other changes? Also, for what you first said, I have copied the "getEatingSound" and the "getDrinkingSound" from the class into my ModFoods class (I could link the whole class if that would help you understand more), though nothing seems to have been done. I also do not see a way to prevent particles from appearing when the item is drank. (Could you also post some examples if possible, that would be a great help to see where I went wrong).   I am at a point where I am quite clueless as the tutorials on YouTube do not cover the area I am needing to go into. I do hope that this is not too much of a bother for you. 
    • "An unexpected problem occurred and the game crashed" "Exit code: 1" I don't know what to do. Please help
    • https://mclo.gs/iVJZfGm https://privatebin.net/?442243857e9dcaca#5MhV8JAuhNJnN587jbG2pcVQi8VnvgAVafmpAd6Gnv91
    • So im making a mod for minecraft and i want to add custom fishing rods... aka fishing rods with different bait, depending on the bait you can have a higher chance of getting other fish. I want to make basically custom fishing rods with at least one custom loot table for each (so that i can choose which fish have a higher chance of being caught in a simpler way with said loot table) Problem is i dont know even where to start with doing this, like at all. Im very beginner with modding minecraft, any help (links to any source which could help me with this is also very helpful) would be great. 1.20 forge(of course)
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.