Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1914174e42 | ||
|
|
4a7f37451a | ||
|
|
4d90a80788 | ||
|
|
3713ad41af | ||
|
|
b8ba6eac69 | ||
|
|
25f8b585b0 | ||
|
|
746b3b58a0 | ||
|
|
89f61e0178 | ||
|
|
9d7de56889 | ||
|
|
5fb210e841 | ||
|
|
0a9af0d430 | ||
|
|
37681d8b27 | ||
|
|
79e03e97bd | ||
|
|
db08be3fa8 | ||
|
|
4133f30701 | ||
|
|
08434a5df2 | ||
|
|
ae825569cf | ||
|
|
1a4f95cd80 | ||
|
|
4edc061969 |
No files matched your search
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.dadus33</groupId>
|
||||
<artifactId>ChatItem</artifactId>
|
||||
<version>2.6</version>
|
||||
<version>2.6.1</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -61,6 +61,10 @@
|
||||
<id>mvdw-software</id>
|
||||
<url>http://repo.mvdw-software.be/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>essentials-snapshots</id>
|
||||
<url>https://repo.essentialsx.net/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
@@ -192,6 +196,12 @@
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.essentialsx</groupId>
|
||||
<artifactId>EssentialsX</artifactId>
|
||||
<version>2.20.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package me.dadus33.chatitem;
|
||||
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class C {
|
||||
|
||||
public static TextComponent text(String s) {
|
||||
return LegacyComponentSerializer.legacySection().deserialize(s);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import me.dadus33.chatitem.commands.ChatItemCommand;
|
||||
import me.dadus33.chatitem.hook.ChatControlSupport;
|
||||
import me.dadus33.chatitem.hook.ChatManagerSupport;
|
||||
import me.dadus33.chatitem.hook.ecoenchants.EcoEnchantsSupport;
|
||||
import me.dadus33.chatitem.hook.placeholders.EssentialsPlaceholdersHook;
|
||||
import me.dadus33.chatitem.hook.placeholders.IPlaceholders;
|
||||
import me.dadus33.chatitem.hook.placeholders.MVdWPlaceholderAPIHook;
|
||||
import me.dadus33.chatitem.hook.placeholders.OwnPlaceholder;
|
||||
@@ -75,13 +76,14 @@ public class ChatItem extends JavaPlugin {
|
||||
pl.saveDefaultConfig();
|
||||
pl.reloadConfig();
|
||||
pl.storage = new Storage(pl.getConfig());
|
||||
pl.chooseManagers();
|
||||
//pl.chooseManagers();
|
||||
Translation.load(pl);
|
||||
InvShower.getInvShower().clear();
|
||||
if(sender != null) {
|
||||
if (!pl.storage.messageReload.isEmpty())
|
||||
sender.sendMessage(pl.storage.messageReload);
|
||||
}
|
||||
ChatManager.setTesting(null);
|
||||
}
|
||||
|
||||
public static ChatItem getInstance() {
|
||||
@@ -189,6 +191,10 @@ public class ChatItem extends JavaPlugin {
|
||||
plugins.add("PlaceholderAPI");
|
||||
PLACEHOLDERS.add(new PlaceholderAPIHook());
|
||||
}
|
||||
if (pm.isPluginEnabled("Essentials")) {
|
||||
plugins.add("Essentials");
|
||||
PLACEHOLDERS.add(new EssentialsPlaceholdersHook());
|
||||
}
|
||||
if (pm.isPluginEnabled("MVdWPlaceholderAPI")) {
|
||||
plugins.add("MVdWPlaceholderAPI");
|
||||
PLACEHOLDERS.add(new MVdWPlaceholderAPIHook());
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.google.gson.JsonParser;
|
||||
|
||||
import me.dadus33.chatitem.utils.Utils;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Translation {
|
||||
|
||||
private static File folder;
|
||||
@@ -81,7 +82,6 @@ public class Translation {
|
||||
pl.getLogger().info("Loaded translation for " + lang + ".");
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static String get(ItemStack item) {
|
||||
String key = (item.getType().isBlock() ? "block" : "item") + ".minecraft." + item.getType().name().toLowerCase();
|
||||
if (messages != null && messages.has(key)) {
|
||||
@@ -90,6 +90,15 @@ public class Translation {
|
||||
ChatItem.debug("Failed to find translation for " + key);
|
||||
return legacy.getString(item.getType().name() + "." + item.getDurability(), item.getType().name().toLowerCase().replace("_", " "));
|
||||
}
|
||||
|
||||
public static String getOr(ItemStack item, String def) {
|
||||
String key = (item.getType().isBlock() ? "block" : "item") + ".minecraft." + item.getType().name().toLowerCase();
|
||||
if (messages != null && messages.has(key)) {
|
||||
return messages.get(key).getAsString();
|
||||
} else
|
||||
ChatItem.debug("Failed to find translation for " + key);
|
||||
return legacy.getString(item.getType().name() + "." + item.getDurability(), def);
|
||||
}
|
||||
|
||||
protected void thisMethodShouldNotBeUsed_InsteadToUpdateLangFileFromLocalInstall() throws Exception {
|
||||
File dir = new File("dir/to/result");
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ChatEventListener implements Listener {
|
||||
String oldMsg = e.getMessage();
|
||||
ItemSlot slot = ItemSlot.getItemSlotFromMessage(e.getMessage());
|
||||
if (slot == null) {
|
||||
ChatItem.debug("(v1) not found placeholders in: " + e.getMessage());
|
||||
ChatItem.debug("(general) not found placeholders in: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
ChatAction action = ChatManager.getChatAction(slot, p);
|
||||
@@ -49,7 +49,7 @@ public class ChatEventListener implements Listener {
|
||||
}
|
||||
|
||||
Chat c = Chat.create(p, oldMsg, action);
|
||||
ChatItem.debug("(v1) Set placeholder to message " + c);
|
||||
ChatItem.debug("(general) Set placeholder to message " + c);
|
||||
e.setMessage(s.replace(Character.toString(ChatManager.SEPARATOR), SEPARATOR + Integer.toString(c.getId()) + SEPARATOR_END));
|
||||
e.setFormat(e.getFormat().replace(oldMsg, e.getMessage())); // set own message for plugin that already put the message into the format
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public abstract class ChatManager {
|
||||
List<String> lines = new ArrayList<>();
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
lines.add(meta.hasDisplayName() ? meta.getDisplayName() : NamerManager.getName(viewer, item, ChatItem.getInstance().getStorage()));
|
||||
lines.add(NamerManager.getName(viewer, item, ChatItem.getInstance().getStorage()));
|
||||
if (meta.hasEnchants()) {
|
||||
meta.getEnchants().forEach((enchant, lvl) -> {
|
||||
lines.add(Colors.RESET + Utils.getEnchantName(enchant) + " " + Utils.toRoman(lvl));
|
||||
@@ -215,6 +215,21 @@ public abstract class ChatManager {
|
||||
return styleItem(viewer, item, c);
|
||||
}
|
||||
|
||||
public static String getNameForChatAction(Player viewer, Chat chat, Storage c) {
|
||||
ChatAction action = chat.getAction();
|
||||
if (action.isItem()) {
|
||||
ItemStack item = action.getItem();
|
||||
if (ItemUtils.isEmpty(item)) {
|
||||
if (c.handDisabled)
|
||||
return ItemSlot.HAND.getPlaceholders().get(0);
|
||||
else
|
||||
return getHandName(chat);
|
||||
}
|
||||
return styleItem(viewer, item, c);
|
||||
}
|
||||
return Messages.getMessage(action.getSlot().name().toLowerCase() + ".chat", "%cible%", action.getOrigin().getName());
|
||||
}
|
||||
|
||||
public static String getNameForChatAction(Player viewer, ChatAction action, Storage c) {
|
||||
if (action.isItem()) {
|
||||
ItemStack item = action.getItem();
|
||||
@@ -280,7 +295,7 @@ public abstract class ChatManager {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (item != null && item.getType().equals(Material.AIR)) {
|
||||
if (item != null && item.getType().equals(Material.AIR) && slot.isBasic()) {
|
||||
if (slot.isDenyIfNoItem()) {
|
||||
if (e != null)
|
||||
e.setCancelled(true);
|
||||
|
||||
@@ -50,7 +50,7 @@ public interface IComponentManager {
|
||||
if (Utils.isBeforeChatJson(viewer))
|
||||
message = JSONManipulator.getInstance().parseEmpty(chat, json, chat.getAction().isItem() ? ChatManager.getMaxLinesFromItem(viewer, chat.getAction().getItem()) : new ArrayList<>(), chat.getPlayer());
|
||||
else
|
||||
message = JSONManipulator.getInstance().parse(chat, json, chat.getAction(), ChatManager.getNameForChatAction(viewer, chat.getAction(), c));
|
||||
message = JSONManipulator.getInstance().parse(chat, json, chat.getAction(), ChatManager.getNameForChatAction(viewer, chat, c));
|
||||
if (message != null) {
|
||||
ChatItem.debug("(v1) Writing message: " + message);
|
||||
writeJson(packet, message);
|
||||
@@ -77,7 +77,14 @@ public interface IComponentManager {
|
||||
}
|
||||
|
||||
private Chat search() {
|
||||
JsonObject jsonObj = JsonParser.parseString(json).getAsJsonObject();
|
||||
JsonObject jsonObj;
|
||||
try {
|
||||
jsonObj = JsonParser.parseString(json).getAsJsonObject();
|
||||
} catch (Exception e) {
|
||||
if(searchInString(json))
|
||||
return getWithId();
|
||||
return null;
|
||||
}
|
||||
if (jsonObj.has("extra")) {
|
||||
if (searchInExtra(jsonObj.getAsJsonArray("extra"))) {
|
||||
return getWithId();
|
||||
|
||||
+28
-13
@@ -7,7 +7,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.Storage;
|
||||
@@ -15,11 +14,12 @@ import me.dadus33.chatitem.chatmanager.Chat;
|
||||
import me.dadus33.chatitem.chatmanager.ChatAction;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.basecomp.IComponentManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.json.JSONManipulator;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.ChatItemPacket;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketContent.ContentModifier;
|
||||
import me.dadus33.chatitem.hook.DiscordSrvSupport;
|
||||
import me.dadus33.chatitem.utils.Messages;
|
||||
import me.dadus33.chatitem.utils.PacketUtils;
|
||||
import me.dadus33.chatitem.utils.ReflectionUtils;
|
||||
import me.dadus33.chatitem.utils.Utils;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.nbt.api.BinaryTagHolder;
|
||||
@@ -47,15 +47,31 @@ public class AdventureComponentManager implements IComponentManager {
|
||||
public void writeJson(ChatItemPacket packet, String json) {
|
||||
}
|
||||
|
||||
public void writeComponentToPacket(ChatItemPacket packet, Component next) {
|
||||
if(packet.getContent().getSpecificModifier(Component.class).readSafely(0) == null) { // hard way
|
||||
ReflectionUtils.setField(ReflectionUtils.getObject(packet.getPacket(), "unsignedContent"), "adventure", next);
|
||||
} else { // easy way
|
||||
packet.getContent().getSpecificModifier(Component.class).write(0, next);
|
||||
}
|
||||
}
|
||||
|
||||
public Component getComponentFromPacket(ChatItemPacket packet) {
|
||||
Component comp = packet.getContent().getSpecificModifier(Component.class).readSafely(0);
|
||||
if (comp == null && packet.getPacketName().equalsIgnoreCase("ClientboundPlayerChatPacket")) { // if can get one more
|
||||
comp = (Component) ReflectionUtils.getObject(ReflectionUtils.getObject(packet.getPacket(), "unsignedContent"), "adventure");
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBaseComponentAsJSON(ChatItemPacket packet) {
|
||||
Component comp = packet.getContent().getSpecificModifier(Component.class).readSafely(0);
|
||||
if (comp == null)
|
||||
Component comp = getComponentFromPacket(packet);
|
||||
if(comp == null) // if comp stay null
|
||||
return null;
|
||||
try {
|
||||
String json = GsonComponentSerializer.gson().serialize(comp);
|
||||
JsonObject jsonObj = JsonParser.parseString(json).getAsJsonObject();
|
||||
ChatItem.debug("AdventureJSON : " + json);
|
||||
JsonObject jsonObj = JSONManipulator.parseOrGet(json);
|
||||
if (jsonObj.has("with")) {
|
||||
JsonObject next = new JsonObject();
|
||||
next.add("extra", jsonObj.get("with"));
|
||||
@@ -73,7 +89,7 @@ public class AdventureComponentManager implements IComponentManager {
|
||||
ChatAction action = chat.getAction();
|
||||
if (action.isItem()) {
|
||||
ItemStack item = action.getItem();
|
||||
String itemName = ChatManager.getNameOfItem(chat.getPlayer(), item, viewer, c);
|
||||
String itemName = ChatManager.getNameForChatAction(viewer, chat, c);
|
||||
ChatItem.debug("NBT tag: " + PacketUtils.getNbtTag(item));
|
||||
HoverEvent<?> hover;
|
||||
if(Utils.IS_PAPER)
|
||||
@@ -93,24 +109,23 @@ public class AdventureComponentManager implements IComponentManager {
|
||||
c.tooltipHand.forEach(s -> builder.append(Component.text(s)));
|
||||
ChatAction action = chat.getAction();
|
||||
if (action.isItem()) {
|
||||
return manage(viewer, chat, packet, ChatManager.getHandName(chat), HoverEvent.showText(builder), null);
|
||||
return manage(viewer, chat, packet, ChatManager.getNameForChatAction(viewer, chat, c), HoverEvent.showText(builder), null);
|
||||
}
|
||||
return manage(viewer, chat, packet, Messages.getMessage(action.getSlot().name().toLowerCase() + ".chat", "%cible%", chat.getPlayer().getName()),
|
||||
HoverEvent.showText(Component.text(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover", "%cible%", chat.getPlayer().getName()))),
|
||||
ClickEvent.runCommand(action.getCommand()));
|
||||
}
|
||||
|
||||
private Object manage(Player p, Chat chat, ChatItemPacket packet, String replacement, HoverEvent<?> hover, ClickEvent click) {
|
||||
ContentModifier<Component> modifier = packet.getContent().getSpecificModifier(Component.class);
|
||||
Component comp = modifier.readSafely(0);
|
||||
private Object manage(Player viewer, Chat chat, ChatItemPacket packet, String replacement, HoverEvent<?> hover, ClickEvent click) {
|
||||
Component comp = getComponentFromPacket(packet);
|
||||
if (comp == null) {
|
||||
ChatItem.debug("The component is null.");
|
||||
return null;
|
||||
}
|
||||
comp = comp.replaceText(TextReplacementConfig.builder().matchLiteral(ChatManager.SEPARATOR + "" + chat.getId() + ChatManager.SEPARATOR_END).replacement(Component.text(replacement).hoverEvent(hover).clickEvent(click)).build());
|
||||
if(ChatItem.discordSrvSupport && DiscordSrvSupport.isSendingMessage() && p == chat.getPlayer())
|
||||
if(ChatItem.discordSrvSupport && DiscordSrvSupport.isSendingMessage() && viewer == chat.getPlayer())
|
||||
DiscordSrvSupport.sendChatMessage(chat.getPlayer(), comp, null);
|
||||
modifier.write(0, comp);
|
||||
return null; // send by manager
|
||||
viewer.sendMessage(comp);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -66,9 +66,9 @@ public class StringComponentManager implements IComponentManager {
|
||||
public Object manageContent(Player viewer, Chat chat, ChatItemPacket packet, String json, Storage c) throws Exception {
|
||||
ChatAction action = chat.getAction();
|
||||
if (action.isItem())
|
||||
return manage(viewer, chat, packet, ChatManager.getNameOfItem(chat.getPlayer(), action.getItem(), viewer, c), Utils.createItemHover(action.getItem(), viewer), null);
|
||||
return manage(viewer, chat, packet, ChatManager.getNameForChatAction(viewer, chat, c), Utils.createItemHover(action.getItem(), viewer), null);
|
||||
else
|
||||
return manage(viewer, chat, packet, ChatManager.getNameForChatAction(viewer, action, c),
|
||||
return manage(viewer, chat, packet, ChatManager.getNameForChatAction(viewer, chat, c),
|
||||
Utils.createTextHover(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover", "%cible%", chat.getPlayer().getName())), Utils.createRunCommand(action.getCommand()));
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,10 @@ public class JSONManipulator {
|
||||
|
||||
private JsonArray classicTooltip;
|
||||
|
||||
private JsonObject parseOrGet(String json) {
|
||||
public static JsonObject parseOrGet(String json) {
|
||||
if(json.startsWith("\"") && json.endsWith("\"")) {// seems to be simple line
|
||||
return JsonParser.parseString("{\"text\":" + json + "}").getAsJsonObject();
|
||||
}
|
||||
try {
|
||||
return JsonParser.parseString(json).getAsJsonObject();
|
||||
} catch (Exception e) {
|
||||
@@ -99,6 +102,7 @@ public class JSONManipulator {
|
||||
wrapper.add("extra", use); // add it only if
|
||||
if (!wrapper.has("text"))
|
||||
wrapper.addProperty("text", ""); // The text field is compulsory, even if it's empty
|
||||
ChatItem.debug("Wrapper " + wrapper + " > " + use);
|
||||
wrapper.add("hoverEvent", hover);
|
||||
|
||||
if (obj.size() == 1 && obj.has("text")) {
|
||||
@@ -118,7 +122,7 @@ public class JSONManipulator {
|
||||
public String parseEmpty(Chat chat, String json, List<String> tooltip, Player sender) {
|
||||
JsonObject obj = parseOrGet(json);
|
||||
JsonArray array = obj.has("extra") ? obj.getAsJsonArray("extra") : new JsonArray();
|
||||
JsonArray use = Translator.toJson(ChatManager.getNameForChatAction(chat.getPlayer(), chat.getAction(), ChatItem.getInstance().getStorage()).replace("{name}", sender.getName()).replace("{display-name}", sender.getDisplayName()));
|
||||
JsonArray use = Translator.toJson(ChatManager.getNameForChatAction(chat.getPlayer(), chat, ChatItem.getInstance().getStorage()).replace("{name}", sender.getName()).replace("{display-name}", sender.getDisplayName()));
|
||||
JsonObject hover = JsonParser.parseString("{\"action\":\"show_text\", \"value\": \"\"}").getAsJsonObject();
|
||||
|
||||
StringBuilder oneLineTooltip = new StringBuilder("");
|
||||
@@ -146,32 +150,37 @@ public class JSONManipulator {
|
||||
|
||||
private JsonArray parseArray(JsonArray arr, JsonElement tooltip) {
|
||||
JsonArray replacer = new JsonArray();
|
||||
boolean isComplex = false;
|
||||
boolean separator = false;
|
||||
for (int i = 0; i < arr.size(); ++i) {
|
||||
JsonElement element = arr.get(i);
|
||||
ChatItem.debug("[JsonManipulator] Element: " + element.toString());
|
||||
if (element.isJsonNull()) {
|
||||
if(element.isJsonNull())
|
||||
continue;
|
||||
} else if (element.isJsonObject()) {
|
||||
isComplex = true;
|
||||
if(separator) {
|
||||
if(ChatManager.containsSeparatorEnd(element.toString()))
|
||||
separator = false;
|
||||
continue;
|
||||
}
|
||||
if (element.isJsonObject()) {
|
||||
JsonElement text = element.getAsJsonObject().get("text");
|
||||
if(text != null && ChatManager.containsSeparator(text.getAsString())) {
|
||||
if(!ChatManager.containsSeparatorEnd(text.getAsString())) // if the separator doesn't end in the same string as it's begin
|
||||
separator = true;
|
||||
}
|
||||
ChatItem.debug("Parsing object " + element.toString());
|
||||
addParsedJsonObjectToArray(element.getAsJsonObject(), replacer, tooltip);
|
||||
} else if (element.isJsonArray()) {
|
||||
isComplex = true;
|
||||
JsonArray jar = element.getAsJsonArray();
|
||||
if (jar.size() != 0) {
|
||||
jar = parseArray(element.getAsJsonArray(), tooltip);
|
||||
replacer.set(i, jar);
|
||||
}
|
||||
} else if (element.isJsonPrimitive() && isComplex) {
|
||||
} else if(element.isJsonPrimitive()) {
|
||||
if(ChatManager.containsSeparator(element.getAsString())) {
|
||||
if(!ChatManager.containsSeparatorEnd(element.getAsString())) // if the separator doesn't end in the same string as it's begin
|
||||
separator = true;
|
||||
addParsedStringToArray(element.getAsString(), replacer, element, tooltip);
|
||||
} else
|
||||
ChatItem.debug("[JSONManipulator] Put " + element + " to trash as it's primitive with complex things");
|
||||
// ignore
|
||||
} else {
|
||||
addParsedStringToArray(element.getAsString(), replacer, element, tooltip);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return replacer;
|
||||
}
|
||||
@@ -219,14 +228,19 @@ public class JSONManipulator {
|
||||
rep.add(o);
|
||||
return;
|
||||
}
|
||||
ChatItem.debug("[JSONManipulator] Parsed string " + msg + ", rep: " + rep);
|
||||
String current = "";
|
||||
boolean wasSep = false;
|
||||
for (String parts : msg.split("")) {
|
||||
if (ChatManager.equalsSeparator(parts)) {
|
||||
if (!current.isEmpty()) {
|
||||
JsonObject jsonObj = o.getAsJsonObject().deepCopy();
|
||||
jsonObj.addProperty("text", current); // edit text
|
||||
rep.add(jsonObj); // add with all basic coloring things
|
||||
if(o.isJsonObject()) {
|
||||
JsonObject jsonObj = o.getAsJsonObject().deepCopy();
|
||||
jsonObj.addProperty("text", current); // edit text
|
||||
rep.add(jsonObj); // add with all basic coloring things
|
||||
} else {
|
||||
rep.add(current);
|
||||
}
|
||||
current = "";
|
||||
}
|
||||
rep.add(tooltip);
|
||||
@@ -239,9 +253,13 @@ public class JSONManipulator {
|
||||
}
|
||||
}
|
||||
if (!current.isEmpty()) {
|
||||
JsonObject jsonObj = o.getAsJsonObject().deepCopy();
|
||||
jsonObj.addProperty("text", current); // edit text
|
||||
rep.add(jsonObj); // add with all basic coloring things
|
||||
if(o.isJsonObject()) {
|
||||
JsonObject jsonObj = o.getAsJsonObject().deepCopy();
|
||||
jsonObj.addProperty("text", current); // edit text
|
||||
rep.add(jsonObj); // add with all basic coloring things
|
||||
} else {
|
||||
rep.add(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,10 +46,12 @@ public class Translator {
|
||||
if(!text.isEmpty()) // ignore this if no text before
|
||||
text += ColorManager.getColorString(colorCode);
|
||||
colorCode = "x";
|
||||
} else if(!colorCode.isEmpty() && !colorCode.startsWith("x")) { // already color and not hex
|
||||
text += ColorManager.COLOR_CHAR + colorCode; // add the color to text
|
||||
colorCode = args + "";
|
||||
} else
|
||||
colorCode += args; // a color by itself
|
||||
} else {
|
||||
waiting = false;
|
||||
if(!colorCode.isEmpty()) { // manage color
|
||||
if(colorCode.startsWith("x") && colorCode.length() == 7) { // hex color code
|
||||
next.addProperty("color", ColorManager.getColor(colorCode).getName());
|
||||
@@ -58,20 +60,21 @@ public class Translator {
|
||||
text += ColorManager.getColor(colorCode);
|
||||
else
|
||||
next.addProperty("color", ColorManager.getColor(colorCode).getName());
|
||||
} else if(!text.isEmpty())// no text before -> color will be used as "color"
|
||||
} else if(!text.isEmpty()) // no text before -> color will be used as "color"
|
||||
text += ColorManager.getColorString(colorCode);
|
||||
|
||||
ChatItem.debug("Add " + colorCode + " to " + text + ", msg: " + message);
|
||||
ChatItem.debug("[Translator] Add color code " + colorCode + " to " + text + args + ", msg: " + message);
|
||||
colorCode = "";
|
||||
}
|
||||
// basic text, not waiting for code after '§'
|
||||
text += args;
|
||||
}
|
||||
}
|
||||
if(!text.isEmpty() || message.isEmpty()) {
|
||||
if(!next.has("color") || colorCode.length() == 1) // if no color or a color that can override it
|
||||
next.addProperty("color", (colorCode.length() == 1 ? ColorManager.getColor(colorCode).getName() : "white"));
|
||||
if(!text.isEmpty() || message.isEmpty() || next.size() > 0) {
|
||||
next.addProperty("text", text);
|
||||
if(!next.has("color"))
|
||||
next.addProperty("color", "white");
|
||||
ChatItem.debug("[Translator] Added content " + next + " to message" + message);
|
||||
message.add(next);
|
||||
}
|
||||
return message;
|
||||
|
||||
@@ -51,7 +51,6 @@ public class ChatPacketManager extends PacketHandler {
|
||||
tryRegister(new AdventureComponentManager());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
ChatItem.getInstance().getLogger().info("Loaded " + componentManager.size() + " getter for base components.");
|
||||
ChatItem.debug("ComponentManager: " + String.join(", ", componentManager.stream().map(IComponentManager::getClass).map(Class::getSimpleName).collect(Collectors.toList())));
|
||||
}
|
||||
|
||||
@@ -143,7 +142,7 @@ public class ChatPacketManager extends PacketHandler {
|
||||
tooltip.addAll(getStorage().tooltipBuggedClient);
|
||||
} else
|
||||
tooltip = new ArrayList<>();
|
||||
message = JSONManipulator.getInstance().parseEmpty(chat, getter.getBaseComponentAsJSON(e), tooltip, chat.getPlayer());
|
||||
message = JSONManipulator.getInstance().parseEmpty(chat, fjson, tooltip, chat.getPlayer());
|
||||
if (message != null) {
|
||||
getter.writeJson(e, message);
|
||||
}
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ public class ChannelInboundHandler extends ChannelInboundHandlerAdapter {
|
||||
int possibleProtocol = ints.readSafely(0, 0);
|
||||
if(possibleProtocol == Bukkit.getPort())
|
||||
possibleProtocol = ints.readSafely(1, 0);
|
||||
if(possibleProtocol == -1 || possibleProtocol == 255)
|
||||
if(possibleProtocol == -1 || possibleProtocol == 255 || possibleProtocol == Bukkit.getPort())
|
||||
possibleProtocol = ints.readSafely(2, 0);
|
||||
packetManager.protocolVersionPerChannel.put(channel, possibleProtocol);
|
||||
}
|
||||
|
||||
@@ -57,10 +57,13 @@ public class ChatListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Player p = e.getPlayer();
|
||||
String targetReplace = ChatManager.SEPARATOR + "";
|
||||
if(ChatManager.containsSeparator(e.getMessage())) { // fix for v1
|
||||
Chat chat = Chat.getFrom(e.getMessage());
|
||||
if(chat != null)
|
||||
if(chat != null) {
|
||||
targetReplace = ChatManager.SEPARATOR + "" + chat.getId() + ChatManager.SEPARATOR_END;
|
||||
e.setMessage(ChatManager.replaceSeparator(chat, e.getMessage(), chat.getSlot().getPlaceholders().get(0)));
|
||||
}
|
||||
}
|
||||
ItemSlot slot = ItemSlot.getItemSlotFromMessage(e.getMessage());
|
||||
if (slot == null) { // if not found
|
||||
@@ -71,11 +74,12 @@ public class ChatListener implements Listener {
|
||||
if(!ChatManager.canUsePlaceholder(p, action.getItem(), slot, e))
|
||||
return;
|
||||
e.setCancelled(true);
|
||||
String format = e.getFormat();
|
||||
String format = e.getFormat().replace(targetReplace, slot.getPlaceholders().get(0));
|
||||
ChatItem.debug("(v2) Using format: " + format + " and message: " + e.getMessage());
|
||||
String defMsg = slot.replacePlaceholdersToSeparator(e.getMessage());
|
||||
if (Utils.countMatches(defMsg, Character.toString(ChatManager.SEPARATOR)) > getStorage().limit) {
|
||||
if (!getStorage().messageLimit.isEmpty())
|
||||
p.sendMessage(getStorage().messageLimit);
|
||||
if (Utils.countMatches(defMsg, Character.toString(ChatManager.SEPARATOR)) > c.limit) {
|
||||
if (!c.messageLimit.isEmpty())
|
||||
p.sendMessage(c.messageLimit);
|
||||
return;
|
||||
}
|
||||
String msg;
|
||||
@@ -90,7 +94,7 @@ public class ChatListener implements Listener {
|
||||
if (ChatItem.discordSrvSupport)
|
||||
DiscordSrvSupport.sendChatMessage(p, defMsg.replace(ChatManager.SEPARATOR + "", itemName), e);
|
||||
Set<Player> recipients = e.getRecipients().isEmpty() ? new HashSet<>(Bukkit.getOnlinePlayers()) : e.getRecipients();
|
||||
ChatItem.debug("Msg: " + ChatItem.replace(p, msg).replace(ChatColor.COLOR_CHAR, '&') + ", format: " + format + " to " + recipients.size() + " players");
|
||||
ChatItem.debug("(v2) Msg: " + ChatItem.replace(p, msg).replace(ChatColor.COLOR_CHAR, '&') + ", format: " + format + " to " + recipients.size() + " players");
|
||||
recipients.forEach((pl) -> ChatItem.getPlatform().sendMessage(pl, p, action, ChatItem.replace(p, msg)));
|
||||
if (c.cooldown > 0 && !p.hasPermission("chatitem.ignore-cooldown"))
|
||||
ChatManager.applyCooldown(p);
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package me.dadus33.chatitem.chatmanager.v3;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import me.dadus33.chatitem.C;
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.ItemSlot;
|
||||
import me.dadus33.chatitem.Storage;
|
||||
@@ -20,6 +22,7 @@ import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.event.HoverEventSource;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
|
||||
public class PaperListener implements Listener {
|
||||
@@ -33,21 +36,22 @@ public class PaperListener implements Listener {
|
||||
public Storage getStorage() {
|
||||
return manage.getStorage();
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onChat(AsyncChatEvent e) {
|
||||
if(ChatManager.isTestingEnabled() && !ChatManager.isTesting("paper"))
|
||||
if (ChatManager.isTestingEnabled() && !ChatManager.isTesting("paper"))
|
||||
return;
|
||||
if(!ChatManager.isSelected("paper"))
|
||||
if (!ChatManager.isSelected("paper"))
|
||||
return;
|
||||
|
||||
Player p = e.getPlayer();
|
||||
Component message = e.message();
|
||||
Component message = e.message();
|
||||
String rawMessage = PlainTextComponentSerializer.plainText().serialize(message);
|
||||
if(ChatManager.containsSeparator(rawMessage)) { // fix for v1
|
||||
if (ChatManager.containsSeparator(rawMessage)) { // fix for v1
|
||||
Chat chat = Chat.getFrom(rawMessage);
|
||||
if(chat != null) {
|
||||
message = message.replaceText(TextReplacementConfig.builder().matchLiteral(ChatManager.SEPARATOR + "" + chat.getId() + ChatManager.SEPARATOR_END).replacement(Component.text(chat.getSlot().getPlaceholders().get(0))).build());
|
||||
if (chat != null) {
|
||||
message = message.replaceText(TextReplacementConfig.builder().matchLiteral(ChatManager.SEPARATOR + "" + chat.getId() + ChatManager.SEPARATOR_END)
|
||||
.replacement(Component.text(chat.getSlot().getPlaceholders().get(0))).build());
|
||||
rawMessage = PlainTextComponentSerializer.plainText().serialize(message);
|
||||
}
|
||||
}
|
||||
@@ -56,20 +60,37 @@ public class PaperListener implements Listener {
|
||||
if (slot == null) // if not found
|
||||
return;
|
||||
ChatAction action = ChatManager.getChatAction(slot, p);
|
||||
if(!ChatManager.canUsePlaceholder(p, action.getItem(), slot, e))
|
||||
if (!ChatManager.canUsePlaceholder(p, action.getItem(), slot, e))
|
||||
return;
|
||||
TextComponent like = Component.text(ChatManager.getNameForChatAction(p, action, getStorage())).hoverEvent(action.isItem() ? action.getItem().asHoverEvent() : HoverEvent.showText(Component.text(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover", "%cible%", p.getName()))));
|
||||
if(action.hasCommand())
|
||||
like.clickEvent(ClickEvent.runCommand(action.getCommand()));
|
||||
for(String s : slot.getPlaceholders())
|
||||
message = message.replaceText(TextReplacementConfig.builder().matchLiteral(s).replacement(like).build());
|
||||
if(ChatItem.getInstance().getConfig().getBoolean("manager-config.paper.send-ourself", false)) {
|
||||
for(Audience a : e.viewers().isEmpty() ? Bukkit.getOnlinePlayers() : e.viewers())
|
||||
a.sendMessage(e.renderer().render(p, p.displayName(), message, a));
|
||||
e.setCancelled(true);
|
||||
} else
|
||||
e.message(message);
|
||||
ChatItem.debug("Changed message to " + PlainTextComponentSerializer.plainText().serialize(message));
|
||||
HoverEventSource<?> hoverEvent = null;
|
||||
if(action.isItem()) {
|
||||
if(!action.getItem().getType().equals(Material.AIR))
|
||||
hoverEvent = action.getItem().asHoverEvent();
|
||||
else {
|
||||
Component t = null;
|
||||
for(String line : Messages.getMessageList("general.hand.tooltip", "%cible%", p.getName())) {
|
||||
if(t == null) {
|
||||
t = Component.text("");
|
||||
} else
|
||||
t.append(Component.newline());
|
||||
t.append(C.text(line));
|
||||
}
|
||||
hoverEvent = HoverEvent.showText(t);
|
||||
}
|
||||
} else
|
||||
hoverEvent = HoverEvent.showText(C.text(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover", "%cible%", p.getName())));
|
||||
TextComponent like = Component.text(ChatManager.getNameForChatAction(p, action, getStorage())).hoverEvent(hoverEvent);
|
||||
if (action.hasCommand())
|
||||
like.clickEvent(ClickEvent.runCommand(action.getCommand()));
|
||||
for (String s : slot.getPlaceholders())
|
||||
message = message.replaceText(TextReplacementConfig.builder().matchLiteral(s).replacement(like).build());
|
||||
if (ChatItem.getInstance().getConfig().getBoolean("manager-config.paper.send-ourself", false)) {
|
||||
for (Audience a : e.viewers().isEmpty() ? Bukkit.getOnlinePlayers() : e.viewers())
|
||||
a.sendMessage(e.renderer().render(p, p.displayName(), message, a));
|
||||
e.setCancelled(true);
|
||||
} else
|
||||
e.message(message);
|
||||
ChatItem.debug("Changed message to " + PlainTextComponentSerializer.plainText().serialize(message));
|
||||
if (getStorage().cooldown > 0 && !p.hasPermission("chatitem.ignore-cooldown"))
|
||||
ChatManager.applyCooldown(p);
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
|
||||
|
||||
static {
|
||||
if(Utils.IS_PAPER)
|
||||
ORDERS = Arrays.asList("packet", "chat", "paper", "all");
|
||||
ORDERS = Arrays.asList("chat", "paper", "packet", "all");
|
||||
else
|
||||
ORDERS = Arrays.asList("packet", "chat", "all");
|
||||
ORDERS = Arrays.asList("chat", "packet", "all");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,6 +150,8 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
|
||||
decline.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/chatitem select " + testing + " no"));
|
||||
decline.setHoverEvent(Utils.createTextHover(Colors.GRAY + "Click to say it's not working as expected"));
|
||||
text.addExtra(decline);
|
||||
if(testing.equalsIgnoreCase("packet"))
|
||||
text.addExtra(" (This manager can have different result between 'chatitem select' and default chat for technical reasons. If nothing works, it's recommended to select it and try again)");
|
||||
p.spigot().sendMessage(text);
|
||||
}, 2);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package me.dadus33.chatitem.hook.placeholders;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
|
||||
public class EssentialsPlaceholdersHook implements IPlaceholders {
|
||||
|
||||
private Essentials getEssentials() {
|
||||
return ((Essentials) Bukkit.getPluginManager().getPlugin("Essentials"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public String replace(Player p, String text) {
|
||||
User user = getEssentials().getUser(p);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
String world = user.getWorld().getName();
|
||||
String username = user.getName();
|
||||
String nickname = user.getFormattedNickname();
|
||||
Player player = user.getBase();
|
||||
Team team = player.getScoreboard().getPlayerTeam(player);
|
||||
|
||||
return text.replace("{GROUP}", user.getGroup()).replace("{WORLD}", getEssentials().getSettings().getWorldAlias(world)).replace("{WORLDNAME}", world)
|
||||
.replace("{SHORTWORLDNAME}", world.substring(0, 1).toUpperCase(Locale.ENGLISH)).replace("{TEAMNAME}", team == null ? "" : team.getDisplayName())
|
||||
.replace("{TEAMPREFIX}", team == null ? "" : team.getPrefix()).replace("{TEAMSUFFIX}", team == null ? "" : team.getSuffix())
|
||||
.replace("{PREFIX}", FormatUtil.replaceFormat(getEssentials().getPermissionsHandler().getPrefix(player)))
|
||||
.replace("{SUFFIX}", FormatUtil.replaceFormat(getEssentials().getPermissionsHandler().getSuffix(player))).replace("{USERNAME}", username)
|
||||
.replace("{NICKNAME}", nickname == null ? username : nickname);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,8 +17,6 @@ import me.dadus33.chatitem.itemnamer.hook.ChatItemTranslationNamer;
|
||||
import me.dadus33.chatitem.itemnamer.hook.DefaultNamer;
|
||||
import me.dadus33.chatitem.itemnamer.hook.ItemDisplayNamer;
|
||||
import me.dadus33.chatitem.itemnamer.hook.LangUtilsNamer;
|
||||
import me.dadus33.chatitem.itemnamer.hook.PaperNamer;
|
||||
import me.dadus33.chatitem.utils.Utils;
|
||||
|
||||
public class NamerManager {
|
||||
|
||||
@@ -39,8 +37,6 @@ public class NamerManager {
|
||||
addNamer(new ChatItemTranslationNamer());
|
||||
addNamer(new ItemDisplayNamer());
|
||||
addNamer(new DefaultNamer());
|
||||
if(Utils.IS_PAPER)
|
||||
addNamer(new PaperNamer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,8 +67,10 @@ public class NamerManager {
|
||||
continue;
|
||||
for(INamer namer : allNamers) {
|
||||
String tmpName = namer.getName(p, item, storage);
|
||||
if(tmpName != null)
|
||||
if(tmpName != null) {
|
||||
ChatItem.debug("Using namer " + namer.getClass().getSimpleName() + ", value: " + tmpName);
|
||||
return tmpName;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null; // this should NEVER append
|
||||
|
||||
@@ -11,12 +11,12 @@ public class ChatItemTranslationNamer implements INamer {
|
||||
|
||||
@Override
|
||||
public Priority getPriority() {
|
||||
return Priority.SMALL;
|
||||
return Priority.MINOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(Player p, ItemStack item, Storage storage) {
|
||||
return Translation.get(item);
|
||||
return Translation.getOr(item, null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,7 +12,7 @@ public class DefaultNamer implements INamer {
|
||||
|
||||
@Override
|
||||
public Priority getPriority() {
|
||||
return Priority.MINOR;
|
||||
return Priority.SMALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.Storage;
|
||||
import me.dadus33.chatitem.itemnamer.INamer;
|
||||
|
||||
@@ -17,10 +18,9 @@ public class ItemDisplayNamer implements INamer {
|
||||
|
||||
@Override
|
||||
public String getName(Player p, ItemStack item, Storage storage) {
|
||||
if(item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
|
||||
String name = item.getItemMeta().getDisplayName();
|
||||
String name = ChatItem.getPlatform().getItemDisplayName(item);
|
||||
if(name != null && name != "")
|
||||
return storage.colorIfColored ? ChatColor.stripColor(name) : name;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package me.dadus33.chatitem.itemnamer.hook;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.dadus33.chatitem.Storage;
|
||||
import me.dadus33.chatitem.itemnamer.INamer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
|
||||
public class PaperNamer implements INamer {
|
||||
|
||||
@Override
|
||||
public Priority getPriority() {
|
||||
return Priority.IMPORTANT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(Player p, ItemStack item, Storage storage) {
|
||||
return PlainTextComponentSerializer.plainText().serialize(item.displayName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,8 +39,7 @@ public class InventoryListener implements Listener {
|
||||
return;
|
||||
InventoryHolder holder = e.getClickedInventory().getHolder();
|
||||
if (holder == null || !(holder instanceof ChatItemHolder)) {
|
||||
if (e.getClick().equals(ClickType.DOUBLE_CLICK) && p.getOpenInventory() != null
|
||||
&& p.getOpenInventory().getTopInventory() != null) {
|
||||
if (e.getClick().equals(ClickType.DOUBLE_CLICK) && p.getOpenInventory() != null && p.getOpenInventory().getTopInventory() != null) {
|
||||
Inventory top = p.getOpenInventory().getTopInventory();
|
||||
if (top.getHolder() != null && top.getHolder() instanceof ChatItemHolder) {
|
||||
e.setCancelled(true);
|
||||
@@ -114,14 +113,13 @@ public class InventoryListener implements Listener {
|
||||
inv.setItem(i, ChatItem.getPlatform().createItemStack(ItemUtils.WHITE_STAINED_GLASS, "-"));
|
||||
|
||||
int slot = 0;
|
||||
for (String manager : Arrays.asList("all", "auto", "packet", "chat", "paper")) {
|
||||
for (String manager : Arrays.asList("all", "packet", "chat", "paper")) {
|
||||
if (manager == "paper" && !Utils.IS_PAPER)
|
||||
continue;
|
||||
holder.keyBySlot.put(slot, manager);
|
||||
inv.setItem(slot++, getManagerItem(manager));
|
||||
}
|
||||
inv.setItem(slot + 1,
|
||||
getManagerItem("actual", "%manager%", Messages.getMessage("admin-inv.manager." + c.manager + ".name")));
|
||||
inv.setItem(slot + 1, getManagerItem("actual", "%manager%", Messages.getMessage("admin-inv.manager." + c.manager + ".name")));
|
||||
|
||||
inv.setItem(8, getBoolChangeItem(ItemUtils.FIREWORK_CHARGE, "debug", c.debug));
|
||||
|
||||
@@ -130,27 +128,22 @@ public class InventoryListener implements Listener {
|
||||
inv.setItem(21, getAmountChangeItem(Material.IRON_DOOR, "limit-per-message", c.limit));
|
||||
inv.setItem(22, getAmountChangeItem(Material.APPLE, "cooldown", c.cooldown));
|
||||
inv.setItem(23, getBoolChangeItem(Material.BLAZE_ROD, "check-update", c.checkUpdate));
|
||||
inv.setItem(24, ChatItem.getPlatform().createTranslatedItemStack(Material.BOOK, "admin-inv.language", "%name%",
|
||||
Translation.getMessage("language.name")));
|
||||
inv.setItem(24, ChatItem.getPlatform().createTranslatedItemStack(Material.BOOK, "admin-inv.language", "%name%", Translation.getMessage("language.name")));
|
||||
|
||||
inv.setItem(26, ChatItem.getPlatform().createItemStack(ItemUtils.MATERIAL_CLOSE,
|
||||
Messages.getMessage("admin-inv.close")));
|
||||
inv.setItem(26, ChatItem.getPlatform().createItemStack(ItemUtils.MATERIAL_CLOSE, Messages.getMessage("admin-inv.close")));
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
private static ItemStack getBoolChangeItem(Material type, String key, boolean b) {
|
||||
return ChatItem.getPlatform().createItemStack(type,
|
||||
Messages.getMessage("admin-inv." + key, "%state%", Messages.getMessage(b ? "enabled" : "disabled")),
|
||||
return ChatItem.getPlatform().createItemStack(type, Messages.getMessage("admin-inv." + key, "%state%", Messages.getMessage(b ? "enabled" : "disabled")),
|
||||
Messages.getMessageList("admin-inv.bool-lore"));
|
||||
}
|
||||
|
||||
private static ItemStack getAmountChangeItem(Material type, String key, int amount) {
|
||||
return ChatItem.getPlatform().createItemStack(type, Messages.getMessage("admin-inv." + key, "%state%", amount),
|
||||
Messages.getMessageList("admin-inv.amount-lore"));
|
||||
return ChatItem.getPlatform().createItemStack(type, Messages.getMessage("admin-inv." + key, "%state%", amount), Messages.getMessageList("admin-inv.amount-lore"));
|
||||
}
|
||||
|
||||
private static ItemStack getManagerItem(String manager, Object... placeholders) {
|
||||
return ChatItem.getPlatform().createTranslatedItemStack(Material.PAPER, "admin-inv.manager." + manager,
|
||||
placeholders);
|
||||
return ChatItem.getPlatform().createTranslatedItemStack(Material.PAPER, "admin-inv.manager." + manager, placeholders);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,8 @@ public interface IPlatform {
|
||||
|
||||
ItemStack createItemStack(Material type, String name, List<String> lore);
|
||||
|
||||
String getItemDisplayName(ItemStack item);
|
||||
|
||||
String getPluginVersion(Plugin plugin);
|
||||
|
||||
Version getMinecraftVersion();
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import me.dadus33.chatitem.C;
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.chatmanager.ChatAction;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
@@ -22,11 +23,12 @@ import me.dadus33.chatitem.utils.Messages;
|
||||
import me.dadus33.chatitem.utils.ReflectionUtils;
|
||||
import me.dadus33.chatitem.utils.Version;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.event.HoverEventSource;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
|
||||
public class PaperPlatform implements IPlatform {
|
||||
|
||||
@@ -37,14 +39,14 @@ public class PaperPlatform implements IPlatform {
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder holder, int slot, String name) {
|
||||
return Bukkit.createInventory(holder, slot, Component.text(name));
|
||||
return Bukkit.createInventory(holder, slot, C.text(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStack(Material type, String name) {
|
||||
ItemStack item = new ItemStack(type);
|
||||
ItemMeta meta = (ItemMeta) item.getItemMeta();
|
||||
meta.displayName(Component.text(name).color(NamedTextColor.WHITE));
|
||||
meta.displayName(C.text(name).color(NamedTextColor.WHITE));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
@@ -53,11 +55,19 @@ public class PaperPlatform implements IPlatform {
|
||||
public ItemStack createItemStack(Material type, String name, List<String> lore) {
|
||||
ItemStack item = new ItemStack(type);
|
||||
ItemMeta meta = (ItemMeta) item.getItemMeta();
|
||||
meta.displayName(Component.text(name).color(NamedTextColor.WHITE));
|
||||
meta.lore(lore.stream().map(Component::text).collect(Collectors.toList()));
|
||||
meta.displayName(C.text(name).color(NamedTextColor.WHITE));
|
||||
meta.lore(lore.stream().map(C::text).collect(Collectors.toList()));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public String getItemDisplayName(ItemStack item) {
|
||||
// actually the get Displayname for better ... See: https://github.com/KyoriPowered/adventure-platform/issues/185
|
||||
// return LegacyComponentSerializer.legacySection().serialize(item.displayName());
|
||||
return item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginVersion(Plugin plugin) {
|
||||
@@ -122,10 +132,27 @@ public class PaperPlatform implements IPlatform {
|
||||
|
||||
@Override
|
||||
public void sendMessage(Player to, Player origin, ChatAction action, String msg) {
|
||||
Component comp = PlainTextComponentSerializer.plainText().deserialize(msg);
|
||||
ComponentLike like = Component.text(ChatManager.getNameForChatAction(origin, action, ChatItem.getInstance().getStorage())).hoverEvent(action.isItem() ? action.getItem().asHoverEvent()
|
||||
: HoverEvent.showText(Component.text(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover", "%cible%", origin.getName()))));
|
||||
HoverEventSource<?> hoverEvent = null;
|
||||
if(action.isItem()) {
|
||||
if(!action.getItem().getType().equals(Material.AIR))
|
||||
hoverEvent = action.getItem().asHoverEvent();
|
||||
else {
|
||||
Component t = null;
|
||||
for(String line : Messages.getMessageList("general.hand.tooltip", "%cible%", origin.getName())) {
|
||||
if(t == null) {
|
||||
t = Component.text("");
|
||||
} else
|
||||
t.append(Component.newline());
|
||||
t.append(C.text(line));
|
||||
}
|
||||
hoverEvent = HoverEvent.showText(t);
|
||||
}
|
||||
} else
|
||||
hoverEvent = HoverEvent.showText(C.text(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover", "%cible%", origin.getName())));
|
||||
TextComponent like = Component.text(ChatManager.getNameForChatAction(origin, action, ChatItem.getInstance().getStorage())).hoverEvent(hoverEvent);
|
||||
if (action.hasCommand())
|
||||
like = like.clickEvent(ClickEvent.runCommand(action.getCommand()));
|
||||
|
||||
to.sendMessage(comp.replaceText(TextReplacementConfig.builder().matchLiteral(ChatManager.SEPARATOR + "").replacement(like).build()));
|
||||
to.sendMessage(C.text(msg).replaceText(TextReplacementConfig.builder().matchLiteral(ChatManager.SEPARATOR + "").replacement(like).build()));
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@@ -38,35 +37,20 @@ import net.md_5.bungee.api.chat.TextComponent;
|
||||
@SuppressWarnings("deprecation")
|
||||
public class SpigotPlatform implements IPlatform {
|
||||
|
||||
private static Method saveMethod;
|
||||
private static boolean shouldUseAppendMethod = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class<?> nbtTag = PacketUtils.getNmsClass("NBTTagCompound", "nbt.");
|
||||
Class<?> itemClass = PacketUtils.getNmsClass("ItemStack", "world.item.");
|
||||
for (Method m : itemClass.getDeclaredMethods()) {
|
||||
if (m.getParameterTypes().length == 1) {
|
||||
if (m.getParameterTypes()[0].equals(nbtTag) && m.getReturnType().equals(nbtTag)) {
|
||||
saveMethod = m;
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
ComponentBuilder.class.getDeclaredMethod("append", BaseComponent[].class);
|
||||
shouldUseAppendMethod = true;
|
||||
} catch (Exception e) {
|
||||
shouldUseAppendMethod = false;
|
||||
}
|
||||
ChatItem.getInstance().getLogger().info(shouldUseAppendMethod ? "Use ComponentBuilder's method." : "Use own ComponentBuilder append method.");
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
Logger log = ChatItem.getInstance().getLogger();
|
||||
String appendMethodMsg = shouldUseAppendMethod ? "Use ComponentBuilder's method." : "Use own ComponentBuilder append method.";
|
||||
if (saveMethod == null)
|
||||
log.info("Failed to find save method. Using default system. " + appendMethodMsg);
|
||||
else
|
||||
log.info("Save method founded: " + saveMethod.getName() + ". " + appendMethodMsg);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,6 +81,11 @@ public class SpigotPlatform implements IPlatform {
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemDisplayName(ItemStack item) {
|
||||
return item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginVersion(Plugin plugin) {
|
||||
@@ -372,7 +361,7 @@ public class SpigotPlatform implements IPlatform {
|
||||
littleBuilder.event(Utils.createItemHover(action.getItem(), to));
|
||||
} else {
|
||||
littleBuilder.event(Utils.createTextHover(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover")));
|
||||
if(action.getCommand() != "")
|
||||
if(action.hasCommand())
|
||||
littleBuilder.event(Utils.createRunCommand(action.getCommand()));
|
||||
}
|
||||
return littleBuilder.create();
|
||||
|
||||
@@ -79,6 +79,8 @@ public class ReflectionUtils {
|
||||
* @return the requested object of the field
|
||||
*/
|
||||
public static Object getObject(Object source, String... field) {
|
||||
if(source == null)
|
||||
return null;
|
||||
try {
|
||||
for(String fieldName : field) {
|
||||
try {
|
||||
@@ -104,6 +106,8 @@ public class ReflectionUtils {
|
||||
* @return the requested field
|
||||
*/
|
||||
public static Field getField(Object source, String field) {
|
||||
if(source == null)
|
||||
return null;
|
||||
try {
|
||||
Field f = source.getClass().getDeclaredField(field);
|
||||
f.setAccessible(true);
|
||||
|
||||
@@ -229,14 +229,6 @@ messages:
|
||||
- "&eShould works with all types of plugins. (Previously named 'both' instead of 'all')"
|
||||
- ""
|
||||
- "&7Since ChatItem v2.1"
|
||||
auto:
|
||||
name: "&6Choose automatically"
|
||||
lore:
|
||||
- "&aChoose automatically between managers available"
|
||||
- "&aaccording to actuals plugins."
|
||||
- "&eThis is better when you are not using own plugin."
|
||||
- ""
|
||||
- "&7Since ChatItem v2.1"
|
||||
packet:
|
||||
name: "&6Intercept packets"
|
||||
lore:
|
||||
|
||||
Reference in new issue
Block a user