ProtectionBuyPlot.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package me.km.plots;
  2. import me.km.api.GlobalText;
  3. import me.km.api.Module;
  4. import me.km.inventory.InventoryUtils;
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.state.IBlockState;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.init.Blocks;
  9. import net.minecraft.init.Items;
  10. import net.minecraft.item.ItemStack;
  11. import net.minecraft.tileentity.TileEntitySign;
  12. import net.minecraft.util.EnumHand;
  13. import net.minecraft.world.World;
  14. import net.minecraftforge.event.entity.player.PlayerInteractEvent;
  15. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  16. public class ProtectionBuyPlot extends Protection
  17. {
  18. public ProtectionBuyPlot(Module m)
  19. {
  20. super(m);
  21. }
  22. /*@SubscribeEvent
  23. public void markRegion(PlayerInteractEvent.RightClickBlock e)
  24. {
  25. if(e.getHand() == EnumHand.OFF_HAND)
  26. {
  27. return;
  28. }
  29. World w = e.getWorld();
  30. IBlockState state = w.getBlockState(e.getPos());
  31. Block b = state.getBlock();
  32. if(b != Blocks.WALL_SIGN && b != Blocks.STANDING_SIGN)
  33. {
  34. return;
  35. }
  36. EntityPlayer p = e.getEntityPlayer();
  37. TileEntitySign sign = (TileEntitySign) w.getTileEntity(e.getPos());
  38. if(sign == null)
  39. {
  40. this.getModule().send(p, GlobalText.shouldNotHappen());
  41. return;
  42. }
  43. System.out.println("SIGN::" + sign.signText[0].getFormattedText());
  44. if(!sign.signText[0].getFormattedText().equals("[§6Plot§0]"))
  45. {
  46. return;
  47. }
  48. int costs;
  49. try
  50. {
  51. String s = sign.signText[1].getUnformattedText();
  52. if(!s.contains(" "))
  53. {
  54. throw new NumberFormatException();
  55. }
  56. costs = Integer.parseInt(s.substring(2, s.indexOf(" ")));
  57. if(costs < 0)
  58. {
  59. throw new NumberFormatException();
  60. }
  61. }
  62. catch(NumberFormatException ex)
  63. {
  64. this.getModule().send(p, "Die angegebenen Kosten sind ungültig.");
  65. return;
  66. }
  67. if(InventoryUtils.searchInventoryFor(p.inventory, new ItemStack(Items.EMERALD), false) < costs)
  68. {
  69. this.getModule().send(p, "Du hast zu wenig Emeralds dabei.");
  70. return;
  71. }
  72. try
  73. {
  74. int id = Integer.parseInt(sign.signText[2].getUnformattedText());
  75. if(id < 0)
  76. {
  77. throw new NumberFormatException();
  78. }
  79. if(!this.getProtectionBank().doesPlotExist(id))
  80. {
  81. this.getModule().send(p, "Der Plot mit der ID '" + id + "' ist nicht vorhanden.");
  82. return;
  83. }
  84. this.getProtectionBank().addPlayer(id, p.getGameProfile(), p);
  85. InventoryUtils.removeFromInventory(p.inventory, new ItemStack(Items.EMERALD, costs));
  86. w.setBlockToAir(e.getPos());
  87. }
  88. catch(NumberFormatException ex)
  89. {
  90. this.getModule().send(p, GlobalText.noNaturalNumber());
  91. }
  92. }*/
  93. }