'placing' blocks on glass

Discussion in 'Plugin Development' started by sgavster, Dec 11, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    sgavster

    zeeveener It's a problem with getAction, putting a debug under Player p = ect..

    Events are registered. I know they are. because I have like 3 events in the class that work. So I'm stumped :/
     
  2. Offline

    zeeveener

    sgavster

    Can you give us the full class with the listener inside?
     
  3. Offline

    sgavster

    Code:java
    1. public class KitDemo implements Listener
    2. {
    3. private final Main plugin;
    4. public KitDemo(Main plugin)
    5. {
    6. this.plugin = plugin;
    7. }
    8.  
    9. private List<Location> plate = new ArrayList<Location>();
    10.  
    11. @EventHandler
    12. public void onInteract(PlayerInteractEvent e)
    13. {
    14. Player p = e.getPlayer();
    15. if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
    16. {
    17. if(p.getItemInHand().getType().equals(Material.FIREBALL))
    18. {
    19. if(plugin.getDemo().contains(p.getName()))
    20. {
    21. e.setCancelled(true);
    22. final Item i = p.getLocation().getWorld().dropItemNaturally(p.getLocation(), new ItemStack(Material.FIREBALL));
    23. i.setVelocity(new Vector(p.getVelocity().getX(), p.getVelocity().getY() + 4, p.getVelocity().getZ()));
    24. i.setVelocity(p.getLocation().getDirection());
    25. i.setPickupDelay(100000);
    26. if(p.getItemInHand().getAmount() == 1)
    27. {
    28. p.setItemInHand(null);
    29. }
    30. else
    31. {
    32. p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
    33. }
    34. Bukkit.getScheduler().runTaskLater(plugin, new Runnable()
    35. {
    36. public void run()
    37. {
    38. i.getWorld().createExplosion(i.getLocation(), 2, false);
    39. i.remove();
    40. }
    41. }, 100L);
    42. }
    43. }
    44. }
    45. else if(e.getAction().equals(Action.PHYSICAL))
    46. {
    47. if(e.getClickedBlock().getType().equals(Material.STONE_PLATE))
    48. {
    49. if(plate.contains(e.getClickedBlock().getLocation()))
    50. {
    51. if(!(plugin.getDemo().contains(p.getName())))
    52. {
    53. e.getClickedBlock().setType(Material.AIR);
    54. plate.remove(e.getClickedBlock().getLocation());
    55. e.getClickedBlock().getWorld().createExplosion(e.getClickedBlock().getLocation(), 2, false);
    56. }
    57. }
    58. }
    59. }
    60. }
    61. @EventHandler
    62. public void onCreate(PlayerInteractEvent e)
    63. {
    64. Player p = e.getPlayer();
    65. Bukkit.broadcastMessage("0");
    66. if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
    67. {
    68. Bukkit.broadcastMessage("1");
    69. if(p.getItemInHand().getType().equals(Material.STONE_PLATE))
    70. {
    71. Bukkit.broadcastMessage("2");
    72. if(plugin.getDemo().contains(p.getName()))
    73. {
    74. Bukkit.broadcastMessage("3");
    75. if(e.getClickedBlock() != null && e.getClickedBlock().getType() != null)
    76. {
    77. Bukkit.broadcastMessage("4");
    78. Location u = new Location(e.getClickedBlock().getWorld(), e.getClickedBlock().getLocation().getX(), e.getClickedBlock().getLocation().getY() + 1, e.getClickedBlock().getLocation().getZ());
    79. plate.add(u);
    80. u.getBlock().setType(Material.STONE_PLATE);
    81. if(p.getItemInHand().getAmount() == 1)
    82. {
    83. p.setItemInHand(null);
    84. }
    85. else
    86. {
    87. p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
    88. }
    89. p.sendMessage("You create a land mine! Punch it to remove it!");
    90. }
    91. }
    92. }
    93. }
    94. }
    95. @EventHandler
    96. public void onPlace(BlockPlaceEvent e)
    97. {
    98. Player p = e.getPlayer();
    99. Block b = e.getBlock();
    100. if(b.getType().equals(Material.STONE_PLATE))
    101. {
    102. if(plugin.getDemo().contains(p.getName()))
    103. {
    104. plate.add(b.getLocation());
    105. p.sendMessage("You create a land mine! Punch it to remove it!");
    106. }
    107. }
    108. }
    109. @EventHandler
    110. public void onDe(BlockDamageEvent e)
    111. {
    112. Player p = e.getPlayer();
    113. Block b = e.getBlock();
    114. if(b.getType().equals(Material.STONE_PLATE))
    115. {
    116. if(plate.contains(e.getBlock().getLocation()))
    117. {
    118. if(plugin.getDemo().contains(p.getName()))
    119. {
    120. e.getBlock().setType(Material.AIR);
    121. plate.remove(e.getBlock().getLocation());
    122. p.sendMessage("You removed a land mine!");
    123. p.getInventory().addItem(setNameAndLore(Material.STONE_PLATE, 1, "&bLand Mine", Enchantment.WATER_WORKER, 10));
    124. }
    125. }
    126. }
    127. }
    128. public ItemStack setNameAndLore(Material material, int amount, String name, Enchantment enchant, int enchantamount, String... lore)
    129. {
    130. ItemStack item = new ItemStack(material, amount);
    131. item.addUnsafeEnchantment(enchant, enchantamount);
    132. ItemMeta meta = item.getItemMeta();
    133. meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
    134. ArrayList<String> lorez = new ArrayList<String>();
    135. for(String mylores : lore)
    136. {
    137. lorez.add(ChatColor.translateAlternateColorCodes('&', mylores));
    138. }
    139. meta.setLore(lorez);
    140. item.setItemMeta(meta);
    141. return item;
    142. }
    143. }
     
  4. Offline

    zeeveener

    sgavster

    You're class is still using the problem setup with the if/else statements. Action.PHYSICAL, I have no idea what that is or when it's called.

    Try checking what is in the hand FIRST, and then determine what to do.

    Code:java
    1. if(itemInHand == Stick){
    2. if(action = block){}
    3. }else if(itemInHand == Fireball){
    4. if(action == block || action == air){}
    5. }
     
  5. Offline

    sgavster

    zeeveener ...
    The event I'm having problems with is the onCreate().

    I don't see how that is causing anything, it's a different event. Action.PHYSICAL is when you stand on pressureplates and such. Everything works but this 1 event.
     
  6. Offline

    zeeveener

    sgavster

    I keep getting lost lol. I'm sorry, finals week has my brain running on fumes.
    I don't know what is wrong with it. I would try the following though:

    Using if(getAction() == Action.RIGHT_CLICK_BLOCK) instead of if(getAction().equals(Action.RIGHT_CLICK_BLOCK)

    Other than that, I am not sure, sorry.
     
  7. Offline

    sgavster

  8. Offline

    zeeveener

    sgavster

    The final advice I can give is try merging the two PlayerInteractEvents. I doubt that'll do anything, but who knows.
     
  9. Offline

    ZeusAllMighty11

    Why create a new location when you can get the clicked location and add 1 to the y?
     
  10. Offline

    sgavster

    ZeusAllMighty11 I had it like that before. I will change it back once I can figure out why it's not checking right_click_block :/

    sgavster ZeusAllMighty11 It works.. Sorta.. It's still counting as null. (the block) and now my grenade wont work.

    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e)
    3. {
    4. Player p = e.getPlayer();
    5. if(e.getAction().equals(Action.RIGHT_CLICK_AIR))
    6. {
    7. Bukkit.broadcastMessage("1");
    8. if(p.getItemInHand().getType().equals(Material.STONE_PLATE))
    9. {
    10. Bukkit.broadcastMessage("2");
    11. if(plugin.getDemo().contains(p.getName()))
    12. {
    13. Bukkit.broadcastMessage("3");
    14. if(e.getClickedBlock() != null && e.getClickedBlock().getType() != null)
    15. {
    16. Bukkit.broadcastMessage("4");
    17. Location l = e.getClickedBlock().getLocation();
    18. plate.add(l.add(0, 1, 0));
    19. l.add(0, 1, 0).getBlock().setType(Material.STONE_PLATE);
    20. if(p.getItemInHand().getAmount() == 1)
    21. {
    22. p.setItemInHand(null);
    23. }
    24. else
    25. {
    26. p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
    27. }
    28. }
    29. }
    30. }
    31. }
    32. else if(e.getAction().equals(Action.RIGHT_CLICK_AIR))
    33. {
    34. if(p.getItemInHand().getType().equals(Material.FIREBALL))
    35. {
    36. if(plugin.getDemo().contains(p.getName()))
    37. {
    38. e.setCancelled(true);
    39. final Item i = p.getLocation().getWorld().dropItemNaturally(p.getLocation(), new ItemStack(Material.FIREBALL));
    40. i.setVelocity(new Vector(p.getVelocity().getX(), p.getVelocity().getY() + 4, p.getVelocity().getZ()));
    41. i.setVelocity(p.getLocation().getDirection());
    42. i.setPickupDelay(100000);
    43. if(p.getItemInHand().getAmount() == 1)
    44. {
    45. p.setItemInHand(null);
    46. }
    47. else
    48. {
    49. p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
    50. }
    51. Bukkit.getScheduler().runTaskLater(plugin, new Runnable()
    52. {
    53. public void run()
    54. {
    55. i.getWorld().createExplosion(i.getLocation(), 2, false);
    56. i.remove();
    57. }
    58. }, 100L);
    59. }
    60. }
    61. }
    62. else if(e.getAction().equals(Action.PHYSICAL))
    63. {
    64. if(e.getClickedBlock().getType().equals(Material.STONE_PLATE))
    65. {
    66. if(plate.contains(e.getClickedBlock().getLocation()))
    67. {
    68. if(!(plugin.getDemo().contains(p.getName())))
    69. {
    70. e.getClickedBlock().setType(Material.AIR);
    71. plate.remove(e.getClickedBlock().getLocation());
    72. e.getClickedBlock().getWorld().createExplosion(e.getClickedBlock().getLocation(), 2, false);
    73. }
    74. }
    75. }
    76. }
    77. }

    I'm really stumped. :/

    I have no idea what to do.. Any ideas? :/

    EDIT: never mind.. For some reason RIGHT_CLICK_BLOCK will not work.. At all. The code above was just both RIGHT_CLICK_AIR. I changed it to block, and it doesn't work.. at all.. :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  11. Offline

    zeeveener

    Code:java
    1.  
    2. if(e.getAction().equals(Action.RIGHT_CLICK_AIR)){
    3. //Called if right clicked air
    4. }else else if(e.getAction().equals(Action.RIGHT_CLICK_AIR)){
    5. //Never called
    6. }else if(e.getAction().equals(Action.PHYSICAL)){
    7. //Called if stood on.
    8. }
    9.  


    Change it to:

    Code:java
    1.  
    2. if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
    3. //Called if right clicked block (won't be null)
    4. }else else if(e.getAction().equals(Action.RIGHT_CLICK_AIR)){
    5. //Called if right clicked air (grenade)
    6. }else if(e.getAction().equals(Action.PHYSICAL)){
    7. //Called if stood on.
    8. }
    9.  
     
  12. Offline

    sgavster

    zeeveener How would I fix then? I have
    RIGHT_CLICK_BLOCK
    RIGHT_CLICK_AIR
    PHYSICAL

    Physical and right_click_air works, not right_click_block, and they ARE in the order I just stated.
     
  13. Offline

    zeeveener

    Perhaps RIGHT_CLICK_BLOCK is deprecated?

    sgavster

    I just copied over your text into a test plugin. It works properly for me. I'll give you the code so you can see for yourself. http://pastebin.com/Pcbv5Sfz

    I removed the references to the getDemo() method. See if that is causing problems. Otherwise, you can create a new plugin and throw this in and it will work fine.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  14. Offline

    sgavster

    zeeveener



    Ignore the lag, crapooter. :p

    I had a video, but youtube hates me and failed to process.
    With the code:

    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e)
    3. {
    4. Player p = e.getPlayer();
    5. if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
    6. {
    7. Bukkit.broadcastMessage("§6§lThe action was RIGHT_CLICK_BLOCK!");
    8. if(p.getItemInHand().getType().equals(Material.STONE_PLATE))
    9. {
    10. Bukkit.broadcastMessage("§6§lYou have a STONE_PLATE in your hands!");
    11. if(plugin.getDemo().contains(p.getName()))
    12. {
    13. Bukkit.broadcastMessage("§6§lYou're a demo!");
    14. if(e.getClickedBlock() != null && e.getClickedBlock().getType() != null)
    15. {
    16. Bukkit.broadcastMessage("§6§lIt's not null!");
    17. Location l = e.getClickedBlock().getLocation();
    18. plate.add(l.add(0, 1, 0));
    19. l.add(0, 1, 0).getBlock().setType(Material.STONE_PLATE);
    20. if(p.getItemInHand().getAmount() == 1)
    21. {
    22. p.setItemInHand(null);
    23. }
    24. else
    25. {
    26. p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
    27. }
    28. p.sendMessage("§3[§fGhost§6Squadron§3]§6 You create a land mine! Punch it to remove it!");
    29. }
    30. }
    31. }
    32. }
    33. else if(e.getAction().equals(Action.RIGHT_CLICK_AIR))
    34. {
    35. Bukkit.broadcastMessage("§6§lThe action was RIGHT_CLICK_AIR!");
    36. if(p.getItemInHand().getType().equals(Material.FIREBALL))
    37. {
    38. Bukkit.broadcastMessage("§6§lYou have a FIREBALL in your hands!");
    39. if(plugin.getDemo().contains(p.getName()))
    40. {
    41. Bukkit.broadcastMessage("§6§lYou're a demo!");
    42. e.setCancelled(true);
    43. final Item i = p.getLocation().getWorld().dropItemNaturally(p.getLocation(), new ItemStack(Material.FIREBALL));
    44. i.setVelocity(new Vector(p.getVelocity().getX(), p.getVelocity().getY() + 4, p.getVelocity().getZ()));
    45. i.setVelocity(p.getLocation().getDirection());
    46. i.setPickupDelay(100000);
    47. if(p.getItemInHand().getAmount() == 1)
    48. {
    49. p.setItemInHand(null);
    50. }
    51. else
    52. {
    53. p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
    54. }
    55. Bukkit.getScheduler().runTaskLater(plugin, new Runnable()
    56. {
    57. public void run()
    58. {
    59. i.getWorld().createExplosion(i.getLocation(), 2, false);
    60. i.remove();
    61. }
    62. }, 100L);
    63. }
    64. }
    65. }
    66. else if(e.getAction().equals(Action.PHYSICAL))
    67. {
    68. if(e.getClickedBlock().getType().equals(Material.STONE_PLATE))
    69. {
    70. if(plate.contains(e.getClickedBlock().getLocation()))
    71. {
    72. if(!(plugin.getDemo().contains(p.getName())))
    73. {
    74. e.getClickedBlock().setType(Material.AIR);
    75. plate.remove(e.getClickedBlock().getLocation());
    76. e.getClickedBlock().getWorld().createExplosion(e.getClickedBlock().getLocation(), 2, false);
    77. }
    78. }
    79. }
    80. }
    81. }


    For some reason it was saying the action was RIGHT_CLICK_AIR when I had a pressure plate in my hand.. And I was clicking a block..

    zeeveener I tried your code.. I added the getDemo(), and right_click_block wont work. But right_click_air does.
    But, right_click_block isn't called. "1" is never said in chat.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  15. Offline

    zeeveener

    sgavster

    Then it is a problem with the rest of your plugin. Make sure you properly registered it. Even if you know so, just make sure. Something else is causing problems because it works fine on my machine.

    Try this jar: https://dl.dropboxusercontent.com/u/263832/Test-0.0.1-SNAPSHOT.jar
    It is my build.

    At this point, I would start branching out.

    What happens when you make a BRAND NEW plugin JUST using the class I gave you?
    What version of Bukkit are you using? Is it the most up to date version?
    What JDK are you compiling against? Is it 1.6 or 1.7?
    What JRE are you running Minecraft and the server in? Is it JRE6 or JRE7?
     
  16. Offline

    sgavster

    zeeveener Okay, now I'm confused:

    I'm clicking the ground with Air and it's saying '1'

    Then, I hold StonePlate and it doesn't say 1.. I'm really confused (I removed the demo check..)
     
  17. Offline

    zeeveener

  18. Offline

    sgavster

    zeeveener
    1. it works, but a pressure plate drops when I place it
    2. #2942
    3. 1.7.2
    4. MC: JRE7, server: not sure, dedicated host
     
  19. Offline

    zeeveener

    sgavster

    The pressure plate dropping is just a side effect. You can handle that when you figure out what is hanging up the plugin in he first place.

    There is no reason why your plugin shouldn't work using my version of the code. I would suggest you take the time to go through your code as if it was starting on the server and envision what happens when you click a block. Perhaps by tracing the code, you will find a bug or inconsistency.
     
  20. Offline

    sgavster

  21. Offline

    maxben34

    It should be impossible to place a pressure plate on glass. I don't think forcing it to be placed on glass, through code will actually allow it to be placed. That might just be the issue at hand here. At this point, I've never seen a pressure plate placed on glass in minecraft so idk. sgavster
     
  22. Offline

    sgavster

Thread Status:
Not open for further replies.

Share This Page