mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-10 04:31:06 +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 buyPrice;
|
||||||
private double sellPrice;
|
private double sellPrice;
|
||||||
private ShopType shopType;
|
private ShopType shopType;
|
||||||
|
private Chest chest;
|
||||||
|
|
||||||
public Shop(int id, ShopChest plugin, OfflinePlayer vendor, ItemStack product, Location location, double buyPrice, double sellPrice, ShopType shopType) {
|
public Shop(int id, ShopChest plugin, OfflinePlayer vendor, ItemStack product, Location location, double buyPrice, double sellPrice, ShopType shopType) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@ -48,6 +49,18 @@ public class Shop {
|
|||||||
this.sellPrice = sellPrice;
|
this.sellPrice = sellPrice;
|
||||||
this.shopType = shopType;
|
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 (hologram == null || !hologram.exists()) createHologram();
|
||||||
if (item == null || item.isDead()) createItem();
|
if (item == null || item.isDead()) createItem();
|
||||||
}
|
}
|
||||||
@ -92,17 +105,11 @@ public class Shop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createHologram() {
|
private void createHologram() {
|
||||||
|
|
||||||
boolean doubleChest;
|
boolean doubleChest;
|
||||||
|
|
||||||
Chest[] chests = new Chest[2];
|
Chest[] chests = new Chest[2];
|
||||||
|
|
||||||
Block b = location.getBlock();
|
Block b = location.getBlock();
|
||||||
|
InventoryHolder ih = chest.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) {
|
if (ih instanceof DoubleChest) {
|
||||||
DoubleChest dc = (DoubleChest) ih;
|
DoubleChest dc = (DoubleChest) ih;
|
||||||
@ -117,16 +124,7 @@ public class Shop {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
doubleChest = false;
|
doubleChest = false;
|
||||||
chests[0] = c;
|
chests[0] = chest;
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
throw new Exception("No Chest found at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Location holoLocation;
|
Location holoLocation;
|
||||||
@ -167,8 +165,7 @@ public class Shop {
|
|||||||
else if ((buyPrice > 0) && (sellPrice > 0))
|
else if ((buyPrice > 0) && (sellPrice > 0))
|
||||||
holoText[1] = LanguageUtils.getMessage(LocalizedMessage.Message.HOLOGRAM_BUY_SELL, new LocalizedMessage.ReplacedRegex(Regex.BUY_PRICE, String.valueOf(buyPrice)),
|
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)));
|
new LocalizedMessage.ReplacedRegex(Regex.SELL_PRICE, String.valueOf(sellPrice)));
|
||||||
else
|
else holoText[1] = LanguageUtils.getMessage(LocalizedMessage.Message.HOLOGRAM_BUY_SELL, new LocalizedMessage.ReplacedRegex(Regex.BUY_PRICE, String.valueOf(buyPrice)),
|
||||||
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)));
|
new LocalizedMessage.ReplacedRegex(Regex.SELL_PRICE, String.valueOf(sellPrice)));
|
||||||
|
|
||||||
switch (Utils.getServerVersion()) {
|
switch (Utils.getServerVersion()) {
|
||||||
@ -226,6 +223,10 @@ public class Shop {
|
|||||||
return hologram;
|
return hologram;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Chest getChest() {
|
||||||
|
return chest;
|
||||||
|
}
|
||||||
|
|
||||||
public enum ShopType {
|
public enum ShopType {
|
||||||
NORMAL,
|
NORMAL,
|
||||||
ADMIN
|
ADMIN
|
||||||
|
@ -45,12 +45,7 @@ public class ShopUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void addShop(Shop shop, boolean addToDatabase) {
|
public static void addShop(Shop shop, boolean addToDatabase) {
|
||||||
Location loc = shop.getLocation();
|
InventoryHolder ih = shop.getChest().getInventory().getHolder();
|
||||||
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();
|
|
||||||
|
|
||||||
if (ih instanceof DoubleChest) {
|
if (ih instanceof DoubleChest) {
|
||||||
DoubleChest dc = (DoubleChest) ih;
|
DoubleChest dc = (DoubleChest) ih;
|
||||||
@ -65,16 +60,11 @@ public class ShopUtils {
|
|||||||
|
|
||||||
if (addToDatabase)
|
if (addToDatabase)
|
||||||
plugin.getShopDatabase().addShop(shop);
|
plugin.getShopDatabase().addShop(shop);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeShop(Shop shop, boolean removeFromDatabase) {
|
public static void removeShop(Shop shop, boolean removeFromDatabase) {
|
||||||
Location loc = shop.getLocation();
|
InventoryHolder ih = shop.getChest().getInventory().getHolder();
|
||||||
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();
|
|
||||||
|
|
||||||
if (ih instanceof DoubleChest) {
|
if (ih instanceof DoubleChest) {
|
||||||
DoubleChest dc = (DoubleChest) ih;
|
DoubleChest dc = (DoubleChest) ih;
|
||||||
@ -93,7 +83,6 @@ public class ShopUtils {
|
|||||||
if (removeFromDatabase)
|
if (removeFromDatabase)
|
||||||
plugin.getShopDatabase().removeShop(shop);
|
plugin.getShopDatabase().removeShop(shop);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static int getShopLimit(Player p) {
|
public static int getShopLimit(Player p) {
|
||||||
int limit = Config.default_limit;
|
int limit = Config.default_limit;
|
||||||
@ -149,16 +138,20 @@ public class ShopUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getShopAmount(OfflinePlayer p) {
|
public static int getShopAmount(OfflinePlayer p) {
|
||||||
int shopCount = 0;
|
float shopCount = 0;
|
||||||
|
|
||||||
for (Shop shop : ShopUtils.getShops()) {
|
for (Shop shop : ShopUtils.getShops()) {
|
||||||
if (shop.getVendor().equals(p)) {
|
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++;
|
shopCount++;
|
||||||
|
|
||||||
|
if (shop.getChest().getInventory().getHolder() instanceof DoubleChest)
|
||||||
|
shopCount -= 0.5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return shopCount;
|
return Math.round(shopCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int reloadShops() {
|
public static int reloadShops() {
|
||||||
|
Loading…
Reference in New Issue
Block a user