mkremins / fanciful

Fancy Bukkit message formatting
MIT License
95 stars 82 forks source link

Tooltip with only 1 word in a msg #43

Closed rJoshy closed 10 years ago

rJoshy commented 10 years ago

Hey,

Is there a way I can only use .tooltip for 1 word in a list of strings/a msg. If i say in chat "Hey Josh", if i put my cursor over Josh, it will only show the tooltip but when i put it over "Hey", it wont show the tooltip.

Thanks, Josh

mkremins commented 10 years ago

You should be able to do this by using .then() to separate the two distinct parts of the message:

new FancyMessage("Hey ").then("Josh").tooltip(YOUR_TOOLTIP_HERE);

Modifiers (applied by .tooltip(), .color(), etc) apply only to the text in the most recent message part. Calling .then() creates a new message part with different modifiers.

rJoshy commented 10 years ago

Hey, thanks for that, what if the message was "Hey Josh, how is it going". I tried with .replace but that doesn't work. Just a correction, this is in a AsyncPlayerChatEvent. So I'm getting the msg and checking if a online players name is mentioned

mkremins commented 10 years ago

Again, you can use .then() to separate the part that should have a tooltip from the parts that shouldn't:

new FancyMessage("Hey ")
  .then("Josh").tooltip(YOUR_TOOLTIP_HERE)
  .then(", how is it going");

If you're doing this dynamically for arbitrary chat messages, you'll have to manually split the message string around the detected player name in order to isolate substrings that should and shouldn't have tooltips. Then you can loop over the array of message parts and add a new section to your FancyMessage (via .then()) for each one, applying tooltips where desired.

mkremins commented 10 years ago

It's been a while since the last activity here, so I'm going to assume the problem was solved and close this issue. Can always reopen later if necessary.