Skip to content

Commit

Permalink
Added enhancement #13.
Browse files Browse the repository at this point in the history
  • Loading branch information
PauMAVA committed May 4, 2020
1 parent e485f97 commit ef70322
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 28 deletions.
2 changes: 1 addition & 1 deletion resources/lang-packages/lang_br.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ teams:
usage: "Uso da opção register: /uhc teams register <nomeDoTime>"
setmaxsize:
notice: "Argumentos invalidos para a opção setMaxSize no comando /uhc teams <opção>!"
usage: "Uso da opção setMaxSize: /uhc teams setMaxSize <nomeDoTime> <numero>"
usage: "Uso da opção setMaxSize: /uhc teams setMaxSize <nomeDoTime> <numero> ou /uhc teams setMaxSize <numero>"
nosuchoption: "Nenhuma opção disponivel para o comando /uhc teams <opção>!"
availableoptions: "Opções disponiveis são: register, add, kick, delete, setMaxSize."

Expand Down
2 changes: 1 addition & 1 deletion resources/lang-packages/lang_ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ teams:
usage: "Ús de l'opció eliminar: /uhc teams register <nom de l'equip>"
setmaxsize:
notice: "Arguments invàlids per a l'opció establirMidaMàxima del comandament /uhc teams <opció>!"
usage: "Ús de l'opció establirMidaMàxima: /uhc teams setMaxSize <nom de l'equip> <número>"
usage: "Ús de l'opció establirMidaMàxima: /uhc teams setMaxSize <nom de l'equip> <número> o /uhc teams setMaxSize <número>"
nosuchoption: "No hi ha aquesta opció disponible per al comandament /uhc teams <opció>!"
availableoptions: "Les opcions disponibles són: register, add, kick, delete, setMaxSize."

Expand Down
2 changes: 1 addition & 1 deletion resources/lang-packages/lang_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ teams:
usage: "Usage of option register: /uhc teams register <teamName>"
setmaxsize:
notice: "Invalid arguments for the option setMaxSize in the command /uhc teams <option>!"
usage: "Usage of option setMaxSize: /uhc teams setMaxSize <teamName> <number>"
usage: "Usage of option setMaxSize: /uhc teams setMaxSize <teamName> <number> or /uhc teams setMaxSize <number>"
nosuchoption: "No such option available for the command /uhc teams <option>!"
availableoptions: "Available options are: register, add, kick, delete, setMaxSize."

Expand Down
2 changes: 1 addition & 1 deletion resources/lang-packages/lang_es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ teams:
usage: "Uso correcto: /uhc teams register <teamName>"
setmaxsize:
notice: "Argumentos inválidos para la opción setMaxSize en el comando /uhc teams <option>!"
usage: "Uso correcto: /uhc teams setMaxSize <teamName> <number>"
usage: "Uso correcto: /uhc teams setMaxSize <teamName> <number> o /uhc teams setMaxSize <number>"
nosuchoption: "No hay opción disponible para /uhc teams <option>!"
availableoptions: "Las opciones disponibles son: register, add, kick, delete, setMaxSize."

Expand Down
2 changes: 1 addition & 1 deletion src/me/PauMAVA/UhcPlugin/commands/UhcCompleteTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private List<String> firstArg(String subCommand) {

}
if(subCommand.equalsIgnoreCase("teams")) {
return Arrays.asList("add","delete","get","kick","register");
return Arrays.asList("add","delete","get","kick","register","setMaxSize");
}
return new ArrayList<String>();
}
Expand Down
8 changes: 7 additions & 1 deletion src/me/PauMAVA/UhcPlugin/teams/TeamsFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import me.PauMAVA.UhcPlugin.UhcPluginCore;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import sun.security.krb5.Config;

public class TeamsFile {

Expand Down Expand Up @@ -197,7 +198,12 @@ public boolean setMaxTeamSize(String teamName, String value) {
e.printStackTrace();
return false;
}
teamsConfig.getConfigurationSection("teams." + teamName).set("teamSize", valueInt);
ConfigurationSection section = teamsConfig.getConfigurationSection("teams." + teamName);
if (section == null) {
return false;
} else {
section.set("teamSize", valueInt);
}
return true;
}

