@@ -45,6 +45,7 @@ public class ActionBarManager extends BukkitRunnable {
4545 private final PluginMain plugin ;
4646 private final int period = 10 ;
4747 private Map <Player , List <ActionBar >> actionBars = new HashMap <>();
48+ private Map <ActionBar , Integer > actionBarTimers = new HashMap <>();
4849 private Map <String , Integer > flashing = new HashMap <>();
4950
5051
@@ -59,16 +60,22 @@ public void run() {
5960 if (actionBars .isEmpty ()) {
6061 return ;
6162 }
62- for (Map .Entry <Player , List <ActionBar >> actionBarList : actionBars .entrySet ()) {
63+ for (Map .Entry <Player , List <ActionBar >> actionBarList : new HashMap <>( actionBars ) .entrySet ()) {
6364 Player player = actionBarList .getKey ();
6465 IPluginArena arena = plugin .getArenaRegistry ().getArena (player );
65- List <ActionBar > bars = new ArrayList <>( actionBarList .getValue () );
66+ List <ActionBar > bars = actionBarList .getValue ();
6667 if (bars .isEmpty ()) {
6768 return ;
6869 }
69- plugin .getDebugger ().debug ("[ActionBarManager] [Arena {0} ] Player {1} got the following bars {2}" , arena .getId (), player .getName (), bars .toString ());
70+ if (arena == null ) {
71+ return ;
72+ }
73+ for (ActionBar actionBar : bars ) {
74+ plugin .getDebugger ().debug ("[ActionBarManager] [Arena {0} ] Player {1} got the following bars {2}" , arena .getId (), player .getName (), "Type:"
75+ + actionBar .getActionBarType () + "Ticks:" + actionBar .getTicks () + "ExecutedTicks:" + actionBar .getExecutedTicks () + "Message:" + actionBar .getMessage ().getRaw () + "Priority:" + actionBar .getPriority ());
76+ }
7077 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 ());
78+ plugin .getDebugger ().debug ("[ActionBarManager] [Arena {0} ] Player {1} sending {2}" , arena .getId (), player .getName (), actionBar .getMessage (). getRaw ());
7279 switch (actionBar .getActionBarType ()) {
7380 case FLASHING :
7481 if (flashing .containsKey (actionBar .getKey ())) {
@@ -84,12 +91,9 @@ public void run() {
8491 }
8592 flashing .put (actionBar .getKey (), -1 );
8693 break ;
87- case COOLDOWN :
88- bars .remove (actionBar );
89- VersionUtils .sendActionBar (player , actionBar .getMessage ().integer ((actionBar .getTicks () - actionBar .getExecutedTicks ()) / 20 ).player (player ).arena (arena ).build ());
90- break ;
9194 case DISPLAY :
92- VersionUtils .sendActionBar (player , actionBar .getMessage ().integer ((actionBar .getTicks () - actionBar .getExecutedTicks ()) / 20 ).player (player ).arena (arena ).build ());
95+ case SHOW_PERMANENT :
96+ VersionUtils .sendActionBar (player , actionBar .getMessage ().player (player ).arena (arena ).build ());
9397 break ;
9498 case PROGRESS :
9599 String progress = StringFormatUtils .getProgressBar (actionBar .getExecutedTicks () + 10 , actionBar .getTicks (),
@@ -100,24 +104,27 @@ public void run() {
100104 break ;
101105 }
102106 });
103- for (ActionBar actionBar : bars ) {
104- if (actionBar .getActionBarType () == ActionBar .ActionBarType .COOLDOWN || actionBar .getActionBarType () == ActionBar .ActionBarType .PROGRESS ) {
107+ List <ActionBar > newActionBars = new ArrayList <>();
108+ for (ActionBar actionBar : new ArrayList <>(bars )) {
109+ if (actionBar .getActionBarType () == ActionBar .ActionBarType .DISPLAY || actionBar .getActionBarType () == ActionBar .ActionBarType .PROGRESS ) {
105110 actionBar .addExecutedTicks (period );
106111 }
107- removeFinishedActionBar (player , actionBar );
112+ if (actionBar .getExecutedTicks () >= actionBar .getTicks ()) {
113+ if (actionBar .getActionBarType () == ActionBar .ActionBarType .FLASHING ) {
114+ flashing .remove (actionBar .getKey ());
115+ }
116+ plugin .getDebugger ().debug ("[ActionBarManager] Player {0} removed {1}" , player .getName (), actionBar .getMessage ().getRaw ());
117+ } else {
118+ newActionBars .add (actionBar );
119+ }
108120 }
109- }
110- }
111-
112- private void removeFinishedActionBar (Player player , ActionBar actionBar ) {
113- 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 , " " );
116- if (actionBar .getActionBarType () == ActionBar .ActionBarType .FLASHING ) {
117- flashing .remove (actionBar .getKey ());
121+ actionBars .remove (player );
122+ if (newActionBars .isEmpty ()) {
123+ //Clear the ActionBar by default as on some changes such as world switch or teleportation the bar could stick
124+ VersionUtils .sendActionBar (player , " " );
125+ } else {
126+ actionBars .put (player , newActionBars );
118127 }
119- actionBars .get (player ).remove (actionBar );
120- plugin .getDebugger ().debug ("[ActionBarManager] Player {1} removing {2}" , player .getName (), actionBar .toString ());
121128 }
122129 }
123130
@@ -126,17 +133,20 @@ public Map<Player, List<ActionBar>> getActionBars() {
126133 }
127134
128135 public void addActionBar (Player player , ActionBar actionBar ) {
129- plugin .getDebugger ().debug ("[ActionBarManager] Player {1 } added {2 }" , player .getName (), actionBar .toString ());
136+ plugin .getDebugger ().debug ("[ActionBarManager] Player {0 } added {1 }" , player .getName (), actionBar .getMessage (). getRaw ());
130137 if (actionBars .containsKey (player )) {
131138 List <ActionBar > bars = new ArrayList <>(actionBars .get (player ));
132139 actionBars .remove (player );
133- if (bars .stream ().anyMatch (bar -> bar .getActionBarType () == ActionBar .ActionBarType .DISPLAY ) && bars .stream ().anyMatch (bar -> bar .getPriority () = = actionBar .getPriority ())) {
134- List <ActionBar > displayBars = bars .stream ().filter (bar -> bar .getActionBarType () == ActionBar .ActionBarType .DISPLAY ).filter (bar -> bar .getPriority () = = actionBar .getPriority ()).collect (Collectors .toList ());
140+ if (bars .stream ().anyMatch (bar -> bar .getActionBarType () == ActionBar .ActionBarType .SHOW_PERMANENT ) && bars .stream ().anyMatch (bar -> bar .getPriority () > = actionBar .getPriority ())) {
141+ List <ActionBar > displayBars = bars .stream ().filter (bar -> bar .getActionBarType () == ActionBar .ActionBarType .SHOW_PERMANENT ).filter (bar -> bar .getPriority () < = actionBar .getPriority ()).collect (Collectors .toList ());
135142 bars .removeAll (displayBars );
136143 }
137144 bars .add (actionBar );
138145 actionBars .put (player , bars );
139- plugin .getDebugger ().debug ("[ActionBarManager] Player {1} got the following bars {2}" , player .getName (), bars .toString ());
146+ for (ActionBar debugActionBar : bars ) {
147+ plugin .getDebugger ().debug ("[ActionBarManager] Player {0} got the following bars {1}" , player .getName (), "Type:"
148+ + debugActionBar .getActionBarType () + "Ticks:" + debugActionBar .getTicks () + "ExecutedTicks:" + debugActionBar .getExecutedTicks () + "Message:" + debugActionBar .getMessage ().getRaw () + "Priority:" + debugActionBar .getPriority ());
149+ }
140150 return ;
141151 }
142152 actionBars .put (player , new ArrayList <>(Collections .singleton (actionBar )));
@@ -145,4 +155,10 @@ public void addActionBar(Player player, ActionBar actionBar) {
145155 public void clearActionBarsFromPlayer (Player player ) {
146156 actionBars .remove (player );
147157 }
158+
159+ public void clearActionBarsFromPlayer (Player player , ActionBar .ActionBarType actionBarType ) {
160+ List <ActionBar > bars = new ArrayList <>(actionBars .get (player ));
161+ actionBars .remove (player );
162+ actionBars .put (player , bars .stream ().filter (bar -> bar .getActionBarType () != actionBarType ).collect (Collectors .toList ()));
163+ }
148164}
0 commit comments