Selecting 2 blocks by clicking after executing command

Discussion in 'Plugin Development' started by alex123099, Feb 10, 2014.

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

    alex123099

    Hi guys,
    I'm making a plugin in which I need a player to execute a command which asks him to right click 2 blocks, and the plugin needs to get those 2 blocks and save their locations.

    What would be the best way to do this system? I cannot think of a good way of telling the listener to listen for 2 clicks of a certain player after he executes the command.
     
  2. Offline

    MrAwellstein

    alex123099
    Mind adding me on skype? I have an idea of how this could work through listeners, plus I could use this for another project of mine, and I'd like to work together. If not then I'll just collaborate on the forums or whatever.
    Skype: Firearchon
     
  3. Offline

    alex123099

    There are 3 people that show up to Firearchon on skype.
     
  4. Offline

    MrAwellstein

    Should be the Top One, Black Ranger (its my steam clan)
     
  5. Offline

    alex123099

  6. Offline

    Panjab

    Write an ArrayList<String> which stores the player names who executed the specific command.
    In your Listener you have to check if the List contains the event-player. If so, count an int-var up and after your second click reset it and remove your player from the list.

    But watch off: You have to write your "counting system" in the opposite way. If you don't your code will run only one time and use the first block twice. So, I mean:

    Code:java
    1.  
    2. ArrayList<String> players = new ArrayList<>();
    3. int counter = 0;
    4.  
    5. if (counter = 1 && players.contains(e.getPlayer().getName())) {
    6. counter = 0;
    7. players.remove(e.getPlayer().getName());
    8.  
    9. // Set your block things
    10. }
    11.  
    12.  
    13. if (counter <= 0 && players.contains(e.getPlayer().getName())) {
    14. counter++;
    15.  
    16. // Set your block things
    17. }
     
  7. Offline

    bennie3211

    should that not be a HashMap and store for each player separately? now when 2 players are in the list doing the click thing, it wont work good, because it will count for 2 players then at the same time
     
  8. Offline

    alex123099

    Panjab
    What do you mean by the opposite way? I don't get that part

    bennie3211
    You're right, a hashmap with the player as a key and counter as value could work.

    I was thinking of doing that method you guys suggested, just was wondering maybe there's a better, less messy system, because I like to have my classes control all the aspects related to it inside the class itself.

    Edit: Is there a way to store multiple values for a certain key? What I need to store is the Player as the key and a counter and a boolean as values. I could make a nested HashMap within the HashMap, but that would be very inefficient.
     
  9. Offline

    bennie3211

    alex123099 You can create a hashmap like this:

    HashMap<String, ArrayList<Boolean>> yourhashmapname = new HashMap<String, ArrayList<Boolean>>();

    PLEASE DON'T SAVE PLAYERS >>> This will cause memmory laggs ect, just store there names and get the player with Bukkit.getPlayerExact(String name); (Im not sure this is correct way to get the player again<<)
     
Thread Status:
Not open for further replies.

Share This Page