Expand Down
53 changes: 31 additions & 22 deletions src/me/PauMAVA/UhcPlugin/teams/UhcTeamsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,12 @@ public static void cmdReciever(CommandSender theSender,String[] args) {
break;
}
case "setmaxsize": {
int newSize = Integer.parseInt(args[2]);
int actualSize = teamsConfig.getTeamMembers(args[1]).size();
if(newSize == actualSize) {
sendMessage(theSender, PluginStrings.INFO_PREFIX.toString() + PluginStrings.TEAMS_THE_TEAM.toString() + args[1] + PluginStrings.TEAMS_SAME_SIZE.toString() + newSize + PluginStrings.TEAMS_NO_CHANGES.toString());
break;
}
if(newSize < actualSize) {
List<String> ls = teamsConfig.settleNewSize(args[1] , actualSize - newSize);
sendMessage(theSender, PluginStrings.WARNING_PREFIX.toString() + PluginStrings.TEAMS_AUTOKICK_NOTICE.toString());
for(String kickedPlayer: ls) {
sendMessage(theSender, ChatColor.YELLOW + " - " + kickedPlayer);
if (args.length == 2) {
for (String teamName: teamsConfig.getTeams()) {
resizeTeam(theSender, teamName, Integer.parseInt(args[1]));
}
sendMessage(theSender, PluginStrings.INFO_PREFIX.toString() + PluginStrings.TEAMS_SIZE_CHANGE_SUCCESS.toString() + args[1] + ".");
teamsConfig.saveConfig();
break;
}
boolean check = teamsConfig.setMaxTeamSize(args[1],args[2]);
teamsConfig.saveConfig();
if(check) {
sendMessage(theSender, PluginStrings.INFO_PREFIX.toString() + args[1] + PluginStrings.TEAMS_SIZE_CHANGE_SUCCESS2.toString() + args[2] + ".");
} else {
sendMessage(theSender, PluginStrings.ERROR_PREFIX.toString() + PluginStrings.TEAMS_UNEXPECTED_ERROR.toString());
} else if (args.length == 3){
resizeTeam(theSender, args[1], Integer.parseInt(args[2]));
}
break;
}
Expand Down Expand Up @@ -175,7 +159,7 @@ private static boolean checkForLegalArgs(CommandSender theSender, String[] args)
break;
}
case "setmaxsize": {
if(length != 3 || isNotInt(args[2])) {
if((length == 2 && isNotInt(args[1])) || (length == 3 && isNotInt(args[2]))) {
sendMessage(theSender, PluginStrings.ERROR_PREFIX.toString() + PluginStrings.TEAMS_LEGAL_ARGS_MAXSIZE_NOTICE.toString());
sendMessage(theSender, PluginStrings.ERROR_PREFIX.toString() + PluginStrings.TEAMS_LEGAL_ARGS_MAXSIZE_USAGE.toString());
return false;
Expand Down Expand Up @@ -344,4 +328,29 @@ public void run() {
}
}.runTaskLater(plugin, 40L);
}

private static void resizeTeam(CommandSender theSender, String teamName, int newSize) {
int actualSize = teamsConfig.getTeamMembers(teamName).size();
if(newSize == actualSize) {
sendMessage(theSender, PluginStrings.INFO_PREFIX.toString() + PluginStrings.TEAMS_THE_TEAM.toString() + teamName + PluginStrings.TEAMS_SAME_SIZE.toString() + newSize + PluginStrings.TEAMS_NO_CHANGES.toString());
return;
}
if(newSize < actualSize) {
List<String> ls = teamsConfig.settleNewSize(teamName , actualSize - newSize);
sendMessage(theSender, PluginStrings.WARNING_PREFIX.toString() + PluginStrings.TEAMS_AUTOKICK_NOTICE.toString());
for(String kickedPlayer: ls) {
sendMessage(theSender, ChatColor.YELLOW + " - " + kickedPlayer);
}
sendMessage(theSender, PluginStrings.INFO_PREFIX.toString() + PluginStrings.TEAMS_SIZE_CHANGE_SUCCESS.toString() + teamName + ".");
teamsConfig.saveConfig();
return;
}
boolean check = teamsConfig.setMaxTeamSize(teamName,String.valueOf(newSize));
teamsConfig.saveConfig();
if(check) {
sendMessage(theSender, PluginStrings.INFO_PREFIX.toString() + teamName + PluginStrings.TEAMS_SIZE_CHANGE_SUCCESS2.toString() + newSize + ".");
} else {
sendMessage(theSender, PluginStrings.ERROR_PREFIX.toString() + PluginStrings.TEAMS_UNEXPECTED_ERROR.toString());
}
}
}

0 comments on commit ef70322

Please sign in to comment.