Skip to content

Commit d81e301

Browse files
Undoing changes
1 parent b9ba600 commit d81e301

26 files changed

+223
-200
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ MissileWars is a famous, fun and fast minigame spigot-plugin for Minecraft
77
You can download the latest jar in the [latest release](https://github.com/Butzlabben/missilewars/releases/latest) or build it yourself (
88
see [BUILDING](#building))
99

10+
However, if you [buy the resource](https://www.spigotmc.org/resources/62947) and leave a review,
11+
you will also receive an extra map and some more missiles.
12+
1013
## Building
1114

1215
To build MissileWars, you need to install the Java 17 JDK. Then you can build it via the Maven Wrapper.

missilewars-plugin/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<version>1.0</version>
2727
</parent>
2828

29-
<version>4.6.0</version>
29+
<version>4.5.3</version>
3030

3131
<modelVersion>4.0.0</modelVersion>
3232

@@ -117,7 +117,7 @@
117117
<dependency>
118118
<groupId>com.mojang</groupId>
119119
<artifactId>authlib</artifactId>
120-
<version>4.0.43</version>
120+
<version>1.5.25</version>
121121
<scope>provided</scope>
122122
</dependency>
123123

missilewars-plugin/src/main/java/de/butzlabben/missilewars/MissileWars.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
@Getter
5858
public class MissileWars extends JavaPlugin {
5959

60-
@Getter
6160
private static MissileWars instance;
6261
public final String version = getDescription().getVersion();
6362
private SignRepository signRepository;
@@ -72,6 +71,13 @@ public MissileWars() {
7271
instance = this;
7372
}
7473

74+
/**
75+
* @return the instance of the plugin
76+
*/
77+
public static MissileWars getInstance() {
78+
return instance;
79+
}
80+
7581
@Override
7682
public void onEnable() {
7783
long startTime;
@@ -110,7 +116,7 @@ public void onEnable() {
110116
GameManager.getInstance().getGames().values().forEach(game -> {
111117
for (Player player : Bukkit.getOnlinePlayers()) {
112118
if (!game.isIn(player.getLocation())) continue;
113-
game.playerJoinInGame(player, false);
119+
game.teleportToLobbySpawn(player);
114120
}
115121
});
116122

missilewars-plugin/src/main/java/de/butzlabben/missilewars/commands/StatsCommands.java

+19-26
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.bukkit.Material;
4848
import org.bukkit.command.CommandSender;
4949
import org.bukkit.entity.Player;
50-
import org.jetbrains.annotations.NotNull;
5150

5251
@CommandAlias("mw|missilewars")
5352
@Subcommand("stats")
@@ -59,28 +58,6 @@ public class StatsCommands extends BaseCommand {
5958
private final SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
6059
private final SimpleDateFormat preciseFormat = new SimpleDateFormat("hh:mm dd.MM.yyyy");
6160

62-
@NotNull
63-
private static List<String> generateRecommendations(StatsFetcher fetcher, SavedStats avgStatsWithoutDraws) {
64-
List<String> recommendations = new ArrayList<>();
65-
int gameCount = fetcher.getGameCount();
66-
67-
double avgWins = avgStatsWithoutDraws.getTeamWon();
68-
if (Math.abs(avgWins - 1) > MAX_AVIATION_WIN) {
69-
recommendations.add("It could be, that your map is biased to one team, as wins are not equally distributed");
70-
}
71-
72-
int draws = fetcher.getDrawFights();
73-
if ((((double) draws / (double) gameCount) * 100) > MAX_FIGHT_DRAW_PERCENTAGE) {
74-
recommendations.add("Increase the game_length option. More than 15% of your games are draws");
75-
}
76-
77-
Duration duration = Duration.ofMillis(avgStatsWithoutDraws.getTimeElapsed());
78-
if (((double) duration.getSeconds() / 60.0) <= MIN_FIGHT_DURATION) {
79-
recommendations.add("Remove some overpowered features. The average game length at won games is under 5 minutes");
80-
}
81-
return recommendations;
82-
}
83-
8461
@Default
8562
@CommandPermission("mw.stats")
8663
public void onStats(CommandSender sender, String[] args) {
@@ -95,7 +72,7 @@ public void onStats(CommandSender sender, String[] args) {
9572
PreFetcher.PrePlayerFetchRunnable preFetchRunnable = PreFetcher.preFetchPlayers(fetcher);
9673

9774
CustomInv inv = new CustomInv("§eMissileWars statistics", 3);
98-
List<String> criteriaLore = Arrays.asList("§7Statistics since: §e" + format.format(fetcher.getFrom()), "§7Specified arena: §e" + (arena.isEmpty() ? "any" : arena));
75+
List<String> criteriaLore = Arrays.asList("§7Statistics since: §e" + format.format(fetcher.getFrom()), "§7Specified arena: §e" + (arena.equals("") ? "any" : arena));
9976
inv.addItem(4, new OrcItem(Material.FEATHER, "§aStatistics search criteria", criteriaLore));
10077

10178
int gameCount = fetcher.getGameCount();
@@ -144,10 +121,26 @@ public void onRecommendations(CommandSender sender, String[] args) {
144121
if (fetcher == null) return;
145122
SavedStats avgStatsWithDraws = fetcher.getAverageSavedStats(false);
146123
SavedStats avgStatsWithoutDraws = fetcher.getAverageSavedStats(true);
147-
List<String> recommendations = generateRecommendations(fetcher, avgStatsWithoutDraws);
124+
List<String> recommendations = new ArrayList<>();
125+
int gameCount = fetcher.getGameCount();
126+
127+
double avgWins = avgStatsWithoutDraws.getTeamWon();
128+
if (Math.abs(avgWins - 1) > MAX_AVIATION_WIN) {
129+
recommendations.add("It could be, that your map is biased to one team, as wins are not equally distributed");
130+
}
131+
132+
int draws = fetcher.getDrawFights();
133+
if ((((double) draws / (double) gameCount) * 100) > MAX_FIGHT_DRAW_PERCENTAGE) {
134+
recommendations.add("Increase the game_length option. More than 15% of your games are draws");
135+
}
136+
137+
Duration duration = Duration.ofMillis(avgStatsWithoutDraws.getTimeElapsed());
138+
if (((double) duration.getSeconds() / 60.0) <= MIN_FIGHT_DURATION) {
139+
recommendations.add("Remove some overpowered features. The average game length at won games is under 5 minutes");
140+
}
148141
// TODO implement more features
149142

150-
if (recommendations.isEmpty()) {
143+
if (recommendations.size() == 0) {
151144
player.sendMessage(Messages.getPrefix() + "§aThere are currently no recommendations, everything seems fine :)");
152145
} else {
153146
player.sendMessage(Messages.getPrefix() + "§7=====[ §eMissileWars recommendations §7]=====");

missilewars-plugin/src/main/java/de/butzlabben/missilewars/configuration/Lobby.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.IOException;
3131
import java.util.ArrayList;
3232
import java.util.List;
33+
import java.util.Optional;
3334
import java.util.stream.Collectors;
3435
import lombok.Getter;
3536
import lombok.RequiredArgsConstructor;
@@ -39,6 +40,12 @@
3940
import org.bukkit.Location;
4041
import org.bukkit.World;
4142

43+
import java.io.File;
44+
import java.io.IOException;
45+
import java.util.ArrayList;
46+
import java.util.List;
47+
import java.util.stream.Collectors;
48+
4249
@Getter
4350
@ToString
4451
@RequiredArgsConstructor
@@ -60,10 +67,9 @@ public class Lobby {
6067
@Setter @SerializedName("spawn_point") private Location spawnPoint = getBukkitDefaultWorld().getSpawnLocation();
6168
@Setter @SerializedName("after_game_spawn") private Location afterGameSpawn = getBukkitDefaultWorld().getSpawnLocation();
6269
@Setter @SerializedName("area") private AreaConfiguration areaConfig = AreaConfiguration.aroundLocation(getBukkitDefaultWorld().getSpawnLocation(), 30);
63-
@SerializedName("map_choose_procedure") private MapChooseProcedure mapChooseProcedure = MapChooseProcedure.MAPCYCLE;
70+
@SerializedName("map_choose_procedure") private MapChooseProcedure mapChooseProcedure = MapChooseProcedure.FIRST;
6471
@SerializedName("possible_arenas") private List<String> possibleArenas = new ArrayList<>() {{
6572
add("arena0");
66-
add("dam");
6773
}};
6874

6975
// These values are only set after the Config has been read.

missilewars-plugin/src/main/java/de/butzlabben/missilewars/configuration/arena/MissileConfiguration.java

-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ public class MissileConfiguration {
5454
add(new Missile("Juggernaut.schematic", "&4Juggernaut", EntityType.MUSHROOM_COW, 2, 2, 1));
5555
add(new Missile("Piranha.schematic", "&3Piranha", EntityType.HORSE, 2, 2, 3));
5656
add(new Missile("Tunnelbore.schematic", "&0Tunnelbore", EntityType.ENDERMAN, 2, 2, 1));
57-
add(new Missile("Minuteman.schematic", "&3Minuteman", EntityType.CAVE_SPIDER, 2, 3, 2));
58-
add(new Missile("Skybolt.schematic", "&bSkybolt", EntityType.SKELETON_HORSE, 2, 2, 2));
59-
add(new Missile("Medusa.schematic", "&5Medusa", EntityType.PARROT, 2, 2, 1));
60-
6157
}};
6258

6359
public List<MissileFacing> getEnabledFacings() {

missilewars-plugin/src/main/java/de/butzlabben/missilewars/game/Arenas.java

+4-11
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
import de.butzlabben.missilewars.configuration.arena.Arena;
2525
import de.butzlabben.missilewars.util.SetupUtil;
2626
import de.butzlabben.missilewars.util.serialization.Serializer;
27+
import lombok.Getter;
28+
import org.bukkit.Bukkit;
29+
2730
import java.io.File;
2831
import java.io.IOException;
2932
import java.util.HashMap;
3033
import java.util.Map;
31-
import lombok.Getter;
32-
import org.bukkit.Bukkit;
3334

3435
public class Arenas {
3536

@@ -58,17 +59,9 @@ public static void load() {
5859
Bukkit.getPluginManager().disablePlugin(MissileWars.getInstance());
5960
return;
6061
}
61-
62-
// Also unpack additional arenas
63-
try {
64-
SetupUtil.copyAndUnzip("Dam-Arena.zip", folder.getAbsolutePath());
65-
} catch (IOException e) {
66-
Logger.ERROR.log("Could not extract Dam Arena");
67-
e.printStackTrace();
68-
}
62+
files = new File[] {defaultArena};
6963
}
7064

71-
files = folder.listFiles();
7265
for (File config : files) {
7366
if (!config.getName().endsWith(".yml") && !config.getName().endsWith(".yaml")) continue;
7467
try {

missilewars-plugin/src/main/java/de/butzlabben/missilewars/game/Game.java

+22-39
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,9 @@
5252
import de.butzlabben.missilewars.util.geometry.GameArea;
5353
import de.butzlabben.missilewars.util.geometry.Geometry;
5454
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;
6055
import lombok.Getter;
6156
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.*;
6858
import org.bukkit.entity.Fireball;
6959
import org.bukkit.entity.Player;
7060
import org.bukkit.event.HandlerList;
@@ -73,6 +63,12 @@
7363
import org.bukkit.scheduler.BukkitTask;
7464
import org.bukkit.util.Vector;
7565

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+
7672
/**
7773
* @author Butzlabben
7874
* @since 01.01.2018
@@ -121,7 +117,7 @@ public Game(Lobby lobby) {
121117
return;
122118
}
123119

124-
if (lobby.getPossibleArenas().isEmpty()) {
120+
if (lobby.getPossibleArenas().size() == 0) {
125121
Logger.ERROR.log("At least one valid arena must be set at lobby \"" + lobby.getName() + "\".");
126122
return;
127123
}
@@ -167,7 +163,7 @@ public Game(Lobby lobby) {
167163
} else if (lobby.getMapChooseProcedure() == MapChooseProcedure.MAPCYCLE) {
168164
final int lastMapIndex = cycles.getOrDefault(lobby.getName(), -1);
169165
List<Arena> arenas = lobby.getArenas();
170-
int index = (lastMapIndex + 1) % arenas.size();
166+
int index = lastMapIndex >= arenas.size() - 1 ? 0 : lastMapIndex + 1;
171167
cycles.put(lobby.getName(), index);
172168
setArena(arenas.get(index));
173169
prepareGame();
@@ -183,14 +179,6 @@ public Game(Lobby lobby) {
183179
}
184180
}
185181

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-
}
194182
}
195183

196184
/**
@@ -307,7 +295,7 @@ public void stopGame() {
307295
Bukkit.getPluginManager().callEvent(new GameStopEvent(this));
308296
}
309297

310-
public void triggerRestart() {
298+
public void reset() {
311299
if (Config.isSetup()) return;
312300

313301
if (restart) {
@@ -413,8 +401,10 @@ public void playerLeaveFromGame(MWPlayer mwPlayer) {
413401
Team team = mwPlayer.getTeam();
414402
boolean playerWasTeamMember = false;
415403

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+
}
418408

419409
PlayerDataProvider.getInstance().loadInventory(player);
420410

@@ -486,12 +476,6 @@ public void resetGame() {
486476
HandlerList.unregisterAll(listener);
487477
taskManager.stopTimer();
488478

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-
495479
if (gameWorld != null) {
496480
gameWorld.unload();
497481
gameWorld.delete();
@@ -665,7 +649,7 @@ public void spawnFireball(Player player, ItemStack itemStack) {
665649
itemStack.setAmount(amount - 1);
666650

667651
Fireball fb = player.launchProjectile(Fireball.class);
668-
fb.setDirection(player.getLocation().getDirection().multiply(2.5D));
652+
fb.setVelocity(player.getLocation().getDirection().multiply(2.5D));
669653
player.playSound(fb.getLocation(), Sound.BLOCK_ANVIL_LAND, 100.0F, 2.0F);
670654
player.playSound(fb.getLocation(), Sound.ITEM_FLINTANDSTEEL_USE, 100.0F, 1.0F);
671655
fb.setYield(3F);
@@ -679,7 +663,7 @@ public void setArena(Arena arena) {
679663
}
680664

681665
arena.getMissileConfiguration().check();
682-
if (arena.getMissileConfiguration().getMissiles().isEmpty()) {
666+
if (arena.getMissileConfiguration().getMissiles().size() == 0) {
683667
throw new IllegalStateException("The game cannot be started, when 0 missiles are configured");
684668
}
685669

@@ -827,21 +811,20 @@ public Team getSmallerTeam() {
827811
}
828812

829813
/**
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
833817
* considered acceptable.
834-
*
818+
*
835819
* @param targetTeam the new team
836-
*
837820
* @return (boolean) 'true' if it's a fair team switch
838821
*/
839822
public boolean isValidTeamSwitch(Team targetTeam) {
840-
823+
841824
// original team sizes
842825
int targetTeamSize = targetTeam.getMembers().size();
843826
int currentTeamSize = targetTeam.getEnemyTeam().getMembers().size();
844-
827+
845828
// Preventing an empty team when previously both teams had at least one player:
846829
if ((currentTeamSize == 1) && (targetTeamSize >= 1)) return false;
847830

missilewars-plugin/src/main/java/de/butzlabben/missilewars/game/GameManager.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
import de.butzlabben.missilewars.configuration.Lobby;
2525
import de.butzlabben.missilewars.util.geometry.GameArea;
2626
import de.butzlabben.missilewars.util.serialization.Serializer;
27+
import lombok.Getter;
28+
import org.bukkit.Bukkit;
29+
import org.bukkit.Location;
30+
2731
import java.io.File;
2832
import java.io.IOException;
2933
import java.util.HashMap;
3034
import java.util.Map;
31-
import lombok.Getter;
32-
import org.bukkit.Bukkit;
33-
import org.bukkit.Location;
3435

3536
@Getter
3637
public class GameManager {
@@ -46,7 +47,6 @@ public void disableAll() {
4647
}
4748

4849
public void restartAll() {
49-
// We use an iterator to prevent a possible ConcurrentModificationException
5050
var iterator = games.values().iterator();
5151
//noinspection WhileLoopReplaceableByForEach
5252
while (iterator.hasNext()) {

0 commit comments

Comments
 (0)