mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Fix RichMessage
This commit is contained in:
parent
109afe7a54
commit
83b6665702
@ -2,6 +2,7 @@ package net.minestom.server.chat;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
|
import net.minestom.server.entity.EntityType;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
|
|
||||||
public class ChatHoverEvent {
|
public class ChatHoverEvent {
|
||||||
@ -26,19 +27,24 @@ public class ChatHoverEvent {
|
|||||||
return new ChatHoverEvent("show_text", text.getJsonObject());
|
return new ChatHoverEvent("show_text", text.getJsonObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static ChatHoverEvent showText(String text) {
|
public static ChatHoverEvent showText(String text) {
|
||||||
return new ChatHoverEvent("show_text", text);
|
return new ChatHoverEvent("show_text", text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChatHoverEvent showItem(ItemStack itemStack) {
|
public static ChatHoverEvent showItem(ItemStack itemStack) {
|
||||||
throw new UnsupportedOperationException("Feature in progress");
|
return new ChatHoverEvent("show_item", "{id:4}");
|
||||||
//return new ChatHoverEvent("show_item", parsedItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChatHoverEvent showEntity(Entity entity) {
|
public static ChatHoverEvent showEntity(Entity entity) {
|
||||||
throw new UnsupportedOperationException("Feature in progress");
|
final String id = entity.getUuid().toString();
|
||||||
//return new ChatHoverEvent("show_entity", parsedEntity);
|
final String type = EntityType.fromId(entity.getEntityType())
|
||||||
|
.getNamespaceID().replace("minecraft:", "");
|
||||||
|
// TODO name
|
||||||
|
|
||||||
|
JsonObject object = new JsonObject();
|
||||||
|
object.addProperty("id", id);
|
||||||
|
object.addProperty("type", type);
|
||||||
|
return new ChatHoverEvent("show_entity", object);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getAction() {
|
protected String getAction() {
|
||||||
|
@ -83,7 +83,14 @@ public class ColoredText {
|
|||||||
return getJsonObject().toString();
|
return getJsonObject().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected JsonObject getJsonObject() {
|
/**
|
||||||
|
* Get the Json representation of this colored text
|
||||||
|
* <p>
|
||||||
|
* Used to send a message
|
||||||
|
*
|
||||||
|
* @return the Json representation of the text
|
||||||
|
*/
|
||||||
|
public JsonObject getJsonObject() {
|
||||||
List<JsonObject> components = getComponents();
|
List<JsonObject> components = getComponents();
|
||||||
|
|
||||||
// No message, return empty object
|
// No message, return empty object
|
||||||
@ -251,6 +258,7 @@ public class ColoredText {
|
|||||||
object.addProperty("color", color);
|
object.addProperty("color", color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
object.addProperty("bold", getBoolean(specialComponentContainer.bold));
|
object.addProperty("bold", getBoolean(specialComponentContainer.bold));
|
||||||
object.addProperty("italic", getBoolean(specialComponentContainer.italic));
|
object.addProperty("italic", getBoolean(specialComponentContainer.italic));
|
||||||
object.addProperty("underlined", getBoolean(specialComponentContainer.underlined));
|
object.addProperty("underlined", getBoolean(specialComponentContainer.underlined));
|
||||||
|
@ -62,15 +62,17 @@ public class RichMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JsonObject getJsonObject() {
|
private JsonObject getJsonObject() {
|
||||||
|
List<RichComponent> cacheComponents = new ArrayList<>(components);
|
||||||
|
|
||||||
// No component, return empty json object
|
// No component, return empty json object
|
||||||
if (components.isEmpty())
|
if (cacheComponents.isEmpty())
|
||||||
return new JsonObject();
|
return new JsonObject();
|
||||||
|
|
||||||
RichComponent firstComponent = components.remove(0);
|
RichComponent firstComponent = cacheComponents.remove(0);
|
||||||
List<JsonObject> firstComponentObjects = getComponentObject(firstComponent);
|
List<JsonObject> firstComponentObjects = getComponentObject(firstComponent);
|
||||||
JsonObject mainObject = firstComponentObjects.remove(0);
|
JsonObject mainObject = firstComponentObjects.remove(0);
|
||||||
|
|
||||||
if (components.isEmpty() && firstComponentObjects.isEmpty())
|
if (cacheComponents.isEmpty() && firstComponentObjects.isEmpty())
|
||||||
return mainObject;
|
return mainObject;
|
||||||
|
|
||||||
JsonArray extraArray = new JsonArray();
|
JsonArray extraArray = new JsonArray();
|
||||||
@ -78,7 +80,7 @@ public class RichMessage {
|
|||||||
extraArray.add(firstComponentObject);
|
extraArray.add(firstComponentObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (RichComponent component : components) {
|
for (RichComponent component : cacheComponents) {
|
||||||
List<JsonObject> componentObjects = getComponentObject(component);
|
List<JsonObject> componentObjects = getComponentObject(component);
|
||||||
for (JsonObject componentObject : componentObjects) {
|
for (JsonObject componentObject : componentObjects) {
|
||||||
extraArray.add(componentObject);
|
extraArray.add(componentObject);
|
||||||
|
Loading…
Reference in New Issue
Block a user