Solved How to be constantly checking for a player's item in hand?

Discussion in 'Plugin Development' started by Lanuk, Oct 20, 2012.

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

    Lanuk

    Hello,

    I am pretty bad with bukkit and coding, so I apologize if don't understand something, but I would like to make a plugin that will take some action when a player is weilding a certain item. I tried using PlayerItemHeld, PlayerPickupItem, PlayerDropItem, etc. events, but accounting for EVERYTHING that could happen to an item in a players hand was simply proving too troublesome, and I could not figure out some of them.

    For this reason I am wondering if there is alternative, such as constantly checking the player's iteminhand, without creating lag or anything.

    Help would be appreciated, thanks!
     
  2. Offline

    TwistedMexi

    I doubt this is the right way to go about it, but before I can be sure: What are you trying to accomplish with this?
     
    Woobie likes this.
  3. Offline

    Woobie

    Not sure if there is a way to check the item in hand without repeating task, I might be wrong.
    You could do this, but it will probably lagg your server
    Code:
    @EventHandler
        public void onPlayerJoin(final PlayerJoinEvent e) {
            this.getServer().getScheduler().scheduleAsyncRepeatingTask((Plugin) this, new Runnable() {
     
                  public void run() {
                      Player player = e.getPlayer();
                      if (player.getItemInHand().getType() == Material.SOMETHING);
                          //do something
                  }
                }, 0L, 20L);
     
  4. Offline

    Lanuk

    Ah thanks guys, and yeah, I suppose it would cause a lot of lag if you were constantly checking. Basically I want to modify mcMMO skills of a player when they are holding an item with certain enchantments on it, and only when they are holding this item.

    So far I have accounted for when they switch the selected item in their inventory "tray" thing, and when they drop an item, but the others seem to be getting more difficult, and I can't figure out how to account for when a player uses their mouse to swap inventory items.
     
  5. Offline

    TwistedMexi

    Well the thing is, most likely what you're trying to modify won't matter when they simply select the item (since this doesn't imply any type of action to anyone/anything outside of the player)

    Depending on the skills, you may want to tap into when the player right-clicks and check for the item in hand there instead - but I'm not familiar with mcMMO so idk.
     
  6. Offline

    Lanuk

    Hmm, that's not a bad idea--I could make the abilities activate on right-click. The problem is that that would interfere with the blocking thing with swords.

    EDIT: also it interferes with mcmmo abilities, and it will be a pain for players.. but I suppose if there is no other way I will go with this.
     
  7. Offline

    Tehmaker

    Use a timer?
     
  8. Offline

    Lanuk

    So then, before I mark this as solved, just wanted to see if anyone else had some ideas on how I could do this efficiently.

    Weird, we posted at the same time lol. If you mean check during certain time intervals, that unfortunately wont work since I need it to change the instant the player changes the item in their hand :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
Thread Status:
Not open for further replies.

Share This Page