Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements/msg configuration #81

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,24 @@ public void pasteCommand(CommandSender sender, String[] args) {
Player player = (Player) sender;

if (args.length < 1) {
player.sendMessage(Messages.getPrefix() + "§cMissile needed.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_MISSILE_NEEDED));
return;
}

if (args.length > 1) {
player.sendMessage(Messages.getPrefix() + "§cToo many arguments.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_TO_MANY_ARGUMENTS));
return;
}

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

Missile missile = game.getArena().getMissileConfiguration().getMissileFromName(args[0]);
if (missile == null) {
player.sendMessage(Messages.getPrefix() + "§cUnknown missile.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_INVALID_MISSILE));
return;
}

Expand All @@ -132,7 +132,7 @@ public void startCommand(CommandSender sender, String[] args) {
Player player = (Player) sender;

if (args.length > 1) {
player.sendMessage(Messages.getPrefix() + "§cToo many arguments.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_TO_MANY_ARGUMENTS));
return;
}

Expand All @@ -141,27 +141,27 @@ public void startCommand(CommandSender sender, String[] args) {
if (args.length == 1) {
game = GameManager.getInstance().getGame(args[0]);
if (game == null) {
player.sendMessage(Messages.getPrefix() + "§cGame not found.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_INVALID_GAME));
return;
}
} else {
game = GameManager.getInstance().getGame(player.getLocation());
if (game == null) {
player.sendMessage(Messages.getMessage("not_in_arena"));
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.GAME_NOT_IN_GAME_AREA));
return;
}
}

if (game.getState() != GameState.LOBBY) {
player.sendMessage(Messages.getPrefix() + "§cGame already started");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.GAME_ALREADY_STARTET));
return;
}

if (game.isReady())
game.startGame();
else {
if (game.getLobby().getMapChooseProcedure() != MapChooseProcedure.MAPVOTING && game.getArena() == null) {
player.sendMessage(Messages.getPrefix() + "§cGame cannot be started");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.GAME_CAN_NOT_STARTET));
} else {
Map.Entry<String, Integer> mostVotes = null;
for (Map.Entry<String, Integer> arena : game.getVotes().entrySet()) {
Expand All @@ -175,7 +175,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(Messages.getPrefix() + "A map was elected. Use \"/mw start\" again to start the round");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.GAME_MAP_SELECTED));
}
}
}
Expand All @@ -189,7 +189,7 @@ public void stopCommand(CommandSender sender, String[] args) {
Player player = (Player) sender;

if (args.length > 1) {
player.sendMessage(Messages.getPrefix() + "§cToo many arguments.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_TO_MANY_ARGUMENTS));
return;
}

Expand All @@ -198,13 +198,13 @@ public void stopCommand(CommandSender sender, String[] args) {
if (args.length == 1) {
game = GameManager.getInstance().getGame(args[0]);
if (game == null) {
player.sendMessage(Messages.getPrefix() + "§cGame not found.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_INVALID_GAME));
return;
}
} else {
game = GameManager.getInstance().getGame(player.getLocation());
if (game == null) {
player.sendMessage(Messages.getMessage("not_in_arena"));
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.GAME_NOT_IN_GAME_AREA));
return;
}
}
Expand All @@ -223,7 +223,7 @@ public void appendrestartCommand(CommandSender sender, String[] args) {
Player player = (Player) sender;

if (args.length > 1) {
player.sendMessage(Messages.getPrefix() + "§cToo many arguments.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_TO_MANY_ARGUMENTS));
return;
}

Expand All @@ -232,19 +232,19 @@ public void appendrestartCommand(CommandSender sender, String[] args) {
if (args.length == 1) {
game = GameManager.getInstance().getGame(args[0]);
if (game == null) {
player.sendMessage(Messages.getPrefix() + "§cGame not found.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_INVALID_GAME));
return;
}
} else {
game = GameManager.getInstance().getGame(player.getLocation());
if (game == null) {
player.sendMessage(Messages.getMessage("not_in_arena"));
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.GAME_NOT_IN_GAME_AREA));
return;
}
}

GameManager.getInstance().getGames().values().forEach(Game::appendRestart);
sender.sendMessage(Messages.getMessage("restart_after_game"));
sender.sendMessage(Messages.getMessage(true, Messages.MessageEnum.SERVER_RESTART_AFTER_GAME));
}

@Subcommand("reload")
Expand All @@ -256,14 +256,15 @@ public void reloadCommand(CommandSender sender, String[] args) {
Player player = (Player) sender;

if (args.length > 0) {
player.sendMessage(Messages.getPrefix() + "§cToo many arguments.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_TO_MANY_ARGUMENTS));
return;
}

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

player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.DEBUG_RELOAD_CONFIG));
}

@Subcommand("debug")
Expand All @@ -275,7 +276,7 @@ public void debugCommand(CommandSender sender, String[] args) {
Player player = (Player) sender;

if (args.length > 0) {
player.sendMessage(Messages.getPrefix() + "§cToo many arguments.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_TO_MANY_ARGUMENTS));
return;
}

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

player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.DEBUG_PRINTED_DEBUG_MSG));
}

@Subcommand("restartall")
Expand All @@ -297,19 +299,22 @@ public void restartallCommand(CommandSender sender, String[] args) {
Player player = (Player) sender;

if (args.length > 0) {
player.sendMessage(Messages.getPrefix() + "§cToo many arguments.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_TO_MANY_ARGUMENTS));
return;
}

sender.sendMessage(Messages.getPrefix() + "§cWarning - Restarting all games. This may take a while");

if (GameManager.getInstance().getGames().size() > 10) {
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.DEBUG_RESTART_ALL_GAMES_WARN));
}

GameManager.getInstance().restartAll();
sender.sendMessage(Messages.getPrefix() + "Restarted all games.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.DEBUG_RESTART_ALL_GAMES));
}

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

sender.sendMessage(Messages.getPrefix() + "§cYou are not a player");
sender.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_ONLY_PLAYERS));
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private boolean isValidGame(String[] args) {
} else {
game = GameManager.getInstance().getGame(player.getLocation());
if (game == null) {
player.sendMessage(Messages.getMessage("not_in_arena"));
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.GAME_NOT_IN_GAME_AREA));
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void onList(CommandSender sender, String[] args) {

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

StatsFetcher fetcher = new StatsFetcher(from, arena);
if (fetcher.getGameCount() < 10) {
player.sendMessage(Messages.getPrefix() + "Please play more than 10 games to enable fight stats");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.STATS_TOO_FEW_GAMES));
return null;
}
player.sendMessage(Messages.getPrefix() + "Loading data...");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.STATS_LOADING_DATA));
return fetcher;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,40 @@ public void voteCommand(CommandSender sender, String[] args) {
Player player = (Player) sender;

if (args.length > 0) {
player.sendMessage(Messages.getPrefix() + "§cToo many arguments.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_TO_MANY_ARGUMENTS));
return;
}

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

if (game.getState() != GameState.LOBBY) {
player.sendMessage(Messages.getPrefix() + "§cThe game is not in the right state to vote right now");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_CHANGE_TEAM_NOT_NOW));
return;
}

