Compare commits

...
25 Commits
Author SHA1 Message Date
Elikill58 587432269a Upgrade to 2.4.9 2023-10-09 23:36:05 +02:00
dependabot[bot] a080e18571 Bump EcoEnchants 10.36.1 (#99)
Bumps [com.github.Auxilor:EcoEnchants](https://github.com/Auxilor/EcoEnchants) from 10.35.3 to 10.36.1.
- [Release notes](https://github.com/Auxilor/EcoEnchants/releases)
- [Commits](https://github.com/Auxilor/EcoEnchants/compare/10.35.3...10.36.1)

---
updated-dependencies:
- dependency-name: com.github.Auxilor:EcoEnchants
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-09 13:57:20 +02:00
dependabot[bot] 7b758882be Bump ProtocolLib to 5.1.0 (#90)
Bumps com.comphenix.protocol:ProtocolLib from 5.0.0 to 5.1.0.

---
updated-dependencies:
- dependency-name: com.comphenix.protocol:ProtocolLib
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-09 13:57:09 +02:00
dependabot[bot] beafc6a635 Bump com.viaversion:viaversion-api from 4.7.0 to 4.8.1 (#102)
Bumps com.viaversion:viaversion-api from 4.7.0 to 4.8.1.

---
updated-dependencies:
- dependency-name: com.viaversion:viaversion-api
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-09 13:54:52 +02:00
dependabot[bot] 0da4039b70 Bump com.willfp:eco from 6.65.4 to 6.65.5 (#95)
Bumps [com.willfp:eco](https://github.com/Auxilor/eco) from 6.65.4 to 6.65.5.
- [Release notes](https://github.com/Auxilor/eco/releases)
- [Commits](https://github.com/Auxilor/eco/compare/6.65.4...6.65.5)

---
updated-dependencies:
- dependency-name: com.willfp:eco
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 08:16:24 +02:00
dependabot[bot] b89e18b149 Bump com.github.Auxilor:EcoEnchants from 10.35.2 to 10.35.3 (#94)
Bumps [com.github.Auxilor:EcoEnchants](https://github.com/Auxilor/EcoEnchants) from 10.35.2 to 10.35.3.
- [Release notes](https://github.com/Auxilor/EcoEnchants/releases)
- [Commits](https://github.com/Auxilor/EcoEnchants/compare/10.35.2...10.35.3)

---
updated-dependencies:
- dependency-name: com.github.Auxilor:EcoEnchants
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 08:15:43 +02:00
Elikill58 07243fbf91 Fix wrong key 2023-09-17 21:59:43 +02:00
Elikill58 4b90aaa070 Prevent no end in message 2023-09-17 11:32:53 +02:00
Elikill58 9d74eb067a Fix #93 2023-09-14 15:56:58 +02:00
dependabot[bot] c51f62a9fb Bump com.github.Auxilor:EcoEnchants from 10.26.5 to 10.35.2 (#92)
Bumps [com.github.Auxilor:EcoEnchants](https://github.com/Auxilor/EcoEnchants) from 10.26.5 to 10.35.2.
- [Release notes](https://github.com/Auxilor/EcoEnchants/releases)
- [Commits](https://github.com/Auxilor/EcoEnchants/compare/10.26.5...10.35.2)

---
updated-dependencies:
- dependency-name: com.github.Auxilor:EcoEnchants
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-14 15:51:07 +02:00
Elikill58 badddd29ed Prevent NPE 2023-08-07 13:01:56 +02:00
Elikill58 d188289e84 Add option for broadcast and show, and change for tab 2023-08-07 11:27:11 +02:00
dependabot[bot] 1b9fd3bf90 Bump com.willfp:eco from 6.65.3 to 6.65.4 (#85)
Bumps com.willfp:eco from 6.65.3 to 6.65.4.

---
updated-dependencies:
- dependency-name: com.willfp:eco
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-07 08:34:36 +02:00
dependabot[bot] 0d98b4408e Bump com.github.Auxilor:EcoEnchants from 10.26.2 to 10.26.5 (#87)
Bumps com.github.Auxilor:EcoEnchants from 10.26.2 to 10.26.5.

---
updated-dependencies:
- dependency-name: com.github.Auxilor:EcoEnchants
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-07 08:34:27 +02:00
dependabot[bot] 769abab65c Bump com.github.Auxilor:EcoEnchants from 10.25.1 to 10.26.2 (#84)
Bumps com.github.Auxilor:EcoEnchants from 10.25.1 to 10.26.2.

---
updated-dependencies:
- dependency-name: com.github.Auxilor:EcoEnchants
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-31 08:14:07 +02:00
Elikill58 78311f60b4 upgrade to snapshot 2023-07-26 19:44:51 +02:00
Elikill58 bd31b5791c Fix for 1.15- players 2023-07-26 19:44:24 +02:00
Elikill58 cd5cfa47ec Fix error with json 2023-07-26 19:27:37 +02:00
Elikill58 d31bdbef68 Remove one import 2023-07-26 19:01:12 +02:00
Elikill58 a82b50b1d0 Fix #78 2023-07-24 11:34:04 +02:00
dependabot[bot] 912bbcf371 Bump com.willfp:eco from 6.65.2 to 6.65.3 (#83)
Bumps com.willfp:eco from 6.65.2 to 6.65.3.

---
updated-dependencies:
- dependency-name: com.willfp:eco
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-24 11:27:03 +02:00
dependabot[bot] af5d63ea93 Bump com.github.Auxilor:EcoEnchants from 10.23.1 to 10.25.1 (#82)
Bumps [com.github.Auxilor:EcoEnchants](https://github.com/Auxilor/EcoEnchants) from 10.23.1 to 10.25.1.
- [Release notes](https://github.com/Auxilor/EcoEnchants/releases)
- [Commits](https://github.com/Auxilor/EcoEnchants/compare/10.23.1...10.25.1)

---
updated-dependencies:
- dependency-name: com.github.Auxilor:EcoEnchants
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-24 11:26:56 +02:00
Elikill58 69681553c8 Fix 1.18 issue 2023-07-20 20:05:58 +02:00
Elikill58 3f6856ddab Fix invocation error 2023-07-20 19:22:39 +02:00
Elikill58 9d55208563 Change ChatControl support 2023-07-19 20:27:14 +02:00
16 changed files with 120 additions and 85 deletions

No files matched your search

+11 -13
View File
@@ -6,7 +6,7 @@
<groupId>me.dadus33</groupId>
<artifactId>ChatItem</artifactId>
<version>2.4.8</version>
<version>2.4.9</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -85,13 +85,13 @@
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.0.0</version>
<version>5.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.viaversion</groupId>
<artifactId>viaversion-api</artifactId>
<version>4.7.0</version>
<version>4.8.1</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -151,13 +151,7 @@
<dependency>
<groupId>com.github.Auxilor</groupId>
<artifactId>EcoEnchants</artifactId>
<version>10.23.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.kangarko</groupId>
<artifactId>ChatControl-Free</artifactId>
<version>5.9.5</version>
<version>10.36.1</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -169,7 +163,7 @@
<dependency>
<groupId>com.willfp</groupId>
<artifactId>eco</artifactId>
<version>6.65.2</version>
<version>6.65.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
@@ -212,8 +206,12 @@
<shadedPattern>me.dadus33.libs.gson</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori.adventure.text.serializer.bungeecord</pattern>
<shadedPattern>me.dadus33.libs.kyori.serializer.bungeecord</shadedPattern>
<pattern>net.kyori</pattern>
<shadedPattern>me.dadus33.libs.kyori</shadedPattern>
</relocation>
<relocation>
<pattern>com.github.steveice10.opennbt</pattern>
<shadedPattern>me.dadus33.libs.opennbt</shadedPattern>
</relocation>
</relocations>
<filters>
@@ -7,6 +7,7 @@ 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;
@@ -173,7 +174,7 @@ public class ChatItem extends JavaPlugin {
getServer().getMessenger().registerIncomingPluginChannel(this, brandChannelName, (chan, p, msg) -> ItemPlayer.getPlayer(p).setClientName(new String(msg).substring(1)));
if (storage.checkUpdate) {
getServer().getScheduler().runTaskAsynchronously(this, () -> {
CompletableFuture.runAsync(() -> {
String urlName = "https://api.spigotmc.org/legacy/update.php?resource=19064";
String content = Utils.getFromURL(urlName);
if (Strings.isNullOrEmpty(content))
@@ -15,7 +15,7 @@ public class Storage {
public final String SECONDS, minutes, hours;
public final String updateMessage, updateHover;
public final List<String> placeholders, tooltipHand, tooltipBuggedClient, ignoredItems;
public boolean colorIfColored, addAmountForced, letMessageThrough, denyIfNoItem, debug, handDisabled, showNoPermissionMessage, checkUpdate, permissionEnabled;
public boolean colorIfColored, addAmountForced, letMessageThrough, denyIfNoItem, debug, handDisabled, showNoPermissionMessage, checkUpdate, permissionEnabled, cmdBroadcast, cmdShow;
public int configVersion, limit, cooldown;
private FileConfiguration conf;
@@ -46,6 +46,8 @@ public class Storage {
tooltipBuggedClient = conf.getStringList("general.bugged_client.tooltip").stream().map(Storage::color).collect(Collectors.toList());
ignoredItems = conf.getStringList("general.ignored_items");
checkUpdate = conf.getBoolean("general.check-update", true);
cmdShow = conf.getBoolean("general.sub-commands.broadcast", true);
cmdBroadcast = conf.getBoolean("general.sub-commands.show", true);
messageDeny = color(conf.getString("messages.deny-message", "&c&lYou have no item in hand!"));
messageReload = color(conf.getString("messages.reload-success", "&b&lSuccessful reload!"));
messageNoPermission = color(conf.getString("messages.no-permission", "&c&lI'm sorry, but you are not allowed to use the placeholder in chat!"));
@@ -59,7 +61,6 @@ public class Storage {
minutes = color(conf.getString("messages.minutes", " minutes"));
hours = color(conf.getString("messages.hours", " hours"));
colorStringList(tooltipHand);
}
public static String color(String s) {
@@ -13,6 +13,7 @@ import me.dadus33.chatitem.chatmanager.v1.listeners.ChatPacketManager;
import me.dadus33.chatitem.chatmanager.v1.packets.ChatItemPacketManager;
import me.dadus33.chatitem.chatmanager.v1.packets.PacketManager;
import me.dadus33.chatitem.utils.PacketUtils;
import me.dadus33.chatitem.utils.ReflectionUtils;
public class PacketEditingChatManager extends ChatManager {
@@ -79,6 +80,7 @@ public class PacketEditingChatManager extends ChatManager {
private static Object internalCreateSystemChatPacket(Object obj) throws Exception {
Class<?> packetClass = PacketUtils.getNmsClass("ClientboundSystemChatPacket", "network.protocol.game.", "PacketPlayOutChat");
Class<?> chatMessageTypeClass = PacketUtils.isClassExist("net.minecraft.network.chat.ChatMessageType") ? PacketUtils.getNmsClass("ChatMessageType", "network.chat.") : null;
Constructor<?> betterOne = null;
Object[] betterParam = null;
for (Constructor<?> cons : packetClass.getDeclaredConstructors()) {
@@ -89,6 +91,8 @@ public class PacketEditingChatManager extends ChatManager {
if(obj instanceof String) {
if (cons.getParameterCount() == 2 && cons.getParameterTypes()[0].equals(String.class) && cons.getParameterTypes()[1].equals(int.class)) { // "string, int"
return cons.newInstance(obj, 1);
} else if (cons.getParameterCount() == 2 && cons.getParameterTypes()[0].equals(String.class) && cons.getParameterTypes()[1].equals(boolean.class)) { // "string, boolean"
return cons.newInstance(obj, false); // false for no overlay
} else if (cons.getParameterCount() == 3 && cons.getParameterTypes()[1].equals(String.class)) { // "component", "string", <something not checked>
Class<?> secondParam = cons.getParameterTypes()[2];
if (secondParam.equals(int.class)) // "component", "string", "int"
@@ -104,6 +108,8 @@ public class PacketEditingChatManager extends ChatManager {
if(cons.getParameterTypes()[i].isAssignableFrom(obj.getClass())) {
params[i] = obj;
nbPut++;
} else if(chatMessageTypeClass != null && cons.getParameterTypes()[i].isAssignableFrom(chatMessageTypeClass)) {
params[i] = getChatMessageType();
}
}
if(nbPut == 1) {
@@ -122,4 +128,9 @@ public class PacketEditingChatManager extends ChatManager {
}
return null;
}
private static Object getChatMessageType() throws Exception {
Class<?> c = PacketUtils.getNmsClass("ChatMessageType", "network.chat.");
return ReflectionUtils.getMethod(c, c, byte.class).invoke(null, (byte) 0);
}
}
@@ -11,7 +11,6 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import me.dadus33.chatitem.ChatItem;
import me.dadus33.chatitem.ItemPlayer;
import me.dadus33.chatitem.Storage;
import me.dadus33.chatitem.chatmanager.Chat;
import me.dadus33.chatitem.chatmanager.ChatManager;
@@ -45,9 +44,12 @@ public interface IComponentManager {
return null;
}
default Object manageItem(Player p, Chat chat, ChatItemPacket packet, ItemStack item, Storage c) throws Exception {
String message = JSONManipulator.getInstance().parse(chat, getBaseComponentAsJSON(packet), item, ChatManager.styleItem(chat.getPlayer(), item, c),
ItemPlayer.getPlayer(p).getProtocolVersion());
default Object manageItem(Player p, Chat chat, ChatItemPacket packet, ItemStack item, 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());
else
message = JSONManipulator.getInstance().parse(chat, json, item, ChatManager.styleItem(chat.getPlayer(), item, c));
if (message != null) {
ChatItem.debug("(v1) Writing message: " + message);
writeJson(packet, message);
@@ -55,8 +57,8 @@ public interface IComponentManager {
return packet.getPacket();
}
default Object manageEmpty(Player p, Chat chat, ChatItemPacket packet, Storage c) {
String message = JSONManipulator.getInstance().parseEmpty(getBaseComponentAsJSON(packet), c.handName, c.tooltipHand, chat.getPlayer());
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());
if (message != null) {
ChatItem.debug("(v1) Writing empty message: " + message);
writeJson(packet, message);
@@ -82,11 +84,11 @@ public interface IComponentManager {
}
if (jsonObj.has("text")) {
JsonElement text = jsonObj.get("text");
if(text.isJsonObject() && searchInObject(text.getAsJsonObject()))
if (text.isJsonObject() && searchInObject(text.getAsJsonObject()))
return getWithId();
else if(text.isJsonArray() && searchInExtra(text.getAsJsonArray()))
else if (text.isJsonArray() && searchInExtra(text.getAsJsonArray()))
return getWithId();
else if(text.isJsonPrimitive() && searchInString(text.getAsString()))
else if (text.isJsonPrimitive() && searchInString(text.getAsString()))
return getWithId();
}
return null;
@@ -122,7 +124,7 @@ public interface IComponentManager {
else if (found)
id += c;
}
return false;
return id != "" && Utils.isInteger(id) && Chat.getChat(Integer.parseInt(id)).isPresent();
}
}
}
@@ -66,13 +66,14 @@ public class AdventureComponentManager implements IComponentManager {
}
@Override
public Object manageItem(Player p, Chat chat, ChatItemPacket packet, ItemStack item, Storage c) throws Exception {
String itemName = ChatManager.getNameOfItem(chat.getPlayer(), item, c);ChatItem.debug("NBT tag: " + PacketUtils.getNbtTag(item));;
public Object manageItem(Player p, Chat chat, ChatItemPacket packet, ItemStack item, String json, Storage c) throws Exception {
String itemName = ChatManager.getNameOfItem(chat.getPlayer(), item, 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))));
}
@Override
public Object manageEmpty(Player p, Chat chat, ChatItemPacket packet, Storage c) {
public Object manageEmpty(Player p, 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();
@@ -60,12 +60,12 @@ public class StringComponentManager implements IComponentManager {
}
@Override
public Object manageItem(Player p, Chat chat, ChatItemPacket packet, ItemStack item, Storage c) throws Exception {
return manage(p, chat, packet, ChatManager.getNameOfItem(chat.getPlayer(), item, c), Utils.createItemHover(item));
public Object manageItem(Player p, Chat chat, ChatItemPacket packet, ItemStack item, String json, Storage c) throws Exception {
return manage(p, chat, packet, ChatManager.getNameOfItem(chat.getPlayer(), item, c), Utils.createItemHover(item, p));
}
@Override
public Object manageEmpty(Player p, Chat chat, ChatItemPacket packet, Storage c) {
public Object manageEmpty(Player p, Chat chat, ChatItemPacket packet, String json, Storage c) {
ComponentBuilder builder = new ComponentBuilder("");
c.tooltipHand.forEach(s -> builder.append(s));
Player sender = chat.getPlayer();
@@ -4,7 +4,6 @@ import static me.dadus33.chatitem.utils.PacketUtils.getNmsClass;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -27,7 +26,6 @@ import me.dadus33.chatitem.chatmanager.Chat;
import me.dadus33.chatitem.chatmanager.ChatManager;
import me.dadus33.chatitem.utils.PacketUtils;
import me.dadus33.chatitem.utils.ReflectionUtils;
import me.dadus33.chatitem.utils.Version;
public class JSONManipulator {
@@ -46,17 +44,16 @@ public class JSONManipulator {
public static final Method SAVE_NMS_ITEM_STACK_METHOD = ReflectionUtils.getMethod(NMS_ITEM_STACK_CLASS, NBT_TAG_COMPOUND, NBT_TAG_COMPOUND);
public static final Field MAP = ReflectionUtils.getField(NBT_TAG_COMPOUND, "map", "x");
private static final ConcurrentHashMap<Map.Entry<Version, ItemStack>, JsonObject> STACKS = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ItemStack, JsonObject> STACKS = new ConcurrentHashMap<>();
private JsonObject itemTooltip;
private JsonArray classicTooltip;
public String parse(Chat chat, String json, ItemStack item, String replacement, int protocol) throws Exception {
public String parse(Chat chat, String json, ItemStack item, String replacement) throws Exception {
JsonObject obj = JsonParser.parseString(json).getAsJsonObject();
final AbstractMap.SimpleEntry<Version, ItemStack> p = new AbstractMap.SimpleEntry<>(Version.getVersion(protocol), item);
JsonObject wrapper = new JsonObject(); // Create a wrapper object for the whole array
if ((itemTooltip = STACKS.get(p)) == null) {
if ((itemTooltip = STACKS.get(item)) == null) {
JsonArray use = Translator.toJson(replacement); // We get the json representation of the old color
// formatting method
ChatItem.debug("Remplacement: " + replacement + " use: " + use.toString());
@@ -84,10 +81,10 @@ public class JSONManipulator {
wrapper.add("hoverEvent", hover);
itemTooltip = wrapper; // Save the tooltip for later use when we encounter a placeholder
STACKS.put(p, itemTooltip); // Save it in the cache too so when parsing other packets with the same item
STACKS.put(item, itemTooltip); // Save it in the cache too so when parsing other packets with the same item
// (and client version) we no longer have to create it again
// We remove it later when no longer needed to save memory
Bukkit.getScheduler().runTaskLaterAsynchronously(ChatItem.getInstance(), () -> STACKS.remove(p), 100L);
Bukkit.getScheduler().runTaskLaterAsynchronously(ChatItem.getInstance(), () -> STACKS.remove(item), 100L);
}
if (obj.size() == 1 && obj.has("text")) {
itemTooltip.add("text", obj.get("text"));
@@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
@@ -140,8 +141,9 @@ public class ChatPacketManager extends PacketHandler {
if (getStorage().cooldown > 0 && !itemPlayer.hasPermission("chatitem.ignore-cooldown"))
ChatManager.applyCooldown(itemPlayer);
IComponentManager getter = choosedGetter;
String fjson = json;
e.setCancelled(true); // We cancel the packet as we're going to resends it anyways
Bukkit.getScheduler().runTaskAsynchronously(ChatItem.getInstance(), () -> {
CompletableFuture.runAsync(() -> {
Player p = e.getPlayer();
String message = null;
try {
@@ -185,10 +187,10 @@ public class ChatPacketManager extends PacketHandler {
copy.setItemMeta(bsm);
}
}
lastSentPacket = getter.manageItem(p, chat, e, item, getStorage());
lastSentPacket = getter.manageItem(p, chat, e, item, fjson, getStorage());
} else {
if (!getStorage().handDisabled) {
lastSentPacket = getter.manageEmpty(p, chat, e, getStorage());
lastSentPacket = getter.manageEmpty(p, chat, e, fjson, getStorage());
}
}
if (lastSentPacket == null)
@@ -158,7 +158,7 @@ public class ChatListener implements Listener {
&& color != null && color != ChatColor.WHITE) {
text = text.substring(2); // remove some code which should not be here
}
appendToComponentBuilder(builder, createComponent(text, color));
appendToComponentBuilder(builder, createComponent(to, text, color));
text = "";
}
waiting = true; // waiting for color code
@@ -194,7 +194,7 @@ public class ChatListener implements Listener {
}
if (args == ChatManager.SEPARATOR) {
// here put the item
appendToComponentBuilder(builder, fixColorComponent(text, color));
appendToComponentBuilder(builder, fixColorComponent(to, text, color));
addItem(builder, to, origin, item);
text = "";
if(ChatManager.containsSeparatorEnd(msg))
@@ -208,7 +208,7 @@ public class ChatListener implements Listener {
}
}
if (!text.isEmpty())
appendToComponentBuilder(builder, createComponent(text, color));
appendToComponentBuilder(builder, createComponent(to, text, color));
to.spigot().sendMessage(builder.create());
}
@@ -216,7 +216,7 @@ public class ChatListener implements Listener {
Storage c = ChatItem.getInstance().getStorage();
if (!ItemUtils.isEmpty(item)) {
ComponentBuilder itemComponent = new ComponentBuilder("");
appendToComponentBuilder(itemComponent, fixColorComponent(ChatManager.getNameOfItem(to, item, c), ChatColor.WHITE, item));
appendToComponentBuilder(itemComponent, fixColorComponent(to, ChatManager.getNameOfItem(to, item, c), ChatColor.WHITE, item));
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());
@@ -266,11 +266,11 @@ public class ChatListener implements Listener {
}
}
public static BaseComponent[] fixColorComponent(String message, ChatColor color) {
return fixColorComponent(message, color, null);
public static BaseComponent[] fixColorComponent(Player to, String message, ChatColor color) {
return fixColorComponent(to, message, color, null);
}
public static BaseComponent[] fixColorComponent(String message, ChatColor color, @Nullable ItemStack item) {
public static BaseComponent[] fixColorComponent(Player to, String message, ChatColor color, @Nullable ItemStack item) {
ComponentBuilder builder = new ComponentBuilder("");
String colorCode = "", text = "";
boolean waiting = false;
@@ -278,7 +278,7 @@ public class ChatListener implements Listener {
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(ColorManager.isHexColor(color) ? ColorManager.removeColorAtBegin(text) : text, color, item));
appendToComponentBuilder(builder, createComponent(to, ColorManager.isHexColor(color) ? ColorManager.removeColorAtBegin(text) : text, color, item));
text = "";
}
waiting = true; // waiting for color code
@@ -317,21 +317,21 @@ public class ChatListener implements Listener {
}
}
if (!text.isEmpty()) {
appendToComponentBuilder(builder, createComponent(text, color, item));
appendToComponentBuilder(builder, createComponent(to, text, color, item));
}
return builder.create();
}
private static BaseComponent[] createComponent(String text, ChatColor color) {
return createComponent(text, color, null);
private static BaseComponent[] createComponent(Player to, String text, ChatColor color) {
return createComponent(to, text, color, null);
}
private static BaseComponent[] createComponent(String text, ChatColor color, ItemStack item) {
private static BaseComponent[] createComponent(Player to, String text, ChatColor color, ItemStack item) {
ComponentBuilder littleBuilder = new ComponentBuilder(text);
if(color != null && color != ChatColor.RESET) // don't add reset thing
littleBuilder.color(color);
if (item != null) // add to all possible sub parts
littleBuilder.event(Utils.createItemHover(item));
littleBuilder.event(Utils.createItemHover(item, to));
return littleBuilder.create();
}
}
@@ -42,7 +42,7 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
InventoryListener.open(p);
} else if (args[0].equalsIgnoreCase("reload") && p.hasPermission("chatitem.reload")) {
ChatItem.reload(sender);
} else if (args[0].equalsIgnoreCase("show")) {
} else if (args[0].equalsIgnoreCase("show") && ChatItem.getInstance().getStorage().cmdShow) {
Player cible = args.length == 1 ? p : Bukkit.getPlayer(args[1]);
if(cible == null) {
Messages.sendMessage(p, "player-not-found", "%arg%", args[1]);
@@ -51,7 +51,7 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
Storage c = ChatItem.getInstance().getStorage();
ItemStack item = ChatManager.getUsableItem(cible);
ChatListener.showItem(p, cible, item, c.commandFormat.replace("%name%", cible.getName()).replace("%item%", ChatManager.SEPARATOR + ""));
} else if (args[0].equalsIgnoreCase("broadcast")) {
} else if (args[0].equalsIgnoreCase("broadcast") && ChatItem.getInstance().getStorage().cmdBroadcast) {
Player cible = args.length == 1 ? p : Bukkit.getPlayer(args[1]);
if(cible == null) {
Messages.sendMessage(p, "player-not-found", "%arg%", args[1]);
@@ -77,7 +77,7 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
text.addExtra(linkComp);
}
p.spigot().sendMessage(text);
} else if (args[0].equalsIgnoreCase("select")) {
} 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.");
@@ -141,7 +141,16 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
List<String> list = new ArrayList<>();
String prefix = arg[arg.length - 1].toLowerCase(Locale.ROOT);
if(arg.length <= 2) {
for (String s : Arrays.asList("help", "admin", "reload", "link", "show", "broadcast", "select"))
if(sender.hasPermission("chatitem.reload")) {
for (String s : Arrays.asList("admin", "reload", "select"))
if (prefix.isEmpty() || s.startsWith(prefix))
list.add(s);
}
if (ChatItem.getInstance().getStorage().cmdShow && (prefix.isEmpty() || "show".startsWith(prefix)))
list.add("show");
if (ChatItem.getInstance().getStorage().cmdBroadcast && (prefix.isEmpty() || "broadcast".startsWith(prefix)))
list.add("broadcast");
for (String s : Arrays.asList("help", "link"))
if (prefix.isEmpty() || s.startsWith(prefix))
list.add(s);
}
@@ -1,15 +1,18 @@
package me.dadus33.chatitem.hook;
import org.mineacademy.chatcontrol.settings.Settings;
import me.dadus33.chatitem.ChatItem;
public class ChatControlSupport {
public static void init(ChatItem pl) {
Settings.Chat.Grammar.CAPITALIZE = false;
Settings.Chat.Grammar.INSERT_DOT = false;
try {
Class<?> clz = Class.forName("org.mineacademy.chatcontrol.settings.Settings$Chat$Grammar");
clz.getField("CAPITALIZE").setBoolean(null, false);
clz.getField("INSERT_DOT").setBoolean(null, false);
pl.getLogger().info("Loaded ChatControl support by disabling 2 options in 'Chat.Grammar' config.");
} catch (Exception e) {
e.printStackTrace();
}
pl.getLogger().info("Loaded ChatControl support by disabling 2 options in 'Chat.Grammar' config.");
}
}
@@ -13,14 +13,13 @@ 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 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;
/**
* This Map is to reduce Reflection action which take more resources than just
* RAM action
@@ -29,8 +28,7 @@ public class PacketUtils {
static {
IS_THERMOS = isClassExist("thermos.Thermos");
NMS_PREFIX = Version.getVersion().isNewerOrEquals(Version.V1_17) || IS_THERMOS ? "net.minecraft."
: "net.minecraft.server." + VERSION + ".";
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");
COMPONENT_CLASS = getNmsClass("IChatBaseComponent", "network.chat.");
@@ -40,14 +38,12 @@ public class PacketUtils {
/**
* Get the Class in NMS, with a processing reducer
*
* @param name of the NMS class (in net.minecraft.server package ONLY, because
* it's NMS)
* @param name of the NMS class (in net.minecraft.server package ONLY, because it's NMS)
* @return clazz the searched class
*/
public static Class<?> getNmsClass(String name, String packagePrefix, String... alias) {
return ALL_CLASS.computeIfAbsent(name, (a) -> {
String fullPrefix = NMS_PREFIX
+ (Version.getVersion().isNewerOrEquals(Version.V1_17) || IS_THERMOS ? packagePrefix : "");
String fullPrefix = NMS_PREFIX + (Version.getVersion().isNewerOrEquals(Version.V1_17) || IS_THERMOS ? packagePrefix : "");
try {
Class<?> clazz = Class.forName(fullPrefix + name);
if (clazz != null)
@@ -169,9 +165,7 @@ 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."))
playerConnection.getClass().getMethod(Version.getVersion().isNewerOrEquals(Version.V1_18) ? "a" : "sendPacket", getNmsClass("Packet", "network.protocol."))
.invoke(playerConnection, packet);
} catch (Exception e) {
e.printStackTrace();
@@ -179,7 +173,7 @@ public class PacketUtils {
}
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.
@@ -189,18 +183,18 @@ public class PacketUtils {
*/
public static String getNbtTag(ItemStack item) {
try {
if(getNbtMethod == null) {
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))
getNbtMethod = itemClass.getDeclaredMethod("w");
else if(v.equals(Version.V1_19))
else if (v.equals(Version.V1_19))
getNbtMethod = itemClass.getDeclaredMethod("u");
else if(v.equals(Version.V1_18))
else if (v.equals(Version.V1_18))
getNbtMethod = itemClass.getDeclaredMethod("t");
else
getNbtMethod = itemClass.getDeclaredMethod("getTag");
getNbtMethod.setAccessible(true);
}
Object tag = getNbtMethod.invoke(JSONManipulator.AS_NMS_COPY.invoke(null, item));
@@ -210,7 +204,7 @@ public class PacketUtils {
}
return "{}";
}
private static Method getMethod(String name, Class<?> clazz, Class<?>... params) {
try {
return clazz.getDeclaredMethod(name, params);
@@ -24,7 +24,9 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import me.dadus33.chatitem.ChatItem;
import me.dadus33.chatitem.chatmanager.ChatManager;
import me.dadus33.chatitem.chatmanager.v1.json.JSONManipulator;
import me.dadus33.chatitem.playerversion.PlayerVersionManager;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
@@ -156,8 +158,18 @@ public class Utils {
return b;
}
public static boolean isBeforeChatJson(Player p) {
return !PlayerVersionManager.getPlayerVersionAdapter().getPlayerVersion(p).isNewerOrEquals(Version.V1_16) && Version.getVersion().isNewerOrEquals(Version.V1_16);
}
@SuppressWarnings("deprecation")
public static HoverEvent createItemHover(ItemStack item) {
public static HoverEvent createItemHover(ItemStack item, Player to) {
if(isBeforeChatJson(to)) {
ComponentBuilder comp = new ComponentBuilder("");
for(String line : ChatManager.getMaxLinesFromItem(to, item))
comp.append(line + "\n");
return createTextHover(comp.create());
}
if(Version.getVersion().isNewerOrEquals(Version.V1_13)) {
return new HoverEvent(HoverEvent.Action.SHOW_ITEM, new Item(item.getType().getKey().getKey(), item.getAmount(), ItemTag.ofNbt(PacketUtils.getNbtTag(item))));
} else {
+3
View File
@@ -93,6 +93,9 @@ general:
# Check if the plugin have update
check-update: true
language: "en_gb"
sub-commands:
broadcast: true
show: true
# Messages section. You can disable any of them by simply leaving them empty, like this: ""
+1
View File
@@ -5,6 +5,7 @@ version: ${project.version}
softdepend: [ViaVersion, ProtocolSupport, ProtocolLib, LangUtils, HexNicks, EcoEnchants, DiscordSRV, ChatControl, ChatManager]
authors: [dadus33, WOLFI3654, Elikill58]
api-version: 1.13
folia-supported: true
commands:
cireload: