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-
I would suggest looking into the PlayerInteractEvent. Take a look at the bukkit javadocs. http://jd.bukkit.org/apidocs/
I looked there, but this doesn't help me...i don't understand them...can anybody explane me this docs or the function=?
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(); plugin.DoorOpeners.add(playerName); 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; } @EventHandler public void onPlayerInteract(PlayerInteractEvent event){ Player player = event.getPlayer(); Block blocked = player.getTargetBlock(null, 4); Material block = blocked.getType(); String playerName = player.getName; if(plugin.DoorOpeners.contains(playerName){ if(block == Material.WOOD_DOOR){ player.sendMessage("Welcome home"); plugin.DoorOpeners.remove(playerName); //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);
What is manager.registerEvents(new YourDoorListener(this), this);? "Manager" gives a Error. Anything else works fine, beside a few ProgramMistakes.