if (game.getLobby().getMapChooseProcedure() != MapChooseProcedure.MAPVOTING) {
player.sendMessage(Messages.getPrefix() + "§cYou can't vote in this game");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_CANT_VOTE));
return;
}

if (game.getArena() != null) {
player.sendMessage(Messages.getPrefix() + "§cA map was already elected");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_CHANGE_TEAM_NO_LONGER_NOW));
return;
}

String arenaName = args[0];
Optional<Arena> arena = Arenas.getFromName(arenaName);
if (!game.getVotes().containsKey(arenaName) || arena.isEmpty()) {
player.sendMessage(Messages.getPrefix() + "§cNo map with this title was found");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_INVALID_MAP));
return;
}

game.getVotes().put(arenaName, game.getVotes().get(arenaName) + 1);
player.sendMessage(Messages.getMessage("vote.success").replace("%map%", arena.get().getDisplayName()));
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_SUCCESS).replace("%map%", arena.get().getDisplayName()));
}

@Subcommand("change")
Expand All @@ -95,45 +95,51 @@ public void changeCommand(CommandSender sender, String[] args) {
Player player = (Player) sender;

if (args.length < 1) {
player.sendMessage(Messages.getPrefix() + "§cNumber needed.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_TEAM_NUMBER_NEEDED));
return;
}

if (args.length > 1) {
player.sendMessage(Messages.getPrefix() + "§cToo many arguments.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_TO_MANY_ARGUMENTS));
return;
}

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

if (game.getState() != GameState.LOBBY) {
player.sendMessage(Messages.getPrefix() + "§cThe game is not in the right state to change your team right now");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.TEAM_CHANGE_TEAM_NOT_NOW));
return;
}

try {
MWPlayer mwPlayer = game.getPlayer(player);
int teamNumber = Integer.parseInt(args[0]);
Team to = teamNumber == 1 ? game.getTeam1() : game.getTeam2();
int otherCount = to.getEnemyTeam().getMembers().size() - 1;
int toCount = to.getMembers().size() + 1;
int diff = toCount - otherCount;
if (diff > 1) {
daniel-naegele marked this conversation as resolved.
Show resolved Hide resolved
player.sendMessage(Messages.getMessage("cannot_change_difference"));
return;
}

// Remove the player from the old team and add him to the new team
to.addMember(mwPlayer);

player.sendMessage(Messages.getMessage("team_changed").replace("%team%", to.getFullname()));
} catch (NumberFormatException exception) {
player.sendMessage(Messages.getPrefix() + "§c/mw change <1|2>");

if (!(args[0].equalsIgnoreCase("1") || args[0].equalsIgnoreCase("2"))) {
sender.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_INVALID_TEAM_NUMBER));
return;
}

MWPlayer mwPlayer = game.getPlayer(player);
int teamNumber = Integer.parseInt(args[0]);
Team to = teamNumber == 1 ? game.getTeam1() : game.getTeam2();

// Is the same team?
if (to == mwPlayer.getTeam()) {
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.TEAM_ALREADY_IN_TEAM));
return;
}

// Would the number of team members be too far apart?
if (to != game.getNextTeam()) {
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.TEAM_UNFAIR_TEAM_SIZE));
return;
}

// Remove the player from the old team and add him to the new team
to.addMember(mwPlayer);

player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.TEAM_TEAM_CHANGED).replace("%team%", to.getFullname()));
}

@Subcommand("quit|leave")
Expand All @@ -145,13 +151,13 @@ public void quitCommand(CommandSender sender, String[] args) {
Player player = (Player) sender;

if (args.length > 0) {
player.sendMessage(Messages.getPrefix() + "§cToo many arguments.");
player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_TO_MANY_ARGUMENTS));
return;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static void load() {

// re-save the config with only validated options
SetupUtil.safeFile(FILE, cfg);
cfg = SetupUtil.getLoadedConfig(FILE);
}

private static void addDefaults() {
Expand Down
Loading