How would I use a HashMap/HashSet across classes?

Discussion in 'Plugin Development' started by Viyper, Dec 31, 2019.

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

    Viyper

    I've been trying implement player variables but I haven't been able to access a HashMap or HashSet of the data across different classes. Any Help?

    Examples of applicable code.
    Code:
    @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (sender instanceof Player) {
                Player p = (Player) sender;
                vmEnabled.put(p.getName(), true)
                p.sendMessage(vmEnabled.get(p.getName()).toString());
            }
            return false;
        }
    Code:
    @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            if(!vmEnabled.containsKey(p.getName())) {
                vmEnabled.put(p.getName(), false);
            }
        }
    Code:
    public void onEnable() {
            final HashSet <String> vmEnabled = new HashSet<String>();
            Bukkit.getPluginManager().registerEvents(new OnJoin(), this);
            new Heal(this);
            new VeinMine(this);
        }
     
  2. Offline

    timtower Moderator Moderator

    @Viyper Make a variable in the main class.
    Make a getter for the variable.
     
  3. Offline

    bwfcwalshy Retired Staff

    You do add in a Set not put. You do put in a Map.

    Also, this should be in the class scopr not the onEnable method. Put it outside the method at the top.
     
Thread Status:
Not open for further replies.

Share This Page