Skip to content

Commit

Permalink
Merge pull request #138 from RedstoneFuture/refactoring/misc
Browse files Browse the repository at this point in the history
Refactoring: Implement game module system more consistently
  • Loading branch information
RedstoneFuture authored Dec 17, 2024
2 parents 4ce07e1 + c05fb7c commit 37f1559
Show file tree
Hide file tree
Showing 72 changed files with 1,130 additions and 1,202 deletions.
6 changes: 1 addition & 5 deletions missilewars-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<version>1.0</version>
</parent>

<version>4.8.0</version>
<version>5.0.0-rc.1</version>

<modelVersion>4.0.0</modelVersion>

Expand All @@ -52,7 +52,6 @@
<groupId>de.butzlabben</groupId>
<artifactId>FAWE_Paster</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<!-- Other dependencies -->

Expand All @@ -75,22 +74,19 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.2</version>
<scope>compile</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.16.2</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.github.MilkBowl/VaultAPI -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,25 @@
import co.aikar.commands.PaperCommandManager;
import de.butzlabben.missilewars.commands.*;
import de.butzlabben.missilewars.configuration.Config;
import de.butzlabben.missilewars.configuration.Messages;
import de.butzlabben.missilewars.game.Arenas;
import de.butzlabben.missilewars.game.GameManager;
import de.butzlabben.missilewars.game.misc.MissileWarsPlaceholder;
import de.butzlabben.missilewars.game.signs.CheckRunnable;
import de.butzlabben.missilewars.game.schematics.paste.FawePasteProvider;
import de.butzlabben.missilewars.game.schematics.paste.Paster;
import de.butzlabben.missilewars.game.signs.SignRepository;
import de.butzlabben.missilewars.game.stats.StatsFetcher;
import de.butzlabben.missilewars.initialization.FileManager;
import de.butzlabben.missilewars.initialization.GamesInitialization;
import de.butzlabben.missilewars.listener.PlayerListener;
import de.butzlabben.missilewars.listener.SignListener;
import de.butzlabben.missilewars.player.PlayerData;
import de.butzlabben.missilewars.util.ConnectionHolder;
import de.butzlabben.missilewars.util.MoneyUtil;
import de.butzlabben.missilewars.util.SetupUtil;
import de.butzlabben.missilewars.util.stats.PreFetcher;
import de.butzlabben.missilewars.util.version.VersionUtil;
import lombok.Getter;
import org.apache.commons.io.FileUtils;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.Date;

/**
Expand All @@ -60,14 +55,12 @@ public class MissileWars extends JavaPlugin {
public final String version = getDescription().getVersion();
private SignRepository signRepository;
public PaperCommandManager commandManager;

private boolean foundFAWE;

@Getter
private PlayerListener playerListener;
@Getter
private SignListener signListener;


@Getter private PlayerListener playerListener;
@Getter private SignListener signListener;

@Getter private Paster schematicPaster;

public MissileWars() {
instance = this;
}
Expand All @@ -82,73 +75,66 @@ public void onEnable() {
sendPluginInfo();

Logger.BOOT.log("Loading properties...");

// delete old missile wars temp-worlds from the last server session
deleteTempWorlds();

Config.load();
Messages.load();
SetupUtil.saveDefaultSchematics(new File(Config.getMissilesFolder()), "missiles.zip");
SetupUtil.saveDefaultSchematics(new File(Config.getShieldsFolder()), "shields.zip");

new File(Config.getLobbiesFolder()).mkdirs();

this.signRepository = SignRepository.load();


FileManager.setupRoutine();

signRepository = SignRepository.load();

registerEvents();
registerCommands();

Arenas.load();

GameManager.getInstance().loadGamesOnStartup();

// special Dependency-Management:
new Metrics(this, 3749);

// Check if FAWE is installed
foundFAWE = Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null;

GameManager.getInstance().getGames().values().forEach(game -> {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!game.isIn(player.getLocation())) continue;
game.teleportToLobbySpawn(player);
}
});


initialWeSupport();
initialPapiSupport();
MoneyUtil.giveMoney(null, -1);

Bukkit.getScheduler().runTaskTimerAsynchronously(this, new CheckRunnable(), 20, 20 * 10);


GamesInitialization.initialize();

// Warm-up for Stats:
if (Config.isPrefetchPlayers()) {
PreFetcher.preFetchPlayers(new StatsFetcher(new Date(0L), ""));
}

checkPlaceholderAPI();

ConfigurationSerialization.registerClass(PlayerData.class);


endTime = System.currentTimeMillis();
Logger.SUCCESS.log("MissileWars was enabled in " + (endTime - startTime) + "ms");

}

@Override
public void onDisable() {

GameManager.getInstance().disableAll();
deleteTempWorlds();

FileManager.shotDownRoutine();
ConnectionHolder.close();
}

/**
* This method checks which kind of WorldEdit Solution is installed. The paste
* supplier is prepared on the basis of this.
*/
private void initialWeSupport() {
if (Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null) {
schematicPaster = new FawePasteProvider();
Logger.NORMAL.log("FastAsyncWorldEdit is installed. The Schematic Paster is prepared for the behavior of FAWE.");
} else {
schematicPaster = new FawePasteProvider();
Logger.NORMAL.log("(Normal) WorldEdit is installed. The Schematic Paster is prepared for the behavior of WE.");
}
}

/**
* This method checks if the PlaceholderAPI is installed. When it is
* installed, a message is sent to the log.
*/
private void checkPlaceholderAPI() {
private void initialPapiSupport() {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new MissileWarsPlaceholder(this).register();
Logger.NORMAL.log("The PlaceholderAPI is installed. New placeholders are provided by MissileWars.");
}
}

/**
* This method registers all events of the MissileWars event listener.
*/
Expand Down Expand Up @@ -178,33 +164,7 @@ private void registerCommands() {
commandManager.registerCommand(new UserCommands());
commandManager.registerCommand(new SetupCommands());
}

/**
* This method checks if FAWE (FastAsyncWorldEdit) is installed.
*
* @return true, if it's installed
*/
public boolean foundFAWE() {
return foundFAWE;
}

/**
* This methode deletes the temp arena worlds of the MW game.
*/
private void deleteTempWorlds() {
File[] dirs = Bukkit.getWorldContainer().listFiles();
if (dirs == null) return;

for (File dir : dirs) {
if (dir.getName().startsWith("mw-")) {
try {
FileUtils.deleteDirectory(dir);
} catch (Exception ignored) {
}
}
}
}


/**
* This method sends information about the version, version
* warnings (if necessary) and authors in the console.
Expand All @@ -215,26 +175,16 @@ private void sendPluginInfo() {

if (VersionUtil.getVersion() < 20) {
Logger.WARN.log("====================================================");
Logger.WARN.log("It seems that you are using version older than 1.20");
Logger.WARN.log("There is no guarantee for this to work");
Logger.WARN.log("Proceed with extreme caution");
Logger.WARN.log("It seems that you are using version older than 1.20.");
Logger.WARN.log("There is no guarantee for this to work.");
Logger.WARN.log("====================================================");
}

if (version.contains("beta")) {
Logger.WARN.log("NOTE: This is a beta version which means, that it may not be fully stable");
}

if (getDescription().getAuthors().size() > 1) {
StringBuilder sb = new StringBuilder();
for (String author : getDescription().getAuthors()) {
if (author.equals("Butzlabben"))
continue;
sb.append(author);
sb.append(" ");
}
Logger.BOOT.log("Other authors: " + sb);
if (version.contains("snapshot") || version.contains("dev")) {
Logger.WARN.log("NOTE: This is a snapshot for testing. Errors may occur in new or revised modules. " +
"Do not use this version on a production server!");
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void registerMissilesResult() {
Game game = GameManager.getInstance().getGame(player.getLocation());
if (game == null) return null;

return game.getArena().getMissileConfiguration().getSchematicNames();
return game.getArenaConfig().getMissileConfig().getSchematicNames();
});
}

Expand Down Expand Up @@ -88,7 +88,7 @@ private void registerArenasResult() {
Game game = GameManager.getInstance().getGame(player.getLocation());
if (game == null) return null;

return game.getLobby().getPossibleArenas();
return game.getGameConfig().getPossibleArenas();
});
}

Expand Down
Loading

0 comments on commit 37f1559

Please sign in to comment.