mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-27 12:38:40 +01:00
Fixed partial transactions
Removed stackAmount from Shop and TransactionEvent's constructor.
This commit is contained in:
parent
5908eb67fa
commit
c63ba4c9a4
@ -25,7 +25,7 @@ public class TransactionEvent extends Event {
|
|||||||
|
|
||||||
private Type transactionType;
|
private Type transactionType;
|
||||||
|
|
||||||
public TransactionEvent(Type transactionType, Container container, Sign sign, Player client, String owner, ItemStack item, int itemAmount, double price) {
|
public TransactionEvent(Type transactionType, Container container, Sign sign, Player client, String owner, ItemStack item, double price) {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.sign = sign;
|
this.sign = sign;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ public class TransactionEvent extends Event {
|
|||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
|
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.itemAmount = itemAmount;
|
this.itemAmount = item.getAmount();
|
||||||
|
|
||||||
this.transactionType = transactionType;
|
this.transactionType = transactionType;
|
||||||
this.price = price;
|
this.price = price;
|
||||||
|
@ -37,7 +37,6 @@ public class Shop {
|
|||||||
private final Container container;
|
private final Container container;
|
||||||
private final String owner;
|
private final String owner;
|
||||||
|
|
||||||
private int stockAmount;
|
|
||||||
private ItemStack stock;
|
private ItemStack stock;
|
||||||
|
|
||||||
private final Sign sign;
|
private final Sign sign;
|
||||||
@ -47,7 +46,6 @@ public class Shop {
|
|||||||
this.owner = sign.getLine(NAME_LINE);
|
this.owner = sign.getLine(NAME_LINE);
|
||||||
|
|
||||||
this.stock = stock;
|
this.stock = stock;
|
||||||
this.stockAmount = stock.getAmount();
|
|
||||||
|
|
||||||
this.sign = sign;
|
this.sign = sign;
|
||||||
}
|
}
|
||||||
@ -89,8 +87,8 @@ public class Shop {
|
|||||||
if (!partialTransactionAllowed(possiblePartialItemCount)) {
|
if (!partialTransactionAllowed(possiblePartialItemCount)) {
|
||||||
return NOT_ENOUGH_MONEY;
|
return NOT_ENOUGH_MONEY;
|
||||||
} else {
|
} else {
|
||||||
price = (price / stockAmount) * possiblePartialItemCount;
|
price = (price / stock.getAmount()) * possiblePartialItemCount;
|
||||||
stockAmount = possiblePartialItemCount;
|
stock.setAmount(possiblePartialItemCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,8 +106,8 @@ public class Shop {
|
|||||||
|
|
||||||
return NOT_ENOUGH_STOCK;
|
return NOT_ENOUGH_STOCK;
|
||||||
} else {
|
} else {
|
||||||
price = (price / stockAmount) * possiblePartialItemCount;
|
price = (price / stock.getAmount()) * possiblePartialItemCount;
|
||||||
stockAmount = possiblePartialItemCount;
|
stock.setAmount(possiblePartialItemCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +119,7 @@ public class Shop {
|
|||||||
|
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
|
|
||||||
TransactionEvent event = new TransactionEvent(BUY, container, sign, player, this.owner, stock, stockAmount, price);
|
TransactionEvent event = new TransactionEvent(BUY, container, sign, player, this.owner, stock, price);
|
||||||
ChestShop.callEvent(event);
|
ChestShop.callEvent(event);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -148,8 +146,8 @@ public class Shop {
|
|||||||
if (!partialTransactionAllowed(possiblePartialItemCount)) {
|
if (!partialTransactionAllowed(possiblePartialItemCount)) {
|
||||||
return NOT_ENOUGH_MONEY_SHOP;
|
return NOT_ENOUGH_MONEY_SHOP;
|
||||||
} else {
|
} else {
|
||||||
price = (price / stockAmount) * possiblePartialItemCount;
|
price = (price / stock.getAmount()) * possiblePartialItemCount;
|
||||||
stockAmount = possiblePartialItemCount;
|
stock.setAmount(possiblePartialItemCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,8 +157,8 @@ public class Shop {
|
|||||||
if (!partialTransactionAllowed(possiblePartialItemCount)) {
|
if (!partialTransactionAllowed(possiblePartialItemCount)) {
|
||||||
return NOT_ENOUGH_ITEMS_TO_SELL;
|
return NOT_ENOUGH_ITEMS_TO_SELL;
|
||||||
} else {
|
} else {
|
||||||
price = (price / stockAmount) * possiblePartialItemCount;
|
price = (price / stock.getAmount()) * possiblePartialItemCount;
|
||||||
stockAmount = possiblePartialItemCount;
|
stock.setAmount(possiblePartialItemCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +174,7 @@ public class Shop {
|
|||||||
InventoryUtil.remove(stock, player.getInventory());
|
InventoryUtil.remove(stock, player.getInventory());
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
|
|
||||||
TransactionEvent event = new TransactionEvent(SELL, container, sign, player, this.owner, stock, stockAmount, price);
|
TransactionEvent event = new TransactionEvent(SELL, container, sign, player, this.owner, stock, price);
|
||||||
ChestShop.callEvent(event);
|
ChestShop.callEvent(event);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -207,11 +205,11 @@ public class Shop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean playerHasEnoughItems(Player player) {
|
private boolean playerHasEnoughItems(Player player) {
|
||||||
return InventoryUtil.getAmount(stock, player.getInventory()) >= stockAmount;
|
return InventoryUtil.getAmount(stock, player.getInventory()) >= stock.getAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calculateItemAmount(double money, double basePrice) {
|
private int calculateItemAmount(double money, double basePrice) {
|
||||||
return (int) Math.floor(money / (basePrice / stockAmount));
|
return (int) Math.floor(money / (basePrice / stock.getAmount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendMessage(Player player, Language message) {
|
private static void sendMessage(Player player, Language message) {
|
||||||
|
@ -2,7 +2,7 @@ name: ChestShop
|
|||||||
|
|
||||||
main: com.Acrobot.ChestShop.ChestShop
|
main: com.Acrobot.ChestShop.ChestShop
|
||||||
|
|
||||||
version: 3.43 TEST BUILD
|
version: 3.44 TEST BUILD
|
||||||
|
|
||||||
#for CButD
|
#for CButD
|
||||||
dev-url: http://dev.bukkit.org/server-mods/chestshop/
|
dev-url: http://dev.bukkit.org/server-mods/chestshop/
|
||||||
|
Loading…
Reference in New Issue
Block a user