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


    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.
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (sender instanceof Player) {
                Player p = (Player) sender;
                vmEnabled.put(p.getName(), true)
            return false;
        public void onJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            if(!vmEnabled.containsKey(p.getName())) {
                vmEnabled.put(p.getName(), false);
    public void onEnable() {
            final HashSet <String> vmEnabled = new HashSet<String>();
            Bukkit.getPluginManager().registerEvents(new OnJoin(), this);
            new Heal(this);
            new VeinMine(this);
  2. Online

    timtower Administrator Moderator

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

    Forge_User_45064837 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