Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Integer RunTransaction(String[] args, Player P, Boolean PlBuy) {
- ItemStack I = null;
- Integer Qty = ToInt(args[2]);
- // if (args[1].equalsIgnoreCase("this")) {
- // I = P.getItemInHand().clone();
- // I.setAmount(Qty);
- // } else {
- // Material M = ArgToMat(args[1],P);
- // if (M != null) {
- // I = new ItemStack(ArgToMat(args[1],P),Qty);
- // } else {
- // MsgP(P,"Uknown item: "+args[1]);
- // return 0;
- // }
- // }
- Material M = ArgToMat(args[1],P);
- if (M != null) {
- Integer MaxQty = GetAPItem(M.getId()).TransactionMaxQty;
- if (MaxQty==null) { MaxQty=1; }
- if (Qty > MaxQty) {
- Qty = MaxQty;
- }
- if (args[1].equalsIgnoreCase("this")) {
- I = P.getItemInHand().clone();
- MsgP(P,"Changing qty of: "+I.getType().name());
- I.setAmount(Qty);
- MsgP(P,"Changed qty of: "+I.getType().name());
- } else {
- I = new ItemStack(ArgToMat(args[1],P),Qty);
- }
- } else {
- MsgP(P,"Uknown item: "+args[1]);
- return 0;
- }
- if (this.getConfig().getBoolean("Items."+I.getTypeId()+".tradable") != true) {
- MsgP(P,"You can't trade: "+I.getType().name());
- return 0;
- }
- float Pr = GetFinalPrice(PlBuy,I,P);
- Integer Got = 0;
- Integer TATot = 0;
- if (PlBuy) {
- if (econ.getBalance(P.getName())>=Qty*Pr) {
- while (Qty-TATot > I.getType().getMaxStackSize()) {
- //Get full stacks
- Got = AddQty(P,I.getType(),I.getType().getMaxStackSize());
- if (Got>0) { TATot += Got; } else { Qty=0; break; }
- }
- //Get less than a stack
- if (Qty>TATot) { TATot += AddQty(P,I.getType(),Qty-TATot); }
- EcoTransaction(P,-1*TATot*Pr);
- } else {
- MsgP(P,"You can't afford "+Qty+" "+I.getType().name()
- +" ("+Qty+" * "+Pr+" = "+(Qty*Pr)+"). You only have: "+econ.getBalance(P.getName()));
- return 0;
- }
- } else {
- TATot = Qty - QtyFromISMap(P.getInventory().removeItem(I));
- EcoTransaction(P,TATot*Pr);
- }
- if (TATot>0) {
- float PrTot = Pr*TATot;
- String TATyp = "You sold ";
- if (PlBuy) { TATyp = "You bought "; }
- MsgP(P,TATyp+TATot+" "+I.getType().name()+" for "+Pr+" each ("+PrTot+" total)");
- UpdateItem(PlBuy, I.getType().getId(), TATot);
- } else if (PlBuy) {
- MsgP(P,"You have no room for "+I.getType().name());
- } else {
- MsgP(P,"You don't have any "+I.getType().name());
- }
- return TATot;
- }
Advertisement
Add Comment
Please, Sign In to add comment