52
52
import de .butzlabben .missilewars .util .geometry .GameArea ;
53
53
import de .butzlabben .missilewars .util .geometry .Geometry ;
54
54
import de .butzlabben .missilewars .util .serialization .Serializer ;
55
- import java .util .HashMap ;
56
- import java .util .List ;
57
- import java .util .Map ;
58
- import java .util .UUID ;
59
- import java .util .function .Consumer ;
60
55
import lombok .Getter ;
61
56
import lombok .ToString ;
62
- import org .bukkit .Bukkit ;
63
- import org .bukkit .GameMode ;
64
- import org .bukkit .Location ;
65
- import org .bukkit .Material ;
66
- import org .bukkit .Sound ;
67
- import org .bukkit .World ;
57
+ import org .bukkit .*;
68
58
import org .bukkit .entity .Fireball ;
69
59
import org .bukkit .entity .Player ;
70
60
import org .bukkit .event .HandlerList ;
73
63
import org .bukkit .scheduler .BukkitTask ;
74
64
import org .bukkit .util .Vector ;
75
65
66
+ import java .util .HashMap ;
67
+ import java .util .List ;
68
+ import java .util .Map ;
69
+ import java .util .UUID ;
70
+ import java .util .function .Consumer ;
71
+
76
72
/**
77
73
* @author Butzlabben
78
74
* @since 01.01.2018
@@ -121,7 +117,7 @@ public Game(Lobby lobby) {
121
117
return ;
122
118
}
123
119
124
- if (lobby .getPossibleArenas ().isEmpty () ) {
120
+ if (lobby .getPossibleArenas ().size () == 0 ) {
125
121
Logger .ERROR .log ("At least one valid arena must be set at lobby \" " + lobby .getName () + "\" ." );
126
122
return ;
127
123
}
@@ -167,7 +163,7 @@ public Game(Lobby lobby) {
167
163
} else if (lobby .getMapChooseProcedure () == MapChooseProcedure .MAPCYCLE ) {
168
164
final int lastMapIndex = cycles .getOrDefault (lobby .getName (), -1 );
169
165
List <Arena > arenas = lobby .getArenas ();
170
- int index = ( lastMapIndex + 1 ) % arenas .size ();
166
+ int index = lastMapIndex >= arenas .size () - 1 ? 0 : lastMapIndex + 1 ;
171
167
cycles .put (lobby .getName (), index );
172
168
setArena (arenas .get (index ));
173
169
prepareGame ();
@@ -183,14 +179,6 @@ public Game(Lobby lobby) {
183
179
}
184
180
}
185
181
186
- // Add players if they are in the game area
187
- for (Player player : Bukkit .getOnlinePlayers ()) {
188
- if (!isIn (player .getLocation ())) {
189
- continue ;
190
- }
191
-
192
- playerJoinInGame (player , false );
193
- }
194
182
}
195
183
196
184
/**
@@ -307,7 +295,7 @@ public void stopGame() {
307
295
Bukkit .getPluginManager ().callEvent (new GameStopEvent (this ));
308
296
}
309
297
310
- public void triggerRestart () {
298
+ public void reset () {
311
299
if (Config .isSetup ()) return ;
312
300
313
301
if (restart ) {
@@ -413,8 +401,10 @@ public void playerLeaveFromGame(MWPlayer mwPlayer) {
413
401
Team team = mwPlayer .getTeam ();
414
402
boolean playerWasTeamMember = false ;
415
403
416
- BukkitTask task = playerTasks .get (mwPlayer .getUuid ());
417
- if (task != null ) task .cancel ();
404
+ if (state == GameState .INGAME ) {
405
+ BukkitTask task = playerTasks .get (mwPlayer .getUuid ());
406
+ if (task != null ) task .cancel ();
407
+ }
418
408
419
409
PlayerDataProvider .getInstance ().loadInventory (player );
420
410
@@ -486,12 +476,6 @@ public void resetGame() {
486
476
HandlerList .unregisterAll (listener );
487
477
taskManager .stopTimer ();
488
478
489
- // Just in case this wasn't executed in stopGame() already
490
- // This can happen if a game restart gets issued while it's still active
491
- for (BukkitTask bt : playerTasks .values ()) {
492
- bt .cancel ();
493
- }
494
-
495
479
if (gameWorld != null ) {
496
480
gameWorld .unload ();
497
481
gameWorld .delete ();
@@ -665,7 +649,7 @@ public void spawnFireball(Player player, ItemStack itemStack) {
665
649
itemStack .setAmount (amount - 1 );
666
650
667
651
Fireball fb = player .launchProjectile (Fireball .class );
668
- fb .setDirection (player .getLocation ().getDirection ().multiply (2.5D ));
652
+ fb .setVelocity (player .getLocation ().getDirection ().multiply (2.5D ));
669
653
player .playSound (fb .getLocation (), Sound .BLOCK_ANVIL_LAND , 100.0F , 2.0F );
670
654
player .playSound (fb .getLocation (), Sound .ITEM_FLINTANDSTEEL_USE , 100.0F , 1.0F );
671
655
fb .setYield (3F );
@@ -679,7 +663,7 @@ public void setArena(Arena arena) {
679
663
}
680
664
681
665
arena .getMissileConfiguration ().check ();
682
- if (arena .getMissileConfiguration ().getMissiles ().isEmpty () ) {
666
+ if (arena .getMissileConfiguration ().getMissiles ().size () == 0 ) {
683
667
throw new IllegalStateException ("The game cannot be started, when 0 missiles are configured" );
684
668
}
685
669
@@ -827,21 +811,20 @@ public Team getSmallerTeam() {
827
811
}
828
812
829
813
/**
830
- * This method checks whether a team switch would be fair based on
831
- * the new team size. If no empty team results or if the team size
832
- * difference does not exceed a certain value, the switch is
814
+ * This method checks whether a team switch would be fair based on
815
+ * the new team size. If no empty team results or if the team size
816
+ * difference does not exceed a certain value, the switch is
833
817
* considered acceptable.
834
- *
818
+ *
835
819
* @param targetTeam the new team
836
- *
837
820
* @return (boolean) 'true' if it's a fair team switch
838
821
*/
839
822
public boolean isValidTeamSwitch (Team targetTeam ) {
840
-
823
+
841
824
// original team sizes
842
825
int targetTeamSize = targetTeam .getMembers ().size ();
843
826
int currentTeamSize = targetTeam .getEnemyTeam ().getMembers ().size ();
844
-
827
+
845
828
// Preventing an empty team when previously both teams had at least one player:
846
829
if ((currentTeamSize == 1 ) && (targetTeamSize >= 1 )) return false ;
847
830
0 commit comments