Solved Hashmap

Discussion in 'Plugin Development' started by kangkyuchang, Jun 28, 2020.

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

    kangkyuchang

    I am trying to use the Hashmap in one class in another class, but the data stored in the Hashmap is not output.
    Code:
    public class MainQuest {
       
        public HashMap<UUID,Integer> Quest = new HashMap<UUID,Integer>();
        public QuestStore q = new QuestStore();
    }
    public class MainGUI {
       
        public QuestStore q = new QuestStore();
        public MainQuest mq = new MainQuest();
        public HashMap<UUID,Integer> Quest = mq.Quest;
    }
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    kangkyuchang

  4. Offline

    timtower Administrator Administrator Moderator

    Those will not be linked then as they don't share the same variable.
    Why not make a mainquest in your onEnable and pass it to both instances? Or even better: only have 1 instance.
     
  5. Offline

    kangkyuchang

    How can I do one?
     
    Last edited: Jun 28, 2020
  6. Offline

    timtower Administrator Administrator Moderator

    Where are you using this? Post the full classes
     
  7. Offline

    kangkyuchang

    Code:
    public class MainQuest {
        public HashMap<UUID,Integer> Quest = new HashMap<UUID,Integer>();
        public QuestStore q = new QuestStore();
        public void MainQuest0(Player p)
        {
            long[] quest;
            quest = q.getQuest(p.getUniqueId().toString());
            if(Quest.containsKey(p.getUniqueId()))
            {
                if(Quest.get(p.getUniqueId()) >= 100)
                {
                    quest[0] = 2;
                    p.closeInventory();
                    Quest.remove(p.getUniqueId());
                    q.setQuest(p.getUniqueId().toString(), quest);
                }
                     return;
            }
            Quest.put(p.getUniqueId(), 0);
            p.closeInventory();
    }
    }
    public class MainGUI {
    
        public QuestStore q = new QuestStore();
        public MainQuest mq = new MainQuest();
        public HashMap<UUID,Integer> Quest = mq.Quest;
        public void QusetList(Player p)
        {
            long[] quest;
            quest = q.getQuest(p.getUniqueId().toString());
            Inventory inv = Bukkit.createInventory(null, 54, "§fQuestList");
            if(quest[0] == 1)
            {
                if(Quest.containsKey(p.getUniqueId()))
                {
                    p.sendMessage("TEST");
                    int qa = Quest.get(p.getUniqueId());
                    Stack("§Quest",397,3,1,Arrays.asList(" " + qa + " /100"),0,inv);
                }
            }
          }
    }
     
    Last edited: Jun 28, 2020
Thread Status:
Not open for further replies.

Share This Page