Skip to content

Commit

Permalink
feat: preserve save name, compare and set save names when creating ne…
Browse files Browse the repository at this point in the history
…w teams
  • Loading branch information
Misat11 committed Jun 20, 2024
1 parent f928366 commit 0ba3bab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ public static Game loadGame(File file, boolean firstAttempt) {
t.newColor = team.getBoolean("isNewColor", false);
t.color = TeamColor.valueOf(MiscUtils.convertColorToNewFormat(team.getString("color"), t));
t.name = team.getString("actualName", teamN);
t.saveName = teamN;
t.bed = MiscUtils.readLocationFromString(game.world, team.getString("bed"));
t.maxPlayers = team.getInt("maxPlayers");
t.spawn = MiscUtils.readLocationFromString(game.world, team.getString("spawn"));
Expand Down Expand Up @@ -1208,7 +1209,7 @@ public void saveToConfig() {
configMap.set("customPrefix", customPrefix);
if (!teams.isEmpty()) {
for (Team t : teams) {
String name = t.name.replace('.', '_').replace(' ', '_');
String name = t.getSaveName();
configMap.set("teams." + name + ".isNewColor", t.isNewColor());
configMap.set("teams." + name + ".color", t.color.name());
configMap.set("teams." + name + ".maxPlayers", t.maxPlayers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,9 @@ private String removeTeam(String name) {
}

private String addTeam(String name, String color, int maxPlayers) {
String saveName = name.replace('.', '_').replace(' ', '_');
for (Team t : game.getTeams()) {
if (t.name.equals(name)) {
if (t.name.equals(name) || t.getSaveName().equals(saveName)) {
return i18n("admin_command_team_is_already_exists");
}
}
Expand All @@ -728,6 +729,7 @@ private String addTeam(String name, String color, int maxPlayers) {
team.color = c;
team.maxPlayers = maxPlayers;
team.game = game;
team.saveName = saveName;
game.getTeams().add(team);

return i18n("admin_command_team_created").replace("%team%", team.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.screamingsandals.bedwars.game;

import org.jetbrains.annotations.Nullable;
import org.screamingsandals.bedwars.api.game.Game;
import org.bukkit.Location;

Expand All @@ -29,6 +30,7 @@ public class Team implements Cloneable, org.screamingsandals.bedwars.api.Team {
public Location bed;
public Location spawn;
public int maxPlayers;
public @Nullable String saveName;
public Game game;

public Team clone() {
Expand All @@ -40,6 +42,7 @@ public Team clone() {
t.spawn = this.spawn;
t.maxPlayers = this.maxPlayers;
t.game = this.game;
t.saveName = this.saveName;
return t;
}

Expand Down Expand Up @@ -77,4 +80,8 @@ public int getMaxPlayers() {
public Game getGame() {
return game;
}

public String getSaveName() {
return saveName != null ? saveName : name.replace('.', '_').replace(' ', '_');
}
}

0 comments on commit 0ba3bab

Please sign in to comment.