@@ -35,7 +35,6 @@ public CubicListener(CubicCountdown plugin) {
3535 @ EventHandler
3636 public void onCubeCountdownEnd (CubeCountdownEndEvent event ) {
3737 if (event .getCubicSettings ().getCube () != null ) {
38- executeCommands ("OnCountdownEnd" , event .getCubicSettings ().getCube ().getName ());
3938 plugin .getCubicAPI ().increaseWins (event .getCubicSettings ().getCube ());
4039 }
4140 }
@@ -45,7 +44,7 @@ public void onCubeCountdownCancel(CubeCountdownCancelEvent event) {
4544 if (event .getCubicSettings ().getCube () != null ) {
4645 executeCommands ("OnCountdownCancel" , event .getCubicSettings ().getCube ().getName ());
4746 plugin .getCubicAPI ().increaseLoses (event .getCubicSettings ().getCube ());
48- if (plugin .getConfigHandler ().getBoolean ("Reverse" )){
47+ if (! plugin .getConfigHandler ().getBoolean ("Reverse" ) && event . whileFillAnimation () || plugin . getConfigHandler (). getBoolean ( "Reverse" ) && event . whileClearAnimation ( )){
4948 plugin .getCubicAPI ().increaseHelpCounter (event .getCubicSettings ().getCube ());
5049 }
5150 }
@@ -55,14 +54,17 @@ public void onCubeCountdownCancel(CubeCountdownCancelEvent event) {
5554 public void onCubeCountdownStart (CubeCountdownStartEvent event ){
5655 if (event .getCubicSettings ().getCube () != null ) {
5756 executeCommands ("OnCountdownStart" , event .getCubicSettings ().getCube ().getName ());
58- if (!plugin .getConfigHandler ().getBoolean ("Reverse" )){
57+ if (!plugin .getConfigHandler ().getBoolean ("Reverse" ) && event . whileFillAnimation () || plugin . getConfigHandler (). getBoolean ( "Reverse" ) && event . whileClearAnimation () ){
5958 plugin .getCubicAPI ().increaseHelpCounter (event .getCubicSettings ().getCube ());
6059 }
6160 }
6261 }
6362
64- private void executeCommands (String key , String map ){
63+ public void executeCommands (String key , String map ){
6564 plugin .getConfigHandler ().getStringList ("Commands." +key +"" ).forEach (command -> {
65+ if (command .startsWith (" " ) || command .startsWith ("/" )){
66+ command = command .substring (0 , command .length ()-1 );
67+ }
6668 Bukkit .dispatchCommand (Bukkit .getConsoleSender (), command .replaceAll ("%map%" , map ));
6769 });
6870 }
@@ -184,30 +186,47 @@ public void run() {
184186 if (player != null && !cubicSettings .playerList ().contains (player )) {
185187 cubicSettings .addPlayer (player );
186188 }
187- CountdownModule countdownModule = new CountdownModule (cubicSettings );
188- CubeCountdownStartEvent event = new CubeCountdownStartEvent (player , countdownModule );
189- Bukkit .getPluginManager ().callEvent (event );
190- if (!event .isCancelled ()) {
191- countdownModule .start ();
192- r .set (true );
189+ if (atomicCube .get () != null && plugin .getCubicAPI ().getCountdownModuleFromCube (atomicCube .get ()) == null ) {
190+ CountdownModule countdownModule = new CountdownModule (cubicSettings );
191+ CubeCountdownStartEvent event = new CubeCountdownStartEvent (player , countdownModule );
192+ Bukkit .getPluginManager ().callEvent (event );
193+ if (!event .isCancelled ()) {
194+ countdownModule .start ();
195+ r .set (true );
196+ }
197+ if (plugin .getConfigHandler ().getBoolean ("Reverse" ) && plugin .getCubicAPI ().getClearAnimationList ().containsKey (atomicCube .get ().getName ())) {
198+ Bukkit .getScheduler ().cancelTask (plugin .getCubicAPI ().getClearAnimationList ().get (atomicCube .get ().getName ()));
199+ plugin .getCubicAPI ().getClearAnimationList ().remove (atomicCube .get ().getName ());
200+ }else if (plugin .getCubicAPI ().getFillAnimationList ().containsKey (atomicCube .get ().getName ())){
201+ Bukkit .getScheduler ().cancelTask (plugin .getCubicAPI ().getFillAnimationList ().get (atomicCube .get ().getName ()));
202+ plugin .getCubicAPI ().getFillAnimationList ().remove (atomicCube .get ().getName ());
203+ }
193204 }
194205 } else if (!reverse && atomicCube .get () != null && !atomicCube .get ().filledOut () || reverse && atomicCube .get () != null && !atomicCube .get ().empty ()) {
195206 try {
196207 plugin .getCountdownList ().forEach (countdownModule -> {
197208 if (countdownModule .getCubicSettings ().getCube () != null && countdownModule .getCubicSettings ().getCube ().isSimilar (atomicCube .get ())) {
198- CubeCountdownCancelEvent event = new CubeCountdownCancelEvent (player , countdownModule );
199- Bukkit .getPluginManager ().callEvent (event );
200- if (!event .isCancelled ()) {
201- countdownModule .cancel ();
202- r .set (true );
209+ if (atomicCube .get () != null && plugin .getCubicAPI ().getCountdownModuleFromCube (atomicCube .get ()) != null ) {
210+ CubeCountdownCancelEvent event = new CubeCountdownCancelEvent (player , countdownModule );
211+ Bukkit .getPluginManager ().callEvent (event );
212+ if (!event .isCancelled ()) {
213+ countdownModule .cancel ();
214+ r .set (true );
215+ }
216+ if (!plugin .getConfigHandler ().getBoolean ("Reverse" ) && plugin .getCubicAPI ().getClearAnimationList ().containsKey (atomicCube .get ().getName ())) {
217+ Bukkit .getScheduler ().cancelTask (plugin .getCubicAPI ().getClearAnimationList ().get (atomicCube .get ().getName ()));
218+ plugin .getCubicAPI ().getClearAnimationList ().remove (atomicCube .get ().getName ());
219+ }else if (plugin .getCubicAPI ().getFillAnimationList ().containsKey (atomicCube .get ().getName ())){
220+ Bukkit .getScheduler ().cancelTask (plugin .getCubicAPI ().getFillAnimationList ().get (atomicCube .get ().getName ()));
221+ plugin .getCubicAPI ().getFillAnimationList ().remove (atomicCube .get ().getName ());
222+ }
203223 }
204224 }
205225 });
206226 //TODO
207227 } catch (ConcurrentModificationException exception ) {
208228 }
209229 }
210-
211230 }
212231 });
213232 }
0 commit comments