getBlock event

Discussion in 'Plugin Development' started by pr33dat0r, Oct 11, 2012.

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


    Hey BukkitCommunity!

    I know, i am a totally noob in programming BukkitPlugins! But please help me to learn this.
    My Problem:

    When a Player "clicks" after a Command on a Door, there should happen something...But how i can check if the player had clicked on a door, and on which position the door is? I know that i can maybe use BlockDamageEvent and getBlock...Listeners/Events etc.! But can anybody help me?

    Much Thanks!
    Greetz pr33dat0r

    -sry for my english-
  2. Offline

    Infamous Jeezy

  3. Offline


    I looked there, but this doesn't help me...i don't understand them...can anybody explane me this docs or the function=?
  4. Offline


    First make the command.

    public ArrayList<String> DoorOpeners;
    public void onEnable(){
    this.getCommand("DoorOpen").setExecutor(new YourCommandClass(this));
    this.DoorOpeners = new ArrayList<String>();
    //edit add this.
    manager.registerEvents(new YourDoorListener(this), this);

    Now create YourCommandClass.

    It should look like this :

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class SpecialCommandClass implements CommandExecutor{

    private YourMainClass plugin;

    public YourCommandClass(YourMainClass plugin){
    this.plugin = plugin;

    public boolean onCommand(CommandSender sender, Command command, String label,String[] args){
    if (sender instanceof Player == false){
    sender.sendMessage(ChatColor.RED + "Sorry this command can only be used ingame.");
    return true;


    Player player = (Player) sender;
    String playerName = player.getName();
    player.sendmessage("You now use door open mode")
    return true;

    Now create a new class for getting when he opens a door.

    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;

    public class YourDoorListener implements Listener{

    private YourMainClass plugin;

    public YourDoorListener(YourMainClass plugin){
    this.plugin = plugin;


    public void onPlayerInteract(PlayerInteractEvent event){
    Player player = event.getPlayer();
    Block blocked = player.getTargetBlock(null, 4);
    Material block = blocked.getType();
    String playerName = player.getName;
    if(block == Material.WOOD_DOOR){
    player.sendMessage("Welcome home");
    //you could just put anything here

    I haven't tested this so if you get any roblems just pm me.
    Credit me if you used this.

    Edit! Forgot to mention that you should register the events of the doorListener in onenable with:

    manager.registerEvents(new YourDoorListener(this), this);

  5. Offline


    What is manager.registerEvents(new YourDoorListener(this), this);?

    "Manager" gives a Error. Anything else works fine, beside a few ProgramMistakes.
  6. Offline


    Just do
    PluginManager manager = this.getServer().getPluginManager();
    Before the manager itself
Thread Status:
Not open for further replies.

Share This Page