1818
1919package plugily .projects .minigamesbox .classic .utils .actionbar ;
2020
21- import org .bukkit .Bukkit ;
2221import org .bukkit .ChatColor ;
2322import org .bukkit .entity .Player ;
2423import org .bukkit .scheduler .BukkitRunnable ;
@@ -60,14 +59,16 @@ public void run() {
6059 if (actionBars .isEmpty ()) {
6160 return ;
6261 }
63- for (Map .Entry <Player , List <ActionBar >> actionBarList : new HashMap <>( actionBars ) .entrySet ()) {
62+ for (Map .Entry <Player , List <ActionBar >> actionBarList : actionBars .entrySet ()) {
6463 Player player = actionBarList .getKey ();
6564 IPluginArena arena = plugin .getArenaRegistry ().getArena (player );
6665 List <ActionBar > bars = new ArrayList <>(actionBarList .getValue ());
6766 if (bars .isEmpty ()) {
6867 return ;
6968 }
70- new ArrayList <>(actionBarList .getValue ()).stream ().max (Comparator .comparingInt (ActionBar ::getPriority )).ifPresent (actionBar -> {
69+ plugin .getDebugger ().debug ("[ActionBarManager] [Arena {0} ] Player {1} got the following bars {2}" , arena .getId (), player .getName (), bars .toString ());
70+ bars .stream ().max (Comparator .comparingInt (ActionBar ::getPriority )).ifPresent (actionBar -> {
71+ plugin .getDebugger ().debug ("[ActionBarManager] [Arena {0} ] Player {1} sending {2}" , arena .getId (), player .getName (), actionBar .toString ());
7172 switch (actionBar .getActionBarType ()) {
7273 case FLASHING :
7374 if (flashing .containsKey (actionBar .getKey ())) {
@@ -110,11 +111,13 @@ public void run() {
110111
111112 private void removeFinishedActionBar (Player player , ActionBar actionBar ) {
112113 if (actionBar .getExecutedTicks () >= actionBar .getTicks ()) {
114+ //Clear the ActionBar by default as on some changes such as world switch or teleportation the bar could stick
115+ VersionUtils .sendActionBar (player , " " );
113116 if (actionBar .getActionBarType () == ActionBar .ActionBarType .FLASHING ) {
114- VersionUtils .sendActionBar (player , "" );
115117 flashing .remove (actionBar .getKey ());
116118 }
117119 actionBars .get (player ).remove (actionBar );
120+ plugin .getDebugger ().debug ("[ActionBarManager] Player {1} removing {2}" , player .getName (), actionBar .toString ());
118121 }
119122 }
120123
@@ -123,14 +126,17 @@ public Map<Player, List<ActionBar>> getActionBars() {
123126 }
124127
125128 public void addActionBar (Player player , ActionBar actionBar ) {
129+ plugin .getDebugger ().debug ("[ActionBarManager] Player {1} added {2}" , player .getName (), actionBar .toString ());
126130 if (actionBars .containsKey (player )) {
127- List <ActionBar > bars = actionBars .get (player );
131+ List <ActionBar > bars = new ArrayList <>(actionBars .get (player ));
132+ actionBars .remove (player );
128133 if (bars .stream ().anyMatch (bar -> bar .getActionBarType () == ActionBar .ActionBarType .DISPLAY ) && bars .stream ().anyMatch (bar -> bar .getPriority () == actionBar .getPriority ())) {
129134 List <ActionBar > displayBars = bars .stream ().filter (bar -> bar .getActionBarType () == ActionBar .ActionBarType .DISPLAY ).filter (bar -> bar .getPriority () == actionBar .getPriority ()).collect (Collectors .toList ());
130135 bars .removeAll (displayBars );
131136 }
132137 bars .add (actionBar );
133138 actionBars .put (player , bars );
139+ plugin .getDebugger ().debug ("[ActionBarManager] Player {1} got the following bars {2}" , player .getName (), bars .toString ());
134140 return ;
135141 }
136142 actionBars .put (player , new ArrayList <>(Collections .singleton (actionBar )));
0 commit comments