Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e508790d9f | ||
|
|
c26259f5e7 | ||
|
|
62bf8b07fb | ||
|
|
bd93d3e610 | ||
|
|
c0a37084ce | ||
|
|
0f42e22da9 | ||
|
|
5e10bb4450 | ||
|
|
b88a1ca83e | ||
|
|
05ae520cf1 | ||
|
|
76123c895d | ||
|
|
4284497bf5 | ||
|
|
62a7b10142 | ||
|
|
cd341109de | ||
|
|
68fb201855 | ||
|
|
baa4eab53f | ||
|
|
20c5fc3e45 | ||
|
|
818cd535bb | ||
|
|
1107b7fe90 | ||
|
|
bed3a87c09 | ||
|
|
499d0eb93c | ||
|
|
913d04b96a | ||
|
|
497c317d3f | ||
|
|
c9d8d52406 | ||
|
|
38f8e47b92 | ||
|
|
6fb80712be | ||
|
|
00ef83bd67 | ||
|
|
1615bdf739 | ||
|
|
09854352a1 | ||
|
|
c6585bb94a | ||
|
|
1e359523fa | ||
|
|
885f6b9d7a | ||
|
|
f2a49e2f3a | ||
|
|
7c8b61c6eb | ||
|
|
f502cfa548 | ||
|
|
fcef1245d6 | ||
|
|
b6c4ad0170 | ||
|
|
a97710b2c4 | ||
|
|
64642cdc58 | ||
|
|
9ac6e7abbc | ||
|
|
fddf389169 | ||
|
|
3006a7857c | ||
|
|
e370723a82 | ||
|
|
2a496b9a1a | ||
|
|
655304bd52 | ||
|
|
0081c616d3 |
No files matched your search
@@ -8,11 +8,11 @@ You can:
|
||||
- [  ](https://discord.gg/yng5PPf62h)
|
||||
- [Check the wiki](https://github.com/dadus33-plugins/ChatItem/wiki)
|
||||
|
||||
# Item not well showed in chat
|
||||
# Item doesn't show up well in chat
|
||||
|
||||
You can try to do `/chatitem admin` then select different paper item. It will change how the plugin try to add item in chat.
|
||||
You can do `/chatitem admin` then select one of the other paper items in the menu. It will change how the plugin tries to display items in chat.
|
||||
|
||||
**If you already have issue, please do**:
|
||||
**If you still have an issue, please do**:
|
||||
1) Do `/chatitem admin` then select on "Debug" item at top right
|
||||
2) Try to use ChatItem in chat
|
||||
3) Come on discord [here](https://discord.gg/yng5PPf62h) or in private message: `Elikill58#0743`
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.dadus33</groupId>
|
||||
<artifactId>ChatItem</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<version>2.6</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -52,15 +52,23 @@
|
||||
<repository>
|
||||
<id>Scarsz-Nexus</id>
|
||||
<url>https://nexus.scarsz.me/content/groups/public/</url>
|
||||
</repository>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>PaperMC</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>mvdw-software</id>
|
||||
<url>http://repo.mvdw-software.be/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.17-R0.1-SNAPSHOT</version>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.20.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -91,7 +99,7 @@
|
||||
<dependency>
|
||||
<groupId>com.viaversion</groupId>
|
||||
<artifactId>viaversion-api</artifactId>
|
||||
<version>4.9.2</version>
|
||||
<version>4.10.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -139,7 +147,7 @@
|
||||
<dependency>
|
||||
<groupId>com.discordsrv</groupId>
|
||||
<artifactId>discordsrv</artifactId>
|
||||
<version>1.26.2</version>
|
||||
<version>1.27.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -151,7 +159,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.Auxilor</groupId>
|
||||
<artifactId>EcoEnchants</artifactId>
|
||||
<version>12.2.3</version>
|
||||
<version>12.5.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -166,6 +174,24 @@
|
||||
<version>6.66.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>be.maximvdw</groupId>
|
||||
<artifactId>MVdWPlaceholderAPI</artifactId>
|
||||
<version>3.1.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -5,15 +5,14 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@@ -23,16 +22,25 @@ import me.dadus33.chatitem.chatmanager.ChatEventListener;
|
||||
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.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.IPlaceholders;
|
||||
import me.dadus33.chatitem.hook.placeholders.MVdWPlaceholderAPIHook;
|
||||
import me.dadus33.chatitem.hook.placeholders.OwnPlaceholder;
|
||||
import me.dadus33.chatitem.hook.placeholders.PlaceholderAPIHook;
|
||||
import me.dadus33.chatitem.hook.placeholders.VaultPlaceholderHook;
|
||||
import me.dadus33.chatitem.invsee.InvShower;
|
||||
import me.dadus33.chatitem.itemnamer.NamerManager;
|
||||
import me.dadus33.chatitem.listeners.InventoryListener;
|
||||
import me.dadus33.chatitem.listeners.JoinListener;
|
||||
import me.dadus33.chatitem.listeners.TranslationInventoryListener;
|
||||
import me.dadus33.chatitem.platform.IPlatform;
|
||||
import me.dadus33.chatitem.platform.hook.PaperPlatform;
|
||||
import me.dadus33.chatitem.platform.hook.SpigotPlatform;
|
||||
import me.dadus33.chatitem.playernamer.PlayerNamerManager;
|
||||
import me.dadus33.chatitem.utils.ReflectionUtils;
|
||||
import me.dadus33.chatitem.utils.SemVer;
|
||||
@@ -41,6 +49,19 @@ import me.dadus33.chatitem.utils.Version;
|
||||
|
||||
public class ChatItem extends JavaPlugin {
|
||||
|
||||
private static final List<IPlaceholders> PLACEHOLDERS = new ArrayList<>();
|
||||
public static List<IPlaceholders> getPlaceholders() {
|
||||
return PLACEHOLDERS;
|
||||
}
|
||||
public static String replace(Player p, String text) {
|
||||
for(IPlaceholders ip : getPlaceholders())
|
||||
text = ip.replace(p, text);
|
||||
return text;
|
||||
}
|
||||
private static final IPlatform platform = Utils.IS_PAPER ? new PaperPlatform() : new SpigotPlatform();
|
||||
public static IPlatform getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
public final static int CFG_VER = 13;
|
||||
public static boolean discordSrvSupport = false, hasNewVersion = false;
|
||||
private static ChatItem instance;
|
||||
@@ -53,7 +74,6 @@ public class ChatItem extends JavaPlugin {
|
||||
if (pl.getConfig().getKeys(false).isEmpty())
|
||||
pl.saveDefaultConfig();
|
||||
pl.reloadConfig();
|
||||
String oldChatManager = pl.storage.manager;
|
||||
pl.storage = new Storage(pl.getConfig());
|
||||
pl.chooseManagers();
|
||||
Translation.load(pl);
|
||||
@@ -61,8 +81,6 @@ public class ChatItem extends JavaPlugin {
|
||||
if(sender != null) {
|
||||
if (!pl.storage.messageReload.isEmpty())
|
||||
sender.sendMessage(pl.storage.messageReload);
|
||||
if (!oldChatManager.equalsIgnoreCase(pl.storage.manager))
|
||||
sender.sendMessage(ChatColor.GOLD + "Changing the manager with command reloading CAN produce issue. It's mostly suggested to restart after finding the better manager for you.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,28 +99,23 @@ public class ChatItem extends JavaPlugin {
|
||||
private void chooseManagers() {
|
||||
this.chatManager.forEach((cm) -> cm.unload(this));
|
||||
this.chatManager.clear();
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
|
||||
this.chatManager.add(new PacketEditingChatManager(this));
|
||||
this.chatManager.add(new ChatListenerChatManager(this));
|
||||
if(Utils.IS_PAPER)
|
||||
this.chatManager.add(new PaperChatManager(this));
|
||||
|
||||
String managerName = getStorage().manager;
|
||||
|
||||
switch (managerName.toLowerCase(Locale.ROOT)) {
|
||||
case "both":
|
||||
this.chatManager.add(new PacketEditingChatManager(this));
|
||||
this.chatManager.add(new ChatListenerChatManager(this));
|
||||
getLogger().info("Manager automatically chosen: " + getVisualChatManagers());
|
||||
break;
|
||||
case "all":
|
||||
case "auto":
|
||||
if (getPluginThatRequirePacket().stream().map(pm::getPlugin).anyMatch(Objects::nonNull) && Version.getVersion().isNewerThan(Version.V1_7))
|
||||
this.chatManager.add(new PacketEditingChatManager(this));
|
||||
else
|
||||
this.chatManager.add(new ChatListenerChatManager(this));
|
||||
getLogger().info("Manager automatically chosen: " + getVisualChatManagers());
|
||||
break;
|
||||
case "paper":
|
||||
case "packet":
|
||||
this.chatManager.add(new PacketEditingChatManager(this));
|
||||
getLogger().info("Manager chosen: " + getVisualChatManagers());
|
||||
break;
|
||||
case "chat":
|
||||
this.chatManager.add(new ChatListenerChatManager(this));
|
||||
getLogger().info("Manager chosen: " + getVisualChatManagers());
|
||||
break;
|
||||
default:
|
||||
@@ -111,7 +124,6 @@ public class ChatItem extends JavaPlugin {
|
||||
getLogger().severe("Please reset your config and/or check wiki for more information");
|
||||
getLogger().severe("Using default manager: chat.");
|
||||
getLogger().severe("----- WARN -----");
|
||||
this.chatManager.add(new ChatListenerChatManager(this));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -121,7 +133,7 @@ public class ChatItem extends JavaPlugin {
|
||||
PlayerNamerManager.load(this);
|
||||
}
|
||||
|
||||
private List<String> getPluginThatRequirePacket() {
|
||||
public static List<String> getPluginThatRequirePacket() {
|
||||
return Arrays.asList("DeluxeChat", "HexNicks", "VentureChat", "ItemsAdder");
|
||||
}
|
||||
|
||||
@@ -129,7 +141,7 @@ public class ChatItem extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
// Save the instance (we're basically a singleton)
|
||||
instance = this;
|
||||
getLogger().info("Detected server version: " + Version.getVersion().name().toLowerCase());
|
||||
getLogger().info("Detected server version: " + Version.getVersion().name().toLowerCase() + " (Platform: " + getPlatform().getName() + ")");
|
||||
|
||||
// Load config
|
||||
if (!new File(getDataFolder(), "config.yml").exists()) {
|
||||
@@ -173,10 +185,23 @@ public class ChatItem extends JavaPlugin {
|
||||
if (pm.isPluginEnabled("EcoEnchants") && EcoEnchantsSupport.load()) {
|
||||
plugins.add("EcoEnchants");
|
||||
}
|
||||
if (pm.isPluginEnabled("PlaceholderAPI")) {
|
||||
plugins.add("PlaceholderAPI");
|
||||
PLACEHOLDERS.add(new PlaceholderAPIHook());
|
||||
}
|
||||
if (pm.isPluginEnabled("MVdWPlaceholderAPI")) {
|
||||
plugins.add("MVdWPlaceholderAPI");
|
||||
PLACEHOLDERS.add(new MVdWPlaceholderAPIHook());
|
||||
}
|
||||
if (pm.isPluginEnabled("Vault")) {
|
||||
plugins.add("Vault");
|
||||
PLACEHOLDERS.add(new VaultPlaceholderHook());
|
||||
}
|
||||
|
||||
if (plugins.length() > 0)
|
||||
getLogger().info("Load " + plugins.toString() + " support.");
|
||||
|
||||
PLACEHOLDERS.add(new OwnPlaceholder());
|
||||
Translation.load(this);
|
||||
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this, brandChannelName, (chan, p, msg) -> ItemPlayer.getPlayer(p).setClientName(new String(msg).substring(1)));
|
||||
@@ -187,12 +212,12 @@ public class ChatItem extends JavaPlugin {
|
||||
String content = Utils.getFromURL(urlName);
|
||||
if (Strings.isNullOrEmpty(content))
|
||||
return;
|
||||
SemVer currentVersion = SemVer.parse(getDescription().getVersion());
|
||||
SemVer currentVersion = SemVer.parse(getPlatform().getPluginVersion(this));
|
||||
if (currentVersion == null)
|
||||
return;
|
||||
SemVer latestVersion = SemVer.parse(content);
|
||||
if (latestVersion != null && latestVersion.isNewerThan(currentVersion)) {
|
||||
hasNewVersion = !content.equalsIgnoreCase(getDescription().getVersion());
|
||||
hasNewVersion = !content.equalsIgnoreCase(getPlatform().getPluginVersion(this));
|
||||
if (hasNewVersion)
|
||||
getLogger().info(storage.updateMessage);
|
||||
}
|
||||
@@ -214,6 +239,14 @@ public class ChatItem extends JavaPlugin {
|
||||
public List<ChatManager> getChatManager() {
|
||||
return chatManager;
|
||||
}
|
||||
|
||||
public boolean isManagerEnabled(String id) {
|
||||
for (ChatManager cm : chatManager) {
|
||||
if(cm.getId().equalsIgnoreCase(id))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getVisualChatManagers() {
|
||||
StringJoiner sj = new StringJoiner(", ");
|
||||
|
||||
@@ -3,9 +3,10 @@ package me.dadus33.chatitem;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import me.dadus33.chatitem.utils.Colors;
|
||||
|
||||
public class Storage {
|
||||
|
||||
public String handName, nameFormat, amountFormat, commandFormat, manager, permissionName, buggedClientAction, language;
|
||||
@@ -22,6 +23,8 @@ public class Storage {
|
||||
configVersion = conf.getInt("config-version", 13);
|
||||
checkConfigVersion();
|
||||
this.manager = conf.getString("manager", "auto");
|
||||
if(manager == "both")
|
||||
manager = "all";
|
||||
language = conf.getString("general.language", "en_gb");
|
||||
debug = conf.getBoolean("debug", false);
|
||||
nameFormat = color(conf.getString("general.name-format", "&b&l&o{name} {amount}&r"));
|
||||
@@ -61,7 +64,7 @@ public class Storage {
|
||||
}
|
||||
|
||||
public static String color(String s) {
|
||||
return s == null || s.isEmpty() ? s : ChatColor.translateAlternateColorCodes('&', s);
|
||||
return s == null || s.isEmpty() ? s : Colors.translateAlternateColorCodes('&', s);
|
||||
}
|
||||
|
||||
private static void colorStringList(List<String> input) {
|
||||
@@ -74,10 +77,10 @@ public class Storage {
|
||||
int latestVersion = ChatItem.CFG_VER;
|
||||
if (latestVersion != configVersion) {
|
||||
ChatItem pl = ChatItem.getInstance();
|
||||
pl.getLogger().warning(ChatColor.RED + "ChatItem detected an older or invalid configuration file. Replacing it with the default config...");
|
||||
pl.getLogger().warning("ChatItem detected an older or invalid configuration file. Replacing it with the default config...");
|
||||
performOverwrite();
|
||||
conf = pl.getConfig();
|
||||
pl.getLogger().warning(ChatColor.RED + "Replacement complete!");
|
||||
pl.getLogger().warning("Replacement complete!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.stream.Collectors;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
@@ -53,6 +54,11 @@ public class Translation {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public static String getMessage(String key) {
|
||||
JsonElement result = messages.get(key);
|
||||
return result == null ? "" : result.getAsString();
|
||||
}
|
||||
|
||||
public static void loadLang(String lang) {
|
||||
ChatItem pl = ChatItem.getInstance();
|
||||
File langFile = new File(folder, lang + ".json");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.dadus33.chatitem.chatmanager;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.dadus33.chatitem.ItemSlot;
|
||||
@@ -10,19 +11,26 @@ public class ChatAction {
|
||||
private ItemSlot slot;
|
||||
private String command;
|
||||
private ItemStack item;
|
||||
private Player origin;
|
||||
|
||||
public ChatAction(ItemSlot slot, ItemStack item) {
|
||||
public ChatAction(ItemSlot slot, Player origin, ItemStack item) {
|
||||
this.slot = slot;
|
||||
this.item = item;
|
||||
this.origin = origin;
|
||||
this.isItem = true;
|
||||
}
|
||||
|
||||
public ChatAction(ItemSlot slot, String command) {
|
||||
public ChatAction(ItemSlot slot, Player origin, String command) {
|
||||
this.slot = slot;
|
||||
this.command = command;
|
||||
this.origin = origin;
|
||||
this.isItem = false;
|
||||
}
|
||||
|
||||
public Player getOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
public ItemSlot getSlot() {
|
||||
return slot;
|
||||
}
|
||||
@@ -35,6 +43,10 @@ public class ChatAction {
|
||||
return command;
|
||||
}
|
||||
|
||||
public boolean hasCommand() {
|
||||
return command != null && command != "";
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import me.dadus33.chatitem.ItemSlot;
|
||||
import me.dadus33.chatitem.Storage;
|
||||
import me.dadus33.chatitem.utils.Utils;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ChatEventListener implements Listener {
|
||||
|
||||
private Storage getStorage() {
|
||||
@@ -24,6 +25,8 @@ public class ChatEventListener implements Listener {
|
||||
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()));
|
||||
}
|
||||
@@ -35,7 +38,7 @@ public class ChatEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
ChatAction action = ChatManager.getChatAction(slot, p);
|
||||
if(action.isItem() && !ChatManager.canShowItem(p, action.getItem(), slot, e))
|
||||
if(!ChatManager.canUsePlaceholder(p, action.getItem(), slot, e))
|
||||
return;
|
||||
String s = slot.replacePlaceholdersToSeparator(e.getMessage());
|
||||
if (Utils.countMatches(s, Character.toString(ChatManager.SEPARATOR)) > getStorage().limit) {
|
||||
|
||||
@@ -4,11 +4,12 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -26,10 +27,13 @@ import me.dadus33.chatitem.invsee.InvShower;
|
||||
import me.dadus33.chatitem.invsee.hook.EnderChestShower;
|
||||
import me.dadus33.chatitem.invsee.hook.PlayerInventoryShower;
|
||||
import me.dadus33.chatitem.itemnamer.NamerManager;
|
||||
import me.dadus33.chatitem.utils.Colors;
|
||||
import me.dadus33.chatitem.utils.ItemUtils;
|
||||
import me.dadus33.chatitem.utils.Messages;
|
||||
import me.dadus33.chatitem.utils.Utils;
|
||||
import me.dadus33.chatitem.utils.Version;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class ChatManager {
|
||||
|
||||
public static String inTest = null;
|
||||
@@ -100,14 +104,14 @@ public abstract class ChatManager {
|
||||
* @return the usable item
|
||||
*/
|
||||
public static ItemStack getUsableItem(Player p, ItemSlot slot) {
|
||||
if(slot == null)
|
||||
if (slot == null)
|
||||
return null;
|
||||
ItemStack betterItem = HandItem.getBetterItem(p, slot);
|
||||
if(betterItem == null)
|
||||
if (betterItem == null)
|
||||
return null;
|
||||
|
||||
|
||||
ItemStack item = betterItem.clone();
|
||||
if(slot.isDenyIfNoItem() && ItemUtils.isEmpty(item))
|
||||
if (slot.isDenyIfNoItem() && ItemUtils.isEmpty(item))
|
||||
return null;
|
||||
if (EcoEnchantsSupport.hasSupport()) {
|
||||
item = EcoEnchantsSupport.manageItem(item);
|
||||
@@ -131,14 +135,14 @@ public abstract class ChatManager {
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
public static ChatAction getChatAction(ItemSlot slot, Player p) {
|
||||
if(slot.isCommand()) {
|
||||
if (slot.isCommand()) {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
InvShower.add(uuid.toString(), slot == ItemSlot.INVENTORY ? new PlayerInventoryShower(p) : new EnderChestShower(p));
|
||||
return new ChatAction(slot, "/chatitem seeinv " + uuid.toString());
|
||||
return new ChatAction(slot, p, "/chatitem seeinv " + uuid.toString());
|
||||
}
|
||||
return new ChatAction(slot, getUsableItem(p, slot));
|
||||
return new ChatAction(slot, p, getUsableItem(p, slot));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,20 +152,20 @@ public abstract class ChatManager {
|
||||
* @param item the item to get lines from
|
||||
* @return all lores
|
||||
*/
|
||||
public static List<String> getMaxLinesFromItem(Player p, ItemStack item) {
|
||||
public static List<String> getMaxLinesFromItem(Player viewer, ItemStack item) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
lines.add(meta.hasDisplayName() ? meta.getDisplayName() : NamerManager.getName(p, item, ChatItem.getInstance().getStorage()));
|
||||
lines.add(meta.hasDisplayName() ? meta.getDisplayName() : NamerManager.getName(viewer, item, ChatItem.getInstance().getStorage()));
|
||||
if (meta.hasEnchants()) {
|
||||
meta.getEnchants().forEach((enchant, lvl) -> {
|
||||
lines.add(ChatColor.RESET + Utils.getEnchantName(enchant) + " " + Utils.toRoman(lvl));
|
||||
lines.add(Colors.RESET + Utils.getEnchantName(enchant) + " " + Utils.toRoman(lvl));
|
||||
});
|
||||
}
|
||||
if (meta.hasLore())
|
||||
lines.addAll(meta.getLore());
|
||||
} else {
|
||||
lines.add(NamerManager.getName(p, item, ChatItem.getInstance().getStorage()));
|
||||
lines.add(NamerManager.getName(viewer, item, ChatItem.getInstance().getStorage()));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
@@ -171,12 +175,12 @@ public abstract class ChatManager {
|
||||
* Prefer use {@link #getNameOfItem(Player, ItemStack, Storage)} if you want
|
||||
* take in count the empty item
|
||||
*
|
||||
* @param p the player
|
||||
* @param item the item
|
||||
* @param c the config
|
||||
* @return the name of item
|
||||
* @param viewer the player
|
||||
* @param item the item
|
||||
* @param c the config
|
||||
* @return the name of item
|
||||
*/
|
||||
public static String styleItem(Player p, ItemStack item, Storage c) {
|
||||
public static String styleItem(Player viewer, ItemStack item, Storage c) {
|
||||
String replacer = c.nameFormat;
|
||||
String amount = c.amountFormat;
|
||||
if (item.getAmount() == 1) {
|
||||
@@ -190,7 +194,7 @@ public abstract class ChatManager {
|
||||
amount = amount.replace(TIMES, String.valueOf(item.getAmount()));
|
||||
replacer = replacer.replace(AMOUNT, amount);
|
||||
}
|
||||
return replacer.replace(NAME, NamerManager.getName(p, item, c));
|
||||
return replacer.replace(NAME, NamerManager.getName(viewer, item, c));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,28 +205,38 @@ public abstract class ChatManager {
|
||||
* @param c the config
|
||||
* @return the name of item or hand
|
||||
*/
|
||||
public static String getNameOfItem(Player p, ItemStack item, Storage c) {
|
||||
public static String getNameOfItem(Player p, ItemStack item, Player viewer, Storage c) {
|
||||
if (ItemUtils.isEmpty(item)) {
|
||||
if (c.handDisabled)
|
||||
return ItemSlot.HAND.getPlaceholders().get(0);
|
||||
else
|
||||
return c.handName;
|
||||
return getHandName(p);
|
||||
}
|
||||
return styleItem(p, item, c);
|
||||
return styleItem(viewer, item, c);
|
||||
}
|
||||
|
||||
public static String getNameForChatAction(Player p, ChatAction action, Storage c) {
|
||||
if(action.isItem()) {
|
||||
|
||||
public static String getNameForChatAction(Player viewer, ChatAction action, Storage c) {
|
||||
if (action.isItem()) {
|
||||
ItemStack item = action.getItem();
|
||||
if (ItemUtils.isEmpty(item)) {
|
||||
if (c.handDisabled)
|
||||
return ItemSlot.HAND.getPlaceholders().get(0);
|
||||
else
|
||||
return c.handName;
|
||||
return getHandName(action.getOrigin());
|
||||
}
|
||||
return styleItem(p, item, c);
|
||||
return styleItem(viewer, item, c);
|
||||
}
|
||||
return "";
|
||||
return 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());
|
||||
}
|
||||
|
||||
public static String getHandName(Chat c) {
|
||||
Player p = c.getPlayer();
|
||||
return ChatItem.getInstance().getStorage().handName.replace("{name}", p.getName()).replace("{display-name}", p.getDisplayName());
|
||||
}
|
||||
|
||||
public static String calculateTime(long seconds) {
|
||||
@@ -254,9 +268,7 @@ public abstract class ChatManager {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static boolean canShowItem(Player p, ItemStack item, ItemSlot slot, @Nullable Cancellable e) {
|
||||
if(item == null)
|
||||
return false;
|
||||
public static boolean canUsePlaceholder(Player p, ItemStack item, ItemSlot slot, @Nullable Cancellable e) {
|
||||
Storage c = ChatItem.getInstance().getStorage();
|
||||
if (c.permissionEnabled && !p.hasPermission(c.permissionName)) {
|
||||
if (!c.letMessageThrough) {
|
||||
@@ -268,7 +280,7 @@ public abstract class ChatManager {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (item.getType().equals(Material.AIR)) {
|
||||
if (item != null && item.getType().equals(Material.AIR)) {
|
||||
if (slot.isDenyIfNoItem()) {
|
||||
if (e != null)
|
||||
e.setCancelled(true);
|
||||
@@ -301,9 +313,11 @@ public abstract class ChatManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String ignored : c.ignoredItems) {
|
||||
if (item.getType().name().toLowerCase().contains(ignored.toLowerCase())) {
|
||||
return false;
|
||||
if (item != null) {
|
||||
for (String ignored : c.ignoredItems) {
|
||||
if (item.getType().name().toLowerCase().contains(ignored.toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,16 +344,34 @@ public abstract class ChatManager {
|
||||
public static void applyCooldown(Player p) {
|
||||
COOLDOWNS.put(p.getUniqueId(), System.currentTimeMillis() / 1000);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isTestingEnabled() {
|
||||
return inTest != null;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isTesting(String actual) {
|
||||
return inTest != null && (inTest == "both" || inTest.equalsIgnoreCase(actual));
|
||||
return inTest != null && (inTest == "both" || inTest == "all" || inTest.equalsIgnoreCase(actual));
|
||||
}
|
||||
|
||||
|
||||
public static void setTesting(String actual) {
|
||||
inTest = actual;
|
||||
}
|
||||
|
||||
public static boolean isSelected(String actual) {
|
||||
if(isTestingEnabled())
|
||||
return true;
|
||||
String selected = ChatItem.getInstance().getStorage().manager;
|
||||
if (selected == "both" || selected == "all")
|
||||
return true;
|
||||
if (selected == "auto") {
|
||||
if (Utils.IS_PAPER && actual == "paper")
|
||||
return true;
|
||||
else if (actual == "packet" && ChatItem.getPluginThatRequirePacket().stream().map(Bukkit.getPluginManager()::getPlugin).anyMatch(Objects::nonNull)
|
||||
&& Version.getVersion().isNewerThan(Version.V1_7))
|
||||
return true;
|
||||
else if (actual == "chat")
|
||||
return true;
|
||||
}
|
||||
return selected.equalsIgnoreCase(actual);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.dadus33.chatitem.chatmanager.v1;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@@ -9,6 +10,7 @@ import me.dadus33.chatitem.Storage;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.listeners.ChatPacketManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.ChatItemPacketManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketContent;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketManager;
|
||||
import me.dadus33.chatitem.utils.PacketUtils;
|
||||
import me.dadus33.chatitem.utils.ReflectionUtils;
|
||||
@@ -73,21 +75,23 @@ public class PacketEditingChatManager extends ChatManager {
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static Object createSystemChatPacket(String json) throws Exception {
|
||||
public static Object createSystemChatPacket(String json, Object old) throws Exception {
|
||||
json = checkPacketSize(json, 150000);
|
||||
Object packet = internalCreateSystemChatPacket(json);
|
||||
Object packet = internalCreateSystemChatPacket(json, old);
|
||||
if(packet != null)
|
||||
return packet;
|
||||
packet = internalCreateSystemChatPacket(PacketUtils.ICB_FROM_JSON.invoke(null, json));
|
||||
Object icb = ChatItem.getPlatform().jsonToBaseComponent(json);
|
||||
if(icb != null)
|
||||
packet = internalCreateSystemChatPacket(icb, old);
|
||||
if(packet != null)
|
||||
return packet;
|
||||
ChatItem.getInstance().getLogger().warning("Can't create a new packet for json " + json);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Object internalCreateSystemChatPacket(Object obj) throws Exception {
|
||||
Class<?> packetClass = PacketUtils.getNmsClass("ClientboundPlayerChatPacket", "network.protocol.game.", "ClientboundSystemChatPacket", "PacketPlayOutChat");
|
||||
Class<?> chatMessageTypeClass = PacketUtils.isClassExist("net.minecraft.network.chat.ChatMessageType") ? PacketUtils.getNmsClass("ChatMessageType", "network.chat.") : null;
|
||||
private static Object internalCreateSystemChatPacket(Object obj, Object old) throws Exception {
|
||||
Class<?> packetClass = PacketUtils.getNmsClass("ClientboundSystemChatPacket", "network.protocol.game.", "ClientboundPlayerChatPacket", "PacketPlayOutChat");
|
||||
Class<?> chatMessageTypeClass = Utils.isClassExist("net.minecraft.network.chat.ChatMessageType") ? PacketUtils.getNmsClass("ChatMessageType", "network.chat.") : null;
|
||||
Constructor<?> betterOne = null;
|
||||
Object[] betterParam = null;
|
||||
for (Constructor<?> cons : packetClass.getDeclaredConstructors()) {
|
||||
@@ -107,20 +111,35 @@ public class PacketEditingChatManager extends ChatManager {
|
||||
else if (secondParam.equals(boolean.class)) // "component", "string", "boolean"
|
||||
return cons.newInstance(null, obj, false);
|
||||
}
|
||||
} else if(obj.getClass().isAssignableFrom(PacketUtils.COMPONENT_CLASS)) {
|
||||
if (cons.getParameterCount() == 2 && cons.getParameterTypes()[0].isAssignableFrom(PacketUtils.COMPONENT_CLASS) && cons.getParameterTypes()[1].equals(boolean.class)) // "string, boolean"
|
||||
return cons.newInstance(obj, false);
|
||||
}
|
||||
|
||||
int nbPut = 0;
|
||||
Object[] params = new Object[cons.getParameterCount()];
|
||||
for(int i = 0; i < params.length; i++) {
|
||||
if(cons.getParameterTypes()[i].isAssignableFrom(obj.getClass())) {
|
||||
Class<?> type = cons.getParameterTypes()[i];
|
||||
if(type.isAssignableFrom(obj.getClass())) {
|
||||
params[i] = obj;
|
||||
nbPut++;
|
||||
} else if(chatMessageTypeClass != null && cons.getParameterTypes()[i].isAssignableFrom(chatMessageTypeClass)) {
|
||||
} else if(chatMessageTypeClass != null && type.isAssignableFrom(chatMessageTypeClass)) {
|
||||
params[i] = getChatMessageType();
|
||||
} else if(cons.getParameterTypes()[i].isAssignableFrom(boolean.class)) // need to set primitives
|
||||
} else if(type.isAssignableFrom(boolean.class)) // need to set primitives
|
||||
params[i] = false;
|
||||
else if(cons.getParameterTypes()[i].isAssignableFrom(int.class)) // need to set primitives
|
||||
else if(type.isAssignableFrom(int.class)) // need to set primitives
|
||||
params[i] = 0;
|
||||
else {
|
||||
boolean found = false;
|
||||
for(Class<?> prim : Arrays.asList(float.class, long.class)) { // if not primitive
|
||||
if(type.isAssignableFrom(prim)) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if(!found) {
|
||||
params[i] = new PacketContent(old).getSpecificModifier(type).readSafely(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(nbPut == 1) {
|
||||
if((betterOne == null && betterParam == null) || betterParam.length > params.length) {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package me.dadus33.chatitem.chatmanager.v1.basecomp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -44,12 +45,12 @@ public interface IComponentManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
default Object manageItem(Player p, Chat chat, ChatItemPacket packet, ItemStack item, String json, Storage c) throws Exception {
|
||||
default Object manageContent(Player viewer, Chat chat, ChatItemPacket packet, String json, Storage c) throws Exception {
|
||||
String message;
|
||||
if (Utils.isBeforeChatJson(p))
|
||||
message = JSONManipulator.getInstance().parseEmpty(json, ChatManager.styleItem(chat.getPlayer(), item, c), ChatManager.getMaxLinesFromItem(p, item), chat.getPlayer());
|
||||
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.styleItem(chat.getPlayer(), item, c));
|
||||
message = JSONManipulator.getInstance().parse(chat, json, chat.getAction(), ChatManager.getNameForChatAction(viewer, chat.getAction(), c));
|
||||
if (message != null) {
|
||||
ChatItem.debug("(v1) Writing message: " + message);
|
||||
writeJson(packet, message);
|
||||
@@ -58,7 +59,7 @@ public interface IComponentManager {
|
||||
}
|
||||
|
||||
default Object manageEmpty(Player p, Chat chat, ChatItemPacket packet, String json, Storage c) {
|
||||
String message = JSONManipulator.getInstance().parseEmpty(json, c.handName, c.tooltipHand, chat.getPlayer());
|
||||
String message = JSONManipulator.getInstance().parseEmpty(chat, json, c.tooltipHand, chat.getPlayer());
|
||||
if (message != null) {
|
||||
ChatItem.debug("(v1) Writing empty message: " + message);
|
||||
writeJson(packet, message);
|
||||
|
||||
+20
-51
@@ -1,8 +1,6 @@
|
||||
package me.dadus33.chatitem.chatmanager.v1.basecomp.hook;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -22,15 +20,13 @@ 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 net.kyori.adventure.audience.Audience;
|
||||
import me.dadus33.chatitem.utils.Utils;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.nbt.api.BinaryTagHolder;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
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.format.TextColor;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
public class AdventureComponentManager implements IComponentManager {
|
||||
@@ -67,34 +63,39 @@ public class AdventureComponentManager implements IComponentManager {
|
||||
}
|
||||
return json;
|
||||
} catch (JsonParseException e) { // ignore this and just let skip this
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object manageItem(Player p, Chat chat, ChatItemPacket packet, ItemStack item, String json, Storage c) throws Exception {
|
||||
public Object manageContent(Player viewer, Chat chat, ChatItemPacket packet, String json, Storage c) throws Exception {
|
||||
ChatAction action = chat.getAction();
|
||||
if (action.isItem()) {
|
||||
String itemName = ChatManager.getNameOfItem(chat.getPlayer(), item, c);
|
||||
ItemStack item = action.getItem();
|
||||
String itemName = ChatManager.getNameOfItem(chat.getPlayer(), item, viewer, c);
|
||||
ChatItem.debug("NBT tag: " + PacketUtils.getNbtTag(item));
|
||||
return manage(p, chat, packet, itemName, HoverEvent.showItem(Key.key(item.getType().getKey().getKey()), item.getAmount(), BinaryTagHolder.of(PacketUtils.getNbtTag(item))), null);
|
||||
HoverEvent<?> hover;
|
||||
if(Utils.IS_PAPER)
|
||||
hover = item.asHoverEvent();
|
||||
else
|
||||
hover = HoverEvent.showItem(Key.key(item.getType().getKey().getKey()), item.getAmount(), BinaryTagHolder.of(PacketUtils.getNbtTag(item)));
|
||||
return manage(viewer, chat, packet, itemName, hover, null);
|
||||
}
|
||||
return manage(p, chat, packet, Messages.getMessage(action.getSlot().name().toLowerCase() + ".chat", "%cible%", chat.getPlayer().getName()),
|
||||
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()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object manageEmpty(Player p, Chat chat, ChatItemPacket packet, String json, Storage c) {
|
||||
public Object manageEmpty(Player viewer, Chat chat, ChatItemPacket packet, String json, Storage c) {
|
||||
Component builder = Component.text("");
|
||||
c.tooltipHand.forEach(s -> builder.append(Component.text(s)));
|
||||
Player sender = chat.getPlayer();
|
||||
ChatAction action = chat.getAction();
|
||||
if (action.isItem()) {
|
||||
String handName = c.handName.replace("{name}", sender.getName()).replace("{display-name}", sender.getDisplayName());
|
||||
return manage(p, chat, packet, handName, HoverEvent.showText(builder), null);
|
||||
return manage(viewer, chat, packet, ChatManager.getHandName(chat), HoverEvent.showText(builder), null);
|
||||
}
|
||||
return manage(p, chat, packet, Messages.getMessage(action.getSlot().name().toLowerCase() + ".chat", "%cible%", chat.getPlayer().getName()),
|
||||
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()));
|
||||
}
|
||||
@@ -106,42 +107,10 @@ public class AdventureComponentManager implements IComponentManager {
|
||||
ChatItem.debug("The component is null.");
|
||||
return null;
|
||||
}
|
||||
comp = checkComponent(comp, hover, click, replacement, chat);
|
||||
if(ChatItem.discordSrvSupport && DiscordSrvSupport.isSendingMessage())
|
||||
DiscordSrvSupport.sendChatMessage(p, comp, null);
|
||||
try {
|
||||
((Audience) Audience.class.getDeclaredMethod("audience", Audience.class).invoke(null, p)).sendMessage(comp);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
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())
|
||||
DiscordSrvSupport.sendChatMessage(chat.getPlayer(), comp, null);
|
||||
modifier.write(0, comp);
|
||||
return null; // send by manager
|
||||
}
|
||||
|
||||
private Component checkComponent(Component comp, HoverEvent<?> hover, ClickEvent click, String itemName, Chat chat) {
|
||||
if (comp instanceof TextComponent) {
|
||||
TextComponent tc = (TextComponent) comp;
|
||||
if (ChatManager.containsSeparator(tc.content())) {
|
||||
ChatItem.debug("Changing text " + tc.content() + " to " + itemName);
|
||||
TextColor color = tc.color();
|
||||
comp = tc.content(ChatManager.replaceSeparator(chat, tc.content(), itemName)).hoverEvent(hover);
|
||||
if (click != null)
|
||||
comp.clickEvent(click);
|
||||
comp.append(Component.text("").color(color)); // reset color
|
||||
} else
|
||||
ChatItem.debug("No insert of text without separator: " + tc.content());
|
||||
} else if (comp instanceof TranslatableComponent) {
|
||||
TranslatableComponent tc = (TranslatableComponent) comp;
|
||||
List<Component> next = new ArrayList<>();
|
||||
for (Component extra : tc.args()) {
|
||||
next.add(checkComponent(extra, hover, click, itemName, chat));
|
||||
}
|
||||
comp = tc.args(next);
|
||||
} else
|
||||
ChatItem.debug("Not valid comp class " + comp.getClass().getSimpleName() + " : " + comp);
|
||||
List<Component> next = new ArrayList<>();
|
||||
for (Component extra : comp.children()) {
|
||||
next.add(checkComponent(extra, hover, click, itemName, chat));
|
||||
}
|
||||
return comp.children(next);
|
||||
}
|
||||
}
|
||||
+3
-4
@@ -7,13 +7,12 @@ import me.dadus33.chatitem.chatmanager.v1.PacketEditingChatManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.basecomp.IComponentManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.ChatItemPacket;
|
||||
import me.dadus33.chatitem.hook.DiscordSrvSupport;
|
||||
import me.dadus33.chatitem.utils.PacketUtils;
|
||||
|
||||
public class ComponentNMSManager implements IComponentManager {
|
||||
|
||||
@Override
|
||||
public boolean hasConditions() {
|
||||
return PacketUtils.COMPONENT_CLASS != null;
|
||||
return ChatItem.getPlatform().hasBaseComponentSerializer();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -21,7 +20,7 @@ public class ComponentNMSManager implements IComponentManager {
|
||||
Object chatBaseComp = packet.getContent().getChatComponents().readSafely(0);
|
||||
if (chatBaseComp != null) {
|
||||
try {
|
||||
Object o = PacketUtils.CHAT_SERIALIZER.getMethod("a", PacketUtils.COMPONENT_CLASS).invoke(null, chatBaseComp);
|
||||
Object o = ChatItem.getPlatform().baseComponentToJson(chatBaseComp);
|
||||
if(o != null && o instanceof String && JsonParser.parseString((String) o).isJsonObject()) {
|
||||
return (String) o;
|
||||
}
|
||||
@@ -39,7 +38,7 @@ public class ComponentNMSManager implements IComponentManager {
|
||||
ChatItem.debug("(v1 ComponentNMS) Can't send message to discord");
|
||||
// DiscordSrvSupport.sendChatMessage(p, comp, null);
|
||||
try {
|
||||
packet.setPacket(PacketEditingChatManager.createSystemChatPacket(json));
|
||||
packet.setPacket(PacketEditingChatManager.createSystemChatPacket(json, packet.getPacket()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
+3
-25
@@ -1,44 +1,22 @@
|
||||
package me.dadus33.chatitem.chatmanager.v1.basecomp.hook;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.chatmanager.v1.PacketEditingChatManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.basecomp.IComponentManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.ChatItemPacket;
|
||||
import me.dadus33.chatitem.utils.PacketUtils;
|
||||
|
||||
public class IChatBaseComponentManager implements IComponentManager {
|
||||
|
||||
private Method serializerGetJson;
|
||||
|
||||
public IChatBaseComponentManager() {
|
||||
try {
|
||||
Class<?> chatSerializer = PacketUtils.CHAT_SERIALIZER;
|
||||
//fromJson = chatSerializer.getMethod("a", String.class);
|
||||
for (Method m : chatSerializer.getDeclaredMethods()) {
|
||||
if (m.getParameterCount() == 1 && m.getParameterTypes()[0].equals(PacketUtils.COMPONENT_CLASS) && m.getReturnType().equals(String.class)) {
|
||||
serializerGetJson = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (serializerGetJson == null)
|
||||
ChatItem.getInstance().getLogger().warning("Failed to find JSON serializer in class: " + chatSerializer.getCanonicalName());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasConditions() {
|
||||
return serializerGetJson != null;
|
||||
return ChatItem.getPlatform().hasBaseComponentSerializer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBaseComponentAsJSON(ChatItemPacket packet) {
|
||||
try {
|
||||
Object obj = packet.getContent().getChatComponents().readSafely(0);
|
||||
return obj == null ? null : (String) serializerGetJson.invoke(null, obj);
|
||||
return obj == null ? null : (String) ChatItem.getPlatform().baseComponentToJson(obj);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
}
|
||||
@@ -48,7 +26,7 @@ public class IChatBaseComponentManager implements IComponentManager {
|
||||
@Override
|
||||
public void writeJson(ChatItemPacket packet, String json) {
|
||||
try {
|
||||
packet.setPacket(PacketEditingChatManager.createSystemChatPacket(json));
|
||||
packet.setPacket(PacketEditingChatManager.createSystemChatPacket(json, packet.getPacket()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ public class PCMComponentManager implements IComponentManager {
|
||||
Object chatBaseComp = ReflectionUtils.getMethod(pcmClass, PacketUtils.COMPONENT_CLASS).invoke(pcm);
|
||||
if(chatBaseComp != null)
|
||||
ChatItem.debug("[PCMManager] Founded " + chatBaseComp.getClass().getSimpleName());
|
||||
return chatBaseComp == null ? null : PacketUtils.CHAT_SERIALIZER.getMethod("a", PacketUtils.COMPONENT_CLASS).invoke(null, chatBaseComp).toString();
|
||||
return chatBaseComp == null ? null : ChatItem.getPlatform().baseComponentToJson(chatBaseComp);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class PCMComponentManager implements IComponentManager {
|
||||
@Override
|
||||
public void writeJson(ChatItemPacket packet, String json) {
|
||||
try {
|
||||
Object chatComp = PacketUtils.CHAT_SERIALIZER.getMethod("a", String.class).invoke(null, json);
|
||||
Object chatComp = ChatItem.getPlatform().jsonToBaseComponent(json);
|
||||
Class<?> pcmClass = PacketUtils.getNmsClass("PlayerChatMessage", "network.chat.");
|
||||
ContentModifier<Object> pcmModifier = packet.getContent().getSpecificModifier((Class<Object>) pcmClass);
|
||||
Object pcm = ReflectionUtils.getMethod(pcmClass, pcmClass, PacketUtils.COMPONENT_CLASS).invoke(pcmModifier.readSafely(0), chatComp);
|
||||
|
||||
+12
-15
@@ -3,7 +3,6 @@ package me.dadus33.chatitem.chatmanager.v1.basecomp.hook;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -57,45 +56,43 @@ public class StringComponentManager implements IComponentManager {
|
||||
@Override
|
||||
public void writeJson(ChatItemPacket packet, String json) {
|
||||
try {
|
||||
packet.setPacket(PacketEditingChatManager.createSystemChatPacket(json));
|
||||
packet.setPacket(PacketEditingChatManager.createSystemChatPacket(json, packet.getPacket()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object manageItem(Player p, Chat chat, ChatItemPacket packet, ItemStack item, String json, Storage c) throws Exception {
|
||||
public Object manageContent(Player viewer, Chat chat, ChatItemPacket packet, String json, Storage c) throws Exception {
|
||||
ChatAction action = chat.getAction();
|
||||
if (action.isItem())
|
||||
return manage(p, chat, packet, ChatManager.getNameOfItem(chat.getPlayer(), item, c), Utils.createItemHover(item, p), null);
|
||||
return manage(viewer, chat, packet, ChatManager.getNameOfItem(chat.getPlayer(), action.getItem(), viewer, c), Utils.createItemHover(action.getItem(), viewer), null);
|
||||
else
|
||||
return manage(p, chat, packet, ChatManager.getNameOfItem(chat.getPlayer(), item, c),
|
||||
Utils.createTextHover(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover", "%cible%", chat.getPlayer().getName())),
|
||||
Utils.createRunCommand(action.getCommand()));
|
||||
return manage(viewer, chat, packet, ChatManager.getNameForChatAction(viewer, action, c),
|
||||
Utils.createTextHover(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover", "%cible%", chat.getPlayer().getName())), Utils.createRunCommand(action.getCommand()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object manageEmpty(Player p, Chat chat, ChatItemPacket packet, String json, Storage c) {
|
||||
public Object manageEmpty(Player viewer, Chat chat, ChatItemPacket packet, String json, Storage c) {
|
||||
ComponentBuilder builder = new ComponentBuilder("");
|
||||
c.tooltipHand.forEach(s -> builder.append(s));
|
||||
Player sender = chat.getPlayer();
|
||||
HoverEvent hover;
|
||||
ClickEvent click;
|
||||
String rep;
|
||||
ChatAction action = chat.getAction();
|
||||
if (action.isItem()) {
|
||||
hover = Utils.createTextHover(builder.create());
|
||||
rep = c.handName.replace("{name}", sender.getName()).replace("{display-name}", sender.getDisplayName());
|
||||
rep = ChatManager.getHandName(chat);
|
||||
click = null;
|
||||
} else {
|
||||
hover = Utils.createTextHover(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover", "%cible%", chat.getPlayer().getName()));
|
||||
rep = Messages.getMessage(action.getSlot().name().toLowerCase() + ".chat", "%cible%", chat.getPlayer().getName());
|
||||
click = Utils.createRunCommand(action.getCommand());
|
||||
}
|
||||
return manage(p, chat, packet, rep, hover, click);
|
||||
return manage(viewer, chat, packet, rep, hover, click);
|
||||
}
|
||||
|
||||
private Object manage(Player p, Chat chat, ChatItemPacket packet, String replacement, HoverEvent hover, ClickEvent click) {
|
||||
private Object manage(Player viewer, Chat chat, ChatItemPacket packet, String replacement, HoverEvent hover, ClickEvent click) {
|
||||
BaseComponent[] components = packet.getContent().getSpecificModifier(BaseComponent[].class).readSafely(0);
|
||||
if (components == null) {
|
||||
String json = packet.getContent().getStrings().readSafely(0);
|
||||
@@ -125,10 +122,10 @@ public class StringComponentManager implements IComponentManager {
|
||||
ChatItem.debug("Checking for " + components.length + " components");
|
||||
Arrays.asList(components).forEach(comp -> checkComponent(comp, hover, click, replacement, chat));
|
||||
|
||||
if(ChatItem.discordSrvSupport && DiscordSrvSupport.isSendingMessage())
|
||||
DiscordSrvSupport.sendChatMessage(p, TextComponent.toLegacyText(components), null);
|
||||
if (ChatItem.discordSrvSupport && DiscordSrvSupport.isSendingMessage() && viewer == chat.getPlayer())
|
||||
DiscordSrvSupport.sendChatMessage(viewer, TextComponent.toLegacyText(components), null);
|
||||
try {
|
||||
packet.setPacket(PacketEditingChatManager.createSystemChatPacket(ComponentSerializer.toString(components)));
|
||||
packet.setPacket(PacketEditingChatManager.createSystemChatPacket(ComponentSerializer.toString(components), packet.getPacket()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -45,9 +45,19 @@ public class JSONManipulator {
|
||||
public static final Field MAP = ReflectionUtils.getField(NBT_TAG_COMPOUND, "map", "x");
|
||||
|
||||
private JsonArray classicTooltip;
|
||||
|
||||
private JsonObject parseOrGet(String json) {
|
||||
try {
|
||||
return JsonParser.parseString(json).getAsJsonObject();
|
||||
} catch (Exception e) {
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.addProperty("text", json);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
public String parse(Chat chat, String json, ChatAction action, String replacement) throws Exception {
|
||||
JsonObject obj = JsonParser.parseString(json).getAsJsonObject();
|
||||
JsonObject obj = parseOrGet(json);
|
||||
|
||||
JsonObject wrapper = new JsonObject(); // Create a wrapper object for the whole array
|
||||
JsonArray use = Translator.toJson(replacement); // We get the json representation of the old color
|
||||
@@ -67,7 +77,9 @@ 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", parseEmpty(json, replacement, Arrays.asList(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover", "%cible%", chat.getItemPlayer().getPlayer().getName())), chat.getPlayer()));
|
||||
JsonArray hoverArray = new JsonArray();
|
||||
hoverArray.add(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover", "%cible%", chat.getItemPlayer().getPlayer().getName()));
|
||||
hover.add("value", hoverArray);
|
||||
|
||||
JsonObject click = new JsonObject();
|
||||
click.addProperty("action", "run_command");
|
||||
@@ -102,10 +114,11 @@ public class JSONManipulator {
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
public String parseEmpty(String json, String repl, List<String> tooltip, Player sender) {
|
||||
JsonObject obj = JsonParser.parseString(json).getAsJsonObject();
|
||||
@SuppressWarnings("deprecation")
|
||||
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(repl.replace("{name}", sender.getName()).replace("{display-name}", sender.getDisplayName()));
|
||||
JsonArray use = Translator.toJson(ChatManager.getNameForChatAction(chat.getPlayer(), chat.getAction(), 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("");
|
||||
@@ -136,6 +149,7 @@ public class JSONManipulator {
|
||||
boolean isComplex = false;
|
||||
for (int i = 0; i < arr.size(); ++i) {
|
||||
JsonElement element = arr.get(i);
|
||||
ChatItem.debug("[JsonManipulator] Element: " + element.toString());
|
||||
if (element.isJsonNull()) {
|
||||
continue;
|
||||
} else if (element.isJsonObject()) {
|
||||
@@ -201,7 +215,6 @@ public class JSONManipulator {
|
||||
}
|
||||
|
||||
private void addParsedStringToArray(String msg, JsonArray rep, JsonElement o, JsonElement tooltip) {
|
||||
ChatItem.debug("Checking " + msg + " > " + rep + ", o: " + o);
|
||||
if (!ChatManager.containsSeparator(msg)) {
|
||||
rep.add(o);
|
||||
return;
|
||||
@@ -211,7 +224,9 @@ public class JSONManipulator {
|
||||
for (String parts : msg.split("")) {
|
||||
if (ChatManager.equalsSeparator(parts)) {
|
||||
if (!current.isEmpty()) {
|
||||
rep.add(current);
|
||||
JsonObject jsonObj = o.getAsJsonObject().deepCopy();
|
||||
jsonObj.addProperty("text", current); // edit text
|
||||
rep.add(jsonObj); // add with all basic coloring things
|
||||
current = "";
|
||||
}
|
||||
rep.add(tooltip);
|
||||
@@ -223,8 +238,11 @@ public class JSONManipulator {
|
||||
current += parts;
|
||||
}
|
||||
}
|
||||
if (!current.isEmpty())
|
||||
rep.add(current);
|
||||
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) {
|
||||
@@ -283,7 +301,6 @@ public class JSONManipulator {
|
||||
sb.append(entry.getKey());
|
||||
sb.append(":");
|
||||
}
|
||||
ChatItem.debug("Cleaning " + entry.getKey() + ": " + entry.getValue() + " > " + cleanStr(entry.getValue()));
|
||||
sb.append(cleanStr(entry.getValue()));
|
||||
}
|
||||
sb.append("}}"); // End of tag and end of item
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package me.dadus33.chatitem.chatmanager.v1.listeners;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -38,24 +37,11 @@ import me.dadus33.chatitem.utils.Version;
|
||||
public class ChatPacketManager extends PacketHandler {
|
||||
|
||||
private Object lastSentPacket = null;
|
||||
private Method serializerGetJson;
|
||||
private PacketEditingChatManager manager;
|
||||
private final List<IComponentManager> componentManager = new ArrayList<>();
|
||||
|
||||
public ChatPacketManager(PacketEditingChatManager manager) {
|
||||
this.manager = manager;
|
||||
try {
|
||||
for (Method m : PacketUtils.CHAT_SERIALIZER.getDeclaredMethods()) {
|
||||
if (m.getParameterCount() == 1 && m.getParameterTypes()[0].equals(PacketUtils.COMPONENT_CLASS) && m.getReturnType().equals(String.class)) {
|
||||
serializerGetJson = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (serializerGetJson == null)
|
||||
ChatItem.getInstance().getLogger().warning("Failed to find JSON serializer in class: " + PacketUtils.CHAT_SERIALIZER.getCanonicalName());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for (IComponentManager getter : Arrays.asList(new StringComponentManager(), new ComponentNMSManager(), new PCMComponentManager())) {
|
||||
tryRegister(getter);
|
||||
@@ -63,7 +49,8 @@ public class ChatPacketManager extends PacketHandler {
|
||||
try {
|
||||
Class.forName("net.kyori.adventure.text.Component");
|
||||
tryRegister(new AdventureComponentManager());
|
||||
} catch (Exception e) {}
|
||||
} 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())));
|
||||
}
|
||||
@@ -75,11 +62,14 @@ public class ChatPacketManager extends PacketHandler {
|
||||
ChatItem.debug("Component " + getter.getClass().getSimpleName() + " doesn't answer conditions");
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onSend(ChatItemPacket e) {
|
||||
if (!e.hasPlayer() || !e.getPacketType().equals(PacketType.Server.CHAT))
|
||||
return;
|
||||
if(ChatManager.isTestingEnabled() && !ChatManager.isTesting("packet"))
|
||||
if (ChatManager.isTestingEnabled() && !ChatManager.isTesting("packet"))
|
||||
return;
|
||||
if(!ChatManager.isSelected("packet"))
|
||||
return;
|
||||
if (lastSentPacket != null && lastSentPacket == e.getPacket())
|
||||
return; // prevent infinite loop
|
||||
@@ -89,10 +79,6 @@ public class ChatPacketManager extends PacketHandler {
|
||||
String json = "{}";
|
||||
IComponentManager choosedGetter = null;
|
||||
if (version.isNewerOrEquals(Version.V1_19)) {
|
||||
/*if (packet.getIntegers().readSafely(0, 0) > 1) { // not parsed chat message type
|
||||
ChatItem.debug("Invalid int: " + packet.getIntegers().read(0));
|
||||
return;
|
||||
}*/
|
||||
choosedGetter = new StringComponentManager();
|
||||
json = choosedGetter.getBaseComponentAsJSON(e); // if null, will be re-checked so anyway
|
||||
} else if (version.isNewerOrEquals(Version.V1_12)) {
|
||||
@@ -101,12 +87,13 @@ public class ChatPacketManager extends PacketHandler {
|
||||
return; // It's an actionbar message, ignoring
|
||||
} else if (version.isNewerOrEquals(Version.V1_8) && packet.getBytes().readSafely(0) == (byte) 2)
|
||||
return; // It's an actionbar message, ignoring
|
||||
if (json == null || choosedGetter == null) {
|
||||
if (json == null || choosedGetter == null || !ChatManager.containsSeparator(json)) {
|
||||
for (IComponentManager getters : componentManager) {
|
||||
String tmpJson = getters.getBaseComponentAsJSON(e);
|
||||
if (tmpJson != null) {
|
||||
json = ChatManager.fixSeparator(tmpJson);
|
||||
choosedGetter = getters;
|
||||
ChatItem.debug("Seems to have one nice manager with " + getters.getClass().getSimpleName() + " (json: " + json + ")");
|
||||
if (ChatManager.containsSeparator(json))
|
||||
break; // be sure it's valid one
|
||||
} else
|
||||
@@ -139,52 +126,55 @@ public class ChatPacketManager extends PacketHandler {
|
||||
Player p = e.getPlayer();
|
||||
String message = null;
|
||||
try {
|
||||
ItemStack item = ChatManager.getUsableItem(itemPlayer, chat.getSlot());
|
||||
if (!ItemUtils.isEmpty(item)) {
|
||||
ItemStack copy = item.clone();
|
||||
|
||||
if (ItemPlayer.getPlayer(p).isBuggedClient()) { // if the guy that will receive it is bugged
|
||||
String act = getStorage().buggedClientAction;
|
||||
List<String> tooltip;
|
||||
if (act.equalsIgnoreCase("tooltip"))
|
||||
tooltip = getStorage().tooltipBuggedClient;
|
||||
else if (act.equalsIgnoreCase("item"))
|
||||
tooltip = ChatManager.getMaxLinesFromItem(p, copy);
|
||||
else if (act.equalsIgnoreCase("show_both")) {
|
||||
tooltip = ChatManager.getMaxLinesFromItem(p, copy);
|
||||
tooltip.addAll(getStorage().tooltipBuggedClient);
|
||||
} else
|
||||
tooltip = new ArrayList<>();
|
||||
message = JSONManipulator.getInstance().parseEmpty(getter.getBaseComponentAsJSON(e), ChatManager.styleItem(p, copy, getStorage()), tooltip, chat.getPlayer());
|
||||
if(message != null) {
|
||||
getter.writeJson(e, message);
|
||||
}
|
||||
lastSentPacket = e.getPacket();
|
||||
}
|
||||
if (copy.hasItemMeta()) {
|
||||
ItemMeta meta = copy.getItemMeta();
|
||||
if (meta instanceof BookMeta) { // filtering written books
|
||||
BookMeta bm = (BookMeta) copy.getItemMeta();
|
||||
bm.setPages(Collections.emptyList());
|
||||
copy.setItemMeta(bm);
|
||||
} else if (meta instanceof BlockStateMeta && Version.getVersion().isNewerOrEquals(Version.V1_9)) { // if it's a block
|
||||
BlockStateMeta bsm = (BlockStateMeta) copy.getItemMeta();
|
||||
if (bsm.hasBlockState() && bsm.getBlockState() instanceof ShulkerBox) {
|
||||
ShulkerBox sb = (ShulkerBox) bsm.getBlockState();
|
||||
for (ItemStack itemInv : sb.getInventory()) {
|
||||
ItemUtils.stripData(itemInv);
|
||||
}
|
||||
bsm.setBlockState(sb);
|
||||
if(chat.getAction().isItem()) {
|
||||
ItemStack item = ChatManager.getUsableItem(itemPlayer, chat.getSlot());
|
||||
if (!ItemUtils.isEmpty(item)) {
|
||||
ItemStack copy = item.clone();
|
||||
|
||||
if (ItemPlayer.getPlayer(p).isBuggedClient()) { // if the guy that will receive it is bugged
|
||||
String act = getStorage().buggedClientAction;
|
||||
List<String> tooltip;
|
||||
if (act.equalsIgnoreCase("tooltip"))
|
||||
tooltip = getStorage().tooltipBuggedClient;
|
||||
else if (act.equalsIgnoreCase("item"))
|
||||
tooltip = ChatManager.getMaxLinesFromItem(p, copy);
|
||||
else if (act.equalsIgnoreCase("show_both")) {
|
||||
tooltip = ChatManager.getMaxLinesFromItem(p, copy);
|
||||
tooltip.addAll(getStorage().tooltipBuggedClient);
|
||||
} else
|
||||
tooltip = new ArrayList<>();
|
||||
message = JSONManipulator.getInstance().parseEmpty(chat, getter.getBaseComponentAsJSON(e), tooltip, chat.getPlayer());
|
||||
if (message != null) {
|
||||
getter.writeJson(e, message);
|
||||
}
|
||||
copy.setItemMeta(bsm);
|
||||
lastSentPacket = e.getPacket();
|
||||
}
|
||||
if (copy.hasItemMeta()) {
|
||||
ItemMeta meta = copy.getItemMeta();
|
||||
if (meta instanceof BookMeta) { // filtering written books
|
||||
BookMeta bm = (BookMeta) copy.getItemMeta();
|
||||
bm.setPages(Collections.emptyList());
|
||||
copy.setItemMeta(bm);
|
||||
} else if (meta instanceof BlockStateMeta && Version.getVersion().isNewerOrEquals(Version.V1_9)) { // if it's a block
|
||||
BlockStateMeta bsm = (BlockStateMeta) copy.getItemMeta();
|
||||
if (bsm.hasBlockState() && bsm.getBlockState() instanceof ShulkerBox) {
|
||||
ShulkerBox sb = (ShulkerBox) bsm.getBlockState();
|
||||
for (ItemStack itemInv : sb.getInventory()) {
|
||||
ItemUtils.stripData(itemInv);
|
||||
}
|
||||
bsm.setBlockState(sb);
|
||||
}
|
||||
copy.setItemMeta(bsm);
|
||||
}
|
||||
}
|
||||
lastSentPacket = getter.manageContent(p, chat, e, fjson, getStorage());
|
||||
} else {
|
||||
if (!getStorage().handDisabled) {
|
||||
lastSentPacket = getter.manageEmpty(p, chat, e, fjson, getStorage());
|
||||
}
|
||||
}
|
||||
lastSentPacket = getter.manageItem(p, chat, e, item, fjson, getStorage());
|
||||
} else {
|
||||
if (!getStorage().handDisabled) {
|
||||
lastSentPacket = getter.manageEmpty(p, chat, e, fjson, getStorage());
|
||||
}
|
||||
}
|
||||
} else
|
||||
lastSentPacket = getter.manageContent(p, chat, e, fjson, getStorage());
|
||||
if (lastSentPacket == null) // maybe sent by the manager directly
|
||||
ChatItem.debug("(v1) No packet to sent with manager " + getter.getClass().getName());
|
||||
else
|
||||
|
||||
@@ -22,4 +22,13 @@ public abstract class PacketManager {
|
||||
public void notifyHandlersSent(ChatItemPacket packet) {
|
||||
handlers.forEach((handler) -> handler.onSend(packet));
|
||||
}
|
||||
|
||||
public ChatItemPacket onPacketSent(PacketType type, Player sender, Object packet) {
|
||||
if(type == null) {
|
||||
return null;
|
||||
}
|
||||
ChatItemPacket customPacket = new ChatItemPacket(type, packet, sender);
|
||||
notifyHandlersSent(customPacket);
|
||||
return customPacket;
|
||||
}
|
||||
}
|
||||
-11
@@ -10,9 +10,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.ChatItemPacket;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketType;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.custom.channel.ChannelAbstract;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.custom.channel.INC2Channel;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.custom.channel.INCChannel;
|
||||
@@ -80,13 +78,4 @@ public class CustomPacketManager extends PacketManager implements Listener {
|
||||
if(channel.getRemoveChannelExecutor() != null)
|
||||
channel.getRemoveChannelExecutor().shutdownNow();
|
||||
}
|
||||
|
||||
public ChatItemPacket onPacketSent(PacketType type, Player sender, Object packet) {
|
||||
if(type == null) {
|
||||
return null;
|
||||
}
|
||||
ChatItemPacket customPacket = new ChatItemPacket(type, packet, sender);
|
||||
notifyHandlersSent(customPacket);
|
||||
return customPacket;
|
||||
}
|
||||
}
|
||||
-8
@@ -51,12 +51,4 @@ public class ProtocollibPacketManager extends PacketManager {
|
||||
public void stop() {
|
||||
protocolManager.removePacketListeners(ChatItem.getInstance());
|
||||
}
|
||||
|
||||
public ChatItemPacket onPacketSent(PacketType type, Player sender, Object packet) {
|
||||
if(type == null)
|
||||
return null;
|
||||
ChatItemPacket customPacket = new ChatItemPacket(type, packet, sender);
|
||||
notifyHandlersSent(customPacket);
|
||||
return customPacket;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
package me.dadus33.chatitem.chatmanager.v2;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -14,10 +9,8 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.ItemPlayer;
|
||||
import me.dadus33.chatitem.ItemSlot;
|
||||
import me.dadus33.chatitem.Storage;
|
||||
import me.dadus33.chatitem.chatmanager.Chat;
|
||||
@@ -25,50 +18,12 @@ import me.dadus33.chatitem.chatmanager.ChatAction;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.hook.DiscordSrvSupport;
|
||||
import me.dadus33.chatitem.playernamer.PlayerNamerManager;
|
||||
import me.dadus33.chatitem.utils.ColorManager;
|
||||
import me.dadus33.chatitem.utils.ItemUtils;
|
||||
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.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ChatListener implements Listener {
|
||||
|
||||
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;
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
|
||||
private ChatListenerChatManager manage;
|
||||
|
||||
public ChatListener(ChatListenerChatManager manage) {
|
||||
@@ -83,6 +38,8 @@ public class ChatListener implements Listener {
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
if(ChatManager.isTestingEnabled() && !ChatManager.isTesting("chat"))
|
||||
return;
|
||||
if(!ChatManager.isSelected("chat"))
|
||||
return;
|
||||
Storage c = getStorage();
|
||||
if (e.isCancelled()) {
|
||||
if (ChatItem.getInstance().getChatManager().size() == 1) { // only chat
|
||||
@@ -111,7 +68,7 @@ public class ChatListener implements Listener {
|
||||
return;
|
||||
}
|
||||
ChatAction action = ChatManager.getChatAction(slot, p);
|
||||
if(action.isItem() && !ChatManager.canShowItem(p, action.getItem(), slot, e))
|
||||
if(!ChatManager.canUsePlaceholder(p, action.getItem(), slot, e))
|
||||
return;
|
||||
e.setCancelled(true);
|
||||
String format = e.getFormat();
|
||||
@@ -128,209 +85,14 @@ public class ChatListener implements Listener {
|
||||
msg = format.replace(e.getMessage(), defMsg);
|
||||
}
|
||||
String itemName = ChatManager.getNameForChatAction(p, action, c);
|
||||
String loggedMessage = msg.replace(ChatManager.SEPARATOR + "", itemName).replace("{name}", p.getName()).replace("{display-name}", p.getDisplayName());
|
||||
String loggedMessage = msg.replace(ChatManager.SEPARATOR + "", itemName);
|
||||
Bukkit.getConsoleSender().sendMessage(loggedMessage); // show in log
|
||||
if (ChatItem.discordSrvSupport)
|
||||
DiscordSrvSupport.sendChatMessage(p, defMsg.replace(ChatManager.SEPARATOR + "", itemName).replace("{name}", p.getName()).replace("{display-name}", p.getDisplayName()), e);
|
||||
DiscordSrvSupport.sendChatMessage(p, defMsg.replace(ChatManager.SEPARATOR + "", itemName), e);
|
||||
Set<Player> recipients = e.getRecipients().isEmpty() ? new HashSet<>(Bukkit.getOnlinePlayers()) : e.getRecipients();
|
||||
ChatItem.debug("Msg: " + msg.replace(ChatColor.COLOR_CHAR, '&') + ", format: " + format + " to " + recipients.size() + " players");
|
||||
recipients.forEach((pl) -> showItem(pl, p, action, msg));
|
||||
ChatItem.debug("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);
|
||||
}
|
||||
|
||||
public static void showItem(Player to, Player origin, ChatAction action, String msg) {
|
||||
ComponentBuilder builder = new ComponentBuilder("");
|
||||
ChatColor color = ChatColor.WHITE;
|
||||
String colorCode = "", text = "";
|
||||
boolean waiting = false, removing = false;
|
||||
for (char args : msg.toCharArray()) {
|
||||
if (args == '§') { // begin of color
|
||||
if (colorCode.isEmpty() && !text.isEmpty()) { // text before this char
|
||||
ChatItem.debug("Append '" + text.replace(ChatColor.COLOR_CHAR, '&') + "' (len: " + text.length() + ")");
|
||||
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));
|
||||
text = "";
|
||||
}
|
||||
waiting = true; // waiting for color code
|
||||
} else if (waiting) { // if waiting for code and valid str
|
||||
// if it's hexademical value and with enough space for full color
|
||||
waiting = false;
|
||||
if (args == 'r' && colorCode.isEmpty()) {
|
||||
color = ChatColor.RESET;
|
||||
continue;
|
||||
} else if(args == 'x') {
|
||||
if(!colorCode.isEmpty()) {
|
||||
color = ColorManager.getColor(colorCode);
|
||||
colorCode = ""; // clean for previous things
|
||||
}
|
||||
}
|
||||
colorCode += args;
|
||||
} else {
|
||||
waiting = false;
|
||||
if (!colorCode.isEmpty()) {
|
||||
if (colorCode.startsWith("x") && colorCode.length() >= 7) {
|
||||
if (colorCode.length() == 7)
|
||||
color = ColorManager.getColor(colorCode);
|
||||
else {
|
||||
color = ColorManager.getColor(colorCode.substring(0, 7)); // only the hex code
|
||||
ChatItem.debug("Adding color for " + colorCode.substring(7, colorCode.length()) + " (in " + colorCode + ")");
|
||||
text += ColorManager.getColorString(colorCode.substring(7, colorCode.length()));
|
||||
}
|
||||
} else if (colorCode.length() == 1) // if only one color code
|
||||
color = ColorManager.getColor(colorCode);
|
||||
else
|
||||
text += ColorManager.getColorString(colorCode);
|
||||
colorCode = "";
|
||||
}
|
||||
if (args == ChatManager.SEPARATOR) {
|
||||
// here put the item
|
||||
appendToComponentBuilder(builder, fixColorComponent(to, text, color, action));
|
||||
if(action.isItem())
|
||||
addItem(builder, to, origin, action.getItem(), action);
|
||||
else
|
||||
addCommand(builder, to, origin, action.getCommand(), action);
|
||||
text = "";
|
||||
if(ChatManager.containsSeparatorEnd(msg))
|
||||
removing = true;
|
||||
} else if(args == ChatManager.SEPARATOR_END) {
|
||||
removing = false;
|
||||
} else if(!removing) { // not removing content
|
||||
// basic text, not waiting for code after '§'
|
||||
text += args;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!text.isEmpty())
|
||||
appendToComponentBuilder(builder, createComponent(to, text, color, action));
|
||||
to.spigot().sendMessage(builder.create());
|
||||
}
|
||||
|
||||
public static void addItem(ComponentBuilder builder, Player to, Player origin, ItemStack item, ChatAction action) {
|
||||
Storage c = ChatItem.getInstance().getStorage();
|
||||
if (!ItemUtils.isEmpty(item)) {
|
||||
ComponentBuilder itemComponent = new ComponentBuilder("");
|
||||
appendToComponentBuilder(itemComponent, fixColorComponent(to, ChatManager.getNameOfItem(to, item, c), ChatColor.WHITE, action));
|
||||
ChatItem.debug("Item for " + to.getName() + " (ver: " + ItemPlayer.getPlayer(to).getVersion().name() + ") : " + PacketUtils.getNbtTag(item));
|
||||
// itemComponent.event(new HoverEvent(Action.SHOW_ITEM, itemBaseComponent));
|
||||
appendToComponentBuilder(builder, itemComponent.create());
|
||||
} else {
|
||||
String handName = c.handName;
|
||||
ComponentBuilder handComp = new ComponentBuilder("");
|
||||
ComponentBuilder handTooltip = new ComponentBuilder("");
|
||||
int stay = c.tooltipHand.size();
|
||||
for (String line : c.tooltipHand) {
|
||||
stay--;
|
||||
handTooltip.append(ColorManager.fixColor(line.replace("{name}", origin.getName()).replace("{display-name}", origin.getDisplayName())));
|
||||
if (stay > 0)
|
||||
handTooltip.append("\n");
|
||||
}
|
||||
handComp.event(Utils.createTextHover(handTooltip.create()));
|
||||
if (handName.contains("{display-name}")) {
|
||||
String[] splitted = handName.split("\\{display-name\\}");
|
||||
for (int i = 0; i < (splitted.length - 1); i++) {
|
||||
handComp.append(splitted[i]);
|
||||
appendToComponentBuilder(handComp, PlayerNamerManager.getPlayerNamer().getName(origin));
|
||||
}
|
||||
handComp.append(splitted[splitted.length - 1]);
|
||||
} else
|
||||
handComp.append(handName.replace("{name}", origin.getName()));
|
||||
appendToComponentBuilder(builder, handComp.create());
|
||||
}
|
||||
}
|
||||
|
||||
public static void addCommand(ComponentBuilder builder, Player to, Player origin, String command, ChatAction action) {
|
||||
ComponentBuilder itemComponent = new ComponentBuilder("");
|
||||
appendToComponentBuilder(itemComponent, fixColorComponent(to, Messages.getMessage(action.getSlot().name().toLowerCase() + ".chat", "%cible%", origin.getName()), ChatColor.WHITE, action));
|
||||
appendToComponentBuilder(builder, itemComponent.create());
|
||||
}
|
||||
|
||||
public static void appendToComponentBuilder(ComponentBuilder builder, BaseComponent[] comps) {
|
||||
if (shouldUseAppendMethod) {
|
||||
try {
|
||||
builder.append(comps);
|
||||
} catch (Exception e) {
|
||||
ChatItem.getInstance().getLogger().severe("This should NEVER append. The ComponentBuilder#append(BaseComponent[]) was found but it's NOT. Using own next time.");
|
||||
shouldUseAppendMethod = false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Field currentField = ReflectionUtils.getField(builder, "current");
|
||||
List<BaseComponent> parts = (List<BaseComponent>) ReflectionUtils.getObject(builder, "parts");
|
||||
parts.add(new TextComponent((TextComponent) currentField.get(builder)));
|
||||
parts.addAll(Arrays.asList(comps));
|
||||
currentField.set(builder, new TextComponent(""));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static BaseComponent[] fixColorComponent(Player to, String message, ChatColor color, ChatAction action) {
|
||||
ComponentBuilder builder = new ComponentBuilder("");
|
||||
String colorCode = "", text = "";
|
||||
boolean waiting = false;
|
||||
for (char args : message.toCharArray()) {
|
||||
if (args == '§') { // begin of color
|
||||
if (colorCode.isEmpty() && !text.isEmpty()) { // text before this char
|
||||
ChatItem.debug("Append while fixing name " + (ColorManager.isHexColor(color) && builder.getParts().isEmpty() ? ColorManager.removeColorAtBegin(text) : text));
|
||||
appendToComponentBuilder(builder, createComponent(to, ColorManager.isHexColor(color) ? ColorManager.removeColorAtBegin(text) : text, color, action));
|
||||
text = "";
|
||||
}
|
||||
waiting = true; // waiting for color code
|
||||
} else if (waiting) { // if waiting for code and valid str
|
||||
// if it's hexademical value and with enough space for full color
|
||||
waiting = false;
|
||||
if (args == 'r' && colorCode.isEmpty()) {
|
||||
color = ChatColor.RESET;
|
||||
continue;
|
||||
}
|
||||
if (args == 'x' && !colorCode.isEmpty()) {
|
||||
text += ColorManager.getColorString(colorCode);
|
||||
colorCode = "x";
|
||||
} else
|
||||
colorCode += args; // a color by itself
|
||||
} else {
|
||||
waiting = false;
|
||||
if (!colorCode.isEmpty()) {
|
||||
if (colorCode.startsWith("x") && colorCode.length() >= 7) {
|
||||
if (colorCode.length() == 7)
|
||||
color = ColorManager.getColor(colorCode);
|
||||
else {
|
||||
color = ColorManager.getColor(colorCode.substring(0, 7)); // only the hex code
|
||||
ChatItem.debug("Adding color for " + colorCode.substring(7, colorCode.length()) + " (in " + colorCode + ")");
|
||||
text += ColorManager.getColorString(colorCode.substring(7, colorCode.length()));
|
||||
}
|
||||
} else if (colorCode.length() == 1) // if only one color code
|
||||
color = ColorManager.getColor(colorCode);
|
||||
else
|
||||
text += ColorManager.getColorString(colorCode);
|
||||
ChatItem.debug("Color: " + color + ", text: " + text + ", code: " + colorCode);
|
||||
colorCode = "";
|
||||
}
|
||||
// basic text, not waiting for code after '§'
|
||||
text += args;
|
||||
}
|
||||
}
|
||||
if (!text.isEmpty()) {
|
||||
appendToComponentBuilder(builder, createComponent(to, text, color, action));
|
||||
}
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
private static BaseComponent[] createComponent(Player to, String text, ChatColor color, ChatAction action) {
|
||||
ComponentBuilder littleBuilder = new ComponentBuilder(text);
|
||||
if(color != null && color != ChatColor.RESET) // don't add reset thing
|
||||
littleBuilder.color(color);
|
||||
if (action.isItem())
|
||||
littleBuilder.event(Utils.createItemHover(action.getItem(), to));
|
||||
else {
|
||||
littleBuilder.event(Utils.createTextHover(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover")));
|
||||
littleBuilder.event(Utils.createRunCommand(action.getCommand()));
|
||||
}
|
||||
return littleBuilder.create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package me.dadus33.chatitem.chatmanager.v3;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.Storage;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
|
||||
public class PaperChatManager extends ChatManager {
|
||||
|
||||
private PaperListener paperListener;
|
||||
|
||||
public PaperChatManager(ChatItem pl) {
|
||||
paperListener = new PaperListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Paper";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "paper";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(ChatItem pl, Storage s) {
|
||||
super.load(pl, s);
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(paperListener, pl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(ChatItem pl) {
|
||||
HandlerList.unregisterAll(paperListener);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package me.dadus33.chatitem.chatmanager.v3;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
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.ChatItem;
|
||||
import me.dadus33.chatitem.ItemSlot;
|
||||
import me.dadus33.chatitem.Storage;
|
||||
import me.dadus33.chatitem.chatmanager.Chat;
|
||||
import me.dadus33.chatitem.chatmanager.ChatAction;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.utils.Messages;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
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;
|
||||
|
||||
public class PaperListener implements Listener {
|
||||
|
||||
private PaperChatManager manage;
|
||||
|
||||
public PaperListener(PaperChatManager manage) {
|
||||
this.manage = manage;
|
||||
}
|
||||
|
||||
public Storage getStorage() {
|
||||
return manage.getStorage();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onChat(AsyncChatEvent e) {
|
||||
if(ChatManager.isTestingEnabled() && !ChatManager.isTesting("paper"))
|
||||
return;
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
ItemSlot slot = ItemSlot.getItemSlotFromMessage(rawMessage);
|
||||
ChatItem.debug("(v3) Raw message: " + rawMessage + ", slot: " + slot);
|
||||
if (slot == null) // if not found
|
||||
return;
|
||||
ChatAction action = ChatManager.getChatAction(slot, p);
|
||||
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));
|
||||
if (getStorage().cooldown > 0 && !p.hasPermission("chatitem.ignore-cooldown"))
|
||||
ChatManager.applyCooldown(p);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -20,17 +19,25 @@ import me.dadus33.chatitem.ItemSlot;
|
||||
import me.dadus33.chatitem.Storage;
|
||||
import me.dadus33.chatitem.chatmanager.ChatAction;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.chatmanager.v2.ChatListener;
|
||||
import me.dadus33.chatitem.invsee.InvShower;
|
||||
import me.dadus33.chatitem.listeners.InventoryListener;
|
||||
import me.dadus33.chatitem.utils.Colors;
|
||||
import me.dadus33.chatitem.utils.Messages;
|
||||
import me.dadus33.chatitem.utils.Utils;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ChatItemCommand implements CommandExecutor, TabExecutor {
|
||||
|
||||
private static final List<String> orders = Arrays.asList("packet", "chat", "both");
|
||||
private static final List<String> ORDERS;
|
||||
|
||||
static {
|
||||
if(Utils.IS_PAPER)
|
||||
ORDERS = Arrays.asList("packet", "chat", "paper", "all");
|
||||
else
|
||||
ORDERS = Arrays.asList("packet", "chat", "all");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
@@ -53,7 +60,7 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
|
||||
}
|
||||
Storage c = ChatItem.getInstance().getStorage();
|
||||
ItemStack item = ChatManager.getUsableItem(cible, ItemSlot.HAND);
|
||||
ChatListener.showItem(p, cible, new ChatAction(ItemSlot.HAND, item), c.commandFormat.replace("%name%", cible.getName()).replace("%item%", ChatManager.SEPARATOR + ""));
|
||||
ChatItem.getPlatform().sendMessage(p, cible, new ChatAction(ItemSlot.HAND, cible, item), c.commandFormat.replace("%name%", cible.getName()).replace("%item%", ChatManager.SEPARATOR + ""));
|
||||
} else if (args[0].equalsIgnoreCase("broadcast") && ChatItem.getInstance().getStorage().cmdBroadcast) {
|
||||
Player cible = args.length == 1 ? p : Bukkit.getPlayer(args[1]);
|
||||
if(cible == null) {
|
||||
@@ -63,7 +70,7 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
|
||||
Storage c = ChatItem.getInstance().getStorage();
|
||||
ItemStack item = ChatManager.getUsableItem(cible, ItemSlot.HAND);
|
||||
for(Player all : Bukkit.getOnlinePlayers())
|
||||
ChatListener.showItem(all, cible, new ChatAction(ItemSlot.HAND, item), c.commandFormat.replace("%name%", cible.getName()).replace("%item%", ChatManager.SEPARATOR + ""));
|
||||
ChatItem.getPlatform().sendMessage(all, cible, new ChatAction(ItemSlot.HAND, cible, item), c.commandFormat.replace("%name%", cible.getName()).replace("%item%", ChatManager.SEPARATOR + ""));
|
||||
} else if (args[0].equalsIgnoreCase("link") || args[0].equalsIgnoreCase("links")) {
|
||||
ConfigurationSection config = ChatItem.getInstance().getConfig()
|
||||
.getConfigurationSection("messages.chatitem-cmd.links");
|
||||
@@ -82,35 +89,35 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
|
||||
p.spigot().sendMessage(text);
|
||||
} else if (args[0].equalsIgnoreCase("select") && p.hasPermission("chatitem.reload")) {
|
||||
if(args.length == 1) {
|
||||
p.sendMessage(ChatColor.GRAY + "----------" + ChatColor.GOLD + " ChatItem - Setup " + ChatColor.GRAY + "----------");
|
||||
p.sendMessage(ChatColor.AQUA + "Welcome in the help of setup." + ChatColor.YELLOW + " Please follow step by simply answer to test.");
|
||||
sendCheckSelectMessage(p, orders.get(0));
|
||||
p.sendMessage(Colors.GRAY + "----------" + Colors.GOLD + " ChatItem - Setup " + Colors.GRAY + "----------");
|
||||
p.sendMessage(Colors.AQUA + "Welcome in the help of setup." + Colors.YELLOW + " Please follow step by simply answer to test.");
|
||||
sendCheckSelectMessage(p, ORDERS.get(0));
|
||||
} else {
|
||||
String tested = args[1];
|
||||
if(!orders.contains(tested)) {
|
||||
p.sendMessage(ChatColor.RED + "Unknow test for " + tested + ".");
|
||||
if(!ORDERS.contains(tested)) {
|
||||
p.sendMessage(Colors.RED + "Unknow test for " + tested + ".");
|
||||
return false;
|
||||
}
|
||||
if(args.length == 2) {
|
||||
p.sendMessage(ChatColor.RED + "Can't find if it works");
|
||||
p.sendMessage(Colors.RED + "Can't find if it works");
|
||||
return false;
|
||||
}
|
||||
if(args[2].equalsIgnoreCase("yes")) {
|
||||
ChatManager.setTesting(null);
|
||||
InventoryListener.setInConfig("manager", tested);
|
||||
p.sendMessage(ChatColor.GREEN + "Perfect ! Updating config ...");
|
||||
p.sendMessage(Colors.GREEN + "Perfect ! Updating config ...");
|
||||
ChatItem.reload(p);
|
||||
} else if(args[2].equalsIgnoreCase("no")) {
|
||||
int index = orders.indexOf(tested);
|
||||
if(orders.size() == (index + 1)) {
|
||||
p.sendMessage(ChatColor.RED + "Sad. Sorry but nothing is available. I suggest you to come on discord for more help. Do '/chatitem link' for all links.");
|
||||
int index = ORDERS.indexOf(tested);
|
||||
if(ORDERS.size() == (index + 1)) {
|
||||
p.sendMessage(Colors.RED + "Sad. Sorry but nothing is available. I suggest you to come on discord for more help. Do '/chatitem link' for all links.");
|
||||
ChatManager.setTesting(null);
|
||||
} else {
|
||||
p.sendMessage(ChatColor.RED + "Sad. Checking for next manager ...");
|
||||
sendCheckSelectMessage(p, orders.get(index + 1));
|
||||
p.sendMessage(Colors.RED + "Sad. Checking for next manager ...");
|
||||
sendCheckSelectMessage(p, ORDERS.get(index + 1));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(ChatColor.RED + "Can't find if it works");
|
||||
p.sendMessage(Colors.RED + "Can't find if it works");
|
||||
}
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("seeinv")) {
|
||||
@@ -133,15 +140,15 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
|
||||
p.chat("Checking for " + testing + ": [i]");
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(ChatItem.getInstance(), () -> {
|
||||
TextComponent text = new TextComponent(ChatColor.GOLD + "Did it worked fine? ");
|
||||
TextComponent agree = new TextComponent(ChatColor.GREEN + "Yes");
|
||||
TextComponent text = new TextComponent(Colors.GOLD + "Did it worked fine? ");
|
||||
TextComponent agree = new TextComponent(Colors.GREEN + "Yes");
|
||||
agree.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/chatitem select " + testing + " yes"));
|
||||
agree.setHoverEvent(Utils.createTextHover(ChatColor.GRAY + "Click to say it worked fine"));
|
||||
agree.setHoverEvent(Utils.createTextHover(Colors.GRAY + "Click to say it worked fine"));
|
||||
text.addExtra(agree);
|
||||
text.addExtra(" ");
|
||||
TextComponent decline = new TextComponent(ChatColor.RED + "No");
|
||||
TextComponent decline = new TextComponent(Colors.RED + "No");
|
||||
decline.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/chatitem select " + testing + " no"));
|
||||
decline.setHoverEvent(Utils.createTextHover(ChatColor.GRAY + "Click to say it's not working as expected"));
|
||||
decline.setHoverEvent(Utils.createTextHover(Colors.GRAY + "Click to say it's not working as expected"));
|
||||
text.addExtra(decline);
|
||||
p.spigot().sendMessage(text);
|
||||
}, 2);
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.bukkit.event.Event;
|
||||
import github.scarsz.discordsrv.DiscordSRV;
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
public class DiscordSrvSupport {
|
||||
|
||||
@@ -15,17 +16,11 @@ public class DiscordSrvSupport {
|
||||
|
||||
public static void sendChatMessage(Player p, String message, Event e) {
|
||||
DiscordSRV pl = DiscordSRV.getPlugin();
|
||||
if (DiscordSRV.config().getBooleanElse("UseModernPaperChatEvent", false) && pl.isModernChatEventAvailable()) {
|
||||
return;
|
||||
}
|
||||
pl.processChatMessage(p, message, pl.getOptionalChannel("global"), false, e);
|
||||
}
|
||||
|
||||
public static void sendChatMessage(Player p, Component message, Event e) {
|
||||
DiscordSRV pl = DiscordSRV.getPlugin();
|
||||
if (DiscordSRV.config().getBooleanElse("UseModernPaperChatEvent", false) && pl.isModernChatEventAvailable()) {
|
||||
return;
|
||||
}
|
||||
pl.processChatMessage(p, message, pl.getOptionalChannel("global"), false, e);
|
||||
pl.processChatMessage(p, github.scarsz.discordsrv.dependencies.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().deserialize(GsonComponentSerializer.gson().serialize(message)), pl.getOptionalChannel("global"), false, e);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class EcoEnchantsSupport {
|
||||
}
|
||||
|
||||
public static boolean load() {
|
||||
String ver = Bukkit.getPluginManager().getPlugin("EcoEnchants").getDescription().getVersion();
|
||||
String ver = ChatItem.getPlatform().getPluginVersion(Bukkit.getPluginManager().getPlugin("EcoEnchants"));
|
||||
if(ver.startsWith("8."))
|
||||
supportedVersion = 8;
|
||||
else if(ver.startsWith("10."))
|
||||
@@ -34,6 +34,7 @@ public class EcoEnchantsSupport {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ItemStack manageItem(ItemStack item) {
|
||||
if(supportedVersion == 8) {
|
||||
List<String> addLore = EcoEnchantsV8Support.getLores(item);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package me.dadus33.chatitem.hook.placeholders;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface IPlaceholders {
|
||||
|
||||
String replace(Player p, String text);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package me.dadus33.chatitem.hook.placeholders;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import be.maximvdw.placeholderapi.PlaceholderAPI;
|
||||
|
||||
public class MVdWPlaceholderAPIHook implements IPlaceholders {
|
||||
|
||||
@Override
|
||||
public String replace(Player p, String text) {
|
||||
return PlaceholderAPI.replacePlaceholders(p, text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package me.dadus33.chatitem.hook.placeholders;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class OwnPlaceholder implements IPlaceholders {
|
||||
|
||||
@Override
|
||||
public String replace(Player p, String text) {
|
||||
return text.replace("{name}", p.getName()).replace("%name%", p.getName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package me.dadus33.chatitem.hook.placeholders;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
|
||||
public class PlaceholderAPIHook implements IPlaceholders {
|
||||
|
||||
@Override
|
||||
public String replace(Player p, String text) {
|
||||
return PlaceholderAPI.setPlaceholders(p, text);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package me.dadus33.chatitem.hook.placeholders;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
|
||||
public class VaultPlaceholderHook implements IPlaceholders {
|
||||
|
||||
private Chat chat = null;
|
||||
|
||||
public Chat getChat() {
|
||||
if (chat == null) {
|
||||
RegisteredServiceProvider<Chat> rs = Bukkit.getServicesManager().getRegistration(Chat.class);
|
||||
if (rs != null) // chat well setup
|
||||
chat = rs.getProvider();
|
||||
}
|
||||
return chat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String replace(Player p, String text) {
|
||||
Chat chat = getChat();
|
||||
if (chat == null)
|
||||
return text;
|
||||
return text.replace("{prefix}", chat.getPlayerPrefix(p)).replace("{suffix}", chat.getPlayerSuffix(p)).replace("%prefix%", chat.getPlayerPrefix(p)).replace("%suffix%", chat.getPlayerSuffix(p));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package me.dadus33.chatitem.invsee.hook;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.invsee.InvShower;
|
||||
import me.dadus33.chatitem.listeners.holder.CustomInventoryHolder;
|
||||
import me.dadus33.chatitem.utils.ItemUtils;
|
||||
@@ -26,7 +26,7 @@ public class EnderChestShower extends InvShower {
|
||||
|
||||
@Override
|
||||
public void open(Player p) {
|
||||
Inventory inv = Bukkit.createInventory(new CustomInventoryHolder(), items.length, Messages.getMessage("enderchest.name", "%cible%", name));
|
||||
Inventory inv = ChatItem.getPlatform().createInventory(new CustomInventoryHolder(), items.length, Messages.getMessage("enderchest.name", "%cible%", name));
|
||||
|
||||
for(int i = 0; i < items.length; i++)
|
||||
inv.setItem(i, items[i]);
|
||||
|
||||
@@ -2,12 +2,12 @@ package me.dadus33.chatitem.invsee.hook;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.invsee.InvShower;
|
||||
import me.dadus33.chatitem.listeners.holder.CustomInventoryHolder;
|
||||
import me.dadus33.chatitem.utils.ItemUtils;
|
||||
@@ -34,10 +34,10 @@ public class PlayerInventoryShower extends InvShower {
|
||||
|
||||
@Override
|
||||
public void open(Player p) {
|
||||
Inventory inv = Bukkit.createInventory(new CustomInventoryHolder(), 54, Messages.getMessage("inventory.name", "%cible%", name));
|
||||
Inventory inv = ChatItem.getPlatform().createInventory(new CustomInventoryHolder(), 54, Messages.getMessage("inventory.name", "%cible%", name));
|
||||
|
||||
for(int i = 0; i < 18; i++)
|
||||
inv.setItem(i, ItemUtils.createItem(ItemUtils.getMaterialWithCompatibility("BROWN_STAINED_GLASS_PANE", "STAINED_GLASS_PANE"), ""));
|
||||
inv.setItem(i, ItemUtils.ITEM_EMPTY_BROWN);
|
||||
|
||||
inv.setItem(2, new ItemStack(ItemUtils.getMaterialWithCompatibility("EXPERIENCE_BOTTLE", "EXP_BOTTLE"), level == 0 ? 1 : (level >= 64 ? 64 : level)));
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ 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 {
|
||||
|
||||
@@ -37,6 +39,8 @@ public class NamerManager {
|
||||
addNamer(new ChatItemTranslationNamer());
|
||||
addNamer(new ItemDisplayNamer());
|
||||
addNamer(new DefaultNamer());
|
||||
if(Utils.IS_PAPER)
|
||||
addNamer(new PaperNamer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,8 +49,7 @@ public class NamerManager {
|
||||
* @param namer the namer to add
|
||||
*/
|
||||
public static void addNamer(INamer namer) {
|
||||
List<INamer> namers = getOrCreate(namer.getPriority());
|
||||
namers.add(namer);
|
||||
getOrCreate(namer.getPriority()).add(namer);
|
||||
}
|
||||
|
||||
private static List<INamer> getOrCreate(Priority p){
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import me.dadus33.chatitem.Storage;
|
||||
import me.dadus33.chatitem.itemnamer.INamer;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ItemDisplayNamer implements INamer {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
package me.dadus33.chatitem.listeners;
|
||||
|
||||
import static me.dadus33.chatitem.utils.ItemUtils.createItem;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -23,6 +20,7 @@ import me.dadus33.chatitem.listeners.holder.ChatItemHolder;
|
||||
import me.dadus33.chatitem.listeners.holder.CustomInventoryHolder;
|
||||
import me.dadus33.chatitem.utils.ItemUtils;
|
||||
import me.dadus33.chatitem.utils.Messages;
|
||||
import me.dadus33.chatitem.utils.Utils;
|
||||
|
||||
public class InventoryListener implements Listener {
|
||||
|
||||
@@ -30,90 +28,101 @@ public class InventoryListener implements Listener {
|
||||
public void onClick(InventoryClickEvent e) {
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
|
||||
if(e.getClickedInventory() == null || !(e.getWhoClicked() instanceof Player))
|
||||
InventoryHolder openInventoryHolder = p.getOpenInventory().getTopInventory().getHolder();
|
||||
|
||||
if (openInventoryHolder instanceof CustomInventoryHolder) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getClickedInventory() == null || !(e.getWhoClicked() instanceof Player))
|
||||
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 (holder == null || !(holder instanceof ChatItemHolder)) {
|
||||
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) {
|
||||
if (top.getHolder() != null && top.getHolder() instanceof ChatItemHolder) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(holder instanceof CustomInventoryHolder) {
|
||||
if (holder instanceof CustomInventoryHolder) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if(!(holder instanceof AdminHolder))
|
||||
if (!(holder instanceof AdminHolder))
|
||||
return;
|
||||
e.setCancelled(true);
|
||||
if(e.getCurrentItem() == null)
|
||||
if (e.getCurrentItem() == null)
|
||||
return;
|
||||
ItemStack item = e.getCurrentItem();
|
||||
Material type = item.getType();
|
||||
Storage c = ChatItem.getInstance().getStorage();
|
||||
if(type.equals(ItemUtils.MATERIAL_CLOSE)) {
|
||||
if (type.equals(ItemUtils.MATERIAL_CLOSE)) {
|
||||
p.closeInventory();
|
||||
} else if(type.equals(Material.BOOK)) {
|
||||
} else if (type.equals(Material.BOOK)) {
|
||||
TranslationInventoryListener.open(p, 0);
|
||||
} else if(type.equals(Material.PAPER)) {
|
||||
} else if (type.equals(Material.PAPER)) {
|
||||
String key = ((AdminHolder) holder).keyBySlot.get(e.getSlot());
|
||||
if(key != null) {
|
||||
if (key != null) {
|
||||
setInConfig("manager", key);
|
||||
p.closeInventory();
|
||||
ChatItem.reload(p);
|
||||
}
|
||||
} else if(type.equals(ItemUtils.INK_SAC)) {
|
||||
} else if (type.equals(ItemUtils.INK_SAC)) {
|
||||
setInConfig("general.color-if-already-colored", c.colorIfColored = !c.colorIfColored);
|
||||
open(p);
|
||||
} else if(type.equals(Material.STICK)) {
|
||||
} else if (type.equals(Material.STICK)) {
|
||||
setInConfig("general.hand.disabled", c.handDisabled = !c.handDisabled);
|
||||
open(p);
|
||||
} else if(type.equals(Material.BLAZE_ROD)) {
|
||||
} else if (type.equals(Material.BLAZE_ROD)) {
|
||||
setInConfig("general.check-update", c.checkUpdate = !c.checkUpdate);
|
||||
open(p);
|
||||
} else if(type.equals(ItemUtils.FIREWORK_CHARGE)) {
|
||||
} else if (type.equals(ItemUtils.FIREWORK_CHARGE)) {
|
||||
setInConfig("debug", c.debug = !c.debug);
|
||||
open(p);
|
||||
} else if(type.equals(Material.IRON_DOOR)) {
|
||||
if(e.getClick().equals(ClickType.RIGHT))
|
||||
} else if (type.equals(Material.IRON_DOOR)) {
|
||||
if (e.getClick().equals(ClickType.RIGHT))
|
||||
c.limit--;
|
||||
else if(e.getClick().equals(ClickType.LEFT))
|
||||
else if (e.getClick().equals(ClickType.LEFT))
|
||||
c.limit++;
|
||||
setInConfig("general.limit-per-message", c.limit);
|
||||
open(p);
|
||||
} else if(type.equals(Material.APPLE)) {
|
||||
if(e.getClick().equals(ClickType.RIGHT))
|
||||
} else if (type.equals(Material.APPLE)) {
|
||||
if (e.getClick().equals(ClickType.RIGHT))
|
||||
c.cooldown--;
|
||||
else if(e.getClick().equals(ClickType.LEFT))
|
||||
else if (e.getClick().equals(ClickType.LEFT))
|
||||
c.cooldown++;
|
||||
setInConfig("general.cooldown", c.cooldown);
|
||||
open(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void setInConfig(String key, Object val) {
|
||||
ChatItem pl = ChatItem.getInstance();
|
||||
pl.getConfig().set(key, val);
|
||||
pl.saveConfig();
|
||||
}
|
||||
|
||||
|
||||
public static void open(Player p) {
|
||||
AdminHolder holder = new AdminHolder();
|
||||
Storage c = ChatItem.getInstance().getStorage();
|
||||
Inventory inv = Bukkit.createInventory(holder, 27, Messages.getMessage("admin-inv.name"));
|
||||
for(int i = 0; i < inv.getSize(); i ++)
|
||||
inv.setItem(i, createItem(ItemUtils.WHITE_STAINED_GLASS, "-"));
|
||||
|
||||
Inventory inv = ChatItem.getPlatform().createInventory(holder, 27, Messages.getMessage("admin-inv.name"));
|
||||
for (int i = 0; i < inv.getSize(); i++)
|
||||
inv.setItem(i, ChatItem.getPlatform().createItemStack(ItemUtils.WHITE_STAINED_GLASS, "-"));
|
||||
|
||||
int slot = 0;
|
||||
for(String manager : Arrays.asList("both", "auto", "packet", "chat")) {
|
||||
for (String manager : Arrays.asList("all", "auto", "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));
|
||||
|
||||
inv.setItem(18, getBoolChangeItem(ItemUtils.INK_SAC, "color-if-already-colored", c.colorIfColored));
|
||||
@@ -121,23 +130,27 @@ 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, createItem(Material.BOOK, Messages.getMessage("admin-inv.language.name"),
|
||||
Messages.getMessage("admin-inv.language.lore", "%name%", Translation.getMessages().get("language.name").getAsString())));
|
||||
|
||||
inv.setItem(26, createItem(ItemUtils.MATERIAL_CLOSE, Messages.getMessage("admin-inv.close")));
|
||||
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")));
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
|
||||
private static ItemStack getBoolChangeItem(Material type, String key, boolean b) {
|
||||
return createItem(type, Messages.getMessage("admin-inv." + key, "%state%", Messages.getMessage(b ? "enabled" : "disabled")), Messages.getMessageList("admin-inv.bool-lore"));
|
||||
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 createItem(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 createItem(Material.PAPER, Messages.getMessage("admin-inv.manager." + manager + ".name", placeholders),
|
||||
Messages.getMessageList("admin-inv.manager." + manager + ".lore", placeholders));
|
||||
return ChatItem.getPlatform().createTranslatedItemStack(Material.PAPER, "admin-inv.manager." + manager,
|
||||
placeholders);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class JoinListener implements Listener {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package me.dadus33.chatitem.listeners;
|
||||
|
||||
import static me.dadus33.chatitem.utils.ItemUtils.createItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -21,6 +17,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.Translation;
|
||||
import me.dadus33.chatitem.listeners.holder.TranslationHolder;
|
||||
import me.dadus33.chatitem.utils.Colors;
|
||||
import me.dadus33.chatitem.utils.ItemUtils;
|
||||
import me.dadus33.chatitem.utils.Messages;
|
||||
|
||||
@@ -55,7 +52,7 @@ public class TranslationInventoryListener implements Listener {
|
||||
pl.getConfig().set("general.language", lang);
|
||||
pl.saveConfig();
|
||||
Translation.loadLang(lang);
|
||||
p.sendMessage(ChatColor.GREEN + "Language changed to " + Translation.getMessages().get("language.name").getAsString());
|
||||
p.sendMessage(Colors.GREEN + "Language changed to " + Translation.getMessages().get("language.name").getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,23 +61,23 @@ public class TranslationInventoryListener implements Listener {
|
||||
int perPage = 45;
|
||||
List<String> langs = new ArrayList<>(Translation.getAllLangs().keySet());
|
||||
TranslationHolder holder = new TranslationHolder(page);
|
||||
Inventory inv = Bukkit.createInventory(holder, 54, "Change language - " + ChatColor.GOLD + " Page " + (page + 1) + " / " + ((langs.size() / perPage) + 1));
|
||||
Inventory inv = ChatItem.getPlatform().createInventory(holder, 54, "Change language - " + Colors.GOLD + " Page " + (page + 1) + " / " + ((langs.size() / perPage) + 1));
|
||||
for(int i = 0; i < 9; i ++)
|
||||
inv.setItem(i, new ItemStack(ItemUtils.GRAY_STAINED_GLASS_PANE));
|
||||
inv.setItem(0, createItem(Material.ARROW, ChatColor.GRAY + "Back"));
|
||||
inv.setItem(0, ChatItem.getPlatform().createItemStack(Material.ARROW, Colors.GRAY + "Back"));
|
||||
|
||||
if(page > 0)
|
||||
inv.setItem(3, createItem(Material.ARROW, ChatColor.RED + "Previous page"));
|
||||
inv.setItem(3, ChatItem.getPlatform().createItemStack(Material.ARROW, Colors.RED + "Previous page"));
|
||||
if(langs.size() > (perPage * (page + 1)))
|
||||
inv.setItem(5, createItem(Material.ARROW, ChatColor.GREEN + "Next page"));
|
||||
inv.setItem(5, ChatItem.getPlatform().createItemStack(Material.ARROW, Colors.GREEN + "Next page"));
|
||||
|
||||
inv.setItem(8, createItem(ItemUtils.MATERIAL_CLOSE, Messages.getMessage("admin-inv.close")));
|
||||
inv.setItem(8, ChatItem.getPlatform().createItemStack(ItemUtils.MATERIAL_CLOSE, Messages.getMessage("admin-inv.close")));
|
||||
|
||||
int slot = 9;
|
||||
for(int i = (page * perPage); i < langs.size() && (i < ((page + 1) * perPage)); i++) {
|
||||
String lang = langs.get(i);
|
||||
holder.langBySlot.put(slot, lang);
|
||||
ItemStack item = createItem(Material.PAPER, ChatColor.GOLD + Translation.getAllLangs().get(lang), ChatColor.GRAY + "Clic to select this language");
|
||||
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);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package me.dadus33.chatitem.platform;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import me.dadus33.chatitem.chatmanager.ChatAction;
|
||||
import me.dadus33.chatitem.utils.Messages;
|
||||
import me.dadus33.chatitem.utils.Version;
|
||||
|
||||
public interface IPlatform {
|
||||
|
||||
String getName();
|
||||
|
||||
Inventory createInventory(InventoryHolder holder, int slot, String name);
|
||||
|
||||
ItemStack createItemStack(Material type, String name);
|
||||
|
||||
default ItemStack createTranslatedItemStack(Material type, String key, Object... placeholders) {
|
||||
return createItemStack(type, Messages.getMessage(key + ".name", placeholders), Messages.getMessageList(key + ".lore", placeholders));
|
||||
}
|
||||
|
||||
default ItemStack createItemStack(Material type, String name, String... lore) {
|
||||
return createItemStack(type, name, Arrays.asList(lore));
|
||||
}
|
||||
|
||||
ItemStack createItemStack(Material type, String name, List<String> lore);
|
||||
|
||||
String getPluginVersion(Plugin plugin);
|
||||
|
||||
Version getMinecraftVersion();
|
||||
|
||||
String getNMSVersion();
|
||||
|
||||
boolean hasBaseComponentSerializer();
|
||||
|
||||
String baseComponentToJson(Object obj);
|
||||
|
||||
Object jsonToBaseComponent(String json);
|
||||
|
||||
void sendMessage(Player to, Player origin, ChatAction action, String msg);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
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;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.chatmanager.ChatAction;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.platform.IPlatform;
|
||||
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.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
|
||||
public class PaperPlatform implements IPlatform {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "PaperMC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder holder, int slot, String name) {
|
||||
return Bukkit.createInventory(holder, slot, Component.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));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
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()));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginVersion(Plugin plugin) {
|
||||
return plugin.getPluginMeta().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getMinecraftVersion() {
|
||||
return Version.getVersionByName("v" + Bukkit.getMinecraftVersion().replace(".", "_"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNMSVersion() {
|
||||
String[] parts = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",");
|
||||
return parts.length <= 3 ? "" : parts[3];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBaseComponentSerializer() {
|
||||
return SpigotPlatform.getBaseComponentToJsonMethod() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String baseComponentToJson(Object obj) {
|
||||
Method m = SpigotPlatform.getBaseComponentToJsonMethod();
|
||||
if (m == null)
|
||||
return null;
|
||||
try {
|
||||
Object[] args = new Object[m.getParameterCount()];
|
||||
args[0] = obj;
|
||||
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());
|
||||
}
|
||||
}
|
||||
return (String) m.invoke(null, args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
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")) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
return m.invoke(null, args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@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()))));
|
||||
|
||||
to.sendMessage(comp.replaceText(TextReplacementConfig.builder().matchLiteral(ChatManager.SEPARATOR + "").replacement(like).build()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
package me.dadus33.chatitem.platform.hook;
|
||||
|
||||
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;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
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.platform.IPlatform;
|
||||
import me.dadus33.chatitem.playernamer.PlayerNamerManager;
|
||||
import me.dadus33.chatitem.utils.ColorManager;
|
||||
import me.dadus33.chatitem.utils.Colors;
|
||||
import me.dadus33.chatitem.utils.ItemUtils;
|
||||
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 me.dadus33.chatitem.utils.Version;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
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;
|
||||
}
|
||||
} 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
|
||||
public String getName() {
|
||||
return "Spigot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder holder, int slot, String name) {
|
||||
return Bukkit.createInventory(holder, slot, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStack(Material type, String name) {
|
||||
ItemStack item = new ItemStack(type);
|
||||
ItemMeta meta = (ItemMeta) item.getItemMeta();
|
||||
meta.setDisplayName(Colors.RESET + name);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStack(Material type, String name, List<String> lore) {
|
||||
ItemStack item = new ItemStack(type);
|
||||
ItemMeta meta = (ItemMeta) item.getItemMeta();
|
||||
meta.setDisplayName(Colors.RESET + name);
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginVersion(Plugin plugin) {
|
||||
return plugin.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
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;
|
||||
return m.invoke(null, args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 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)
|
||||
return null;
|
||||
try {
|
||||
for (Method m : chatSerializerClass.getDeclaredMethods()) {
|
||||
if(m.getParameterTypes()[0].equals(chatBaseComponentClass) && m.getReturnType().equals(String.class)) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
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)
|
||||
return null;
|
||||
try {
|
||||
for (Method m : chatSerializerClass.getDeclaredMethods()) {
|
||||
if(m.getParameterCount() == 0)
|
||||
continue;
|
||||
if(m.getParameterTypes()[0].equals(String.class) && (m.getReturnType().isAssignableFrom(chatBaseComponentClass) || (chatMutableComponentClass != null && m.getReturnType().equals(chatMutableComponentClass)))) {
|
||||
m.setAccessible(true);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(Player to, Player origin, ChatAction action, String msg) {
|
||||
ComponentBuilder builder = new ComponentBuilder("");
|
||||
ChatColor color = ChatColor.WHITE;
|
||||
String colorCode = "", text = "";
|
||||
boolean waiting = false, removing = false;
|
||||
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) {
|
||||
text = text.substring(2); // remove some code which should not be here
|
||||
}
|
||||
appendToComponentBuilder(builder, createComponent(to, text, color, action));
|
||||
text = "";
|
||||
}
|
||||
waiting = true; // waiting for color code
|
||||
} else if (waiting) { // if waiting for code and valid str
|
||||
// if it's hexademical value and with enough space for full color
|
||||
waiting = false;
|
||||
if (args == 'r' && colorCode.isEmpty()) {
|
||||
color = ChatColor.RESET;
|
||||
continue;
|
||||
} else if(args == 'x') {
|
||||
if(!colorCode.isEmpty()) {
|
||||
color = ColorManager.getColor(colorCode);
|
||||
colorCode = ""; // clean for previous things
|
||||
}
|
||||
}
|
||||
colorCode += args;
|
||||
} else {
|
||||
waiting = false;
|
||||
if (!colorCode.isEmpty()) {
|
||||
if (colorCode.startsWith("x") && colorCode.length() >= 7) {
|
||||
if (colorCode.length() == 7)
|
||||
color = ColorManager.getColor(colorCode);
|
||||
else {
|
||||
color = ColorManager.getColor(colorCode.substring(0, 7)); // only the hex code
|
||||
text += ColorManager.getColorString(colorCode.substring(7, colorCode.length()));
|
||||
}
|
||||
} else if (colorCode.length() == 1) // if only one color code
|
||||
color = ColorManager.getColor(colorCode);
|
||||
else
|
||||
text += ColorManager.getColorString(colorCode);
|
||||
colorCode = "";
|
||||
}
|
||||
if (args == ChatManager.SEPARATOR) {
|
||||
// here put the item
|
||||
appendToComponentBuilder(builder, fixColorComponent(to, text, color, action));
|
||||
if(action.isItem())
|
||||
addItem(builder, to, origin, action.getItem(), action);
|
||||
else
|
||||
addCommand(builder, to, origin, action.getCommand(), action);
|
||||
text = "";
|
||||
if(ChatManager.containsSeparatorEnd(msg))
|
||||
removing = true;
|
||||
} else if(args == ChatManager.SEPARATOR_END) {
|
||||
removing = false;
|
||||
} else if(!removing) { // not removing content
|
||||
// basic text, not waiting for code after '§'
|
||||
text += args;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!text.isEmpty())
|
||||
appendToComponentBuilder(builder, createComponent(to, text, color, action));
|
||||
to.spigot().sendMessage(builder.create());
|
||||
}
|
||||
|
||||
public static void addItem(ComponentBuilder builder, Player to, Player origin, ItemStack item, ChatAction action) {
|
||||
Storage c = ChatItem.getInstance().getStorage();
|
||||
if (!ItemUtils.isEmpty(item)) {
|
||||
ComponentBuilder itemComponent = new ComponentBuilder("");
|
||||
appendToComponentBuilder(itemComponent, fixColorComponent(to, ChatManager.getNameOfItem(origin, item, to, c), ChatColor.WHITE, action));
|
||||
ChatItem.debug("Item for " + to.getName() + " (ver: " + ItemPlayer.getPlayer(to).getVersion().name() + ") : " + PacketUtils.getNbtTag(item));
|
||||
// itemComponent.event(new HoverEvent(Action.SHOW_ITEM, itemBaseComponent));
|
||||
appendToComponentBuilder(builder, itemComponent.create());
|
||||
} else {
|
||||
String handName = c.handName;
|
||||
ComponentBuilder handComp = new ComponentBuilder("");
|
||||
ComponentBuilder handTooltip = new ComponentBuilder("");
|
||||
int stay = c.tooltipHand.size();
|
||||
for (String line : c.tooltipHand) {
|
||||
stay--;
|
||||
handTooltip.append(ColorManager.fixColor(line.replace("{name}", origin.getName()).replace("{display-name}", origin.getDisplayName())));
|
||||
if (stay > 0)
|
||||
handTooltip.append("\n");
|
||||
}
|
||||
handComp.event(Utils.createTextHover(handTooltip.create()));
|
||||
if (handName.contains("{display-name}")) {
|
||||
String[] splitted = handName.split("\\{display-name\\}");
|
||||
for (int i = 0; i < (splitted.length - 1); i++) {
|
||||
handComp.append(splitted[i]);
|
||||
appendToComponentBuilder(handComp, PlayerNamerManager.getPlayerNamer().getName(origin));
|
||||
}
|
||||
handComp.append(splitted[splitted.length - 1]);
|
||||
} else
|
||||
handComp.append(handName.replace("{name}", origin.getName()));
|
||||
appendToComponentBuilder(builder, handComp.create());
|
||||
}
|
||||
}
|
||||
|
||||
public static void addCommand(ComponentBuilder builder, Player to, Player origin, String command, ChatAction action) {
|
||||
ComponentBuilder itemComponent = new ComponentBuilder("");
|
||||
appendToComponentBuilder(itemComponent, fixColorComponent(to, Messages.getMessage(action.getSlot().name().toLowerCase() + ".chat", "%cible%", origin.getName()), ChatColor.WHITE, action));
|
||||
appendToComponentBuilder(builder, itemComponent.create());
|
||||
}
|
||||
|
||||
public static void appendToComponentBuilder(ComponentBuilder builder, BaseComponent[] comps) {
|
||||
if (shouldUseAppendMethod) {
|
||||
try {
|
||||
builder.append(comps);
|
||||
} catch (Exception e) {
|
||||
ChatItem.getInstance().getLogger().severe("This should NEVER append. The ComponentBuilder#append(BaseComponent[]) was found but it's NOT. Using own next time.");
|
||||
shouldUseAppendMethod = false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Field currentField = ReflectionUtils.getField(builder, "current");
|
||||
List<BaseComponent> parts = (List<BaseComponent>) ReflectionUtils.getObject(builder, "parts");
|
||||
parts.add(new TextComponent((TextComponent) currentField.get(builder)));
|
||||
parts.addAll(Arrays.asList(comps));
|
||||
currentField.set(builder, new TextComponent(""));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static BaseComponent[] fixColorComponent(Player to, String message, ChatColor color, ChatAction action) {
|
||||
ComponentBuilder builder = new ComponentBuilder("");
|
||||
String colorCode = "", text = "";
|
||||
boolean waiting = false;
|
||||
for (char args : message.toCharArray()) {
|
||||
if (args == '§') { // begin of color
|
||||
if (colorCode.isEmpty() && !text.isEmpty()) { // text before this char
|
||||
ChatItem.debug("Append while fixing name " + (ColorManager.isHexColor(color) && builder.getParts().isEmpty() ? ColorManager.removeColorAtBegin(text) : text));
|
||||
appendToComponentBuilder(builder, createComponent(to, ColorManager.isHexColor(color) ? ColorManager.removeColorAtBegin(text) : text, color, action));
|
||||
text = "";
|
||||
}
|
||||
waiting = true; // waiting for color code
|
||||
} else if (waiting) { // if waiting for code and valid str
|
||||
// if it's hexademical value and with enough space for full color
|
||||
waiting = false;
|
||||
if (args == 'r' && colorCode.isEmpty()) {
|
||||
color = ChatColor.RESET;
|
||||
continue;
|
||||
}
|
||||
if (args == 'x' && !colorCode.isEmpty()) {
|
||||
text += ColorManager.getColorString(colorCode);
|
||||
colorCode = "x";
|
||||
} else
|
||||
colorCode += args; // a color by itself
|
||||
} else {
|
||||
waiting = false;
|
||||
if (!colorCode.isEmpty()) {
|
||||
if (colorCode.startsWith("x") && colorCode.length() >= 7) {
|
||||
if (colorCode.length() == 7)
|
||||
color = ColorManager.getColor(colorCode);
|
||||
else {
|
||||
color = ColorManager.getColor(colorCode.substring(0, 7)); // only the hex code
|
||||
text += ColorManager.getColorString(colorCode.substring(7, colorCode.length()));
|
||||
}
|
||||
} else if (colorCode.length() == 1) // if only one color code
|
||||
color = ColorManager.getColor(colorCode);
|
||||
else
|
||||
text += ColorManager.getColorString(colorCode);
|
||||
colorCode = "";
|
||||
}
|
||||
// basic text, not waiting for code after '§'
|
||||
text += args;
|
||||
}
|
||||
}
|
||||
if (!text.isEmpty()) {
|
||||
appendToComponentBuilder(builder, createComponent(to, text, color, action));
|
||||
}
|
||||
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
|
||||
littleBuilder.color(color);
|
||||
if (action.isItem()) {
|
||||
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() != "")
|
||||
littleBuilder.event(Utils.createRunCommand(action.getCommand()));
|
||||
}
|
||||
return littleBuilder.create();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public class PlayerNamerManager {
|
||||
|
||||
|
||||
if (plugin != null) {
|
||||
char majorVersion = plugin.getDescription().getVersion().charAt(0);
|
||||
char majorVersion = ChatItem.getPlatform().getPluginVersion(plugin).charAt(0);
|
||||
|
||||
if (majorVersion == '3')
|
||||
setPlayerNamer(new HexNicksV3PlayerNamer());
|
||||
|
||||
@@ -8,7 +8,8 @@ import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class ColorManager {
|
||||
|
||||
public static final List<String> COLORS = Arrays.asList("4", "c", "6", "e", "2", "a", "b", "3", "1", "9", "d", "5", "f", "7", "8", "0");
|
||||
public static final char COLOR_CHAR = '§';
|
||||
public static final List<String> COLORS = Arrays.asList("4", "c", "6", "e", "2", "a", "b", "3", "1", "9", "d", "5", "f", "7", "8", "0", "k", "l", "m", "n", "o", "r");
|
||||
|
||||
public static boolean isHexColor(ChatColor c) {
|
||||
return Version.getVersion().isNewerOrEquals(Version.V1_16) && c.getName().startsWith("#");
|
||||
@@ -82,7 +83,7 @@ public class ColorManager {
|
||||
String colorCode = "", text = "";
|
||||
boolean waiting = false;
|
||||
for (char args : message.toCharArray()) {
|
||||
if (args == '§') { // begin of color
|
||||
if (args == COLOR_CHAR) { // begin of color
|
||||
waiting = true; // waiting for color code
|
||||
} else if (waiting) { // if waiting for code and valid str
|
||||
// if it's hexademical value and with enough space for full color
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package me.dadus33.chatitem.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class Colors {
|
||||
|
||||
public static final String YELLOW = ColorManager.COLOR_CHAR + "e";
|
||||
public static final String AQUA = ColorManager.COLOR_CHAR + "b";
|
||||
public static final String GOLD = ColorManager.COLOR_CHAR + "6";
|
||||
public static final String GRAY = ColorManager.COLOR_CHAR + "7";
|
||||
public static final String RED = ColorManager.COLOR_CHAR + "c";
|
||||
public static final String GREEN = ColorManager.COLOR_CHAR + "a";
|
||||
public static final String RESET = ColorManager.COLOR_CHAR + "r";
|
||||
|
||||
|
||||
public static String color(String s) {
|
||||
return s == null || s.isEmpty() ? s : translateAlternateColorCodes('&', s);
|
||||
}
|
||||
|
||||
public static String translateAlternateColorCodes(char altColorChar, @NotNull String textToTranslate) {
|
||||
Preconditions.checkArgument(textToTranslate != null, "Cannot translate null text");
|
||||
|
||||
char[] b = textToTranslate.toCharArray();
|
||||
for (int i = 0; i < b.length - 1; i++) {
|
||||
if (b[i] == altColorChar && ColorManager.COLORS.contains(b[i + 1] + "")) {
|
||||
b[i] = ColorManager.COLOR_CHAR;
|
||||
b[i + 1] = Character.toLowerCase(b[i + 1]);
|
||||
}
|
||||
}
|
||||
return new String(b);
|
||||
}
|
||||
|
||||
public static boolean isFormatting(ChatColor c) {
|
||||
return Arrays.asList(ChatColor.RESET, ChatColor.BOLD, ChatColor.MAGIC, ChatColor.UNDERLINE, ChatColor.ITALIC, ChatColor.STRIKETHROUGH).contains(c);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
package me.dadus33.chatitem.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
|
||||
public class ItemUtils {
|
||||
|
||||
public static final Material MATERIAL_CLOSE = getMaterialWithCompatibility("BARRIER", "REDSTONE_BLOCK");
|
||||
@@ -25,8 +23,11 @@ public class ItemUtils {
|
||||
public static final Material BIRCH_WOOD_STAIRS = getMaterialWithCompatibility("BIRCH_WOOD_STAIRS", "BIRCH_STAIRS");
|
||||
|
||||
// colored items
|
||||
public static final Material GRAY_STAINED_GLASS_PANE = getMaterialWithCompatibility("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE");
|
||||
public static final Material WHITE_STAINED_GLASS = getMaterialWithCompatibility("STAINED_GLASS_PANE", "WHITE_STAINED_GLASS_PANE");
|
||||
public static final Material BROWN_STAINED_GLASS_PANE = getMaterialWithCompatibility("BROWN_STAINED_GLASS_PANE", "STAINED_GLASS_PANE");
|
||||
public static final Material GRAY_STAINED_GLASS_PANE = getMaterialWithCompatibility("GRAY_STAINED_GLASS_PANE", "STAINED_GLASS_PANE");
|
||||
public static final Material WHITE_STAINED_GLASS = getMaterialWithCompatibility("WHITE_STAINED_GLASS_PANE", "STAINED_GLASS_PANE");
|
||||
|
||||
public static final ItemStack ITEM_EMPTY_BROWN = ChatItem.getPlatform().createItemStack(BROWN_STAINED_GLASS_PANE, "");
|
||||
|
||||
public static Material getMaterialWithCompatibility(String... tempMat) {
|
||||
for(String s : tempMat) {
|
||||
@@ -40,42 +41,6 @@ public class ItemUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack createItem(Material m, String name, String... lore) {
|
||||
return createItem(m, name, 1, lore);
|
||||
}
|
||||
|
||||
public static ItemStack createItem(Material m, String name, int quantite, String... lore) {
|
||||
ItemStack item = new ItemStack(m, quantite);
|
||||
ItemMeta meta = (ItemMeta) item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.RESET + name);
|
||||
meta.setLore(Arrays.asList(lore));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack createItem(Material m, String name, List<String> lore) {
|
||||
return createItem(m, name, 1, lore);
|
||||
}
|
||||
|
||||
public static ItemStack createItem(Material m, String name, int quantite, List<String> lore) {
|
||||
ItemStack item = new ItemStack(m, quantite);
|
||||
ItemMeta meta = (ItemMeta) item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.RESET + name);
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ItemStack createItem(Material m, String name, int amount, byte b, String... lore) {
|
||||
ItemStack item = new ItemStack(m, amount, b);
|
||||
ItemMeta meta = (ItemMeta) item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.RESET + name);
|
||||
meta.setLore(Arrays.asList(lore));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack hideAttributes(ItemStack stack) {
|
||||
if (Version.getVersion().isNewerThan(Version.V1_7)) {
|
||||
@@ -95,6 +60,7 @@ public class ItemUtils {
|
||||
return item == null || item.getType().equals(Material.AIR);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void stripData(ItemStack i) {
|
||||
if (i == null) {
|
||||
return;
|
||||
|
||||
@@ -15,12 +15,12 @@ import me.dadus33.chatitem.chatmanager.v1.json.JSONManipulator;
|
||||
|
||||
public class PacketUtils {
|
||||
|
||||
public static final String VERSION = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
public static final String NMS_PREFIX;
|
||||
public static final String OBC_PREFIX;
|
||||
public static final boolean IS_THERMOS;
|
||||
public static final Class<?> CHAT_SERIALIZER, COMPONENT_CLASS;
|
||||
public static final Method ICB_FROM_JSON;
|
||||
public static final boolean IS_THERMOS = Utils.isClassExist("thermos.Thermos");
|
||||
public static final Class<?> COMPONENT_CLASS;
|
||||
|
||||
private static Method getNbtMethod, sendPacketMethod;
|
||||
|
||||
/**
|
||||
* This Map is to reduce Reflection action which take more resources than just
|
||||
@@ -29,12 +29,10 @@ public class PacketUtils {
|
||||
private static final Map<String, Class<?>> ALL_CLASS = Collections.synchronizedMap(new HashMap<String, Class<?>>());
|
||||
|
||||
static {
|
||||
IS_THERMOS = isClassExist("thermos.Thermos");
|
||||
NMS_PREFIX = Version.getVersion().isNewerOrEquals(Version.V1_17) || IS_THERMOS ? "net.minecraft." : "net.minecraft.server." + VERSION + ".";
|
||||
OBC_PREFIX = "org.bukkit.craftbukkit." + VERSION + ".";
|
||||
CHAT_SERIALIZER = getNmsClass("IChatBaseComponent$ChatSerializer", "network.chat.", "ChatSerializer");
|
||||
String version = ChatItem.getPlatform().getNMSVersion();
|
||||
NMS_PREFIX = Version.getVersion().isNewerOrEquals(Version.V1_17) || IS_THERMOS ? "net.minecraft." : "net.minecraft.server." + (version == "" ? "" : version + ".");
|
||||
OBC_PREFIX = "org.bukkit.craftbukkit." + (version == "" ? "" : version + ".");
|
||||
COMPONENT_CLASS = getNmsClass("IChatBaseComponent", "network.chat.");
|
||||
ICB_FROM_JSON = getMethod("a", CHAT_SERIALIZER, String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,21 +48,14 @@ public class PacketUtils {
|
||||
Class<?> clazz = Class.forName(fullPrefix + name);
|
||||
if (clazz != null)
|
||||
return clazz;
|
||||
} catch (ClassNotFoundException e) {
|
||||
if (alias.length == 0)
|
||||
e.printStackTrace(); // no alias, print error
|
||||
// else ignore and go check for alias
|
||||
}
|
||||
} catch (ClassNotFoundException e) {}
|
||||
|
||||
for (String className : alias) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(fullPrefix + className);
|
||||
if (clazz != null)
|
||||
return clazz;
|
||||
} catch (ClassNotFoundException e) {
|
||||
if (className == alias[alias.length - 1]) // if it's last alias, print error
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (ClassNotFoundException e) {}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
@@ -118,15 +109,6 @@ public class PacketUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isClassExist(String name) {
|
||||
try {
|
||||
Class.forName(name);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get NMS player connection of specified player
|
||||
*
|
||||
@@ -167,15 +149,22 @@ public class PacketUtils {
|
||||
public static void sendPacket(Player p, Object packet) {
|
||||
try {
|
||||
Object playerConnection = getPlayerConnection(p);
|
||||
playerConnection.getClass().getMethod(Version.getVersion().isNewerOrEquals(Version.V1_18) ? "a" : "sendPacket", getNmsClass("Packet", "network.protocol."))
|
||||
.invoke(playerConnection, packet);
|
||||
if(sendPacketMethod == null) {
|
||||
Version v = Version.getVersion();
|
||||
if(v.isNewerOrEquals(Version.V1_20)) {
|
||||
Class<?> packetSrvClass = getNmsClass("ServerCommonPacketListenerImpl", "server.network.");
|
||||
if(packetSrvClass != null)
|
||||
sendPacketMethod = packetSrvClass.getDeclaredMethod("b", getNmsClass("Packet", "network.protocol."));
|
||||
}
|
||||
if(sendPacketMethod == null)
|
||||
sendPacketMethod = playerConnection.getClass().getMethod(Version.getVersion().isNewerOrEquals(Version.V1_18) ? "a" : "sendPacket", getNmsClass("Packet", "network.protocol."));
|
||||
}
|
||||
sendPacketMethod.invoke(playerConnection, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static Method getNbtMethod;
|
||||
|
||||
/**
|
||||
* Converts an {@link org.bukkit.inventory.ItemStack} to a Json string for
|
||||
* sending with {@link net.md_5.bungee.api.chat.BaseComponent}'s.
|
||||
@@ -188,7 +177,9 @@ public class PacketUtils {
|
||||
if (getNbtMethod == null) {
|
||||
Class<?> itemClass = getNmsClass("ItemStack", "world.item.");
|
||||
Version v = Version.getVersion();
|
||||
if (v.isNewerOrEquals(Version.V1_20))
|
||||
if(v.isNewerOrEquals(Version.V1_20_6))
|
||||
getNbtMethod = itemClass.getDeclaredMethod("d"); // return DataComponentPatch's object
|
||||
else if (v.equals(Version.V1_20))
|
||||
getNbtMethod = itemClass.getDeclaredMethod("w");
|
||||
else if (v.equals(Version.V1_19))
|
||||
getNbtMethod = itemClass.getDeclaredMethod("u");
|
||||
@@ -206,15 +197,6 @@ public class PacketUtils {
|
||||
}
|
||||
return "{}";
|
||||
}
|
||||
|
||||
private static Method getMethod(String name, Class<?> clazz, Class<?>... params) {
|
||||
try {
|
||||
return clazz.getDeclaredMethod(name, params);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void printPacketToDebug(Object packet) {
|
||||
if(!ChatItem.hasDebug())
|
||||
|
||||
@@ -39,6 +39,7 @@ import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static final boolean IS_PAPER = isClassExist("io.papermc.paper.event.player.AsyncChatEvent");
|
||||
private static final Pattern UUID_PATTERN = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$");
|
||||
private static final TreeMap<Integer, String> ROMAN_KEYS = new TreeMap<>();
|
||||
private static final HashMap<String, String> ENCHANTS_NAMES = new HashMap<>();
|
||||
@@ -120,7 +121,7 @@ public class Utils {
|
||||
connection.setUseCaches(true);
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.setReadTimeout(5000);
|
||||
connection.setRequestProperty("User-Agent", "ChatItem " + pl.getDescription().getVersion());
|
||||
connection.setRequestProperty("User-Agent", "ChatItem");
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestMethod("GET");
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
@@ -259,4 +260,13 @@ public class Utils {
|
||||
sj.add(o == null ? "null" : o.toString());
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
public static boolean isClassExist(String name) {
|
||||
try {
|
||||
Class.forName(name);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@ package me.dadus33.chatitem.utils;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
|
||||
public enum Version {
|
||||
@@ -22,7 +20,9 @@ public enum Version {
|
||||
V1_17(755, 756, 17),
|
||||
V1_18(757, 758, 18),
|
||||
V1_19(759, 762, 19),
|
||||
V1_20(763, 1000, 20),
|
||||
V1_20(763, 765, 20),
|
||||
V1_20_6(766, 766, 20.6),
|
||||
V1_21(767, 1000, 21),
|
||||
HIGHER(Integer.MAX_VALUE, -1, Integer.MAX_VALUE);
|
||||
|
||||
// Latest version should always have the upper limit set to Integer.MAX_VALUE so
|
||||
@@ -30,17 +30,11 @@ public enum Version {
|
||||
|
||||
public final int MIN_VER;
|
||||
public final int MAX_VER;
|
||||
public final int index; // Represents how new the version is (0 - extremely old)
|
||||
public final double index; // Represents how new the version is (0 - extremely old)
|
||||
|
||||
private static final Version SERVER_VERSION;
|
||||
public static final String BUKKIT_VERSION;
|
||||
private static final Version SERVER_VERSION = ChatItem.getPlatform().getMinecraftVersion();
|
||||
|
||||
static {
|
||||
BUKKIT_VERSION = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
SERVER_VERSION = getVersionByName(BUKKIT_VERSION);
|
||||
}
|
||||
|
||||
Version(int min, int max, int index) {
|
||||
Version(int min, int max, double index) {
|
||||
this.MIN_VER = min;
|
||||
this.MAX_VER = max;
|
||||
this.index = index;
|
||||
@@ -55,6 +49,9 @@ public enum Version {
|
||||
}
|
||||
|
||||
public static Version getVersionByName(String name) {
|
||||
try {
|
||||
return Version.valueOf(name.toUpperCase());
|
||||
} catch (Exception e) {}
|
||||
for (Version v : Version.values())
|
||||
if (name.toLowerCase().startsWith(v.name().toLowerCase()))
|
||||
return v;
|
||||
@@ -62,12 +59,7 @@ public enum Version {
|
||||
}
|
||||
|
||||
public static Version getVersion(int protocolVersion) {
|
||||
for (Version ver : Version.values()) {
|
||||
if (protocolVersion >= ver.MIN_VER && protocolVersion <= ver.MAX_VER) {
|
||||
return ver;
|
||||
}
|
||||
}
|
||||
return HIGHER;
|
||||
return getVersion(protocolVersion, HIGHER);
|
||||
}
|
||||
|
||||
public static Version getVersion(int protocolVersion, Version def) {
|
||||
|
||||
@@ -17,7 +17,7 @@ config-version: 13
|
||||
# amount of possible issues.
|
||||
# You can replace 'both' by another mode that should correspond to what you want.
|
||||
# If you don't know which one use, come on discord (link at begin of config or in spigotmc)
|
||||
manager: "both"
|
||||
manager: "all"
|
||||
|
||||
#General configuration
|
||||
general:
|
||||
@@ -62,7 +62,7 @@ general:
|
||||
inventory:
|
||||
enabled: true
|
||||
deny-if-no-item: true
|
||||
# Time in minute before the placeholder expire
|
||||
# Time in seconds before the placeholder expire
|
||||
time-expire: 1800
|
||||
keys:
|
||||
- "[inv]"
|
||||
@@ -70,7 +70,7 @@ general:
|
||||
enderchest:
|
||||
enabled: true
|
||||
deny-if-no-item: true
|
||||
# Time in minute before the placeholder expire
|
||||
# Time in seconds before the placeholder expire
|
||||
time-expire: 1800
|
||||
keys:
|
||||
- "[ec]"
|
||||
@@ -174,9 +174,9 @@ messages:
|
||||
chatitem-cmd:
|
||||
help:
|
||||
- "&6/chatitem admin : &7Manage some options"
|
||||
- "&6/chatitem links : &7See all links which are usefull"
|
||||
- "&6/chatitem links : &7See all links which are useful"
|
||||
links:
|
||||
begin: "&aAll usefull links: "
|
||||
begin: "&aAll useful links: "
|
||||
list:
|
||||
1:
|
||||
message: "\n&7- &eSpigotmc updates"
|
||||
@@ -221,11 +221,12 @@ messages:
|
||||
lore: "&7Actual: &e%name%"
|
||||
# Change name and lore of all managers
|
||||
manager:
|
||||
both:
|
||||
name: "&6Use both manager&7: &aPacket & Chat"
|
||||
all:
|
||||
name: "&6Use all manager&7: &aPacket, Chat & Paper"
|
||||
lore:
|
||||
- "&aTry both manager. Very usefull when you have lot of plugins"
|
||||
- "&aTry all managers to be sure at least one success. Default options."
|
||||
- "&eIt enable to use ChatItem for all type of messages"
|
||||
- "&eShould works with all types of plugins. (Previously named 'both' instead of 'all')"
|
||||
- ""
|
||||
- "&7Since ChatItem v2.1"
|
||||
auto:
|
||||
@@ -247,11 +248,19 @@ messages:
|
||||
chat:
|
||||
name: "&6Change basic message"
|
||||
lore:
|
||||
- "&aVery quick and usefull for server without plugin message !"
|
||||
- "&aVery quick and useful for server without plugin message !"
|
||||
- "&aIt enable to use ChatItem without packet reading."
|
||||
- "&eIt's more optimized than others manager"
|
||||
- ""
|
||||
- "&7Since ChatItem v2.0"
|
||||
paper:
|
||||
name: "&6Use paper messaging"
|
||||
lore:
|
||||
- "&aPaper has his own messaging system."
|
||||
- "&aChatItem can you this system to be easier to manage"
|
||||
- "&eAdapted for paper user, and could be used with more plugin that others"
|
||||
- ""
|
||||
- "&7Since ChatItem v2.6"
|
||||
# The item that show the actual manager
|
||||
actual:
|
||||
name: '&6Actual manager: %manager%'
|
||||
@@ -275,4 +284,8 @@ messages:
|
||||
|
||||
# If ChatItem send message using DiscordSRV
|
||||
# This option will be ignored if you don't have it
|
||||
discord-srv-send-our: true
|
||||
discord-srv-send-our: true
|
||||
|
||||
manager-config:
|
||||
paper:
|
||||
send-ourself: false
|
||||
@@ -2,7 +2,7 @@ name: ChatItem
|
||||
main: me.dadus33.chatitem.ChatItem
|
||||
version: ${project.version}
|
||||
|
||||
softdepend: [ViaVersion, ProtocolSupport, ProtocolLib, LangUtils, HexNicks, EcoEnchants, DiscordSRV, ChatControl, ChatManager]
|
||||
softdepend: [ViaVersion, ProtocolSupport, ProtocolLib, LangUtils, HexNicks, EcoEnchants, DiscordSRV, ChatControl, ChatManager, PlaceholderAPI, MVdWPlaceholderAPI, Vault]
|
||||
authors: [dadus33, WOLFI3654, Elikill58]
|
||||
api-version: 1.13
|
||||
folia-supported: true
|
||||
|
||||
Reference in new issue
Block a user