tubelius

I.setAmount(Qty);

Jun 30th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. public Integer RunTransaction(String[] args, Player P, Boolean PlBuy) {
  2. ItemStack I = null;
  3. Integer Qty = ToInt(args[2]);
  4.  
  5. // if (args[1].equalsIgnoreCase("this")) {
  6. // I = P.getItemInHand().clone();
  7. // I.setAmount(Qty);
  8. // } else {
  9. // Material M = ArgToMat(args[1],P);
  10. // if (M != null) {
  11. // I = new ItemStack(ArgToMat(args[1],P),Qty);
  12. // } else {
  13. // MsgP(P,"Uknown item: "+args[1]);
  14. // return 0;
  15. // }
  16. // }
  17.  
  18. Material M = ArgToMat(args[1],P);
  19. if (M != null) {
  20. Integer MaxQty = GetAPItem(M.getId()).TransactionMaxQty;
  21. if (MaxQty==null) { MaxQty=1; }
  22. if (Qty > MaxQty) {
  23. Qty = MaxQty;
  24. }
  25.  
  26. if (args[1].equalsIgnoreCase("this")) {
  27. I = P.getItemInHand().clone();
  28. MsgP(P,"Changing qty of: "+I.getType().name());
  29. I.setAmount(Qty);
  30. MsgP(P,"Changed qty of: "+I.getType().name());
  31. } else {
  32. I = new ItemStack(ArgToMat(args[1],P),Qty);
  33. }
  34. } else {
  35. MsgP(P,"Uknown item: "+args[1]);
  36. return 0;
  37. }
  38.  
  39. if (this.getConfig().getBoolean("Items."+I.getTypeId()+".tradable") != true) {
  40. MsgP(P,"You can't trade: "+I.getType().name());
  41. return 0;
  42. }
  43.  
  44. float Pr = GetFinalPrice(PlBuy,I,P);
  45.  
  46. Integer Got = 0;
  47. Integer TATot = 0;
  48. if (PlBuy) {
  49. if (econ.getBalance(P.getName())>=Qty*Pr) {
  50. while (Qty-TATot > I.getType().getMaxStackSize()) {
  51. //Get full stacks
  52. Got = AddQty(P,I.getType(),I.getType().getMaxStackSize());
  53. if (Got>0) { TATot += Got; } else { Qty=0; break; }
  54. }
  55. //Get less than a stack
  56. if (Qty>TATot) { TATot += AddQty(P,I.getType(),Qty-TATot); }
  57. EcoTransaction(P,-1*TATot*Pr);
  58. } else {
  59. MsgP(P,"You can't afford "+Qty+" "+I.getType().name()
  60. +" ("+Qty+" * "+Pr+" = "+(Qty*Pr)+"). You only have: "+econ.getBalance(P.getName()));
  61. return 0;
  62. }
  63. } else {
  64. TATot = Qty - QtyFromISMap(P.getInventory().removeItem(I));
  65. EcoTransaction(P,TATot*Pr);
  66. }
  67.  
  68. if (TATot>0) {
  69. float PrTot = Pr*TATot;
  70. String TATyp = "You sold ";
  71. if (PlBuy) { TATyp = "You bought "; }
  72. MsgP(P,TATyp+TATot+" "+I.getType().name()+" for "+Pr+" each ("+PrTot+" total)");
  73. UpdateItem(PlBuy, I.getType().getId(), TATot);
  74. } else if (PlBuy) {
  75. MsgP(P,"You have no room for "+I.getType().name());
  76. } else {
  77. MsgP(P,"You don't have any "+I.getType().name());
  78. }
  79.  
  80. return TATot;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment