mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 02:12:25 +00:00
Double Chests shouldn't be counted twice
This commit is contained in:
parent
2b9a2c957f
commit
67016787df
@ -37,6 +37,7 @@ public class Shop {
|
||||
private double buyPrice;
|
||||
private double sellPrice;
|
||||
private ShopType shopType;
|
||||
private Chest chest;
|
||||
|
||||
public Shop(int id, ShopChest plugin, OfflinePlayer vendor, ItemStack product, Location location, double buyPrice, double sellPrice, ShopType shopType) {
|
||||
this.id = id;
|
||||
@ -48,6 +49,18 @@ public class Shop {
|
||||
this.sellPrice = sellPrice;
|
||||
this.shopType = shopType;
|
||||
|
||||
Block b = location.getBlock();
|
||||
if (b.getType() == Material.CHEST || b.getType() == Material.TRAPPED_CHEST) {
|
||||
this.chest = (Chest) b.getState();
|
||||
} else {
|
||||
try {
|
||||
throw new Exception("No Chest found at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (hologram == null || !hologram.exists()) createHologram();
|
||||
if (item == null || item.isDead()) createItem();
|
||||
}
|
||||
@ -92,41 +105,26 @@ public class Shop {
|
||||
}
|
||||
|
||||
private void createHologram() {
|
||||
|
||||
boolean doubleChest;
|
||||
|
||||
Chest[] chests = new Chest[2];
|
||||
|
||||
Block b = location.getBlock();
|
||||
InventoryHolder ih = chest.getInventory().getHolder();
|
||||
|
||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
||||
if (ih instanceof DoubleChest) {
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
|
||||
Chest c = (Chest) b.getState();
|
||||
InventoryHolder ih = c.getInventory().getHolder();
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
if (ih instanceof DoubleChest) {
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
chests[0] = r;
|
||||
chests[1] = l;
|
||||
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
chests[0] = r;
|
||||
chests[1] = l;
|
||||
|
||||
doubleChest = true;
|
||||
|
||||
} else {
|
||||
doubleChest = false;
|
||||
chests[0] = c;
|
||||
}
|
||||
doubleChest = true;
|
||||
|
||||
} else {
|
||||
try {
|
||||
throw new Exception("No Chest found at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
doubleChest = false;
|
||||
chests[0] = chest;
|
||||
}
|
||||
|
||||
Location holoLocation;
|
||||
@ -167,8 +165,7 @@ public class Shop {
|
||||
else if ((buyPrice > 0) && (sellPrice > 0))
|
||||
holoText[1] = LanguageUtils.getMessage(LocalizedMessage.Message.HOLOGRAM_BUY_SELL, new LocalizedMessage.ReplacedRegex(Regex.BUY_PRICE, String.valueOf(buyPrice)),
|
||||
new LocalizedMessage.ReplacedRegex(Regex.SELL_PRICE, String.valueOf(sellPrice)));
|
||||
else
|
||||
holoText[1] = LanguageUtils.getMessage(LocalizedMessage.Message.HOLOGRAM_BUY_SELL, new LocalizedMessage.ReplacedRegex(Regex.BUY_PRICE, String.valueOf(buyPrice)),
|
||||
else holoText[1] = LanguageUtils.getMessage(LocalizedMessage.Message.HOLOGRAM_BUY_SELL, new LocalizedMessage.ReplacedRegex(Regex.BUY_PRICE, String.valueOf(buyPrice)),
|
||||
new LocalizedMessage.ReplacedRegex(Regex.SELL_PRICE, String.valueOf(sellPrice)));
|
||||
|
||||
switch (Utils.getServerVersion()) {
|
||||
@ -226,6 +223,10 @@ public class Shop {
|
||||
return hologram;
|
||||
}
|
||||
|
||||
public Chest getChest() {
|
||||
return chest;
|
||||
}
|
||||
|
||||
public enum ShopType {
|
||||
NORMAL,
|
||||
ADMIN
|
||||
|
@ -45,36 +45,26 @@ public class ShopUtils {
|
||||
}
|
||||
|
||||
public static void addShop(Shop shop, boolean addToDatabase) {
|
||||
Location loc = shop.getLocation();
|
||||
Block b = loc.getBlock();
|
||||
InventoryHolder ih = shop.getChest().getInventory().getHolder();
|
||||
|
||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
||||
Chest c = (Chest) b.getState();
|
||||
InventoryHolder ih = c.getInventory().getHolder();
|
||||
if (ih instanceof DoubleChest) {
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
if (ih instanceof DoubleChest) {
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
shopLocation.put(r.getLocation(), shop);
|
||||
shopLocation.put(l.getLocation(), shop);
|
||||
} else {
|
||||
shopLocation.put(shop.getLocation(), shop);
|
||||
}
|
||||
|
||||
if (addToDatabase)
|
||||
plugin.getShopDatabase().addShop(shop);
|
||||
shopLocation.put(r.getLocation(), shop);
|
||||
shopLocation.put(l.getLocation(), shop);
|
||||
} else {
|
||||
shopLocation.put(shop.getLocation(), shop);
|
||||
}
|
||||
|
||||
if (addToDatabase)
|
||||
plugin.getShopDatabase().addShop(shop);
|
||||
|
||||
}
|
||||
|
||||
public static void removeShop(Shop shop, boolean removeFromDatabase) {
|
||||
Location loc = shop.getLocation();
|
||||
Block b = loc.getBlock();
|
||||
|
||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
||||
Chest c = (Chest) b.getState();
|
||||
InventoryHolder ih = c.getInventory().getHolder();
|
||||
InventoryHolder ih = shop.getChest().getInventory().getHolder();
|
||||
|
||||
if (ih instanceof DoubleChest) {
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
@ -92,7 +82,6 @@ public class ShopUtils {
|
||||
|
||||
if (removeFromDatabase)
|
||||
plugin.getShopDatabase().removeShop(shop);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getShopLimit(Player p) {
|
||||
@ -149,16 +138,20 @@ public class ShopUtils {
|
||||
}
|
||||
|
||||
public static int getShopAmount(OfflinePlayer p) {
|
||||
int shopCount = 0;
|
||||
float shopCount = 0;
|
||||
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
if (shop.getVendor().equals(p)) {
|
||||
if (shop.getShopType() != Shop.ShopType.ADMIN || !Config.exclude_admin_shops)
|
||||
if (shop.getShopType() != Shop.ShopType.ADMIN || !Config.exclude_admin_shops) {
|
||||
shopCount++;
|
||||
|
||||
if (shop.getChest().getInventory().getHolder() instanceof DoubleChest)
|
||||
shopCount -= 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return shopCount;
|
||||
return Math.round(shopCount);
|
||||
}
|
||||
|
||||
public static int reloadShops() {
|
||||
|
Loading…
Reference in New Issue
Block a user