package de.craften.plugins.rpgplus.scripting.api.actionbar;

import de.craften.plugins.rpgplus.scripting.util.ScriptUtil;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.OneArgFunction;
import org.luaj.vm2.lib.ThreeArgFunction;

import java.util.HashMap;

public class ActionBarModule extends LuaTable {
    private HashMap<Player, ActionBar> actionBars = new HashMap<>();

    public ActionBarModule() {
        set("set", new ThreeArgFunction() {
            @Override
            public LuaValue call(LuaValue player, LuaValue message, LuaValue duration) {
                Player p = ScriptUtil.getPlayer(player);
                String msg = ChatColor.translateAlternateColorCodes('&', message.checkjstring());

                if (actionBars.containsKey(p)) {
                    actionBars.remove(p).end();
                }

                actionBars.put(p, new ActionBar(p, msg, duration.optint(-1)));

                return LuaValue.NIL;
            }
        });

        set("clear", new OneArgFunction() {
            @Override
            public LuaValue call(LuaValue player) {
                Player p = ScriptUtil.getPlayer(player);
                ActionBar actionBar = actionBars.remove(p);
                if (actionBar != null) {
                    actionBar.end();
                }

                return LuaValue.NIL;
            }
        });
    }

    public void reset() {
        for (ActionBar actionBar : actionBars.values()) {
            actionBar.end();
        }
        actionBars.clear();
    }
}

@@ -54,16 +54,59 @@
 onbar;%0A%0A
+import de.craften.plugins.rpgplus.RpgPlus;%0A
 import d
@@ -384,17 +384,13 @@
 til.
-Hash
 Map;%0A
+
 %0Apub
@@ -446,20 +446,16 @@
 private 
-Hash
 Map%3CPlay
@@ -486,22 +486,86 @@
 s = 
-new HashMap%3C%3E(
+RpgPlus.getPlugin(RpgPlus.class).getWeakPlayerMaps().createMap(ActionBar.class
 );%0A%0A

Use a weak player map for the actionbar module.