mirror of
https://github.com/Minestom/Minestom.git
synced 2024-10-02 08:27:58 +02:00
Add support for insertion text in RichMessage
This commit is contained in:
parent
fe73c43eef
commit
f95feeaaf1
@ -295,6 +295,8 @@ public class PlayerInit {
|
||||
|
||||
RichMessage richMessage = RichMessage.of(ColoredText.of(ChatColor.RED + "test item"));
|
||||
richMessage.setHoverEvent(ChatHoverEvent.showItem(new ItemStack(Material.DIAMOND, (byte) 1)));
|
||||
richMessage.setInsertion("Test Insert");
|
||||
System.out.println(richMessage.toString());
|
||||
player.sendMessage(richMessage);
|
||||
|
||||
//EntityBoat entityBoat = new EntityBoat(player.getPosition());
|
||||
|
@ -63,6 +63,19 @@ public class RichMessage {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the insertion string of the current rich component
|
||||
*
|
||||
* @param insertion the string to insert in the chat box
|
||||
* @return the rich message
|
||||
*/
|
||||
public RichMessage setInsertion(String insertion) {
|
||||
Check.notNull(insertion, "the insertion cannot be null");
|
||||
|
||||
currentComponent.setInsertion(insertion);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new rich component to the message
|
||||
*
|
||||
@ -142,14 +155,15 @@ public class RichMessage {
|
||||
* @return a list of processed components
|
||||
*/
|
||||
private List<JsonObject> getComponentObject(RichComponent component) {
|
||||
ColoredText coloredText = component.getText();
|
||||
List<JsonObject> componentObjects = coloredText.getComponents();
|
||||
final ColoredText coloredText = component.getText();
|
||||
final List<JsonObject> componentObjects = coloredText.getComponents();
|
||||
|
||||
ChatClickEvent clickEvent = component.getClickEvent();
|
||||
ChatHoverEvent hoverEvent = component.getHoverEvent();
|
||||
final ChatClickEvent clickEvent = component.getClickEvent();
|
||||
final ChatHoverEvent hoverEvent = component.getHoverEvent();
|
||||
final String insertion = component.getInsertion();
|
||||
|
||||
// Nothing to process
|
||||
if (clickEvent == null && hoverEvent == null) {
|
||||
if (clickEvent == null && hoverEvent == null && insertion == null) {
|
||||
return componentObjects;
|
||||
}
|
||||
|
||||
@ -175,6 +189,10 @@ public class RichMessage {
|
||||
}
|
||||
componentObject.add("hoverEvent", hoverObject);
|
||||
}
|
||||
// Add insertion if any
|
||||
if (insertion != null) {
|
||||
componentObject.addProperty("insertion", insertion);
|
||||
}
|
||||
}
|
||||
|
||||
return componentObjects;
|
||||
@ -200,6 +218,7 @@ public class RichMessage {
|
||||
private FormatRetention formatRetention;
|
||||
private ChatClickEvent clickEvent;
|
||||
private ChatHoverEvent hoverEvent;
|
||||
private String insertion;
|
||||
|
||||
private RichComponent(ColoredText text, FormatRetention formatRetention) {
|
||||
this.text = text;
|
||||
@ -229,6 +248,14 @@ public class RichMessage {
|
||||
public void setHoverEvent(ChatHoverEvent hoverEvent) {
|
||||
this.hoverEvent = hoverEvent;
|
||||
}
|
||||
|
||||
public String getInsertion() {
|
||||
return insertion;
|
||||
}
|
||||
|
||||
public void setInsertion(String insertion) {
|
||||
this.insertion = insertion;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user