Is it possible to check if players right click a sign with a hashmap? If So How?

Discussion in 'Plugin Development' started by ShredNyx, Sep 22, 2013.

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

    ShredNyx

    Im making a plugin to check if the player right click a sign then if more than 3 people are in the game it starts a timer which after is done it teleports the players
     
  2. To answer your question: Just make a PlayerIteractEvent, check if they right click a block, check if the block is a sign. Then check if the player is in the HashMap.
     
  3. Offline

    ShredNyx

    Im a little stuck on the HashMap part can you explain to me how it works
    legostarwarszach

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. Offline

    ShredNyx

    Yes legostarwarszach and an example in code please

    Please advise

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  5. ShredNyx

    Well, a HashMap, is a map. It can hold anything, but has a disadvantage. But can sometimes cause memory leaks.
    An example HashMap:
    Code:
    public HashMap<String, Integer> nameofhashmap = new HashMap<Player, Integer>(); 
    This will let you add Players and Integers to the HashMap

    To add to the HashMap:
    Code:
    nameofhashmap.add(p.getDisplayName(), 1); 
    To remove:
    Code:
    nameofhashmap.remove(p.getDisplayName(), 1); 
     
  6. Offline

    metalhedd

    legostarwarszach Everything you've said up to this point is wrong. a HashMap is not a list, it's a map, they're very different data structures. HashMaps also don't inherently cause memory leaks, and especially not in relation to how much data is stored in them.

    The code you've posted also demonstrates how to (potentially) create memory leaks by storing Player objects instead of just names, but it has nothing to do with the HashMap.

    ShredNyx avoid the above post. its completely 100% wrong. That being said, I'm not going to attempt to explain how a HashMap works, you can just google that.
     
  7. metalhedd
    Omg! Thanks for pointing this out to me! I guess I was confused! Sorry ShredNyx !
     
Thread Status:
Not open for further replies.

Share This Page