hubeb

cs

Jun 25th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. import org.bukkit.ChatColor;
  2. import org.bukkit.Material;
  3. import org.bukkit.block.Block;
  4. import org.bukkit.block.Chest;
  5. import org.bukkit.block.Sign;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.event.EventHandler;
  8. import org.bukkit.event.Listener;
  9. import org.bukkit.event.block.Action;
  10. import org.bukkit.event.player.PlayerInteractEvent;
  11. import org.bukkit.inventory.ItemStack;
  12.  
  13. public class ShopSignListener implements Listener {
  14.  
  15. ShopSign plugin;
  16.  
  17. public ShopSignListener(ShopSign plugin) {
  18. this.plugin = plugin;
  19. }
  20.  
  21. @SuppressWarnings("deprecation")
  22. @EventHandler
  23. public void PlayerSignShopInteract(PlayerInteractEvent event) {
  24. Block clickblock = event.getClickedBlock();
  25. Material type = clickblock.getType();
  26.  
  27. if(clickblock != null && type == Material.SIGN_POST || type == Material.WALL_SIGN && event.getAction() == Action.LEFT_CLICK_BLOCK) {
  28. Player player = event.getPlayer();
  29. Sign sign = (Sign)event.getClickedBlock().getState();
  30.  
  31. String line1 = sign.getLine(0);
  32. String getLine2 = sign.getLine(1);
  33. int line2 = Integer.parseInt(getLine2);
  34. String line3 = sign.getLine(2);
  35. String line4 = sign.getLine(3);
  36.  
  37. String[] data = line3.split(":");
  38.  
  39. Integer buy = Integer.parseInt(data[0]);
  40.  
  41. int x = event.getClickedBlock().getX();
  42. int y = event.getClickedBlock().getY();
  43. int z = event.getClickedBlock().getZ();
  44.  
  45. if(ShopSign.econ.getBalance(player.getName()) < buy) {
  46. player.sendMessage(ChatColor.RED+"You don't have enough "+ShopSign.econ.currencyNamePlural());
  47. } else {
  48. if(clickblock.getWorld().getBlockAt(x, y - 1, z).getType() == Material.CHEST) {
  49. Chest chest = (Chest)clickblock.getWorld().getBlockAt(x, y - 1, z).getState();
  50. if(chest.getBlockInventory().containsAtLeast(new ItemStack(Material.getMaterial(line4.toUpperCase())), line2)) {
  51. chest.getBlockInventory().removeItem(new ItemStack(Material.getMaterial(line4.toUpperCase()), line2));
  52. player.getInventory().addItem(new ItemStack(Material.getMaterial(line4.toUpperCase()), line2));
  53. ShopSign.econ.withdrawPlayer(player.getName(), buy);
  54. ShopSign.econ.depositPlayer(line1, buy);
  55. player.sendMessage(ChatColor.GREEN+"You bought "+getLine2+" "+line4+" for "+buy+" "+ShopSign.econ.currencyNamePlural());
  56. }
  57. }
  58. }
  59. }
  60. if(clickblock != null && clickblock.getType() == Material.SIGN_POST && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  61. Player player = event.getPlayer();
  62. Sign sign = (Sign)event.getClickedBlock().getState();
  63.  
  64. String line1 = sign.getLine(0);
  65. String getLine2 = sign.getLine(1);
  66. int line2 = Integer.parseInt(getLine2);
  67. String line3 = sign.getLine(2);
  68. String line4 = sign.getLine(3);
  69.  
  70. String[] data = line3.split(":");
  71.  
  72. Integer sell = Integer.parseInt(data[1]);
  73.  
  74. int x = event.getClickedBlock().getX();
  75. int y = event.getClickedBlock().getY();
  76. int z = event.getClickedBlock().getZ();
  77.  
  78. if(ShopSign.econ.getBalance(line1) < sell) {
  79. player.sendMessage(ChatColor.RED+line1+" does not have enough "+ShopSign.econ.currencyNamePlural());
  80. } else {
  81. if(clickblock.getWorld().getBlockAt(x, y - 1, z).getType() == Material.CHEST) {
  82. Chest chest = (Chest)clickblock.getWorld().getBlockAt(x, y - 1, z).getState();
  83. if(chest.getBlockInventory().firstEmpty() == -1) {
  84. player.sendMessage(ChatColor.RED+"There is not enough space in the chest!");
  85. } else {
  86. player.getInventory().removeItem(new ItemStack(Material.matchMaterial(line4.toUpperCase()), line2));
  87. chest.getBlockInventory().addItem(new ItemStack(Material.matchMaterial(line4.toUpperCase()), line2));
  88. player.updateInventory();
  89. ShopSign.econ.depositPlayer(player.getName(), sell);
  90. ShopSign.econ.withdrawPlayer(line1, sell);
  91. player.sendMessage(ChatColor.GREEN+"You sold "+getLine2+" "+line4+" for "+sell+" "+ShopSign.econ.currencyNamePlural());
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment