Grappler kit problems

Discussion in 'Plugin Development' started by TCO_007, Jun 8, 2014.

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

    TCO_007

    Hi! I am fairly new to coding and I am getting better every time I code. The thing is, I am not always 100 percent correct in my coding. I am having an error with my code here. Let me start off by explaining the kit. What you do is you throw the fishing rod at a block within a 100 block radius and it basically takes you in the direction of that block. My plugin, however, will not fulfill this duty. It says there are many problems with the .getX() and .getY()
    If anyone could help me correct my code, that would be fantastic!
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onGrappleThrow(ProjectileLaunchEvent e){
    4. if (plugin.Grappler.contains(p.getName())){
    5. if (!e.getEntityType().equals(EntityType.FISHING_HOOK)) return;
    6. if (!(e.getEntity().getShooter() instanceof Player)) return;
    7.  
    8. final Player p = (Player) e.getEntity().getShooter();
    9.  
    10. if (plugin.cooldown.contains(p.getName())){
    11. e.setCancelled(true);
    12. return;
    13. }
    14. Location target = null;
    15.  
    16. for (Block block : p.getLineOfSight(null, 100)){
    17. if(!block.getType().equals(Material.AIR)){
    18. target = (Location) block.getLocation();
    19. break;
    20. }
    21.  
    22. }
    23. if (target == null){
    24. e.setCancelled(true);
    25. return;
    26. }
    27.  
    28. p.teleport(p.getLocation().add(0, 0.5, 0));
    29.  
    30. final Vector v = getVectorForPoints((Location) p.getLocation(), target);
    31.  
    32. e.getEntity().setVelocity(v);
    33.  
    34. if (!plugin.nofall.contains(p)){
    35. plugin.nofall.add(p.getName());
    36. }
    37.  
    38. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    39. public void run(){
    40. p.setVelocity(v);
    41. }
    42. }, 5);
    43.  
    44. plugin.cooldown.add(p.getName());
    45. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    46. public void run(){
    47. plugin.cooldown.remove(p.getName());
    48. }
    49. }, 15);
    50. }
    51. }
    52. private Vector getVectorForPoints(Location l1, Location l2){
    53. double g = -0.08;
    54. double d = l2.distance(l1);
    55. double t = d;
    56. double vX = (1.0+0.07*t) * ( l2.getX() - l1.getX()/t);
    57. double vY = (1.0+0.03*t) * (l2.getY() - l1.getY()/t)-0.5*g*t;
    58. double vZ = (1.0+0.07*t) * (l2.getZ() - l1.getZ()/t);
    59. return new Vector(vX,vY,vZ);
    60. }
    61.  
    62. @EventHandler
    63. public void OnEntityFallDamage(EntityDamageEvent e){
    64. if (!(e.getEntity() instanceof Player)){
    65. return;
    66. }
    67. if (!e.getCause().equals(DamageCause.FALL)){
    68. return;
    69. }
    70. Player p = (Player) e.getEntity();
    71.  
    72. if (plugin.nofall.contains(p)){
    73. e.setCancelled(true);
    74. plugin.nofall.remove(p);
    75. return;
    76. }
    77. }
    78. }
    79.  

    By the way, this is a SEPERATE class from the main class of the plugin.
     
  2. Offline

    Cloaking_Ocean

Thread Status:
Not open for further replies.

Share This Page