Hello, at this moment I'm tryin to write my first Bukkit plugin. For the first one I choosen to write an Basic-Admin Plugin. Already working commands: Code: heal: description: Heals you or another Player. usage: /<command> [playername] i: description: Gives you or another player some item usage: /<command> <itemId> [amount] [playername] w: description: Manages the weather usage: /<command> <sun|storm|thunder> [duration] time: description: Simple time management usage: /<command> <day|night> rep: description: repair breakable items in your hand/inventory. usage: /<command> [all] now i wanted to create an command for instantBreak blocks. Code: break: description: adds you or another player the ability to break blocks instantly or by normal amount of hits usage: /<command> <instant|normal> [player] But i dont know what i have to do, a friend told me that i would need to create an EventListener for that, now i added an PlayerEventListener.. But how do I add some players the ability to instant break blocks? Someone help me pls.. (Sorry for my bad English)
Listen to PlayerInteract, check if it's a leftclick against a block, check if the player is allowed to use instant break/ if it's enabled, set the block to air, spawn an item. You then could call the blockbreak event so nobody can use it inside a worldguard region. Tell me at which step you need help.
This is a fast way to get it to instantly break (however it uses craftbukkit so you'll need that too) Code: ((CraftPlayer)player).getHandle().itemInWorldManager.c(block.getX(), block.getY(), block.getZ());
How about setInstaBreak(true) in onBlockDamage? I'm not sure if that calls a BlockBreakEvent, though.
Thank you all, @ Bone: setInstaBreak in onBlockDamage was the first thing i tryed.. but then the server console got spammed with errors on every hit on an block^^ @ Shamebot: Thanks, did not notice the PlayerInteract Event, this lead me to the solution.. InstaBreak is now working.. now I will just have to filter the Players for their right, after I came back home from work. Code: public void onPlayerInteract(PlayerInteractEvent e) { e.getClickedBlock().setTypeId(0); } Ok, I don't know if I maybe shoud open a new thread, but I'm working on the Players Right or Ability to instant break blocks. I thougth about adding the Player an new attribut/properity and check the ability is true/false when the Player is hiting some block, it should be only set for the current session! Can someone help me again, pls? I don't know how to add a new attribut/properity to an player :/ If you know another solution for that problem, tell me pls. :/ EDIT by Moderator: merged posts, please use the edit button instead of double posting.
You can't and shouldn't modify the Player class itself. It's best to save properties about players in a Collection like a HashMap, a List or a Set. As you only need boolean information, a List would be enough and you only check if the player is in the list. But to increase perfomance and simplicity, a Set (HashSet) would be even better. Set<Player> enabledPlayers = new HashSet<Player>(); To "enable" the player, just put it into the set. To see if it's enabled, use contains().
You are right on Code: @Override public void onBlockDamage(BlockDamageEvent event) { event.setInstaBreak(true); }