Block Break Event

Discussion in 'Plugin Development' started by paxi, Nov 15, 2012.

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

    paxi

    Hey,

    can somebody say me where the BlockBreakEvent is?
    I want to know when a player breaks a block but i didn't find the command!

    Thanks :)
     
  2. Offline

    bryce325

  3. Offline

    Lolmewn

    And of course, @EventHandler.
     
    Jamboozlez likes this.
  4. Offline

    paxi

    Thank you, i was very blind ..... :oops:
     
  5. Offline

    fireblast709

    And do not forget to register your events. If that method is in your main class,
    add after extends JavaPlugin;
    Code:java
    1. public class [yourmainclass] extends JavaPlugin implements Listener

    add to onEnable():
    Code:java
    1. Bukkit.getPluginManager().registerEvents(this, this);


    If it is not,
    add after the class name where the function is in:
    Code:java
    1. public class [your class where the method is] implements Listener

    and register the events with an instance of your class, in onEnable()
    Code:java
    1. Bukkit.getPluginManager().registerEvents(new yourclass(), this);

    Obviously, replace the parts where I refer to 'yourclass' and 'yourmainclass', etc.
     
  6. Offline

    paxi

  7. Offline

    fireblast709

    do it like this:
    Code:java
    1. Block b = event.getBlock();
    2. int x = b.getX();
     
  8. Offline

    paxi

    I done this:
    float x,y,z;
    org.bukkit.block.Block b = event.getBlock();
    x = b.getX();

    because eclipse said some mistakes ! Thank you for your help :)

    I write now following code:
    Code:
    package me.paxi.RPhysik;
     
     
     
    import net.minecraft.server.Block;
     
    import org.bukkit.Bukkit;
    import org.bukkit.block.Biome;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class RPhysik extends JavaPlugin implements Listener{
     
       
     
     
          PluginManager manager = this.getServer().getPluginManager();
           
            public void onEnable() {
                Bukkit.getPluginManager().registerEvents(this, this);
            }
       
            public void onBlockBreak(BlockBreakEvent event){
                float x,y,z;
                org.bukkit.block.Block b = event.getBlock();
                org.bukkit.block.Block b1 = event.getBlock();
                x = b.getX();
                y = b.getY();
                z = b.getZ();
                if (b1 == Block.WOOD  ){
                    setTypeID(x+1,y+2,z+1,17);
                   
                }
                   
               
            }
     
            private void setTypeID(float f, float g, float h, int i) {
                // TODO Auto-generated method stub
               
            }
    }
    and the same mistake in my console comes which is in an other self made plugin:

    12:19:54 [SCHWERWIEGEND] Could not load 'plugins\Physik.jar' in folder 'plugins'

    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:152)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:305)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:230)
    at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:229)
    at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:205)
    at net.minecraft.server.ServerConfigurationManagerAbstract.<init>(Server
    ConfigurationManagerAbstract.java:51)
    at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)

    at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:105)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:400)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:818)
    Caused by: java.lang.NullPointerException
    at me.paxi.RPhysik.RPhysik.<init>(RPhysik.java:26)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:148)
    ... 9 more

    Plugin.yml :

    name: Physik
    main: me.paxi.RPhysik.RPhysik
    version: 0.9
    description: PRE_RELEASE




    I don't understand it.... :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  9. Offline

    bryce325

    what do you have
    Code:
                Bukkit.getPluginManager().registerEvents(this, this);
    
    remove that :/ and
    Code:
          PluginManager manager = this.getServer().getPluginManager();
    
    also add @EventHandler above the blockbreakevent
     
  10. Offline

    paxi

    public class RPhysik extends JavaPlugin implements Listener{



    PluginManager manager = this.getServer().getPluginManager();
    public void onEnable() {
    PluginManager manager = this.getServer().getPluginManager();
    }
    @EventHandler
    public void onBlockBreak(BlockBreakEvent event){
    [....]

    Same mistake :(
    I'm too silly.... ^^
     
  11. Offline

    fireblast709

    no he should only remove the PluginManger manager = ... line
     
  12. Offline

    paxi

    Which from this?
    First i deleted the first line but it doens't work so i added it again and it doens'T work again!
     
  13. Offline

    fireblast709

    Code:java
    1. package me.paxi.RPhysik;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.block.Biome;
    5. import org.bukkit.block.Block;
    6. import org.bukkit.block.BlockFace;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.Event;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.BlockBreakEvent;
    12. import org.bukkit.event.player.PlayerMoveEvent;
    13. import org.bukkit.plugin.PluginManager;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15. import org.bukkit.potion.PotionEffect;
    16. import org.bukkit.potion.PotionEffectType;
    17.  
    18. public class RPhysik extends JavaPlugin implements Listener
    19. {
    20.  
    21. public void onEnable()
    22. {
    23. Bukkit.getPluginManager().registerEvents(this, this);
    24. }
    25.  
    26. @EventHandler
    27. public void onBlockBreak(BlockBreakEvent event)
    28. {
    29. float x,y,z;
    30. Block b = event.getBlock();
    31. org.bukkit.Material b1 = b.getType();
    32. x = b.getX();
    33. y = b.getY();
    34. z = b.getZ();
    35. if (b1 == Block.WOOD )
    36. {
    37. // setting its type and id to coordinates?
    38. b.setTypeId(x+1,y+2,z+1,17);
    39. // Do you mean:
    40. b.setTypeId(Material.LOG); // example to set it to log
    41. }
    42. }
    43. }

    Apart from the fact that Im wondering what its function is (setting the block type to coordinates?)
    this code should be clean (though, as said before, the setTypeId does not take such parameters)
     
  14. Offline

    paxi

    IT doens'T works.... :( I forget to delete an ohter plugin

    I had to change the code to:
    if (b1 == Block.WOOD ){
    b.setTypeId(17);
    // Do you mean:
    b.setType(Material.LOG); //


    because eclipse said that your version had following mistake:
    The method setTypeId(int) in the type Block is not applicable for the arguments (Material)

    And i shoudl change it :(
    And so i can't change the koordinates
     
  15. Offline

    fireblast709

    a block is literally a block, a representation of what is on a given location. If you want to get another block, get the location you want to change something and change that block (Ok maybe this is a bit weird, let me explain in code:)
    Code:java
    1. Block above = b.getRelative(BlockFace.UP, 1); // gets the block above the one you break

    Besides that, setTypeId for id's, setType for Materials
     
  16. i need you help this is my main class
    and this is my listener class
    but it doesn't work
     
Thread Status:
Not open for further replies.

Share This Page