Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e75e04e47 | ||
|
|
3c2d092200 | ||
|
|
b1dac86e96 | ||
|
|
4b0c8ef6ff | ||
|
|
02e53a9dd6 | ||
|
|
37f6051794 | ||
|
|
6280cb211b | ||
|
|
6e7554e0a4 |
No files matched your search
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.dadus33</groupId>
|
||||
<artifactId>ChatItem</artifactId>
|
||||
<version>2.6.2</version>
|
||||
<version>2.6.3-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -75,13 +75,6 @@
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>minecraft-server</artifactId>
|
||||
<version>1.7.10</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
@@ -103,7 +96,7 @@
|
||||
<dependency>
|
||||
<groupId>com.viaversion</groupId>
|
||||
<artifactId>viaversion-api</artifactId>
|
||||
<version>5.0.3</version>
|
||||
<version>5.2.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ItemPlayer {
|
||||
}
|
||||
|
||||
public boolean isBuggedClient() {
|
||||
return (getVersion().equals(Version.V1_7) && getClientName().toLowerCase().contains("lunarclient")) || (!getVersion().isNewerOrEquals(Version.V1_15) && Version.getVersion().isNewerOrEquals(Version.V1_16));
|
||||
return (!getVersion().isNewerOrEquals(Version.V1_15) && Version.getVersion().isNewerOrEquals(Version.V1_16));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,28 +3,32 @@ package me.dadus33.chatitem;
|
||||
import java.util.List;
|
||||
|
||||
import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.utils.Colors;
|
||||
|
||||
public enum ItemSlot {
|
||||
|
||||
HAND(true, "", false),
|
||||
HELMET(false, "helmet", false),
|
||||
CHESTPLATE(false, "chestplate", false),
|
||||
LEGGINGS(false, "leggings", false),
|
||||
BOOTS(false, "boots", false),
|
||||
INVENTORY(false, "inventory", true),
|
||||
ENDERCHEST(false, "enderchest", true);
|
||||
HAND("", false),
|
||||
HELMET("helmet", false),
|
||||
CHESTPLATE("chestplate", false),
|
||||
LEGGINGS("leggings", false),
|
||||
BOOTS("boots", false),
|
||||
INVENTORY("inventory", true),
|
||||
ENDERCHEST("enderchest", true);
|
||||
|
||||
private final boolean basic, command;
|
||||
private final boolean command;
|
||||
private final String key;
|
||||
|
||||
private ItemSlot(boolean basic, String key, boolean command) {
|
||||
this.basic = basic;
|
||||
private ItemSlot(String key, boolean command) {
|
||||
this.command = command;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public boolean isBasic() {
|
||||
return basic;
|
||||
return key.equalsIgnoreCase("");
|
||||
}
|
||||
|
||||
public boolean isCommand() {
|
||||
@@ -32,15 +36,19 @@ public enum ItemSlot {
|
||||
}
|
||||
|
||||
public List<String> getPlaceholders() {
|
||||
return ChatItem.getInstance().getConfig().getStringList(basic ? "general.placeholders" : "general.other-placeholders." + key + ".keys");
|
||||
return ChatItem.getInstance().getConfig().getStringList(isBasic() ? "general.placeholders" : "general.other-placeholders." + key + ".keys");
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return basic || ChatItem.getInstance().getConfig().getBoolean("general.other-placeholders." + key + ".enabled", true);
|
||||
return isBasic() || ChatItem.getInstance().getConfig().getBoolean("general.other-placeholders." + key + ".enabled", true);
|
||||
}
|
||||
|
||||
public boolean isDenyIfNoItem() {
|
||||
return ChatItem.getInstance().getConfig().getBoolean("general" + (basic ? "" : ".other-placeholders." + key) + ".deny-if-no-item", true);
|
||||
return ChatItem.getInstance().getConfig().getBoolean("general" + (isBasic() ? "" : ".other-placeholders." + key) + ".deny-if-no-item", true);
|
||||
}
|
||||
|
||||
public String getShowMessage() {
|
||||
return Colors.color(ChatItem.getInstance().getConfig().getString("general" + (isBasic() ? "" : ".other-placeholders." + key) + ".show", ""));
|
||||
}
|
||||
|
||||
public boolean hasPlaceholders(String message) {
|
||||
@@ -66,4 +74,13 @@ public enum ItemSlot {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemSlot getItemSlotByKey(String key) {
|
||||
for(ItemSlot slot : ItemSlot.values()) {
|
||||
if(slot.isEnabled() && slot.getKey().equalsIgnoreCase(key)) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -51,4 +51,9 @@ public class ChatAction {
|
||||
public ItemStack getItem() {
|
||||
return item == null ? new ItemStack(Material.AIR) : item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ChatAction[slot=" + slot + ",command=" + command + ",item=" + item + ",origin=" + origin + "]";
|
||||
}
|
||||
}
|
||||
@@ -379,8 +379,7 @@ public abstract class ChatManager {
|
||||
if (selected == "auto") {
|
||||
if (Utils.IS_PAPER && actual == "paper")
|
||||
return true;
|
||||
else if (actual == "packet" && ChatItem.getPluginThatRequirePacket().stream().map(Bukkit.getPluginManager()::getPlugin).anyMatch(Objects::nonNull)
|
||||
&& Version.getVersion().isNewerThan(Version.V1_7))
|
||||
else if (actual == "packet" && ChatItem.getPluginThatRequirePacket().stream().map(Bukkit.getPluginManager()::getPlugin).anyMatch(Objects::nonNull))
|
||||
return true;
|
||||
else if (actual == "chat")
|
||||
return true;
|
||||
|
||||
@@ -68,7 +68,9 @@ public class JSONManipulator {
|
||||
|
||||
// Get the JSON representation of the item (well, not really JSON, but rather a
|
||||
// string representation of NBT data)
|
||||
hover.addProperty("value", ChatItem.getPlatform().stringifyItem(action.getItem()));
|
||||
String item = ChatItem.getPlatform().stringifyItem(action.getItem());
|
||||
hover.addProperty("value", item);
|
||||
hover.add("contents", parseOrGet(item));
|
||||
} else {
|
||||
hover.addProperty("action", "show_text");
|
||||
|
||||
|
||||
-3
@@ -14,7 +14,6 @@ import me.dadus33.chatitem.chatmanager.v1.packets.PacketManager;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.custom.channel.ChannelAbstract;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.custom.channel.INC2Channel;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.custom.channel.INCChannel;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.custom.channel.NMUChannel;
|
||||
import me.dadus33.chatitem.utils.Utils;
|
||||
import me.dadus33.chatitem.utils.Version;
|
||||
|
||||
@@ -30,8 +29,6 @@ public class CustomPacketManager extends PacketManager implements Listener {
|
||||
Version version = Version.getVersion();
|
||||
if (version.isNewerOrEquals(Version.V1_17))
|
||||
channel = new INC2Channel(this);
|
||||
else if (version.equals(Version.V1_7))
|
||||
channel = new NMUChannel(this);
|
||||
else
|
||||
channel = new INCChannel(this);
|
||||
pl.getServer().getPluginManager().registerEvents(this, pl);
|
||||
|
||||
-166
@@ -1,166 +0,0 @@
|
||||
package me.dadus33.chatitem.chatmanager.v1.packets.custom.channel;
|
||||
|
||||
import static me.dadus33.chatitem.utils.PacketUtils.getPlayerConnection;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.ChatItemPacket;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketContent;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.PacketType;
|
||||
import me.dadus33.chatitem.chatmanager.v1.packets.custom.CustomPacketManager;
|
||||
import me.dadus33.chatitem.utils.PacketUtils;
|
||||
import me.dadus33.chatitem.utils.ReflectionUtils;
|
||||
import net.minecraft.util.io.netty.channel.Channel;
|
||||
import net.minecraft.util.io.netty.channel.ChannelFuture;
|
||||
import net.minecraft.util.io.netty.channel.ChannelHandler;
|
||||
import net.minecraft.util.io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.util.io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import net.minecraft.util.io.netty.channel.ChannelInitializer;
|
||||
import net.minecraft.util.io.netty.channel.ChannelOutboundHandlerAdapter;
|
||||
import net.minecraft.util.io.netty.channel.ChannelPipeline;
|
||||
import net.minecraft.util.io.netty.channel.ChannelPromise;
|
||||
|
||||
public class NMUChannel extends ChannelAbstract {
|
||||
|
||||
private ChannelInboundHandlerAdapter boundHandler;
|
||||
private ChannelPipeline pipeline;
|
||||
|
||||
public NMUChannel(CustomPacketManager customPacketManager) {
|
||||
super(customPacketManager);
|
||||
try {
|
||||
Object dedicatedSrv = PacketUtils.getCraftServer();
|
||||
Object mcServer = dedicatedSrv.getClass().getMethod("getServer").invoke(dedicatedSrv);
|
||||
Object co = ReflectionUtils.getFirstWith(mcServer, PacketUtils.getNmsClass("MinecraftServer", "server."), PacketUtils.getNmsClass("ServerConnection", "network."));
|
||||
List<ChannelFuture> g = (List<ChannelFuture>) ReflectionUtils.getObject(co, "g", "e");
|
||||
g.forEach((channelFuture) -> {
|
||||
pipeline = channelFuture.channel().pipeline();
|
||||
pipeline.addFirst(boundHandler = new ChannelInboundHandlerAdapter() {
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
((Channel) msg).pipeline().addFirst(new ChannelInitializer<Channel>() {
|
||||
@Override
|
||||
protected void initChannel(Channel channel) {
|
||||
try {
|
||||
channel.eventLoop().submit(() -> {
|
||||
try {
|
||||
ChannelHandler interceptor = channel.pipeline().get(KEY_HANDSHAKE);
|
||||
// Inject our packet interceptor
|
||||
if (interceptor == null) {
|
||||
interceptor = new ChannelHandlerHandshakeReceive(channel);
|
||||
channel.pipeline().addBefore("packet_handler", KEY_HANDSHAKE, interceptor);
|
||||
}
|
||||
return interceptor;
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Try again
|
||||
return channel.pipeline().get(KEY_HANDSHAKE);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
getPacketManager().getPlugin().getLogger().log(Level.SEVERE, "Cannot inject incomming channel " + channel, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
ctx.fireChannelRead(msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void stopPipelines() {
|
||||
pipeline.remove(boundHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChannel(final Player player, String endChannelName) {
|
||||
getOrCreateAddChannelExecutor().execute(() -> {
|
||||
try {
|
||||
Channel channel = getChannel(player);
|
||||
// Managing outgoing packet (to the player)
|
||||
channel.pipeline().addAfter(KEY_HANDLER_SERVER, KEY_SERVER + endChannelName, new ChannelHandlerSent(player));
|
||||
} catch (NoSuchElementException e) {
|
||||
// appear when the player's channel isn't accessible because of reload.
|
||||
getPacketManager().getPlugin().getLogger().warning("Please, don't use reload, this can produce some problem. Currently, " + player.getName() + " isn't fully checked because of that. More details: " + e.getMessage() + " (NoSuchElementException)");
|
||||
} catch (IllegalArgumentException e) {
|
||||
if(e.getMessage().contains("Duplicate")) {
|
||||
removeChannel(player, endChannelName);
|
||||
addChannel(player, endChannelName);
|
||||
} else
|
||||
getPacketManager().getPlugin().getLogger().severe("Error while loading Packet channel. " + e.getMessage() + ". Please, prefer restart than reload.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChannel(Player player, String endChannelName) {
|
||||
getOrCreateRemoveChannelExecutor().execute(() -> {
|
||||
try {
|
||||
final Channel channel = getChannel(player);
|
||||
if(channel.pipeline().get(KEY_SERVER + endChannelName) != null)
|
||||
channel.pipeline().remove(KEY_SERVER + endChannelName);
|
||||
} catch (Exception e) {}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Channel getChannel(Player p) throws Exception {
|
||||
Object playerConnection = getPlayerConnection(p);
|
||||
Object networkManager = playerConnection.getClass().getField("networkManager").get(playerConnection);
|
||||
|
||||
for (Field field : networkManager.getClass().getDeclaredFields())
|
||||
if (field.getType().equals(Channel.class)) {
|
||||
field.setAccessible(true);
|
||||
return (Channel) field.get(networkManager);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private class ChannelHandlerSent extends ChannelOutboundHandlerAdapter {
|
||||
|
||||
private final Player owner;
|
||||
|
||||
public ChannelHandlerSent(Player player) {
|
||||
this.owner = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
|
||||
ChatItemPacket nextPacket = getPacketManager().onPacketSent(PacketType.getType(packet.getClass().getSimpleName()), owner, packet);
|
||||
if(nextPacket != null && nextPacket.isCancelled())
|
||||
return;
|
||||
super.write(ctx, nextPacket == null ? packet : nextPacket.getPacket(), promise);
|
||||
}
|
||||
}
|
||||
|
||||
private class ChannelHandlerHandshakeReceive extends ChannelInboundHandlerAdapter {
|
||||
|
||||
private final Channel channel;
|
||||
|
||||
public ChannelHandlerHandshakeReceive(Channel channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object packet) {
|
||||
try {
|
||||
PacketType packetType = PacketType.getType(packet.getClass().getSimpleName());
|
||||
if(packetType != null && packetType == PacketType.Handshake.IS_SET_PROTOCOL) {
|
||||
getPacketManager().protocolVersionPerChannel.put(channel, new PacketContent(packet).getIntegers().readSafely(1, 0));
|
||||
}
|
||||
super.channelRead(ctx, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package me.dadus33.chatitem.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -12,7 +13,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
import me.dadus33.chatitem.ItemSlot;
|
||||
@@ -22,6 +22,7 @@ import me.dadus33.chatitem.chatmanager.ChatManager;
|
||||
import me.dadus33.chatitem.invsee.InvShower;
|
||||
import me.dadus33.chatitem.listeners.InventoryListener;
|
||||
import me.dadus33.chatitem.utils.Colors;
|
||||
import me.dadus33.chatitem.utils.ItemUtils;
|
||||
import me.dadus33.chatitem.utils.Messages;
|
||||
import me.dadus33.chatitem.utils.Utils;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
@@ -52,25 +53,14 @@ 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("ec") && ChatItem.getInstance().getStorage().cmdShow) {
|
||||
sendCommandFormatFrom(p, ItemSlot.ENDERCHEST, Bukkit.getOnlinePlayers());
|
||||
} else if (args[0].equalsIgnoreCase("inv") && ChatItem.getInstance().getStorage().cmdShow) {
|
||||
sendCommandFormatFrom(p, ItemSlot.INVENTORY, Bukkit.getOnlinePlayers());
|
||||
} 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]);
|
||||
return false;
|
||||
}
|
||||
Storage c = ChatItem.getInstance().getStorage();
|
||||
ItemStack item = ChatManager.getUsableItem(cible, ItemSlot.HAND);
|
||||
ChatItem.getPlatform().sendMessage(p, cible, new ChatAction(ItemSlot.HAND, cible, item), c.commandFormat.replace("%name%", cible.getName()).replace("%item%", ChatManager.SEPARATOR + ""));
|
||||
sendCommandFormatFrom(p, ItemSlot.getItemSlotByKey(args.length <= 1 ? "" : args[1]), Arrays.asList(p));
|
||||
} 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]);
|
||||
return false;
|
||||
}
|
||||
Storage c = ChatItem.getInstance().getStorage();
|
||||
ItemStack item = ChatManager.getUsableItem(cible, ItemSlot.HAND);
|
||||
for(Player all : Bukkit.getOnlinePlayers())
|
||||
ChatItem.getPlatform().sendMessage(all, cible, new ChatAction(ItemSlot.HAND, cible, item), c.commandFormat.replace("%name%", cible.getName()).replace("%item%", ChatManager.SEPARATOR + ""));
|
||||
sendCommandFormatFrom(p, ItemSlot.getItemSlotByKey(args.length <= 1 ? "" : args[1]), Bukkit.getOnlinePlayers());
|
||||
} else if (args[0].equalsIgnoreCase("link") || args[0].equalsIgnoreCase("links")) {
|
||||
ConfigurationSection config = ChatItem.getInstance().getConfig()
|
||||
.getConfigurationSection("messages.chatitem-cmd.links");
|
||||
@@ -135,6 +125,21 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void sendCommandFormatFrom(Player p, ItemSlot slot, Collection<? extends Player> receivers) {
|
||||
if(slot == null) {
|
||||
Messages.sendMessage(p, "chatitem-cmd.help");
|
||||
return;
|
||||
}
|
||||
ChatAction action = ChatManager.getChatAction(slot, p);
|
||||
ChatItem.debug("Action: " + action);
|
||||
if(action.isItem() && ItemUtils.isEmpty(action.getItem())) {
|
||||
Messages.sendMessage(p, "empty-item");
|
||||
return;
|
||||
}
|
||||
for(Player all : receivers)
|
||||
ChatItem.getPlatform().sendMessage(all, p, action, slot.getShowMessage().replace("%name%", p.getName()).replace("%item%", ChatManager.SEPARATOR + ""));
|
||||
}
|
||||
|
||||
private void sendCheckSelectMessage(Player p, String testing) {
|
||||
ChatManager.setTesting(testing);
|
||||
p.chat("Checking for " + testing + ": [i]");
|
||||
@@ -145,7 +150,7 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
|
||||
agree.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/chatitem select " + testing + " yes"));
|
||||
agree.setHoverEvent(Utils.createTextHover(Colors.GRAY + "Click to say it worked fine"));
|
||||
text.addExtra(agree);
|
||||
text.addExtra(" ");
|
||||
text.addExtra(", ");
|
||||
TextComponent decline = new TextComponent(Colors.RED + "No");
|
||||
decline.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/chatitem select " + testing + " no"));
|
||||
decline.setHoverEvent(Utils.createTextHover(Colors.GRAY + "Click to say it's not working as expected"));
|
||||
@@ -160,19 +165,26 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] arg) {
|
||||
List<String> list = new ArrayList<>();
|
||||
String prefix = arg[arg.length - 1].toLowerCase(Locale.ROOT);
|
||||
if(arg.length <= 2) {
|
||||
if(arg.length <= 1) {
|
||||
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().cmdShow) {
|
||||
for (String s : Arrays.asList("show", "ec", "inv"))
|
||||
if (prefix.isEmpty() || s.startsWith(prefix))
|
||||
list.add(s);
|
||||
}
|
||||
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);
|
||||
} else if(arg[0].equalsIgnoreCase("show") || arg[0].equalsIgnoreCase("broadcast")) {
|
||||
for (ItemSlot slot : ItemSlot.values())
|
||||
if (prefix.isEmpty() || slot.getKey().startsWith(prefix))
|
||||
list.add(slot.getKey());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class NamerManager {
|
||||
continue;
|
||||
for(INamer namer : allNamers) {
|
||||
String tmpName = namer.getName(p, item, storage);
|
||||
if(tmpName != null) {
|
||||
if(tmpName != null && tmpName != "") {
|
||||
ChatItem.debug("Using namer " + namer.getClass().getSimpleName() + ", value: " + tmpName);
|
||||
return tmpName;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public class ChatItemTranslationNamer implements INamer {
|
||||
|
||||
@Override
|
||||
public Priority getPriority() {
|
||||
return Priority.MINOR;
|
||||
return Priority.SMALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,7 @@ public class DefaultNamer implements INamer {
|
||||
|
||||
@Override
|
||||
public Priority getPriority() {
|
||||
return Priority.SMALL;
|
||||
return Priority.MINOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,10 +30,8 @@ public class InventoryListener implements Listener {
|
||||
return;
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
|
||||
InventoryHolder openInventoryHolder = null;
|
||||
try {
|
||||
openInventoryHolder = p.getOpenInventory().getTopInventory().getHolder();
|
||||
} catch(java.lang.IncompatibleClassChangeError exc) {} // ignore this
|
||||
Inventory topInventory = Utils.getTopInventory(e);
|
||||
InventoryHolder openInventoryHolder = topInventory == null ? null : topInventory.getHolder();
|
||||
|
||||
if (openInventoryHolder != null && openInventoryHolder instanceof CustomInventoryHolder) {
|
||||
e.setCancelled(true);
|
||||
@@ -44,9 +42,8 @@ public class InventoryListener implements Listener {
|
||||
|
||||
InventoryHolder holder = e.getClickedInventory().getHolder();
|
||||
if (holder == null || !(holder instanceof ChatItemHolder)) {
|
||||
if (e.getClick().equals(ClickType.DOUBLE_CLICK) && p.getOpenInventory() != null && p.getOpenInventory().getTopInventory() != null) {
|
||||
Inventory top = p.getOpenInventory().getTopInventory();
|
||||
if (top.getHolder() != null && top.getHolder() instanceof ChatItemHolder) {
|
||||
if (e.getClick().equals(ClickType.DOUBLE_CLICK) && topInventory != null) {
|
||||
if (openInventoryHolder != null && openInventoryHolder instanceof ChatItemHolder) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,12 +44,10 @@ public class ItemUtils {
|
||||
}
|
||||
|
||||
public static ItemStack hideAttributes(ItemStack stack) {
|
||||
if (Version.getVersion().isNewerThan(Version.V1_7)) {
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
// All ItemFlags are used to hide attributes, their javadoc says so too.
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
// All ItemFlags are used to hide attributes, their javadoc says so too.
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.ConnectException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
@@ -23,6 +25,8 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.dadus33.chatitem.ChatItem;
|
||||
@@ -272,4 +276,26 @@ public class Utils {
|
||||
public static String cleanStr(String s) {
|
||||
return s.startsWith("'") && s.endsWith("'") ? s.substring(1, s.length() - 1) : s;
|
||||
}
|
||||
|
||||
/**
|
||||
* In API versions 1.20.6 and earlier, InventoryView is a class.
|
||||
* In versions 1.21 and later, it is an interface.
|
||||
* This method uses reflection to get the top Inventory object from the
|
||||
* InventoryView associated with an InventoryEvent, to avoid runtime errors.
|
||||
* @param event The generic InventoryEvent with an InventoryView to inspect.
|
||||
* @return The top Inventory object from the event's InventoryView.
|
||||
*/
|
||||
public static Inventory getTopInventory(InventoryEvent event) {
|
||||
try {
|
||||
Object view = event.getView();
|
||||
if(view == null)
|
||||
return null;
|
||||
Method getTopInventory = view.getClass().getMethod("getTopInventory");
|
||||
getTopInventory.setAccessible(true);
|
||||
return (Inventory) getTopInventory.invoke(view);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import me.dadus33.chatitem.ChatItem;
|
||||
public enum Version {
|
||||
|
||||
// http://wiki.vg/Protocol_version_numbers
|
||||
V1_7(0, 5, 7),
|
||||
UNSUPPORTED(0, 5, 7),
|
||||
V1_8(6, 47, 8),
|
||||
V1_9(49, 110, 9), // 1.9.X - Starts with 49 as 48 was an april fools update
|
||||
V1_10(201, 210, 10), // 1.10.X - Starts with 201 because why not.
|
||||
|
||||
@@ -38,6 +38,7 @@ general:
|
||||
keys:
|
||||
- "[head]"
|
||||
- "{head}"
|
||||
show: "&6%name%'s helmet is %item%"
|
||||
# Show the CHESTPLATE not the enderchest or whatever
|
||||
chestplate:
|
||||
enabled: true
|
||||
@@ -45,6 +46,7 @@ general:
|
||||
keys:
|
||||
- "[chest]"
|
||||
- "{chest}"
|
||||
show: "&6%name%'s chestplate is %item%"
|
||||
# Show leggings
|
||||
leggings:
|
||||
enabled: true
|
||||
@@ -52,6 +54,7 @@ general:
|
||||
keys:
|
||||
- "[legs]"
|
||||
- "{legs}"
|
||||
show: "&6%name%'s leggings are %item%"
|
||||
# Show what is their feets
|
||||
boots:
|
||||
enabled: true
|
||||
@@ -59,6 +62,7 @@ general:
|
||||
keys:
|
||||
- "[feet]"
|
||||
- "{feet}"
|
||||
show: "&6%name%'s boots are %item%"
|
||||
inventory:
|
||||
enabled: true
|
||||
deny-if-no-item: true
|
||||
@@ -67,6 +71,7 @@ general:
|
||||
keys:
|
||||
- "[inv]"
|
||||
- "{inv}"
|
||||
show: "&6%name%'s inventory is %item%"
|
||||
enderchest:
|
||||
enabled: true
|
||||
deny-if-no-item: true
|
||||
@@ -75,6 +80,7 @@ general:
|
||||
keys:
|
||||
- "[ec]"
|
||||
- "{ec}"
|
||||
show: "&6%name%'s enderchest is %item%"
|
||||
|
||||
# The format of the item placeholders.
|
||||
name-format: "&b&l&o{name}{amount}&r"
|
||||
@@ -118,7 +124,7 @@ general:
|
||||
- "&7Failed to parse item for your client"
|
||||
|
||||
# Format used with using /chatitem show
|
||||
command-format: "&6%name%'s item is %item%"
|
||||
show: "&6%name%'s item is %item%"
|
||||
|
||||
# Here you can set when the players should see the no-permission message (defined in the 'Messages' section bellow).
|
||||
# 'normal' dictates whether the user should see the message when using the placeholder in normal chat, and 'command'
|
||||
@@ -145,8 +151,10 @@ general:
|
||||
sub-commands:
|
||||
broadcast: true
|
||||
show: true
|
||||
# This part of config is in WIP. Please ignore it.
|
||||
ownformatter:
|
||||
format: "%name%: %message%"
|
||||
# End of WIP config section.
|
||||
|
||||
|
||||
|
||||
@@ -155,6 +163,8 @@ messages:
|
||||
# The message sent if showing off hands is disabled and the user isn't holding an item.
|
||||
# Only works if 'General.deny-if-no-item' is set to true!
|
||||
deny-message: "&c&lYou have no item in hand!"
|
||||
# Send for some command to prevent wrong messages
|
||||
empty-item: "&cCan't show empty item"
|
||||
# The message sent after the configuration file is successfully reloaded.
|
||||
reload-success: "&b&lSuccessful reload!"
|
||||
# The message sent if the player is on cooldown from sending a placeholder.
|
||||
|
||||
Reference in new issue
Block a user