Solved PlayerMoveEvent

Discussion in 'Plugin Development' started by bwfcwalshy, Aug 19, 2014.

Thread Status:
Not open for further replies.
  1. Ok So i am making it so when you move on a block (mossy stone brick) it gives you speed until you go off but its not giving me speed.

    Code for the event
    Code:java
    1. @EventHandler
    2. public void onPlayerMove(PlayerMoveEvent e){
    3. final Player player = e.getPlayer();
    4.  
    5. @SuppressWarnings("deprecation")
    6. ItemStack is = new ItemStack(Material.getMaterial(main.getConfig().getInt("SpeedBlock")));
    7. Block block = player.getLocation().getBlock().getRelative(0, -1, 0);
    8.  
    9. if(block == is){
    10. player.addPotionEffect(speedBlock);
    11. hasSpeed = true;
    12. }else{
    13. if(hasSpeed == true){
    14. player.removePotionEffect(PotionEffectType.SPEED);
    15. }
     
  2. Offline

    teej107

    You're checking if Block == ItemStack
     
  3. teej107 I can't use anything else.
     
  4. Offline

    br456

    bwfcwalshy
    Code:java
    1. if( block.getType()==is.getType() )
     
  5. br456 Now I get a exception every time I walk.
    Code:
    [20:13:04 ERROR]: Could not pass event PlayerMoveEvent to Speed_Block v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:294) ~[custom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[custom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:501) [custom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:486) [custom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java
    :235) [custom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.PacketPlayInFlying.a(SourceFile:137) [cu
    stom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.PacketPlayInPosition.handle(SourceFile:6
    3) [custom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157
    ) [custom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [cust
    om.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:6
    67) [custom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:2
    60) [custom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:5
    58) [custom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java
    :469) [custom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:6
    28) [custom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
            at org.bukkit.inventory.ItemStack.<init>(ItemStack.java:68) ~[custom.jar
    :git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at org.bukkit.inventory.ItemStack.<init>(ItemStack.java:46) ~[custom.jar
    :git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at com.bwfcwalshy.blockspeed.SpeedBlock.onPlayerMove(SpeedBlock.java:30)
    ~[?:?]
            at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source) ~[?:?]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_51]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:292) ~[custom.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            ... 13 more
    Error line:
    Code:java
    1. ItemStack is = new ItemStack(Material.getMaterial(main.getConfig().getInt("Speed-Block")));
     
  6. Offline

    br456

  7. Offline

    kurtv

    bwfcwalshy
    Code:java
    1. getInt("Speed-Block")

    wtf i think "Speed-Block" is a string not an integer .__.

    Do:
    Code:
    getString("Speed-Block")
    .__.
     
  8. Offline

    br456

    kurtv
    He is reading an int from the config file, the path is Speed-Block
     
  9. kurtv br456
    Code:
    #SpeedBlock config
    Speed-Block: 98:1
     
  10. Offline

    br456

    bwfcwalshy
    98:1 is not an integer
    You can not have colons in an integer
     
  11. br456 So how would I do the metadata bit (I believe its the metadata, the way to make it mossy stone brick)
     
  12. Offline

    Necrodoom

  13. Necrodoom Like?
    Code:java
    1. String[] isBlock = main.getConfig().getString("Speed-Block").split(":");
    2. ItemStack is = new ItemStack(Material.getMaterial(isBlock);
     
  14. Offline

    br456

    bwfcwalshy
    You can't use a string array to get a material
     
  15. br456 So how could I do this?
     
  16. Offline

    Necrodoom

    bwfcwalshy read the itemstack javadocs and see how it works.
     
  17. br456 I tried isBlock.toString() but that didn't work either.
     
  18. Offline

    br456

    bwfcwalshy likes this.
  19. Offline

    Necrodoom

    If you think you can simply .toString an array and get a meaningful result, you need to learn Java before trying to do any of this.
     
  20. br456 Thank you, 1. For being nice and not just saying I need to lean Java 2. For proving resources aswell.
    I should of guessed you needed to use isBuild[0/1] Same as with arguments, Guess i'm not thinking right today. Thank you so much.
     
  21. Offline

    Necrodoom

    bwfcwalshy you don't know where the javadocs are at?
     
  22. Necrodoom There are 2 ways to get to them, search bukkit javadocs or go to jd.bukkit.org, but what I want is that he sent a link with lead right to the ItemStack part he was talking about.
     
  23. Offline

    Necrodoom

    bwfcwalshy which I asked you to look at too.
    If you just claim that I'm not nice because I actually get you to work for yourself this won't get far.
     
Thread Status:
Not open for further replies.

Share This Page