Solved How to create a HashMap when executing a command?

Discussion in 'Spigot Plugin Development' started by Deitog, Jul 10, 2019.

  1. Hello everyone

    I want to ask for your help to know how to do a HashMap when executing a command (I say this example) This is the example:
    Code (Text):
    public boolean onCommand(CommandSender sender,Command cmd,String label,String[] args){
            if(args.length == 0){
                // Stuff to create a HashMap
            }
            return false;
        }
    The HashMap that I want to create is this:
    Code (Text):
    HashMap<Player,Long> chaters = new HashMap<>();
    Can you teach me how to do it? is that I do not have too much knowledge
     
  2. What do you mean by "creating a HashMap" ? Give more precisions please
     
  3. You already posted the code...What are you asking for help with?
    If you want to have the hashmap persist across multiple command usages, then you would need to make it a variable that the class holds, then initiate it upon the creation of that class (constructor or onEnable)
     
  4. What I am trying to achieve is a Simulator of an application and it will have a system that users can create networks and when creating networks a HashMap will be created to maintain the network

    It is to create a different HashMap when executing a command

    What I need is a method to create HashMap and save them in the plugin

    I just realized that I can save them in the config and get them from there
     
  5. I think you can do an HashMap<Player, HashMap> as instance variable, if your objective, as I understood, is to create a new HashMap for each Player.

    Code (Text):


    HashMap<Player, HashMap<Player,Long>> hM = new HashMap<>();
    public boolean onCommand(CommandSender sender,Command cmd,String label,String[] args){
            if(args.length == 0){
                // Stuff to create a HashMap
                hM.put((Player)sender, new HashMap<>());
            }
            return false;
        }
     
  6. I'd advice making a Network object which has a HashMap field, you can than proceed to store all Networks in a list in another class.
     
    • Informative Informative x 1