SteamWar/BungeeCore
Archiviert
13
2

Added Multi Leader Feature

Dieser Commit ist enthalten in:
zOnlyKroks 2021-04-11 15:45:35 +02:00
Ursprung fc20d9c671
Commit f3a6269331
4 geänderte Dateien mit 74 neuen und 42 gelöschten Zeilen

Datei anzeigen

@ -38,6 +38,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.time.Instant; import java.time.Instant;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import static de.steamwar.bungeecore.Storage.teamInvitations; import static de.steamwar.bungeecore.Storage.teamInvitations;
@ -90,13 +91,14 @@ public class TeamCommand extends BasicCommand {
Message.send("TEAM_HELP_LEAVE", sender); Message.send("TEAM_HELP_LEAVE", sender);
Team team = Team.get(user.getTeam()); Team team = Team.get(user.getTeam());
if(team.getTeamLeader() == user.getId()){ if(user.isLeader()){
Message.send("TEAM_HELP_INVITE", sender); Message.send("TEAM_HELP_INVITE", sender);
Message.send("TEAM_HELP_REMOVE", sender); Message.send("TEAM_HELP_REMOVE", sender);
Message.send("TEAM_HELP_KUERZEL", sender); Message.send("TEAM_HELP_KUERZEL", sender);
Message.send("TEAM_HELP_NAME", sender); Message.send("TEAM_HELP_NAME", sender);
Message.send("TEAM_HELP_COLOR", sender); Message.send("TEAM_HELP_COLOR", sender);
Message.send("TEAM_HELP_LEADER", sender); Message.send("TEAM_HELP_LEADER", sender);
Message.send("TEAM_HELP_STEP_BACK", sender);
} }
} }
} }
@ -122,6 +124,9 @@ public class TeamCommand extends BasicCommand {
case "join": case "join":
join(player, user, args); join(player, user, args);
break; break;
case "stepback":
stepBack(player,user,team);
break;
case "leave": case "leave":
leave(player, user, team); leave(player, user, team);
break; break;
@ -137,8 +142,8 @@ public class TeamCommand extends BasicCommand {
case "changename": case "changename":
changename(player, user, team, args); changename(player, user, team, args);
break; break;
case "changeleader": case "promote":
changeleader(player, user, team, args); promote(player, user, team, args);
break; break;
case "changecolor": case "changecolor":
changeColor(player, user, team); changeColor(player, user, team);
@ -225,18 +230,31 @@ public class TeamCommand extends BasicCommand {
Message.send("TEAM_JOIN_JOINED", player, Team.get(t).getTeamName()); Message.send("TEAM_JOIN_JOINED", player, Team.get(t).getTeamName());
} }
private void stepBack(ProxiedPlayer player, SteamwarUser user, Team team) {
if(notLeader(player, user, team))
return;
if(team.size() > 1 && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)){
Message.send("TEAM_OTHER_LEADER_REQUIRED", player);
return;
}
user.setLeader(false);
Message.send("TEAM_STEP_BACK", player);
}
private void leave(ProxiedPlayer player, SteamwarUser user, Team team){ private void leave(ProxiedPlayer player, SteamwarUser user, Team team){
if(notInTeam(player, user)) if(notInTeam(player, user))
return; return;
if(team.getTeamLeader() == user.getId() && team.size() > 1){ if(team.size() > 1 && user.isLeader() && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)){
Message.send("TEAM_LEAVE_OTHER_LEADER", player); Message.send("TEAM_OTHER_LEADER_REQUIRED", player);
return; return;
} }
user.setTeam(0); user.setTeam(0);
if(team.getTeamLeader() == user.getId()){ if(user.isLeader() && team.size() > 0){
team.disband(); team.disband();
} }
@ -296,7 +314,7 @@ public class TeamCommand extends BasicCommand {
return; return;
} }
if (team.getTeamLeader() == target.getId()) { if (user.isLeader()) {
Message.send("TEAM_REMOVE_NOT_LEADER", player); Message.send("TEAM_REMOVE_NOT_LEADER", player);
return; return;
} }
@ -363,7 +381,7 @@ public class TeamCommand extends BasicCommand {
Message.send("TEAM_NAME_CHANGED", player); Message.send("TEAM_NAME_CHANGED", player);
} }
private void changeleader(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ private void promote(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(notLeader(player, user, team)) if(notLeader(player, user, team))
return; return;
@ -386,8 +404,8 @@ public class TeamCommand extends BasicCommand {
return; return;
} }
team.setTeamLeader(target.getId()); target.setLeader(true);
Message.send("TEAM_LEADER_CHANGED", player, args[1]); Message.send("TEAM_LEADER_PROMOTED", player, args[1]);
} }
private String playerName(SteamwarUser user){ private String playerName(SteamwarUser user){
@ -408,17 +426,15 @@ public class TeamCommand extends BasicCommand {
} }
Message.sendPrefixless("TEAM_INFO_TEAM", player, team.getTeamName(), team.getTeamColor(), team.getTeamKuerzel()); Message.sendPrefixless("TEAM_INFO_TEAM", player, team.getTeamName(), team.getTeamColor(), team.getTeamKuerzel());
Message.sendPrefixless("TEAM_INFO_LEADER", player, playerName(SteamwarUser.get(team.getTeamLeader())));
if(team.getMembers().size() > 1) { List<SteamwarUser> users = team.getMembers().stream().map(userId -> SteamwarUser.get(userId)).collect(Collectors.toList());
StringBuilder sb = new StringBuilder();
List<Integer> members = team.getMembers(); Message.sendPrefixless("TEAM_INFO_LEADER", player, getMemberList(users, true));
for (int i : members) {
if (i == team.getTeamLeader()) String members = getMemberList(users, false);
continue;
sb.append(playerName(SteamwarUser.get(i))).append(" "); if(members.length() > 0) {
} Message.sendPrefixless("TEAM_INFO_MEMBER", player, members);
Message.sendPrefixless("TEAM_INFO_MEMBER", player, sb.toString());
} }
Set<Event> events = TeamTeilnahme.getEvents(team.getTeamId()); Set<Event> events = TeamTeilnahme.getEvents(team.getTeamId());
@ -430,6 +446,16 @@ public class TeamCommand extends BasicCommand {
} }
} }
private String getMemberList(List<SteamwarUser> users, boolean leaders) {
StringBuilder sb = new StringBuilder();
for(SteamwarUser user : users) {
if(user.isLeader() == leaders) {
sb.append(playerName(user)).append(" ");
}
}
return sb.toString();
}
private void list(ProxiedPlayer player, String[] args){ private void list(ProxiedPlayer player, String[] args){
final int TEAMS_PER_PAGE = 10; final int TEAMS_PER_PAGE = 10;
@ -458,7 +484,7 @@ public class TeamCommand extends BasicCommand {
Team tm = all.get(i); Team tm = all.get(i);
Message.sendPrefixless("TEAM_LIST_TEAM", player, Message.parse("TEAM_LIST_TEAM_HOVER", player), Message.sendPrefixless("TEAM_LIST_TEAM", player, Message.parse("TEAM_LIST_TEAM_HOVER", player),
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + tm.getTeamKuerzel()), tm.getTeamColor(), tm.getTeamKuerzel(), tm.getTeamName(), SteamwarUser.get(tm.getTeamLeader()).getUserName()); new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + tm.getTeamKuerzel()), tm.getTeamColor(), tm.getTeamKuerzel(), tm.getTeamName());
} }
TextComponent beforePage = new TextComponent("««"); TextComponent beforePage = new TextComponent("««");
@ -593,7 +619,7 @@ public class TeamCommand extends BasicCommand {
private boolean notLeader(ProxiedPlayer player, SteamwarUser user, Team team){ private boolean notLeader(ProxiedPlayer player, SteamwarUser user, Team team){
if(notInTeam(player, user)) if(notInTeam(player, user))
return true; return true;
if(team.getTeamLeader() != user.getId()){ if(!user.isLeader()){
Message.send("TEAM_NOT_LEADER", player); Message.send("TEAM_NOT_LEADER", player);
return true; return true;
} }
@ -615,6 +641,7 @@ public class TeamCommand extends BasicCommand {
tab.add("create"); tab.add("create");
tab.add("join"); tab.add("join");
tab.add("invite"); tab.add("invite");
tab.add("stepback");
tab.add("leave"); tab.add("leave");
tab.add("info"); tab.add("info");
tab.add("remove"); tab.add("remove");

Datei anzeigen

@ -44,6 +44,7 @@ public class SteamwarUser {
private String userName; private String userName;
private UserGroup userGroup; private UserGroup userGroup;
private int team; private int team;
private boolean leader;
private Map<Punishment.PunishmentType, Punishment> punishments; private Map<Punishment.PunishmentType, Punishment> punishments;
private static final Map<String, SteamwarUser> usersByName = new HashMap<>(); private static final Map<String, SteamwarUser> usersByName = new HashMap<>();
@ -66,6 +67,7 @@ public class SteamwarUser {
userName = rs.getString("UserName"); userName = rs.getString("UserName");
userGroup = UserGroup.getUsergroup(rs.getString("UserGroup")); userGroup = UserGroup.getUsergroup(rs.getString("UserGroup"));
team = rs.getInt("Team"); team = rs.getInt("Team");
leader = rs.getBoolean("Leader");
usersById.put(id, this); usersById.put(id, this);
usersByName.put(userName.toLowerCase(), this); usersByName.put(userName.toLowerCase(), this);
usersByUUID.put(uuid, this); usersByUUID.put(uuid, this);
@ -127,6 +129,7 @@ public class SteamwarUser {
public void setTeam(int team){ public void setTeam(int team){
this.team = team; this.team = team;
SQL.update("Update UserData SET Team = ? WHERE id = ?", team, id); SQL.update("Update UserData SET Team = ? WHERE id = ?", team, id);
setLeader(false);
} }
public int getId() { public int getId() {
@ -261,4 +264,13 @@ public class SteamwarUser {
throw new SecurityException("Could not load First Join"); throw new SecurityException("Could not load First Join");
} }
} }
public boolean isLeader() {
return leader;
}
public void setLeader(boolean leader) {
this.leader = leader;
SQL.update("Update UserData SET Leader = ? WHERE id = ?", leader, id);
}
} }

Datei anzeigen

@ -33,17 +33,15 @@ public class Team {
private final int teamId; private final int teamId;
private String teamKuerzel; private String teamKuerzel;
private String teamName; private String teamName;
private int teamLeader;
private String teamColor; private String teamColor;
private static final List<Team> teamCache = new LinkedList<>(); private static final List<Team> teamCache = new LinkedList<>();
private static final Team pub = new Team(0, "PUB", "Öffentlich", 0, "8"); private static final Team pub = new Team(0, "PUB", "Öffentlich", "8");
private Team(int id, String kuerzel, String name, int leader, String color){ private Team(int id, String kuerzel, String name, String color){
teamId = id; teamId = id;
teamKuerzel = kuerzel; teamKuerzel = kuerzel;
teamName = name; teamName = name;
teamLeader = leader;
teamColor = color; teamColor = color;
if (id != 0) { if (id != 0) {
teamCache.add(this); teamCache.add(this);
@ -51,7 +49,7 @@ public class Team {
} }
private Team(ResultSet rs) throws SQLException { private Team(ResultSet rs) throws SQLException {
this(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getInt("TeamLeader"), rs.getString("TeamColor")); this(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getString("TeamColor"));
} }
public static void create(String kuerzel, String name, int leader){ public static void create(String kuerzel, String name, int leader){
@ -60,7 +58,7 @@ public class Team {
public static Team get(int id){ public static Team get(int id){
if(id == -1) if(id == -1)
return new Team(-1, "?", "?", 0, "8"); return new Team(-1, "?", "?", "8");
if(id == 0) if(id == 0)
return pub; return pub;
for(Team team : teamCache) for(Team team : teamCache)
@ -110,7 +108,7 @@ public class Team {
} }
private void updateDB(){ private void updateDB(){
SQL.update("INSERT INTO Team (TeamID, TeamKuerzel, TeamName, TeamLeader, TeamColor) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE TeamName = VALUES(TeamName), TeamKuerzel = VALUES(TeamKuerzel), TeamLeader = VALUES(TeamLeader), TeamColor = VALUES(TeamColor)", teamId, teamKuerzel, teamName, teamLeader, teamColor); SQL.update("INSERT INTO Team (TeamID, TeamKuerzel, TeamName, TeamColor) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE TeamName = VALUES(TeamName), TeamKuerzel = VALUES(TeamKuerzel), TeamColor = VALUES(TeamColor)", teamId, teamKuerzel, teamName, teamColor);
} }
public int getTeamId() { public int getTeamId() {
@ -135,15 +133,6 @@ public class Team {
updateDB(); updateDB();
} }
public int getTeamLeader() {
return teamLeader;
}
public void setTeamLeader(int teamLeader) {
this.teamLeader = teamLeader;
updateDB();
}
public String getTeamColor() { public String getTeamColor() {
return teamColor; return teamColor;
} }

Datei anzeigen

@ -324,7 +324,8 @@ TEAM_HELP_REMOVE=§8/§7team remove §8- §7Entferne jemanden aus deinem Team.
TEAM_HELP_KUERZEL=§8/§7team changekuerzel §8- §7Ändere dein Teamkürzel. TEAM_HELP_KUERZEL=§8/§7team changekuerzel §8- §7Ändere dein Teamkürzel.
TEAM_HELP_NAME=§8/§7team changename §8- §7Ändere deinen Teamnamen. TEAM_HELP_NAME=§8/§7team changename §8- §7Ändere deinen Teamnamen.
TEAM_HELP_COLOR=§8/§7eteam changecolor §8- §7Ändere deine Teamfarbe. TEAM_HELP_COLOR=§8/§7eteam changecolor §8- §7Ändere deine Teamfarbe.
TEAM_HELP_LEADER=§8/§7eteam changeleader §8- §7Ernenne jemanden zum Teamleader. TEAM_HELP_LEADER=§8/§7eteam promote §8- §7Ernenne jemanden zum Teamleader.
TEAM_HELP_STEP_BACK=§8/§7eteam stepback §8- §7Tritt als Leader zurück.
#Team Create #Team Create
TEAM_CREATE_USAGE=§8/§7team create §8[§eTeamkürzel§8] §8[§eTeamname§8] TEAM_CREATE_USAGE=§8/§7team create §8[§eTeamkürzel§8] §8[§eTeamname§8]
@ -338,9 +339,12 @@ TEAM_JOIN_NOT_BY_TEAM=§cVon diesem Team wurdest du nicht eingeladen.
TEAM_JOIN_JOINED=§7Du bist dem Team §e{0} §7beigetreten! TEAM_JOIN_JOINED=§7Du bist dem Team §e{0} §7beigetreten!
#Team Leave #Team Leave
TEAM_LEAVE_OTHER_LEADER=§cBitte ernenne zunächst ein anderes Teammitglied zum Leader! TEAM_OTHER_LEADER_REQUIRED=§cBitte ernenne zunächst ein anderes Teammitglied zum Leader!
TEAM_LEAVE_LEFT=§7Du hast dein Team verlassen! TEAM_LEAVE_LEFT=§7Du hast dein Team verlassen!
#Team Step Back
TEAM_STEP_BACK=§7Du hast deinen Posten als Teamleader abgegeben§8!
#Team Invite #Team Invite
TEAM_INVITE_USAGE=§8/§7team invite §8[§eSpieler§8] TEAM_INVITE_USAGE=§8/§7team invite §8[§eSpieler§8]
TEAM_INVITE_NO_PLAYER=§cDiesen Spieler gibt es nicht. TEAM_INVITE_NO_PLAYER=§cDiesen Spieler gibt es nicht.
@ -375,7 +379,7 @@ TEAM_NAME_TAKEN=§cEs gibt bereits ein Team mit diesem Namen.
TEAM_LEADER_USAGE=§8/§7team changeleader §8[§eMember§8] TEAM_LEADER_USAGE=§8/§7team changeleader §8[§eMember§8]
TEAM_LEADER_NOT_USER=§cDen Spieler {0} gibt es nicht. TEAM_LEADER_NOT_USER=§cDen Spieler {0} gibt es nicht.
TEAM_LEADER_NOT_MEMBER=§cDer Spieler ist nicht in deinem Team. TEAM_LEADER_NOT_MEMBER=§cDer Spieler ist nicht in deinem Team.
TEAM_LEADER_CHANGED=§7Du hast den Spieler §e{0} §7zum Leader gemacht! TEAM_LEADER_PROMOTED=§7Du hast den Spieler §e{0} §7zum Leader gemacht!
#Team Info #Team Info
TEAM_INFO_USAGE=§8/§7team info §8[§eTeamname§8] TEAM_INFO_USAGE=§8/§7team info §8[§eTeamname§8]
@ -388,7 +392,7 @@ TEAM_INFO_EVENTS=§7Events§8: §e{0}
TEAM_LIST_NOT_PAGE=§cKeine Seitenzahl angegeben TEAM_LIST_NOT_PAGE=§cKeine Seitenzahl angegeben
TEAM_LIST_UNKNOWN_PAGE=§cUngültige Seitenzahl angegeben TEAM_LIST_UNKNOWN_PAGE=§cUngültige Seitenzahl angegeben
TEAM_LIST_HEADER=§7§lTeamliste §7{0}§8/§7{1} TEAM_LIST_HEADER=§7§lTeamliste §7{0}§8/§7{1}
TEAM_LIST_TEAM=§{0}{1} §e{2} §8[§7{3}§8] TEAM_LIST_TEAM=§{0}{1} §e{2}
TEAM_LIST_TEAM_HOVER=§7Teaminfo TEAM_LIST_TEAM_HOVER=§7Teaminfo
TEAM_LIST_PAGE=Seite TEAM_LIST_PAGE=Seite
TEAM_LIST_NEXT=§eNächste Seite TEAM_LIST_NEXT=§eNächste Seite