InstaBreak

Discussion in 'Plugin Development' started by H4ckHunt3r, Aug 7, 2011.

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

    H4ckHunt3r

    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)
     
  2. Offline

    Shamebot

    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.
     
    H4ckHunt3r likes this.
  3. Offline

    Crash

    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());
     
  4. How about setInstaBreak(true) in onBlockDamage? I'm not sure if that calls a BlockBreakEvent, though.
     
  5. Offline

    H4ckHunt3r

    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.
     
    Last edited by a moderator: May 18, 2016
  6. 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().
     
    H4ckHunt3r likes this.
  7. Offline

    shamonj03

    You are right on :p
    Code:
        @Override
        public void onBlockDamage(BlockDamageEvent event) {
            event.setInstaBreak(true);
        }
     
Thread Status:
Not open for further replies.

Share This Page