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
Code: public void onBlockBreak(BlockBreakEvent event){ really isn't that hard to find. I use http://jd.bukkit.org/doxygen/index.html to find all the thigns I need, and i recommend it.
And do not forget to register your events. If that method is in your main class, add after extends JavaPlugin; Code:java public class [yourmainclass] extends JavaPlugin implements Listener add to onEnable(): Code:java Bukkit.getPluginManager().registerEvents(this, this); If it is not, add after the class name where the function is in: Code:java public class [your class where the method is] implements Listener and register the events with an instance of your class, in onEnable() Code:java Bukkit.getPluginManager().registerEvents(new yourclass(), this); Obviously, replace the parts where I refer to 'yourclass' and 'yourmainclass', etc.
I write now x=Block.getX(); (X is float variable) but eclipse said me that the method getX is undefinied but in the http://jd.bukkit.org/apidocs/index.html?deprecated-list.html Block has the methode getX ?? Can somebody help?
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.
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
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.... ^^
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!
Code:java package me.paxi.RPhysik; import org.bukkit.Bukkit;import org.bukkit.block.Biome;import org.bukkit.block.Block;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{ public void onEnable() { Bukkit.getPluginManager().registerEvents(this, this); } @EventHandler public void onBlockBreak(BlockBreakEvent event) { float x,y,z; Block b = event.getBlock(); org.bukkit.Material b1 = b.getType(); x = b.getX(); y = b.getY(); z = b.getZ(); if (b1 == Block.WOOD ) { // setting its type and id to coordinates? b.setTypeId(x+1,y+2,z+1,17); // Do you mean: b.setTypeId(Material.LOG); // example to set it to log } }} 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)
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
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 Block above = b.getRelative(BlockFace.UP, 1); // gets the block above the one you break Besides that, setTypeId for id's, setType for Materials