Skip to content

Commit

Permalink
Merge pull request #53 from RedstoneFuture/Refactoring/RestructuringF…
Browse files Browse the repository at this point in the history
…iles

Restructuring classes
  • Loading branch information
daniel-naegele authored Dec 4, 2022
2 parents 3b9916e + 9e08170 commit ed924d5
Show file tree
Hide file tree
Showing 80 changed files with 371 additions and 372 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package de.butzlabben.missilewars;

import de.butzlabben.missilewars.configuration.Config;
import org.bukkit.Bukkit;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@
package de.butzlabben.missilewars;

import co.aikar.commands.PaperCommandManager;
import de.butzlabben.missilewars.cmd.MWCommands;
import de.butzlabben.missilewars.cmd.StatsCommands;
import de.butzlabben.missilewars.cmd.UserCommands;
import de.butzlabben.missilewars.commands.MWCommands;
import de.butzlabben.missilewars.commands.StatsCommands;
import de.butzlabben.missilewars.commands.UserCommands;
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.signs.SignRepository;
import de.butzlabben.missilewars.game.stats.StatsFetcher;
import de.butzlabben.missilewars.listener.PlayerListener;
import de.butzlabben.missilewars.listener.SignListener;
import de.butzlabben.missilewars.util.ConnectionHolder;
import de.butzlabben.missilewars.util.MissileWarsPlaceholder;
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 de.butzlabben.missilewars.wrapper.signs.CheckRunnable;
import de.butzlabben.missilewars.wrapper.signs.SignRepository;
import de.butzlabben.missilewars.wrapper.stats.StatsFetcher;
import lombok.Getter;
import org.apache.commons.io.FileUtils;
import org.bstats.bukkit.Metrics;
Expand Down Expand Up @@ -84,7 +86,7 @@ public void onEnable() {
deleteTempWorlds();

Config.load();
MessageConfig.load();
Messages.load();
SetupUtil.checkMissiles();

new File(Config.getLobbiesFolder()).mkdirs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,31 @@
* along with MissileWars. If not, see <https://www.gnu.org/licenses/>.
*/

package de.butzlabben.missilewars.cmd;
package de.butzlabben.missilewars.commands;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Syntax;
import de.butzlabben.missilewars.Config;
import co.aikar.commands.annotation.*;
import de.butzlabben.missilewars.Logger;
import de.butzlabben.missilewars.MessageConfig;
import de.butzlabben.missilewars.MissileWars;
import de.butzlabben.missilewars.configuration.Config;
import de.butzlabben.missilewars.configuration.Lobby;
import de.butzlabben.missilewars.configuration.Messages;
import de.butzlabben.missilewars.configuration.arena.Arena;
import de.butzlabben.missilewars.game.Arenas;
import de.butzlabben.missilewars.game.Game;
import de.butzlabben.missilewars.game.GameManager;
import de.butzlabben.missilewars.game.GameState;
import de.butzlabben.missilewars.wrapper.abstracts.Arena;
import de.butzlabben.missilewars.wrapper.abstracts.Lobby;
import de.butzlabben.missilewars.wrapper.abstracts.MapChooseProcedure;
import de.butzlabben.missilewars.wrapper.missile.Missile;
import de.butzlabben.missilewars.wrapper.missile.MissileFacing;
import de.butzlabben.missilewars.game.enums.GameState;
import de.butzlabben.missilewars.game.enums.MapChooseProcedure;
import de.butzlabben.missilewars.game.missile.Missile;
import de.butzlabben.missilewars.game.missile.MissileFacing;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

@CommandAlias("mw|missilewars")
public class MWCommands extends BaseCommand {
Expand All @@ -54,31 +49,31 @@ public class MWCommands extends BaseCommand {
@Description("Shows information about the MissileWars Plugin.")
public void mwCommand(CommandSender sender) {

sender.sendMessage(MessageConfig.getPrefix() + "MissileWars v" + MissileWars.getInstance().version + " by Butzlabben");
sender.sendMessage(Messages.getPrefix() + "MissileWars v" + MissileWars.getInstance().version + " by Butzlabben");

if (sender.hasPermission("mw.quit"))
sender.sendMessage(MessageConfig.getPrefix() + "/mw quit - Quit a game");
sender.sendMessage(Messages.getPrefix() + "/mw quit - Quit a game");
if (sender.hasPermission("mw.start"))
sender.sendMessage(MessageConfig.getPrefix() + "/mw start - Starts the game");
sender.sendMessage(Messages.getPrefix() + "/mw start - Starts the game");
if (sender.hasPermission("mw.stop"))
sender.sendMessage(MessageConfig.getPrefix() + "/mw stop - Stops the game");
sender.sendMessage(Messages.getPrefix() + "/mw stop - Stops the game");
if (sender.hasPermission("mw.restart"))
sender.sendMessage(MessageConfig.getPrefix() + "/mw start - Restarts the game");
sender.sendMessage(Messages.getPrefix() + "/mw start - Restarts the game");
if (sender.hasPermission("mw.appendrestart"))
sender.sendMessage(MessageConfig.getPrefix()
sender.sendMessage(Messages.getPrefix()
+ "/mw appendrestart - Appends a restart after the next game ends");
if (sender.hasPermission("mw.paste"))
sender.sendMessage(MessageConfig.getPrefix() + "/mw paste - Pastes a missile");
sender.sendMessage(Messages.getPrefix() + "/mw paste - Pastes a missile");
if (sender.hasPermission("mw.reload"))
sender.sendMessage(MessageConfig.getPrefix() + "/mw reload - Reloads configurations");
sender.sendMessage(Messages.getPrefix() + "/mw reload - Reloads configurations");
if (sender.hasPermission("mw.stats"))
sender.sendMessage(MessageConfig.getPrefix() + "/mw stats - Shows stats");
sender.sendMessage(Messages.getPrefix() + "/mw stats - Shows stats");
if (sender.hasPermission("mw.stats.recommendations"))
sender.sendMessage(MessageConfig.getPrefix() + "/mw stats recommendations - Shows recommendations");
sender.sendMessage(Messages.getPrefix() + "/mw stats recommendations - Shows recommendations");
if (sender.hasPermission("mw.stats.players"))
sender.sendMessage(MessageConfig.getPrefix() + "/mw stats players - Shows player list");
sender.sendMessage(Messages.getPrefix() + "/mw stats players - Shows player list");
if (sender.hasPermission("mw.stats.list"))
sender.sendMessage(MessageConfig.getPrefix() + "/mw stats list - Lists history of games");
sender.sendMessage(Messages.getPrefix() + "/mw stats list - Lists history of games");
}

@Subcommand("paste")
Expand All @@ -93,14 +88,14 @@ public void pasteCommand(CommandSender sender, String[] args) {

Game game = GameManager.getInstance().getGame(player.getLocation());
if (game == null) {
player.sendMessage(MessageConfig.getMessage("not_in_arena"));
player.sendMessage(Messages.getMessage("not_in_arena"));
return;
}

String arguments = getAllNextArgumentsAsString(args, false);
Missile m = game.getArena().getMissileConfiguration().getMissileFromName(arguments.trim());
if (m == null) {
player.sendMessage(MessageConfig.getPrefix() + "§cUnknown missile");
player.sendMessage(Messages.getPrefix() + "§cUnknown missile");
return;
}
MissileFacing mf = MissileFacing.getFacingPlayer(player, game.getArena().getMissileConfiguration());
Expand All @@ -119,19 +114,19 @@ public void startCommand(CommandSender sender, String[] args) {

Game game = GameManager.getInstance().getGame(player.getLocation());
if (game == null) {
player.sendMessage(MessageConfig.getMessage("not_in_arena"));
player.sendMessage(Messages.getMessage("not_in_arena"));
return;
}

if (game.getState() != GameState.LOBBY) {
player.sendMessage(MessageConfig.getPrefix() + "§cGame already started");
player.sendMessage(Messages.getPrefix() + "§cGame already started");
return;
}
if (game.isReady())
game.startGame();
else {
if (game.getLobby().getMapChooseProcedure() != MapChooseProcedure.MAPVOTING && game.getArena() == null) {
player.sendMessage(MessageConfig.getPrefix() + "§cGame cannot be started");
player.sendMessage(Messages.getPrefix() + "§cGame cannot be started");
} else {
Map.Entry<String, Integer> mostVotes = null;
for (Map.Entry<String, Integer> arena : game.getVotes().entrySet()) {
Expand All @@ -145,7 +140,7 @@ public void startCommand(CommandSender sender, String[] args) {
Optional<Arena> arena = Arenas.getFromName(mostVotes.getKey());
if (arena.isEmpty()) throw new IllegalStateException("Voted arena is not present");
game.setArena(arena.get());
player.sendMessage(MessageConfig.getPrefix() + "A map was elected. Use \"/mw start\" again to start the round");
player.sendMessage(Messages.getPrefix() + "A map was elected. Use \"/mw start\" again to start the round");
}
}
}
Expand All @@ -162,7 +157,7 @@ public void stopCommand(CommandSender sender, String[] args) {

Game game = GameManager.getInstance().getGame(player.getLocation());
if (game == null) {
player.sendMessage(MessageConfig.getMessage("not_in_arena"));
player.sendMessage(Messages.getMessage("not_in_arena"));
return;
}

Expand All @@ -185,7 +180,7 @@ public void restartCommand(CommandSender sender, String[] args) {
Game game = GameManager.getInstance().getGame(player.getLocation());

if (game == null) {
player.sendMessage(MessageConfig.getMessage("not_in_arena"));
player.sendMessage(Messages.getMessage("not_in_arena"));
return;
}

Expand All @@ -203,7 +198,7 @@ public void restartCommand(CommandSender sender, String[] args) {
public void appendRestartCommand(CommandSender sender, String[] args) {

GameManager.getInstance().getGames().values().forEach(Game::appendRestart);
sender.sendMessage(MessageConfig.getMessage("restart_after_game"));
sender.sendMessage(Messages.getMessage("restart_after_game"));
}

@Subcommand("reload")
Expand All @@ -214,9 +209,9 @@ public void appendRestartCommand(CommandSender sender, String[] args) {
public void onReload(CommandSender sender, String[] args) {

Config.load();
MessageConfig.load();
Messages.load();
Arenas.load();
sender.sendMessage(MessageConfig.getPrefix() + "Reloaded configs");
sender.sendMessage(Messages.getPrefix() + "Reloaded configs");
}

@Subcommand("debug")
Expand All @@ -232,7 +227,7 @@ public void onDebug(CommandSender sender, String[] args) {
Logger.NORMAL.log("Printing state for arena " + game.getArena().getName() + ". Number: " + i);
Logger.NORMAL.log(game.toString());
}
sender.sendMessage(MessageConfig.getPrefix() + "Printed debug message into the log file");
sender.sendMessage(Messages.getPrefix() + "Printed debug message into the log file");
}

@Subcommand("restartall")
Expand All @@ -242,17 +237,17 @@ public void onDebug(CommandSender sender, String[] args) {
@CommandPermission("mw.reload")
public void onRestartAll(CommandSender sender, String[] args) {

sender.sendMessage(MessageConfig.getPrefix() + "§cWarning - Restarting all games. This may take a while");
sender.sendMessage(Messages.getPrefix() + "§cWarning - Restarting all games. This may take a while");
List<Lobby> arenaPropertiesList = GameManager.getInstance().getGames().values()
.stream().map(Game::getLobby).collect(Collectors.toList());
arenaPropertiesList.forEach(GameManager.getInstance()::restartGame);
sender.sendMessage(MessageConfig.getPrefix() + "Reloaded configs");
sender.sendMessage(Messages.getPrefix() + "Reloaded configs");
}

private boolean senderIsPlayer(CommandSender sender) {
if (sender instanceof Player) return true;

sender.sendMessage(MessageConfig.getPrefix() + "§cYou are not a player");
sender.sendMessage(Messages.getPrefix() + "§cYou are not a player");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
* along with MissileWars. If not, see <https://www.gnu.org/licenses/>.
*/

package de.butzlabben.missilewars.cmd;
package de.butzlabben.missilewars.commands;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import de.butzlabben.missilewars.Config;
import de.butzlabben.missilewars.MessageConfig;
import de.butzlabben.missilewars.configuration.Config;
import de.butzlabben.missilewars.configuration.Messages;
import de.butzlabben.missilewars.game.stats.PlayerStats;
import de.butzlabben.missilewars.game.stats.SavedStats;
import de.butzlabben.missilewars.game.stats.StatsFetcher;
import de.butzlabben.missilewars.inventory.CustomInv;
import de.butzlabben.missilewars.inventory.OrcItem;
import de.butzlabben.missilewars.inventory.pages.PageGUICreator;
import de.butzlabben.missilewars.util.stats.PlayerGuiFactory;
import de.butzlabben.missilewars.util.stats.PreFetcher;
import de.butzlabben.missilewars.util.stats.StatsUtil;
import de.butzlabben.missilewars.util.version.VersionUtil;
import de.butzlabben.missilewars.wrapper.stats.PlayerStats;
import de.butzlabben.missilewars.wrapper.stats.SavedStats;
import de.butzlabben.missilewars.wrapper.stats.StatsFetcher;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -138,10 +138,10 @@ public void onRecommendations(CommandSender sender, String[] args) {
// TODO implement more features

if (recommendations.size() == 0) {
player.sendMessage(MessageConfig.getPrefix() + "§aThere are currently no recommendations, everything seems fine :)");
player.sendMessage(Messages.getPrefix() + "§aThere are currently no recommendations, everything seems fine :)");
} else {
player.sendMessage(MessageConfig.getPrefix() + "§7=====[ §eMissileWars recommendations §7]=====");
recommendations.forEach(str -> player.sendMessage(MessageConfig.getPrefix() + str));
player.sendMessage(Messages.getPrefix() + "§7=====[ §eMissileWars recommendations §7]=====");
recommendations.forEach(str -> player.sendMessage(Messages.getPrefix() + str));
}
}

Expand Down Expand Up @@ -188,7 +188,7 @@ public void onList(CommandSender sender, String[] args) {

private StatsFetcher getFetcher(Player player, String[] args) {
if (!Config.isFightStatsEnabled()) {
player.sendMessage(MessageConfig.getPrefix() + "§cFightStats are not enabled!");
player.sendMessage(Messages.getPrefix() + "§cFightStats are not enabled!");
return null;
}
Date from = new Date(0);
Expand All @@ -197,7 +197,7 @@ private StatsFetcher getFetcher(Player player, String[] args) {
try {
from = format.parse(args[0]);
} catch (ParseException e) {
player.sendMessage(MessageConfig.getPrefix() + "§cPlease use the date format dd.MM.yyyy");
player.sendMessage(Messages.getPrefix() + "§cPlease use the date format dd.MM.yyyy");
return null;
}
if (args.length > 1) {
Expand All @@ -207,17 +207,17 @@ private StatsFetcher getFetcher(Player player, String[] args) {

StatsFetcher fetcher = new StatsFetcher(from, arena);
if (fetcher.getGameCount() < 10) {
player.sendMessage(MessageConfig.getPrefix() + "Please play more than 10 games to enable fight stats");
player.sendMessage(Messages.getPrefix() + "Please play more than 10 games to enable fight stats");
return null;
}
player.sendMessage(MessageConfig.getPrefix() + "Loading data...");
player.sendMessage(Messages.getPrefix() + "Loading data...");
return fetcher;
}

private boolean senderIsPlayer(CommandSender sender) {
if (sender instanceof Player) return true;

sender.sendMessage(MessageConfig.getPrefix() + "§cYou are not a player");
sender.sendMessage(Messages.getPrefix() + "§cYou are not a player");
return false;
}
}
Loading

0 comments on commit ed924d5

Please sign in to comment.