Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
144be87448 | ||
|
|
217e7316b9 | ||
|
|
9bf2900bb5 | ||
|
|
23640b1772 | ||
|
|
fecf35b3a9 | ||
|
|
8068fe6a7f | ||
|
|
2f21538c76 | ||
|
|
340cad0b2f | ||
|
|
0c51c73f31 | ||
|
|
717db94dc2 | ||
|
|
51e6708fcb | ||
|
|
a6f22d090a | ||
|
|
979f39a171 | ||
|
|
0f057720b8 | ||
|
|
a4eb8bd8fe | ||
|
|
38a8f24c9c | ||
|
|
82de0cf4dc | ||
|
|
13fcea5b57 | ||
|
|
4292871294 | ||
|
|
827c7f92ae | ||
|
|
bcd28eddca | ||
|
|
4d873146dd | ||
|
|
95bcd6ceff | ||
|
|
b596873300 | ||
|
|
0425336f67 | ||
|
|
1a27bcbec2 | ||
|
|
17761fb649 | ||
|
|
9b287c5f83 | ||
|
|
ce44cd7297 | ||
|
|
4ee5a69a28 | ||
|
|
e7f19acc7f | ||
|
|
9d557260ae | ||
|
|
6bbf12182a | ||
|
|
54a582d3eb | ||
|
|
0cbf4edbd1 | ||
|
|
0d4d8a7bf1 | ||
|
|
332bed1bcb | ||
|
|
ecbcbbab12 | ||
|
|
e143dd14bf | ||
|
|
5234812a49 | ||
|
|
ec770ddd15 | ||
|
|
fbe0538a71 | ||
|
|
fb1027f4a8 | ||
|
|
97e6ad4245 | ||
|
|
2ef74e9166 |
No files matched your search
@@ -1,6 +1,3 @@
|
||||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||
|
||||
name: Build v2
|
||||
|
||||
on:
|
||||
@@ -11,16 +8,31 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 11
|
||||
name: Checkout repo
|
||||
|
||||
- name: Set up JDK 17 (LTS)
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '11'
|
||||
java-version: '17'
|
||||
distribution: 'adopt'
|
||||
cache: maven
|
||||
|
||||
- name: Build with Maven
|
||||
run: mvn install --file pom.xml
|
||||
|
||||
- uses: actions/upload-artifact@v2
|
||||
name: Upload Artifact
|
||||
with:
|
||||
name: ChatItem.jar
|
||||
path: target/ChatItem-*.jar
|
||||
- name: Send file README.md to discord channel
|
||||
uses: sinshutu/upload-to-discord@master
|
||||
env:
|
||||
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
|
||||
with:
|
||||
args: target/ChatItem-*.jar
|
||||
@@ -0,0 +1,4 @@
|
||||
jdk:
|
||||
- openjdk11
|
||||
install:
|
||||
- mvn install
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.dadus33</groupId>
|
||||
<artifactId>chatitem</artifactId>
|
||||
<version>2.1</version>
|
||||
<version>2.2.1</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -45,6 +45,15 @@
|
||||
<id>elikill-repo</id>
|
||||
<url>https://repo.eliapp.fr:8081/repository/internal/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dv8tion</id>
|
||||
<name>m2-dv8tion</name>
|
||||
<url>https://m2.dv8tion.net/releases</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Scarsz-Nexus</id>
|
||||
<url>https://nexus.scarsz.me/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
@@ -66,12 +75,19 @@
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.17.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.17.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.9.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.meowj</groupId>
|
||||
@@ -101,7 +117,7 @@
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.1.53.Final</version>
|
||||
<scope>compile</scope>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.GeyserMC</groupId>
|
||||
@@ -118,7 +134,13 @@
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.9.3</version>
|
||||
<version>4.9.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.discordsrv</groupId>
|
||||
<artifactId>discordsrv</artifactId>
|
||||
<version>1.24.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -137,7 +159,6 @@
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@@ -148,14 +169,6 @@
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<configuration>
|
||||
<outputDirectory>${dir}</outputDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
@@ -168,6 +181,12 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.google.gson</pattern>
|
||||
<shadedPattern>me.dadus33.libs.gson</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -176,9 +195,9 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<outputDirectory>${export_dir}</outputDirectory>
|
||||
</configuration>
|
||||
<configuration>
|
||||
<outputDirectory>${export_dir}</outputDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package me.dadus33.chatitem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -9,6 +11,7 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
@@ -23,6 +26,7 @@ import me.dadus33.chatitem.itemnamer.NamerManager;
|
||||
import me.dadus33.chatitem.listeners.InventoryListener;
|
||||
import me.dadus33.chatitem.listeners.JoinListener;
|
||||
import me.dadus33.chatitem.playernamer.PlayerNamerManager;
|
||||
import me.dadus33.chatitem.utils.SemVer;
|
||||
import me.dadus33.chatitem.utils.Storage;
|
||||
import me.dadus33.chatitem.utils.Utils;
|
||||
import me.dadus33.chatitem.utils.Version;
|
||||
@@ -33,19 +37,20 @@ public class ChatItem extends JavaPlugin {
|
||||
private static ChatItem instance;
|
||||
private Log4jFilter filter;
|
||||
private Storage storage;
|
||||
private boolean hasNewVersion = false;
|
||||
public static boolean discordSrvSupport = false, hasNewVersion = false;
|
||||
private List<ChatManager> chatManager = new ArrayList<>();
|
||||
|
||||
private void chooseManagers() {
|
||||
this.chatManager.forEach((cm) -> cm.unload(this));
|
||||
this.chatManager.clear();
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
String managerName = getStorage().MANAGER;
|
||||
if(managerName.equalsIgnoreCase("both")) {
|
||||
this.chatManager.add(new PacketEditingChatManager(this));
|
||||
this.chatManager.add(new ChatListenerChatManager(this));
|
||||
getLogger().info("Manager automatically choosed: " + getVisualChatManagers());
|
||||
} else if(managerName.equalsIgnoreCase("auto")) {
|
||||
if(getServer().getPluginManager().getPlugin("DeluxeChat") != null && Version.getVersion().isNewerThan(Version.V1_7))
|
||||
if(getPluginThatRequirePacket().stream().map(pm::getPlugin).filter(Objects::nonNull).count() > 0 && Version.getVersion().isNewerThan(Version.V1_7))
|
||||
this.chatManager.add(new PacketEditingChatManager(this));
|
||||
else
|
||||
this.chatManager.add(new ChatListenerChatManager(this));
|
||||
@@ -72,6 +77,10 @@ public class ChatItem extends JavaPlugin {
|
||||
PlayerNamerManager.load(this);
|
||||
}
|
||||
|
||||
private List<String> getPluginThatRequirePacket(){
|
||||
return Arrays.asList("DeluxeChat", "HexNicks", "VentureChat");
|
||||
}
|
||||
|
||||
public static void reload(CommandSender sender) {
|
||||
ChatItem pl = getInstance();
|
||||
if(pl.getConfig() == null || pl.getConfig().getKeys(false).isEmpty())
|
||||
@@ -96,38 +105,40 @@ public class ChatItem extends JavaPlugin {
|
||||
//Save the instance (we're basically a singleton)
|
||||
instance = this;
|
||||
|
||||
//Load ProtocolManager
|
||||
//pm = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
//Load config
|
||||
saveDefaultConfig();
|
||||
storage = new Storage(getConfig());
|
||||
|
||||
//We halt the use of this system for now, until we can solve the infamous getProtocolVersion issue
|
||||
//Till then, users of both ViaVersion and ProtocolSupport should do just fine
|
||||
/*if(!protocolSupport && !viaVersion) {
|
||||
//We only implement our own way of getting protocol versions if we have no other choice
|
||||
pm.addPacketListener(new HandshakeListener(this, ListenerPriority.MONITOR, PacketType.Handshake.Client.SET_PROTOCOL));
|
||||
}*/
|
||||
|
||||
//Commands
|
||||
loadCommand(getCommand("cireload"), new CIReloadCommand());
|
||||
loadCommand(getCommand("chatitem"), new ChatItemCommand());
|
||||
|
||||
// events
|
||||
getServer().getPluginManager().registerEvents(new JoinListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new InventoryListener(), this);
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvents(new JoinListener(), this);
|
||||
pm.registerEvents(new InventoryListener(), this);
|
||||
|
||||
chooseManagers();
|
||||
|
||||
//Initialize Log4J filter (remove ugly console messages)
|
||||
filter = new Log4jFilter(storage);
|
||||
|
||||
if(pm.getPlugin("DiscordSRV") != null) {
|
||||
discordSrvSupport = true;
|
||||
getLogger().info("Load DiscordSRV support.");
|
||||
}
|
||||
|
||||
if(storage.CHECK_UPDATE) {
|
||||
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
||||
String urlName = "https://api.spigotmc.org/legacy/update.php?resource=19064";
|
||||
String content = Utils.getFromURL(urlName);
|
||||
if(!Strings.isNullOrEmpty(content)) {
|
||||
if(Strings.isNullOrEmpty(content))
|
||||
return;
|
||||
SemVer currentVersion = SemVer.parse(getDescription().getVersion());
|
||||
if (currentVersion == null)
|
||||
return;
|
||||
SemVer latestVersion = SemVer.parse(content);
|
||||
if (latestVersion != null && latestVersion.isNewerThan(currentVersion)) {
|
||||
hasNewVersion = !content.equalsIgnoreCase(getDescription().getVersion());
|
||||
if(hasNewVersion) {
|
||||
getLogger().info(storage.JOIN_UPDATE_MESSAGE);
|
||||
@@ -165,7 +176,7 @@ public class ChatItem extends JavaPlugin {
|
||||
}
|
||||
|
||||
public static void debug(String msg) {
|
||||
if(getInstance().getConfig().getBoolean("debug", false))
|
||||
getInstance().getLogger().info(msg);
|
||||
if(getInstance().getStorage().DEBUG)
|
||||
getInstance().getLogger().info("[Debug] " + msg);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import me.dadus33.chatitem.utils.Storage;
|
||||
public abstract class ChatManager {
|
||||
|
||||
public final static char SEPARATOR = ((char) 0x0007);
|
||||
public final static String SEPARATOR_STR = "\\u0007";
|
||||
|
||||
protected Storage s;
|
||||
|
||||
|
||||
@@ -7,17 +7,14 @@ import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.json.JSONManipulator;
|
||||
import me.dadus33.chatitem.chatmanager.v1.json.JSONManipulatorCurrent;
|
||||
import me.dadus33.chatitem.chatmanager.v1.listeners.v15lower.ChatEventListener;
|
||||
import me.dadus33.chatitem.chatmanager.v1.listeners.v15lower.ChatPacket15Manager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.listeners.v16upper.ChatPacket16Manager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.listeners.ChatEventListener;
|
||||
import me.dadus33.chatitem.chatmanager.v1.listeners.ChatPacketManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.ChatItemPacketManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketHandler;
|
||||
import me.dadus33.chatitem.chatmanager.v1.playerversion.IPlayerVersion;
|
||||
import me.dadus33.chatitem.chatmanager.v1.playerversion.hooks.DefaultVersionHook;
|
||||
import me.dadus33.chatitem.chatmanager.v1.playerversion.hooks.ProtocolSupportHook;
|
||||
import me.dadus33.chatitem.chatmanager.v1.playerversion.hooks.ViaVersionHook;
|
||||
import me.dadus33.chatitem.utils.Storage;
|
||||
import me.dadus33.chatitem.utils.Version;
|
||||
|
||||
public class PacketEditingChatManager extends ChatManager {
|
||||
|
||||
@@ -25,19 +22,14 @@ public class PacketEditingChatManager extends ChatManager {
|
||||
private boolean baseComponentAvailable = true;
|
||||
private final ChatItemPacketManager packetManager;
|
||||
private final ChatEventListener chatEventListener;
|
||||
private final PacketHandler chatPacketManager;
|
||||
private final ChatPacketManager chatPacketManager;
|
||||
private IPlayerVersion playerVersionAdapter;
|
||||
|
||||
public PacketEditingChatManager(ChatItem pl) {
|
||||
jsonManipulator = new JSONManipulatorCurrent();
|
||||
packetManager = new ChatItemPacketManager(pl);
|
||||
if(Version.getVersion().isNewerOrEquals(Version.V1_16)) {
|
||||
chatPacketManager = new ChatPacket16Manager(this);
|
||||
chatEventListener = null;
|
||||
} else {
|
||||
chatEventListener = new ChatEventListener(this);
|
||||
chatPacketManager = new ChatPacket15Manager(this);
|
||||
}
|
||||
chatEventListener = new ChatEventListener(this);
|
||||
chatPacketManager = new ChatPacketManager(this);
|
||||
|
||||
//Check for existence of BaseComponent class (only on spigot)
|
||||
try {
|
||||
@@ -61,8 +53,7 @@ public class PacketEditingChatManager extends ChatManager {
|
||||
public void load(ChatItem pl, Storage s) {
|
||||
super.load(pl, s);
|
||||
|
||||
if(chatEventListener != null)
|
||||
Bukkit.getPluginManager().registerEvents(chatEventListener, pl);
|
||||
Bukkit.getPluginManager().registerEvents(chatEventListener, pl);
|
||||
packetManager.getPacketManager().addHandler(chatPacketManager);
|
||||
|
||||
if(Bukkit.getPluginManager().getPlugin("ViaVersion") != null){
|
||||
@@ -78,8 +69,7 @@ public class PacketEditingChatManager extends ChatManager {
|
||||
|
||||
@Override
|
||||
public void unload(ChatItem pl) {
|
||||
if(chatEventListener != null)
|
||||
HandlerList.unregisterAll(chatEventListener);
|
||||
HandlerList.unregisterAll(chatEventListener);
|
||||
packetManager.getPacketManager().removeHandler(chatPacketManager);
|
||||
packetManager.getPacketManager().stop();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package me.dadus33.chatitem.chatmanager.v1.json;
|
||||
|
||||
import static me.dadus33.chatitem.utils.PacketUtils.getNmsClass;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.AbstractMap;
|
||||
@@ -44,19 +46,19 @@ import me.dadus33.chatitem.utils.PacketUtils;
|
||||
import me.dadus33.chatitem.utils.Reflect;
|
||||
import me.dadus33.chatitem.utils.Version;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"unchecked", "deprecation"})
|
||||
public class JSONManipulatorCurrent implements JSONManipulator {
|
||||
|
||||
private static final Class<?> CRAFT_ITEM_STACK_CLASS = PacketUtils.getObcClass("inventory.CraftItemStack");
|
||||
private static final Class<?> NBT_STRING = PacketUtils.getNmsClass("NBTTagString", "nbt.");
|
||||
private static final Class<?> NBT_LIST = PacketUtils.getNmsClass("NBTTagList", "nbt.");
|
||||
private static final Class<?> NBT_STRING = getNmsClass("NBTTagString", "nbt.");
|
||||
private static final Class<?> NBT_LIST = getNmsClass("NBTTagList", "nbt.");
|
||||
private static final Map<Class<?>, BiFunction<String, Object, Tag>> TYPES_TO_MC_NBT_TAGS = new HashMap<>();
|
||||
private static final Map<Class<?>, Function<String, Tag>> TYPES_TO_OPEN_NBT_TAGS = new HashMap<>();
|
||||
private static final List<Class<?>> NBT_BASE_CLASSES = new ArrayList<>();
|
||||
private static final List<Field> NBT_BASE_DATA_FIELD = new ArrayList<>();
|
||||
private static final Class<?> NMS_ITEM_STACK_CLASS = PacketUtils.getNmsClass("ItemStack", "world.item.");
|
||||
private static final Class<?> NMS_ITEM_STACK_CLASS = getNmsClass("ItemStack", "world.item.");
|
||||
private static final Method AS_NMS_COPY = Reflect.getMethod(CRAFT_ITEM_STACK_CLASS, "asNMSCopy", ItemStack.class);
|
||||
private static final Class<?> NBT_TAG_COMPOUND = PacketUtils.getNmsClass("NBTTagCompound", "nbt.");
|
||||
private static final Class<?> NBT_TAG_COMPOUND = getNmsClass("NBTTagCompound", "nbt.");
|
||||
private static final Method SAVE_NMS_ITEM_STACK_METHOD = Reflect.getMethod(NMS_ITEM_STACK_CLASS, NBT_TAG_COMPOUND,
|
||||
NBT_TAG_COMPOUND);
|
||||
private static final Field MAP = Reflect.getField(NBT_TAG_COMPOUND, "map", "x");
|
||||
@@ -69,28 +71,28 @@ public class JSONManipulatorCurrent implements JSONManipulator {
|
||||
private static final ConcurrentHashMap<Map.Entry<Version, ItemStack>, JsonObject> STACKS = new ConcurrentHashMap<>();
|
||||
|
||||
static {
|
||||
NBT_BASE_CLASSES.add(PacketUtils.getNmsClass("NBTTagByte", "nbt."));
|
||||
NBT_BASE_CLASSES.add(PacketUtils.getNmsClass("NBTTagByteArray", "nbt."));
|
||||
NBT_BASE_CLASSES.add(PacketUtils.getNmsClass("NBTTagDouble", "nbt."));
|
||||
NBT_BASE_CLASSES.add(PacketUtils.getNmsClass("NBTTagFloat", "nbt."));
|
||||
NBT_BASE_CLASSES.add(PacketUtils.getNmsClass("NBTTagInt", "nbt."));
|
||||
NBT_BASE_CLASSES.add(PacketUtils.getNmsClass("NBTTagIntArray", "nbt."));
|
||||
NBT_BASE_CLASSES.add(PacketUtils.getNmsClass("NBTTagLong", "nbt."));
|
||||
NBT_BASE_CLASSES.add(PacketUtils.getNmsClass("NBTTagShort", "nbt."));
|
||||
NBT_BASE_CLASSES.add(getNmsClass("NBTTagByte", "nbt."));
|
||||
NBT_BASE_CLASSES.add(getNmsClass("NBTTagByteArray", "nbt."));
|
||||
NBT_BASE_CLASSES.add(getNmsClass("NBTTagDouble", "nbt."));
|
||||
NBT_BASE_CLASSES.add(getNmsClass("NBTTagFloat", "nbt."));
|
||||
NBT_BASE_CLASSES.add(getNmsClass("NBTTagInt", "nbt."));
|
||||
NBT_BASE_CLASSES.add(getNmsClass("NBTTagIntArray", "nbt."));
|
||||
NBT_BASE_CLASSES.add(getNmsClass("NBTTagLong", "nbt."));
|
||||
NBT_BASE_CLASSES.add(getNmsClass("NBTTagShort", "nbt."));
|
||||
|
||||
for (Class<?> NBT_BASE_CLASS : NBT_BASE_CLASSES) {
|
||||
NBT_BASE_DATA_FIELD.add(Reflect.getField(NBT_BASE_CLASS, "data", "c", "x"));
|
||||
}
|
||||
|
||||
// include NBT tags
|
||||
TYPES_TO_MC_NBT_TAGS.put(PacketUtils.getNmsClass("NBTTagByte", "nbt."), (name, obj) -> new ByteTag(name, NBTUtils.get(obj, "h")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(PacketUtils.getNmsClass("NBTTagByteArray", "nbt."), (name, obj) -> new ByteArrayTag(name, NBTUtils.get(obj, "d")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(PacketUtils.getNmsClass("NBTTagDouble", "nbt."), (name, obj) -> new DoubleTag(name, NBTUtils.get(obj, "i")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(PacketUtils.getNmsClass("NBTTagFloat", "nbt."), (name, obj) -> new FloatTag(name, NBTUtils.get(obj, "j")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(PacketUtils.getNmsClass("NBTTagInt", "nbt."), (name, obj) -> new IntTag(name, NBTUtils.get(obj, "f")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(PacketUtils.getNmsClass("NBTTagIntArray", "nbt."), (name, obj) -> new IntArrayTag(name, NBTUtils.get(obj, "c")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(PacketUtils.getNmsClass("NBTTagLong", "nbt."), (name, obj) -> new LongTag(name, NBTUtils.get(obj, "e")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(PacketUtils.getNmsClass("NBTTagShort", "nbt."), (name, obj) -> new ShortTag(name, NBTUtils.get(obj, "g")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(getNmsClass("NBTTagByte", "nbt."), (name, obj) -> new ByteTag(name, get(obj, "h")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(getNmsClass("NBTTagByteArray", "nbt."), (name, obj) -> new ByteArrayTag(name, get(obj, "d")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(getNmsClass("NBTTagDouble", "nbt."), (name, obj) -> new DoubleTag(name, get(obj, "i")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(getNmsClass("NBTTagFloat", "nbt."), (name, obj) -> new FloatTag(name, get(obj, "j")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(getNmsClass("NBTTagInt", "nbt."), (name, obj) -> new IntTag(name, get(obj, "f")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(getNmsClass("NBTTagIntArray", "nbt."), (name, obj) -> new IntArrayTag(name, get(obj, "c")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(getNmsClass("NBTTagLong", "nbt."), (name, obj) -> new LongTag(name, get(obj, "e")));
|
||||
TYPES_TO_MC_NBT_TAGS.put(getNmsClass("NBTTagShort", "nbt."), (name, obj) -> new ShortTag(name, get(obj, "g")));
|
||||
// now basic types
|
||||
TYPES_TO_OPEN_NBT_TAGS.put(Byte.class, ByteTag::new);
|
||||
TYPES_TO_OPEN_NBT_TAGS.put(Byte[].class, ByteArrayTag::new);
|
||||
@@ -112,6 +114,15 @@ public class JSONManipulatorCurrent implements JSONManipulator {
|
||||
|
||||
}
|
||||
|
||||
public static <T> T get(Object obj, String methodName){
|
||||
try {
|
||||
return (T) obj.getClass().getDeclaredMethod(methodName).invoke(obj);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<String> replaces;
|
||||
private String rgx;
|
||||
private Version protocolVersion;
|
||||
@@ -701,7 +712,6 @@ public class JSONManipulatorCurrent implements JSONManipulator {
|
||||
return replacer;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private Item toItem(ItemStack is) throws Exception {
|
||||
CompoundTag tag = new CompoundTag("tag");
|
||||
|
||||
@@ -758,10 +768,10 @@ public class JSONManipulatorCurrent implements JSONManipulator {
|
||||
if (NBT_LIST.isInstance(nmsTag)) {
|
||||
List<Object> nmsNBTBaseList = (List<Object>) LIST_FIELD.get(nmsTag);
|
||||
List<Tag> list = new ArrayList<>();
|
||||
int i = 0;
|
||||
//int i = 0;
|
||||
for (Object baseTag : nmsNBTBaseList) {
|
||||
list.add(toOpenTag(baseTag, String.valueOf(i)));
|
||||
++i;
|
||||
list.add(toOpenTag(baseTag, ""));
|
||||
//++i;
|
||||
}
|
||||
return new ListTag(name, list);
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package me.dadus33.chatitem.chatmanager.v1.json;
|
||||
|
||||
public class NBTUtils {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T get(Object obj, String methodName){
|
||||
try {
|
||||
return (T) obj.getClass().getDeclaredMethod(methodName).invoke(obj);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+24
-12
@@ -1,8 +1,9 @@
|
||||
package me.dadus33.chatitem.chatmanager.v1.listeners.v15lower;
|
||||
package me.dadus33.chatitem.chatmanager.v1.listeners;
|
||||
|
||||
import static me.dadus33.chatitem.chatmanager.ChatManager.SEPARATOR;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@@ -79,7 +80,7 @@ public class ChatEventListener implements Listener {
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) // We need to have lowest priority in order
|
||||
// to get to the event before DeluxeChat or
|
||||
// other plugins do
|
||||
public void onChat(final AsyncPlayerChatEvent e) {
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
ChatItem.debug("(v1) Check for v1 system. Cancelled: " + e.isCancelled());
|
||||
if (e.getMessage().indexOf(SEPARATOR) != -1) { // If the BELL character is found, we have to remove it
|
||||
String msg = e.getMessage().replace(Character.toString(SEPARATOR), "");
|
||||
@@ -87,9 +88,9 @@ public class ChatEventListener implements Listener {
|
||||
e.setMessage(msg);
|
||||
}
|
||||
boolean found = false;
|
||||
|
||||
final String oldMsg = e.getMessage();
|
||||
for (String rep : getStorage().PLACEHOLDERS)
|
||||
if (e.getMessage().contains(rep)) {
|
||||
if (oldMsg.contains(rep)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@@ -101,7 +102,7 @@ public class ChatEventListener implements Listener {
|
||||
|
||||
Player p = e.getPlayer();
|
||||
|
||||
if (!p.hasPermission("chatitem.use")) {
|
||||
if (getStorage().PERMISSION_ENABLED && !p.hasPermission(getStorage().PERMISSION_NAME)) {
|
||||
if (!getStorage().LET_MESSAGE_THROUGH) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
@@ -124,6 +125,7 @@ public class ChatEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
ChatItem.debug("(v1) Checking cooldown " + e.getMessage());
|
||||
if (getStorage().COOLDOWN > 0 && !p.hasPermission("chatitem.ignore-cooldown")) {
|
||||
if (COOLDOWNS.containsKey(p.getName())) {
|
||||
long start = COOLDOWNS.get(p.getName());
|
||||
@@ -144,11 +146,11 @@ public class ChatEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
String s = e.getMessage();
|
||||
String s = e.getMessage(), firstPlaceholder = getStorage().PLACEHOLDERS.get(0);
|
||||
for (String placeholder : getStorage().PLACEHOLDERS) {
|
||||
s = s.replace(placeholder, getStorage().PLACEHOLDERS.get(0));
|
||||
s = s.replace(placeholder, firstPlaceholder);
|
||||
}
|
||||
int occurrences = countOccurrences(getStorage().PLACEHOLDERS.get(0), s);
|
||||
int occurrences = countOccurrences(firstPlaceholder, s);
|
||||
|
||||
if (occurrences > getStorage().LIMIT) {
|
||||
e.setCancelled(true);
|
||||
@@ -160,11 +162,21 @@ public class ChatEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
String oldmsg = e.getMessage();
|
||||
StringBuilder sb = new StringBuilder(oldmsg);
|
||||
sb.append(SEPARATOR).append(e.getPlayer().getName());
|
||||
e.setMessage(sb.toString());
|
||||
ChatItem.debug("(v1) Set placeholder: " + e.getMessage());
|
||||
try {
|
||||
StringJoiner msg = new StringJoiner(" ");
|
||||
for(String part : e.getMessage().split(" ")) {
|
||||
if(part.equalsIgnoreCase(firstPlaceholder)) {
|
||||
msg.add(firstPlaceholder + SEPARATOR + p.getName());
|
||||
} else {
|
||||
msg.add(part);
|
||||
}
|
||||
}
|
||||
e.setMessage(msg.toString());
|
||||
e.setFormat(e.getFormat().replace(oldMsg, e.getMessage())); // set own message for plugin that already put the message into the format
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
}
|
||||
if (!p.hasPermission("chatitem.ignore-cooldown")) {
|
||||
COOLDOWNS.put(p.getName(), System.currentTimeMillis() / 1000);
|
||||
}
|
||||
+31
-18
@@ -1,11 +1,11 @@
|
||||
package me.dadus33.chatitem.chatmanager.v1.listeners.v15lower;
|
||||
package me.dadus33.chatitem.chatmanager.v1.listeners;
|
||||
|
||||
import static me.dadus33.chatitem.chatmanager.ChatManager.SEPARATOR;
|
||||
import static me.dadus33.chatitem.chatmanager.ChatManager.SEPARATOR_STR;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -23,13 +23,14 @@ import me.dadus33.chatitem.chatmanager.v1.packets.ChatItemPacket;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketContent;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketHandler;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketType;
|
||||
import me.dadus33.chatitem.utils.ItemUtils;
|
||||
import me.dadus33.chatitem.utils.PacketUtils;
|
||||
import me.dadus33.chatitem.utils.Storage;
|
||||
import me.dadus33.chatitem.utils.Version;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
|
||||
public class ChatPacket15Manager extends PacketHandler {
|
||||
public class ChatPacketManager extends PacketHandler {
|
||||
|
||||
private final static String NAME = "{name}";
|
||||
private final static String AMOUNT = "{amount}";
|
||||
@@ -38,7 +39,7 @@ public class ChatPacket15Manager extends PacketHandler {
|
||||
private Method serializerGetJson;
|
||||
private PacketEditingChatManager manager;
|
||||
|
||||
public ChatPacket15Manager(PacketEditingChatManager manager) {
|
||||
public ChatPacketManager(PacketEditingChatManager manager) {
|
||||
this.manager = manager;
|
||||
try {
|
||||
for (Method m : PacketUtils.CHAT_SERIALIZER.getDeclaredMethods()) {
|
||||
@@ -79,10 +80,9 @@ public class ChatPacket15Manager extends PacketHandler {
|
||||
return; // It means it's an actionbar message, and we ain't intercepting those
|
||||
}
|
||||
}
|
||||
ChatItem.debug("UUID: " + e.getContent().getSpecificModifier(UUID.class).readSafely(0, null));
|
||||
boolean usesBaseComponents = false;
|
||||
PacketContent packet = e.getContent();
|
||||
String json;
|
||||
String json = "{}";
|
||||
if (packet.getChatComponents().readSafely(0) == null) { // null check for some cases of messages sent using
|
||||
// spigot's Chat Component API or other means
|
||||
if (!manager.supportsChatComponentApi()) // only if the API is supported in this server distribution
|
||||
@@ -90,20 +90,28 @@ public class ChatPacket15Manager extends PacketHandler {
|
||||
// we shouldn't mess with anyways
|
||||
BaseComponent[] components = packet.getSpecificModifier(BaseComponent[].class).readSafely(0);
|
||||
if (components == null) {
|
||||
ChatItem.debug("No base components");
|
||||
return;
|
||||
}
|
||||
json = ComponentSerializer.toString(components);
|
||||
Object chatBaseComp = packet.getSpecificModifier(PacketUtils.COMPONENT_CLASS).readSafely(0);
|
||||
if(chatBaseComp == null) {
|
||||
ChatItem.debug("No base components, without chat base comp");
|
||||
return;
|
||||
} else {
|
||||
ChatItem.debug("No base components, with chatbasecomp: " + chatBaseComp);
|
||||
try {
|
||||
json = PacketUtils.CHAT_SERIALIZER.getMethod("a", PacketUtils.COMPONENT_CLASS).invoke(null, e.getPacket()).toString();
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else
|
||||
json = ComponentSerializer.toString(components);
|
||||
usesBaseComponents = true;
|
||||
} else {
|
||||
try {
|
||||
json = (String) serializerGetJson.invoke(null, packet.getChatComponents().readSafely(0));
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
json = "{}";
|
||||
}
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
for (String rep : getStorage().PLACEHOLDERS) {
|
||||
if (json.contains(rep)) {
|
||||
@@ -115,13 +123,17 @@ public class ChatPacket15Manager extends PacketHandler {
|
||||
ChatItem.debug("No placeholders founded");
|
||||
return; // then it's just a normal message without placeholders, so we leave it alone
|
||||
}
|
||||
if (json.lastIndexOf(SEPARATOR) == -1) { // if the message doesn't contain the BELL separator, then it's
|
||||
// certainly NOT a message we want to parse
|
||||
Object toReplace = null;
|
||||
if(json.lastIndexOf(SEPARATOR) != -1)
|
||||
toReplace = SEPARATOR;
|
||||
if(json.lastIndexOf(SEPARATOR_STR) != -1)
|
||||
toReplace = SEPARATOR_STR;
|
||||
if (toReplace == null) { // if the message doesn't contain the BELL separator, then it's certainly NOT a message we want to parse
|
||||
ChatItem.debug("Not contains bell " + json);
|
||||
return;
|
||||
}
|
||||
ChatItem.debug("Add packet meta");
|
||||
String fjson = json;
|
||||
String fjson = json, toReplaceStr = toReplace.toString();
|
||||
boolean bUsesBaseComponents = usesBaseComponents;
|
||||
e.setCancelled(true); // We cancel the packet as we're going to resend it anyways (ignoring listeners
|
||||
// this time)
|
||||
@@ -130,14 +142,14 @@ public class ChatPacket15Manager extends PacketHandler {
|
||||
int topIndex = -1;
|
||||
String name = null;
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
String pname = SEPARATOR + p.getName();
|
||||
String pname = toReplaceStr + p.getName();
|
||||
if (!fjson.contains(pname)) {
|
||||
continue;
|
||||
}
|
||||
int index = fjson.lastIndexOf(pname) + pname.length();
|
||||
if (index > topIndex) {
|
||||
topIndex = index;
|
||||
name = pname.replace(SEPARATOR + "", "");
|
||||
name = pname.replace(toReplaceStr, "");
|
||||
}
|
||||
}
|
||||
if (name == null) { // something went really bad, so we run away and hide (AKA the player left or is
|
||||
@@ -154,7 +166,7 @@ public class ChatPacket15Manager extends PacketHandler {
|
||||
|
||||
String message = null;
|
||||
try {
|
||||
if (!p.getItemInHand().getType().equals(Material.AIR)) {
|
||||
if (!ItemUtils.isEmpty(p.getItemInHand())) {
|
||||
ItemStack copy = p.getItemInHand().clone();
|
||||
if (copy.getType().name().contains("_BOOK")) { // filtering written books
|
||||
BookMeta bm = (BookMeta) copy.getItemMeta();
|
||||
@@ -196,6 +208,7 @@ public class ChatPacket15Manager extends PacketHandler {
|
||||
PacketUtils.sendPacket(e.getPlayer(), e.getPacket());
|
||||
});
|
||||
}
|
||||
|
||||
private Object jsonToChatComponent(String json) {
|
||||
try {
|
||||
return PacketUtils.CHAT_SERIALIZER.getMethod("a", String.class).invoke(null, json);
|
||||
-234
@@ -1,234 +0,0 @@
|
||||
package me.dadus33.chatitem.chatmanager.v1.listeners.v16upper;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.chatmanager.v1.PacketEditingChatManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.ChatItemPacket;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketContent;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketHandler;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketType;
|
||||
import me.dadus33.chatitem.utils.PacketUtils;
|
||||
import me.dadus33.chatitem.utils.Storage;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
|
||||
public class ChatPacket16Manager extends PacketHandler {
|
||||
|
||||
private final static String NAME = "{name}";
|
||||
private final static String AMOUNT = "{amount}";
|
||||
private final static String TIMES = "{times}";
|
||||
|
||||
private Method serializerGetJson;
|
||||
private PacketEditingChatManager manager;
|
||||
|
||||
public ChatPacket16Manager(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();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onSend(ChatItemPacket e) {
|
||||
if (!e.hasPlayer() || !e.getPacketType().equals(PacketType.Server.CHAT)) {
|
||||
return;
|
||||
}
|
||||
UUID sender = e.getContent().getSpecificModifier(UUID.class).readSafely(0, null);
|
||||
if(sender.equals(UUID.fromString("00000000-0000-0000-0000-000000000000"))) // not chat message
|
||||
return;
|
||||
ChatItem.debug("UUID: " + sender);
|
||||
PacketContent packet = e.getContent();
|
||||
String nfJson;
|
||||
Object possibleChatComponent = packet.getChatComponents().readSafely(0);
|
||||
if (possibleChatComponent == null) {
|
||||
BaseComponent[] components = packet.getSpecificModifier(BaseComponent[].class).readSafely(0);
|
||||
if (components == null) {
|
||||
ChatItem.debug("No base components");
|
||||
return;
|
||||
}
|
||||
nfJson = ComponentSerializer.toString(components);
|
||||
} else {
|
||||
try {
|
||||
nfJson = (String) serializerGetJson.invoke(null, possibleChatComponent);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
nfJson = "{}";
|
||||
}
|
||||
}
|
||||
String json = nfJson;
|
||||
boolean found = false;
|
||||
for (String rep : getStorage().PLACEHOLDERS) {
|
||||
if (json.contains(rep)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
ChatItem.debug("No placeholders founded");
|
||||
return; // then it's just a normal message without placeholders, so we leave it alone
|
||||
}
|
||||
Player p = Bukkit.getPlayer(sender);
|
||||
String message = null;
|
||||
try {
|
||||
if (!p.getItemInHand().getType().equals(Material.AIR)) {
|
||||
ItemStack copy = p.getItemInHand().clone();
|
||||
if (copy.getType().name().contains("_BOOK")) { // filtering written books
|
||||
BookMeta bm = (BookMeta) copy.getItemMeta();
|
||||
bm.setPages(Collections.emptyList());
|
||||
copy.setItemMeta(bm);
|
||||
} else {
|
||||
if (copy.getType().name().contains("SHULKER_BOX")) { // if it's shulker
|
||||
if (copy.hasItemMeta()) {
|
||||
BlockStateMeta bsm = (BlockStateMeta) copy.getItemMeta();
|
||||
if (bsm.hasBlockState()) {
|
||||
ShulkerBox sb = (ShulkerBox) bsm.getBlockState();
|
||||
for (ItemStack item : sb.getInventory()) {
|
||||
stripData(item);
|
||||
}
|
||||
bsm.setBlockState(sb);
|
||||
}
|
||||
copy.setItemMeta(bsm);
|
||||
}
|
||||
}
|
||||
}
|
||||
message = manager.getManipulator().parse(json, getStorage().PLACEHOLDERS, copy,
|
||||
styleItem(copy, getStorage()), manager.getPlayerVersionAdapter().getProtocolVersion(p));
|
||||
} else {
|
||||
if (!getStorage().HAND_DISABLED) {
|
||||
message = manager.getManipulator().parseEmpty(json, getStorage().PLACEHOLDERS,
|
||||
getStorage().HAND_NAME, getStorage().HAND_TOOLTIP, p);
|
||||
}
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
if (message != null) {
|
||||
if (json.equalsIgnoreCase("{}")) {
|
||||
packet.getChatComponents().write(0, jsonToChatComponent(message));
|
||||
} else {
|
||||
packet.getSpecificModifier(BaseComponent[].class).write(0, ComponentSerializer.parse(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
private Object jsonToChatComponent(String json) {
|
||||
try {
|
||||
return PacketUtils.CHAT_SERIALIZER.getMethod("a", String.class).invoke(null, json);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String styleItem(ItemStack item, Storage c) {
|
||||
String replacer = c.NAME_FORMAT;
|
||||
String amount = c.AMOUNT_FORMAT;
|
||||
boolean dname = item.hasItemMeta() ? item.getItemMeta().hasDisplayName() : false;
|
||||
|
||||
if (item.getAmount() == 1) {
|
||||
if (c.FORCE_ADD_AMOUNT) {
|
||||
amount = amount.replace(TIMES, "1");
|
||||
replacer = replacer.replace(AMOUNT, amount);
|
||||
} else {
|
||||
replacer = replacer.replace(AMOUNT, "");
|
||||
}
|
||||
} else {
|
||||
amount = amount.replace(TIMES, String.valueOf(item.getAmount()));
|
||||
replacer = replacer.replace(AMOUNT, amount);
|
||||
}
|
||||
if (dname) {
|
||||
String trp = item.getItemMeta().getDisplayName();
|
||||
if (c.COLOR_IF_ALREADY_COLORED) {
|
||||
replacer = replacer.replace(NAME, ChatColor.stripColor(trp));
|
||||
} else {
|
||||
replacer = replacer.replace(NAME, trp);
|
||||
}
|
||||
} else {
|
||||
HashMap<Short, String> translationSection = c.TRANSLATIONS.get(item.getType().name());
|
||||
if (translationSection == null) {
|
||||
String trp = materialToName(item.getType());
|
||||
replacer = replacer.replace(NAME, trp);
|
||||
} else {
|
||||
@SuppressWarnings("deprecation")
|
||||
String translated = translationSection.get(item.getDurability());
|
||||
if (translated != null) {
|
||||
replacer = replacer.replace(NAME, translated);
|
||||
} else {
|
||||
replacer = replacer.replace(NAME, materialToName(item.getType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return replacer;
|
||||
}
|
||||
|
||||
private static String materialToName(Material m) {
|
||||
if (m.equals(Material.TNT)) {
|
||||
return "TNT";
|
||||
}
|
||||
String orig = m.toString().toLowerCase();
|
||||
String[] splits = orig.split("_");
|
||||
StringBuilder sb = new StringBuilder(orig.length());
|
||||
int pos = 0;
|
||||
for (String split : splits) {
|
||||
sb.append(split);
|
||||
int loc = sb.lastIndexOf(split);
|
||||
char charLoc = sb.charAt(loc);
|
||||
if (!(split.equalsIgnoreCase("of") || split.equalsIgnoreCase("and") || split.equalsIgnoreCase("with")
|
||||
|| split.equalsIgnoreCase("on")))
|
||||
sb.setCharAt(loc, Character.toUpperCase(charLoc));
|
||||
if (pos != splits.length - 1)
|
||||
sb.append(' ');
|
||||
++pos;
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void stripData(ItemStack i) {
|
||||
if (i == null) {
|
||||
return;
|
||||
}
|
||||
if (i.getType().equals(Material.AIR)) {
|
||||
return;
|
||||
}
|
||||
if (!i.hasItemMeta()) {
|
||||
return;
|
||||
}
|
||||
ItemMeta im = Bukkit.getItemFactory().getItemMeta(i.getType());
|
||||
ItemMeta original = i.getItemMeta();
|
||||
if (original.hasDisplayName()) {
|
||||
im.setDisplayName(original.getDisplayName());
|
||||
}
|
||||
i.setItemMeta(im);
|
||||
}
|
||||
|
||||
|
||||
public Storage getStorage() {
|
||||
return manager.getStorage();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -34,7 +34,7 @@ public class INC2Channel extends ChannelAbstract {
|
||||
try {
|
||||
Object mcServer = ReflectionUtils.callMethod(PacketUtils.getCraftServer(), Version.getVersion().equals(Version.V1_17) ? "getServer" : "b");
|
||||
Object co = ReflectionUtils.getFirstWith(mcServer, PacketUtils.getNmsClass("MinecraftServer", "server."), PacketUtils.getNmsClass("ServerConnection", "server.network."));
|
||||
((List<ChannelFuture>) ReflectionUtils.getField(co, "f")).forEach((channelFuture) -> {
|
||||
((List<ChannelFuture>) ReflectionUtils.getObject(co, "f")).forEach((channelFuture) -> {
|
||||
pipeline = channelFuture.channel().pipeline();
|
||||
pipeline.addFirst(boundHandler);
|
||||
});
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class NMUChannel extends ChannelAbstract {
|
||||
Object mcServer = dedicatedSrv.getClass().getMethod("getServer").invoke(dedicatedSrv);
|
||||
Object co = ReflectionUtils.getFirstWith(mcServer, PacketUtils.getNmsClass("MinecraftServer", "server."), PacketUtils.getNmsClass("ServerConnection", "network."));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ChannelFuture> g = (List<ChannelFuture>) ReflectionUtils.getField(co, "g");
|
||||
List<ChannelFuture> g = (List<ChannelFuture>) ReflectionUtils.getObject(co, "g");
|
||||
g.forEach((channelFuture) -> {
|
||||
pipeline = channelFuture.channel().pipeline();
|
||||
pipeline.addFirst(boundHandler = new ChannelInboundHandlerAdapter() {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package me.dadus33.chatitem.chatmanager.v2;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -12,222 +14,264 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.hook.DiscordSrvSupport;
|
||||
import me.dadus33.chatitem.itemnamer.NamerManager;
|
||||
import me.dadus33.chatitem.playernamer.PlayerNamerManager;
|
||||
import me.dadus33.chatitem.utils.ColorManager;
|
||||
import me.dadus33.chatitem.utils.ItemUtils;
|
||||
import me.dadus33.chatitem.utils.PacketUtils;
|
||||
import me.dadus33.chatitem.utils.ReflectionUtils;
|
||||
import me.dadus33.chatitem.utils.Storage;
|
||||
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.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent.Action;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ChatListener implements Listener {
|
||||
|
||||
public final static char SEPARATOR = ((char)0x0007);
|
||||
private final static String NAME = "{name}";
|
||||
private final static String AMOUNT = "{amount}";
|
||||
private final static String TIMES = "{times}";
|
||||
private final static String LEFT = "{remaining}";
|
||||
private final HashMap<String, Long> COOLDOWNS = new HashMap<>();
|
||||
private final static String LEFT = "{remaining}";
|
||||
private final HashMap<String, Long> COOLDOWNS = new HashMap<>();
|
||||
private ChatListenerChatManager manage;
|
||||
private Method saveMethod;
|
||||
|
||||
private boolean shouldUseAppendMethod = false;
|
||||
|
||||
public ChatListener(ChatListenerChatManager manage) {
|
||||
this.manage = manage;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {
|
||||
|
||||
|
||||
}
|
||||
if(saveMethod == null)
|
||||
ChatItem.getInstance().getLogger().info("Failed to find save method. Using default system...");
|
||||
String appendMethodMsg = shouldUseAppendMethod ? "Use ComponentBuilder's method."
|
||||
: "Use own ComponentBuilder append method.";
|
||||
if (saveMethod == null)
|
||||
ChatItem.getInstance().getLogger()
|
||||
.info("Failed to find save method. Using default system. " + appendMethodMsg);
|
||||
else
|
||||
ChatItem.getInstance().getLogger().info("Save method founded: " + saveMethod.getName() + ".");
|
||||
ChatItem.getInstance().getLogger()
|
||||
.info("Save method founded: " + saveMethod.getName() + ". " + appendMethodMsg);
|
||||
}
|
||||
|
||||
|
||||
public Storage getStorage() {
|
||||
return manage.getStorage();
|
||||
}
|
||||
|
||||
private String calculateTime(long seconds){
|
||||
if(seconds < 60){
|
||||
return seconds+getStorage().SECONDS;
|
||||
}
|
||||
if(seconds < 3600){
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int minutes = (int) seconds / 60;
|
||||
builder.append(minutes).append(getStorage().MINUTES);
|
||||
int secs = (int) seconds - minutes*60;
|
||||
if(secs != 0){
|
||||
builder.append(" ").append(secs).append(getStorage().SECONDS);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int hours = (int) seconds / 3600;
|
||||
builder.append(hours).append(getStorage().HOURS);
|
||||
int minutes = (int) (seconds/60) - (hours*60);
|
||||
if(minutes != 0){
|
||||
builder.append(" ").append(minutes).append(getStorage().MINUTES);
|
||||
}
|
||||
int secs = (int) (seconds - ((seconds/60)*60));
|
||||
if(secs != 0){
|
||||
builder.append(" ").append(secs).append(getStorage().SECONDS);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private String calculateTime(long seconds) {
|
||||
if (seconds < 60) {
|
||||
return seconds + getStorage().SECONDS;
|
||||
}
|
||||
if (seconds < 3600) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int minutes = (int) seconds / 60;
|
||||
builder.append(minutes).append(getStorage().MINUTES);
|
||||
int secs = (int) seconds - minutes * 60;
|
||||
if (secs != 0) {
|
||||
builder.append(" ").append(secs).append(getStorage().SECONDS);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int hours = (int) seconds / 3600;
|
||||
builder.append(hours).append(getStorage().HOURS);
|
||||
int minutes = (int) (seconds / 60) - (hours * 60);
|
||||
if (minutes != 0) {
|
||||
builder.append(" ").append(minutes).append(getStorage().MINUTES);
|
||||
}
|
||||
int secs = (int) (seconds - ((seconds / 60) * 60));
|
||||
if (secs != 0) {
|
||||
builder.append(" ").append(secs).append(getStorage().SECONDS);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
if(e.isCancelled())
|
||||
return;
|
||||
Player p = e.getPlayer();
|
||||
for (String rep : getStorage().PLACEHOLDERS) {
|
||||
if (e.getMessage().contains(rep + ChatManager.SEPARATOR + p.getName())) { // already managed by v1
|
||||
return;
|
||||
}
|
||||
}
|
||||
boolean found = false;
|
||||
|
||||
for(String key : e.getMessage().split(" ")) {
|
||||
if(found)
|
||||
break;
|
||||
for (String rep : getStorage().PLACEHOLDERS) {
|
||||
if (key.equalsIgnoreCase(rep)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
return;
|
||||
}
|
||||
if (!p.hasPermission("chatitem.use")) {
|
||||
if(!getStorage().LET_MESSAGE_THROUGH) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
if(!getStorage().NO_PERMISSION_MESSAGE.isEmpty() && getStorage().SHOW_NO_PERM_NORMAL){
|
||||
p.sendMessage(getStorage().NO_PERMISSION_MESSAGE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (p.getItemInHand().getType().equals(Material.AIR)) {
|
||||
if (getStorage().DENY_IF_NO_ITEM) {
|
||||
e.setCancelled(true);
|
||||
if (!getStorage().DENY_MESSAGE.isEmpty())
|
||||
e.getPlayer().sendMessage(getStorage().DENY_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if(getStorage().HAND_DISABLED) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(getStorage().COOLDOWN > 0 && !p.hasPermission("chatitem.ignore-cooldown")){
|
||||
if(COOLDOWNS.containsKey(p.getName())){
|
||||
long start = COOLDOWNS.get(p.getName());
|
||||
long current = System.currentTimeMillis()/1000;
|
||||
long elapsed = current - start;
|
||||
if(elapsed >= getStorage().COOLDOWN){
|
||||
COOLDOWNS.remove(p.getName());
|
||||
} else {
|
||||
if(!getStorage().LET_MESSAGE_THROUGH) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
if(!getStorage().COOLDOWN_MESSAGE.isEmpty()){
|
||||
long left = (start + getStorage().COOLDOWN) - current;
|
||||
p.sendMessage(getStorage().COOLDOWN_MESSAGE.replace(LEFT, calculateTime(left)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
e.setCancelled(true);
|
||||
String format = e.getFormat(), defMsg = e.getMessage();
|
||||
Bukkit.getConsoleSender().sendMessage(String.format(e.getFormat(), e.getPlayer().getDisplayName(), defMsg)); // show in log
|
||||
boolean isAlreadyParsed = false;
|
||||
if(format.contains("%1$s") && format.contains("%2$s")) // message not parsed but not default way
|
||||
isAlreadyParsed = false;
|
||||
if(format.equalsIgnoreCase(defMsg)) // is message already parsed
|
||||
isAlreadyParsed = true;
|
||||
if(format.equalsIgnoreCase("<%1$s> %2$s")) // default MC message
|
||||
isAlreadyParsed = false;
|
||||
String msg = isAlreadyParsed ? format : String.format(format, p.getDisplayName(), defMsg);
|
||||
ItemStack item = p.getItemInHand();
|
||||
ItemMeta meta = item == null ? null : item.getItemMeta();
|
||||
e.getRecipients().forEach((pl) -> {
|
||||
TextComponent component = new TextComponent("");
|
||||
ChatColor color = ChatColor.getByChar(getColorChat(e.getFormat()));
|
||||
for (String args : msg.split(" ")) {
|
||||
if (getStorage().PLACEHOLDERS.contains(args)) {
|
||||
if(meta != null) {
|
||||
TextComponent itemComponent = new TextComponent(ChatListener.styleItem(pl, item, getStorage()));
|
||||
String itemJson = convertItemStackToJson(item);
|
||||
itemComponent.setHoverEvent(
|
||||
new HoverEvent(Action.SHOW_ITEM, new BaseComponent[] { new TextComponent(itemJson) }));
|
||||
component.addExtra(itemComponent);
|
||||
} else {
|
||||
if(getStorage().HAND_DISABLED)
|
||||
component.addExtra(color + args);
|
||||
else {
|
||||
String handName = getStorage().HAND_NAME;
|
||||
TextComponent handComp = new TextComponent("");
|
||||
ComponentBuilder handTooltip = new ComponentBuilder();
|
||||
int stay = getStorage().HAND_TOOLTIP.size();
|
||||
for(String line : getStorage().HAND_TOOLTIP) {
|
||||
stay--;
|
||||
handTooltip.append(line.replace("{name}", p.getName()).replace("{display-name}", p.getDisplayName()));
|
||||
if(stay > 0)
|
||||
handTooltip.append("\n");
|
||||
}
|
||||
handComp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,handTooltip.create()));
|
||||
if(handName.contains("{name}")) {
|
||||
String[] splitted = handName.split("{name}");
|
||||
for(int i = 0; i < (splitted.length - 1); i++) {
|
||||
handComp.addExtra(new TextComponent(splitted[i]));
|
||||
handComp.addExtra(PlayerNamerManager.getPlayerNamer().getName(p));
|
||||
}
|
||||
handComp.addExtra(new TextComponent(splitted[splitted.length - 1]));
|
||||
} else
|
||||
handComp.addExtra(handName.replace("{display-name}", p.getDisplayName()));
|
||||
component.addExtra(handComp);
|
||||
}
|
||||
Storage c = getStorage();
|
||||
if (e.isCancelled()) {
|
||||
if (ChatItem.getInstance().getChatManager().size() == 1) { // only chat
|
||||
String msg = e.getMessage().toLowerCase();
|
||||
for (String rep : c.PLACEHOLDERS) {
|
||||
if (msg.contains(rep)) {
|
||||
ChatItem.debug(
|
||||
"You choose 'chat' manager but it seems to don't be the good choice. More informations here: https://github.com/dadus33-plugins/ChatItem/wiki");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
component.addExtra(color + args);
|
||||
}
|
||||
component.addExtra(" ");
|
||||
char maybeNextCode = getColorChat(args);
|
||||
if(maybeNextCode != 'r') {
|
||||
color = ChatColor.getByChar(maybeNextCode);
|
||||
}
|
||||
}
|
||||
pl.spigot().sendMessage(component);
|
||||
});
|
||||
//Utils.getOnlinePlayers().forEach((pl) -> pl.spigot().sendMessage(component));
|
||||
ChatItem.debug("Chat cancelled for " + e.getPlayer().getName());
|
||||
return;
|
||||
}
|
||||
Player p = e.getPlayer();
|
||||
boolean found = false, hasv1 = false;
|
||||
|
||||
for (String rep : c.PLACEHOLDERS) {
|
||||
// v1 try to manage it, but the message have not been changed by another plugin
|
||||
if (e.getMessage().contains(rep + ChatManager.SEPARATOR + p.getName())) {
|
||||
hasv1 = true;
|
||||
found = true;
|
||||
ChatItem.debug("Found v1 placeholders in v2");
|
||||
break;
|
||||
}
|
||||
if (e.getMessage().contains(rep)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
ChatItem.debug("(v2) Can't found placeholder in: " + e.getMessage() + " > " + PlayerNamerManager.getPlayerNamer().getName(p));
|
||||
return;
|
||||
}
|
||||
if (c.PERMISSION_ENABLED && !p.hasPermission(c.PERMISSION_NAME)) {
|
||||
if (!getStorage().LET_MESSAGE_THROUGH) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
if (!c.NO_PERMISSION_MESSAGE.isEmpty() && c.SHOW_NO_PERM_NORMAL) {
|
||||
p.sendMessage(c.NO_PERMISSION_MESSAGE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (p.getItemInHand().getType().equals(Material.AIR)) {
|
||||
if (c.DENY_IF_NO_ITEM) {
|
||||
e.setCancelled(true);
|
||||
if (!c.DENY_MESSAGE.isEmpty())
|
||||
e.getPlayer().sendMessage(c.DENY_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if (c.HAND_DISABLED) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (c.COOLDOWN > 0 && !p.hasPermission("chatitem.ignore-cooldown")) { // use cooldown
|
||||
if (COOLDOWNS.containsKey(p.getName())) {
|
||||
long start = COOLDOWNS.get(p.getName());
|
||||
long current = System.currentTimeMillis() / 1000;
|
||||
long elapsed = current - start;
|
||||
if (elapsed >= getStorage().COOLDOWN) {
|
||||
COOLDOWNS.remove(p.getName());
|
||||
} else {
|
||||
if (!c.LET_MESSAGE_THROUGH) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
if (!c.COOLDOWN_MESSAGE.isEmpty()) {
|
||||
long left = (start + c.COOLDOWN) - current;
|
||||
p.sendMessage(c.COOLDOWN_MESSAGE.replace(LEFT, calculateTime(left)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
COOLDOWNS.put(p.getName(), System.currentTimeMillis() / 1000);
|
||||
}
|
||||
e.setCancelled(true);
|
||||
String format = e.getFormat();
|
||||
String msg, defMsg = e.getMessage();
|
||||
for (String rep : c.PLACEHOLDERS) {
|
||||
if (hasv1)
|
||||
defMsg = defMsg.replace(rep + ChatManager.SEPARATOR + p.getName(), ChatManager.SEPARATOR + ""); // remove
|
||||
// v1
|
||||
// char
|
||||
else
|
||||
defMsg = defMsg.replace(rep, ChatManager.SEPARATOR + "");
|
||||
}
|
||||
if (format.contains("%1$s") || format.contains("%2$s")) {
|
||||
ChatItem.debug("Begin def msg: " + defMsg + "");
|
||||
msg = (format.contains("%2$s") ? String.format(format, p.getDisplayName(), defMsg)
|
||||
: String.format(format, p.getDisplayName()));
|
||||
} else {
|
||||
msg = format.replace(e.getMessage(), defMsg);
|
||||
}
|
||||
ItemStack item = p.getItemInHand();
|
||||
String itemName = ItemUtils.isEmpty(item) ? (c.HAND_DISABLED ? c.PLACEHOLDERS.get(0) : c.HAND_NAME)
|
||||
: styleItem(p, item, c);
|
||||
String loggedMessage = msg.replace(ChatManager.SEPARATOR + "", itemName).replace("{name}", p.getName())
|
||||
.replace("{display-name}", p.getDisplayName());
|
||||
Bukkit.getConsoleSender().sendMessage(loggedMessage); // show in log
|
||||
if (ChatItem.discordSrvSupport)
|
||||
DiscordSrvSupport.sendchatMessage(p, loggedMessage);
|
||||
ChatItem.debug("Msg: " + msg.replace(ChatColor.COLOR_CHAR, '&') + ", format: " + format);
|
||||
e.getRecipients().forEach((pl) -> showItem(pl, p, item, msg));
|
||||
}
|
||||
|
||||
private void showItem(Player to, Player origin, ItemStack item, String msg) {
|
||||
ComponentBuilder builder = new ComponentBuilder("");
|
||||
ChatColor color = ChatColor.RESET;
|
||||
String colorCode = "", text = "";
|
||||
boolean waiting = false, isHex = false;
|
||||
for (char args : msg.toCharArray()) {
|
||||
if (args == '§') { // begin of color
|
||||
if (colorCode.isEmpty() && !text.isEmpty()) { // text before this char
|
||||
ChatItem.debug("Append " + text);
|
||||
appendToComponentBuilder(builder, new ComponentBuilder(text).color(color).create());
|
||||
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())
|
||||
isHex = true;
|
||||
colorCode += args; // a color by itself
|
||||
} else {
|
||||
waiting = false;
|
||||
if(!colorCode.isEmpty()) {
|
||||
if(isHex && colorCode.length() >= 7)
|
||||
color = ColorManager.getColor(colorCode);
|
||||
else if(colorCode.length() == 1) // if only one color code
|
||||
color = ColorManager.getColor(colorCode);
|
||||
else
|
||||
text += ColorManager.getColorString(colorCode);
|
||||
colorCode = "";
|
||||
}
|
||||
if (args == ChatManager.SEPARATOR
|
||||
&& (!getStorage().HAND_DISABLED || (item != null && item.hasItemMeta()))) {
|
||||
// here put the item
|
||||
appendToComponentBuilder(builder, new ComponentBuilder(text).color(color).create());
|
||||
addItem(builder, to, origin, item);
|
||||
text = "";
|
||||
} else {
|
||||
// basic text, not waiting for code after '§'
|
||||
text += args;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!text.isEmpty())
|
||||
appendToComponentBuilder(builder, new ComponentBuilder(text).color(color).create());
|
||||
to.spigot().sendMessage(builder.create());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an {@link org.bukkit.inventory.ItemStack} to a Json string for
|
||||
* sending with {@link net.md_5.bungee.api.chat.BaseComponent}'s.
|
||||
*
|
||||
* @param itemStack
|
||||
* the item to convert
|
||||
* @param itemStack the item to convert
|
||||
* @return the Json string representation of the item
|
||||
*/
|
||||
public String convertItemStackToJson(ItemStack itemStack) {
|
||||
@@ -235,9 +279,10 @@ public class ChatListener implements Listener {
|
||||
Class<?> nbtTag = PacketUtils.getNmsClass("NBTTagCompound", "nbt.");
|
||||
Class<?> craftItemClass = PacketUtils.getObcClass("inventory.CraftItemStack");
|
||||
Object nmsNbtTagCompoundObj = nbtTag.newInstance();
|
||||
if(saveMethod == null) {
|
||||
if (saveMethod == null) {
|
||||
Object nmsItemStackObj = craftItemClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, itemStack);
|
||||
return nmsItemStackObj.getClass().getMethod("save", nbtTag).invoke(nmsItemStackObj, nmsNbtTagCompoundObj).toString();
|
||||
return nmsItemStackObj.getClass().getMethod("save", nbtTag)
|
||||
.invoke(nmsItemStackObj, nmsNbtTagCompoundObj).toString();
|
||||
} else {
|
||||
Object nmsItemStackObj = craftItemClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, itemStack);
|
||||
return saveMethod.invoke(nmsItemStackObj, nmsNbtTagCompoundObj).toString();
|
||||
@@ -247,30 +292,43 @@ public class ChatListener implements Listener {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest color chat
|
||||
*
|
||||
* @param msg the message that contains color
|
||||
* @return the char of the color or 'r' if nothing found
|
||||
*/
|
||||
private char getColorChat(String msg) {
|
||||
if(msg.length() < 2)
|
||||
return 'r';
|
||||
for(int i = msg.length() - 2; i > 0; i--) {
|
||||
char s = msg.charAt(i);
|
||||
if(ChatColor.COLOR_CHAR == s) {
|
||||
return msg.charAt(i + 1);
|
||||
}
|
||||
}
|
||||
return 'r';
|
||||
}
|
||||
|
||||
public void addItem(ComponentBuilder builder, Player to, Player origin, ItemStack item) {
|
||||
if (!ItemUtils.isEmpty(item)) {
|
||||
ComponentBuilder itemComponent = new ComponentBuilder(ChatListener.styleItem(to, item, getStorage()));
|
||||
String itemJson = convertItemStackToJson(item);
|
||||
itemComponent.event(new HoverEvent(Action.SHOW_ITEM, new ComponentBuilder(itemJson).create()));
|
||||
appendToComponentBuilder(builder, itemComponent.create());
|
||||
} else {
|
||||
String handName = getStorage().HAND_NAME;
|
||||
ComponentBuilder handComp = new ComponentBuilder("");
|
||||
ComponentBuilder handTooltip = new ComponentBuilder("");
|
||||
int stay = getStorage().HAND_TOOLTIP.size();
|
||||
for (String line : getStorage().HAND_TOOLTIP) {
|
||||
stay--;
|
||||
handTooltip.append(
|
||||
line.replace("{name}", origin.getName()).replace("{display-name}", origin.getDisplayName()));
|
||||
if (stay > 0)
|
||||
handTooltip.append("\n");
|
||||
}
|
||||
handComp.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, handTooltip.create()));
|
||||
if (handName.contains("{name}")) {
|
||||
String[] splitted = handName.split("\\{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("{display-name}", origin.getDisplayName()));
|
||||
appendToComponentBuilder(builder, handComp.create());
|
||||
}
|
||||
}
|
||||
|
||||
public static String styleItem(Player p, ItemStack item, Storage c) {
|
||||
String replacer = c.NAME_FORMAT;
|
||||
String amount = c.AMOUNT_FORMAT;
|
||||
|
||||
|
||||
if (item.getAmount() == 1) {
|
||||
if (c.FORCE_ADD_AMOUNT) {
|
||||
amount = amount.replace(TIMES, "1");
|
||||
@@ -285,4 +343,27 @@ public class ChatListener implements Listener {
|
||||
replacer = replacer.replace(NAME, NamerManager.getName(p, item, c));
|
||||
return replacer;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,72 +12,70 @@ import org.apache.logging.log4j.message.Message;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.dadus33.chatitem.chatmanager.v2.ChatListener;
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.utils.Storage;
|
||||
|
||||
|
||||
public class Log4jFilter implements Filter {
|
||||
|
||||
private Storage c;
|
||||
private Storage c;
|
||||
|
||||
public Log4jFilter(Storage st){
|
||||
c = st;
|
||||
((Logger) LogManager.getRootLogger()).addFilter(this);
|
||||
}
|
||||
public Log4jFilter(Storage st) {
|
||||
c = st;
|
||||
((Logger) LogManager.getRootLogger()).addFilter(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getOnMismatch() {
|
||||
return NEUTRAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getOnMismatch() {
|
||||
return NEUTRAL;
|
||||
}
|
||||
@Override
|
||||
public Result getOnMatch() {
|
||||
return NEUTRAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getOnMatch() {
|
||||
return NEUTRAL;
|
||||
}
|
||||
@Override
|
||||
public Result filter(Logger logger, Level level, Marker marker, String s, Object... objects) {
|
||||
return checkMessage(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(Logger logger, Level level, Marker marker, String s, Object... objects) {
|
||||
return checkMessage(s);
|
||||
}
|
||||
@Override
|
||||
public Result filter(Logger logger, Level level, Marker marker, Object o, Throwable throwable) {
|
||||
return checkMessage(((Message) o).getFormattedMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(Logger logger, Level level, Marker marker, Object o, Throwable throwable) {
|
||||
return checkMessage(((Message)o).getFormattedMessage());
|
||||
}
|
||||
@Override
|
||||
public Result filter(Logger logger, Level level, Marker marker, Message message, Throwable throwable) {
|
||||
return checkMessage(message.getFormattedMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(Logger logger, Level level, Marker marker, Message message, Throwable throwable) {
|
||||
return checkMessage(message.getFormattedMessage());
|
||||
}
|
||||
@Override
|
||||
public Result filter(LogEvent logEvent) {
|
||||
return checkMessage(logEvent.getMessage().getFormattedMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(LogEvent logEvent) {
|
||||
return checkMessage(logEvent.getMessage().getFormattedMessage());
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
// seems to be required
|
||||
}
|
||||
public void stop() {
|
||||
// seems to be required
|
||||
}
|
||||
|
||||
private Result checkMessage(String msg){
|
||||
if(msg==null){
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
for(String placeholder : c.PLACEHOLDERS){
|
||||
if(msg.contains(placeholder)){
|
||||
for(Player p : Bukkit.getOnlinePlayers()){
|
||||
if(msg.contains(ChatListener.SEPARATOR +p.getName())){
|
||||
return Result.DENY;
|
||||
}
|
||||
}
|
||||
private Result checkMessage(String msg) {
|
||||
if (msg == null) {
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
for (String placeholder : c.PLACEHOLDERS) {
|
||||
if (msg.contains(placeholder)) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (msg.contains(ChatManager.SEPARATOR + p.getName())) {
|
||||
return Result.DENY;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
|
||||
public void setStorage(Storage nst){
|
||||
this.c = nst;
|
||||
}
|
||||
public void setStorage(Storage nst) {
|
||||
this.c = nst;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package me.dadus33.chatitem.hook;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import github.scarsz.discordsrv.DiscordSRV;
|
||||
|
||||
public class DiscordSrvSupport {
|
||||
|
||||
public static void sendchatMessage(Player p, String message) {
|
||||
DiscordSRV pl = DiscordSRV.getPlugin();
|
||||
if (DiscordSRV.config().getBooleanElse("UseModernPaperChatEvent", false) && pl.isModernChatEventAvailable()) {
|
||||
return;
|
||||
}
|
||||
pl.processChatMessage(p, message, pl.getOptionalChannel("global"), false);
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class InventoryListener implements Listener {
|
||||
p.closeInventory();
|
||||
ChatItem.reload(p);
|
||||
}
|
||||
} else if(type.equals(Material.INK_SAC)) {
|
||||
} else if(type.equals(ItemUtils.INK_SAC)) {
|
||||
setInConfig("general.color-if-already-colored", c.COLOR_IF_ALREADY_COLORED = !c.COLOR_IF_ALREADY_COLORED);
|
||||
open(p);
|
||||
} else if(type.equals(Material.REDSTONE)) {
|
||||
@@ -50,6 +50,9 @@ public class InventoryListener implements Listener {
|
||||
} else if(type.equals(Material.STICK)) {
|
||||
setInConfig("general.hand.disabled", c.HAND_DISABLED = !c.HAND_DISABLED);
|
||||
open(p);
|
||||
} 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))
|
||||
c.LIMIT--;
|
||||
@@ -86,8 +89,10 @@ public class InventoryListener implements Listener {
|
||||
inv.setItem(slot++, getManagerItem(manager));
|
||||
}
|
||||
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(Material.INK_SAC, "color-if-already-colored", c.COLOR_IF_ALREADY_COLORED));
|
||||
inv.setItem(18, getBoolChangeItem(ItemUtils.INK_SAC, "color-if-already-colored", c.COLOR_IF_ALREADY_COLORED));
|
||||
inv.setItem(19, getBoolChangeItem(Material.REDSTONE, "deny-no-item", c.DENY_IF_NO_ITEM));
|
||||
inv.setItem(20, getBoolChangeItem(Material.STICK, "hand-disabled", c.HAND_DISABLED));
|
||||
inv.setItem(21, getAmountChangeItem(Material.IRON_DOOR, "limit-per-message", c.LIMIT));
|
||||
|
||||
@@ -2,10 +2,10 @@ package me.dadus33.chatitem.playernamer;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
public interface IPlayerNamer {
|
||||
|
||||
public TextComponent getName(Player p);
|
||||
public BaseComponent[] getName(Player p);
|
||||
|
||||
}
|
||||
@@ -22,7 +22,6 @@ public class PlayerNamerManager {
|
||||
pl.getLogger().info("Enable support for HexNicks plugin !");
|
||||
} else {
|
||||
setPlayerNamer(new DefaultPlayerNamer());
|
||||
pl.getLogger().info("Use default player namer.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,13 @@ package me.dadus33.chatitem.playernamer.hook;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.dadus33.chatitem.playernamer.IPlayerNamer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
||||
public class DefaultPlayerNamer implements IPlayerNamer {
|
||||
|
||||
@Override
|
||||
public TextComponent getName(Player p) {
|
||||
return new TextComponent(p.getName());
|
||||
public BaseComponent[] getName(Player p) {
|
||||
return new ComponentBuilder(p.getName()).create();
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,14 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import dev.majek.hexnicks.Nicks;
|
||||
import me.dadus33.chatitem.playernamer.IPlayerNamer;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
public class HexNicksPlayerNamer implements IPlayerNamer {
|
||||
|
||||
@Override
|
||||
public TextComponent getName(Player p) {
|
||||
return new TextComponent(BukkitComponentSerializer.legacy().toBuilder().hexColors()
|
||||
.useUnusualXRepeatedCharacterHexFormat().build().serialize(Nicks.api().getStoredNick(p).join()));
|
||||
public BaseComponent[] getName(Player p) {
|
||||
return BungeeComponentSerializer.get().serialize(Nicks.api().getStoredNick(p).join());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package me.dadus33.chatitem.utils;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class ColorManager {
|
||||
|
||||
public static String getColorString(String input) {
|
||||
if(input == null || input.isEmpty())
|
||||
return "";
|
||||
String str = "";
|
||||
if(Version.getVersion().isNewerOrEquals(Version.V1_16) && input.startsWith("x")) { // x mean it's an hex
|
||||
ChatItem.debug("Removing char x at begin: " + input.substring(1));
|
||||
input = input.substring(1);
|
||||
if(input.length() >= 6) { // at least hex
|
||||
str += ChatColor.of("#" + input.substring(0, 6)); // get first hex color code
|
||||
ChatItem.debug("Str with hex: " + str);
|
||||
if(input.length() > 6) // if as another color code
|
||||
str += getColorString(input.substring(6)); // get color for after
|
||||
return str;
|
||||
} else
|
||||
ChatItem.debug("Low len: " + input.length());
|
||||
} else
|
||||
ChatItem.debug("1.15 - for : " + input);
|
||||
// not hex
|
||||
for(char c : input.toCharArray())
|
||||
str += ChatColor.getByChar(c);
|
||||
return str;
|
||||
}
|
||||
|
||||
public static ChatColor getColor(String input) {
|
||||
if(input == null || input.isEmpty())
|
||||
return ChatColor.RESET;
|
||||
if(Version.getVersion().isNewerOrEquals(Version.V1_16) && input.startsWith("x")) { // x mean it's an hex
|
||||
ChatItem.debug("Removing char x at begin: " + input.substring(1));
|
||||
if(input.length() >= 7) { // at least hex, and 7 because we count the "x"
|
||||
return ChatColor.of("#" + input.substring(1, 7)); // get first hex color code
|
||||
} else
|
||||
ChatItem.debug("Low len: " + input.length());
|
||||
} else
|
||||
ChatItem.debug("1.15 - for : " + input);
|
||||
// not hex
|
||||
return ChatColor.getByChar(input.charAt(0));
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@ public class ItemUtils {
|
||||
public static final Material BOOK_AND_QUILL = getMaterialWithCompatibility("BOOK_AND_QUILL", "WRITTEN_BOOK");
|
||||
public static final Material WEB = getMaterialWithCompatibility("WEB", "COBWEB");
|
||||
public static final Material FIREBALL = getMaterialWithCompatibility("FIREBALL", "FIRE_CHARGE");
|
||||
public static final Material INK_SAC = getMaterialWithCompatibility("INK_SAC", "INK_SACK", "DYE", "GRAY_DYE");
|
||||
public static final Material FIREWORK_CHARGE = getMaterialWithCompatibility("FIREWORK_CHARGE", "FIRE_CHARGE");
|
||||
|
||||
public static final Material BIRCH_WOOD_STAIRS = getMaterialWithCompatibility("BIRCH_WOOD_STAIRS", "BIRCH_STAIRS");
|
||||
|
||||
@@ -83,4 +85,8 @@ public class ItemUtils {
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static boolean isEmpty(ItemStack item) {
|
||||
return item == null || item.getType().equals(Material.AIR);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package me.dadus33.chatitem.utils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -17,10 +19,9 @@ public class PacketUtils {
|
||||
/**
|
||||
* This Map is to reduce Reflection action which take more resources than just RAM action
|
||||
*/
|
||||
private static final HashMap<String, Class<?>> ALL_CLASS;
|
||||
private static final Map<String, Class<?>> ALL_CLASS = Collections.synchronizedMap(new HashMap<String, Class<?>>());
|
||||
|
||||
static {
|
||||
ALL_CLASS = new HashMap<>();
|
||||
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 + ".";
|
||||
|
||||
@@ -26,9 +26,9 @@ public class ReflectionUtils {
|
||||
*
|
||||
* @param source where we will find the field
|
||||
* @param field the name of the field
|
||||
* @return the requested field
|
||||
* @return the requested object of the field
|
||||
*/
|
||||
public static Object getField(Object source, String field) {
|
||||
public static Object getObject(Object source, String field) {
|
||||
try {
|
||||
Field f = source.getClass().getDeclaredField(field);
|
||||
f.setAccessible(true);
|
||||
@@ -39,6 +39,24 @@ public class ReflectionUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specified field name in the object source
|
||||
*
|
||||
* @param source where we will find the field
|
||||
* @param field the name of the field
|
||||
* @return the requested field
|
||||
*/
|
||||
public static Field getField(Object source, String field) {
|
||||
try {
|
||||
Field f = source.getClass().getDeclaredField(field);
|
||||
f.setAccessible(true);
|
||||
return f;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call method. Return the method return.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
package me.dadus33.chatitem.utils;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Represents the simplified SemVer schema Negativity uses for its plugin versions.
|
||||
*/
|
||||
public final class SemVer implements Comparable<SemVer> {
|
||||
|
||||
private final int major;
|
||||
private final int minor;
|
||||
private final int patch;
|
||||
|
||||
private final @Nullable Suffix suffix;
|
||||
|
||||
public SemVer(int major, int minor, int patch, @Nullable Suffix suffix) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
this.suffix = suffix;
|
||||
}
|
||||
|
||||
public boolean isNewerThan(SemVer other) {
|
||||
return this.compareTo(other) > 0;
|
||||
}
|
||||
|
||||
public boolean isOlderThan(SemVer other) {
|
||||
return this.compareTo(other) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Slightly different from {@link #equals} in that this method will return
|
||||
* true if the suffix has the same {@link Suffix#getWeight() weight}
|
||||
* but not the same {@link Suffix#getText()} text
|
||||
*/
|
||||
public boolean isEquivalentTo(SemVer other) {
|
||||
return this.compareTo(other) == 0;
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return major;
|
||||
}
|
||||
|
||||
public int getMinor() {
|
||||
return minor;
|
||||
}
|
||||
|
||||
public int getPatch() {
|
||||
return patch;
|
||||
}
|
||||
|
||||
public @Nullable Suffix getSuffix() {
|
||||
return suffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(SemVer o) {
|
||||
int majorDelta = Integer.compare(this.major, o.major);
|
||||
if (majorDelta != 0) {
|
||||
return majorDelta;
|
||||
}
|
||||
int minorDelta = Integer.compare(this.minor, o.minor);
|
||||
if (minorDelta != 0) {
|
||||
return minorDelta;
|
||||
}
|
||||
int patchDelta = Integer.compare(this.patch, o.patch);
|
||||
if (patchDelta != 0) {
|
||||
return patchDelta;
|
||||
}
|
||||
if (this.suffix != null) {
|
||||
return o.suffix != null ? this.suffix.compareTo(o.suffix) : -1;
|
||||
}
|
||||
if (o.suffix != null) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SemVer semVer = (SemVer) o;
|
||||
return major == semVer.major && minor == semVer.minor && patch == semVer.patch && Objects.equals(suffix, semVer.suffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(major, minor, patch, suffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SemVer{major=" + major + ", minor=" + minor + ", patch=" + patch + ", suffix=" + suffix + '}';
|
||||
}
|
||||
|
||||
public String toFormattedString() {
|
||||
if (suffix == null) {
|
||||
if(patch > 0)
|
||||
return major + "." + minor + (patch > 0 ? "." + patch : "");
|
||||
}
|
||||
return major + "." + minor + (patch > 0 ? "." + patch : "") + (suffix == null ? "" : "-" + suffix.getText());
|
||||
}
|
||||
|
||||
public static @Nullable SemVer parse(String text) {
|
||||
if (text == null || text.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] suffixSplit = text.split("-", 2);
|
||||
Suffix suffix = null;
|
||||
if (suffixSplit.length > 1) {
|
||||
suffix = Suffix.of(suffixSplit[1]);
|
||||
}
|
||||
|
||||
String[] parts = suffixSplit[0].split("\\.");
|
||||
int major;
|
||||
try {
|
||||
major = Integer.parseInt(parts[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
int minor = 0;
|
||||
if (parts.length > 1) {
|
||||
try {
|
||||
minor = Integer.parseInt(parts[1]);
|
||||
} catch (NumberFormatException ignore) {
|
||||
}
|
||||
}
|
||||
int patch = 0;
|
||||
if (parts.length > 2) {
|
||||
try {
|
||||
patch = Integer.parseInt(parts[2]);
|
||||
} catch (NumberFormatException ignore) {
|
||||
}
|
||||
}
|
||||
return new SemVer(major, minor, patch, suffix);
|
||||
}
|
||||
|
||||
public static final class Suffix implements Comparable<Suffix> {
|
||||
|
||||
public static final Suffix SNAPSHOT = new Suffix(0, "SNAPSHOT");
|
||||
public static final Suffix ALPHA = new Suffix(1, "ALPHA");
|
||||
public static final Suffix BETA = new Suffix(2, "BETA");
|
||||
public static final Suffix GAMMA = new Suffix(3, "GAMMA");
|
||||
public static final Suffix DELTA = new Suffix(4, "DELTA");
|
||||
|
||||
private final int weight;
|
||||
private final String text;
|
||||
|
||||
public Suffix(int weight, String text) {
|
||||
this.weight = weight;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public int getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Suffix o) {
|
||||
return Integer.compare(this.weight, o.weight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Suffix suffix = (Suffix) o;
|
||||
return weight == suffix.weight && text.equals(suffix.text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(weight, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Suffix{weight=" + weight + ", text='" + text + "'}";
|
||||
}
|
||||
|
||||
public static Suffix of(String text) {
|
||||
String uppercaseText = text.toUpperCase(Locale.ROOT);
|
||||
switch (uppercaseText) {
|
||||
case "SNAPSHOT":
|
||||
return SNAPSHOT;
|
||||
case "ALPHA":
|
||||
return ALPHA;
|
||||
case "BETA":
|
||||
return BETA;
|
||||
case "GAMMA":
|
||||
return GAMMA;
|
||||
case "DELTA":
|
||||
return DELTA;
|
||||
default:
|
||||
return new Suffix(-1, uppercaseText);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,9 @@ public class Storage {
|
||||
|
||||
private FileConfiguration conf;
|
||||
public final HashMap<String, HashMap<Short, String>> TRANSLATIONS = new HashMap<>();
|
||||
public boolean COLOR_IF_ALREADY_COLORED, FORCE_ADD_AMOUNT, LET_MESSAGE_THROUGH, DENY_IF_NO_ITEM,
|
||||
HAND_DISABLED, SHOW_NO_PERM_NORMAL, CHECK_UPDATE, SHOW_NO_PERM_COMMAND;
|
||||
public final String HAND_NAME, NAME_FORMAT, AMOUNT_FORMAT, MANAGER;
|
||||
public boolean COLOR_IF_ALREADY_COLORED, FORCE_ADD_AMOUNT, LET_MESSAGE_THROUGH, DENY_IF_NO_ITEM, DEBUG,
|
||||
HAND_DISABLED, SHOW_NO_PERM_NORMAL, CHECK_UPDATE, SHOW_NO_PERM_COMMAND, PERMISSION_ENABLED;
|
||||
public final String HAND_NAME, NAME_FORMAT, AMOUNT_FORMAT, MANAGER, PERMISSION_NAME;
|
||||
public final String NO_PERMISSION_MESSAGE, DENY_MESSAGE, RELOAD_MESSAGE, COOLDOWN_MESSAGE, LIMIT_MESSAGE;
|
||||
public final String SECONDS, MINUTES, HOURS;
|
||||
public final String JOIN_UPDATE_MESSAGE, JOIN_UPDATE_HOVER;
|
||||
@@ -45,6 +45,7 @@ public class Storage {
|
||||
|
||||
TRANSLATIONS.put(key, entry);
|
||||
}
|
||||
DEBUG = conf.getBoolean("debug", false);
|
||||
PLACEHOLDERS = ImmutableList.copyOf(conf.getStringList("general.placeholders"));
|
||||
NAME_FORMAT = color(conf.getString("general.name-format", "&b&l&o{name} {amount}&r"));
|
||||
AMOUNT_FORMAT = color(conf.getString("general.amount-format", "x{times}"));
|
||||
@@ -56,6 +57,8 @@ public class Storage {
|
||||
COOLDOWN = conf.getInt("general.cooldown", 60);
|
||||
SHOW_NO_PERM_NORMAL = conf.getBoolean("general.show-no-permission-message.normal", true);
|
||||
SHOW_NO_PERM_COMMAND = conf.getBoolean("general.show-no-permission-message.command", false);
|
||||
PERMISSION_ENABLED = conf.getBoolean("general.permission.enabled", false);
|
||||
PERMISSION_NAME = conf.getString("general.permission.name", "chatitem.use");
|
||||
HAND_DISABLED = conf.getBoolean("general.hand.disabled", false);
|
||||
HAND_NAME = color(conf.getString("general.hand.name", "&b&l&o{display-name}&b&l&o's hand"));
|
||||
HAND_TOOLTIP = conf.getStringList("general.hand.tooltip");
|
||||
@@ -69,8 +72,8 @@ public class Storage {
|
||||
JOIN_UPDATE_MESSAGE = color(conf.getString("messages.join-update.message",
|
||||
"&cA new version of ChatItem is available. &aClick here to download."));
|
||||
JOIN_UPDATE_HOVER = color(conf.getString("messages.join-update.hover", "&6Click to go to spigot page !"));
|
||||
LIMIT_MESSAGE = color(conf.getString("messages.limit-message"));
|
||||
|
||||
LIMIT_MESSAGE = color(conf.getString("messages.limit-message", "&c&lYou can only add 8 item placeholders per message!"));
|
||||
|
||||
SECONDS = color(conf.getString("messages.seconds", " seconds"));
|
||||
MINUTES = color(conf.getString("messages.minutes", " minutes"));
|
||||
HOURS = color(conf.getString("messages.hours", " hours"));
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
# For info visit
|
||||
# Spigotmc: https://www.spigotmc.org/resources/chatitem.19064/
|
||||
# Discord: https://discord.gg/ttA5CjMhk7
|
||||
|
||||
|
||||
# Version info, DON'T TOUCH
|
||||
config-version: 13
|
||||
|
||||
|
||||
# By default, it's in "both" mode.
|
||||
#
|
||||
# Available mode :
|
||||
@@ -50,7 +50,7 @@ general:
|
||||
tooltip:
|
||||
- "&7Nothing to see here"
|
||||
- "&7Just the empty hand of {display-name}."
|
||||
|
||||
|
||||
# Here you can choose which commands will the plugin attempt to parse. Console commands will all be ignored,
|
||||
# however player commands will be taken into consideration. To add a command, simply add an element to the list
|
||||
# bellow containing an alias (or name) for that command.
|
||||
@@ -65,6 +65,10 @@ general:
|
||||
show-no-permission-message:
|
||||
normal: true
|
||||
command: false
|
||||
# Manage permission to use placeholders
|
||||
permission:
|
||||
enabled: false
|
||||
name: "chatitem.use"
|
||||
# Here you can set the limit on how many placeholders a user is allowed to use inside a message.
|
||||
# Allowing too many placeholders can result in client crashes.
|
||||
limit: 8
|
||||
@@ -73,8 +77,8 @@ general:
|
||||
cooldown: 60
|
||||
# Check if the plugin have update
|
||||
check-update: true
|
||||
|
||||
|
||||
|
||||
|
||||
# Messages section. You can disable any of them by simply leaving them empty, like this: ""
|
||||
messages:
|
||||
# The message sent if showing off hands is disabled and the user isn't holding an item.
|
||||
@@ -138,6 +142,7 @@ messages:
|
||||
hand-disabled: "&6Hand disabled: %state%"
|
||||
limit-per-message: "&6Limit per message: &a%state%"
|
||||
cooldown: "&6Cooldown: &a%state%"
|
||||
debug: "&6Debug: &a%state%"
|
||||
# Change name and lore of all managers
|
||||
manager:
|
||||
both:
|
||||
@@ -180,14 +185,14 @@ messages:
|
||||
seconds: " seconds"
|
||||
minutes: " minutes"
|
||||
hours: " hours"
|
||||
|
||||
|
||||
enabled: "&aEnabled"
|
||||
disabled: "&cDisabled"
|
||||
|
||||
|
||||
# Translations
|
||||
# This is used to display prettier names in chat for items/blocks. Modifying this is usually unnecessary unless you know what you're doing.
|
||||
translations:
|
||||
## Blocks ##
|
||||
STONE:
|
||||
1: "Granite"
|
||||
STONE:
|
||||
0: "Stone"
|
||||
1: "Granite"
|
||||
@@ -780,8 +785,8 @@ translations:
|
||||
STONE_PICKAXE:
|
||||
0: "Stone Pickaxe"
|
||||
STONE_AXE:
|
||||
0: "Stone Axe
|
||||
DIAMOND_SWORD: "
|
||||
0: "Stone Axe"
|
||||
DIAMOND_SWORD:
|
||||
0: "Diamond Sword"
|
||||
DIAMOND_SPADE:
|
||||
0: "Diamond Shovel"
|
||||
@@ -933,8 +938,6 @@ translations:
|
||||
1: "Raw Salmon"
|
||||
2: "Clownfish"
|
||||
3: "Pufferfish"
|
||||
COOKED_FISH:
|
||||
0: "Cooked Fish"
|
||||
COOKED_FISH:
|
||||
0: "Cooked Salmon"
|
||||
INK_SACK:
|
||||
@@ -1066,9 +1069,6 @@ translations:
|
||||
16394: "Splash Potion of Slowness"
|
||||
16426: "Splash Potion of Slowness II"
|
||||
16458: "Extended Splash Potion of Slowness"
|
||||
16395: "Splash Potion of Leaping"
|
||||
16427: "Splash Potion of Leaping II"
|
||||
16459: "Extended Splash Potion of Leaping"
|
||||
16396: "Splash Potion of Harming"
|
||||
16428: "Splash Potion of Harming II"
|
||||
16460: "Extended Splash Potion of Harming"
|
||||
@@ -1149,8 +1149,8 @@ translations:
|
||||
POISONOUS_POTATO:
|
||||
0: "Poisonous Potato"
|
||||
EMPTY_MAP:
|
||||
0: "Empty Map
|
||||
GOLDEN_CARROT: "
|
||||
0: "Empty Map"
|
||||
GOLDEN_CARROT:
|
||||
0: "Golden Carrot"
|
||||
SKULL_ITEM:
|
||||
0: "Skeleton Head"
|
||||
|
||||
Reference in new issue
Block a user