Solved Event doesn't work!

Discussion in 'Plugin Development' started by ThrustLP, Jun 21, 2014.

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

    ThrustLP

    Hey guys! My PlayerMoveEvent doesn't work. Here it is:

    Code:java
    1. @EventHandler
    2. public void onMove(PlayerMoveEvent e){
    3. Player pe = e.getPlayer();
    4. if(launcher.contains(pe.getName())){
    5. if(pe.getLocation().getBlock().getType() == Material.SPONGE){
    6. Vector v = pe.getLocation().getDirection().multiply(0D).setY(5D);
    7. pe.setVelocity(v);
    8.  
    9. }
    10. }
    11.  
    12.  
    13. }


    It's also registert in my onEnable:

    Code:java
    1. public void onEnable(){
    2. System.out.println("[Tkits] ON");
    3. Bukkit.getPluginManager().registerEvents(this, this);
    4. }



    But if i walk over a sponge I don't get pushed up :/

    Why?

    Thanks!
     
  2. Offline

    NoLiver92

    Is the event registered in the main class in onEnable()?
     
  3. Offline

    ThrustLP

    NoLiver92
    The event is wirtten in my Main class.
     
  4. Offline

    xTigerRebornx

    ThrustLP Mind showing the full class?
     
  5. Offline

    ThrustLP

    xTigerRebornx

    Of coure :p Here is my nooby jave beginner class:

    Code:java
    1. package me.thrustlp.kangaroo;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Material;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.player.PlayerMoveEvent;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import org.bukkit.util.Vector;
    15.  
    16. public class Main extends JavaPlugin implements Listener{
    17.  
    18.  
    19.  
    20.  
    21.  
    22.  
    23.  
    24. ArrayList<String> launcher = new ArrayList<String>();
    25. ArrayList<String> k = new ArrayList<String>();
    26.  
    27. String noperm = "ยง4No permission! /warp donate";
    28.  
    29.  
    30. public void onEnable(){
    31. System.out.println("[Tkits] ON");
    32. Bukkit.getPluginManager().registerEvents(this, this);
    33. }
    34.  
    35. public void onDisable(){
    36.  
    37. System.out.println("[Tkits] OFF");
    38. }
    39.  
    40.  
    41.  
    42.  
    43.  
    44. public boolean onCommand(CommandSender sender, Command cmd, String cmdlabel, String[] args){
    45. Player p = (Player) sender;
    46. if(cmd.getName().equalsIgnoreCase("launcher")){
    47. if(p.hasPermission("tkits.launcher")){
    48. launcher.add(p.getName());
    49. k.add(p.getName());
    50. p.getInventory().clear();
    51.  
    52. p.sendMessage(launcher.get(0));
    53.  
    54.  
    55.  
    56. }else{
    57. p.sendMessage(noperm);
    58. }
    59. }
    60.  
    61.  
    62.  
    63.  
    64.  
    65. return false;
    66. }
    67.  
    68. @EventHandler
    69. public void onMove(PlayerMoveEvent e){
    70. Player pe = e.getPlayer();
    71. if(launcher.contains(pe.getName())){
    72. if(pe.getLocation().getBlock().getType() == Material.SPONGE){
    73. Vector v = pe.getLocation().getDirection().multiply(0D).setY(5D);
    74. pe.setVelocity(v);
    75.  
    76. }
    77. }
    78.  
    79.  
    80. }
    81.  
    82.  
    83. }
    84.  


    BTW: The array "k" is used in the next step (after fixing that fail)
     
  6. ThrustLP
    Code:java
    1. if(pe.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.SPONGE){
     
    ThrustLP likes this.
  7. Offline

    monkeymanboy

    When you do this
    Code:java
    1. if(pe.getLocation().getBlock().getType() == Material.SPONGE){

    are you trying to get the block below the player? because I think you need to subtract 1 from the players y axis to get that
     
    ThrustLP likes this.
  8. Offline

    ThrustLP

    Thanks you two!!!! Solved the problem ;)
     
Thread Status:
Not open for further replies.

Share This Page