Read

Discussion in 'Plugin Development' started by Jayyy, Oct 17, 2015.

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

    Jayyy

    1.) I know the title is dumb but I couldn't rephrase it.
    2.) What I'm trying to ask is, how could I make something happen automatically instead of a player issuing a command or using an event. Example: If a player has an item in their inventory such as stone it will teleport them somewhere instead of them performing a command or if they move on a playermoveevent.
    - Thanks for your time and I hope I don't seem stupid asking this question ;l
     
  2. Offline

    Zombie_Striker

    @Jayyy
    If you don't want to use events or commands/ the next step would be to set up tasks. You can set up a delayed task that will trigger after ___ seconds after an event (this can be randomized if you want), or you can set up a repeating task that randomly selects a time to get triggered.
     
  3. Offline

    Scimiguy

    @Jayyy @Zombie_Striker

    Actually, if you are wanting a player to be teleported when they get an item in their inventory, you can listen to the PlayerPickupItemEvent

    There's various events you can listen to which will activate at different times, it's worth looking at the different ones available.
    If you don't understand how to do the bits after that, I'd suggest you google some basic Java techniques and learn about that a bit more.
    If you don't want to learn how to do it, then make a plugin request instead
     
    Zombie_Striker likes this.
  4. Offline

    Jayyy

    That was an example... I know basic Java and some more.
     
  5. The problem with it is that there are many more ways to get an item, for example taking it out of a chest, inventory.addItem in code etc.
    so a repeating task between 1 and 5 ticks would be the best solution
     
  6. Offline

    Reynergodoy

    PlayerMoveEvent
    check every tick if p has item in inventory
     
  7. No. This is bad.
    You ask why? What if the player doesn't move and he picks up an item? Then it doesn't work.
    And I have to say it again: Create one repeating task (in onEnable). That will work for any cases of items appearing in a players inventory. And isn't even that hard to setup:
    Code:
    new BukkitRunnable() {
    public void run() {
    //Loop through all online players and make your item checks
    }
    }.runTaskTimer(plugin instance, 0, period in ticks);
    plugin instance: If you know java you should know what an instance is, otherwise: google it
    period in ticks: 20 ticks = 1 second so if you want it to check every 1/4 second use 5 ticks. The smallest period you can have is 1 ticks which is 1/20 seconds.

    Thats it :D
     
  8. Offline

    Xerox262

    What's wrong with using pickup event and inventory click event?
     
  9. Offline

    mythbusterma

    @Xerox262

    Nothing, he was saying don't use PlayerMoveEvent, because that's just stupid, frankly.
    @Jayyy
    Okay, so you know basic Java and your question has been answered (either use pick up events or scheduled tasks).

    What's your question?
     
  10. Offline

    Jayyy

    Got it Thanks to you all :)
     
Thread Status:
Not open for further replies.

Share This Page