Problem with jump blocks

Discussion in 'Plugin Development' started by W&L-Craft, Apr 19, 2014.

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

    W&L-Craft

    Hello, i am making a plugin that allows you to make 'Jump blocks' and i cant get it to work properly.

    I want the player to be able to do /blockjump and then when he right clicks a stone pressure plate a jumpblock will be added.

    but for some reason it is not working, here is my code:
    Code:java
    1.  
    2. package me.WLCraft.BlockJump;
    3.  
    4. import java.util.ArrayList;
    5. import java.util.List;
    6. import java.util.logging.Logger;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Location;
    9. import org.bukkit.Material;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.block.Action;
    16. import org.bukkit.event.player.PlayerInteractEvent;
    17. import org.bukkit.plugin.PluginManager;
    18. import org.bukkit.plugin.java.JavaPlugin;
    19. import org.bukkit.util.Vector;
    20.  
    21. public class BlockJump extends JavaPlugin implements Listener{
    22. public final Logger logger = Logger.getLogger("minecraft");
    23. private List<Location> jumpblock = new ArrayList<Location>();
    24. List<String> Jump = new ArrayList<String>();
    25.  
    26.  
    27.  
    28. public void onDisable(){
    29. this.logger.info("BlockJump v0.1 is now disabled");
    30. }
    31.  
    32. public void onEnable(){
    33. this.logger.info("BlockJump v0.1 is now enabled");
    34. PluginManager pm = getServer().getPluginManager();
    35. pm.registerEvents(this, this);
    36. }
    37.  
    38.  
    39. @EventHandler
    40. public void onActivate(PlayerInteractEvent e) {
    41. Player p = e.getPlayer();
    42. if(e.getAction().equals(Action.PHYSICAL))
    43. return;
    44. if(!jumpblock.contains(p.getName()))
    45. return;
    46. if(e.getClickedBlock().getType().equals(Material.STONE_PLATE))
    47. return;
    48. if(jumpblock.contains(e.getClickedBlock().getLocation())) {
    49. return;
    50. Vector jump = p.getLocation().getDirection().multiply(0.2).setY(1.1);
    51. p.setVelocity(p.getVelocity().add(jump));
    52. }
    53. }
    54.  
    55.  
    56. @EventHandler
    57. public void onPlayerInteract(PlayerInteractEvent e){
    58. Player p = e.getPlayer();
    59. if(!(e.getAction() == Action.RIGHT_CLICK_BLOCK))
    60. return;
    61. if(e.getClickedBlock().getType().equals(Material.STONE_PLATE))
    62. return;
    63. if(!Jump.contains(p.getName()))
    64. jumpblock.add(e.getClickedBlock().getLocation());
    65. e.getPlayer().sendMessage(ChatColor.GOLD + "Created jumpblock");
    66. }
    67.  
    68.  
    69. public boolean onCommand(CommandSender sender, Command cmd, String label, String [] args){
    70. Player p = (Player) sender;
    71. if(cmd.getName().equalsIgnoreCase("blockjump")){
    72. p.sendMessage(ChatColor.GOLD + "[BlockJump] You can add jump blocks by right clicking on stone pressure plates!");
    73. Jump.add(p.getName());
    74. }
    75. return true;
    76. }
    77. }
    78.  
     
  2. Offline

    coasterman10

    Check lines 61-62. This causes the method to return and the rest of the code not to execute if the material is stone pressure plate. It appears you want the opposite, so insert an exclamation point in the if statement to fix it.

    You should also consider using == instead of equals() for enum constants.
     
  3. Offline

    ever_x

    Ok, I'm on my ipad ATM so I can't be of much use, but here is how I understand your code so far, and what I believe is wrong with it.
    Firstly, in your first event handler, you check if jump block doesn't contain the players name. It should be if JUMP (not jump block) DOES contain players name. Secondly, in both handlers you check if the material is a stone plate and then return. That should be if the material isn't a stone plate, because otherwise your launch pads could be any block EXCEPT from a stone plate. Thirdly on line 63 you forgot to add a return statement. Now your code could resemble working (if I caught everything), but to me, it is way too simple. I presume you want launch pads like on HiveMc or Hypixel, so that when you walk over them they boost you. At the moment you have to click a launch pad; not entirely what I think you want. I have a very similar piece of code for my server, but instead of launch pads, you step on a pad and it teleports you to a specified location. When I'm on my pc in a couple of days, I'll post some code I think you need.
     
Thread Status:
Not open for further replies.

Share This Page