diff --git a/pom.xml b/pom.xml
index 6a25648ae..08d27e8b1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
org.maxgamer
QuickShop
- Reremake 1.0.8 beta-1
+ Reremake 1.0.8
diff --git a/src/main/java/org/maxgamer/quickshop/Listeners/WorldListener.java b/src/main/java/org/maxgamer/quickshop/Listeners/WorldListener.java
index afc2f0672..818b9905b 100644
--- a/src/main/java/org/maxgamer/quickshop/Listeners/WorldListener.java
+++ b/src/main/java/org/maxgamer/quickshop/Listeners/WorldListener.java
@@ -1,79 +1,82 @@
-package org.maxgamer.quickshop.Listeners;
-
-import java.util.HashMap;
-import java.util.Map.Entry;
-
-import org.bukkit.Chunk;
-import org.bukkit.Location;
-import org.bukkit.World;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.event.world.WorldLoadEvent;
-import org.bukkit.event.world.WorldUnloadEvent;
-import org.maxgamer.quickshop.QuickShop;
-import org.maxgamer.quickshop.Shop.Shop;
-import org.maxgamer.quickshop.Shop.ShopChunk;
-
-public class WorldListener implements Listener {
- QuickShop plugin;
-
- public WorldListener(QuickShop plugin) {
- this.plugin = plugin;
- }
-
- @EventHandler
- public void onWorldLoad(WorldLoadEvent e) {
- /* *************************************
- * This listener fixes any broken world references. Such as hashmap
- * lookups will fail, because the World reference is different, but the
- * world value is the same. ************************************
- */
- World world = e.getWorld();
- // New world data
- HashMap> inWorld = new HashMap>(1);
- // Old world data
- HashMap> oldInWorld = plugin.getShopManager().getShops(world.getName());
- // Nothing in the old world, therefore we don't care. No locations to
- // update.
- if (oldInWorld == null)
- return;
- for (Entry> oldInChunk : oldInWorld.entrySet()) {
- HashMap inChunk = new HashMap(1);
- // Put the new chunk were the old chunk was
- inWorld.put(oldInChunk.getKey(), inChunk);
- for (Entry entry : oldInChunk.getValue().entrySet()) {
- Shop shop = entry.getValue();
- shop.getLocation().setWorld(world);
- inChunk.put(shop.getLocation(), shop);
- }
- }
- // Done - Now we can store the new world dataz!
- plugin.getShopManager().getShops().put(world.getName(), inWorld);
- // This is a workaround, because I don't get parsed chunk events when a
- // world first loads....
- // So manually tell all of these shops they're loaded.
- for (Chunk chunk : world.getLoadedChunks()) {
- HashMap inChunk = plugin.getShopManager().getShops(chunk);
- if (inChunk == null)
- continue;
- for (Shop shop : inChunk.values()) {
- shop.onLoad();
- }
- }
- }
-
- @EventHandler
- public void onWorldUnload(WorldUnloadEvent e) {
- // This is a workaround, because I don't get parsed chunk events when a
- // world unloads, I think...
- // So manually tell all of these shops they're unloaded.
- for (Chunk chunk : e.getWorld().getLoadedChunks()) {
- HashMap inChunk = plugin.getShopManager().getShops(chunk);
- if (inChunk == null)
- continue;
- for (Shop shop : inChunk.values()) {
- shop.onUnload();
- }
- }
- }
+package org.maxgamer.quickshop.Listeners;
+
+import java.util.HashMap;
+import java.util.Map.Entry;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Chunk;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.world.WorldLoadEvent;
+import org.bukkit.event.world.WorldUnloadEvent;
+import org.maxgamer.quickshop.QuickShop;
+import org.maxgamer.quickshop.Shop.Shop;
+import org.maxgamer.quickshop.Shop.ShopChunk;
+
+public class WorldListener implements Listener {
+ QuickShop plugin;
+
+ public WorldListener(QuickShop plugin) {
+ this.plugin = plugin;
+ }
+
+ @EventHandler
+ public void onWorldLoad(WorldLoadEvent e) {
+ Bukkit.getServer().broadcastMessage("´¥·¢WorldLoadEvent");
+ /* *************************************
+ * This listener fixes any broken world references. Such as hashmap
+ * lookups will fail, because the World reference is different, but the
+ * world value is the same. ************************************
+ */
+ World world = e.getWorld();
+ // New world data
+ HashMap> inWorld = new HashMap>(1);
+ // Old world data
+ HashMap> oldInWorld = plugin.getShopManager().getShops(world.getName());
+ // Nothing in the old world, therefore we don't care. No locations to
+ // update.
+ if (oldInWorld == null)
+ return;
+ for (Entry> oldInChunk : oldInWorld.entrySet()) {
+ HashMap inChunk = new HashMap(1);
+ // Put the new chunk were the old chunk was
+ inWorld.put(oldInChunk.getKey(), inChunk);
+ for (Entry entry : oldInChunk.getValue().entrySet()) {
+ Shop shop = entry.getValue();
+ shop.getLocation().setWorld(world);
+ inChunk.put(shop.getLocation(), shop);
+ }
+ }
+ // Done - Now we can store the new world dataz!
+ plugin.getShopManager().getShops().put(world.getName(), inWorld);
+ // This is a workaround, because I don't get parsed chunk events when a
+ // world first loads....
+ // So manually tell all of these shops they're loaded.
+ for (Chunk chunk : world.getLoadedChunks()) {
+ HashMap inChunk = plugin.getShopManager().getShops(chunk);
+ if (inChunk == null)
+ continue;
+ for (Shop shop : inChunk.values()) {
+ shop.onLoad();
+ }
+ }
+ }
+
+ @EventHandler
+ public void onWorldUnload(WorldUnloadEvent e) {
+ Bukkit.getServer().broadcastMessage("´¥·¢WorldUnloadEvent");
+ // This is a workaround, because I don't get parsed chunk events when a
+ // world unloads, I think...
+ // So manually tell all of these shops they're unloaded.
+ for (Chunk chunk : e.getWorld().getLoadedChunks()) {
+ HashMap inChunk = plugin.getShopManager().getShops(chunk);
+ if (inChunk == null)
+ continue;
+ for (Shop shop : inChunk.values()) {
+ shop.onUnload();
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java
index 0e6867645..1ad32daac 100644
--- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java
+++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java
@@ -1,712 +1,714 @@
-package org.maxgamer.quickshop.Shop;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.UUID;
-import java.util.logging.Level;
-
-import org.bukkit.Bukkit;
-import org.bukkit.Location;
-import org.bukkit.Material;
-import org.bukkit.block.Block;
-import org.bukkit.block.Sign;
-import org.bukkit.enchantments.Enchantment;
-import org.bukkit.entity.Item;
-import org.bukkit.entity.Player;
-import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
-import org.bukkit.inventory.Inventory;
-import org.bukkit.inventory.InventoryHolder;
-import org.bukkit.inventory.ItemStack;
-import org.maxgamer.quickshop.QuickShop;
-import org.maxgamer.quickshop.Util.MsgUtil;
-import org.maxgamer.quickshop.Util.Util;
-
-public class ContainerShop implements Shop {
- private Location loc;
- private double price;
- private UUID owner;
- private ItemStack item;
- private DisplayItem displayItem;
- private boolean unlimited;
- private ShopType shopType;
- private QuickShop plugin;
-
- /**
- * Returns a clone of this shop. References to the same display item,
- * itemstack, location and owner as this shop does. Do not modify them or
- * you will modify this shop.
- *
- * **NOT A DEEP CLONE**
- */
- public ContainerShop clone() {
- return new ContainerShop(this);
- }
-
- private ContainerShop(ContainerShop s) {
- this.displayItem = s.displayItem;
- this.shopType = s.shopType;
- this.item = s.item;
- this.loc = s.loc;
- this.plugin = s.plugin;
- this.unlimited = s.unlimited;
- this.owner = s.owner;
- this.price = s.price;
- }
-
- /**
- * Adds a new shop.
- *
- * @param loc
- * The location of the chest block
- * @param price
- * The cost per item
- * @param item
- * The itemstack with the properties we want. This is .cloned, no
- * need to worry about references
- * @param owner
- * The player who owns this shop.
- */
- public ContainerShop(Location loc, double price, ItemStack item, UUID owner) {
- this.loc = loc;
- this.price = price;
- this.owner = owner;
- this.item = item.clone();
- this.plugin = (QuickShop) Bukkit.getPluginManager().getPlugin("QuickShop");
- this.item.setAmount(1);
- if (plugin.display) {
- this.displayItem = new DisplayItem(this, this.item);
- }
- this.shopType = ShopType.SELLING;
- }
-
- /**
- * Returns the number of items this shop has in stock.
- *
- * @return The number of items available for purchase.
- */
- public int getRemainingStock() {
- if (this.unlimited)
- return 10000;
- return Util.countItems(this.getInventory(), this.getItem());
- }
-
- /**
- * Returns the number of free spots in the chest for the particular item.
- *
- * @param stackSize
- * @return
- */
- public int getRemainingSpace() {
- if (this.unlimited)
- return 10000;
- return Util.countSpace(this.getInventory(), item);
- }
-
- /**
- * Returns true if the ItemStack matches what this shop is selling/buying
- *
- * @param item
- * The ItemStack
- * @return True if the ItemStack is the same (Excludes amounts)
- */
- public boolean matches(ItemStack item) {
- return Util.matches(this.item, item);
- }
-
- /**
- * Returns the shop that shares it's inventory with this one.
- *
- * @return the shop that shares it's inventory with this one. Will return
- * null if this shop is not attached to another.
- */
- public ContainerShop getAttachedShop() {
- Block c = Util.getSecondHalf(this.getLocation().getBlock());
- if (c == null)
- return null;
- Shop shop = plugin.getShopManager().getShop(c.getLocation());
- return shop == null ? null : (ContainerShop) shop;
- }
-
- /**
- * Returns true if this shop is a double chest, and the other half is
- * selling/buying the same as this is buying/selling.
- *
- * @return true if this shop is a double chest, and the other half is
- * selling/buying the same as this is buying/selling.
- */
- public boolean isDoubleShop() {
- ContainerShop nextTo = this.getAttachedShop();
- if (nextTo == null) {
- return false;
- }
- if (nextTo.matches(this.getItem())) {
- // They're both trading the same item
- if (this.getShopType() == nextTo.getShopType()) {
- // They're both buying or both selling => Not a double shop,
- // just two shops.
- return false;
- } else {
- // One is buying, one is selling.
- return true;
- }
- } else {
- return false;
- }
- }
-
- /**
- * @return The location of the shops chest
- */
- public Location getLocation() {
- return this.loc;
- }
-
- /**
- * @return The price per item this shop is selling
- */
- public double getPrice() {
- return this.price;
- }
-
- /**
- * Sets the price of the shop. Does not update it in the database. Use
- * shop.update() for that.
- *
- * @param price
- * The new price of the shop.
- */
- public void setPrice(double price) {
- this.price = price;
- }
-
- /**
- * @return The ItemStack type of this shop
- */
- public Material getMaterial() {
- return this.item.getType();
- }
-
- /**
- * Upates the shop into the database.
- */
- public void update() {
- int x = this.getLocation().getBlockX();
- int y = this.getLocation().getBlockY();
- int z = this.getLocation().getBlockZ();
- String world = this.getLocation().getWorld().getName();
- int unlimited = this.isUnlimited() ? 1 : 0;
- String q = "UPDATE shops SET owner = ?, itemConfig = ?, unlimited = ?, type = ?, price = ? WHERE x = ? AND y = ? and z = ? and world = ?";
- try {
- plugin.getDB().execute(q, this.getOwner().toString(), Util.serialize(this.getItem()), unlimited, shopType.toID(), this.getPrice(), x, y, z, world);
- } catch (Exception e) {
- e.printStackTrace();
- System.out.println("Could not update shop in database! Changes will revert after a reboot!");
- }
- }
-
- /**
- * @return The durability of the item
- */
- public short getDurability() {
- return this.item.getDurability();
- }
-
- /**
- * @return The chest this shop is based on.
- */
- public Inventory getInventory() throws IllegalStateException {
- InventoryHolder container;
- try {
- container = (InventoryHolder) this.loc.getBlock().getState();
- return container.getInventory();
- } catch (Exception e) {
- throw new IllegalStateException("Inventory doesn't exist anymore: "+this);
- }
- }
-
- /**
- * @return The name of the player who owns the shop.
- */
- public UUID getOwner() {
- return this.owner;
- }
-
- /**
- * @return The enchantments the shop has on its items.
- */
- public Map getEnchants() {
- return this.item.getItemMeta().getEnchants();
- }
-
- /**
- * @return Returns a dummy itemstack of the item this shop is selling.
- */
- public ItemStack getItem() {
- return item;
- }
-
- /**
- * Removes an item from the shop.
- *
- * @param item
- * The itemstack. The amount does not matter, just everything
- * else
- * @param amount
- * The amount to remove from the shop.
- */
- public void remove(ItemStack item, int amount) {
- if (this.unlimited)
- return;
- Inventory inv = this.getInventory();
- int remains = amount;
- while (remains > 0) {
- int stackSize = Math.min(remains, item.getMaxStackSize());
- item.setAmount(stackSize);
- inv.removeItem(item);
- remains = remains - stackSize;
- }
- }
-
- /**
- * Add an item to shops chest.
- *
- * @param item
- * The itemstack. The amount does not matter, just everything
- * else
- * @param amount
- * The amount to add to the shop.
- */
- public void add(ItemStack item, int amount) {
- if (this.unlimited)
- return;
- Inventory inv = this.getInventory();
- int remains = amount;
- while (remains > 0) {
- int stackSize = Math.min(remains, item.getMaxStackSize());
- item.setAmount(stackSize);
- inv.addItem(item);
- remains = remains - stackSize;
- }
- }
-
- /**
- * Sells amount of item to Player p. Does NOT check our inventory, or
- * balances
- *
- * @param p
- * The player to sell to
- * @param amount
- * The amount to sell
- */
- public void sell(Player p, int amount) {
- if (amount < 0)
- this.buy(p, -amount);
- // Items to drop on floor
- ArrayList floor = new ArrayList(5);
- Inventory pInv = p.getInventory();
- if (this.isUnlimited()) {
- ItemStack item = this.item.clone();
- while (amount > 0) {
- int stackSize = Math.min(amount, this.item.getMaxStackSize());
- item.setAmount(stackSize);
- pInv.addItem(item);
- amount -= stackSize;
- }
- } else {
- ItemStack[] chestContents = this.getInventory().getContents();
- for (int i = 0; amount > 0 && i < chestContents.length; i++) {
- // Can't clone it here, it could be null
- ItemStack item = chestContents[i];
- if (item != null && this.matches(item)) {
- // Copy it, we don't want to interfere
- item = item.clone();
- // Amount = total, item.getAmount() = how many items in the
- // stack
- int stackSize = Math.min(amount, item.getAmount());
- // If Amount is item.getAmount(), then this sets the amount
- // to 0
- // Else it sets it to the remainder
- chestContents[i].setAmount(chestContents[i].getAmount() - stackSize);
- // We can modify this, it is a copy.
- item.setAmount(stackSize);
- // Add the items to the players inventory
- floor.addAll(pInv.addItem(item).values());
- amount -= stackSize;
- }
- }
- // We now have to update the chests inventory manually.
- this.getInventory().setContents(chestContents);
- }
- for (int i = 0; i < floor.size(); i++) {
- p.getWorld().dropItem(p.getLocation(), floor.get(i));
- }
- }
-
- /**
- * Buys amount of item from Player p. Does NOT check our inventory, or
- * balances
- *
- * @param p
- * The player to buy from
- * @param item
- * The itemStack to buy
- * @param amount
- * The amount to buy
- */
- public void buy(Player p, int amount) {
- if (amount < 0)
- this.sell(p, -amount);
- if (this.isUnlimited()) {
- ItemStack[] contents = p.getInventory().getContents();
- for (int i = 0; amount > 0 && i < contents.length; i++) {
- ItemStack stack = contents[i];
- if (stack == null)
- continue; // No item
- if (matches(stack)) {
- int stackSize = Math.min(amount, stack.getAmount());
- stack.setAmount(stack.getAmount() - stackSize);
- amount -= stackSize;
- }
- }
- // Send the players new inventory to them
- p.getInventory().setContents(contents);
- // This should not happen.
- if (amount > 0) {
- plugin.getLogger().log(Level.WARNING, "Could not take all items from a players inventory on purchase! " + p.getName() + ", missing: " + amount + ", item: " + this.getDataName() + "!");
- }
- } else {
- ItemStack[] playerContents = p.getInventory().getContents();
- Inventory chestInv = this.getInventory();
- for (int i = 0; amount > 0 && i < playerContents.length; i++) {
- ItemStack item = playerContents[i];
- if (item != null && this.matches(item)) {
- // Copy it, we don't want to interfere
- item = item.clone();
- // Amount = total, item.getAmount() = how many items in the
- // stack
- int stackSize = Math.min(amount, item.getAmount());
- // If Amount is item.getAmount(), then this sets the amount
- // to 0
- // Else it sets it to the remainder
- playerContents[i].setAmount(playerContents[i].getAmount() - stackSize);
- // We can modify this, it is a copy.
- item.setAmount(stackSize);
- // Add the items to the players inventory
- chestInv.addItem(item);
- amount -= stackSize;
- }
- }
- // Now update the players inventory.
- p.getInventory().setContents(playerContents);
- }
- }
-
- /**
- * Changes the owner of this shop to the given player.
- *
- * @param owner
- * The name of the owner. You must do shop.update() after to save
- * it after a reboot.
- */
- public void setOwner(UUID owner) {
- this.owner = owner;
- }
-
- /**
- * Returns the display item associated with this shop.
- *
- * @return The display item associated with this shop.
- */
- public DisplayItem getDisplayItem() {
- return this.displayItem;
- }
-
- public void setUnlimited(boolean unlimited) {
- this.unlimited = unlimited;
- }
-
- public boolean isUnlimited() {
- return this.unlimited;
- }
-
- public ShopType getShopType() {
- return this.shopType;
- }
-
- public boolean isBuying() {
- return this.shopType == ShopType.BUYING;
- }
-
- public boolean isSelling() {
- return this.shopType == ShopType.SELLING;
- }
-
- /**
- * Changes a shop type to Buying or Selling. Also updates the signs nearby.
- *
- * @param shopType
- * The new type (ShopType.BUYING or ShopType.SELLING)
- */
- public void setShopType(ShopType shopType) {
- this.shopType = shopType;
- this.setSignText();
- }
-
- /**
- * Updates signs attached to the shop
- */
- public void setSignText() {
- if (Util.isLoaded(this.getLocation()) == false)
- return;
- String[] lines = new String[4];
- lines[0] = MsgUtil.getMessage("signs.header", this.ownerName());
- if (this.isSelling()) {
- lines[1] = MsgUtil.getMessage("signs.selling", "" + this.getRemainingStock());
- } else if (this.isBuying()) {
- lines[1] = MsgUtil.getMessage("signs.buying", "" + this.getRemainingSpace());
- }
- lines[2] = MsgUtil.getMessage("signs.item", Util.getNameForSign(this.item));
- lines[3] = MsgUtil.getMessage("signs.price", Util.format(this.getPrice()));
- this.setSignText(lines);
- }
-
- /**
- * Changes all lines of text on a sign near the shop
- *
- * @param lines
- * The array of lines to change. Index is line number.
- */
- public void setSignText(String[] lines) {
- if (Util.isLoaded(this.getLocation()) == false)
- return;
- for (Sign sign : this.getSigns()) {
- for (int i = 0; i < lines.length; i++) {
- sign.setLine(i, lines[i].length() < 16 ? lines[i] : lines[i].substring(0, 15));
- }
- sign.update();
- }
- }
-
- /**
- * Returns a list of signs that are attached to this shop (QuickShop and
- * blank signs only)
- *
- * @return a list of signs that are attached to this shop (QuickShop and
- * blank signs only)
- */
- public List getSigns() {
- ArrayList signs = new ArrayList(1);
- if (this.getLocation().getWorld() == null)
- return signs;
- Block[] blocks = new Block[4];
- blocks[0] = loc.getBlock().getRelative(1, 0, 0);
- blocks[1] = loc.getBlock().getRelative(-1, 0, 0);
- blocks[2] = loc.getBlock().getRelative(0, 0, 1);
- blocks[3] = loc.getBlock().getRelative(0, 0, -1);
- final String signHeader = MsgUtil.getMessage("signs.header", "");
- for (Block b : blocks) {
- if (b.getType() != Material.WALL_SIGN)
- continue;
- if (!isAttached(b))
- continue;
- Sign sign = (Sign) b.getState();
- if (sign.getLine(0).contains(signHeader)) {
- signs.add(sign);
- } else {
- boolean text = false;
- for (String s : sign.getLines()) {
- if (!s.isEmpty()) {
- text = true;
- break;
- }
- }
- if (!text) {
- signs.add(sign);
- }
- }
- }
- return signs;
- }
-
- public boolean isAttached(Block b) {
- if (b.getType() != Material.WALL_SIGN)
- new IllegalArgumentException(b + " Is not a sign!").printStackTrace();
- return this.getLocation().getBlock().equals(Util.getAttached(b));
- }
-
- /**
- * Convenience method. Equivilant to
- * org.maxgamer.quickshop.Util.getName(shop.getItem()).
- *
- * @return The name of this shops item
- */
- public String getDataName() {
- return Util.getName(this.getItem());
- }
-
- /**
- * Deletes the shop from the list of shops and queues it for database
- * deletion *DOES* delete it from memory
- */
- public void delete() {
- delete(true);
- }
-
- /**
- * Deletes the shop from the list of shops and queues it for database
- * deletion
- *
- * @param fromMemory
- * True if you are *NOT* iterating over this currently, *false if
- * you are iterating*
- */
- public void delete(boolean fromMemory) {
- // Delete the display item
- if (this.getDisplayItem() != null) {
- this.getDisplayItem().remove();
- }
- // Delete the signs around it
- for (Sign s : this.getSigns()) {
- s.getBlock().setType(Material.AIR);
- }
- // Delete it from the database
- int x = this.getLocation().getBlockX();
- int y = this.getLocation().getBlockY();
- int z = this.getLocation().getBlockZ();
- String world = this.getLocation().getWorld().getName();
- plugin.getDB().execute("DELETE FROM shops WHERE x = '" + x + "' AND y = '" + y + "' AND z = '" + z + "' AND world = '" + world + "'");
- // Refund if necessary
- if (plugin.getConfig().getBoolean("shop.refund")) {
- plugin.getEcon().deposit(this.getOwner(), plugin.getConfig().getDouble("shop.cost"));
- }
- if (fromMemory) {
- // Delete it from memory
- plugin.getShopManager().removeShop(this);
- }
- }
-
- public boolean isValid() {
- checkDisplay();
- return Util.canBeShop(this.getLocation().getBlock());
- }
-
- private void checkDisplay() {
- if (plugin.display == false)
- return;
- if (getLocation().getWorld() == null)
- return; // not loaded
- boolean trans = Util.isTransparent(getLocation().clone().add(0.5, 1.2, 0.5).getBlock().getType());
- if (trans && this.getDisplayItem() == null) {
- this.displayItem = new DisplayItem(this, this.getItem());
- this.getDisplayItem().spawn();
- }
- if (this.getDisplayItem() != null) {
- if (!trans) { // We have a display item in a block... delete it
- this.getDisplayItem().remove();
- this.displayItem = null;
- return;
- }
- DisplayItem disItem = this.getDisplayItem();
- Location dispLoc = disItem.getDisplayLocation();
- if (dispLoc.getBlock() != null && dispLoc.getBlock().getType() == Material.WATER) {
- disItem.remove();
- return;
- }
- if (disItem.getItem() == null) {
- disItem.removeDupe();
- disItem.spawn();
- return;
- }
- Item item = disItem.getItem();
- if (item.getTicksLived() > 5000 || !item.isValid() || item.isDead()) {
- disItem.respawn();
- disItem.removeDupe();
- } else if (item.getLocation().distanceSquared(dispLoc) > 1) {
- item.teleport(dispLoc, TeleportCause.PLUGIN);
- }
- }
- }
-
- public boolean checkDisplayMoved() {
- // don't check if the plugin doesn't know about the object
- if (this.getDisplayItem() == null) {
- return false;
- }
-
- Item item = this.getDisplayItem().getItem();
- if (item == null) {
- return false;
- }
-
- if (item.isDead()) {
- return false;
- }
-
- // don't check if the chunk is not loaded
- if (!item.getLocation().getWorld().isChunkLoaded(item.getLocation().getChunk())) {
- return false;
- }
-
- return this.getDisplayItem().getDisplayLocation().distanceSquared(item.getLocation()) > 0.2;
- }
-
- public void onUnload() {
- if (this.getDisplayItem() != null) {
- this.getDisplayItem().remove();
- this.displayItem = null;
- }
- }
-
- public void onLoad() {
- checkDisplay();
-
- // update sign
- this.setSignText();
-
- // check price restriction
- Entry priceRestriction = Util.getPriceRestriction(this.getMaterial());
- if (priceRestriction!=null) {
- if (pricepriceRestriction.getValue()) {
- price=priceRestriction.getValue();
- this.update();
- }
- }
- }
-
- public void onClick() {
- this.setSignText();
- }
-
- public String ownerName() {
- if (this.isUnlimited()) {
- return MsgUtil.getMessage("admin-shop");
- }
-
- if (this.getOwner() == null) {
- return MsgUtil.getMessage("unknown-owner");
- }
-
- final String name = Bukkit.getOfflinePlayer(this.getOwner()).getName();
- if (name == null) {
- return MsgUtil.getMessage("unknown-owner");
- }
-
- return name;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("Shop " + (loc.getWorld() == null ? "unloaded world" : loc.getWorld().getName()) + "(" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ")");
- sb.append(" Owner: " + this.ownerName() + " - " + getOwner().toString());
- if (isUnlimited())
- sb.append(" Unlimited: true");
- sb.append(" Price: " + getPrice());
- sb.append(" Item: " + getItem().toString());
- return sb.toString();
- }
+package org.maxgamer.quickshop.Shop;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.UUID;
+import java.util.logging.Level;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.Sign;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.Item;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.InventoryHolder;
+import org.bukkit.inventory.ItemStack;
+import org.maxgamer.quickshop.QuickShop;
+import org.maxgamer.quickshop.Util.MsgUtil;
+import org.maxgamer.quickshop.Util.Util;
+
+public class ContainerShop implements Shop {
+ private Location loc;
+ private double price;
+ private UUID owner;
+ private ItemStack item;
+ private DisplayItem displayItem;
+ private boolean unlimited;
+ private ShopType shopType;
+ private QuickShop plugin;
+
+ /**
+ * Returns a clone of this shop. References to the same display item,
+ * itemstack, location and owner as this shop does. Do not modify them or
+ * you will modify this shop.
+ *
+ * **NOT A DEEP CLONE**
+ */
+ public ContainerShop clone() {
+ return new ContainerShop(this);
+ }
+
+ private ContainerShop(ContainerShop s) {
+ this.displayItem = s.displayItem;
+ this.shopType = s.shopType;
+ this.item = s.item;
+ this.loc = s.loc;
+ this.plugin = s.plugin;
+ this.unlimited = s.unlimited;
+ this.owner = s.owner;
+ this.price = s.price;
+ }
+
+ /**
+ * Adds a new shop.
+ *
+ * @param loc
+ * The location of the chest block
+ * @param price
+ * The cost per item
+ * @param item
+ * The itemstack with the properties we want. This is .cloned, no
+ * need to worry about references
+ * @param owner
+ * The player who owns this shop.
+ */
+ public ContainerShop(Location loc, double price, ItemStack item, UUID owner) {
+ this.loc = loc;
+ this.price = price;
+ this.owner = owner;
+ this.item = item.clone();
+ this.plugin = (QuickShop) Bukkit.getPluginManager().getPlugin("QuickShop");
+ this.item.setAmount(1);
+ if (plugin.display) {
+ this.displayItem = new DisplayItem(this, this.item);
+ }
+ this.shopType = ShopType.SELLING;
+ }
+
+ /**
+ * Returns the number of items this shop has in stock.
+ *
+ * @return The number of items available for purchase.
+ */
+ public int getRemainingStock() {
+ if (this.unlimited)
+ return 10000;
+ return Util.countItems(this.getInventory(), this.getItem());
+ }
+
+ /**
+ * Returns the number of free spots in the chest for the particular item.
+ *
+ * @param stackSize
+ * @return
+ */
+ public int getRemainingSpace() {
+ if (this.unlimited)
+ return 10000;
+ return Util.countSpace(this.getInventory(), item);
+ }
+
+ /**
+ * Returns true if the ItemStack matches what this shop is selling/buying
+ *
+ * @param item
+ * The ItemStack
+ * @return True if the ItemStack is the same (Excludes amounts)
+ */
+ public boolean matches(ItemStack item) {
+ return Util.matches(this.item, item);
+ }
+
+ /**
+ * Returns the shop that shares it's inventory with this one.
+ *
+ * @return the shop that shares it's inventory with this one. Will return
+ * null if this shop is not attached to another.
+ */
+ public ContainerShop getAttachedShop() {
+ Block c = Util.getSecondHalf(this.getLocation().getBlock());
+ if (c == null)
+ return null;
+ Shop shop = plugin.getShopManager().getShop(c.getLocation());
+ return shop == null ? null : (ContainerShop) shop;
+ }
+
+ /**
+ * Returns true if this shop is a double chest, and the other half is
+ * selling/buying the same as this is buying/selling.
+ *
+ * @return true if this shop is a double chest, and the other half is
+ * selling/buying the same as this is buying/selling.
+ */
+ public boolean isDoubleShop() {
+ ContainerShop nextTo = this.getAttachedShop();
+ if (nextTo == null) {
+ return false;
+ }
+ if (nextTo.matches(this.getItem())) {
+ // They're both trading the same item
+ if (this.getShopType() == nextTo.getShopType()) {
+ // They're both buying or both selling => Not a double shop,
+ // just two shops.
+ return false;
+ } else {
+ // One is buying, one is selling.
+ return true;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @return The location of the shops chest
+ */
+ public Location getLocation() {
+ return this.loc;
+ }
+
+ /**
+ * @return The price per item this shop is selling
+ */
+ public double getPrice() {
+ return this.price;
+ }
+
+ /**
+ * Sets the price of the shop. Does not update it in the database. Use
+ * shop.update() for that.
+ *
+ * @param price
+ * The new price of the shop.
+ */
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+ /**
+ * @return The ItemStack type of this shop
+ */
+ public Material getMaterial() {
+ return this.item.getType();
+ }
+
+ /**
+ * Upates the shop into the database.
+ */
+ public void update() {
+ int x = this.getLocation().getBlockX();
+ int y = this.getLocation().getBlockY();
+ int z = this.getLocation().getBlockZ();
+ String world = this.getLocation().getWorld().getName();
+ int unlimited = this.isUnlimited() ? 1 : 0;
+ String q = "UPDATE shops SET owner = ?, itemConfig = ?, unlimited = ?, type = ?, price = ? WHERE x = ? AND y = ? and z = ? and world = ?";
+ try {
+ plugin.getDB().execute(q, this.getOwner().toString(), Util.serialize(this.getItem()), unlimited, shopType.toID(), this.getPrice(), x, y, z, world);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.out.println("Could not update shop in database! Changes will revert after a reboot!");
+ }
+ }
+
+ /**
+ * @return The durability of the item
+ */
+ public short getDurability() {
+ return this.item.getDurability();
+ }
+
+ /**
+ * @return The chest this shop is based on.
+ */
+ public Inventory getInventory() throws IllegalStateException {
+ InventoryHolder container;
+ try {
+ container = (InventoryHolder) this.loc.getBlock().getState();
+ return container.getInventory();
+ } catch (Exception e) {
+ throw new IllegalStateException("Inventory doesn't exist anymore: "+this);
+ }
+ }
+
+ /**
+ * @return The name of the player who owns the shop.
+ */
+ public UUID getOwner() {
+ return this.owner;
+ }
+
+ /**
+ * @return The enchantments the shop has on its items.
+ */
+ public Map getEnchants() {
+ return this.item.getItemMeta().getEnchants();
+ }
+
+ /**
+ * @return Returns a dummy itemstack of the item this shop is selling.
+ */
+ public ItemStack getItem() {
+ return item;
+ }
+
+ /**
+ * Removes an item from the shop.
+ *
+ * @param item
+ * The itemstack. The amount does not matter, just everything
+ * else
+ * @param amount
+ * The amount to remove from the shop.
+ */
+ public void remove(ItemStack item, int amount) {
+ Bukkit.getServer().broadcastMessage("´¥·¢remove");
+ if (this.unlimited)
+ return;
+ Inventory inv = this.getInventory();
+ int remains = amount;
+ while (remains > 0) {
+ int stackSize = Math.min(remains, item.getMaxStackSize());
+ item.setAmount(stackSize);
+ inv.removeItem(item);
+ remains = remains - stackSize;
+ }
+ }
+
+ /**
+ * Add an item to shops chest.
+ *
+ * @param item
+ * The itemstack. The amount does not matter, just everything
+ * else
+ * @param amount
+ * The amount to add to the shop.
+ */
+ public void add(ItemStack item, int amount) {
+ if (this.unlimited)
+ return;
+ Inventory inv = this.getInventory();
+ int remains = amount;
+ while (remains > 0) {
+ int stackSize = Math.min(remains, item.getMaxStackSize());
+ item.setAmount(stackSize);
+ inv.addItem(item);
+ remains = remains - stackSize;
+ }
+ }
+
+ /**
+ * Sells amount of item to Player p. Does NOT check our inventory, or
+ * balances
+ *
+ * @param p
+ * The player to sell to
+ * @param amount
+ * The amount to sell
+ */
+ public void sell(Player p, int amount) {
+ if (amount < 0)
+ this.buy(p, -amount);
+ // Items to drop on floor
+ ArrayList floor = new ArrayList(5);
+ Inventory pInv = p.getInventory();
+ if (this.isUnlimited()) {
+ ItemStack item = this.item.clone();
+ while (amount > 0) {
+ int stackSize = Math.min(amount, this.item.getMaxStackSize());
+ item.setAmount(stackSize);
+ pInv.addItem(item);
+ amount -= stackSize;
+ }
+ } else {
+ ItemStack[] chestContents = this.getInventory().getContents();
+ for (int i = 0; amount > 0 && i < chestContents.length; i++) {
+ // Can't clone it here, it could be null
+ ItemStack item = chestContents[i];
+ if (item != null && this.matches(item)) {
+ // Copy it, we don't want to interfere
+ item = item.clone();
+ // Amount = total, item.getAmount() = how many items in the
+ // stack
+ int stackSize = Math.min(amount, item.getAmount());
+ // If Amount is item.getAmount(), then this sets the amount
+ // to 0
+ // Else it sets it to the remainder
+ chestContents[i].setAmount(chestContents[i].getAmount() - stackSize);
+ // We can modify this, it is a copy.
+ item.setAmount(stackSize);
+ // Add the items to the players inventory
+ floor.addAll(pInv.addItem(item).values());
+ amount -= stackSize;
+ }
+ }
+ // We now have to update the chests inventory manually.
+ this.getInventory().setContents(chestContents);
+ }
+ for (int i = 0; i < floor.size(); i++) {
+ p.getWorld().dropItem(p.getLocation(), floor.get(i));
+ }
+ }
+
+ /**
+ * Buys amount of item from Player p. Does NOT check our inventory, or
+ * balances
+ *
+ * @param p
+ * The player to buy from
+ * @param item
+ * The itemStack to buy
+ * @param amount
+ * The amount to buy
+ */
+ public void buy(Player p, int amount) {
+ if (amount < 0)
+ this.sell(p, -amount);
+ if (this.isUnlimited()) {
+ ItemStack[] contents = p.getInventory().getContents();
+ for (int i = 0; amount > 0 && i < contents.length; i++) {
+ ItemStack stack = contents[i];
+ if (stack == null)
+ continue; // No item
+ if (matches(stack)) {
+ int stackSize = Math.min(amount, stack.getAmount());
+ stack.setAmount(stack.getAmount() - stackSize);
+ amount -= stackSize;
+ }
+ }
+ // Send the players new inventory to them
+ p.getInventory().setContents(contents);
+ // This should not happen.
+ if (amount > 0) {
+ plugin.getLogger().log(Level.WARNING, "Could not take all items from a players inventory on purchase! " + p.getName() + ", missing: " + amount + ", item: " + this.getDataName() + "!");
+ }
+ } else {
+ ItemStack[] playerContents = p.getInventory().getContents();
+ Inventory chestInv = this.getInventory();
+ for (int i = 0; amount > 0 && i < playerContents.length; i++) {
+ ItemStack item = playerContents[i];
+ if (item != null && this.matches(item)) {
+ // Copy it, we don't want to interfere
+ item = item.clone();
+ // Amount = total, item.getAmount() = how many items in the
+ // stack
+ int stackSize = Math.min(amount, item.getAmount());
+ // If Amount is item.getAmount(), then this sets the amount
+ // to 0
+ // Else it sets it to the remainder
+ playerContents[i].setAmount(playerContents[i].getAmount() - stackSize);
+ // We can modify this, it is a copy.
+ item.setAmount(stackSize);
+ // Add the items to the players inventory
+ chestInv.addItem(item);
+ amount -= stackSize;
+ }
+ }
+ // Now update the players inventory.
+ p.getInventory().setContents(playerContents);
+ }
+ }
+
+ /**
+ * Changes the owner of this shop to the given player.
+ *
+ * @param owner
+ * The name of the owner. You must do shop.update() after to save
+ * it after a reboot.
+ */
+ public void setOwner(UUID owner) {
+ this.owner = owner;
+ }
+
+ /**
+ * Returns the display item associated with this shop.
+ *
+ * @return The display item associated with this shop.
+ */
+ public DisplayItem getDisplayItem() {
+ return this.displayItem;
+ }
+
+ public void setUnlimited(boolean unlimited) {
+ this.unlimited = unlimited;
+ }
+
+ public boolean isUnlimited() {
+ return this.unlimited;
+ }
+
+ public ShopType getShopType() {
+ return this.shopType;
+ }
+
+ public boolean isBuying() {
+ return this.shopType == ShopType.BUYING;
+ }
+
+ public boolean isSelling() {
+ return this.shopType == ShopType.SELLING;
+ }
+
+ /**
+ * Changes a shop type to Buying or Selling. Also updates the signs nearby.
+ *
+ * @param shopType
+ * The new type (ShopType.BUYING or ShopType.SELLING)
+ */
+ public void setShopType(ShopType shopType) {
+ this.shopType = shopType;
+ this.setSignText();
+ }
+
+ /**
+ * Updates signs attached to the shop
+ */
+ public void setSignText() {
+ if (Util.isLoaded(this.getLocation()) == false)
+ return;
+ String[] lines = new String[4];
+ lines[0] = MsgUtil.getMessage("signs.header", this.ownerName());
+ if (this.isSelling()) {
+ lines[1] = MsgUtil.getMessage("signs.selling", "" + this.getRemainingStock());
+ } else if (this.isBuying()) {
+ lines[1] = MsgUtil.getMessage("signs.buying", "" + this.getRemainingSpace());
+ }
+ lines[2] = MsgUtil.getMessage("signs.item", Util.getNameForSign(this.item));
+ lines[3] = MsgUtil.getMessage("signs.price", Util.format(this.getPrice()));
+ this.setSignText(lines);
+ }
+
+ /**
+ * Changes all lines of text on a sign near the shop
+ *
+ * @param lines
+ * The array of lines to change. Index is line number.
+ */
+ public void setSignText(String[] lines) {
+ if (Util.isLoaded(this.getLocation()) == false)
+ return;
+ for (Sign sign : this.getSigns()) {
+ for (int i = 0; i < lines.length; i++) {
+ sign.setLine(i, lines[i].length() < 16 ? lines[i] : lines[i].substring(0, 15));
+ }
+ sign.update();
+ }
+ }
+
+ /**
+ * Returns a list of signs that are attached to this shop (QuickShop and
+ * blank signs only)
+ *
+ * @return a list of signs that are attached to this shop (QuickShop and
+ * blank signs only)
+ */
+ public List getSigns() {
+ ArrayList signs = new ArrayList(1);
+ if (this.getLocation().getWorld() == null)
+ return signs;
+ Block[] blocks = new Block[4];
+ blocks[0] = loc.getBlock().getRelative(1, 0, 0);
+ blocks[1] = loc.getBlock().getRelative(-1, 0, 0);
+ blocks[2] = loc.getBlock().getRelative(0, 0, 1);
+ blocks[3] = loc.getBlock().getRelative(0, 0, -1);
+ final String signHeader = MsgUtil.getMessage("signs.header", "");
+ for (Block b : blocks) {
+ if (b.getType() != Material.WALL_SIGN)
+ continue;
+ if (!isAttached(b))
+ continue;
+ Sign sign = (Sign) b.getState();
+ if (sign.getLine(0).contains(signHeader)) {
+ signs.add(sign);
+ } else {
+ boolean text = false;
+ for (String s : sign.getLines()) {
+ if (!s.isEmpty()) {
+ text = true;
+ break;
+ }
+ }
+ if (!text) {
+ signs.add(sign);
+ }
+ }
+ }
+ return signs;
+ }
+
+ public boolean isAttached(Block b) {
+ if (b.getType() != Material.WALL_SIGN)
+ new IllegalArgumentException(b + " Is not a sign!").printStackTrace();
+ return this.getLocation().getBlock().equals(Util.getAttached(b));
+ }
+
+ /**
+ * Convenience method. Equivilant to
+ * org.maxgamer.quickshop.Util.getName(shop.getItem()).
+ *
+ * @return The name of this shops item
+ */
+ public String getDataName() {
+ return Util.getName(this.getItem());
+ }
+
+ /**
+ * Deletes the shop from the list of shops and queues it for database
+ * deletion *DOES* delete it from memory
+ */
+ public void delete() {
+ delete(true);
+ }
+
+ /**
+ * Deletes the shop from the list of shops and queues it for database
+ * deletion
+ *
+ * @param fromMemory
+ * True if you are *NOT* iterating over this currently, *false if
+ * you are iterating*
+ */
+ public void delete(boolean fromMemory) {
+ // Delete the display item
+ if (this.getDisplayItem() != null) {
+ this.getDisplayItem().remove();
+ }
+ // Delete the signs around it
+ for (Sign s : this.getSigns()) {
+ s.getBlock().setType(Material.AIR);
+ }
+ // Delete it from the database
+ int x = this.getLocation().getBlockX();
+ int y = this.getLocation().getBlockY();
+ int z = this.getLocation().getBlockZ();
+ String world = this.getLocation().getWorld().getName();
+ plugin.getDB().execute("DELETE FROM shops WHERE x = '" + x + "' AND y = '" + y + "' AND z = '" + z + "' AND world = '" + world + "'");
+ // Refund if necessary
+ if (plugin.getConfig().getBoolean("shop.refund")) {
+ plugin.getEcon().deposit(this.getOwner(), plugin.getConfig().getDouble("shop.cost"));
+ }
+ if (fromMemory) {
+ // Delete it from memory
+ plugin.getShopManager().removeShop(this);
+ }
+ }
+
+ public boolean isValid() {
+ checkDisplay();
+ return Util.canBeShop(this.getLocation().getBlock());
+ }
+
+ private void checkDisplay() {
+ if (plugin.display == false)
+ return;
+ if (getLocation().getWorld() == null)
+ return; // not loaded
+ boolean trans = Util.isTransparent(getLocation().clone().add(0.5, 1.2, 0.5).getBlock().getType());
+ if (trans && this.getDisplayItem() == null) {
+ this.displayItem = new DisplayItem(this, this.getItem());
+ this.getDisplayItem().spawn();
+ }
+ if (this.getDisplayItem() != null) {
+ if (!trans) { // We have a display item in a block... delete it
+ this.getDisplayItem().remove();
+ this.displayItem = null;
+ return;
+ }
+ DisplayItem disItem = this.getDisplayItem();
+ Location dispLoc = disItem.getDisplayLocation();
+ if (dispLoc.getBlock() != null && dispLoc.getBlock().getType() == Material.WATER) {
+ disItem.remove();
+ return;
+ }
+ if (disItem.getItem() == null) {
+ disItem.removeDupe();
+ disItem.spawn();
+ return;
+ }
+ Item item = disItem.getItem();
+ if (item.getTicksLived() > 5000 || !item.isValid() || item.isDead()) {
+ disItem.respawn();
+ disItem.removeDupe();
+ } else if (item.getLocation().distanceSquared(dispLoc) > 1) {
+ item.teleport(dispLoc, TeleportCause.PLUGIN);
+ }
+ }
+ }
+
+ public boolean checkDisplayMoved() {
+ // don't check if the plugin doesn't know about the object
+ if (this.getDisplayItem() == null) {
+ return false;
+ }
+
+ Item item = this.getDisplayItem().getItem();
+ if (item == null) {
+ return false;
+ }
+
+ if (item.isDead()) {
+ return false;
+ }
+
+ // don't check if the chunk is not loaded
+ if (!item.getLocation().getWorld().isChunkLoaded(item.getLocation().getChunk())) {
+ return false;
+ }
+
+ return this.getDisplayItem().getDisplayLocation().distanceSquared(item.getLocation()) > 0.2;
+ }
+
+ public void onUnload() {
+ if (this.getDisplayItem() != null) {
+ this.getDisplayItem().remove();
+ this.displayItem = null;
+ }
+ }
+
+ public void onLoad() {
+ checkDisplay();
+
+ //Clear the chest?
+
+ //this.setSignText();
+
+ // check price restriction
+ Entry priceRestriction = Util.getPriceRestriction(this.getMaterial());
+ if (priceRestriction!=null) {
+ if (pricepriceRestriction.getValue()) {
+ price=priceRestriction.getValue();
+ this.update();
+ }
+ }
+ }
+
+ public void onClick() {
+ this.setSignText();
+ }
+
+ public String ownerName() {
+ if (this.isUnlimited()) {
+ return MsgUtil.getMessage("admin-shop");
+ }
+
+ if (this.getOwner() == null) {
+ return MsgUtil.getMessage("unknown-owner");
+ }
+
+ final String name = Bukkit.getOfflinePlayer(this.getOwner()).getName();
+ if (name == null) {
+ return MsgUtil.getMessage("unknown-owner");
+ }
+
+ return name;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("Shop " + (loc.getWorld() == null ? "unloaded world" : loc.getWorld().getName()) + "(" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ")");
+ sb.append(" Owner: " + this.ownerName() + " - " + getOwner().toString());
+ if (isUnlimited())
+ sb.append(" Unlimited: true");
+ sb.append(" Price: " + getPrice());
+ sb.append(" Item: " + getItem().toString());
+ return sb.toString();
+ }
}
\ No newline at end of file
diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java
index 9882078ce..0835d09dc 100644
--- a/src/main/java/org/maxgamer/quickshop/Util/Util.java
+++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java
@@ -285,6 +285,7 @@ public class Util {
item.addEnchantment(ench, level);
}
}
+ Bukkit.getServer().broadcastMessage("´¥·¢makeItem");
return item;
}
@@ -429,353 +430,8 @@ public class Util {
* @return A string with the name of the item.
*/
private static String getDataName(Material mat, short damage) {
- int id = mat.getId();
- switch (id) {
- case 35:
- switch ((int) damage) {
- case 0:
- return "WHITE_WOOL";
- case 1:
- return "ORANGE_WOOL";
- case 2:
- return "MAGENTA_WOOL";
- case 3:
- return "LIGHT_BLUE_WOOL";
- case 4:
- return "YELLOW_WOOL";
- case 5:
- return "LIME_WOOL";
- case 6:
- return "PINK_WOOL";
- case 7:
- return "GRAY_WOOL";
- case 8:
- return "LIGHT_GRAY_WOOL";
- case 9:
- return "CYAN_WOOL";
- case 10:
- return "PURPLE_WOOL";
- case 11:
- return "BLUE_WOOL";
- case 12:
- return "BROWN_WOOL";
- case 13:
- return "GREEN_WOOL";
- case 14:
- return "RED_WOOL";
- case 15:
- return "BLACK_WOOL";
- }
- return mat.toString();
- case 351:
- switch ((int) damage) {
- case 0:
- return "INK_SAC";
- case 1:
- return "ROSE_RED";
- case 2:
- return "CACTUS_GREEN";
- case 3:
- return "COCOA_BEANS";
- case 4:
- return "LAPIS_LAZULI";
- case 5:
- return "PURPLE_DYE";
- case 6:
- return "CYAN_DYE";
- case 7:
- return "LIGHT_GRAY_DYE";
- case 8:
- return "GRAY_DYE";
- case 9:
- return "PINK_DYE";
- case 10:
- return "LIME_DYE";
- case 11:
- return "DANDELION_YELLOW";
- case 12:
- return "LIGHT_BLUE_DYE";
- case 13:
- return "MAGENTA_DYE";
- case 14:
- return "ORANGE_DYE";
- case 15:
- return "BONE_MEAL";
- }
- return mat.toString();
- case 98:
- switch ((int) damage) {
- case 0:
- return "STONE_BRICKS";
- case 1:
- return "MOSSY_STONE_BRICKS";
- case 2:
- return "CRACKED_STONE_BRICKS";
- case 3:
- return "CHISELED_STONE_BRICKS";
- }
- return mat.toString();
- case 373:
- // Special case,.. Why?
- if (damage == 0)
- return "WATER_BOTTLE";
- Potion pot;
- try {
- pot = Potion.fromDamage(damage);
- } catch (Exception e) {
- return "CUSTOM_POTION";
- }
- String prefix = "";
- String suffix = "";
- if (pot.getLevel() > 0)
- suffix += "_" + pot.getLevel();
- if (pot.hasExtendedDuration())
- prefix += "EXTENDED_";
- if (pot.isSplash())
- prefix += "SPLASH_";
- if (pot.getEffects().isEmpty()) {
- switch ((int) pot.getNameId()) {
- case 0:
- return prefix + "MUNDANE_POTION" + suffix;
- case 7:
- return prefix + "CLEAR_POTION" + suffix;
- case 11:
- return prefix + "DIFFUSE_POTION" + suffix;
- case 13:
- return prefix + "ARTLESS_POTION" + suffix;
- case 15:
- return prefix + "THIN_POTION" + suffix;
- case 16:
- return prefix + "AWKWARD_POTION" + suffix;
- case 32:
- return prefix + "THICK_POTION" + suffix;
- }
- } else {
- String effects = "";
- for (PotionEffect effect : pot.getEffects()) {
- effects += effect.toString().split(":")[0];
- }
- return prefix + effects + suffix;
- }
- return mat.toString();
- case 6:
- switch ((int) damage) {
- case 0:
- return "OAK_SAPLING";
- case 1:
- return "PINE_SAPLING";
- case 2:
- return "BIRCH_SAPLING";
- case 3:
- return "JUNGLE_TREE_SAPLING";
- }
- return mat.toString();
- case 5:
- switch ((int) damage) {
- case 0:
- return "OAK_PLANKS";
- case 1:
- return "PINE_PLANKS";
- case 2:
- return "BIRCH_PLANKS";
- case 3:
- return "JUNGLE_PLANKS";
- }
- return mat.toString();
- case 17:
- switch (damage) {
- case 0:
- return "OAK_LOG";
- case 1:
- return "PINE_LOG";
- case 2:
- return "BIRCH_LOG";
- case 3:
- return "JUNGLE_LOG";
- }
- return mat.toString();
- case 18:
- damage = (short) (damage % 4);
- switch (damage) {
- case 0:
- return "OAK_LEAVES";
- case 1:
- return "PINE_LEAVES";
- case 2:
- return "BIRCH_LEAVES";
- case 3:
- return "JUNGLE_LEAVES";
- }
- case 263:
- switch (damage) {
- case 0:
- return "COAL";
- case 1:
- return "CHARCOAL";
- }
- return mat.toString();
- case 24:
- switch ((int) damage) {
- case 0:
- return "SANDSTONE";
- case 1:
- return "CHISELED_SANDSTONE";
- case 2:
- return "SMOOTH_SANDSTONE";
- }
- return mat.toString();
- case 31:
- switch ((int) damage) {
- case 0:
- return "DEAD_SHRUB";
- case 1:
- return "TALL_GRASS";
- case 2:
- return "FERN";
- }
- return mat.toString();
- case 44:
- switch ((int) damage) {
- case 0:
- return "STONE_SLAB";
- case 1:
- return "SANDSTONE_SLAB";
- case 2:
- return "WOODEN_SLAB";
- case 3:
- return "COBBLESTONE_SLAB";
- case 4:
- return "BRICK_SLAB";
- case 5:
- return "STONE_BRICK_SLAB";
- }
- return mat.toString();
- case 383:
- switch ((int) damage) {
- case 50:
- return "CREEPER_EGG";
- case 51:
- return "SKELETON_EGG";
- case 52:
- return "SPIDER_EGG";
- case 53:
- return "GIANT_EGG";
- case 54:
- return "ZOMBIE_EGG";
- case 55:
- return "SLIME_EGG";
- case 56:
- return "GHAST_EGG";
- case 57:
- return "ZOMBIE_PIGMAN_EGG";
- case 58:
- return "ENDERMAN_EGG";
- case 59:
- return "CAVE_SPIDER_EGG";
- case 60:
- return "SILVERFISH_EGG";
- case 61:
- return "BLAZE_EGG";
- case 62:
- return "MAGMA_CUBE_EGG";
- case 63:
- return "ENDER_DRAGON_EGG";
- case 90:
- return "PIG_EGG";
- case 91:
- return "SHEEP_EGG";
- case 92:
- return "COW_EGG";
- case 93:
- return "CHICKEN_EGG";
- case 94:
- return "SQUID_EGG";
- case 95:
- return "WOLF_EGG";
- case 96:
- return "MOOSHROOM_EGG";
- case 97:
- return "SNOW_GOLEM_EGG";
- case 98:
- return "OCELOT_EGG";
- case 99:
- return "IRON_GOLEM_EGG";
- case 120:
- return "VILLAGER_EGG";
- case 200:
- return "ENDER_CRYSTAL_EGG";
- case 14:
- return "PRIMED_TNT_EGG";
- case 66:
- return "WITCH_EGG";
- case 65:
- return "BAT_EGG";
- }
- return mat.toString();
- case 397:
- switch ((int) damage) {
- case 0:
- return "SKELETON_SKULL";
- case 1:
- return "WITHER_SKULL";
- case 2:
- return "ZOMBIE_HEAD";
- case 3:
- return "PLAYER_HEAD";
- case 4:
- return "CREEPER_HEAD";
- }
- break;
- case 76:
- return "REDSTONE_TORCH";
- case 115:
- return "NETHER_WART";
- case 30:
- return "COBWEB";
- case 102:
- return "GLASS_PANE";
- case 101:
- return "IRON_BARS";
- case 58:
- return "CRAFTING_TABLE";
- case 123:
- return "REDSTONE_LAMP";
- case 392:
- return "POTATO";
- case 289:
- return "GUNPOWDER";
- case 391:
- return "CARROT";
- case 322:
- switch ((int) damage) {
- case 0:
- return "GOLDEN_APPLE";
- case 1:
- return "ENCHANTED_GOLDEN_APPLE";
- }
- break;
- case 390:
- return "FLOWER_POT";
- case 145:
- switch ((int) damage) {
- case 0:
- return "ANVIL";
- case 1:
- return "SLIGHTLY_DAMAGED_ANVIL";
- case 2:
- return "VERY_DAMAGED:ANVIL";
- }
- break;
- case 384:
- return "BOTTLE_O'_ENCHANTING";
- case 402:
- return "FIREWORK_STAR";
- case 385:
- return "FIREWORK_CHARGE";
- }
- if (damage == 0 || isTool(mat))
- return mat.toString();
- return mat.toString() + ":" + damage;
+ return mat.name();
+ //Not need in 1.13
}
/**