Click Sign Twice to Continue

Discussion in 'Plugin Development' started by Lavabird, Feb 10, 2015.

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

    Lavabird

    Hey everyone, this is my first forum post in the Bukkit forums. I'm in the middle of creating a plugin where the player right clicks a sign to receive a class. I have this working, however, I want to make it so that the player is prompted with a warning on the first right click, in which he or she can then right click AGAIN to confirm their action. I can't quite figure this out, so any help would be greatly appreciated :D
     
  2. @Lavabird Onthe first click check if it's a right click, and then send them a message.
     
  3. Offline

    SuchSwegMuchWow

    @Lavabird When theh first click the sign, add them to an ArrayList then on the second click, ceck if they are in ArrayList and give them the class and remove them
     
    FisheyLP likes this.
  4. Offline

    coasterman10

  5. Offline

    nj2miami

    If you use a Set, then schedule a task to remove them after say 3 seconds so that a person who clicks it at some point isn't perpetually flagged as clicking it. When they click it the first time, add them. If they click it and they exist in the Set, then it must be a second click so then do whatever code you want.

    So:

    Right click: check if they exist in the Set
    if No: add to set and start timer
    if Yes: Do code and remove from Set to stop additional processing (triple clicking)

    I warn you that this COULD still produce triple clicks (or additional double click events put another way) if your code does not execute fast enough.

    Because of this, I would recommend a HashMap<UUID, Long>. Store the UUID and current time in ms. (System.currentTimeMillis or somethign like that). Make sure at least 1 second has passed from the last click or something.
     
  6. Offline

    mythbusterma

    @nj2miami

    But actually, it can't.

    The entire Bukkit API is written synchronously, and the events are guaranteed to be called one after another. The execution time of your code is COMPLETELY irrelevant to this order, as the server will not be allowed to call any more events until the execution of your code has completed.

    So I have absolutely no idea what you're on about. Also, the most common set (HashSet) is just a HashMap with no values in the buckets.

    Unless OP is worried about the effects of someone clicking this sign more than once (which I don't see any reason to be), your post is unfounded.
     
    Last edited: Feb 10, 2015
  7. Offline

    nj2miami

    Did you even READ the OP post? He is trying to detect a SECOND CLICK from the user. Not a SINGLE CLICK. So, rather then inserting your ego into a conversation for the sake of reading yourself, how about you apply some constructive feedback rather than attack a provided solution?

    Without framing the click into some context, they would all be SINGLE CLICKS. You also would not want a user who has clicked a sign once to be in a set that says he clicked this sign SOME TIME. You want to know they clicked it within a relative time frame from a previous click.
     
  8. Offline

    mythbusterma

    @nj2miami

    Fair enough, I didn't read the post carefully.

    You're still completely unfounded in this "execution time" claim you make.

    There is also still no reason to add them to a Map and then remove them at a later point, either use lazy data or don't use lazy data. Don't do both.
     
  9. Offline

    nj2miami

    Again, you fail to understand the goal.

    If I want to know someone clicked a sign TWICE, in a defined time space, what method would you suggest?? Add the UUID and the Timestamp of the first click, into a Hash, then run a scheduled task to remove it after some default time.

    What part of that are you disagreeing with? And moreso, even if you are disagreeing, why not provide YOUR OWN solution rather than continue a semantic debate with me?

    You have been a member for 2+ years and you produce no plugins yet feel compelled to discredit or chastise a solution provided?
     
  10. Offline

    mythbusterma

    @nj2miami

    Ad hominem attacks, classy.

    I would suggest, if he needs to check that they have clicked it recently, adding them to a Map, associating their name with the last time they clicked, if it was within the allowable time, give them a class, otherwise, reset the time associated with their name.

    No scheduler required.

    EDIT: Also, my original disputation was with the "if your code does not execute fast enough," which, as I have stated above, is completely irrelevant to this.
     
  11. Offline

    teej107

    @nj2miami @mythbusterma The OP didn't specify anything about the amount of time to be passed before needing a first click again.

    EDIT: But if he decides he does, @mythbusterma 's way is the way to go.
     
  12. Offline

    nj2miami

    You felt compelled to ridicule my solution, initially by not even fully understanding the problem and then get thin skinned because I called your character into play? *smh*
     
  13. Offline

    mythbusterma

    @nj2miami

    I don't feel that I'm the one being thin skinned, as I have not personally attacked you, despite you personally attacking me.

    Now, for a personal attack, you've completely veered this post off-topic. *slow clap*
     
  14. Offline

    nj2miami

    I agree he did not, but considering in all likelihood he would not want to perpetually think someone who clicks a sign twice should never need to click it again, I provided the value added response to clean up the Hash. Myth's solution keeps EVERY person who has EVER clicked the sign in memory.

    I'll still err on my side to keep only those being tracked inside the Hash.
     
  15. Offline

    teej107

  16. Offline

    nj2miami

    LOL...OK I am done here. You guys keep telling him the better way is to create a bunch of listeners to respond to events to handle a simple add/remove from a Hash, or simply keep every player in a Hash or a Set or whatever.

    Every post I see from you guys are some elitist, "don't do it that way" or "this way is better" condescending responses. I can scroll through 20 of your last responses to find maybe 1 beneficial one. Instead of commenting on MY WAY, inject YOUR WAY maybe?
     
  17. Offline

    teej107

  18. Offline

    nj2miami

    Just more of the same from you. You must be fun at parties.

    *yawn* You have reduced this post seeking help to a useless conversation. Had you simply injected your own opinion rather than decide to critique my own, this could have gone a whole other way. Yet you decided to inject your ego and elitist comments instead of offering a solution.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 27, 2017
  19. Offline

    mythbusterma

    @nj2miami

    Your ad hominem attacks are so desperate it's not even funny (I linked it here since you probably don't know what it means).
     
    teej107 likes this.
  20. Offline

    eyamaz

    Enough. Discuss and debate, but more useless character attacks will get you some warnings.
     
  21. Offline

    teej107

    What does me at parties have to do with double clicks and Maps?
    I'll backup my reasoning with reason.

    When you can and when appropriate, using the "cooldown" method (comparing System time) is better than using timers. Creating a timer for every Player is less efficient for the CPU. Who cares if the Player is still in the Map. The only time you should care is when the Player leaves which can be solved with
    Keeping the Player in the Map when they are online won't cause memory leaks or anything like it. You have a reference to the same Player object as Bukkit references. They are references and not a new Object!
     
Thread Status:
Not open for further replies.

Share This Page