From bfccc8a6fc737f66ea0b9ecc8f222f5a427c8e2c Mon Sep 17 00:00:00 2001 From: Tim Baxendale Date: Thu, 9 Jan 2020 19:37:10 -0600 Subject: [PATCH] Removed versions/ directory --- versions/1_12/README.md | 4 - versions/1_12/include/plugin.yml | 53 -- versions/1_12/pom.xml | 80 --- .../baxshops/internal/items/ItemUtil.java | 539 ---------------- .../baxshops/internal/items/LegacyItem.java | 58 -- .../baxshops/internal/items/NBTTagable.java | 200 ------ versions/1_13/README.md | 4 - versions/1_13/include/plugin.yml | 53 -- versions/1_13/pom.xml | 80 --- .../baxshops/internal/items/ItemUtil.java | 563 ----------------- .../baxshops/internal/items/LegacyItem.java | 58 -- versions/1_14/README.md | 4 - versions/1_14/include/plugin.yml | 53 -- versions/1_14/pom.xml | 80 --- .../baxshops/internal/items/ItemUtil.java | 573 ----------------- .../baxshops/internal/items/LegacyItem.java | 58 -- versions/1_8/README.md | 4 - versions/1_8/include/plugin.yml | 53 -- versions/1_8/pom.xml | 80 --- .../baxshops/internal/items/ItemUtil.java | 576 ------------------ .../baxshops/internal/items/LegacyItem.java | 58 -- .../baxshops/internal/items/NBTTagable.java | 197 ------ .../internal/versioning/LegacyConfigUtil.java | 37 -- .../versioning/LegacyOfflinePlayer.java | 34 -- .../internal/versioning/LegacyPlayerUtil.java | 56 -- 25 files changed, 3555 deletions(-) delete mode 100644 versions/1_12/README.md delete mode 100644 versions/1_12/include/plugin.yml delete mode 100644 versions/1_12/pom.xml delete mode 100644 versions/1_12/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java delete mode 100644 versions/1_12/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java delete mode 100644 versions/1_12/src/main/java/org/tbax/baxshops/internal/items/NBTTagable.java delete mode 100644 versions/1_13/README.md delete mode 100644 versions/1_13/include/plugin.yml delete mode 100644 versions/1_13/pom.xml delete mode 100644 versions/1_13/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java delete mode 100644 versions/1_13/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java delete mode 100644 versions/1_14/README.md delete mode 100644 versions/1_14/include/plugin.yml delete mode 100644 versions/1_14/pom.xml delete mode 100644 versions/1_14/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java delete mode 100644 versions/1_14/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java delete mode 100644 versions/1_8/README.md delete mode 100644 versions/1_8/include/plugin.yml delete mode 100644 versions/1_8/pom.xml delete mode 100644 versions/1_8/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java delete mode 100644 versions/1_8/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java delete mode 100644 versions/1_8/src/main/java/org/tbax/baxshops/internal/items/NBTTagable.java delete mode 100644 versions/1_8/src/main/java/org/tbax/baxshops/internal/versioning/LegacyConfigUtil.java delete mode 100644 versions/1_8/src/main/java/org/tbax/baxshops/internal/versioning/LegacyOfflinePlayer.java delete mode 100644 versions/1_8/src/main/java/org/tbax/baxshops/internal/versioning/LegacyPlayerUtil.java diff --git a/versions/1_12/README.md b/versions/1_12/README.md deleted file mode 100644 index e70d9c48..00000000 --- a/versions/1_12/README.md +++ /dev/null @@ -1,4 +0,0 @@ -BaxShops -========= - -BaxShops is a shops plugin for Bukkit 1.12 diff --git a/versions/1_12/include/plugin.yml b/versions/1_12/include/plugin.yml deleted file mode 100644 index b7b53d29..00000000 --- a/versions/1_12/include/plugin.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: BaxShops -main: org.tbax.baxshops.internal.ShopPlugin -description: Create and manage shops with a Vault economy -api-version: '1.12' -version: '1.0-beta.3' -commands: - shop: - description: manage shops - usage: | - /shop - §6Help: §f/shop help - aliases: s - buy: - description: buy from a shop - usage: | - /buy [amt] - sell: - description: sell to a shop - usage: | - /sell - restock: - description: restocks an item that is already in a shop with an item in hand - usage: | - /restock -permissions: - shops.*: - description: All Shops permissions - default: op - children: - shops.admin: true - shops.trader: true - shops.trader: - description: Allows you to buy and sell from shops - default: true - children: - shops.buy: true - shops.sell: true - shops.admin: - description: Allows you to create and remove shops - default: op - children: - shops.owner: true - shops.owner: - description: Allows you to create shops for yourself - default: true - children: - shops.trader: true - shops.buy: - description: Allows you to buy from shops - default: true - shops.sell: - description: Allows you to sell to shops - default: true diff --git a/versions/1_12/pom.xml b/versions/1_12/pom.xml deleted file mode 100644 index d1bf3b96..00000000 --- a/versions/1_12/pom.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - 4.0.0 - org.tbax.shops - baxshops - 1.0b3-bukkit1_12-RELEASE - jar - - UTF-8 - 1.7 - 1.7 - - - - - 3.1 - org.apache.maven.plugins - maven-compiler-plugin - - 8 - 8 - - - - - - include - - **/*.yml - **/*.txt - - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - pub-repo - http://nexus.hc.to/content/repositories/pub_releases/ - - - - - - - org.bukkit - bukkit - 1.12.2-R0.1-SNAPSHOT - provided - - - - - net.milkbowl.vault - Vault - 1.6.6 - provided - - - org.jetbrains - annotations - RELEASE - compile - - - diff --git a/versions/1_12/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java b/versions/1_12/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java deleted file mode 100644 index d9b420cd..00000000 --- a/versions/1_12/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java +++ /dev/null @@ -1,539 +0,0 @@ -/* - * Copyright (C) Timothy Baxendale - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package org.tbax.baxshops.internal.items; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BannerMeta; -import org.bukkit.inventory.meta.EnchantmentStorageMeta; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionType; -import org.tbax.baxshops.BaxEntry; -import org.tbax.baxshops.BaxShop; -import org.tbax.baxshops.Format; -import org.tbax.baxshops.internal.ShopPlugin; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.lang.reflect.Method; -import java.util.*; - -public final class ItemUtil -{ - private static final String MINECRAFT_VERSION; - private static final Method AS_NMS_COPY; - private static final Method GET_NAME; - - private static Map legacyItems = null; - private static Map legacyEnchants = null; - - private static final Map SIGN_TO_SIGN = new HashMap<>(); - private static final List SIGN_TYPES = Arrays.asList(Material.SIGN, Material.WALL_SIGN); - - static { - String name = Bukkit.getServer().getClass().getPackage().getName(); - MINECRAFT_VERSION = name.substring(name.lastIndexOf('.') + 1); - - Method nmsCpyMthd = null; - Method getNmMthd = null; - try { - Class itemStackCls = Class.forName("net.minecraft.server." + MINECRAFT_VERSION + ".ItemStack"); - nmsCpyMthd = Class.forName("org.bukkit.craftbukkit." + MINECRAFT_VERSION + ".inventory.CraftItemStack") - .getMethod("asNMSCopy", ItemStack.class); - getNmMthd = itemStackCls.getMethod("getName"); - } - catch (ReflectiveOperationException e) { - e.printStackTrace(); - } - AS_NMS_COPY = nmsCpyMthd; - GET_NAME = getNmMthd; - - SIGN_TO_SIGN.put(Material.WALL_SIGN, Material.SIGN); - } - - /** - * A list of enchantment names - */ - private static final Map enchants = new HashMap<>(); - private static final Map potions = new HashMap<>(); - - private ItemUtil() - { - } - - public static List getItemFromAlias(String input, BaxShop shop) - { - String[] words = input.toUpperCase().split("_"); - String normalizedInput = input.replace('_', ' ').toUpperCase(); - - int maxMatch = -1; - List entries = new ArrayList<>(); - - for (BaxEntry entry : shop) { - String entryName = entry.getName().toUpperCase(); - if (Objects.equals(entryName, normalizedInput)) { - return Collections.singletonList(entry); // 100% match - } - else { - String[] entryWords = entryName.split(" "); - int matches = getMatches(entryWords, words); - if (matches == maxMatch) { - entries.add(entry); - } - else if (matches > maxMatch && matches > 0) { - entries.clear(); - entries.add(entry); - maxMatch = matches; - } - } - } - return entries; - } - - private static int getMatches(String[] array1, String[] array2) - { - int matches = 0; - for (String word1 : array1) { - for (String word2 : array2) { - if (word1.equals(word2)) { - ++matches; - } - } - } - return matches; - } - - /** - * Gets the name of an item. - * - * @param entry the shop entry - * @return the item's name - */ - public static String getName(BaxEntry entry) - { - return ItemUtil.getName(entry.getItemStack()); - } - - /** - * Gets the name of an item. - * - * @param item an item stack - * @return the item's name - */ - public static String getName(ItemStack item) - { - if (item.getType() == Material.ENCHANTED_BOOK) { - Map enchants = EnchantMap.getEnchants(item); - if (enchants != null) - return EnchantMap.fullListString(enchants); - } - - item = item.clone(); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(null); - item.setItemMeta(meta); - } - try { - Object nmsCopy = AS_NMS_COPY.invoke(null, item); - Object txtObj = GET_NAME.invoke(nmsCopy); - try { - return (String)txtObj; - } - catch (ClassCastException e) { - return (String)txtObj.getClass().getMethod("getText").invoke(txtObj); - } - } - catch (ReflectiveOperationException | ClassCastException e) { - ShopPlugin.logWarning("Could not get item name for " + item.getType()); - return item.getType().toString(); - } - } - - public static String getEnchantName(Enchantment enchant) - { - Enchantable enchantable = enchants.get(enchant); - if (enchantable == null) - return Format.toFriendlyName(enchant.getName()); - return enchantable.getName(); - } - - /** - * Loads the enchantment names in enchants.yml - */ - public static void loadEnchants(ShopPlugin plugin) - { - try (InputStream stream = plugin.getResource("enchants.yml")) { - YamlConfiguration enchantConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(stream)); - List> section = enchantConfig.getMapList("enchants"); - - for (Map enchantMap : section) { - Enchantment enchantment = Enchantment.getByName((String)enchantMap.get("enchantment")); - if (enchantment != null) { - String name = (String)enchantMap.get("name"); - Object id = enchantMap.get("id"); - if (id instanceof Number) { - enchants.put(enchantment, new Enchantable(enchantment, name, ((Number)id).intValue())); - } - else { - enchants.put(enchantment, new Enchantable(enchantment, name)); - } - } - } - } - catch (IOException e) { - plugin.getLogger().warning("Failed to read enchants file: " + e.toString()); - } - } - - /** - * Loads the potion names in potions.yml - */ - public static void loadPotions(ShopPlugin plugin) - { - try (InputStream stream = plugin.getResource("potions.yml")) { - YamlConfiguration potionConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(stream)); - List> section = potionConfig.getMapList("potions"); - - for (Map potionMap : section) { - try { - PotionType potionType = PotionType.valueOf((String)potionMap.get("type")); - String name = (String)potionMap.get("name"); - String regular = (String)potionMap.get("regular"); - String upgraded = (String)potionMap.get("upgraded"); - String extended = (String)potionMap.get("extended"); - PotionInfo info = new PotionInfo(potionType, name, regular, upgraded, extended); - potions.put(potionType, info); - } - catch (IllegalArgumentException e) { - // skip - } - } - } - catch (IOException e) { - plugin.getLogger().warning("Failed to read potions file: " + e.toString()); - } - } - - public static Enchantable getEnchantable(Enchantment enchantment) - { - Enchantable enchantable = enchants.get(enchantment); - if (enchantable == null) - return new Enchantable(enchantment, Format.toFriendlyName(enchantment.getName())); - return enchantable; - } - - public static boolean isSameBanner(ItemStack stack1, ItemStack stack2) - { - BannerMeta bannerMeta1, bannerMeta2; - if (stack1.getItemMeta() instanceof BannerMeta) { - bannerMeta1 = (BannerMeta)stack1.getItemMeta(); - } - else { - return false; - } - if (stack2.getItemMeta() instanceof BannerMeta) { - bannerMeta2 = (BannerMeta)stack2.getItemMeta(); - } - else { - return false; - } - if (stack1.getType() != stack2.getType()) - return false; - if (bannerMeta1.numberOfPatterns() != bannerMeta2.numberOfPatterns()) - return false; - for (int i = 0; i < bannerMeta1.numberOfPatterns(); ++i) { - if (!bannerMeta1.getPattern(i).equals(bannerMeta2.getPattern(i))) { - return false; - } - } - return true; - } - - public static boolean isSameBook(ItemStack stack1, ItemStack stack2) - { - EnchantmentStorageMeta enchantmentMeta1, enchantmentMeta2; - if (stack1.getType() != Material.ENCHANTED_BOOK || stack2.getType() != Material.ENCHANTED_BOOK) { - return false; - } - - enchantmentMeta1 = (EnchantmentStorageMeta)stack1.getItemMeta(); - enchantmentMeta2 = (EnchantmentStorageMeta)stack2.getItemMeta(); - - if (enchantmentMeta1.getStoredEnchants().size() != enchantmentMeta2.getStoredEnchants().size()) { - return false; - } - - for (Map.Entry enchants : enchantmentMeta1.getStoredEnchants().entrySet()) { - if (!Objects.equals(enchantmentMeta2.getStoredEnchants().get(enchants.getKey()), enchants.getValue())) { - return false; - } - } - - return true; - } - - public static boolean isSimilar(ItemStack stack1, ItemStack stack2, boolean smartStack) - { - if (stack1 == stack2) return true; - if (stack1 == null || stack2 == null) return false; - if (!smartStack) return stack1.isSimilar(stack2); - if (!stack1.isSimilar(stack2)) { - return stack1.getType() == stack2.getType() && - (isSameBook(stack1, stack2) || isSameBanner(stack1, stack2)); - } - return true; - } - - public static boolean isShop(ItemStack item) - { - return isSign(item) && - item.hasItemMeta() && - item.getItemMeta().hasLore() && - item.getItemMeta().getLore().get(item.getItemMeta().getLore().size() - 1).startsWith(ChatColor.GRAY + "ID: "); - } - - public static boolean isSign(ItemStack item) - { - return item != null && isSign(item.getType()); - } - - public static boolean isSign(Material type) - { - return type != null && SIGN_TYPES.contains(type); - } - - public static BaxShop fromItem(ItemStack item) - { - String id = item.getItemMeta().getLore().get(item.getItemMeta().getLore().size() - 1).substring((ChatColor.GRAY + "ID: ").length()); - BaxShop shop = ShopPlugin.getShopByShortId2(id); // try short id2 - if (shop == null) { - shop = ShopPlugin.getShopByShortId(id); // try short id - if (shop == null) { - try { - return ShopPlugin.getShop(UUID.fromString(id)); // finally try full id - } - catch (IllegalArgumentException e) { - return null; - } - } - } - return shop; - } - - public static String[] extractSignText(ItemStack item) - { - List lore = item.getItemMeta().getLore().subList(0, item.getItemMeta().getLore().size() - 1); - String[] lines = new String[lore.size()]; - for (int i = 0; i < lines.length; ++i) { - lines[i] = ChatColor.stripColor(lore.get(i)); - } - return lines; - } - - public static List getSignTypesAsItems() - { - ItemStack[] stacks = new ItemStack[SIGN_TYPES.size()]; - for (int i = 0; i < SIGN_TYPES.size(); ++i) { - stacks[i] = new ItemStack(SIGN_TYPES.get(i), 1); - } - return Arrays.asList(stacks); - } - - public static ItemStack newDefaultSign() - { - return new ItemStack(getDefaultSignType(), 1); - } - - public static Material getDefaultSignType() - { - return Material.SIGN; - } - - public static Material toInventorySign(Material sign) - { - Material m = SIGN_TO_SIGN.get(sign); - return m == null ? sign : m; - } - - public static Map all(Inventory inventory, List itemStacks) - { - Map all = new HashMap<>(); - for (int idx = 0; idx < inventory.getSize(); ++idx) { - ItemStack item = inventory.getItem(idx); - for (ItemStack other : itemStacks) { - if (other.isSimilar(item)) { - all.put(idx, other); - } - } - } - return all; - } - - @Deprecated - public static ItemStack fromItemId(int id) - { - return fromItemId(id, (short)0); - } - - @Deprecated - public static ItemStack fromItemId(int id, short damage) - { - LegacyItem item = legacyItems.get(id); - if (item == null) return null; - return item.toItemStack(damage); - } - - public static void loadLegacyItems(JavaPlugin plugin) throws IOException - { - legacyItems = new HashMap<>(); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource("legacy_items.txt")))) { - String line; - while ((line = reader.readLine()) != null) { - Scanner scanner = new Scanner(line); - LegacyItem item = new LegacyItem(scanner.nextInt(), scanner.next(), scanner.nextBoolean()); - legacyItems.put(item.getItemId(), item); - } - } - } - - public static void loadLegacyEnchants() - { - legacyEnchants = new HashMap<>(); - for (Map.Entry entry : enchants.entrySet()) { - try { - legacyEnchants.put(entry.getValue().getLegacyId(), entry.getKey()); - } - catch (UnsupportedOperationException e) { - // do not add - } - } - } - - @Deprecated - public static Enchantment getLegacyEnchantment(int id) - { - return legacyEnchants.get(id); - } - - public static int getDurability(ItemStack stack) - { - return stack.getDurability(); - } - - public static void setDurability(ItemStack stack, int durability) - { - stack.setDurability((short)durability); - } - - public static List getSignOnBlock(Block block) - { - List signs = new ArrayList<>(); - for (int x = -1; x <= 1; ++x) { - for (int y = -1; y <= 1; ++y) { - for (int z = -1; z <= 1; ++z) { - Location l = block.getLocation().add(x, y, z); - Block curr = l.getBlock(); - if (ItemUtil.isSign(curr.getType())) { - if (curr.getState().getData() instanceof org.bukkit.material.Sign) { - org.bukkit.material.Sign sign = (org.bukkit.material.Sign)curr.getState().getData(); - if (sign.isWallSign()) { - Block attached = curr.getRelative(sign.getFacing().getOppositeFace()); - if (attached.getLocation().equals(block.getLocation())) { - signs.add(curr); - } - } - else { - Location below = l.subtract(0, 1, 0); - if (below.equals(block.getLocation())) { - signs.add(curr); - } - } - } - } - } - } - } - return signs; - } - - public static boolean isWallSign(Block block) - { - BlockState blockState = block.getState(); - if (blockState.getData() instanceof org.bukkit.material.Sign) { - org.bukkit.material.Sign sign = (org.bukkit.material.Sign)blockState.getData(); - return sign.isWallSign(); - } - return false; - } - - public static BlockFace getSignFacing(Block block) - { - org.bukkit.material.Sign sign = (org.bukkit.material.Sign)block.getState().getData(); - return sign.getFacing(); - } - - public static void setSignFacing(Block block, BlockFace face) - { - BlockState blockState = block.getState(); - org.bukkit.material.Sign sign = (org.bukkit.material.Sign)blockState.getData(); - sign.setFacingDirection(face); - blockState.setData(sign); - blockState.update(); - } - - public static String getNBTTag(ItemStack stack) - { - return new NBTTagable(stack).toString(); - } - - public static PotionInfo getNbtPotionInfo(PotionType type) - { - return potions.get(type); - } - - public static String getPotionInfo(ItemStack item) - { - ItemMeta meta = item.getItemMeta(); - if (meta instanceof PotionMeta) { - PotionData data = ((PotionMeta)meta).getBasePotionData(); - if (data.isExtended()) { - return Format.enchantments("(Extended)"); - } - else if (data.isUpgraded()) { - return Format.enchantments("II"); - } - } - return ""; - } -} \ No newline at end of file diff --git a/versions/1_12/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java b/versions/1_12/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java deleted file mode 100644 index a05dd083..00000000 --- a/versions/1_12/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) Timothy Baxendale - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package org.tbax.baxshops.internal.items; - -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -public final class LegacyItem -{ - private int itemId; - private boolean legacy; - private String name; - - public LegacyItem(int itemId, String name, boolean legacy) - { - this.itemId = itemId; - this.name = name; - this.legacy = legacy; - } - - public int getItemId() - { - return itemId; - } - - public String getName() - { - return name; - } - - public boolean isLegacy() - { - return legacy; - } - - public ItemStack toItemStack(short damage) - { - Material material = Material.getMaterial(name); - if (material == null) return null; - return new ItemStack(material, 1, damage); - } -} diff --git a/versions/1_12/src/main/java/org/tbax/baxshops/internal/items/NBTTagable.java b/versions/1_12/src/main/java/org/tbax/baxshops/internal/items/NBTTagable.java deleted file mode 100644 index 8bfa8aba..00000000 --- a/versions/1_12/src/main/java/org/tbax/baxshops/internal/items/NBTTagable.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (C) Timothy Baxendale - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package org.tbax.baxshops.internal.items; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionEffect; - -import java.util.Map; - -public final class NBTTagable -{ - private ItemStack stack; - private ItemMeta itemMeta; - - public NBTTagable(ItemStack stack) - { - setStack(stack); - } - - public ItemStack getStack() - { - return stack.clone(); - } - - public void setStack(ItemStack stack) - { - this.stack = stack.clone(); - this.itemMeta = this.stack.getItemMeta(); - } - - public JsonElement getEnchantElement() - { - if (stack.getEnchantments() != null && !stack.getEnchantments().isEmpty()) { - JsonArray enchantArray = new JsonArray(); - for (Map.Entry enchants : stack.getEnchantments().entrySet()) { - JsonObject enchantMap = new JsonObject(); - enchantMap.addProperty("id", enchants.getKey().getId()); - enchantMap.addProperty("lvl", enchants.getValue()); - enchantArray.add(enchantMap); - } - return enchantArray; - } - return null; - } - - public JsonElement getLoreElement() - { - if (itemMeta.hasLore()) { - JsonArray lore = new JsonArray(); - for (String line : itemMeta.getLore()) { - JsonObject text = new JsonObject(); - text.addProperty("text", line); - lore.add(text.toString()); - } - return lore; - } - return null; - } - - public JsonElement getNameElement() - { - if (itemMeta.hasDisplayName()) { - JsonObject text = new JsonObject(); - text.addProperty("text", stack.getItemMeta().getDisplayName()); - return text; - } - return null; - } - - public JsonElement getDisplayElement() - { - JsonObject display = new JsonObject(); - JsonElement nameElement = getNameElement(); - if (nameElement != null) { - display.add("Name", nameElement); - } - JsonElement loreElement = getLoreElement(); - if (loreElement != null) { - display.add("Lore", loreElement); - } - if (display.size() > 0) { - return display; - } - else { - return null; - } - } - - public JsonElement getTagElement() - { - JsonObject tag = new JsonObject(); - JsonElement enchantElement = getEnchantElement(); - if (enchantElement != null) { - tag.add("Enchantments", enchantElement); - } - JsonElement displayElement = getDisplayElement(); - if (displayElement != null) { - tag.add("display", displayElement); - } - - if (itemMeta instanceof PotionMeta) { - PotionMeta potionMeta = (PotionMeta)itemMeta; - PotionData potionData = potionMeta.getBasePotionData(); - PotionInfo potionInfo = ItemUtil.getNbtPotionInfo(potionMeta.getBasePotionData().getType()); - - String name; - if (potionInfo == null) { - name = potionData.getType().name().toLowerCase(); - } - else if (potionData.isExtended()) { - name = potionInfo.getExtendedNbtName(); - } - else if (potionData.isUpgraded()) { - name = potionInfo.getUpgradedNbtName(); - } - else { - name = potionInfo.getNbtName(); - } - - tag.addProperty("Potion", "minecraft:" + name); - JsonElement customPotionEffectsElement = getCustomPotionEffectsElement(); - if (customPotionEffectsElement != null) { - tag.add("CustomPotionEffects", customPotionEffectsElement); - } - - if (potionMeta.hasColor()) { - tag.addProperty("CustomPotionColor", potionMeta.getColor().asRGB()); - } - } - - if (tag.size() > 0) { - return tag; - } else { - return null; - } - } - - public JsonElement getCustomPotionEffectsElement() - { - if (itemMeta instanceof PotionMeta) { - PotionMeta potionMeta = (PotionMeta)itemMeta; - if (potionMeta.getCustomEffects() != null && !potionMeta.getCustomEffects().isEmpty()) { - JsonArray customPotionEffectElement = new JsonArray(); - for (PotionEffect effect : potionMeta.getCustomEffects()) { - JsonObject effectElement = new JsonObject(); - effectElement.addProperty("Id", effect.getType().getName()); - effectElement.addProperty("Amplifier", effect.getAmplifier()); - effectElement.addProperty("Duration", effect.getDuration()); - customPotionEffectElement.add(effectElement); - } - return customPotionEffectElement; - } - } - return null; - } - - public JsonElement asJsonElement() - { - JsonObject object = new JsonObject(); - object.addProperty("id", stack.getType().getId()); - object.addProperty("Count", stack.getAmount()); - if (stack.getType().getMaxDurability() > 0) { - object.addProperty("Damage", ItemUtil.getDurability(stack)); - } - JsonElement tag = getTagElement(); - if (tag != null) { - object.add("tag", tag); - } - return object; - } - - @Override - public String toString() - { - return asJsonElement().toString(); - } -} diff --git a/versions/1_13/README.md b/versions/1_13/README.md deleted file mode 100644 index 490de946..00000000 --- a/versions/1_13/README.md +++ /dev/null @@ -1,4 +0,0 @@ -BaxShops -========= - -BaxShops is a shops plugin for Bukkit 1.13 diff --git a/versions/1_13/include/plugin.yml b/versions/1_13/include/plugin.yml deleted file mode 100644 index 92e89d7e..00000000 --- a/versions/1_13/include/plugin.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: BaxShops -main: org.tbax.baxshops.internal.ShopPlugin -description: Create and manage shops with a Vault economy -api-version: '1.13' -version: '1.0-beta.3' -commands: - shop: - description: manage shops - usage: | - /shop - §6Help: §f/shop help - aliases: s - buy: - description: buy from a shop - usage: | - /buy [amt] - sell: - description: sell to a shop - usage: | - /sell - restock: - description: restocks an item that is already in a shop with an item in hand - usage: | - /restock -permissions: - shops.*: - description: All Shops permissions - default: op - children: - shops.admin: true - shops.trader: true - shops.trader: - description: Allows you to buy and sell from shops - default: true - children: - shops.buy: true - shops.sell: true - shops.admin: - description: Allows you to create and remove shops - default: op - children: - shops.owner: true - shops.owner: - description: Allows you to create shops for yourself - default: true - children: - shops.trader: true - shops.buy: - description: Allows you to buy from shops - default: true - shops.sell: - description: Allows you to sell to shops - default: true diff --git a/versions/1_13/pom.xml b/versions/1_13/pom.xml deleted file mode 100644 index 19915596..00000000 --- a/versions/1_13/pom.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - 4.0.0 - org.tbax.shops - baxshops - 1.0b3-bukkit1_13-RELEASE - jar - - UTF-8 - 1.7 - 1.7 - - - - - 3.1 - org.apache.maven.plugins - maven-compiler-plugin - - 8 - 8 - - - - - - include - - **/*.yml - **/*.txt - - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - pub-repo - http://nexus.hc.to/content/repositories/pub_releases/ - - - - - - - org.bukkit - bukkit - 1.13.2-R0.1-SNAPSHOT - provided - - - - - net.milkbowl.vault - Vault - 1.6.6 - provided - - - org.jetbrains - annotations - RELEASE - compile - - - diff --git a/versions/1_13/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java b/versions/1_13/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java deleted file mode 100644 index 3a94c7f6..00000000 --- a/versions/1_13/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java +++ /dev/null @@ -1,563 +0,0 @@ -/* - * Copyright (C) Timothy Baxendale - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package org.tbax.baxshops.internal.items; - -import org.bukkit.*; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.banner.Pattern; -import org.bukkit.block.banner.PatternType; -import org.bukkit.block.data.type.Sign; -import org.bukkit.block.data.type.WallSign; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.*; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionType; -import org.jetbrains.annotations.NotNull; -import org.tbax.baxshops.BaxEntry; -import org.tbax.baxshops.BaxShop; -import org.tbax.baxshops.Format; -import org.tbax.baxshops.internal.ShopPlugin; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.lang.reflect.Method; -import java.util.*; - -public final class ItemUtil -{ - private static final String MINECRAFT_VERSION; - private static final Method AS_NMS_COPY; - private static final Method GET_NAME; - - private static Map legacyItems = null; - private static Map legacyEnchants = null; - - private static final Map SIGN_TO_SIGN = new HashMap<>(); - - private static final List SIGN_TYPES = Arrays.asList(Material.SIGN, Material.WALL_SIGN, - Material.LEGACY_SIGN, Material.LEGACY_WALL_SIGN, Material.LEGACY_SIGN_POST); - - static { - String name = Bukkit.getServer().getClass().getPackage().getName(); - MINECRAFT_VERSION = name.substring(name.lastIndexOf('.') + 1); - - Method nmsCpyMthd = null; - Method getNmMthd = null; - try { - Class itemStackCls = Class.forName("net.minecraft.server." + MINECRAFT_VERSION + ".ItemStack"); - nmsCpyMthd = Class.forName("org.bukkit.craftbukkit." + MINECRAFT_VERSION + ".inventory.CraftItemStack") - .getMethod("asNMSCopy", ItemStack.class); - getNmMthd = itemStackCls.getMethod("getName"); - } - catch (ReflectiveOperationException e) { - e.printStackTrace(); - } - AS_NMS_COPY = nmsCpyMthd; - GET_NAME = getNmMthd; - - SIGN_TO_SIGN.put(Material.WALL_SIGN, Material.SIGN); - SIGN_TO_SIGN.put(Material.LEGACY_WALL_SIGN, Material.LEGACY_SIGN); - SIGN_TO_SIGN.put(Material.LEGACY_SIGN_POST, Material.LEGACY_SIGN); - } - - /** - * A list of enchantment names - */ - private static final Map enchants = new HashMap<>(); - private static final Map potions = new HashMap<>(); - - private ItemUtil() - { - } - - public static List getItemFromAlias(String input, BaxShop shop) - { - String[] words = input.toUpperCase().split("_"); - String normalizedInput = input.replace('_', ' ').toUpperCase(); - - int maxMatch = -1; - List entries = new ArrayList<>(); - - for (BaxEntry entry : shop) { - String entryName = entry.getName().toUpperCase(); - if (Objects.equals(entryName, normalizedInput)) { - return Collections.singletonList(entry); // 100% match - } - else { - String[] entryWords = entryName.split(" "); - int matches = getMatches(entryWords, words); - if (matches == maxMatch) { - entries.add(entry); - } - else if (matches > maxMatch && matches > 0) { - entries.clear(); - entries.add(entry); - maxMatch = matches; - } - } - } - return entries; - } - - private static int getMatches(String[] array1, String[] array2) - { - int matches = 0; - for (String word1 : array1) { - for (String word2 : array2) { - if (word1.equals(word2)) { - ++matches; - } - } - } - return matches; - } - - /** - * Gets the name of an item. - * - * @param entry the shop entry - * @return the item's name - */ - public static String getName(BaxEntry entry) - { - return ItemUtil.getName(entry.getItemStack()); - } - - /** - * Gets the name of an item. - * - * @param item an item stack - * @return the item's name - */ - public static String getName(ItemStack item) - { - if (item.getType() == Material.ENCHANTED_BOOK) { - Map enchants = EnchantMap.getEnchants(item); - if (enchants != null) - return EnchantMap.fullListString(enchants); - } - else if (isOminousBanner(item)) { - return ChatColor.GOLD + "Ominous Banner"; - } - - item = item.clone(); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(null); - item.setItemMeta(meta); - } - try { - Object nmsCopy = AS_NMS_COPY.invoke(null, item); - Object txtObj = GET_NAME.invoke(nmsCopy); - try { - return (String)txtObj; - } - catch (ClassCastException e) { - return (String)txtObj.getClass().getMethod("getText").invoke(txtObj); - } - } - catch (ReflectiveOperationException | ClassCastException e) { - ShopPlugin.logWarning("Could not get item name for " + item.getType()); - return item.getType().toString(); - } - } - - public static boolean isOminousBanner(@NotNull ItemStack stack) - { - if (stack.getType() != Material.WHITE_BANNER) - return false; - BannerMeta bannerMeta = (BannerMeta)stack.getItemMeta(); - return bannerMeta.getPatterns().containsAll(ominousPatterns()); - } - - private static List ominousPatterns() - { - Pattern[] patterns = new Pattern[8]; - patterns[0] = new Pattern(DyeColor.CYAN, PatternType.RHOMBUS_MIDDLE); - patterns[1] = new Pattern(DyeColor.LIGHT_GRAY, PatternType.STRIPE_BOTTOM); - patterns[2] = new Pattern(DyeColor.GRAY, PatternType.STRIPE_CENTER); - patterns[3] = new Pattern(DyeColor.LIGHT_GRAY, PatternType.BORDER); - patterns[4] = new Pattern(DyeColor.BLACK, PatternType.STRIPE_MIDDLE); - patterns[5] = new Pattern(DyeColor.LIGHT_GRAY, PatternType.HALF_HORIZONTAL); - patterns[6] = new Pattern(DyeColor.LIGHT_GRAY, PatternType.CIRCLE_MIDDLE); - patterns[7] = new Pattern(DyeColor.BLACK, PatternType.BORDER); - return Arrays.asList(patterns); - } - - public static String getEnchantName(Enchantment enchant) - { - Enchantable enchantable = enchants.get(enchant); - if (enchantable == null) - return Format.toFriendlyName(enchant.getKey().getKey()); - return enchantable.getName(); - } - - /** - * Loads the enchantment names in enchants.yml - */ - public static void loadEnchants(ShopPlugin plugin) - { - try (InputStream stream = plugin.getResource("enchants.yml")) { - YamlConfiguration enchantConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(stream)); - List> section = enchantConfig.getMapList("enchants"); - - for (Map enchantMap : section) { - Map namespaceKey = (Map)enchantMap.get("key"); - Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft((String)namespaceKey.get("key"))); - if (enchantment != null) { - String name = (String)enchantMap.get("name"); - Object id = enchantMap.get("id"); - if (id instanceof Number) { - enchants.put(enchantment, new Enchantable(enchantment, name, ((Number)id).intValue())); - } - else { - enchants.put(enchantment, new Enchantable(enchantment, name)); - } - } - } - } - catch (IOException e) { - plugin.getLogger().warning("Failed to read enchants file: " + e.toString()); - } - } - - /** - * Loads the potion names in potions.yml - */ - public static void loadPotions(ShopPlugin plugin) - { - try (InputStream stream = plugin.getResource("potions.yml")) { - YamlConfiguration potionConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(stream)); - List> section = potionConfig.getMapList("potions"); - - for (Map potionMap : section) { - try { - PotionType potionType = PotionType.valueOf((String)potionMap.get("type")); - String name = (String)potionMap.get("name"); - String regular = (String)potionMap.get("regular"); - String upgraded = (String)potionMap.get("upgraded"); - String extended = (String)potionMap.get("extended"); - PotionInfo info = new PotionInfo(potionType, name, regular, upgraded, extended); - potions.put(potionType, info); - } - catch (IllegalArgumentException e) { - // skip - } - } - } - catch (IOException e) { - plugin.getLogger().warning("Failed to read potions file: " + e.toString()); - } - } - - public static Enchantable getEnchantable(Enchantment enchantment) - { - Enchantable enchantable = enchants.get(enchantment); - if (enchantable == null) - return new Enchantable(enchantment, Format.toFriendlyName(enchantment.getKey().getKey())); - return enchantable; - } - - public static boolean isSameBanner(ItemStack stack1, ItemStack stack2) - { - BannerMeta bannerMeta1, bannerMeta2; - if (stack1.getItemMeta() instanceof BannerMeta) { - bannerMeta1 = (BannerMeta)stack1.getItemMeta(); - } - else { - return false; - } - if (stack2.getItemMeta() instanceof BannerMeta) { - bannerMeta2 = (BannerMeta)stack2.getItemMeta(); - } - else { - return false; - } - if (stack1.getType() != stack2.getType()) - return false; - if (bannerMeta1.numberOfPatterns() != bannerMeta2.numberOfPatterns()) - return false; - for (int i = 0; i < bannerMeta1.numberOfPatterns(); ++i) { - if (!bannerMeta1.getPattern(i).equals(bannerMeta2.getPattern(i))) { - return false; - } - } - return true; - } - - public static boolean isSameBook(ItemStack stack1, ItemStack stack2) - { - EnchantmentStorageMeta enchantmentMeta1, enchantmentMeta2; - if (stack1.getType() != Material.ENCHANTED_BOOK || stack2.getType() != Material.ENCHANTED_BOOK) { - return false; - } - - enchantmentMeta1 = (EnchantmentStorageMeta)stack1.getItemMeta(); - enchantmentMeta2 = (EnchantmentStorageMeta)stack2.getItemMeta(); - - if (enchantmentMeta1.getStoredEnchants().size() != enchantmentMeta2.getStoredEnchants().size()) { - return false; - } - - for (Map.Entry enchants : enchantmentMeta1.getStoredEnchants().entrySet()) { - if (!Objects.equals(enchantmentMeta2.getStoredEnchants().get(enchants.getKey()), enchants.getValue())) { - return false; - } - } - - return true; - } - - public static boolean isSimilar(ItemStack stack1, ItemStack stack2, boolean smartStack) - { - if (stack1 == stack2) return true; - if (stack1 == null || stack2 == null) return false; - if (!smartStack) return stack1.isSimilar(stack2); - if (!stack1.isSimilar(stack2)) { - return stack1.getType() == stack2.getType() && - (isSameBook(stack1, stack2) || isSameBanner(stack1, stack2)); - } - return true; - } - - public static boolean isShop(ItemStack item) - { - return isSign(item) && - item.hasItemMeta() && - item.getItemMeta().hasLore() && - item.getItemMeta().getLore().get(item.getItemMeta().getLore().size() - 1).startsWith(ChatColor.GRAY + "ID: "); - } - - public static boolean isSign(ItemStack item) - { - return item != null && isSign(item.getType()); - } - - public static boolean isSign(Material type) - { - return type != null && SIGN_TYPES.contains(type); - } - - public static BaxShop fromItem(ItemStack item) - { - String id = item.getItemMeta().getLore().get(item.getItemMeta().getLore().size() - 1).substring((ChatColor.GRAY + "ID: ").length()); - BaxShop shop = ShopPlugin.getShopByShortId2(id); // try short id2 - if (shop == null) { - shop = ShopPlugin.getShopByShortId(id); // try short id - if (shop == null) { - try { - return ShopPlugin.getShop(UUID.fromString(id)); // finally try full id - } - catch (IllegalArgumentException e) { - return null; - } - } - } - return shop; - } - - public static String[] extractSignText(ItemStack item) - { - List lore = item.getItemMeta().getLore().subList(0, item.getItemMeta().getLore().size() - 1); - String[] lines = new String[lore.size()]; - for (int i = 0; i < lines.length; ++i) { - lines[i] = ChatColor.stripColor(lore.get(i)); - } - return lines; - } - - public static List getSignTypesAsItems() - { - ItemStack[] stacks = new ItemStack[SIGN_TYPES.size()]; - for (int i = 0; i < SIGN_TYPES.size(); ++i) { - stacks[i] = new ItemStack(SIGN_TYPES.get(i), 1); - } - return Arrays.asList(stacks); - } - - public static ItemStack newDefaultSign() - { - return new ItemStack(getDefaultSignType(), 1); - } - - public static Material getDefaultSignType() - { - return Material.SIGN; - } - - public static Material toInventorySign(Material sign) - { - Material m = SIGN_TO_SIGN.get(sign); - return m == null ? sign : m; - } - - public static Map all(Inventory inventory, List itemStacks) - { - Map all = new HashMap<>(); - for (int idx = 0; idx < inventory.getSize(); ++idx) { - ItemStack item = inventory.getItem(idx); - for (ItemStack other : itemStacks) { - if (other.isSimilar(item)) { - all.put(idx, other); - } - } - } - return all; - } - - @Deprecated - public static ItemStack fromItemId(int id) - { - return fromItemId(id, (short)0); - } - - @Deprecated - public static ItemStack fromItemId(int id, short damage) - { - LegacyItem item = legacyItems.get(id); - if (item == null) return null; - return item.toItemStack(damage); - } - - public static void loadLegacyItems(JavaPlugin plugin) throws IOException - { - legacyItems = new HashMap<>(); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource("legacy_items.txt")))) { - String line; - while ((line = reader.readLine()) != null) { - Scanner scanner = new Scanner(line); - LegacyItem item = new LegacyItem(scanner.nextInt(), scanner.next(), scanner.nextBoolean()); - legacyItems.put(item.getItemId(), item); - } - } - } - - public static void loadLegacyEnchants() - { - legacyEnchants = new HashMap<>(); - for (Map.Entry entry : enchants.entrySet()) { - try { - legacyEnchants.put(entry.getValue().getLegacyId(), entry.getKey()); - } - catch (UnsupportedOperationException e) { - // do not add - } - } - } - - @Deprecated - public static Enchantment getLegacyEnchantment(int id) - { - return legacyEnchants.get(id); - } - - public static int getDurability(ItemStack stack) - { - if (stack.getItemMeta() instanceof Damageable) { - Damageable damage = (Damageable)stack.getItemMeta(); - return damage.getDamage(); - } - return 0; - } - - public static void setDurability(ItemStack stack, int durability) - { - if (stack.getItemMeta() instanceof Damageable) { - Damageable damage = (Damageable)stack.getItemMeta(); - damage.setDamage(durability); - stack.setItemMeta((ItemMeta)damage); - } - } - - public static List getSignOnBlock(Block block) - { - List signs = new ArrayList<>(); - for (int x = -1; x <= 1; ++x) { - for (int y = -1; y <= 1; ++y) { - for (int z = -1; z <= 1; ++z) { - Location l = block.getLocation().add(x, y, z); - Block curr = l.getBlock(); - if (ItemUtil.isSign(curr.getType())) { - if (curr.getBlockData() instanceof WallSign) { - WallSign sign = (WallSign)curr.getBlockData(); - Block attached = curr.getRelative(sign.getFacing().getOppositeFace()); - if (attached.getLocation().equals(block.getLocation())) { - signs.add(curr); - } - } - else { - Location below = l.subtract(0, 1, 0); - if (below.equals(block.getLocation())) { - signs.add(curr); - } - } - } - } - } - } - return signs; - } - - public static boolean isWallSign(Block block) - { - return block.getBlockData() instanceof WallSign; - } - - public static BlockFace getSignFacing(Block block) - { - return ((Sign)block.getBlockData()).getRotation(); - } - - public static void setSignFacing(Block block, BlockFace face) - { - ((Sign)block.getBlockData()).setRotation(face); - } - - public static String getNBTTag(ItemStack stack) - { - return new NBTTagable(stack).toString(); - } - - public static PotionInfo getNbtPotionInfo(PotionType type) - { - return potions.get(type); - } - - public static String getPotionInfo(ItemStack item) - { - ItemMeta meta = item.getItemMeta(); - if (meta instanceof PotionMeta) { - PotionData data = ((PotionMeta)meta).getBasePotionData(); - if (data.isExtended()) { - return Format.enchantments("(Extended)"); - } - else if (data.isUpgraded()) { - return Format.enchantments("II"); - } - } - return ""; - } -} \ No newline at end of file diff --git a/versions/1_13/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java b/versions/1_13/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java deleted file mode 100644 index 67042264..00000000 --- a/versions/1_13/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) Timothy Baxendale - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package org.tbax.baxshops.internal.items; - -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -public final class LegacyItem -{ - private int itemId; - private boolean legacy; - private String name; - - public LegacyItem(int itemId, String name, boolean legacy) - { - this.itemId = itemId; - this.name = name; - this.legacy = legacy; - } - - public int getItemId() - { - return itemId; - } - - public String getName() - { - return name; - } - - public boolean isLegacy() - { - return legacy; - } - - public ItemStack toItemStack(short damage) - { - Material material = Material.getMaterial(name, isLegacy()); - if (material == null) return null; - return new ItemStack(material, 1, damage); - } -} diff --git a/versions/1_14/README.md b/versions/1_14/README.md deleted file mode 100644 index e5a6bc79..00000000 --- a/versions/1_14/README.md +++ /dev/null @@ -1,4 +0,0 @@ -BaxShops -========= - -BaxShops is a shops plugin for Bukkit 1.14 diff --git a/versions/1_14/include/plugin.yml b/versions/1_14/include/plugin.yml deleted file mode 100644 index 4012636d..00000000 --- a/versions/1_14/include/plugin.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: BaxShops -main: org.tbax.baxshops.internal.ShopPlugin -description: Create and manage shops with a Vault economy -api-version: '1.14' -version: '1.0-beta.3' -commands: - shop: - description: manage shops - usage: | - /shop - §6Help: §f/shop help - aliases: s - buy: - description: buy from a shop - usage: | - /buy [amt] - sell: - description: sell to a shop - usage: | - /sell - restock: - description: restocks an item that is already in a shop with an item in hand - usage: | - /restock -permissions: - shops.*: - description: All Shops permissions - default: op - children: - shops.admin: true - shops.trader: true - shops.trader: - description: Allows you to buy and sell from shops - default: true - children: - shops.buy: true - shops.sell: true - shops.admin: - description: Allows you to create and remove shops - default: op - children: - shops.owner: true - shops.owner: - description: Allows you to create shops for yourself - default: true - children: - shops.trader: true - shops.buy: - description: Allows you to buy from shops - default: true - shops.sell: - description: Allows you to sell to shops - default: true diff --git a/versions/1_14/pom.xml b/versions/1_14/pom.xml deleted file mode 100644 index 6832d442..00000000 --- a/versions/1_14/pom.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - 4.0.0 - org.tbax.shops - baxshops - 1.0b3-bukkit1_14-RELEASE - jar - - UTF-8 - 1.7 - 1.7 - - - - - 3.1 - org.apache.maven.plugins - maven-compiler-plugin - - 8 - 8 - - - - - - include - - **/*.yml - **/*.txt - - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - pub-repo - http://nexus.hc.to/content/repositories/pub_releases/ - - - - - - - org.bukkit - bukkit - 1.14.2-R0.1-SNAPSHOT - provided - - - - - net.milkbowl.vault - Vault - 1.6.6 - provided - - - org.jetbrains - annotations - RELEASE - compile - - - diff --git a/versions/1_14/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java b/versions/1_14/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java deleted file mode 100644 index 30b1b815..00000000 --- a/versions/1_14/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java +++ /dev/null @@ -1,573 +0,0 @@ -/* - * Copyright (C) Timothy Baxendale - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package org.tbax.baxshops.internal.items; - -import org.bukkit.*; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.banner.Pattern; -import org.bukkit.block.banner.PatternType; -import org.bukkit.block.data.type.Sign; -import org.bukkit.block.data.type.WallSign; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.*; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionType; -import org.jetbrains.annotations.NotNull; -import org.tbax.baxshops.BaxEntry; -import org.tbax.baxshops.BaxShop; -import org.tbax.baxshops.Format; -import org.tbax.baxshops.internal.ShopPlugin; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.lang.reflect.Method; -import java.util.*; - -public final class ItemUtil -{ - private static final String MINECRAFT_VERSION; - private static final Method AS_NMS_COPY; - private static final Method GET_NAME; - - private static Map legacyItems = null; - private static Map legacyEnchants = null; - - private static final Map SIGN_TO_SIGN = new HashMap<>(); - - private static final List SIGN_TYPES = Arrays.asList(Material.SPRUCE_SIGN, Material.SPRUCE_WALL_SIGN, - Material.ACACIA_SIGN, Material.ACACIA_WALL_SIGN, - Material.BIRCH_SIGN, Material.BIRCH_WALL_SIGN, - Material.DARK_OAK_SIGN, Material.DARK_OAK_WALL_SIGN, - Material.JUNGLE_SIGN, Material.JUNGLE_WALL_SIGN, - Material.OAK_SIGN, Material.OAK_WALL_SIGN, - Material.LEGACY_SIGN, Material.LEGACY_WALL_SIGN, Material.LEGACY_SIGN_POST); - - static { - String name = Bukkit.getServer().getClass().getPackage().getName(); - MINECRAFT_VERSION = name.substring(name.lastIndexOf('.') + 1); - - Method nmsCpyMthd = null; - Method getNmMthd = null; - try { - Class itemStackCls = Class.forName("net.minecraft.server." + MINECRAFT_VERSION + ".ItemStack"); - nmsCpyMthd = Class.forName("org.bukkit.craftbukkit." + MINECRAFT_VERSION + ".inventory.CraftItemStack") - .getMethod("asNMSCopy", ItemStack.class); - getNmMthd = itemStackCls.getMethod("getName"); - } - catch (ReflectiveOperationException e) { - e.printStackTrace(); - } - AS_NMS_COPY = nmsCpyMthd; - GET_NAME = getNmMthd; - - SIGN_TO_SIGN.put(Material.OAK_WALL_SIGN, Material.OAK_SIGN); - SIGN_TO_SIGN.put(Material.ACACIA_WALL_SIGN, Material.ACACIA_SIGN); - SIGN_TO_SIGN.put(Material.BIRCH_WALL_SIGN, Material.BIRCH_SIGN); - SIGN_TO_SIGN.put(Material.DARK_OAK_WALL_SIGN, Material.DARK_OAK_SIGN); - SIGN_TO_SIGN.put(Material.SPRUCE_WALL_SIGN, Material.SPRUCE_SIGN); - SIGN_TO_SIGN.put(Material.JUNGLE_WALL_SIGN, Material.JUNGLE_SIGN); - SIGN_TO_SIGN.put(Material.LEGACY_WALL_SIGN, Material.LEGACY_SIGN); - SIGN_TO_SIGN.put(Material.LEGACY_SIGN_POST, Material.LEGACY_SIGN); - } - - /** - * A list of enchantment names - */ - private static final Map enchants = new HashMap<>(); - private static final Map potions = new HashMap<>(); - - private ItemUtil() - { - } - - public static List getItemFromAlias(String input, BaxShop shop) - { - String[] words = input.toUpperCase().split("_"); - String normalizedInput = input.replace('_', ' ').toUpperCase(); - - int maxMatch = -1; - List entries = new ArrayList<>(); - - for (BaxEntry entry : shop) { - String entryName = entry.getName().toUpperCase(); - if (Objects.equals(entryName, normalizedInput)) { - return Collections.singletonList(entry); // 100% match - } - else { - String[] entryWords = entryName.split(" "); - int matches = getMatches(entryWords, words); - if (matches == maxMatch) { - entries.add(entry); - } - else if (matches > maxMatch && matches > 0) { - entries.clear(); - entries.add(entry); - maxMatch = matches; - } - } - } - return entries; - } - - private static int getMatches(String[] array1, String[] array2) - { - int matches = 0; - for (String word1 : array1) { - for (String word2 : array2) { - if (word1.equals(word2)) { - ++matches; - } - } - } - return matches; - } - - /** - * Gets the name of an item. - * - * @param entry the shop entry - * @return the item's name - */ - public static String getName(BaxEntry entry) - { - return ItemUtil.getName(entry.getItemStack()); - } - - /** - * Gets the name of an item. - * - * @param item an item stack - * @return the item's name - */ - public static String getName(ItemStack item) - { - if (item.getType() == Material.ENCHANTED_BOOK) { - Map enchants = EnchantMap.getEnchants(item); - if (enchants != null) - return EnchantMap.fullListString(enchants); - } - else if (isOminousBanner(item)) { - return ChatColor.GOLD + "Ominous Banner"; - } - - item = item.clone(); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(null); - item.setItemMeta(meta); - } - try { - Object nmsCopy = AS_NMS_COPY.invoke(null, item); - Object txtObj = GET_NAME.invoke(nmsCopy); - try { - return (String)txtObj; - } - catch (ClassCastException e) { - return (String)txtObj.getClass().getMethod("getText").invoke(txtObj); - } - } - catch (ReflectiveOperationException | ClassCastException e) { - ShopPlugin.logWarning("Could not get item name for " + item.getType()); - return item.getType().toString(); - } - } - - public static boolean isOminousBanner(@NotNull ItemStack stack) - { - if (stack.getType() != Material.WHITE_BANNER) - return false; - BannerMeta bannerMeta = (BannerMeta)stack.getItemMeta(); - return bannerMeta.getPatterns().containsAll(ominousPatterns()); - } - - private static List ominousPatterns() - { - Pattern[] patterns = new Pattern[8]; - patterns[0] = new Pattern(DyeColor.CYAN, PatternType.RHOMBUS_MIDDLE); - patterns[1] = new Pattern(DyeColor.LIGHT_GRAY, PatternType.STRIPE_BOTTOM); - patterns[2] = new Pattern(DyeColor.GRAY, PatternType.STRIPE_CENTER); - patterns[3] = new Pattern(DyeColor.LIGHT_GRAY, PatternType.BORDER); - patterns[4] = new Pattern(DyeColor.BLACK, PatternType.STRIPE_MIDDLE); - patterns[5] = new Pattern(DyeColor.LIGHT_GRAY, PatternType.HALF_HORIZONTAL); - patterns[6] = new Pattern(DyeColor.LIGHT_GRAY, PatternType.CIRCLE_MIDDLE); - patterns[7] = new Pattern(DyeColor.BLACK, PatternType.BORDER); - return Arrays.asList(patterns); - } - - public static String getEnchantName(Enchantment enchant) - { - Enchantable enchantable = enchants.get(enchant); - if (enchantable == null) - return Format.toFriendlyName(enchant.getKey().getKey()); - return enchantable.getName(); - } - - /** - * Loads the enchantment names in enchants.yml - */ - public static void loadEnchants(ShopPlugin plugin) - { - try (InputStream stream = plugin.getResource("enchants.yml")) { - YamlConfiguration enchantConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(stream)); - List> section = enchantConfig.getMapList("enchants"); - - for (Map enchantMap : section) { - Map namespaceKey = (Map)enchantMap.get("key"); - Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft((String)namespaceKey.get("key"))); - if (enchantment != null) { - String name = (String)enchantMap.get("name"); - Object id = enchantMap.get("id"); - if (id instanceof Number) { - enchants.put(enchantment, new Enchantable(enchantment, name, ((Number)id).intValue())); - } - else { - enchants.put(enchantment, new Enchantable(enchantment, name)); - } - } - } - } - catch (IOException e) { - plugin.getLogger().warning("Failed to read enchants file: " + e.toString()); - } - } - - /** - * Loads the potion names in potions.yml - */ - public static void loadPotions(ShopPlugin plugin) - { - try (InputStream stream = plugin.getResource("potions.yml")) { - YamlConfiguration potionConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(stream)); - List> section = potionConfig.getMapList("potions"); - - for (Map potionMap : section) { - try { - PotionType potionType = PotionType.valueOf((String)potionMap.get("type")); - String name = (String)potionMap.get("name"); - String regular = (String)potionMap.get("regular"); - String upgraded = (String)potionMap.get("upgraded"); - String extended = (String)potionMap.get("extended"); - PotionInfo info = new PotionInfo(potionType, name, regular, upgraded, extended); - potions.put(potionType, info); - } - catch (IllegalArgumentException e) { - // skip - } - } - } - catch (IOException e) { - plugin.getLogger().warning("Failed to read potions file: " + e.toString()); - } - } - - public static Enchantable getEnchantable(Enchantment enchantment) - { - Enchantable enchantable = enchants.get(enchantment); - if (enchantable == null) - return new Enchantable(enchantment, Format.toFriendlyName(enchantment.getKey().getKey())); - return enchantable; - } - - public static boolean isSameBanner(ItemStack stack1, ItemStack stack2) - { - BannerMeta bannerMeta1, bannerMeta2; - if (stack1.getItemMeta() instanceof BannerMeta) { - bannerMeta1 = (BannerMeta)stack1.getItemMeta(); - } - else { - return false; - } - if (stack2.getItemMeta() instanceof BannerMeta) { - bannerMeta2 = (BannerMeta)stack2.getItemMeta(); - } - else { - return false; - } - if (stack1.getType() != stack2.getType()) - return false; - if (bannerMeta1.numberOfPatterns() != bannerMeta2.numberOfPatterns()) - return false; - for (int i = 0; i < bannerMeta1.numberOfPatterns(); ++i) { - if (!bannerMeta1.getPattern(i).equals(bannerMeta2.getPattern(i))) { - return false; - } - } - return true; - } - - public static boolean isSameBook(ItemStack stack1, ItemStack stack2) - { - EnchantmentStorageMeta enchantmentMeta1, enchantmentMeta2; - if (stack1.getType() != Material.ENCHANTED_BOOK || stack2.getType() != Material.ENCHANTED_BOOK) { - return false; - } - - enchantmentMeta1 = (EnchantmentStorageMeta)stack1.getItemMeta(); - enchantmentMeta2 = (EnchantmentStorageMeta)stack2.getItemMeta(); - - if (enchantmentMeta1.getStoredEnchants().size() != enchantmentMeta2.getStoredEnchants().size()) { - return false; - } - - for (Map.Entry enchants : enchantmentMeta1.getStoredEnchants().entrySet()) { - if (!Objects.equals(enchantmentMeta2.getStoredEnchants().get(enchants.getKey()), enchants.getValue())) { - return false; - } - } - - return true; - } - - public static boolean isSimilar(ItemStack stack1, ItemStack stack2, boolean smartStack) - { - if (stack1 == stack2) return true; - if (stack1 == null || stack2 == null) return false; - if (!smartStack) return stack1.isSimilar(stack2); - if (!stack1.isSimilar(stack2)) { - return stack1.getType() == stack2.getType() && - (isSameBook(stack1, stack2) || isSameBanner(stack1, stack2)); - } - return true; - } - - public static boolean isShop(ItemStack item) - { - return isSign(item) && - item.hasItemMeta() && - item.getItemMeta().hasLore() && - item.getItemMeta().getLore().get(item.getItemMeta().getLore().size() - 1).startsWith(ChatColor.GRAY + "ID: "); - } - - public static boolean isSign(ItemStack item) - { - return item != null && isSign(item.getType()); - } - - public static boolean isSign(Material type) - { - return type != null && SIGN_TYPES.contains(type); - } - - public static BaxShop fromItem(ItemStack item) - { - String id = item.getItemMeta().getLore().get(item.getItemMeta().getLore().size() - 1).substring((ChatColor.GRAY + "ID: ").length()); - BaxShop shop = ShopPlugin.getShopByShortId2(id); // try short id2 - if (shop == null) { - shop = ShopPlugin.getShopByShortId(id); // try short id - if (shop == null) { - try { - return ShopPlugin.getShop(UUID.fromString(id)); // finally try full id - } - catch (IllegalArgumentException e) { - return null; - } - } - } - return shop; - } - - public static String[] extractSignText(ItemStack item) - { - List lore = item.getItemMeta().getLore().subList(0, item.getItemMeta().getLore().size() - 1); - String[] lines = new String[lore.size()]; - for (int i = 0; i < lines.length; ++i) { - lines[i] = ChatColor.stripColor(lore.get(i)); - } - return lines; - } - - public static List getSignTypesAsItems() - { - ItemStack[] stacks = new ItemStack[SIGN_TYPES.size()]; - for (int i = 0; i < SIGN_TYPES.size(); ++i) { - stacks[i] = new ItemStack(SIGN_TYPES.get(i), 1); - } - return Arrays.asList(stacks); - } - - public static ItemStack newDefaultSign() - { - return new ItemStack(getDefaultSignType(), 1); - } - - public static Material getDefaultSignType() - { - return Material.OAK_SIGN; - } - - public static Material toInventorySign(Material sign) - { - Material m = SIGN_TO_SIGN.get(sign); - return m == null ? sign : m; - } - - public static Map all(Inventory inventory, List itemStacks) - { - Map all = new HashMap<>(); - for (int idx = 0; idx < inventory.getSize(); ++idx) { - ItemStack item = inventory.getItem(idx); - for (ItemStack other : itemStacks) { - if (other.isSimilar(item)) { - all.put(idx, other); - } - } - } - return all; - } - - @Deprecated - public static ItemStack fromItemId(int id) - { - return fromItemId(id, (short)0); - } - - @Deprecated - public static ItemStack fromItemId(int id, short damage) - { - LegacyItem item = legacyItems.get(id); - if (item == null) return null; - return item.toItemStack(damage); - } - - public static void loadLegacyItems(JavaPlugin plugin) throws IOException - { - legacyItems = new HashMap<>(); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource("legacy_items.txt")))) { - String line; - while ((line = reader.readLine()) != null) { - Scanner scanner = new Scanner(line); - LegacyItem item = new LegacyItem(scanner.nextInt(), scanner.next(), scanner.nextBoolean()); - legacyItems.put(item.getItemId(), item); - } - } - } - - public static void loadLegacyEnchants() - { - legacyEnchants = new HashMap<>(); - for (Map.Entry entry : enchants.entrySet()) { - try { - legacyEnchants.put(entry.getValue().getLegacyId(), entry.getKey()); - } - catch (UnsupportedOperationException e) { - // do not add - } - } - } - - @Deprecated - public static Enchantment getLegacyEnchantment(int id) - { - return legacyEnchants.get(id); - } - - public static int getDurability(ItemStack stack) - { - if (stack.getItemMeta() instanceof Damageable) { - Damageable damage = (Damageable)stack.getItemMeta(); - return damage.getDamage(); - } - return 0; - } - - public static void setDurability(ItemStack stack, int durability) - { - if (stack.getItemMeta() instanceof Damageable) { - Damageable damage = (Damageable)stack.getItemMeta(); - damage.setDamage(durability); - stack.setItemMeta((ItemMeta)damage); - } - } - - public static List getSignOnBlock(Block block) - { - List signs = new ArrayList<>(); - for (int x = -1; x <= 1; ++x) { - for (int y = -1; y <= 1; ++y) { - for (int z = -1; z <= 1; ++z) { - Location l = block.getLocation().add(x, y, z); - Block curr = l.getBlock(); - if (isSign(curr.getType())) { - if (isWallSign(curr)) { - WallSign sign = (WallSign)curr.getBlockData(); - Block attached = curr.getRelative(sign.getFacing().getOppositeFace()); - if (attached.getLocation().equals(block.getLocation())) { - signs.add(curr); - } - } - else { - Location below = l.subtract(0, 1, 0); - if (below.equals(block.getLocation())) { - signs.add(curr); - } - } - } - } - } - } - return signs; - } - - public static boolean isWallSign(Block block) - { - return block.getBlockData() instanceof WallSign; - } - - public static BlockFace getSignFacing(Block block) - { - return ((Sign)block.getBlockData()).getRotation(); - } - - public static void setSignFacing(Block block, BlockFace face) - { - ((Sign)block.getBlockData()).setRotation(face); - } - - public static String getNBTTag(ItemStack stack) - { - return new NBTTagable(stack).toString(); - } - - public static PotionInfo getNbtPotionInfo(PotionType type) - { - return potions.get(type); - } - - public static String getPotionInfo(ItemStack item) - { - ItemMeta meta = item.getItemMeta(); - if (meta instanceof PotionMeta) { - PotionData data = ((PotionMeta)meta).getBasePotionData(); - if (data.isExtended()) { - return Format.enchantments("(Extended)"); - } - else if (data.isUpgraded()) { - return Format.enchantments("II"); - } - } - return ""; - } -} \ No newline at end of file diff --git a/versions/1_14/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java b/versions/1_14/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java deleted file mode 100644 index 67042264..00000000 --- a/versions/1_14/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) Timothy Baxendale - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package org.tbax.baxshops.internal.items; - -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -public final class LegacyItem -{ - private int itemId; - private boolean legacy; - private String name; - - public LegacyItem(int itemId, String name, boolean legacy) - { - this.itemId = itemId; - this.name = name; - this.legacy = legacy; - } - - public int getItemId() - { - return itemId; - } - - public String getName() - { - return name; - } - - public boolean isLegacy() - { - return legacy; - } - - public ItemStack toItemStack(short damage) - { - Material material = Material.getMaterial(name, isLegacy()); - if (material == null) return null; - return new ItemStack(material, 1, damage); - } -} diff --git a/versions/1_8/README.md b/versions/1_8/README.md deleted file mode 100644 index bef8bf1d..00000000 --- a/versions/1_8/README.md +++ /dev/null @@ -1,4 +0,0 @@ -BaxShops -========= - -BaxShops is a shops plugin for Bukkit 1.8 diff --git a/versions/1_8/include/plugin.yml b/versions/1_8/include/plugin.yml deleted file mode 100644 index 25e5cef0..00000000 --- a/versions/1_8/include/plugin.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: BaxShops -main: org.tbax.baxshops.internal.ShopPlugin -description: Create and manage shops with a Vault economy -api-version: '1.8' -version: '1.0-beta.3' -commands: - shop: - description: manage shops - usage: | - /shop - §6Help: §f/shop help - aliases: s - buy: - description: buy from a shop - usage: | - /buy [amt] - sell: - description: sell to a shop - usage: | - /sell - restock: - description: restocks an item that is already in a shop with an item in hand - usage: | - /restock -permissions: - shops.*: - description: All Shops permissions - default: op - children: - shops.admin: true - shops.trader: true - shops.trader: - description: Allows you to buy and sell from shops - default: true - children: - shops.buy: true - shops.sell: true - shops.admin: - description: Allows you to create and remove shops - default: op - children: - shops.owner: true - shops.owner: - description: Allows you to create shops for yourself - default: true - children: - shops.trader: true - shops.buy: - description: Allows you to buy from shops - default: true - shops.sell: - description: Allows you to sell to shops - default: true diff --git a/versions/1_8/pom.xml b/versions/1_8/pom.xml deleted file mode 100644 index 812cfdbd..00000000 --- a/versions/1_8/pom.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - 4.0.0 - org.tbax.shops - baxshops - 1.0b3-bukkit1_8-RELEASE - jar - - UTF-8 - 1.7 - 1.7 - - - - - 3.1 - org.apache.maven.plugins - maven-compiler-plugin - - 8 - 8 - - - - - - include - - **/*.yml - **/*.txt - - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - pub-repo - http://nexus.hc.to/content/repositories/pub_releases/ - - - - - - - org.bukkit - bukkit - 1.8.8-R0.1-SNAPSHOT - provided - - - - - net.milkbowl.vault - Vault - 1.6.6 - provided - - - org.jetbrains - annotations - RELEASE - compile - - - diff --git a/versions/1_8/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java b/versions/1_8/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java deleted file mode 100644 index c0d743b8..00000000 --- a/versions/1_8/src/main/java/org/tbax/baxshops/internal/items/ItemUtil.java +++ /dev/null @@ -1,576 +0,0 @@ -/* - * Copyright (C) Timothy Baxendale - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package org.tbax.baxshops.internal.items; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import org.bukkit.*; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.block.banner.Pattern; -import org.bukkit.block.banner.PatternType; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BannerMeta; -import org.bukkit.inventory.meta.EnchantmentStorageMeta; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.potion.Potion; -import org.jetbrains.annotations.NotNull; -import org.tbax.baxshops.BaxEntry; -import org.tbax.baxshops.BaxShop; -import org.tbax.baxshops.Format; -import org.tbax.baxshops.internal.ShopPlugin; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.lang.reflect.Method; -import java.util.*; - -public final class ItemUtil -{ - private static final String MINECRAFT_VERSION; - private static final Method AS_NMS_COPY; - private static final Method GET_NAME; - - private static Map legacyItems = null; - private static Map legacyEnchants = null; - - private static final Map SIGN_TO_SIGN = new HashMap<>(); - - private static final List SIGN_TYPES = Arrays.asList(Material.SIGN, Material.SIGN_POST, Material.WALL_SIGN); - - static { - String name = Bukkit.getServer().getClass().getPackage().getName(); - MINECRAFT_VERSION = name.substring(name.lastIndexOf('.') + 1); - - Method nmsCpyMthd = null; - Method getNmMthd = null; - try { - Class itemStackCls = Class.forName("net.minecraft.server." + MINECRAFT_VERSION + ".ItemStack"); - nmsCpyMthd = Class.forName("org.bukkit.craftbukkit." + MINECRAFT_VERSION + ".inventory.CraftItemStack") - .getMethod("asNMSCopy", ItemStack.class); - getNmMthd = itemStackCls.getMethod("getName"); - } - catch (ReflectiveOperationException e) { - e.printStackTrace(); - } - AS_NMS_COPY = nmsCpyMthd; - GET_NAME = getNmMthd; - - SIGN_TO_SIGN.put(Material.WALL_SIGN, Material.SIGN); - SIGN_TO_SIGN.put(Material.SIGN_POST, Material.SIGN); - } - - /** - * A list of enchantment names - */ - private static final Map enchants = new HashMap<>(); - - private ItemUtil() - { - } - - public static List getItemFromAlias(String input, BaxShop shop) - { - String[] words = input.toUpperCase().split("_"); - String normalizedInput = input.replace('_', ' ').toUpperCase(); - - int maxMatch = -1; - List entries = new ArrayList<>(); - - for (BaxEntry entry : shop) { - String entryName = entry.getName().toUpperCase(); - if (Objects.equals(entryName, normalizedInput)) { - return Collections.singletonList(entry); // 100% match - } - else { - String[] entryWords = entryName.split(" "); - int matches = getMatches(entryWords, words); - if (matches == maxMatch) { - entries.add(entry); - } - else if (matches > maxMatch && matches > 0) { - entries.clear(); - entries.add(entry); - maxMatch = matches; - } - } - } - return entries; - } - - private static int getMatches(String[] array1, String[] array2) - { - int matches = 0; - for (String word1 : array1) { - for (String word2 : array2) { - if (word1.equals(word2)) { - ++matches; - } - } - } - return matches; - } - - /** - * Gets the name of an item. - * - * @param entry the shop entry - * @return the item's name - */ - public static String getName(BaxEntry entry) - { - return ItemUtil.getName(entry.getItemStack()); - } - - /** - * Gets the name of an item. - * - * @param item an item stack - * @return the item's name - */ - public static String getName(ItemStack item) - { - if (item.getType() == Material.ENCHANTED_BOOK) { - Map enchants = EnchantMap.getEnchants(item); - if (enchants != null) - return EnchantMap.fullListString(enchants); - } - else if (isOminousBanner(item)) { - return ChatColor.GOLD + "Ominous Banner"; - } - - item = item.clone(); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(null); - item.setItemMeta(meta); - } - try { - Object nmsCopy = AS_NMS_COPY.invoke(null, item); - Object txtObj = GET_NAME.invoke(nmsCopy); - try { - return (String)txtObj; - } - catch (ClassCastException e) { - return (String)txtObj.getClass().getMethod("getText").invoke(txtObj); - } - } - catch (ReflectiveOperationException | ClassCastException e) { - ShopPlugin.logWarning("Could not get item name for " + item.getType()); - return item.getType().toString(); - } - } - - public static boolean isOminousBanner(@NotNull ItemStack stack) - { - if (stack.getType() != Material.BANNER) - return false; - BannerMeta bannerMeta = (BannerMeta)stack.getItemMeta(); - return bannerMeta.getPatterns().containsAll(ominousPatterns()); - } - - private static List ominousPatterns() - { - Pattern[] patterns = new Pattern[8]; - patterns[0] = new Pattern(DyeColor.CYAN, PatternType.RHOMBUS_MIDDLE); - patterns[1] = new Pattern(DyeColor.SILVER, PatternType.STRIPE_BOTTOM); - patterns[2] = new Pattern(DyeColor.GRAY, PatternType.STRIPE_CENTER); - patterns[3] = new Pattern(DyeColor.SILVER, PatternType.BORDER); - patterns[4] = new Pattern(DyeColor.BLACK, PatternType.STRIPE_MIDDLE); - patterns[5] = new Pattern(DyeColor.SILVER, PatternType.HALF_HORIZONTAL); - patterns[6] = new Pattern(DyeColor.SILVER, PatternType.CIRCLE_MIDDLE); - patterns[7] = new Pattern(DyeColor.BLACK, PatternType.BORDER); - return Arrays.asList(patterns); - } - - public static String getEnchantName(Enchantment enchant) - { - Enchantable enchantable = enchants.get(enchant); - if (enchantable == null) - return Format.toFriendlyName(enchant.getName()); - return enchantable.getName(); - } - - /** - * Loads the enchantment names in enchants.txt - */ - public static void loadEnchants(ShopPlugin plugin) - { - try (InputStream stream = plugin.getResource("enchants.yml")) { - YamlConfiguration enchantConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(stream)); - List> section = enchantConfig.getMapList("enchants"); - - for (Map enchantMap : section) { - Enchantment enchantment = Enchantment.getByName((String)enchantMap.get("enchantment")); - if (enchantment != null) { - String name = (String)enchantMap.get("name"); - Object id = enchantMap.get("id"); - if (id instanceof Number) { - enchants.put(enchantment, new Enchantable(enchantment, name, ((Number)id).intValue())); - } - else { - enchants.put(enchantment, new Enchantable(enchantment, name)); - } - } - } - } - catch (IOException e) { - plugin.getLogger().warning("Failed to readFromDisk enchants: " + e.toString()); - } - } - - public static Enchantable getEnchantable(Enchantment enchantment) - { - Enchantable enchantable = enchants.get(enchantment); - if (enchantable == null) - return new Enchantable(enchantment, Format.toFriendlyName(enchantment.getName())); - return enchantable; - } - - public static boolean isSameBanner(ItemStack stack1, ItemStack stack2) - { - BannerMeta bannerMeta1, bannerMeta2; - if (stack1.getItemMeta() instanceof BannerMeta) { - bannerMeta1 = (BannerMeta)stack1.getItemMeta(); - } - else { - return false; - } - if (stack2.getItemMeta() instanceof BannerMeta) { - bannerMeta2 = (BannerMeta)stack2.getItemMeta(); - } - else { - return false; - } - if (stack1.getType() != stack2.getType()) - return false; - if (bannerMeta1.numberOfPatterns() != bannerMeta2.numberOfPatterns()) - return false; - for (int i = 0; i < bannerMeta1.numberOfPatterns(); ++i) { - if (!bannerMeta1.getPattern(i).equals(bannerMeta2.getPattern(i))) { - return false; - } - } - return true; - } - - public static boolean isSameBook(ItemStack stack1, ItemStack stack2) - { - EnchantmentStorageMeta enchantmentMeta1, enchantmentMeta2; - if (stack1.getType() != Material.ENCHANTED_BOOK || stack2.getType() != Material.ENCHANTED_BOOK) { - return false; - } - - enchantmentMeta1 = (EnchantmentStorageMeta)stack1.getItemMeta(); - enchantmentMeta2 = (EnchantmentStorageMeta)stack2.getItemMeta(); - - if (enchantmentMeta1.getStoredEnchants().size() != enchantmentMeta2.getStoredEnchants().size()) { - return false; - } - - for (Map.Entry enchants : enchantmentMeta1.getStoredEnchants().entrySet()) { - if (!Objects.equals(enchantmentMeta2.getStoredEnchants().get(enchants.getKey()), enchants.getValue())) { - return false; - } - } - - return true; - } - - public static boolean isSimilar(ItemStack stack1, ItemStack stack2, boolean smartStack) - { - if (stack1 == stack2) return true; - if (stack1 == null || stack2 == null) return false; - if (!smartStack) return stack1.isSimilar(stack2); - if (!stack1.isSimilar(stack2)) { - return stack1.getType() == stack2.getType() && - (isSameBook(stack1, stack2) || isSameBanner(stack1, stack2)); - } - return true; - } - - public static boolean isShop(ItemStack item) - { - return isSign(item) && - item.hasItemMeta() && - item.getItemMeta().hasLore() && - item.getItemMeta().getLore().get(item.getItemMeta().getLore().size() - 1).startsWith(ChatColor.GRAY + "ID: "); - } - - public static boolean isSign(ItemStack item) - { - return item != null && isSign(item.getType()); - } - - public static boolean isSign(Material type) - { - return type != null && SIGN_TYPES.contains(type); - } - - public static BaxShop fromItem(ItemStack item) - { - String id = item.getItemMeta().getLore().get(item.getItemMeta().getLore().size() - 1).substring((ChatColor.GRAY + "ID: ").length()); - BaxShop shop = ShopPlugin.getShopByShortId2(id); // try short id2 - if (shop == null) { - shop = ShopPlugin.getShopByShortId(id); // try short id - if (shop == null) { - try { - return ShopPlugin.getShop(UUID.fromString(id)); // finally try full id - } - catch (IllegalArgumentException e) { - return null; - } - } - } - return shop; - } - - public static String[] extractSignText(ItemStack item) - { - List lore = item.getItemMeta().getLore().subList(0, item.getItemMeta().getLore().size() - 1); - String[] lines = new String[lore.size()]; - for (int i = 0; i < lines.length; ++i) { - lines[i] = ChatColor.stripColor(lore.get(i)); - } - return lines; - } - - public static List getSignTypesAsItems() - { - ItemStack[] stacks = new ItemStack[SIGN_TYPES.size()]; - for (int i = 0; i < SIGN_TYPES.size(); ++i) { - stacks[i] = new ItemStack(SIGN_TYPES.get(i), 1); - } - return Arrays.asList(stacks); - } - - public static ItemStack newDefaultSign() - { - return new ItemStack(getDefaultSignType(), 1); - } - - public static Material getDefaultSignType() - { - return Material.SIGN; - } - - public static Material toInventorySign(Material sign) - { - Material m = SIGN_TO_SIGN.get(sign); - return m == null ? sign : m; - } - - public static Map all(Inventory inventory, List itemStacks) - { - Map all = new HashMap<>(); - for (int idx = 0; idx < inventory.getSize(); ++idx) { - ItemStack item = inventory.getItem(idx); - for (ItemStack other : itemStacks) { - if (other.isSimilar(item)) { - all.put(idx, other); - } - } - } - return all; - } - - @Deprecated - public static ItemStack fromItemId(int id) - { - return fromItemId(id, (short)0); - } - - @Deprecated - public static ItemStack fromItemId(int id, short damage) - { - LegacyItem item = legacyItems.get(id); - if (item == null) return null; - return item.toItemStack(damage); - } - - public static void loadLegacyItems(JavaPlugin plugin) throws IOException - { - legacyItems = new HashMap<>(); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource("legacy_items.txt")))) { - String line; - while ((line = reader.readLine()) != null) { - Scanner scanner = new Scanner(line); - LegacyItem item = new LegacyItem(scanner.nextInt(), scanner.next(), scanner.nextBoolean()); - legacyItems.put(item.getItemId(), item); - } - } - } - - public static void loadLegacyEnchants() - { - legacyEnchants = new HashMap<>(); - for (Map.Entry entry : enchants.entrySet()) { - try { - legacyEnchants.put(entry.getValue().getLegacyId(), entry.getKey()); - } - catch (UnsupportedOperationException e) { - // do not add - } - } - } - - @Deprecated - public static Enchantment getLegacyEnchantment(int id) - { - return legacyEnchants.get(id); - } - - public static int getDurability(ItemStack stack) - { - return stack.getDurability(); - } - - public static void setDurability(ItemStack stack, int durability) - { - stack.setDurability((short)durability); - } - - public static List getSignOnBlock(Block block) - { - List signs = new ArrayList<>(); - for (int x = -1; x <= 1; ++x) { - for (int y = -1; y <= 1; ++y) { - for (int z = -1; z <= 1; ++z) { - Location l = block.getLocation().add(x, y, z); - Block curr = l.getBlock(); - if (ItemUtil.isSign(curr.getType())) { - if (curr.getState().getData() instanceof org.bukkit.material.Sign) { - org.bukkit.material.Sign sign = (org.bukkit.material.Sign)curr.getState().getData(); - if (sign.isWallSign()) { - Block attached = curr.getRelative(sign.getFacing().getOppositeFace()); - if (attached.getLocation().equals(block.getLocation())) { - signs.add(curr); - } - } - else { - Location below = l.subtract(0, 1, 0); - if (below.equals(block.getLocation())) { - signs.add(curr); - } - } - } - } - } - } - } - return signs; - } - - public static boolean isWallSign(Block block) - { - BlockState blockState = block.getState(); - if (blockState.getData() instanceof org.bukkit.material.Sign) { - org.bukkit.material.Sign sign = (org.bukkit.material.Sign)blockState.getData(); - return sign.isWallSign(); - } - return false; - } - - public static BlockFace getSignFacing(Block block) - { - org.bukkit.material.Sign sign = (org.bukkit.material.Sign)block.getState().getData(); - return sign.getFacing(); - } - - public static void setSignFacing(Block block, BlockFace face) - { - BlockState blockState = block.getState(); - org.bukkit.material.Sign sign = (org.bukkit.material.Sign)blockState.getData(); - sign.setFacingDirection(face); - blockState.setData(sign); - blockState.update(); - } - - public static String getNBTTag(ItemStack stack) - { - JsonObject object = new JsonObject(); - object.addProperty("id", stack.getType().getId()); - object.addProperty("Count", stack.getAmount()); - if (stack.getType().getMaxDurability() > 0) { - object.addProperty("Damage", getDurability(stack)); - } - JsonObject tag = new JsonObject(); - if (stack.getEnchantments() != null && !stack.getEnchantments().isEmpty()) { - JsonArray enchantArray = new JsonArray(); - for (Map.Entry enchants : stack.getEnchantments().entrySet()) { - JsonObject enchantMap = new JsonObject(); - enchantMap.addProperty("id", enchants.getKey().getId() - ); - enchantMap.addProperty("lvl", enchants.getValue()); - enchantArray.add(enchantMap); - } - tag.add("Enchantments", enchantArray); - } - - JsonObject display = new JsonObject(); - if (stack.hasItemMeta()) { - ItemMeta itemMeta = stack.getItemMeta(); - if (itemMeta.hasDisplayName()) { - JsonObject text = new JsonObject(); - text.addProperty("text", stack.getItemMeta().getDisplayName()); - display.addProperty("Name", text.toString()); - } - if (itemMeta.hasLore()) { - JsonArray lore = new JsonArray(); - for (String line : itemMeta.getLore()) { - JsonObject text = new JsonObject(); - text.addProperty("text", line); - lore.add(new JsonPrimitive(text.toString())); - } - display.add("Lore", lore); - } - } - - if (!display.entrySet().isEmpty()) { - tag.add("display", display); - } - if (!tag.entrySet().isEmpty()) { - object.add("tag", tag); - } - ShopPlugin.logInfo(object.toString()); - return object.toString(); - } - - public static String getPotionInfo(ItemStack item) - { - if (item.getType() == Material.POTION) { - Potion potion = Potion.fromItemStack(item); - if (potion.hasExtendedDuration()) { - return Format.enchantments("(Extended)"); - } - else if (potion.getTier() == Potion.Tier.TWO) { - return Format.enchantments("II"); - } - } - return ""; - } -} \ No newline at end of file diff --git a/versions/1_8/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java b/versions/1_8/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java deleted file mode 100644 index a05dd083..00000000 --- a/versions/1_8/src/main/java/org/tbax/baxshops/internal/items/LegacyItem.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) Timothy Baxendale - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package org.tbax.baxshops.internal.items; - -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -public final class LegacyItem -{ - private int itemId; - private boolean legacy; - private String name; - - public LegacyItem(int itemId, String name, boolean legacy) - { - this.itemId = itemId; - this.name = name; - this.legacy = legacy; - } - - public int getItemId() - { - return itemId; - } - - public String getName() - { - return name; - } - - public boolean isLegacy() - { - return legacy; - } - - public ItemStack toItemStack(short damage) - { - Material material = Material.getMaterial(name); - if (material == null) return null; - return new ItemStack(material, 1, damage); - } -} diff --git a/versions/1_8/src/main/java/org/tbax/baxshops/internal/items/NBTTagable.java b/versions/1_8/src/main/java/org/tbax/baxshops/internal/items/NBTTagable.java deleted file mode 100644 index 6232ca6b..00000000 --- a/versions/1_8/src/main/java/org/tbax/baxshops/internal/items/NBTTagable.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (C) Timothy Baxendale - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package org.tbax.baxshops.internal.items; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.Potion; -import org.bukkit.potion.PotionEffect; - -import java.util.Map; - -public final class NBTTagable -{ - private ItemStack stack; - private ItemMeta itemMeta; - - public NBTTagable(ItemStack stack) - { - setStack(stack); - } - - public ItemStack getStack() - { - return stack.clone(); - } - - public void setStack(ItemStack stack) - { - this.stack = stack.clone(); - this.itemMeta = this.stack.getItemMeta(); - } - - public JsonElement getEnchantElement() - { - if (stack.getEnchantments() != null && !stack.getEnchantments().isEmpty()) { - JsonArray enchantArray = new JsonArray(); - for (Map.Entry enchants : stack.getEnchantments().entrySet()) { - JsonObject enchantMap = new JsonObject(); - enchantMap.addProperty("id", enchants.getKey().getId()); - enchantMap.addProperty("lvl", enchants.getValue()); - enchantArray.add(enchantMap); - } - return enchantArray; - } - return null; - } - - public JsonElement getLoreElement() - { - if (itemMeta.hasLore()) { - JsonArray lore = new JsonArray(); - for (String line : itemMeta.getLore()) { - JsonObject text = new JsonObject(); - text.addProperty("text", line); - lore.add(new JsonPrimitive(text.toString())); - } - return lore; - } - return null; - } - - public JsonElement getNameElement() - { - if (itemMeta.hasDisplayName()) { - JsonObject text = new JsonObject(); - text.addProperty("text", stack.getItemMeta().getDisplayName()); - return text; - } - return null; - } - - public JsonElement getDisplayElement() - { - JsonObject display = new JsonObject(); - JsonElement nameElement = getNameElement(); - if (nameElement != null) { - display.add("Name", nameElement); - } - JsonElement loreElement = getLoreElement(); - if (loreElement != null) { - display.add("Lore", loreElement); - } - if (display.entrySet().size() > 0) { - return display; - } - else { - return null; - } - } - - public JsonElement getTagElement() - { - JsonObject tag = new JsonObject(); - JsonElement enchantElement = getEnchantElement(); - if (enchantElement != null) { - tag.add("Enchantments", enchantElement); - } - JsonElement displayElement = getDisplayElement(); - if (displayElement != null) { - tag.add("display", displayElement); - } - - if (stack.getType() == Material.POTION) { - Potion potion = Potion.fromItemStack(stack); - PotionInfo potionInfo = ItemUtil.getNbtPotionInfo(potion.getType()); - - String name; - if (potionInfo == null) { - name = potion.getType().name().toLowerCase(); - } - else if (potion.hasExtendedDuration()) { - name = potionInfo.getExtendedNbtName(); - } - else if (potion.getTier() == Potion.Tier.TWO) { - name = potionInfo.getUpgradedNbtName(); - } - else { - name = potionInfo.getNbtName(); - } - - tag.addProperty("Potion", "minecraft:" + name); - JsonElement customPotionEffectsElement = getCustomPotionEffectsElement(); - if (customPotionEffectsElement != null) { - tag.add("CustomPotionEffects", customPotionEffectsElement); - } - } - - if (tag.entrySet().size() > 0) { - return tag; - } else { - return null; - } - } - - public JsonElement getCustomPotionEffectsElement() - { - if (itemMeta instanceof PotionMeta) { - PotionMeta potionMeta = (PotionMeta)itemMeta; - if (potionMeta.getCustomEffects() != null && !potionMeta.getCustomEffects().isEmpty()) { - JsonArray customPotionEffectElement = new JsonArray(); - for (PotionEffect effect : potionMeta.getCustomEffects()) { - JsonObject effectElement = new JsonObject(); - effectElement.addProperty("Id", effect.getType().getName()); - effectElement.addProperty("Amplifier", effect.getAmplifier()); - effectElement.addProperty("Duration", effect.getDuration()); - customPotionEffectElement.add(effectElement); - } - return customPotionEffectElement; - } - } - return null; - } - - public JsonElement asJsonElement() - { - JsonObject object = new JsonObject(); - object.addProperty("id", stack.getType().getId()); - object.addProperty("Count", stack.getAmount()); - if (stack.getType().getMaxDurability() > 0) { - object.addProperty("Damage", ItemUtil.getDurability(stack)); - } - JsonElement tag = getTagElement(); - if (tag != null) { - object.add("tag", tag); - } - return object; - } - - @Override - public String toString() - { - return asJsonElement().toString(); - } -} \ No newline at end of file diff --git a/versions/1_8/src/main/java/org/tbax/baxshops/internal/versioning/LegacyConfigUtil.java b/versions/1_8/src/main/java/org/tbax/baxshops/internal/versioning/LegacyConfigUtil.java deleted file mode 100644 index 1a4b559c..00000000 --- a/versions/1_8/src/main/java/org/tbax/baxshops/internal/versioning/LegacyConfigUtil.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) Timothy Baxendale - * Portions derived from Shops Copyright (c) 2012 Nathan Dinsmore and Sam Lazarus. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package org.tbax.baxshops.internal.versioning; - -import org.bukkit.configuration.file.FileConfiguration; - -public final class LegacyConfigUtil -{ - private LegacyConfigUtil() - { - } - - public static boolean configContains(FileConfiguration config, String key) { - return configContains(config, key, false); - } - - public static boolean configContains(FileConfiguration config, String key, boolean ignoreDefault) { - return (ignoreDefault ? config.get(key, null) : config.get(key)) != null; - } -} diff --git a/versions/1_8/src/main/java/org/tbax/baxshops/internal/versioning/LegacyOfflinePlayer.java b/versions/1_8/src/main/java/org/tbax/baxshops/internal/versioning/LegacyOfflinePlayer.java deleted file mode 100644 index 1605e142..00000000 --- a/versions/1_8/src/main/java/org/tbax/baxshops/internal/versioning/LegacyOfflinePlayer.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) Timothy Baxendale - * Portions derived from Shops Copyright (c) 2012 Nathan Dinsmore and Sam Lazarus. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package org.tbax.baxshops.internal.versioning; - -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; - -@Deprecated -public abstract class LegacyOfflinePlayer implements OfflinePlayer -{ - @Override - @Deprecated - public void setBanned(boolean b) - { - Bukkit.getOfflinePlayer(getUniqueId()).setBanned(b); - } -} diff --git a/versions/1_8/src/main/java/org/tbax/baxshops/internal/versioning/LegacyPlayerUtil.java b/versions/1_8/src/main/java/org/tbax/baxshops/internal/versioning/LegacyPlayerUtil.java deleted file mode 100644 index c71633c8..00000000 --- a/versions/1_8/src/main/java/org/tbax/baxshops/internal/versioning/LegacyPlayerUtil.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) Timothy Baxendale - * Portions derived from Shops Copyright (c) 2012 Nathan Dinsmore and Sam Lazarus. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package org.tbax.baxshops.internal.versioning; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; - -public final class LegacyPlayerUtil -{ - private LegacyPlayerUtil() - { - } - - public static ItemStack getItemInHand(Player player) - { - return getItemInHand(player.getInventory()); - } - - public static void setItemInHand(Player player, ItemStack stack) - { - setItemInHand(player.getInventory(), stack); - } - - public static void setItemInHand(PlayerInventory inventory, ItemStack stack) - { - inventory.setItemInHand(stack); - } - - public static ItemStack getItemInHand(PlayerInventory inventory) - { - return inventory.getItemInHand(); - } - - public static ItemStack[] getInventoryContents(Player player) - { - return player.getInventory().getContents(); - } -}