mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-24 17:57:36 +01:00
Use Spigot's official chat API
This commit is contained in:
parent
47de261216
commit
6c82640e7e
@ -1,28 +0,0 @@
|
||||
package com.gmail.filoghost.holographicdisplays.nms.interfaces;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface FancyMessage {
|
||||
|
||||
public FancyMessage color(final ChatColor color);
|
||||
|
||||
public FancyMessage style(final ChatColor... styles);
|
||||
|
||||
public FancyMessage file(final String path);
|
||||
|
||||
public FancyMessage link(final String url);
|
||||
|
||||
public FancyMessage suggest(final String command);
|
||||
|
||||
public FancyMessage command(final String command);
|
||||
|
||||
public FancyMessage tooltip(final String text);
|
||||
|
||||
public FancyMessage then(final Object obj);
|
||||
|
||||
public String toJSONString();
|
||||
|
||||
public void send(Player player);
|
||||
|
||||
}
|
@ -23,7 +23,5 @@ public interface NMSManager {
|
||||
public boolean isNMSEntityBase(org.bukkit.entity.Entity bukkitEntity);
|
||||
|
||||
public NMSEntityBase getNMSEntityBase(org.bukkit.entity.Entity bukkitEntity);
|
||||
|
||||
public FancyMessage newFancyMessage(String text);
|
||||
|
||||
}
|
||||
|
@ -1,170 +0,0 @@
|
||||
package com.gmail.filoghost.holographicdisplays.nms.v1_10_R1;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_10_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_10_R1.PacketPlayOutChat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
|
||||
public class FancyMessageImpl implements FancyMessage {
|
||||
|
||||
private List<MessagePart> messageParts;
|
||||
|
||||
public FancyMessageImpl(String firstPartText) {
|
||||
messageParts = new ArrayList<MessagePart>();
|
||||
messageParts.add(new MessagePart(firstPartText));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl color(ChatColor color) {
|
||||
if (!color.isColor()) {
|
||||
throw new IllegalArgumentException(color.name() + " is not a color");
|
||||
}
|
||||
latest().color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl style(ChatColor... styles) {
|
||||
for (ChatColor style : styles) {
|
||||
if (!style.isFormat()) {
|
||||
throw new IllegalArgumentException(style.name() + " is not a style");
|
||||
}
|
||||
}
|
||||
latest().styles = styles;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl file(String path) {
|
||||
onClick("open_file", path);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl link(String url) {
|
||||
onClick("open_url", url);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl suggest(String command) {
|
||||
onClick("suggest_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl command(String command) {
|
||||
onClick("run_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl tooltip(String text) {
|
||||
onHover("show_text", text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl then(Object obj) {
|
||||
messageParts.add(new MessagePart(obj.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter json = new JsonWriter(stringWriter);
|
||||
|
||||
try {
|
||||
if (messageParts.size() == 1) {
|
||||
latest().writeJson(json);
|
||||
} else {
|
||||
json.beginObject().name("text").value("").name("extra").beginArray();
|
||||
for (MessagePart part : messageParts) {
|
||||
part.writeJson(json);
|
||||
}
|
||||
json.endArray().endObject();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("invalid message");
|
||||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Player player) {
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(toJSONString())));
|
||||
}
|
||||
|
||||
private MessagePart latest() {
|
||||
return messageParts.get(messageParts.size() - 1);
|
||||
}
|
||||
|
||||
private void onClick(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.clickActionName = name;
|
||||
latest.clickActionData = data;
|
||||
}
|
||||
|
||||
private void onHover(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.hoverActionName = name;
|
||||
latest.hoverActionData = data;
|
||||
}
|
||||
|
||||
static class MessagePart {
|
||||
|
||||
public ChatColor color = null;
|
||||
public ChatColor[] styles = null;
|
||||
public String clickActionName = null;
|
||||
public String clickActionData = null;
|
||||
public String hoverActionName = null;
|
||||
public String hoverActionData = null;
|
||||
public final String text;
|
||||
|
||||
public MessagePart(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public JsonWriter writeJson(final JsonWriter json) throws IOException {
|
||||
json.beginObject().name("text").value(text);
|
||||
if (color != null) {
|
||||
json.name("color").value(color.name().toLowerCase());
|
||||
}
|
||||
if (styles != null) {
|
||||
for (final ChatColor style : styles) {
|
||||
json.name(style == ChatColor.UNDERLINE ? "underlined" : style.name().toLowerCase()).value(true);
|
||||
}
|
||||
}
|
||||
if (clickActionName != null && clickActionData != null) {
|
||||
json.name("clickEvent")
|
||||
.beginObject()
|
||||
.name("action").value(clickActionName)
|
||||
.name("value").value(clickActionData)
|
||||
.endObject();
|
||||
}
|
||||
if (hoverActionName != null && hoverActionData != null) {
|
||||
json.name("hoverEvent")
|
||||
.beginObject()
|
||||
.name("action").value(hoverActionName)
|
||||
.name("value").value(hoverActionData)
|
||||
.endObject();
|
||||
}
|
||||
return json.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
@ -122,9 +121,4 @@ public class NmsManagerImpl implements NMSManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessage newFancyMessage(String text) {
|
||||
return new FancyMessageImpl(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,170 +0,0 @@
|
||||
package com.gmail.filoghost.holographicdisplays.nms.v1_11_R1;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_11_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_11_R1.PacketPlayOutChat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
|
||||
public class FancyMessageImpl implements FancyMessage {
|
||||
|
||||
private List<MessagePart> messageParts;
|
||||
|
||||
public FancyMessageImpl(String firstPartText) {
|
||||
messageParts = new ArrayList<MessagePart>();
|
||||
messageParts.add(new MessagePart(firstPartText));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl color(ChatColor color) {
|
||||
if (!color.isColor()) {
|
||||
throw new IllegalArgumentException(color.name() + " is not a color");
|
||||
}
|
||||
latest().color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl style(ChatColor... styles) {
|
||||
for (ChatColor style : styles) {
|
||||
if (!style.isFormat()) {
|
||||
throw new IllegalArgumentException(style.name() + " is not a style");
|
||||
}
|
||||
}
|
||||
latest().styles = styles;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl file(String path) {
|
||||
onClick("open_file", path);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl link(String url) {
|
||||
onClick("open_url", url);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl suggest(String command) {
|
||||
onClick("suggest_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl command(String command) {
|
||||
onClick("run_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl tooltip(String text) {
|
||||
onHover("show_text", text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl then(Object obj) {
|
||||
messageParts.add(new MessagePart(obj.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter json = new JsonWriter(stringWriter);
|
||||
|
||||
try {
|
||||
if (messageParts.size() == 1) {
|
||||
latest().writeJson(json);
|
||||
} else {
|
||||
json.beginObject().name("text").value("").name("extra").beginArray();
|
||||
for (MessagePart part : messageParts) {
|
||||
part.writeJson(json);
|
||||
}
|
||||
json.endArray().endObject();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("invalid message");
|
||||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Player player) {
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(toJSONString())));
|
||||
}
|
||||
|
||||
private MessagePart latest() {
|
||||
return messageParts.get(messageParts.size() - 1);
|
||||
}
|
||||
|
||||
private void onClick(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.clickActionName = name;
|
||||
latest.clickActionData = data;
|
||||
}
|
||||
|
||||
private void onHover(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.hoverActionName = name;
|
||||
latest.hoverActionData = data;
|
||||
}
|
||||
|
||||
static class MessagePart {
|
||||
|
||||
public ChatColor color = null;
|
||||
public ChatColor[] styles = null;
|
||||
public String clickActionName = null;
|
||||
public String clickActionData = null;
|
||||
public String hoverActionName = null;
|
||||
public String hoverActionData = null;
|
||||
public final String text;
|
||||
|
||||
public MessagePart(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public JsonWriter writeJson(final JsonWriter json) throws IOException {
|
||||
json.beginObject().name("text").value(text);
|
||||
if (color != null) {
|
||||
json.name("color").value(color.name().toLowerCase());
|
||||
}
|
||||
if (styles != null) {
|
||||
for (final ChatColor style : styles) {
|
||||
json.name(style == ChatColor.UNDERLINE ? "underlined" : style.name().toLowerCase()).value(true);
|
||||
}
|
||||
}
|
||||
if (clickActionName != null && clickActionData != null) {
|
||||
json.name("clickEvent")
|
||||
.beginObject()
|
||||
.name("action").value(clickActionName)
|
||||
.name("value").value(clickActionData)
|
||||
.endObject();
|
||||
}
|
||||
if (hoverActionName != null && hoverActionData != null) {
|
||||
json.name("hoverEvent")
|
||||
.beginObject()
|
||||
.name("action").value(hoverActionName)
|
||||
.name("value").value(hoverActionData)
|
||||
.endObject();
|
||||
}
|
||||
return json.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.gmail.filoghost.holographicdisplays.nms.v1_11_R1;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity;
|
||||
@ -8,7 +9,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
@ -130,9 +130,4 @@ public class NmsManagerImpl implements NMSManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessage newFancyMessage(String text) {
|
||||
return new FancyMessageImpl(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,170 +0,0 @@
|
||||
package com.gmail.filoghost.holographicdisplays.nms.v1_12_R1;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_12_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutChat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
|
||||
public class FancyMessageImpl implements FancyMessage {
|
||||
|
||||
private List<MessagePart> messageParts;
|
||||
|
||||
public FancyMessageImpl(String firstPartText) {
|
||||
messageParts = new ArrayList<MessagePart>();
|
||||
messageParts.add(new MessagePart(firstPartText));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl color(ChatColor color) {
|
||||
if (!color.isColor()) {
|
||||
throw new IllegalArgumentException(color.name() + " is not a color");
|
||||
}
|
||||
latest().color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl style(ChatColor... styles) {
|
||||
for (ChatColor style : styles) {
|
||||
if (!style.isFormat()) {
|
||||
throw new IllegalArgumentException(style.name() + " is not a style");
|
||||
}
|
||||
}
|
||||
latest().styles = styles;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl file(String path) {
|
||||
onClick("open_file", path);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl link(String url) {
|
||||
onClick("open_url", url);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl suggest(String command) {
|
||||
onClick("suggest_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl command(String command) {
|
||||
onClick("run_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl tooltip(String text) {
|
||||
onHover("show_text", text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl then(Object obj) {
|
||||
messageParts.add(new MessagePart(obj.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter json = new JsonWriter(stringWriter);
|
||||
|
||||
try {
|
||||
if (messageParts.size() == 1) {
|
||||
latest().writeJson(json);
|
||||
} else {
|
||||
json.beginObject().name("text").value("").name("extra").beginArray();
|
||||
for (MessagePart part : messageParts) {
|
||||
part.writeJson(json);
|
||||
}
|
||||
json.endArray().endObject();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("invalid message");
|
||||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Player player) {
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(toJSONString())));
|
||||
}
|
||||
|
||||
private MessagePart latest() {
|
||||
return messageParts.get(messageParts.size() - 1);
|
||||
}
|
||||
|
||||
private void onClick(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.clickActionName = name;
|
||||
latest.clickActionData = data;
|
||||
}
|
||||
|
||||
private void onHover(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.hoverActionName = name;
|
||||
latest.hoverActionData = data;
|
||||
}
|
||||
|
||||
static class MessagePart {
|
||||
|
||||
public ChatColor color = null;
|
||||
public ChatColor[] styles = null;
|
||||
public String clickActionName = null;
|
||||
public String clickActionData = null;
|
||||
public String hoverActionName = null;
|
||||
public String hoverActionData = null;
|
||||
public final String text;
|
||||
|
||||
public MessagePart(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public JsonWriter writeJson(final JsonWriter json) throws IOException {
|
||||
json.beginObject().name("text").value(text);
|
||||
if (color != null) {
|
||||
json.name("color").value(color.name().toLowerCase());
|
||||
}
|
||||
if (styles != null) {
|
||||
for (final ChatColor style : styles) {
|
||||
json.name(style == ChatColor.UNDERLINE ? "underlined" : style.name().toLowerCase()).value(true);
|
||||
}
|
||||
}
|
||||
if (clickActionName != null && clickActionData != null) {
|
||||
json.name("clickEvent")
|
||||
.beginObject()
|
||||
.name("action").value(clickActionName)
|
||||
.name("value").value(clickActionData)
|
||||
.endObject();
|
||||
}
|
||||
if (hoverActionName != null && hoverActionData != null) {
|
||||
json.name("hoverEvent")
|
||||
.beginObject()
|
||||
.name("action").value(hoverActionName)
|
||||
.name("value").value(hoverActionData)
|
||||
.endObject();
|
||||
}
|
||||
return json.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -9,7 +9,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
@ -130,10 +129,5 @@ public class NmsManagerImpl implements NMSManager {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessage newFancyMessage(String text) {
|
||||
return new FancyMessageImpl(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,170 +0,0 @@
|
||||
package com.gmail.filoghost.holographicdisplays.nms.v1_13_R1;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_13_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_13_R1.PacketPlayOutChat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
|
||||
public class FancyMessageImpl implements FancyMessage {
|
||||
|
||||
private List<MessagePart> messageParts;
|
||||
|
||||
public FancyMessageImpl(String firstPartText) {
|
||||
messageParts = new ArrayList<MessagePart>();
|
||||
messageParts.add(new MessagePart(firstPartText));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl color(ChatColor color) {
|
||||
if (!color.isColor()) {
|
||||
throw new IllegalArgumentException(color.name() + " is not a color");
|
||||
}
|
||||
latest().color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl style(ChatColor... styles) {
|
||||
for (ChatColor style : styles) {
|
||||
if (!style.isFormat()) {
|
||||
throw new IllegalArgumentException(style.name() + " is not a style");
|
||||
}
|
||||
}
|
||||
latest().styles = styles;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl file(String path) {
|
||||
onClick("open_file", path);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl link(String url) {
|
||||
onClick("open_url", url);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl suggest(String command) {
|
||||
onClick("suggest_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl command(String command) {
|
||||
onClick("run_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl tooltip(String text) {
|
||||
onHover("show_text", text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl then(Object obj) {
|
||||
messageParts.add(new MessagePart(obj.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter json = new JsonWriter(stringWriter);
|
||||
|
||||
try {
|
||||
if (messageParts.size() == 1) {
|
||||
latest().writeJson(json);
|
||||
} else {
|
||||
json.beginObject().name("text").value("").name("extra").beginArray();
|
||||
for (MessagePart part : messageParts) {
|
||||
part.writeJson(json);
|
||||
}
|
||||
json.endArray().endObject();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("invalid message");
|
||||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Player player) {
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(toJSONString())));
|
||||
}
|
||||
|
||||
private MessagePart latest() {
|
||||
return messageParts.get(messageParts.size() - 1);
|
||||
}
|
||||
|
||||
private void onClick(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.clickActionName = name;
|
||||
latest.clickActionData = data;
|
||||
}
|
||||
|
||||
private void onHover(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.hoverActionName = name;
|
||||
latest.hoverActionData = data;
|
||||
}
|
||||
|
||||
static class MessagePart {
|
||||
|
||||
public ChatColor color = null;
|
||||
public ChatColor[] styles = null;
|
||||
public String clickActionName = null;
|
||||
public String clickActionData = null;
|
||||
public String hoverActionName = null;
|
||||
public String hoverActionData = null;
|
||||
public final String text;
|
||||
|
||||
public MessagePart(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public JsonWriter writeJson(final JsonWriter json) throws IOException {
|
||||
json.beginObject().name("text").value(text);
|
||||
if (color != null) {
|
||||
json.name("color").value(color.name().toLowerCase());
|
||||
}
|
||||
if (styles != null) {
|
||||
for (final ChatColor style : styles) {
|
||||
json.name(style == ChatColor.UNDERLINE ? "underlined" : style.name().toLowerCase()).value(true);
|
||||
}
|
||||
}
|
||||
if (clickActionName != null && clickActionData != null) {
|
||||
json.name("clickEvent")
|
||||
.beginObject()
|
||||
.name("action").value(clickActionName)
|
||||
.name("value").value(clickActionData)
|
||||
.endObject();
|
||||
}
|
||||
if (hoverActionName != null && hoverActionData != null) {
|
||||
json.name("hoverEvent")
|
||||
.beginObject()
|
||||
.name("action").value(hoverActionName)
|
||||
.name("value").value(hoverActionData)
|
||||
.endObject();
|
||||
}
|
||||
return json.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -11,7 +11,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
@ -151,10 +150,5 @@ public class NmsManagerImpl implements NMSManager {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessage newFancyMessage(String text) {
|
||||
return new FancyMessageImpl(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,170 +0,0 @@
|
||||
package com.gmail.filoghost.holographicdisplays.nms.v1_13_R2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_13_R2.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutChat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
|
||||
public class FancyMessageImpl implements FancyMessage {
|
||||
|
||||
private List<MessagePart> messageParts;
|
||||
|
||||
public FancyMessageImpl(String firstPartText) {
|
||||
messageParts = new ArrayList<MessagePart>();
|
||||
messageParts.add(new MessagePart(firstPartText));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl color(ChatColor color) {
|
||||
if (!color.isColor()) {
|
||||
throw new IllegalArgumentException(color.name() + " is not a color");
|
||||
}
|
||||
latest().color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl style(ChatColor... styles) {
|
||||
for (ChatColor style : styles) {
|
||||
if (!style.isFormat()) {
|
||||
throw new IllegalArgumentException(style.name() + " is not a style");
|
||||
}
|
||||
}
|
||||
latest().styles = styles;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl file(String path) {
|
||||
onClick("open_file", path);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl link(String url) {
|
||||
onClick("open_url", url);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl suggest(String command) {
|
||||
onClick("suggest_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl command(String command) {
|
||||
onClick("run_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl tooltip(String text) {
|
||||
onHover("show_text", text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl then(Object obj) {
|
||||
messageParts.add(new MessagePart(obj.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter json = new JsonWriter(stringWriter);
|
||||
|
||||
try {
|
||||
if (messageParts.size() == 1) {
|
||||
latest().writeJson(json);
|
||||
} else {
|
||||
json.beginObject().name("text").value("").name("extra").beginArray();
|
||||
for (MessagePart part : messageParts) {
|
||||
part.writeJson(json);
|
||||
}
|
||||
json.endArray().endObject();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("invalid message");
|
||||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Player player) {
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(toJSONString())));
|
||||
}
|
||||
|
||||
private MessagePart latest() {
|
||||
return messageParts.get(messageParts.size() - 1);
|
||||
}
|
||||
|
||||
private void onClick(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.clickActionName = name;
|
||||
latest.clickActionData = data;
|
||||
}
|
||||
|
||||
private void onHover(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.hoverActionName = name;
|
||||
latest.hoverActionData = data;
|
||||
}
|
||||
|
||||
static class MessagePart {
|
||||
|
||||
public ChatColor color = null;
|
||||
public ChatColor[] styles = null;
|
||||
public String clickActionName = null;
|
||||
public String clickActionData = null;
|
||||
public String hoverActionName = null;
|
||||
public String hoverActionData = null;
|
||||
public final String text;
|
||||
|
||||
public MessagePart(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public JsonWriter writeJson(final JsonWriter json) throws IOException {
|
||||
json.beginObject().name("text").value(text);
|
||||
if (color != null) {
|
||||
json.name("color").value(color.name().toLowerCase());
|
||||
}
|
||||
if (styles != null) {
|
||||
for (final ChatColor style : styles) {
|
||||
json.name(style == ChatColor.UNDERLINE ? "underlined" : style.name().toLowerCase()).value(true);
|
||||
}
|
||||
}
|
||||
if (clickActionName != null && clickActionData != null) {
|
||||
json.name("clickEvent")
|
||||
.beginObject()
|
||||
.name("action").value(clickActionName)
|
||||
.name("value").value(clickActionData)
|
||||
.endObject();
|
||||
}
|
||||
if (hoverActionName != null && hoverActionData != null) {
|
||||
json.name("hoverEvent")
|
||||
.beginObject()
|
||||
.name("action").value(hoverActionName)
|
||||
.name("value").value(hoverActionData)
|
||||
.endObject();
|
||||
}
|
||||
return json.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -11,7 +11,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
@ -152,10 +151,5 @@ public class NmsManagerImpl implements NMSManager {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessage newFancyMessage(String text) {
|
||||
return new FancyMessageImpl(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,168 +0,0 @@
|
||||
package com.gmail.filoghost.holographicdisplays.nms.v1_8_R1;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_8_R1.ChatSerializer;
|
||||
import net.minecraft.server.v1_8_R1.PacketPlayOutChat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.libs.com.google.gson.stream.JsonWriter;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
|
||||
public class FancyMessageImpl implements FancyMessage {
|
||||
|
||||
private List<MessagePart> messageParts;
|
||||
|
||||
public FancyMessageImpl(String firstPartText) {
|
||||
messageParts = new ArrayList<MessagePart>();
|
||||
messageParts.add(new MessagePart(firstPartText));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl color(ChatColor color) {
|
||||
if (!color.isColor()) {
|
||||
throw new IllegalArgumentException(color.name() + " is not a color");
|
||||
}
|
||||
latest().color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl style(ChatColor... styles) {
|
||||
for (ChatColor style : styles) {
|
||||
if (!style.isFormat()) {
|
||||
throw new IllegalArgumentException(style.name() + " is not a style");
|
||||
}
|
||||
}
|
||||
latest().styles = styles;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl file(String path) {
|
||||
onClick("open_file", path);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl link(String url) {
|
||||
onClick("open_url", url);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl suggest(String command) {
|
||||
onClick("suggest_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl command(String command) {
|
||||
onClick("run_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl tooltip(String text) {
|
||||
onHover("show_text", text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl then(Object obj) {
|
||||
messageParts.add(new MessagePart(obj.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter json = new JsonWriter(stringWriter);
|
||||
|
||||
try {
|
||||
if (messageParts.size() == 1) {
|
||||
latest().writeJson(json);
|
||||
} else {
|
||||
json.beginObject().name("text").value("").name("extra").beginArray();
|
||||
for (MessagePart part : messageParts) {
|
||||
part.writeJson(json);
|
||||
}
|
||||
json.endArray().endObject();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("invalid message");
|
||||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Player player){
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(ChatSerializer.a(toJSONString())));
|
||||
}
|
||||
|
||||
private MessagePart latest() {
|
||||
return messageParts.get(messageParts.size() - 1);
|
||||
}
|
||||
|
||||
private void onClick(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.clickActionName = name;
|
||||
latest.clickActionData = data;
|
||||
}
|
||||
|
||||
private void onHover(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.hoverActionName = name;
|
||||
latest.hoverActionData = data;
|
||||
}
|
||||
|
||||
static class MessagePart {
|
||||
|
||||
public ChatColor color = null;
|
||||
public ChatColor[] styles = null;
|
||||
public String clickActionName = null;
|
||||
public String clickActionData = null;
|
||||
public String hoverActionName = null;
|
||||
public String hoverActionData = null;
|
||||
public final String text;
|
||||
|
||||
public MessagePart(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public JsonWriter writeJson(final JsonWriter json) throws IOException {
|
||||
json.beginObject().name("text").value(text);
|
||||
if (color != null) {
|
||||
json.name("color").value(color.name().toLowerCase());
|
||||
}
|
||||
if (styles != null) {
|
||||
for (final ChatColor style : styles) {
|
||||
json.name(style == ChatColor.UNDERLINE ? "underlined" : style.name().toLowerCase()).value(true);
|
||||
}
|
||||
}
|
||||
if (clickActionName != null && clickActionData != null) {
|
||||
json.name("clickEvent")
|
||||
.beginObject()
|
||||
.name("action").value(clickActionName)
|
||||
.name("value").value(clickActionData)
|
||||
.endObject();
|
||||
}
|
||||
if (hoverActionName != null && hoverActionData != null) {
|
||||
json.name("hoverEvent")
|
||||
.beginObject()
|
||||
.name("action").value(hoverActionName)
|
||||
.name("value").value(hoverActionData)
|
||||
.endObject();
|
||||
}
|
||||
return json.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -11,7 +11,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
@ -127,10 +126,5 @@ public class NmsManagerImpl implements NMSManager {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessage newFancyMessage(String text) {
|
||||
return new FancyMessageImpl(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,170 +0,0 @@
|
||||
package com.gmail.filoghost.holographicdisplays.nms.v1_8_R2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_8_R2.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_8_R2.PacketPlayOutChat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
|
||||
public class FancyMessageImpl implements FancyMessage {
|
||||
|
||||
private List<MessagePart> messageParts;
|
||||
|
||||
public FancyMessageImpl(String firstPartText) {
|
||||
messageParts = new ArrayList<MessagePart>();
|
||||
messageParts.add(new MessagePart(firstPartText));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl color(ChatColor color) {
|
||||
if (!color.isColor()) {
|
||||
throw new IllegalArgumentException(color.name() + " is not a color");
|
||||
}
|
||||
latest().color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl style(ChatColor... styles) {
|
||||
for (ChatColor style : styles) {
|
||||
if (!style.isFormat()) {
|
||||
throw new IllegalArgumentException(style.name() + " is not a style");
|
||||
}
|
||||
}
|
||||
latest().styles = styles;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl file(String path) {
|
||||
onClick("open_file", path);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl link(String url) {
|
||||
onClick("open_url", url);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl suggest(String command) {
|
||||
onClick("suggest_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl command(String command) {
|
||||
onClick("run_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl tooltip(String text) {
|
||||
onHover("show_text", text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl then(Object obj) {
|
||||
messageParts.add(new MessagePart(obj.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter json = new JsonWriter(stringWriter);
|
||||
|
||||
try {
|
||||
if (messageParts.size() == 1) {
|
||||
latest().writeJson(json);
|
||||
} else {
|
||||
json.beginObject().name("text").value("").name("extra").beginArray();
|
||||
for (MessagePart part : messageParts) {
|
||||
part.writeJson(json);
|
||||
}
|
||||
json.endArray().endObject();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("invalid message");
|
||||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Player player) {
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(toJSONString())));
|
||||
}
|
||||
|
||||
private MessagePart latest() {
|
||||
return messageParts.get(messageParts.size() - 1);
|
||||
}
|
||||
|
||||
private void onClick(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.clickActionName = name;
|
||||
latest.clickActionData = data;
|
||||
}
|
||||
|
||||
private void onHover(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.hoverActionName = name;
|
||||
latest.hoverActionData = data;
|
||||
}
|
||||
|
||||
static class MessagePart {
|
||||
|
||||
public ChatColor color = null;
|
||||
public ChatColor[] styles = null;
|
||||
public String clickActionName = null;
|
||||
public String clickActionData = null;
|
||||
public String hoverActionName = null;
|
||||
public String hoverActionData = null;
|
||||
public final String text;
|
||||
|
||||
public MessagePart(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public JsonWriter writeJson(final JsonWriter json) throws IOException {
|
||||
json.beginObject().name("text").value(text);
|
||||
if (color != null) {
|
||||
json.name("color").value(color.name().toLowerCase());
|
||||
}
|
||||
if (styles != null) {
|
||||
for (final ChatColor style : styles) {
|
||||
json.name(style == ChatColor.UNDERLINE ? "underlined" : style.name().toLowerCase()).value(true);
|
||||
}
|
||||
}
|
||||
if (clickActionName != null && clickActionData != null) {
|
||||
json.name("clickEvent")
|
||||
.beginObject()
|
||||
.name("action").value(clickActionName)
|
||||
.name("value").value(clickActionData)
|
||||
.endObject();
|
||||
}
|
||||
if (hoverActionName != null && hoverActionData != null) {
|
||||
json.name("hoverEvent")
|
||||
.beginObject()
|
||||
.name("action").value(hoverActionName)
|
||||
.name("value").value(hoverActionData)
|
||||
.endObject();
|
||||
}
|
||||
return json.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -11,7 +11,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
@ -126,10 +125,5 @@ public class NmsManagerImpl implements NMSManager {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessage newFancyMessage(String text) {
|
||||
return new FancyMessageImpl(text);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,170 +0,0 @@
|
||||
package com.gmail.filoghost.holographicdisplays.nms.v1_8_R3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
|
||||
public class FancyMessageImpl implements FancyMessage {
|
||||
|
||||
private List<MessagePart> messageParts;
|
||||
|
||||
public FancyMessageImpl(String firstPartText) {
|
||||
messageParts = new ArrayList<MessagePart>();
|
||||
messageParts.add(new MessagePart(firstPartText));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl color(ChatColor color) {
|
||||
if (!color.isColor()) {
|
||||
throw new IllegalArgumentException(color.name() + " is not a color");
|
||||
}
|
||||
latest().color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl style(ChatColor... styles) {
|
||||
for (ChatColor style : styles) {
|
||||
if (!style.isFormat()) {
|
||||
throw new IllegalArgumentException(style.name() + " is not a style");
|
||||
}
|
||||
}
|
||||
latest().styles = styles;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl file(String path) {
|
||||
onClick("open_file", path);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl link(String url) {
|
||||
onClick("open_url", url);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl suggest(String command) {
|
||||
onClick("suggest_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl command(String command) {
|
||||
onClick("run_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl tooltip(String text) {
|
||||
onHover("show_text", text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl then(Object obj) {
|
||||
messageParts.add(new MessagePart(obj.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter json = new JsonWriter(stringWriter);
|
||||
|
||||
try {
|
||||
if (messageParts.size() == 1) {
|
||||
latest().writeJson(json);
|
||||
} else {
|
||||
json.beginObject().name("text").value("").name("extra").beginArray();
|
||||
for (MessagePart part : messageParts) {
|
||||
part.writeJson(json);
|
||||
}
|
||||
json.endArray().endObject();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("invalid message");
|
||||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Player player) {
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(toJSONString())));
|
||||
}
|
||||
|
||||
private MessagePart latest() {
|
||||
return messageParts.get(messageParts.size() - 1);
|
||||
}
|
||||
|
||||
private void onClick(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.clickActionName = name;
|
||||
latest.clickActionData = data;
|
||||
}
|
||||
|
||||
private void onHover(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.hoverActionName = name;
|
||||
latest.hoverActionData = data;
|
||||
}
|
||||
|
||||
static class MessagePart {
|
||||
|
||||
public ChatColor color = null;
|
||||
public ChatColor[] styles = null;
|
||||
public String clickActionName = null;
|
||||
public String clickActionData = null;
|
||||
public String hoverActionName = null;
|
||||
public String hoverActionData = null;
|
||||
public final String text;
|
||||
|
||||
public MessagePart(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public JsonWriter writeJson(final JsonWriter json) throws IOException {
|
||||
json.beginObject().name("text").value(text);
|
||||
if (color != null) {
|
||||
json.name("color").value(color.name().toLowerCase());
|
||||
}
|
||||
if (styles != null) {
|
||||
for (final ChatColor style : styles) {
|
||||
json.name(style == ChatColor.UNDERLINE ? "underlined" : style.name().toLowerCase()).value(true);
|
||||
}
|
||||
}
|
||||
if (clickActionName != null && clickActionData != null) {
|
||||
json.name("clickEvent")
|
||||
.beginObject()
|
||||
.name("action").value(clickActionName)
|
||||
.name("value").value(clickActionData)
|
||||
.endObject();
|
||||
}
|
||||
if (hoverActionName != null && hoverActionData != null) {
|
||||
json.name("hoverEvent")
|
||||
.beginObject()
|
||||
.name("action").value(hoverActionName)
|
||||
.name("value").value(hoverActionData)
|
||||
.endObject();
|
||||
}
|
||||
return json.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -11,7 +11,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
@ -127,9 +126,4 @@ public class NmsManagerImpl implements NMSManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessage newFancyMessage(String text) {
|
||||
return new FancyMessageImpl(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,170 +0,0 @@
|
||||
package com.gmail.filoghost.holographicdisplays.nms.v1_9_R1;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_9_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayOutChat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
|
||||
public class FancyMessageImpl implements FancyMessage {
|
||||
|
||||
private List<MessagePart> messageParts;
|
||||
|
||||
public FancyMessageImpl(String firstPartText) {
|
||||
messageParts = new ArrayList<MessagePart>();
|
||||
messageParts.add(new MessagePart(firstPartText));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl color(ChatColor color) {
|
||||
if (!color.isColor()) {
|
||||
throw new IllegalArgumentException(color.name() + " is not a color");
|
||||
}
|
||||
latest().color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl style(ChatColor... styles) {
|
||||
for (ChatColor style : styles) {
|
||||
if (!style.isFormat()) {
|
||||
throw new IllegalArgumentException(style.name() + " is not a style");
|
||||
}
|
||||
}
|
||||
latest().styles = styles;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl file(String path) {
|
||||
onClick("open_file", path);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl link(String url) {
|
||||
onClick("open_url", url);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl suggest(String command) {
|
||||
onClick("suggest_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl command(String command) {
|
||||
onClick("run_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl tooltip(String text) {
|
||||
onHover("show_text", text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl then(Object obj) {
|
||||
messageParts.add(new MessagePart(obj.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter json = new JsonWriter(stringWriter);
|
||||
|
||||
try {
|
||||
if (messageParts.size() == 1) {
|
||||
latest().writeJson(json);
|
||||
} else {
|
||||
json.beginObject().name("text").value("").name("extra").beginArray();
|
||||
for (MessagePart part : messageParts) {
|
||||
part.writeJson(json);
|
||||
}
|
||||
json.endArray().endObject();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("invalid message");
|
||||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Player player) {
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(toJSONString())));
|
||||
}
|
||||
|
||||
private MessagePart latest() {
|
||||
return messageParts.get(messageParts.size() - 1);
|
||||
}
|
||||
|
||||
private void onClick(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.clickActionName = name;
|
||||
latest.clickActionData = data;
|
||||
}
|
||||
|
||||
private void onHover(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.hoverActionName = name;
|
||||
latest.hoverActionData = data;
|
||||
}
|
||||
|
||||
static class MessagePart {
|
||||
|
||||
public ChatColor color = null;
|
||||
public ChatColor[] styles = null;
|
||||
public String clickActionName = null;
|
||||
public String clickActionData = null;
|
||||
public String hoverActionName = null;
|
||||
public String hoverActionData = null;
|
||||
public final String text;
|
||||
|
||||
public MessagePart(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public JsonWriter writeJson(final JsonWriter json) throws IOException {
|
||||
json.beginObject().name("text").value(text);
|
||||
if (color != null) {
|
||||
json.name("color").value(color.name().toLowerCase());
|
||||
}
|
||||
if (styles != null) {
|
||||
for (final ChatColor style : styles) {
|
||||
json.name(style == ChatColor.UNDERLINE ? "underlined" : style.name().toLowerCase()).value(true);
|
||||
}
|
||||
}
|
||||
if (clickActionName != null && clickActionData != null) {
|
||||
json.name("clickEvent")
|
||||
.beginObject()
|
||||
.name("action").value(clickActionName)
|
||||
.name("value").value(clickActionData)
|
||||
.endObject();
|
||||
}
|
||||
if (hoverActionName != null && hoverActionData != null) {
|
||||
json.name("hoverEvent")
|
||||
.beginObject()
|
||||
.name("action").value(hoverActionName)
|
||||
.name("value").value(hoverActionData)
|
||||
.endObject();
|
||||
}
|
||||
return json.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
@ -121,10 +120,5 @@ public class NmsManagerImpl implements NMSManager {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessage newFancyMessage(String text) {
|
||||
return new FancyMessageImpl(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,170 +0,0 @@
|
||||
package com.gmail.filoghost.holographicdisplays.nms.v1_9_R2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_9_R2.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_9_R2.PacketPlayOutChat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
|
||||
public class FancyMessageImpl implements FancyMessage {
|
||||
|
||||
private List<MessagePart> messageParts;
|
||||
|
||||
public FancyMessageImpl(String firstPartText) {
|
||||
messageParts = new ArrayList<MessagePart>();
|
||||
messageParts.add(new MessagePart(firstPartText));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl color(ChatColor color) {
|
||||
if (!color.isColor()) {
|
||||
throw new IllegalArgumentException(color.name() + " is not a color");
|
||||
}
|
||||
latest().color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl style(ChatColor... styles) {
|
||||
for (ChatColor style : styles) {
|
||||
if (!style.isFormat()) {
|
||||
throw new IllegalArgumentException(style.name() + " is not a style");
|
||||
}
|
||||
}
|
||||
latest().styles = styles;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl file(String path) {
|
||||
onClick("open_file", path);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl link(String url) {
|
||||
onClick("open_url", url);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl suggest(String command) {
|
||||
onClick("suggest_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl command(String command) {
|
||||
onClick("run_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl tooltip(String text) {
|
||||
onHover("show_text", text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessageImpl then(Object obj) {
|
||||
messageParts.add(new MessagePart(obj.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter json = new JsonWriter(stringWriter);
|
||||
|
||||
try {
|
||||
if (messageParts.size() == 1) {
|
||||
latest().writeJson(json);
|
||||
} else {
|
||||
json.beginObject().name("text").value("").name("extra").beginArray();
|
||||
for (MessagePart part : messageParts) {
|
||||
part.writeJson(json);
|
||||
}
|
||||
json.endArray().endObject();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("invalid message");
|
||||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Player player) {
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(toJSONString())));
|
||||
}
|
||||
|
||||
private MessagePart latest() {
|
||||
return messageParts.get(messageParts.size() - 1);
|
||||
}
|
||||
|
||||
private void onClick(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.clickActionName = name;
|
||||
latest.clickActionData = data;
|
||||
}
|
||||
|
||||
private void onHover(String name, String data) {
|
||||
MessagePart latest = latest();
|
||||
latest.hoverActionName = name;
|
||||
latest.hoverActionData = data;
|
||||
}
|
||||
|
||||
static class MessagePart {
|
||||
|
||||
public ChatColor color = null;
|
||||
public ChatColor[] styles = null;
|
||||
public String clickActionName = null;
|
||||
public String clickActionData = null;
|
||||
public String hoverActionName = null;
|
||||
public String hoverActionData = null;
|
||||
public final String text;
|
||||
|
||||
public MessagePart(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public JsonWriter writeJson(final JsonWriter json) throws IOException {
|
||||
json.beginObject().name("text").value(text);
|
||||
if (color != null) {
|
||||
json.name("color").value(color.name().toLowerCase());
|
||||
}
|
||||
if (styles != null) {
|
||||
for (final ChatColor style : styles) {
|
||||
json.name(style == ChatColor.UNDERLINE ? "underlined" : style.name().toLowerCase()).value(true);
|
||||
}
|
||||
}
|
||||
if (clickActionName != null && clickActionData != null) {
|
||||
json.name("clickEvent")
|
||||
.beginObject()
|
||||
.name("action").value(clickActionName)
|
||||
.name("value").value(clickActionData)
|
||||
.endObject();
|
||||
}
|
||||
if (hoverActionName != null && hoverActionData != null) {
|
||||
json.name("hoverEvent")
|
||||
.beginObject()
|
||||
.name("action").value(hoverActionName)
|
||||
.name("value").value(hoverActionData)
|
||||
.endObject();
|
||||
}
|
||||
return json.endObject();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.FancyMessage;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.ItemPickupManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSArmorStand;
|
||||
@ -121,10 +120,5 @@ public class NmsManagerImpl implements NMSManager {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FancyMessage newFancyMessage(String text) {
|
||||
return new FancyMessageImpl(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,11 +3,9 @@ package com.gmail.filoghost.holographicdisplays.commands.main.subs;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.Colors;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.CommandValidator;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.Strings;
|
||||
@ -18,6 +16,12 @@ import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
|
||||
import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Utils;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class EditCommand extends HologramSubCommand {
|
||||
|
||||
private HologramsCommandHandler mainCommandHandler;
|
||||
@ -59,11 +63,12 @@ public class EditCommand extends HologramSubCommand {
|
||||
help.add(Colors.SECONDARY_SHADOW + tutLine);
|
||||
}
|
||||
|
||||
HolographicDisplays.getNMSManager().newFancyMessage(usage)
|
||||
((Player) sender).spigot().sendMessage(new ComponentBuilder(usage)
|
||||
.color(ChatColor.AQUA)
|
||||
.suggest(usage)
|
||||
.tooltip(Utils.join(help, "\n"))
|
||||
.send((Player) sender);
|
||||
.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, usage))
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Utils.join(help, "\n"))))
|
||||
.create());
|
||||
|
||||
} else {
|
||||
sender.sendMessage(Colors.PRIMARY + usage);
|
||||
}
|
||||
@ -71,7 +76,7 @@ public class EditCommand extends HologramSubCommand {
|
||||
}
|
||||
|
||||
if (CommandValidator.isPlayerSender(sender)) {
|
||||
HelpCommand.sendHoverTip(sender);
|
||||
HelpCommand.sendHoverTip((Player) sender);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,9 @@ package com.gmail.filoghost.holographicdisplays.commands.main.subs;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.Colors;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.CommandValidator;
|
||||
import com.gmail.filoghost.holographicdisplays.commands.Strings;
|
||||
@ -15,6 +13,13 @@ import com.gmail.filoghost.holographicdisplays.commands.main.HologramsCommandHan
|
||||
import com.gmail.filoghost.holographicdisplays.exception.CommandException;
|
||||
import com.gmail.filoghost.holographicdisplays.util.Utils;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder.FormatRetention;
|
||||
|
||||
public class HelpCommand extends HologramSubCommand {
|
||||
|
||||
private HologramsCommandHandler mainCommandHandler;
|
||||
@ -52,11 +57,11 @@ public class HelpCommand extends HologramSubCommand {
|
||||
help.add(Colors.SECONDARY_SHADOW + tutLine);
|
||||
}
|
||||
|
||||
HolographicDisplays.getNMSManager().newFancyMessage(usage)
|
||||
.color(ChatColor.AQUA)
|
||||
.suggest(usage)
|
||||
.tooltip(Utils.join(help, "\n"))
|
||||
.send((Player) sender);
|
||||
((Player) sender).spigot().sendMessage(new ComponentBuilder(usage)
|
||||
.color(ChatColor.AQUA)
|
||||
.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, usage))
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Utils.join(help, "\n"))))
|
||||
.create());
|
||||
|
||||
} else {
|
||||
sender.sendMessage(Colors.PRIMARY + usage);
|
||||
@ -65,21 +70,21 @@ public class HelpCommand extends HologramSubCommand {
|
||||
}
|
||||
|
||||
if (CommandValidator.isPlayerSender(sender)) {
|
||||
sendHoverTip(sender);
|
||||
sendHoverTip((Player) sender);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendHoverTip(CommandSender sender) {
|
||||
sender.sendMessage("");
|
||||
HolographicDisplays.getNMSManager().newFancyMessage("TIP").style(ChatColor.BOLD).color(ChatColor.YELLOW)
|
||||
.then(" Try to ").color(ChatColor.GRAY)
|
||||
.then("hover").color(ChatColor.WHITE).style(ChatColor.ITALIC, ChatColor.UNDERLINE)
|
||||
.tooltip(ChatColor.LIGHT_PURPLE + "Hover on the commands to get info about them.")
|
||||
.then(" or ").color(ChatColor.GRAY)
|
||||
.then("click").color(ChatColor.WHITE).style(ChatColor.ITALIC, ChatColor.UNDERLINE)
|
||||
.tooltip(ChatColor.LIGHT_PURPLE + "Click on the commands to insert them in the chat.")
|
||||
.then(" on the commands!").color(ChatColor.GRAY)
|
||||
.send((Player) sender);
|
||||
public static void sendHoverTip(Player player) {
|
||||
player.sendMessage("");
|
||||
player.spigot().sendMessage(new ComponentBuilder("TIP").color(ChatColor.YELLOW).bold(true)
|
||||
.append(" Try to ", FormatRetention.NONE).color(ChatColor.GRAY)
|
||||
.append("hover").color(ChatColor.WHITE).italic(true).underlined(true)
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColor.LIGHT_PURPLE + "Hover on the commands to get info about them.")))
|
||||
.append(" or ", FormatRetention.NONE).color(ChatColor.GRAY)
|
||||
.append("click").color(ChatColor.WHITE).italic(true).underlined(true)
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColor.LIGHT_PURPLE + "Click on the commands to insert them in the chat.")))
|
||||
.append(" on the commands!", FormatRetention.NONE).color(ChatColor.GRAY)
|
||||
.create());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user