Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6435ea0dad | ||
|
|
4e7b14e618 | ||
|
|
c9ea8061c8 | ||
|
|
4b966f056e | ||
|
|
3a2d0ee44d | ||
|
|
5ee9cca3d7 | ||
|
|
e21f236a09 | ||
|
|
554dd8ad39 | ||
|
|
b7a60f1352 | ||
|
|
b8e5e213ae | ||
|
|
08101a8d18 | ||
|
|
4ccb543869 | ||
|
|
153667135b | ||
|
|
00ca8ac11b | ||
|
|
44867e86d8 | ||
|
|
36148b5969 | ||
|
|
103ef2a4f2 | ||
|
|
40f67cc41f | ||
|
|
df555f7151 | ||
|
|
c76c35974c | ||
|
|
81f9711019 | ||
|
|
4edccde81c | ||
|
|
eac6d1c68a | ||
|
|
1914174e42 | ||
|
|
4a7f37451a | ||
|
|
4d90a80788 | ||
|
|
3713ad41af | ||
|
|
b8ba6eac69 | ||
|
|
25f8b585b0 | ||
|
|
746b3b58a0 | ||
|
|
89f61e0178 | ||
|
|
9d7de56889 | ||
|
|
5fb210e841 | ||
|
|
0a9af0d430 | ||
|
|
37681d8b27 | ||
|
|
79e03e97bd | ||
|
|
db08be3fa8 | ||
|
|
4133f30701 | ||
|
|
08434a5df2 | ||
|
|
ae825569cf | ||
|
|
1a4f95cd80 | ||
|
|
4edc061969 |
No files matched your search
@@ -10,14 +10,14 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
name: Checkout repo
|
||||
|
||||
- name: Set up JDK 17 (LTS)
|
||||
uses: actions/setup-java@v3
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'adopt'
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
|
||||
- name: Build with Maven
|
||||
@@ -27,4 +27,4 @@ jobs:
|
||||
name: Upload Artifact
|
||||
with:
|
||||
name: ChatItem.jar
|
||||
path: target/ChatItem-*.jar
|
||||
path: target/ChatItem-*.jar
|
||||
@@ -10,20 +10,20 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
name: Checkout repo
|
||||
|
||||
- name: Set up JDK 17 (LTS)
|
||||
uses: actions/setup-java@v3
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'adopt'
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
|
||||
- name: Build with Maven
|
||||
run: mvn install --file pom.xml
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
name: Upload Artifact
|
||||
with:
|
||||
name: ChatItem.jar
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.dadus33</groupId>
|
||||
<artifactId>ChatItem</artifactId>
|
||||
<version>2.6</version>
|
||||
<version>2.6.2</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>
|
||||
|
||||
|
||||
@@ -68,7 +72,7 @@
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.20.4-R0.1-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -99,7 +103,7 @@
|
||||
<dependency>
|
||||
<groupId>com.viaversion</groupId>
|
||||
<artifactId>viaversion-api</artifactId>
|
||||
<version>4.10.2</version>
|
||||
<version>5.0.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -123,31 +127,25 @@
|
||||
<dependency>
|
||||
<groupId>dev.majek</groupId>
|
||||
<artifactId>HexNicks</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.MajekDev</groupId>
|
||||
<artifactId>HexNicks</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.14.0</version>
|
||||
<version>4.17.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.3.0</version>
|
||||
<version>4.3.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.discordsrv</groupId>
|
||||
<artifactId>discordsrv</artifactId>
|
||||
<version>1.27.0</version>
|
||||
<version>1.28.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -189,7 +187,13 @@
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<version>1.7.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.essentialsx</groupId>
|
||||
<artifactId>EssentialsX</artifactId>
|
||||
<version>2.21.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package me.dadus33.chatitem;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
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);
|
||||
}
|
||||
|
||||
public static String string(Component c) {
|
||||
return LegacyComponentSerializer.legacySection().serialize(c);
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,13 @@ import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.PacketEditingChatManager;
|
||||
import me.dadus33.chatitem.chatmanager.v2.ChatListenerChatManager;
|
||||
import me.dadus33.chatitem.chatmanager.v3.PaperChatManager;
|
||||
import me.dadus33.chatitem.chatmanager.v4.OwnManager;
|
||||
import me.dadus33.chatitem.commands.CIReloadCommand;
|
||||
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 +77,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() {
|
||||
@@ -102,8 +105,10 @@ public class ChatItem extends JavaPlugin {
|
||||
|
||||
this.chatManager.add(new PacketEditingChatManager(this));
|
||||
this.chatManager.add(new ChatListenerChatManager(this));
|
||||
if(Utils.IS_PAPER)
|
||||
if(Utils.IS_PAPER) {
|
||||
this.chatManager.add(new PaperChatManager(this));
|
||||
this.chatManager.add(new OwnManager());
|
||||
}
|
||||
|
||||
String managerName = getStorage().manager;
|
||||
|
||||
@@ -189,6 +194,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");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.dadus33.chatitem.chatmanager;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -15,7 +16,7 @@ public class ChatAction {
|
||||
|
||||
public ChatAction(ItemSlot slot, Player origin, ItemStack item) {
|
||||
this.slot = slot;
|
||||
this.item = item;
|
||||
this.item = item == null ? new ItemStack(Material.AIR) : item;
|
||||
this.origin = origin;
|
||||
this.isItem = true;
|
||||
}
|
||||
@@ -48,6 +49,6 @@ public class ChatAction {
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
return item == null ? new ItemStack(Material.AIR) : item;
|
||||
}
|
||||
}
|
||||
@@ -23,10 +23,6 @@ public class ChatEventListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
if (ChatManager.isTestingEnabled() && !ChatManager.isTesting("packet"))
|
||||
return;
|
||||
if(!ChatItem.getInstance().isManagerEnabled("packet"))
|
||||
return;
|
||||
if (ChatManager.containsSeparator(e.getMessage())) { // If the BELL character is found, we have to remove it
|
||||
e.setMessage(ChatManager.removeSeparator(e.getMessage()));
|
||||
}
|
||||
@@ -34,11 +30,11 @@ 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);
|
||||
if(!ChatManager.canUsePlaceholder(p, action.getItem(), slot, e))
|
||||
if(!ChatManager.canUsePlaceholder(p, action, slot, e))
|
||||
return;
|
||||
String s = slot.replacePlaceholdersToSeparator(e.getMessage());
|
||||
if (Utils.countMatches(s, Character.toString(ChatManager.SEPARATOR)) > getStorage().limit) {
|
||||
@@ -49,7 +45,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));
|
||||
@@ -209,10 +209,23 @@ public abstract class ChatManager {
|
||||
if (ItemUtils.isEmpty(item)) {
|
||||
if (c.handDisabled)
|
||||
return ItemSlot.HAND.getPlaceholders().get(0);
|
||||
else
|
||||
return getHandName(p);
|
||||
return getHandName(p);
|
||||
}
|
||||
return styleItem(viewer, item, c);
|
||||
return ChatItem.replace(p, 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 chat.getSlot().getPlaceholders().get(0);
|
||||
return getHandName(chat);
|
||||
}
|
||||
return ChatItem.replace(chat.getPlayer(), styleItem(viewer, item, c));
|
||||
}
|
||||
return ChatItem.replace(chat.getPlayer(), Messages.getMessage(action.getSlot().name().toLowerCase() + ".chat", "%cible%", action.getOrigin().getName()));
|
||||
}
|
||||
|
||||
public static String getNameForChatAction(Player viewer, ChatAction action, Storage c) {
|
||||
@@ -220,23 +233,23 @@ public abstract class ChatManager {
|
||||
ItemStack item = action.getItem();
|
||||
if (ItemUtils.isEmpty(item)) {
|
||||
if (c.handDisabled)
|
||||
return ItemSlot.HAND.getPlaceholders().get(0);
|
||||
return action.getSlot().getPlaceholders().get(0);
|
||||
else
|
||||
return getHandName(action.getOrigin());
|
||||
}
|
||||
return styleItem(viewer, item, c);
|
||||
return ChatItem.replace(action.getOrigin(), styleItem(viewer, item, c));
|
||||
}
|
||||
return Messages.getMessage(action.getSlot().name().toLowerCase() + ".chat", "%cible%", action.getOrigin().getName());
|
||||
return ChatItem.replace(action.getOrigin(), Messages.getMessage(action.getSlot().name().toLowerCase() + ".chat", "%cible%", action.getOrigin().getName()));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String getHandName(Player p) {
|
||||
return ChatItem.getInstance().getStorage().handName.replace("{name}", p.getName()).replace("{display-name}", p.getDisplayName());
|
||||
return ChatItem.replace(p, ChatItem.getInstance().getStorage().handName.replace("{name}", p.getName()).replace("{display-name}", p.getDisplayName()));
|
||||
}
|
||||
|
||||
public static String getHandName(Chat c) {
|
||||
Player p = c.getPlayer();
|
||||
return ChatItem.getInstance().getStorage().handName.replace("{name}", p.getName()).replace("{display-name}", p.getDisplayName());
|
||||
return ChatItem.replace(p, ChatItem.getInstance().getStorage().handName.replace("{name}", p.getName()).replace("{display-name}", p.getDisplayName()));
|
||||
}
|
||||
|
||||
public static String calculateTime(long seconds) {
|
||||
@@ -268,7 +281,7 @@ public abstract class ChatManager {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static boolean canUsePlaceholder(Player p, ItemStack item, ItemSlot slot, @Nullable Cancellable e) {
|
||||
public static boolean canUsePlaceholder(Player p, ChatAction action, ItemSlot slot, @Nullable Cancellable e) {
|
||||
Storage c = ChatItem.getInstance().getStorage();
|
||||
if (c.permissionEnabled && !p.hasPermission(c.permissionName)) {
|
||||
if (!c.letMessageThrough) {
|
||||
@@ -280,7 +293,7 @@ public abstract class ChatManager {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (item != null && item.getType().equals(Material.AIR)) {
|
||||
if (action.isItem() && action.getItem().getType().equals(Material.AIR) && slot.isBasic()) {
|
||||
if (slot.isDenyIfNoItem()) {
|
||||
if (e != null)
|
||||
e.setCancelled(true);
|
||||
@@ -313,9 +326,9 @@ public abstract class ChatManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (item != null) {
|
||||
if (action.isItem()) {
|
||||
for (String ignored : c.ignoredItems) {
|
||||
if (item.getType().name().toLowerCase().contains(ignored.toLowerCase())) {
|
||||
if (action.getItem().getType().name().toLowerCase().contains(ignored.toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -361,7 +374,7 @@ public abstract class ChatManager {
|
||||
if(isTestingEnabled())
|
||||
return true;
|
||||
String selected = ChatItem.getInstance().getStorage().manager;
|
||||
if (selected == "both" || selected == "all")
|
||||
if (selected.equalsIgnoreCase("both") || selected.equalsIgnoreCase("all"))
|
||||
return true;
|
||||
if (selected == "auto") {
|
||||
if (Utils.IS_PAPER && actual == "paper")
|
||||
|
||||
@@ -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();
|
||||
|
||||
+29
-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 && ReflectionUtils.hasObject(packet.getPacket(), "unsignedContent")) { // 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") && ReflectionUtils.hasObject(packet.getPacket(), "unsignedContent")) { // 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"));
|
||||
@@ -68,12 +84,13 @@ public class AdventureComponentManager implements IComponentManager {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Object manageContent(Player viewer, Chat chat, ChatItemPacket packet, String json, Storage c) throws Exception {
|
||||
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 +110,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()));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,7 @@ import static me.dadus33.chatitem.utils.PacketUtils.getNmsClass;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -35,18 +31,19 @@ public class JSONManipulator {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static final List<String> SKIPPED = Arrays.asList("HSTRY_ENCHANTS");
|
||||
|
||||
public static final Class<?> CRAFT_ITEM_STACK_CLASS = PacketUtils.getObcClass("inventory.CraftItemStack");
|
||||
public static final Class<?> NMS_ITEM_STACK_CLASS = getNmsClass("ItemStack", "world.item.");
|
||||
public static final Method AS_NMS_COPY = ReflectionUtils.getMethod(CRAFT_ITEM_STACK_CLASS, "asNMSCopy", ItemStack.class);
|
||||
public static final Class<?> NBT_TAG_COMPOUND = getNmsClass("NBTTagCompound", "nbt.");
|
||||
public static final Class<?> NBT_TAG_COMPOUND = getNmsClass("NBTTagCompound", "nbt.", "CompoundTag");
|
||||
public static final Method SAVE_NMS_ITEM_STACK_METHOD = ReflectionUtils.getMethod(NMS_ITEM_STACK_CLASS, NBT_TAG_COMPOUND, NBT_TAG_COMPOUND);
|
||||
public static final Field MAP = ReflectionUtils.getField(NBT_TAG_COMPOUND, "map", "x");
|
||||
|
||||
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) {
|
||||
@@ -71,7 +68,7 @@ public class JSONManipulator {
|
||||
|
||||
// Get the JSON representation of the item (well, not really JSON, but rather a
|
||||
// string representation of NBT data)
|
||||
hover.addProperty("value", stringifyItem(action.getItem()));
|
||||
hover.addProperty("value", ChatItem.getPlatform().stringifyItem(action.getItem()));
|
||||
} else {
|
||||
hover.addProperty("action", "show_text");
|
||||
|
||||
@@ -99,6 +96,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")) {
|
||||
@@ -110,7 +108,6 @@ public class JSONManipulator {
|
||||
if (!obj.has("text")) {
|
||||
obj.addProperty("text", "");
|
||||
}
|
||||
ChatItem.debug("Parsed array for item: " + obj.toString() + ", wrapper: " + wrapper);
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
@@ -118,7 +115,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 +143,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 +221,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,75 +246,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
|
||||
}
|
||||
}
|
||||
|
||||
public static String stringifyItem(ItemStack is) {
|
||||
try {
|
||||
return stringifyItemInternal(is);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "{}";
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "deprecation" })
|
||||
public static String stringifyItemInternal(ItemStack is) throws Exception {
|
||||
Object nmsStack = JSONManipulator.AS_NMS_COPY.invoke(null, is);
|
||||
Object nmsTag = JSONManipulator.NBT_TAG_COMPOUND.newInstance();
|
||||
JSONManipulator.SAVE_NMS_ITEM_STACK_METHOD.invoke(nmsStack, nmsTag);
|
||||
HashMap<String, String> tagMap = new HashMap<>();
|
||||
Map<String, Object> nmsMap = (Map<String, Object>) JSONManipulator.MAP.get(nmsTag);
|
||||
String id = nmsMap.get("id").toString().replace("\"", "");
|
||||
Object realTag = nmsMap.get("tag");
|
||||
if (JSONManipulator.NBT_TAG_COMPOUND.isInstance(realTag)) { // We need to make sure this is indeed an
|
||||
// NBTTagCompound
|
||||
Map<String, Object> realMap = (Map<String, Object>) JSONManipulator.MAP.get(realTag);
|
||||
Set<Map.Entry<String, Object>> entrySet = realMap.entrySet();
|
||||
for (Map.Entry<String, Object> entry : entrySet) {
|
||||
tagMap.put(entry.getKey(), entry.getValue().toString());
|
||||
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);
|
||||
}
|
||||
}
|
||||
// TODO check for ID remapping
|
||||
// ItemRewriter.remapIds(Version.getVersion().MAX_VER, protocolVersion.MAX_VER,
|
||||
// is);
|
||||
StringBuilder sb = new StringBuilder("{id:");
|
||||
sb.append("\"").append(id).append("\"").append(","); // Append the id
|
||||
sb.append("Count:").append(is.getAmount()).append("b"); // Append the amount
|
||||
|
||||
if (!tagMap.containsKey("Damage")) { // for new versions
|
||||
sb.append(",Damage:").append(is.getDurability()).append("s"); // Append the durability data
|
||||
}
|
||||
if (tagMap.isEmpty()) {
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
Set<Map.Entry<String, String>> entrySet = tagMap.entrySet();
|
||||
boolean first = true;
|
||||
sb.append(",tag:{"); // Start of the tag
|
||||
for (Map.Entry<String, String> entry : entrySet) {
|
||||
if (SKIPPED.contains(entry.getKey()))
|
||||
continue;
|
||||
if (!first)
|
||||
sb.append(",");
|
||||
first = false;
|
||||
if (!entry.getKey().isEmpty()) {
|
||||
if (entry.getKey().contains(";"))
|
||||
sb.append("\"" + entry.getKey() + "\"");
|
||||
else
|
||||
sb.append(entry.getKey());
|
||||
sb.append(":");
|
||||
}
|
||||
sb.append(cleanStr(entry.getValue()));
|
||||
}
|
||||
sb.append("}}"); // End of tag and end of item
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String cleanStr(String s) {
|
||||
return s.startsWith("'") && s.endsWith("'") ? s.substring(1, s.length() - 1) : s;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -68,14 +71,15 @@ public class ChatListener implements Listener {
|
||||
return;
|
||||
}
|
||||
ChatAction action = ChatManager.getChatAction(slot, p);
|
||||
if(!ChatManager.canUsePlaceholder(p, action.getItem(), slot, e))
|
||||
if(!ChatManager.canUsePlaceholder(p, action, 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,7 +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.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.kyori.adventure.text.event.HoverEventSource;
|
||||
|
||||
public class PaperListener implements Listener {
|
||||
|
||||
@@ -33,22 +35,23 @@ 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();
|
||||
String rawMessage = PlainTextComponentSerializer.plainText().serialize(message);
|
||||
if(ChatManager.containsSeparator(rawMessage)) { // fix for v1
|
||||
Component message = e.message();
|
||||
String rawMessage = C.string(message);
|
||||
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());
|
||||
rawMessage = PlainTextComponentSerializer.plainText().serialize(message);
|
||||
if (chat != null) {
|
||||
message = message.replaceText(TextReplacementConfig.builder().matchLiteral(ChatManager.SEPARATOR + "" + chat.getId() + ChatManager.SEPARATOR_END)
|
||||
.replacement(C.text(chat.getSlot().getPlaceholders().get(0))).build());
|
||||
rawMessage = C.string(message);
|
||||
}
|
||||
}
|
||||
ItemSlot slot = ItemSlot.getItemSlotFromMessage(rawMessage);
|
||||
@@ -56,20 +59,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, 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 = C.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 " + C.string(message));
|
||||
if (getStorage().cooldown > 0 && !p.hasPermission("chatitem.ignore-cooldown"))
|
||||
ChatManager.applyCooldown(p);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package me.dadus33.chatitem.chatmanager.v4;
|
||||
|
||||
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.chatmanager.ChatManager;
|
||||
|
||||
public class OwnListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onChat(AsyncChatEvent e) {
|
||||
if (ChatManager.isTestingEnabled() && !ChatManager.isTesting("ownformatter"))
|
||||
return;
|
||||
if (!ChatManager.isSelected("ownformatter"))
|
||||
return;
|
||||
if (e.isCancelled())
|
||||
return;
|
||||
e.setCancelled(true);
|
||||
/*Player p = e.getPlayer();
|
||||
Component msg = e.message();*/
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package me.dadus33.chatitem.chatmanager.v4;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
|
||||
public class OwnManager extends ChatManager {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Own Formatter";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "ownformatter";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(ChatItem pl) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,21 +26,25 @@ public class InventoryListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent e) {
|
||||
if (!(e.getWhoClicked() instanceof Player))
|
||||
return;
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
|
||||
InventoryHolder openInventoryHolder = p.getOpenInventory().getTopInventory().getHolder();
|
||||
InventoryHolder openInventoryHolder = null;
|
||||
try {
|
||||
openInventoryHolder = p.getOpenInventory().getTopInventory().getHolder();
|
||||
} catch(java.lang.IncompatibleClassChangeError exc) {} // ignore this
|
||||
|
||||
if (openInventoryHolder instanceof CustomInventoryHolder) {
|
||||
if (openInventoryHolder != null && openInventoryHolder instanceof CustomInventoryHolder) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getClickedInventory() == null || !(e.getWhoClicked() instanceof Player))
|
||||
if (e.getClickedInventory() == null)
|
||||
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 +118,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")) {
|
||||
if (manager == "paper" && !Utils.IS_PAPER)
|
||||
for (String manager : Arrays.asList("all", "packet", "chat", "paper")) { //, "ownformatter")) {
|
||||
if ((manager == "paper" || manager == "ownformatter") && !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 +133,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);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -79,7 +78,7 @@ public class TranslationInventoryListener implements Listener {
|
||||
holder.langBySlot.put(slot, lang);
|
||||
ItemStack item = ChatItem.getPlatform().createItemStack(Material.PAPER, Colors.GOLD + Translation.getAllLangs().get(lang), Colors.GRAY + "Clic to select this language");
|
||||
if(lang.equalsIgnoreCase(ChatItem.getInstance().getStorage().language)) {
|
||||
item.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
|
||||
item.addUnsafeEnchantment(ItemUtils.getEnchant("DURABILITY", "UNBREAKING"), 1);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
@@ -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();
|
||||
@@ -45,4 +47,6 @@ public interface IPlatform {
|
||||
Object jsonToBaseComponent(String json);
|
||||
|
||||
void sendMessage(Player to, Player origin, ChatAction action, String msg);
|
||||
|
||||
String stringifyItem(ItemStack item);
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package me.dadus33.chatitem.platform.hook;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@@ -14,6 +13,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 +22,13 @@ 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.HoverEvent.ShowItem;
|
||||
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,12 +55,22 @@ 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) {
|
||||
return plugin.getPluginMeta().getVersion();
|
||||
@@ -80,6 +92,11 @@ public class PaperPlatform implements IPlatform {
|
||||
return SpigotPlatform.getBaseComponentToJsonMethod() != null;
|
||||
}
|
||||
|
||||
private Object getRegistry() throws Exception {
|
||||
Class<?> serverClass = Class.forName("net.minecraft.server.MinecraftServer");
|
||||
return serverClass.getDeclaredMethod("registryAccess").invoke(serverClass.getDeclaredMethod("getServer").invoke(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String baseComponentToJson(Object obj) {
|
||||
Method m = SpigotPlatform.getBaseComponentToJsonMethod();
|
||||
@@ -88,10 +105,10 @@ public class PaperPlatform implements IPlatform {
|
||||
try {
|
||||
Object[] args = new Object[m.getParameterCount()];
|
||||
args[0] = obj;
|
||||
if(args.length > 1 && ReflectionUtils.isClassExist("net.minecraft.core.HolderLookup$Provider")) {
|
||||
if (args.length > 1 && ReflectionUtils.isClassExist("net.minecraft.core.HolderLookup$Provider")) {
|
||||
Class<?> c = Class.forName("net.minecraft.core.HolderLookup$Provider");
|
||||
if(m.getParameterTypes()[1].isAssignableFrom(c)) {
|
||||
args[1] = c.getDeclaredMethod("create", Stream.class).invoke(null, Stream.of());
|
||||
if (m.getParameterTypes()[1].isAssignableFrom(c)) {
|
||||
args[1] = getRegistry();
|
||||
}
|
||||
}
|
||||
return (String) m.invoke(null, args);
|
||||
@@ -100,17 +117,17 @@ public class PaperPlatform implements IPlatform {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object jsonToBaseComponent(String json) {
|
||||
Method m = SpigotPlatform.getJsonToBaseComponentMethod();
|
||||
try {
|
||||
Object[] args = new Object[m.getParameterCount()];
|
||||
args[0] = json;
|
||||
if(args.length > 1 && ReflectionUtils.isClassExist("net.minecraft.core.HolderLookup$Provider")) {
|
||||
if (args.length > 1 && ReflectionUtils.isClassExist("net.minecraft.core.HolderLookup$Provider")) {
|
||||
Class<?> c = Class.forName("net.minecraft.core.HolderLookup$Provider");
|
||||
if(m.getParameterTypes()[1].isAssignableFrom(c)) {
|
||||
args[1] = c.getDeclaredMethod("create", Stream.class).invoke(null, Stream.of());
|
||||
if (m.getParameterTypes()[1].isAssignableFrom(c)) {
|
||||
args[1] = getRegistry();
|
||||
}
|
||||
}
|
||||
return m.invoke(null, args);
|
||||
@@ -122,10 +139,42 @@ 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()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public String stringifyItem(ItemStack item) {
|
||||
ShowItem si = item.asHoverEvent().value();
|
||||
String json = "{id:\"" + si.item().asString() + "\",count:" + item.getAmount();
|
||||
if(si.nbt() != null) {
|
||||
json += ",tag:{" + si.nbt().string() + "}";
|
||||
} else if(Version.getVersion().isNewerOrEquals(Version.V1_20_6)) { // since MC 1.20.5 in fact
|
||||
json += ",components:" + (item.hasItemMeta() ? item.getItemMeta().getAsString() : "{}");
|
||||
}
|
||||
json += "}";
|
||||
ChatItem.debug("Item stringified: " + json);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,10 @@ package me.dadus33.chatitem.platform.hook;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@@ -20,6 +22,7 @@ import me.dadus33.chatitem.ItemPlayer;
|
||||
import me.dadus33.chatitem.Storage;
|
||||
import me.dadus33.chatitem.chatmanager.ChatAction;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.json.JSONManipulator;
|
||||
import me.dadus33.chatitem.platform.IPlatform;
|
||||
import me.dadus33.chatitem.playernamer.PlayerNamerManager;
|
||||
import me.dadus33.chatitem.utils.ColorManager;
|
||||
@@ -38,35 +41,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
|
||||
@@ -98,6 +86,11 @@ public class SpigotPlatform implements IPlatform {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemDisplayName(ItemStack item) {
|
||||
return item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginVersion(Plugin plugin) {
|
||||
return plugin.getDescription().getVersion();
|
||||
@@ -107,51 +100,68 @@ public class SpigotPlatform implements IPlatform {
|
||||
public Version getMinecraftVersion() {
|
||||
return Version.getVersionByName(getNMSVersion().replace("_R4", "_6"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getNMSVersion() {
|
||||
return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasBaseComponentSerializer() {
|
||||
return getBaseComponentToJsonMethod() != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String baseComponentToJson(Object obj) {
|
||||
Method m = getBaseComponentToJsonMethod();
|
||||
try {
|
||||
Object[] args = new Object[m.getParameterCount()];
|
||||
args[0] = obj;
|
||||
if (args.length > 1 && ReflectionUtils.isClassExist("net.minecraft.core.HolderLookup$a")) {
|
||||
Class<?> c = Class.forName("net.minecraft.core.HolderLookup$a");
|
||||
if (m.getParameterTypes()[1].isAssignableFrom(c)) {
|
||||
args[1] = getRegistry();
|
||||
}
|
||||
}
|
||||
return (String) m.invoke(null, args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object jsonToBaseComponent(String json) {
|
||||
Method m = getJsonToBaseComponentMethod();
|
||||
try {
|
||||
Object[] args = new Object[m.getParameterCount()];
|
||||
args[0] = json;
|
||||
if (args.length > 1 && ReflectionUtils.isClassExist("net.minecraft.core.HolderLookup$a")) {
|
||||
Class<?> c = Class.forName("net.minecraft.core.HolderLookup$a");
|
||||
if (m.getParameterTypes()[1].isAssignableFrom(c)) {
|
||||
args[1] = getRegistry();
|
||||
}
|
||||
}
|
||||
return m.invoke(null, args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private Object getRegistry() throws Exception {
|
||||
Class<?> serverClass = Class.forName("net.minecraft.server.MinecraftServer");
|
||||
return serverClass.getDeclaredMethod("ba").invoke(serverClass.getDeclaredMethod("getServer").invoke(null));
|
||||
}
|
||||
|
||||
public static Method getBaseComponentToJsonMethod() {
|
||||
Class<?> chatSerializerClass = PacketUtils.getNmsClass("IChatBaseComponent$ChatSerializer", "network.chat.", "ChatSerializer", "Component$Serializer");
|
||||
Class<?> chatBaseComponentClass = PacketUtils.getNmsClass("IChatBaseComponent", "network.chat.", "Component");
|
||||
if(chatSerializerClass == null || chatBaseComponentClass == null)
|
||||
if (chatSerializerClass == null || chatBaseComponentClass == null)
|
||||
return null;
|
||||
try {
|
||||
for (Method m : chatSerializerClass.getDeclaredMethods()) {
|
||||
if(m.getParameterTypes()[0].equals(chatBaseComponentClass) && m.getReturnType().equals(String.class)) {
|
||||
if (m.getParameterTypes()[0].equals(chatBaseComponentClass) && m.getReturnType().equals(String.class)) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -160,18 +170,19 @@ public class SpigotPlatform implements IPlatform {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static Method getJsonToBaseComponentMethod() {
|
||||
Class<?> chatSerializerClass = PacketUtils.getNmsClass("IChatBaseComponent$ChatSerializer", "network.chat.", "ChatSerializer", "Component$Serializer");
|
||||
Class<?> chatBaseComponentClass = PacketUtils.getNmsClass("IChatBaseComponent", "network.chat.", "Component");
|
||||
Class<?> chatMutableComponentClass = PacketUtils.getNmsClass("IChatMutableComponent", "network.chat.");
|
||||
if(chatSerializerClass == null || chatBaseComponentClass == null)
|
||||
if (chatSerializerClass == null || chatBaseComponentClass == null)
|
||||
return null;
|
||||
try {
|
||||
for (Method m : chatSerializerClass.getDeclaredMethods()) {
|
||||
if(m.getParameterCount() == 0)
|
||||
if (m.getParameterCount() == 0)
|
||||
continue;
|
||||
if(m.getParameterTypes()[0].equals(String.class) && (m.getReturnType().isAssignableFrom(chatBaseComponentClass) || (chatMutableComponentClass != null && m.getReturnType().equals(chatMutableComponentClass)))) {
|
||||
if (m.getParameterTypes()[0].equals(String.class)
|
||||
&& (m.getReturnType().isAssignableFrom(chatBaseComponentClass) || (chatMutableComponentClass != null && m.getReturnType().equals(chatMutableComponentClass)))) {
|
||||
m.setAccessible(true);
|
||||
return m;
|
||||
}
|
||||
@@ -191,8 +202,7 @@ public class SpigotPlatform implements IPlatform {
|
||||
for (char args : msg.toCharArray()) {
|
||||
if (args == '§') { // begin of color
|
||||
if (colorCode.isEmpty() && !text.isEmpty()) { // text before this char
|
||||
if(text.length() > 2 && text.startsWith("§") && text.substring(2) == ChatColor.stripColor(text)
|
||||
&& color != null && color != ChatColor.WHITE) {
|
||||
if (text.length() > 2 && text.startsWith("§") && text.substring(2) == ChatColor.stripColor(text) && color != null && color != ChatColor.WHITE) {
|
||||
text = text.substring(2); // remove some code which should not be here
|
||||
}
|
||||
appendToComponentBuilder(builder, createComponent(to, text, color, action));
|
||||
@@ -205,8 +215,8 @@ public class SpigotPlatform implements IPlatform {
|
||||
if (args == 'r' && colorCode.isEmpty()) {
|
||||
color = ChatColor.RESET;
|
||||
continue;
|
||||
} else if(args == 'x') {
|
||||
if(!colorCode.isEmpty()) {
|
||||
} else if (args == 'x') {
|
||||
if (!colorCode.isEmpty()) {
|
||||
color = ColorManager.getColor(colorCode);
|
||||
colorCode = ""; // clean for previous things
|
||||
}
|
||||
@@ -231,16 +241,16 @@ public class SpigotPlatform implements IPlatform {
|
||||
if (args == ChatManager.SEPARATOR) {
|
||||
// here put the item
|
||||
appendToComponentBuilder(builder, fixColorComponent(to, text, color, action));
|
||||
if(action.isItem())
|
||||
if (action.isItem())
|
||||
addItem(builder, to, origin, action.getItem(), action);
|
||||
else
|
||||
addCommand(builder, to, origin, action.getCommand(), action);
|
||||
text = "";
|
||||
if(ChatManager.containsSeparatorEnd(msg))
|
||||
if (ChatManager.containsSeparatorEnd(msg))
|
||||
removing = true;
|
||||
} else if(args == ChatManager.SEPARATOR_END) {
|
||||
} else if (args == ChatManager.SEPARATOR_END) {
|
||||
removing = false;
|
||||
} else if(!removing) { // not removing content
|
||||
} else if (!removing) { // not removing content
|
||||
// basic text, not waiting for code after '§'
|
||||
text += args;
|
||||
}
|
||||
@@ -360,21 +370,81 @@ public class SpigotPlatform implements IPlatform {
|
||||
}
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
|
||||
private static BaseComponent[] createComponent(Player to, String text, ChatColor color, ChatAction action) {
|
||||
ComponentBuilder littleBuilder = new ComponentBuilder(ChatItem.replace(action.getOrigin(), text));
|
||||
if(color != null && !Colors.isFormatting(color)) // don't add reset thing
|
||||
if (color != null && !Colors.isFormatting(color)) // don't add reset thing
|
||||
littleBuilder.color(color);
|
||||
if (action.isItem()) {
|
||||
if(action.getItem().getType().equals(Material.AIR))
|
||||
if (action.getItem().getType().equals(Material.AIR))
|
||||
littleBuilder.event(Utils.createTextHover(String.join("\n", ChatItem.getInstance().getStorage().tooltipHand)));
|
||||
else
|
||||
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();
|
||||
}
|
||||
|
||||
private static final List<String> SKIPPED = Arrays.asList("HSTRY_ENCHANTS");
|
||||
|
||||
@Override
|
||||
public String stringifyItem(ItemStack item) {
|
||||
try {
|
||||
ChatItem.debug("[JSONManipulator] stringifying item");
|
||||
Object nmsStack = JSONManipulator.AS_NMS_COPY.invoke(null, item);
|
||||
Object nmsTag = JSONManipulator.NBT_TAG_COMPOUND.newInstance();
|
||||
JSONManipulator.SAVE_NMS_ITEM_STACK_METHOD.invoke(nmsStack, nmsTag);
|
||||
HashMap<String, String> tagMap = new HashMap<>();
|
||||
Map<String, Object> nmsMap = (Map<String, Object>) JSONManipulator.MAP.get(nmsTag);
|
||||
String id = nmsMap.get("id").toString().replace("\"", "");
|
||||
Object realTag = nmsMap.get("tag");
|
||||
if (JSONManipulator.NBT_TAG_COMPOUND.isInstance(realTag)) { // We need to make sure this is indeed an
|
||||
// NBTTagCompound
|
||||
Map<String, Object> realMap = (Map<String, Object>) JSONManipulator.MAP.get(realTag);
|
||||
Set<Map.Entry<String, Object>> entrySet = realMap.entrySet();
|
||||
for (Map.Entry<String, Object> entry : entrySet) {
|
||||
tagMap.put(entry.getKey(), entry.getValue().toString());
|
||||
}
|
||||
}
|
||||
// TODO check for ID remapping
|
||||
// ItemRewriter.remapIds(Version.getVersion().MAX_VER, protocolVersion.MAX_VER,
|
||||
// is);
|
||||
StringBuilder sb = new StringBuilder("{id:");
|
||||
sb.append("\"").append(id).append("\"").append(","); // Append the id
|
||||
sb.append("Count:").append(item.getAmount()).append("b"); // Append the amount
|
||||
|
||||
if (!tagMap.containsKey("Damage")) { // for new versions
|
||||
sb.append(",Damage:").append(item.getDurability()).append("s"); // Append the durability data
|
||||
}
|
||||
if (tagMap.isEmpty()) {
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
Set<Map.Entry<String, String>> entrySet = tagMap.entrySet();
|
||||
boolean first = true;
|
||||
sb.append(",tag:{"); // Start of the tag
|
||||
for (Map.Entry<String, String> entry : entrySet) {
|
||||
if (SKIPPED.contains(entry.getKey()))
|
||||
continue;
|
||||
if (!first)
|
||||
sb.append(",");
|
||||
first = false;
|
||||
if (!entry.getKey().isEmpty()) {
|
||||
if (entry.getKey().contains(";"))
|
||||
sb.append("\"" + entry.getKey() + "\"");
|
||||
else
|
||||
sb.append(entry.getKey());
|
||||
sb.append(":");
|
||||
}
|
||||
sb.append(Utils.cleanStr(entry.getValue()));
|
||||
}
|
||||
sb.append("}}"); // End of tag and end of item
|
||||
return sb.toString();
|
||||
} catch (Exception e) {
|
||||
return "{}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.dadus33.chatitem.playernamer.hook;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.majek.hexnicks.Nicks;
|
||||
import me.dadus33.chatitem.playernamer.IPlayerNamer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
@@ -11,7 +13,14 @@ public class HexNicksV2PlayerNamer implements IPlayerNamer {
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getName(Player p) {
|
||||
return BungeeComponentSerializer.get().serialize(Nicks.api().getStoredNick(p).join());
|
||||
try {
|
||||
Object api = Class.forName("dev.majek.hexnicks.Nicks").getDeclaredMethod("api").invoke(null);
|
||||
CompletableFuture<Component> storedNick = (CompletableFuture<Component>) api.getClass().getDeclaredMethod("getStoredNick", Player.class).invoke(api, p);
|
||||
return BungeeComponentSerializer.get().serialize(storedNick.join());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new BaseComponent[0];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package me.dadus33.chatitem.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@@ -78,4 +79,14 @@ public class ItemUtils {
|
||||
}
|
||||
i.setItemMeta(im);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Enchantment getEnchant(String... names) {
|
||||
for(String name : names) {
|
||||
Enchantment possible = Enchantment.getByName(name);
|
||||
if(possible != null)
|
||||
return possible;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.dadus33.chatitem.utils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -17,6 +18,17 @@ public class ReflectionUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Method getMethodByName(Class<?> clazz, String methodName) {
|
||||
try {
|
||||
for(Method m : clazz.getDeclaredMethods())
|
||||
if(m.getName().equals(methodName))
|
||||
return m;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getMethod(Class<?> clazz, Class<?> returned, Class<?>... params) {
|
||||
try {
|
||||
@@ -71,6 +83,20 @@ public class ReflectionUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasObject(Object source, String... field) {
|
||||
if(source == null)
|
||||
return false;
|
||||
for(String fieldName : field) {
|
||||
try {
|
||||
source.getClass().getDeclaredField(fieldName);
|
||||
return true;
|
||||
} catch (NoSuchFieldException e) {
|
||||
// ignore because going to next item
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specified field name in the object source
|
||||
*
|
||||
@@ -79,6 +105,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 +132,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);
|
||||
@@ -191,4 +221,11 @@ public class ReflectionUtils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... params) {
|
||||
try {
|
||||
return clazz.getConstructor(params);
|
||||
} catch (Exception e) {}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.json.JSONManipulator;
|
||||
import me.dadus33.chatitem.playerversion.PlayerVersionManager;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
@@ -178,7 +177,7 @@ public class Utils {
|
||||
if(Version.getVersion().isNewerOrEquals(Version.V1_13)) {
|
||||
return new HoverEvent(HoverEvent.Action.SHOW_ITEM, new Item(item.getType().getKey().getKey(), item.getAmount(), ItemTag.ofNbt(PacketUtils.getNbtTag(item))));
|
||||
} else {
|
||||
return new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(JSONManipulator.stringifyItem(item)).create());
|
||||
return new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(ChatItem.getPlatform().stringifyItem(item)).create());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,4 +268,8 @@ public class Utils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String cleanStr(String s) {
|
||||
return s.startsWith("'") && s.endsWith("'") ? s.substring(1, s.length() - 1) : s;
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ general:
|
||||
- "{legs}"
|
||||
# Show what is their feets
|
||||
boots:
|
||||
enabled: false
|
||||
enabled: true
|
||||
deny-if-no-item: true
|
||||
keys:
|
||||
- "[feet]"
|
||||
@@ -145,6 +145,9 @@ general:
|
||||
sub-commands:
|
||||
broadcast: true
|
||||
show: true
|
||||
ownformatter:
|
||||
format: "%name%: %message%"
|
||||
|
||||
|
||||
|
||||
# Messages section. You can disable any of them by simply leaving them empty, like this: ""
|
||||
@@ -229,14 +232,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:
|
||||
@@ -261,6 +256,13 @@ messages:
|
||||
- "&eAdapted for paper user, and could be used with more plugin that others"
|
||||
- ""
|
||||
- "&7Since ChatItem v2.6"
|
||||
ownformatter:
|
||||
name: "&6ChatItem formatter"
|
||||
lore:
|
||||
- "&aChatItem format the chat for you."
|
||||
- "&aNo longer needs another chat plugin."
|
||||
- ""
|
||||
- "&7Since ChatItem v2.7"
|
||||
# The item that show the actual manager
|
||||
actual:
|
||||
name: '&6Actual manager: %manager%'
|
||||
|
||||
Reference in new issue
Block a user