From 2883c5da212f71b099fe78cd0c2ed462771a829e Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Tue, 4 Dec 2018 14:01:11 +0800 Subject: [PATCH] Remove ProtocolSupport and update some method to use new Bukkit api. Former-commit-id: 2135b713790a6b29455b4b375464e360648a4929 [formerly 7a2489336543648bfc75cd3c6cedee7dfb6d4dbf] Former-commit-id: 4e51182973cbf5ce69127ab9a20841b850ba1035 --- .../org/maxgamer/quickshop/Command/QS.java | 183 ------------------ .../org/maxgamer/quickshop/QuickShop.java | 44 +---- .../org/maxgamer/quickshop/Util/MsgUtil.java | 120 +----------- .../quickshop/Util/SignMenuFactory.java | 101 ---------- .../org/maxgamer/quickshop/Util/Util.java | 36 +--- 5 files changed, 6 insertions(+), 478 deletions(-) delete mode 100644 src/main/java/org/maxgamer/quickshop/Util/SignMenuFactory.java diff --git a/src/main/java/org/maxgamer/quickshop/Command/QS.java b/src/main/java/org/maxgamer/quickshop/Command/QS.java index f4657ce0a..1712c18ae 100644 --- a/src/main/java/org/maxgamer/quickshop/Command/QS.java +++ b/src/main/java/org/maxgamer/quickshop/Command/QS.java @@ -40,8 +40,6 @@ import org.maxgamer.quickshop.Shop.ShopType; import org.maxgamer.quickshop.Util.MsgUtil; import org.maxgamer.quickshop.Util.Util; -import com.google.common.collect.Lists; - public class QS implements CommandExecutor { QuickShop plugin; public static HashMap> signPlayerCache = new HashMap<>(); @@ -50,151 +48,6 @@ public class QS implements CommandExecutor { this.plugin = plugin; } - public void signGUIApi(ArrayList data, String arg) { - - Shop shop = (Shop) data.get(0); - String type = (String) data.get(1); - Util.debugLog("GUI API"); - Player player = Bukkit.getPlayer(UUID.fromString(String.valueOf(data.get(2)))); - Util.debugLog(String.valueOf(data.size())); - switch (type) { - case "owner": - uiOwner(shop, arg, player); - break; - case "refill": - uiRefill(shop, arg, player); - break; - case "price": - uiPrice(shop, arg, player); - default: - break; - } - - } - - private void uiPrice(Shop shop, String arg, Player sender) { - if (sender.hasPermission("quickshop.create.changeprice")) { - Player p = (Player) sender; - double price; - try { - price = Double.parseDouble(arg); - } catch (NumberFormatException e) { - sender.sendMessage(MsgUtil.getMessage("thats-not-a-number")); - return; - } - if (price < 0.01) { - sender.sendMessage(MsgUtil.getMessage("price-too-cheap")); - return; - } - double fee = 0; - if (plugin.priceChangeRequiresFee) { - fee = plugin.getConfig().getDouble("shop.fee-for-price-change"); - if (fee > 0 && plugin.getEcon().getBalance(p.getUniqueId()) < fee) { - sender.sendMessage( - MsgUtil.getMessage("you-cant-afford-to-change-price", plugin.getEcon().format(fee))); - return; - } - } - if (shop != null && (shop.getOwner().equals(((Player) sender).getUniqueId()) - || sender.hasPermission("quickshop.other.price"))) { - if (shop.getPrice() == price) { - // Stop here if there isn't a price change - sender.sendMessage(MsgUtil.getMessage("no-price-change")); - return; - } - if (fee > 0) { - if (!plugin.getEcon().withdraw(p.getUniqueId(), fee)) { - sender.sendMessage( - MsgUtil.getMessage("you-cant-afford-to-change-price", plugin.getEcon().format(fee))); - return; - } - sender.sendMessage( - MsgUtil.getMessage("fee-charged-for-price-change", plugin.getEcon().format(fee))); - try { - for (OfflinePlayer player : Bukkit.getOfflinePlayers()) { - if (player.getName().equals(plugin.getConfig().getString("tax-account"))) { - plugin.getEcon().deposit(player.getUniqueId(), fee); - } - } - } catch (Exception e) { - e.getMessage(); - plugin.getLogger().log(Level.WARNING, - "QuickShop can't pay tax to account in config.yml,Please set tax account name to a exist player!"); - } - - } - // Update the shop - shop.setPrice(price); - shop.setSignText(); - shop.update(); - MsgUtil.sendControlPanelInfo(sender, shop); - sender.sendMessage(MsgUtil.getMessage("price-is-now", plugin.getEcon().format(shop.getPrice()))); - // Chest shops can be double shops. - if (shop instanceof ContainerShop) { - ContainerShop cs = (ContainerShop) shop; - if (cs.isDoubleShop()) { - Shop nextTo = cs.getAttachedShop(); - if (cs.isSelling()) { - if (cs.getPrice() < nextTo.getPrice()) { - sender.sendMessage(MsgUtil.getMessage("buying-more-than-selling")); - } - } else { - // Buying - if (cs.getPrice() > nextTo.getPrice()) { - sender.sendMessage(MsgUtil.getMessage("buying-more-than-selling")); - } - } - } - } - return; - } - } else { - sender.sendMessage(MsgUtil.getMessage("no-permission")); - return; - } - } - - private void uiRefill(Shop shop, String arg, Player player) { - if (player.hasPermission("quickshop.refill")) { - int add; - try { - add = Integer.parseInt(arg); - } catch (NumberFormatException e) { - player.sendMessage(MsgUtil.getMessage("thats-not-a-number")); - return; - } - if (shop != null) { - shop.add(shop.getItem(), add); - shop.setSignText(); - shop.update(); - MsgUtil.sendControlPanelInfo(player, shop); - player.sendMessage(MsgUtil.getMessage("refill-success")); - return; - } - } else { - player.sendMessage(MsgUtil.getMessage("no-permission")); - return; - } - - } - - private void uiOwner(Shop shop, String owner, Player player) { - if (player.hasPermission("quickshop.setowner")) { - if (shop != null) { - @SuppressWarnings("deprecation") - OfflinePlayer p = this.plugin.getServer().getOfflinePlayer(owner); - shop.setOwner(p.getUniqueId()); - shop.update(); - MsgUtil.sendControlPanelInfo(player, shop); - player.sendMessage(MsgUtil.getMessage("command.new-owner", - this.plugin.getServer().getOfflinePlayer(shop.getOwner()).getName())); - return; - } - } else { - player.sendMessage(MsgUtil.getMessage("no-permission")); - return; - } - } private void setUnlimited(CommandSender sender) { if (sender instanceof Player && sender.hasPermission("quickshop.unlimited")) { @@ -239,38 +92,6 @@ public class QS implements CommandExecutor { } } - private void sign(CommandSender sender, String[] args) { - Util.debugLog("sign"); - ShopManager manager = plugin.getShopManager(); - Shop shop = manager.getShop(new Location(Bukkit.getWorld(args[1]), Integer.valueOf(args[2]), - Integer.valueOf(args[3]), Integer.valueOf(args[4]))); - if (shop == null) { - Util.debugLog("shop null!"); - return; - } - Util.debugLog("remakeing data..."); - String[] texts = new String[4]; - String type = args[5]; - texts[0] = args[6]; - texts[1] = args[7]; - texts[2] = args[8]; - texts[3] = args[9]; - Util.debugLog("done"); - Util.debugLog("submiting data"); - ArrayList data = new ArrayList<>(); - data.add(shop); - data.add(type); - data.add(((Player) sender).getUniqueId()); - signPlayerCache.put(((Player) sender).getUniqueId(), data); - try { - Util.sendSignEditForGUI((Player) sender, texts); - QuickShop.signMenuFactory.newMenu((Player) sender, Lists.newArrayList(MsgUtil.getMessage(texts[0]), MsgUtil.getMessage(texts[1]), MsgUtil.getMessage(texts[2]), MsgUtil.getMessage(texts[3])), - (player, input) -> { - //signGUIApi(data, input[0]); - }); - } catch (Exception e) { - } - } private void remove(CommandSender sender, String[] args) { if (sender instanceof Player == false) { @@ -853,9 +674,6 @@ public class QS implements CommandExecutor { } else if (subArg.startsWith("amount")) { amount(sender, args); return true; - } else if (subArg.startsWith("sign")) { - sign(sender, args); - return true; } else if (subArg.startsWith("buy")) { setBuy(sender); return true; @@ -887,7 +705,6 @@ public class QS implements CommandExecutor { } else if (subArg.equals("clean")) { clean(sender); return true; - } else if (subArg.equals("reload")) { reload(sender); return true; diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 24179c5fc..1a675e258 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -1,12 +1,5 @@ package org.maxgamer.quickshop; -import com.comphenix.packetwrapper.WrapperPlayClientUpdateSign; -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLib; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.ProtocolManager; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketEvent; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.*; import org.bukkit.configuration.ConfigurationSection; @@ -28,7 +21,6 @@ import org.maxgamer.quickshop.Shop.Shop; import org.maxgamer.quickshop.Shop.ShopManager; import org.maxgamer.quickshop.Shop.ShopType; import org.maxgamer.quickshop.Util.MsgUtil; -import org.maxgamer.quickshop.Util.SignMenuFactory; import org.maxgamer.quickshop.Util.Util; import org.maxgamer.quickshop.Watcher.ItemWatcher; import org.maxgamer.quickshop.Watcher.LogWatcher; @@ -89,7 +81,6 @@ public class QuickShop extends JavaPlugin { /** The plugin OpenInv (null if not present) */ public Plugin openInvPlugin; - public static SignMenuFactory signMenuFactory; private HashMap limits = new HashMap(); /** Use SpoutPlugin to get item / block names */ public boolean useSpout = false; @@ -100,7 +91,6 @@ public class QuickShop extends JavaPlugin { private boolean noopDisable; private boolean setupDBonEnableding = false; public String dbPrefix=""; - public ProtocolLib protocolLibPlugin = null; private Plugin BKCommonLibPlugin; public int getShopLimit(Player p) { int max = getConfig().getInt("limits.default"); @@ -181,33 +171,6 @@ public class QuickShop extends JavaPlugin { getLogger().info("Successfully loaded BKCommonLib support!"); } } - if (getConfig().getBoolean("plugin.ProtocolLib")) { - if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) { - protocolLibPlugin = (ProtocolLib) Bukkit.getPluginManager().getPlugin("ProtocolLib"); - signMenuFactory = new SignMenuFactory(this); - getProtocolLib().addPacketListener(new PacketAdapter(this, PacketType.Play.Client.UPDATE_SIGN) { - @Override - public void onPacketReceiving(PacketEvent event) { - WrapperPlayClientUpdateSign wrapper = new WrapperPlayClientUpdateSign(event.getPacket()); - // BlockPosition blockPos = wrapper.getLocation(); - Util.debugLog("line:" + wrapper.getLines()[0]); - if (wrapper.getLines()[0] == null || wrapper.getLines()[0] == "") - return; - ArrayList data = QS.signPlayerCache.get(event.getPlayer().getUniqueId()); - new BukkitRunnable() { - @Override - public void run() { - QuickShop.instance.commandExecutor.signGUIApi(data, wrapper.getLines()[0]); - event.getPlayer().sendBlockChange(new Location(event.getPlayer().getWorld(),event.getPlayer().getLocation().getBlockX(), SignMenuFactory.POSITION_HEIGHT, event.getPlayer().getLocation().getBlockZ()), Material.AIR.createBlockData()); - } - }.runTask(QuickShop.instance); - - } - }); - getLogger().info("Successfully loaded ProtocolLib support!"); - } - } - if (getConfig().getInt("config-version") == 0) getConfig().set("config-version", 1); updateConfig(getConfig().getInt("config-version")); @@ -953,11 +916,6 @@ public class QuickShop extends JavaPlugin { public Database getDB() { return this.database; } - public ProtocolManager getProtocolLib() { - if(this.protocolLibPlugin==null) - return null; - return ProtocolLibrary.getProtocolManager(); - } /** * Returns the ShopManager. This is used for fetching, adding and removing @@ -977,7 +935,7 @@ public class QuickShop extends JavaPlugin { * @return Plugin Version */ public static String getVersion() { - return "Reremake "+QuickShop.instance.getDescription().getVersion(); + return QuickShop.instance.getDescription().getVersion(); } } diff --git a/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java b/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java index 4e256d6ba..c893ebbed 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java +++ b/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java @@ -128,7 +128,7 @@ public class MsgUtil { } } - public static void sendNormalControlPanelInfo(CommandSender sender, Shop shop) { + public static void sendControlPanelInfo(CommandSender sender, Shop shop) { if (!sender.hasPermission("quickshop.use")) { return; } @@ -239,124 +239,6 @@ public class MsgUtil { sender.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+"); } - - public static void sendControlPanelInfo(CommandSender sender, Shop shop) { - if (!sender.hasPermission("quickshop.use")) { - return; - } - if (plugin.protocolLibPlugin == null||!plugin.getConfig().getBoolean("plugin.ProtocolLib")) { - sendNormalControlPanelInfo(sender, shop); - return; - } - if (plugin.getConfig().getBoolean("sneak-to-control")) - if (sender instanceof Player) - if (!((Player) sender).isSneaking()) - return; - sender.sendMessage(""); - sender.sendMessage(""); - sender.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+"); - sender.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("controlpanel.infomation")); - // Owner - if (!sender.hasPermission("quickshop.setowner")) { - sender.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.owner", shop.ownerName())); - } else { - String Text = MsgUtil.getMessage("controlpanel.setowner", shop.ownerName()); - String hoverText = MsgUtil.getMessage("controlpanel.setowner-hover"); - String type = "owner"; - String clickCommand = "/qs sign " + shop.getLocation().getWorld().getName() + " " - + shop.getLocation().getBlockX() + " " + shop.getLocation().getBlockY() + " " - + shop.getLocation().getBlockZ() + " " + type + " " + "controlpanel.sign." + type + ".line1" + " " - + "controlpanel.sign." + type + ".line2" + " " + "controlpanel.sign." + type + ".line3" + " " - + "controlpanel.sign." + type + ".line4"; - MsgUtil.sendPanelMessage(sender, Text, hoverText, clickCommand); - } - // Unlimited - if (sender.hasPermission("quickshop.unlimited")) { - String Text = MsgUtil.getMessage("controlpanel.unlimited", bool2String(shop.isUnlimited())); - String hoverText = MsgUtil.getMessage("controlpanel.unlimited-hover"); - String type = "unlimited"; - String clickCommand = "/qs silentunlimited " + shop.getLocation().getWorld().getName() + " " - + shop.getLocation().getBlockX() + " " + shop.getLocation().getBlockY() + " " - + shop.getLocation().getBlockZ() + " " + "controlpanel.sign." + type + ".line1" + " " - + "controlpanel.sign." + type + ".line2" + " " + "controlpanel.sign." + type + ".line3" + " " - + "controlpanel.sign." + type + ".line4"; - MsgUtil.sendPanelMessage(sender, Text, hoverText, clickCommand); - } - // Buying/Selling Mode - if (sender.hasPermission("quickshop.create.buy") && sender.hasPermission("quickshop.create.sell")) { - if (shop.isSelling()) { - String Text = MsgUtil.getMessage("controlpanel.mode-selling"); - String hoverText = MsgUtil.getMessage("controlpanel.mode-selling-hover"); - String type = "buy"; - String clickCommand = "/qs silentbuy " + shop.getLocation().getWorld().getName() + " " - + shop.getLocation().getBlockX() + " " + shop.getLocation().getBlockY() + " " - + shop.getLocation().getBlockZ() + " " + "controlpanel.sign." + type + ".line1" - + " " + "controlpanel.sign." + type + ".line2" + " " + "controlpanel.sign." + type + ".line3" - + " " + "controlpanel.sign." + type + ".line4"; - MsgUtil.sendPanelMessage(sender, Text, hoverText, clickCommand); - } else if (shop.isBuying()) { - String Text = MsgUtil.getMessage("controlpanel.mode-buying"); - String hoverText = MsgUtil.getMessage("controlpanel.mode-buying-hover"); - String type = "sell"; - String clickCommand = "/qs silentsell " + shop.getLocation().getWorld().getName() + " " - + shop.getLocation().getBlockX() + " " + shop.getLocation().getBlockY() + " " - + shop.getLocation().getBlockZ() + " " +"controlpanel.sign." + type + ".line1" - + " " + "controlpanel.sign." + type + ".line2" + " " + "controlpanel.sign." + type + ".line3" - + " " + "controlpanel.sign." + type + ".line4"; - MsgUtil.sendPanelMessage(sender, Text, hoverText, clickCommand); - } - } - // Set Price - if (sender.hasPermission("quickshop.other.price")||shop.getOwner().equals(((Player)sender).getUniqueId())) { - String Text = MsgUtil.getMessage("controlpanel.price", String.valueOf(shop.getPrice())); - String hoverText = MsgUtil.getMessage("controlpanel.mode-buying-hover"); - String type = "price"; - String clickCommand = "/qs sign " + shop.getLocation().getWorld().getName() + " " - + shop.getLocation().getBlockX() + " " + shop.getLocation().getBlockY() + " " - + shop.getLocation().getBlockZ() + " " + type + " " + "controlpanel.sign." + type + ".line1" + " " - + "controlpanel.sign." + type + ".line2" + " " + "controlpanel.sign." + type + ".line3" + " " - + "controlpanel.sign." + type + ".line4"; - MsgUtil.sendPanelMessage(sender, Text, hoverText, clickCommand); - } - // Refill - if (sender.hasPermission("quickshop.refill")) { - String Text = MsgUtil.getMessage("controlpanel.refill", String.valueOf(shop.getPrice())); - String hoverText = MsgUtil.getMessage("controlpanel.refill-hover"); - String type = "refill"; - String clickCommand = "/qs sign " + shop.getLocation().getWorld().getName() + " " - + shop.getLocation().getBlockX() + " " + shop.getLocation().getBlockY() + " " - + shop.getLocation().getBlockZ() + " " + type + " " + "controlpanel.sign." + type + ".line1" + " " - + "controlpanel.sign." + type + ".line2" + " " + "controlpanel.sign." + type + ".line3" + " " - + "controlpanel.sign." + type + ".line4"; - MsgUtil.sendPanelMessage(sender, Text, hoverText, clickCommand); - } - // Empty - if (sender.hasPermission("quickshop.empty")) { - String Text = MsgUtil.getMessage("controlpanel.empty", String.valueOf(shop.getPrice())); - String hoverText = MsgUtil.getMessage("controlpanel.empty-hover"); - String type = "empty"; - String clickCommand = "/qs silentempty " + shop.getLocation().getWorld().getName() + " " - + shop.getLocation().getBlockX() + " " + shop.getLocation().getBlockY() + " " - + shop.getLocation().getBlockZ() + " " +"controlpanel.sign." + type + ".line1" + " " - + "controlpanel.sign." + type + ".line2" + " " + "controlpanel.sign." + type + ".line3" + " " - + "controlpanel.sign." + type + ".line4"; - MsgUtil.sendPanelMessage(sender, Text, hoverText, clickCommand); - } - // Remove - if (sender.hasPermission("quickshop.other.destroy") || shop.getOwner().equals(((Player)sender).getUniqueId())) { - String Text = MsgUtil.getMessage("controlpanel.remove", String.valueOf(shop.getPrice())); - String hoverText = MsgUtil.getMessage("controlpanel.remove-hover"); - String type = "remove"; - String clickCommand = "/qs silentremove " + shop.getLocation().getWorld().getName() + " " - + shop.getLocation().getBlockX() + " " + shop.getLocation().getBlockY() + " " - + shop.getLocation().getBlockZ() + " " + "controlpanel.sign." + type + ".line1" + " " - + "controlpanel.sign." + type + ".line2" + " " + "controlpanel.sign." + type + ".line3" + " " - + "controlpanel.sign." + type + ".line4"; - MsgUtil.sendPanelMessage(sender, Text, hoverText, clickCommand); - } - - sender.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+"); - } public static void sendPanelMessage(CommandSender sender, String Text,String hoverText, String clickCommand) { TextComponent message = new TextComponent(ChatColor.DARK_PURPLE + "| " + Text); message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, clickCommand)); diff --git a/src/main/java/org/maxgamer/quickshop/Util/SignMenuFactory.java b/src/main/java/org/maxgamer/quickshop/Util/SignMenuFactory.java deleted file mode 100644 index 0aa9eee03..000000000 --- a/src/main/java/org/maxgamer/quickshop/Util/SignMenuFactory.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.maxgamer.quickshop.Util; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.wrappers.BlockPosition; -import com.comphenix.protocol.wrappers.nbt.NbtCompound; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.BiConsumer; -import java.util.stream.IntStream; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -public final class SignMenuFactory { - - public static final int POSITION_HEIGHT = 255; - private static final int ACTION_INDEX = 9; - private static final int SIGN_LINES = 4; - - private static final String NBT_FORMAT = "{\"text\":\"%s\"}"; - private static final String NBT_BLOCK_ID = "minecraft:sign"; - - private final Plugin plugin; - - private final Map> inputReceivers; - private final Map signLocations; - - public SignMenuFactory(Plugin plugin) { - this.plugin = plugin; - this.inputReceivers = new HashMap<>(); - this.signLocations = new HashMap<>(); - this.listen(); - } - - public void newMenu(Player player, List text, BiConsumer input) { - Location location = player.getLocation(); - BlockPosition blockPosition = new BlockPosition(location.getBlockX(), POSITION_HEIGHT, location.getBlockZ()); - - player.sendBlockChange(blockPosition.toLocation(location.getWorld()), Material.WALL_SIGN.createBlockData()); - - PacketContainer openSign = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.OPEN_SIGN_EDITOR); - PacketContainer signData = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.TILE_ENTITY_DATA); - - openSign.getBlockPositionModifier().write(0, blockPosition); - - NbtCompound signNBT = (NbtCompound) signData.getNbtModifier().read(0); - - IntStream.range(0, SIGN_LINES).forEach(line -> signNBT.put("Text" + (line + 1), text.size() > line ? String.format(NBT_FORMAT, this.color(text.get(line))) : "")); - - signNBT.put("x", blockPosition.getX()); - signNBT.put("y", blockPosition.getY()); - signNBT.put("z", blockPosition.getZ()); - signNBT.put("id", NBT_BLOCK_ID); - - signData.getBlockPositionModifier().write(0, blockPosition); - signData.getIntegers().write(0, ACTION_INDEX); - signData.getNbtModifier().write(0, signNBT); - - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, signData); - ProtocolLibrary.getProtocolManager().sendServerPacket(player, openSign); - } catch (InvocationTargetException exception) { - exception.printStackTrace(); - } - this.inputReceivers.putIfAbsent(player, input); - this.signLocations.put(player, blockPosition); - } - - private void listen() { - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this.plugin, PacketType.Play.Client.UPDATE_SIGN) { - @Override - public void onPacketReceiving(PacketEvent event) { - PacketContainer packet = event.getPacket(); - Player player = event.getPlayer(); - String[] input = packet.getStringArrays().read(0); - - BiConsumer response = inputReceivers.remove(player); - BlockPosition blockPosition = signLocations.remove(player); - - if (response == null || blockPosition == null) { - return; - } - event.setCancelled(true); - response.accept(player, input); - player.sendBlockChange(blockPosition.toLocation(player.getWorld()), Material.AIR.createBlockData()); - } - }); - } - - private String color(String input) { - return ChatColor.translateAlternateColorCodes('&', input); - } -} \ No newline at end of file diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java index 11a1a496e..98868230a 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java @@ -18,6 +18,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.PotionMeta; @@ -26,13 +27,6 @@ import org.bukkit.potion.PotionEffect; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Shop.DisplayItem; import org.maxgamer.quickshop.Shop.Shop; -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolManager; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.wrappers.BlockPosition; -import com.comphenix.protocol.wrappers.WrappedBlockData; -import com.comphenix.protocol.wrappers.WrappedChatComponent; - import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -45,7 +39,6 @@ import java.util.Map.Entry; * @author MACHENIKE * */ -@SuppressWarnings("deprecation") public class Util { private static final EnumSet blacklist = EnumSet.noneOf(Material.class); private static final EnumSet shoppables = EnumSet.noneOf(Material.class); @@ -118,7 +111,7 @@ public class Util { public static Entry getPriceRestriction(Material material) { return restrictedPrices.get(material); } - + @SuppressWarnings("deprecation") public static boolean isTransparent(Material m) { boolean trans = m.isTransparent(); return trans; @@ -168,7 +161,7 @@ public class Util { * @return The percentage 'health' the tool has. (Opposite of total damage) */ public static String getToolPercentage(ItemStack item) { - double dura = item.getDurability(); + double dura = ((Damageable)item.getItemMeta()).getDamage();; double max = item.getType().getMaxDurability(); DecimalFormat formatter = new DecimalFormat("0"); return formatter.format((1 - dura / max) * 100.0); @@ -197,27 +190,6 @@ public class Util { } return null; } - - public static void sendSignEditForGUI(Player player, String[] lines) throws InvocationTargetException { - debugLog("SignEdit"); - ProtocolManager manager = plugin.getProtocolLib(); - BlockPosition position = new BlockPosition(player.getLocation().getBlockX(), 255, - player.getLocation().getBlockZ()); - - PacketContainer blockChange = manager.createPacket(PacketType.Play.Server.BLOCK_CHANGE); - blockChange.getBlockPositionModifier().write(0, position); - blockChange.getBlockData().write(0, WrappedBlockData.createData(Material.WALL_SIGN)); - PacketContainer updateSign = manager.createPacket(PacketType.Play.Server.UPDATE_SIGN); - updateSign.getBlockPositionModifier().write(0, position); - updateSign.getChatComponentArrays().write(0, new WrappedChatComponent[]{WrappedChatComponent.fromText(lines[0]), WrappedChatComponent.fromText(lines[1]), WrappedChatComponent.fromText(lines[2]), WrappedChatComponent.fromText(lines[3])}); - PacketContainer open = manager.createPacket(PacketType.Play.Server.OPEN_SIGN_ENTITY); - open.getBlockPositionModifier().write(0, position); - - manager.sendServerPacket(player, blockChange); - manager.sendServerPacket(player, updateSign); - manager.sendServerPacket(player, open); - - } /** * Checks whether someone else's shop is within reach of a hopper being placed by a player. @@ -407,7 +379,7 @@ public class Util { return false; // One of them is null (Can't be both, see above) if (stack1.getType() != stack2.getType()) return false; // Not the same material - if (stack1.getDurability() != stack2.getDurability()) + if (((Damageable)stack1.getItemMeta()).getDamage() != ((Damageable)stack2.getItemMeta()).getDamage()) return false; // Not the same durability if (!stack1.getEnchantments().equals(stack2.getEnchantments())) return false; // They have the same enchants