Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. public static void sendBuy(Player player, int itemId, int amount) {
  2. Integer TYPE = (Integer) player.getTemporaryAttributtes().get("CUSTOM_STORE_TYPE");
  3. int price = -1;
  4. int points = -1;
  5. if (TYPE != null) {
  6. switch (TYPE) {
  7. case PKP:
  8. for (int i = 0; i < PKPointsData.ITEMS.length; i++)
  9. if (itemId == PKPointsData.ITEMS[i][0]) {
  10. price = PKPointsData.ITEMS[i][2];
  11. points = player.getPKP();
  12. if (amount * price > points) {
  13. amount = points / price;
  14. price = price * amount;
  15. System.out.println("New amount: " + amount);
  16. System.out.println("New price: " + price);
  17. } else
  18. price = price * amount;
  19. if (price > points || amount < 1) {
  20. player.getPackets().sendGameMessage("You don't have enough points to buy this.");
  21. return;
  22. }
  23. ItemDefinitions defs = ItemDefinitions.getItemDefinitions(itemId);
  24. if (defs.canBeNoted() && !defs.isStackable())
  25. itemId = amount > 1 ? defs.getCertId() : itemId;
  26. defs = ItemDefinitions.getItemDefinitions(itemId);
  27. if (!player.getInventory().hasFreeSlots() && !defs.isStackable()
  28. || (!player.getInventory().hasFreeSlots() && defs.isStackable() && !player.getInventory().containsOneItem(itemId))) {
  29. player.sm("You don't have enough inventory space to buy this.");
  30. return;
  31. }
  32. player.addItem(itemId, amount);
  33. player.setPKP(player.getPKP() - (price));
  34. player.sm("You bought " + amount + " x "
  35. + defs.getName() + " for "
  36. + price + " pk points.");
  37. player.closeInterfaces();
  38. sendInterface(player, TYPE);
  39. }
  40. break;
  41. }
  42. } else
  43. player.sm("NULL");
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement