Skip to content

Commit

Permalink
Merge pull request #64 from RedstoneFuture/Refactoring/Misc
Browse files Browse the repository at this point in the history
Refactoring, Unified config options for folders
  • Loading branch information
daniel-naegele authored Feb 5, 2023
2 parents 9a944fd + 7686066 commit 7921113
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,9 @@ public void onEnable() {
if (Config.isPrefetchPlayers()) {
PreFetcher.preFetchPlayers(new StatsFetcher(new Date(0L), ""));
}

// Small check to make sure that PlaceholderAPI is installed
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new MissileWarsPlaceholder(this).register();
Logger.NORMAL.log("The PlaceholderAPI is installed. New placeholders are provided by MissileWars.");
}


checkPlaceholderAPI();

endTime = System.currentTimeMillis();
Logger.SUCCESS.log("MissileWars was enabled in " + (endTime - startTime) + "ms");
}
Expand All @@ -143,7 +139,18 @@ public void onDisable() {

ConnectionHolder.close();
}


/**
* This method checks if the PlaceholderAPI is installed. When it is
* installed, a message is sent to the log.
*/
private void checkPlaceholderAPI() {
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ private static void addDefaults() {

cfg.addDefault("restart_after_fights", 10);

cfg.addDefault("arena_folder", "plugins/MissileWars/arenas");
cfg.addDefault("arenas.folder", "plugins/MissileWars/arenas");

cfg.addDefault("lobbies.multiple_lobbies", false);
cfg.addDefault("lobbies.folder", "plugins/MissileWars/lobbies");
cfg.addDefault("lobbies.default_lobby", "lobby0.yml");

cfg.addDefault("missiles.folder", "plugins/MissileWars/missiles");

cfg.addDefault("replace.material", JUKEBOX.name());
cfg.addDefault("replace.after_ticks", 2);
cfg.addDefault("replace.radius", 15);
Expand Down Expand Up @@ -200,22 +202,26 @@ public static int getFightRestart() {
return cfg.getInt("restart_after_fights");
}

public static String getArenaFolder() {
return cfg.getString("arena_folder") + "/";
public static String getArenasFolder() {
return cfg.getString("arenas.folder");
}

public static boolean isMultipleLobbies() {
return cfg.getBoolean("lobbies.multiple_lobbies");
}

public static String getLobbiesFolder() {
return cfg.getString("lobbies.folder") + "/";
return cfg.getString("lobbies.folder");
}

public static String getDefaultLobby() {
return cfg.getString("lobbies.default_lobby");
}

public static String getMissilesFolder() {
return cfg.getString("missiles.folder");
}

public static int getReplaceTicks() {
return cfg.getInt("replace.after_ticks");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Arenas {
public static void load() {
arenas.clear();

File folder = new File(Config.getArenaFolder());
File folder = new File(Config.getArenasFolder());

// Creates the folder "/arena", if not existing
folder.mkdirs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public void loadGamesOnStartup() {
if (Config.isMultipleLobbies()) {
lobbyFiles = new File(Config.getLobbiesFolder()).listFiles();
} else {
File file = new File(Config.getLobbiesFolder() + "/" + Config.getDefaultLobby());
File lobbiesFolder = new File(Config.getLobbiesFolder());
File file = new File(lobbiesFolder, Config.getDefaultLobby());
if (file.exists()) {
lobbyFiles = new File[]{file};
}
Expand All @@ -68,7 +69,8 @@ public void loadGamesOnStartup() {

if (lobbyFiles.length == 0) {
Logger.WARN.log("No lobby configs found. Creating default one");
File file = new File(Config.getLobbiesFolder() + "/" + Config.getDefaultLobby());
File lobbiesFolder = new File(Config.getLobbiesFolder());
File file = new File(lobbiesFolder, Config.getDefaultLobby());
try {
file.createNewFile();
Serializer.serialize(file, new Lobby());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public void load() {
i++;
} while (file.exists() || file.isDirectory());

File newFile = new File(Config.getArenaFolder() + "/" + templateName);
File arenasFolder = new File(Config.getArenasFolder());
File newFile = new File(arenasFolder, templateName);

try {
FileUtils.copyDirectory(newFile, file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package de.butzlabben.missilewars.game.misc;

import de.butzlabben.missilewars.configuration.Config;
import de.butzlabben.missilewars.configuration.Messages;
import de.butzlabben.missilewars.game.Game;
import de.butzlabben.missilewars.game.enums.GameState;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -53,9 +54,12 @@ public void updateMOTD(Game game) {
break;
}

String players = "" + game.getPlayers().values().size();
String maxPlayers = "" + game.getLobby().getMaxSize();
motd = ChatColor.translateAlternateColorCodes('&', newMotd).replace("%max_players%", maxPlayers).replace("%players%", players);
int players = game.getPlayers().values().size();
int maxPlayers = game.getLobby().getMaxSize();
motd = ChatColor.translateAlternateColorCodes('&', newMotd)
.replace("%max_players%", "" + maxPlayers)
.replace("%players%", "" + players)
.replace("%prefix%", Messages.getPrefix());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import com.google.gson.annotations.SerializedName;
import de.butzlabben.missilewars.Logger;
import de.butzlabben.missilewars.MissileWars;
import de.butzlabben.missilewars.configuration.Config;
import de.butzlabben.missilewars.game.Game;
import de.butzlabben.missilewars.game.missile.paste.PasteProvider;
import de.butzlabben.missilewars.util.version.VersionUtil;
Expand Down Expand Up @@ -84,8 +84,8 @@ public void paste(Player p, MissileFacing mf, Game game) {
}

public File getSchematic() {
File pluginDir = MissileWars.getInstance().getDataFolder();
File file = new File(pluginDir, "missiles/" + getSchematicName(false));
File missilesFolder = new File(Config.getMissilesFolder());
File file = new File(missilesFolder, getSchematicName(false));
return file;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public static void checkShields() {
}

public static void checkMap(String worldName) {
File file = new File(Config.getArenaFolder() + "/" + worldName);
File arenasFolder = new File(Config.getArenasFolder());
File file = new File(arenasFolder, worldName);
if (!file.isDirectory()) {
String resource = "MissileWars-Arena.zip";

Expand All @@ -125,7 +126,7 @@ public static void checkMap(String worldName) {
}

public static void checkMissiles() {
File file = new File(MissileWars.getInstance().getDataFolder(), "missiles");
File file = new File(Config.getMissilesFolder());
if (!file.isDirectory()) {
String resource = "missiles.zip";

Expand Down

0 comments on commit 7921113

Please sign in to comment.