SteamWar/BungeeCore
Archiviert
13
2

Commits vergleichen

...
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.

4 Commits

Autor SHA1 Nachricht Datum
yoyosource
c7937847bc Update TeamCommand
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2022-09-22 21:30:32 +02:00
yoyosource
18a16e91b0 Update TeamCommand
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2022-09-22 17:16:37 +02:00
yoyosource
9628ff8ac7 Update TeamCommand
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2022-09-22 17:03:26 +02:00
yoyosource
e1a713d52f Initial TeamCommand rework
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2022-09-22 16:51:24 +02:00
2 geänderte Dateien mit 325 neuen und 260 gelöschten Zeilen

Datei anzeigen

@ -24,6 +24,9 @@ import de.steamwar.bungeecore.Storage;
import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.bungeecore.sql.*;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import de.steamwar.messages.ChatSender;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.ChatColor;
@ -41,15 +44,12 @@ import net.md_5.bungee.api.event.ServerConnectEvent;
import java.net.*;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import static de.steamwar.bungeecore.Storage.teamInvitations;
public class TeamCommand extends BasicCommand {
public class TeamCommand extends SWCommand {
private static final List<SWListInv.SWListEntry<String>> COLOR_CODES = new ArrayList<>();
@ -80,64 +80,238 @@ public class TeamCommand extends BasicCommand {
super("team", "");
}
private void help(CommandSender sender){
Message.send("TEAM_HELP_HEADER", sender);
Message.send("TEAM_HELP_LIST", sender);
Message.send("TEAM_HELP_INFO", sender);
Message.send("TEAM_HELP_TP", sender);
if(!(sender instanceof ProxiedPlayer))
return;
ProxiedPlayer player = (ProxiedPlayer) sender;
@Register(help = true)
public void help(ProxiedPlayer player, String... args) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if(user.getTeam() == 0) {
Message.send("TEAM_HELP_CREATE", sender);
Message.send("TEAM_HELP_JOIN", sender);
}else{
Message.send("TEAM_HELP_CHAT", sender);
Message.send("TEAM_HELP_EVENT", sender);
Message.send("TEAM_HELP_LEAVE", sender);
if(user.isLeader()){
Message.send("TEAM_HELP_INVITE", sender);
Message.send("TEAM_HELP_REMOVE", sender);
Message.send("TEAM_HELP_KUERZEL", sender);
Message.send("TEAM_HELP_NAME", sender);
Message.send("TEAM_HELP_COLOR", sender);
Message.send("TEAM_HELP_LEADER", sender);
Message.send("TEAM_HELP_STEP_BACK", sender);
Message.send("TEAM_HELP_SERVER", sender);
Message.send("TEAM_HELP_HEADER", player);
Message.send("TEAM_HELP_LIST", player);
Message.send("TEAM_HELP_INFO", player);
Message.send("TEAM_HELP_TP", player);
if (user.getTeam() == 0) {
Message.send("TEAM_HELP_CREATE", player);
Message.send("TEAM_HELP_JOIN", player);
} else {
Message.send("TEAM_HELP_CHAT", player);
Message.send("TEAM_HELP_EVENT", player);
Message.send("TEAM_HELP_LEAVE", player);
if (user.isLeader()) {
Message.send("TEAM_HELP_INVITE", player);
Message.send("TEAM_HELP_REMOVE", player);
Message.send("TEAM_HELP_KUERZEL", player);
Message.send("TEAM_HELP_NAME", player);
Message.send("TEAM_HELP_COLOR", player);
Message.send("TEAM_HELP_LEADER", player);
Message.send("TEAM_HELP_STEP_BACK", player);
Message.send("TEAM_HELP_SERVER", player);
}
}
}
@Register(value = "create", description = "TEAM_CREATE_USAGE")
public void createTeam(@Validator("noTeam") ProxiedPlayer player, @Validator("unusedKuerzel") String kuerzel, @Validator("unusedName") String name) {
SteamwarUser user = SteamwarUser.get(player);
Team.create(kuerzel, name);
user.setTeam(Team.get(kuerzel).getTeamId());
user.setLeader(true);
Message.send("TEAM_CREATE_CREATED", player, name);
}
@Register(value = "join", description = "TEAM_JOIN_USAGE")
public void joinTeam(@Validator("teamJoin") ProxiedPlayer player, @Mapper("teamJoinTypeMapper") Team toJoin) {
SteamwarUser user = SteamwarUser.get(player);
user.setTeam(toJoin.getTeamId());
teamInvitations.remove(user.getId());
Message.send("TEAM_JOIN_JOINED", player, toJoin.getTeamName());
}
@Register("stepback")
public void stepBack(@Validator("isLeader") ProxiedPlayer player) {
SteamwarUser user = SteamwarUser.get(player);
Team team = Team.get(user.getTeam());
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);
}
@Register("leave")
public void leave(@Validator("inTeam") ProxiedPlayer player) {
SteamwarUser user = SteamwarUser.get(player);
Team team = Team.get(user.getTeam());
int teamSize = team.size();
if (teamSize > 1 && user.isLeader() && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)) {
Message.send("TEAM_OTHER_LEADER_REQUIRED", player);
return;
}
user.setTeam(0);
if (teamSize == 1) team.disband(user);
Message.send("TEAM_LEAVE_LEFT", player);
}
@Validator(value = "noTeam", local = true)
private TypeValidator<ProxiedPlayer> noTeamValidator() {
return (sender, value, messageSender) -> {
if (SteamwarUser.get(value).getTeam() == 0) {
return true;
} else {
messageSender.send("TEAM_IN_TEAM");
return false;
}
};
}
@Validator(value = "inTeam", local = true)
private TypeValidator<ProxiedPlayer> inTeamValidator() {
return (sender, value, messageSender) -> {
if (SteamwarUser.get(value).getTeam() != 0) {
return true;
} else {
messageSender.send("TEAM_NOT_IN_TEAM");
return false;
}
};
}
@Validator(value = "isLeader", local = true)
private TypeValidator<ProxiedPlayer> isLeaderValidator() {
TypeValidator<ProxiedPlayer> inTeam = inTeamValidator();
return (sender, value, messageSender) -> {
if (!inTeam.validate(sender, value, messageSender)) return false;
SteamwarUser steamwarUser = SteamwarUser.get(value);
if (!steamwarUser.isLeader()) {
messageSender.send("TEAM_NOT_LEADER");
return false;
}
return true;
};
}
@Validator(value = "notDuringEvent", local = true)
private TypeValidator<ProxiedPlayer> notDuringEventValidator() {
return (sender, value, messageSender) -> {
if (Event.get() == null) {
return true;
} else {
messageSender.send("TEAM_NOT_IN_EVENT");
return false;
}
};
}
@Validator(value = "teamJoin", local = true)
private TypeValidator<ProxiedPlayer> teamJoinValidator() {
TypeValidator<ProxiedPlayer> noTeam = noTeamValidator();
TypeValidator<ProxiedPlayer> notDuringEvent = notDuringEventValidator();
return (sender, value, messageSender) -> {
if (!noTeam.validate(sender, value, messageSender)) return false;
if (!notDuringEvent.validate(sender, value, messageSender)) return false;
if (!teamInvitations.containsKey(SteamwarUser.get(value).getId())) {
messageSender.send("TEAM_JOIN_NO_INVITATION");
return false;
}
return true;
};
}
@Mapper(value = "teamJoinTypeMapper", local = true)
private TypeMapper<Team> teamJoinTypeMapper() {
return new TypeMapper<Team>() {
@Override
public Team map(CommandSender commandSender, String[] previousArguments, String s) {
SteamwarUser user = SteamwarUser.get((ProxiedPlayer) commandSender);
List<Integer> invs = teamInvitations.get(user.getId());
if (invs.isEmpty()) return null;
if (s.equals("") && invs.size() == 1) {
return Team.get(invs.get(0));
}
for (int i : invs) {
Team team = Team.get(i);
if (team.getTeamName().equals(s)) return team;
}
return null;
}
@Override
public boolean validate(CommandSender sender, Team value, MessageSender messageSender) {
if (value == null) {
SteamwarUser user = SteamwarUser.get((ProxiedPlayer) sender);
List<Integer> invs = teamInvitations.get(user.getId());
if (invs.isEmpty()) {
messageSender.send("TEAM_JOIN_NO_INVITE");
} else {
messageSender.send("TEAM_JOIN_NOT_BY_TEAM");
}
return false;
}
return true;
}
@Override
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
SteamwarUser user = SteamwarUser.get((ProxiedPlayer) sender);
return teamInvitations.get(user.getId()).stream().map(Team::get).map(Team::getTeamName).collect(Collectors.toList());
}
};
}
@Validator(value = "unusedKuerzel", local = true)
private TypeValidator<String> unusedTeamKuerzel() {
return (sender, value, messageSender) -> {
if (value.length() < 2 || value.length() > 4) {
messageSender.send("TEAM_KUERZEL_LENGHT");
return false;
}
Team team = Team.get(SteamwarUser.get((ProxiedPlayer) sender).getTeam());
Team t = Team.get(value);
if (t != null && (team == null || t.getTeamId() != team.getTeamId())) {
messageSender.send("TEAM_KUERZEL_TAKEN");
return false;
}
return true;
};
}
@Validator(value = "unusedName", local = true)
private TypeValidator<String> unusedTeamName() {
return (sender, value, messageSender) -> {
if (value.length() < 4 || value.length() > 15) {
messageSender.send("TEAM_NAME_LENGHT");
return false;
}
Team team = Team.get(SteamwarUser.get((ProxiedPlayer) sender).getTeam());
Team t = Team.get(value);
if (t != null && t.getTeamId() != team.getTeamId()) {
messageSender.send("TEAM_NAME_TAKEN");
return false;
}
return true;
};
}
@Override
public void execute(CommandSender sender, String[] args){
if(args.length < 1){
public void execute(CommandSender sender, String[] args) {
if (args.length < 1) {
help(sender);
return;
}
if(!(sender instanceof ProxiedPlayer))
if (!(sender instanceof ProxiedPlayer))
return;
ProxiedPlayer player = (ProxiedPlayer) sender;
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
Team team = Team.get(user.getTeam());
switch(args[0].toLowerCase()){
case "create":
create(player, user, team, args);
break;
case "join":
join(player, user, args);
break;
case "stepback":
stepBack(player,user,team);
break;
case "leave":
leave(player, user, team);
break;
switch (args[0].toLowerCase()) {
case "invite":
invite(player, user, team, args);
break;
@ -176,133 +350,32 @@ public class TeamCommand extends BasicCommand {
}
}
private void create(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(unwantedInTeam(player, user))
private void invite(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if (notLeader(player, user, team))
return;
if(args.length < 3){
Message.send("TEAM_CREATE_USAGE", player);
return;
}
if(checkTeamKuerzel(player, team, args[1]))
if (notDuringEvent(player))
return;
if(checkTeamName(player, team, args[2]))
return;
Team.create(args[1], args[2]);
user.setTeam(Team.get(args[1]).getTeamId());
user.setLeader(true);
Message.send("TEAM_CREATE_CREATED", player, args[2]);
}
private void join(ProxiedPlayer player, SteamwarUser user, String[] args){
if(unwantedInTeam(player, user))
return;
if(notDuringEvent(player))
return;
if(!teamInvitations.containsKey(user.getId())){
Message.send("TEAM_JOIN_NO_INVITE", player);
return;
}
List<Integer> invs = teamInvitations.get(user.getId());
Integer t = null;
if(invs.size() == 1){
t = invs.get(0);
}else{
if(args.length != 2){
Message.send("TEAM_JOIN_USAGE", player);
StringBuilder sb = new StringBuilder();
for(int inv : invs){
Team team = Team.get(inv);
sb.append(team.getTeamName()).append(" ");
}
Message.send("TEAM_JOIN_INVITED", player, sb.toString());
return;
}
for(int inv : invs){
Team team = Team.get(inv);
if(team.getTeamName().equals(args[1])){
t = inv;
break;
}
}
if(t == null){
Message.send("TEAM_JOIN_NOT_BY_TEAM", player);
return;
}
}
user.setTeam(t);
teamInvitations.remove(user.getId());
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){
if(notInTeam(player, user))
return;
int teamSize = team.size();
if(teamSize > 1 && user.isLeader() && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)){
Message.send("TEAM_OTHER_LEADER_REQUIRED", player);
return;
}
user.setTeam(0);
if(teamSize == 1){
team.disband(user);
}
Message.send("TEAM_LEAVE_LEFT", player);
}
private void invite(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(notLeader(player, user, team))
return;
if(notDuringEvent(player))
return;
if(args.length != 2){
if (args.length != 2) {
Message.send("TEAM_INVITE_USAGE", player);
return;
}
SteamwarUser target = SteamwarUser.get(args[1]);
if(target == null){
if (target == null) {
Message.send("TEAM_INVITE_NO_PLAYER", player);
return;
}else if(target.getTeam() != 0){
} else if (target.getTeam() != 0) {
Message.send("TEAM_INVITE_IN_TEAM", player);
return;
}
if(!teamInvitations.containsKey(target.getId()))
if (!teamInvitations.containsKey(target.getId()))
teamInvitations.put(target.getId(), new LinkedList<>());
if(teamInvitations.get(target.getId()).contains(team.getTeamId())){
if (teamInvitations.get(target.getId()).contains(team.getTeamId())) {
Message.send("TEAM_INVITE_ALREADY_INVITED", player);
return;
}
@ -311,21 +384,21 @@ public class TeamCommand extends BasicCommand {
Message.send("TEAM_INVITE_INVITED", player, args[1]);
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid());
if(p != null)
if (p != null)
Message.send("TEAM_INVITE_INVITED_TARGET", p, team.getTeamColor(), team.getTeamName());
}
private void remove(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(notLeader(player, user, team))
private void remove(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if (notLeader(player, user, team))
return;
if(args.length != 2){
if (args.length != 2) {
Message.send("TEAM_REMOVE_USAGE", player);
return;
}
SteamwarUser target = SteamwarUser.get(args[1]);
if(target == null){
if (target == null) {
Message.send("TEAM_REMOVE_NOT_PLAYER", player);
return;
}
@ -335,18 +408,18 @@ public class TeamCommand extends BasicCommand {
return;
}
if(teamInvitations.containsKey(target.getId())){
if(teamInvitations.get(target.getId()).remove((Integer) team.getTeamId())){
if (teamInvitations.containsKey(target.getId())) {
if (teamInvitations.get(target.getId()).remove((Integer) team.getTeamId())) {
Message.send("TEAM_REMOVE_INVITE", player);
if(teamInvitations.get(target.getId()).isEmpty())
if (teamInvitations.get(target.getId()).isEmpty())
teamInvitations.remove(target.getId());
}else{
} else {
Message.send("TEAM_REMOVE_NO_INVITE", player);
}
return;
}
if(target.getTeam() != user.getTeam()){
if (target.getTeam() != user.getTeam()) {
Message.send("TEAM_REMOVE_NOT_IN_TEAM", player);
return;
}
@ -355,67 +428,67 @@ public class TeamCommand extends BasicCommand {
Message.send("TEAM_REMOVE_REMOVED", player);
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid());
if(p != null)
if (p != null)
Message.send("TEAM_REMOVE_REMOVED_TARGET", player);
}
private void changekuerzel(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(notLeader(player, user, team))
private void changekuerzel(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if (notLeader(player, user, team))
return;
if(notDuringEvent(player))
if (notDuringEvent(player))
return;
if(args.length < 2){
if (args.length < 2) {
Message.send("TEAM_KUERZEL_USAGE", player);
return;
}
if(checkTeamKuerzel(player, team, args[1]))
if (checkTeamKuerzel(player, team, args[1]))
return;
team.setTeamKuerzel(args[1]);
Message.send("TEAM_KUERZEL_CHANGED", player);
}
private void changename(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(notLeader(player, user, team))
private void changename(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if (notLeader(player, user, team))
return;
if(notDuringEvent(player))
if (notDuringEvent(player))
return;
if(args.length < 2){
if (args.length < 2) {
Message.send("TEAM_NAME_USAGE", player);
return;
}
if(checkTeamName(player, team, args[1]))
if (checkTeamName(player, team, args[1]))
return;
team.setTeamName(args[1]);
Message.send("TEAM_NAME_CHANGED", player);
}
private void promote(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(notLeader(player, user, team))
private void promote(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if (notLeader(player, user, team))
return;
if(notDuringEvent(player))
if (notDuringEvent(player))
return;
if(args.length < 2){
if (args.length < 2) {
Message.send("TEAM_LEADER_USAGE", player);
return;
}
SteamwarUser target = SteamwarUser.get(args[1]);
if(target == null){
if (target == null) {
Message.send("TEAM_LEADER_NOT_USER", player, args[1]);
return;
}
if(target.getTeam() != user.getTeam()){
if (target.getTeam() != user.getTeam()) {
Message.send("TEAM_LEADER_NOT_MEMBER", player);
return;
}
@ -424,19 +497,19 @@ public class TeamCommand extends BasicCommand {
Message.send("TEAM_LEADER_PROMOTED", player, args[1]);
}
private String playerName(SteamwarUser user){
private String playerName(SteamwarUser user) {
return ProxyServer.getInstance().getPlayer(user.getUuid()) != null ? "§a" + user.getUserName() : "§e" + user.getUserName();
}
private void info(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(args.length == 1 && user.getTeam() == 0){
private void info(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if (args.length == 1 && user.getTeam() == 0) {
Message.send("TEAM_INFO_USAGE", player);
return;
}else if(user.getTeam() == 0 || args.length == 2){
} else if (user.getTeam() == 0 || args.length == 2) {
team = Team.get(args[1]);
}
if(team == null){
if (team == null) {
Message.send("UNKNOWN_TEAM", player);
return;
}
@ -449,51 +522,51 @@ public class TeamCommand extends BasicCommand {
String members = getMemberList(users, false);
if(members.length() > 0) {
if (members.length() > 0) {
Message.sendPrefixless("TEAM_INFO_MEMBER", player, members);
}
Set<Event> events = TeamTeilnahme.getEvents(team.getTeamId());
if(!events.isEmpty()){
if (!events.isEmpty()) {
Message.sendPrefixless("TEAM_INFO_EVENTS", player, events.stream().map(Event::getEventName).collect(Collectors.joining(", ")));
}
}
private String getMemberList(List<SteamwarUser> users, boolean leaders) {
StringBuilder sb = new StringBuilder();
for(SteamwarUser user : users) {
if(user.isLeader() == leaders) {
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;
int page;
if(args.length > 1){
try{
if (args.length > 1) {
try {
page = Integer.parseInt(args[1]);
}catch(NumberFormatException e){
} catch (NumberFormatException e) {
Message.send("TEAM_LIST_NOT_PAGE", player);
return;
}
}else
} else
page = 1;
List<Team> all = Team.getAll();
final int lastPage = ((all.size() - 1) / 10) + 1;
if(page < 1 || page > lastPage){
if (page < 1 || page > lastPage) {
Message.send("TEAM_LIST_UNKNOWN_PAGE", player);
return;
}
Message.sendPrefixless("TEAM_LIST_HEADER", player, page, lastPage);
for(int i = (page-1) * TEAMS_PER_PAGE; i < (page-1) * TEAMS_PER_PAGE + TEAMS_PER_PAGE && i < all.size(); i++){
for (int i = (page - 1) * TEAMS_PER_PAGE; i < (page - 1) * TEAMS_PER_PAGE + TEAMS_PER_PAGE && i < all.size(); i++) {
Team tm = all.get(i);
Message.sendPrefixless("TEAM_LIST_TEAM", player, Message.parse("TEAM_LIST_TEAM_HOVER", player),
@ -501,77 +574,77 @@ public class TeamCommand extends BasicCommand {
}
TextComponent beforePage = new TextComponent("««");
if(page > 1){
if (page > 1) {
beforePage.setColor(ChatColor.YELLOW);
beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("TEAM_LIST_PREV", player)).create()));
beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team list " + (page - 1)));
}else
} else
beforePage.setColor(ChatColor.DARK_GRAY);
TextComponent nextPage = new TextComponent(" " + Message.parse("TEAM_LIST_PAGE", player) +" »»");
if(page < lastPage){
TextComponent nextPage = new TextComponent(" " + Message.parse("TEAM_LIST_PAGE", player) + " »»");
if (page < lastPage) {
nextPage.setColor(ChatColor.YELLOW);
nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("TEAM_LIST_NEXT", player)).create()));
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team list " + (page + 1)));
}else
} else
nextPage.setColor(ChatColor.DARK_GRAY);
beforePage.addExtra(nextPage);
player.sendMessage(beforePage);
}
private void event(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(notInTeam(player, user))
private void event(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if (notInTeam(player, user))
return;
if(args.length < 2){
if (args.length < 2) {
Message.send("TEAM_EVENT_USAGE", player);
Set<Event> events = TeamTeilnahme.getEvents(team.getTeamId());
if(!events.isEmpty()){
if (!events.isEmpty()) {
Message.send("TEAM_EVENT_HEADER", player);
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_DATE_FORMAT", player));
for(Event e : events)
for (Event e : events)
Message.sendPrefixless("TEAM_EVENT_EVENT", player, e.getStart().toLocalDateTime().format(dateFormat), e.getEventName());
}
return;
}
if(notLeader(player, user, team))
if (notLeader(player, user, team))
return;
if(notDuringEvent(player))
if (notDuringEvent(player))
return;
Event event = Event.get(args[1]);
if(event == null){
if (event == null) {
Message.send("TEAM_EVENT_NO_EVENT", player);
return;
}
if(Instant.now().isAfter(event.getDeadline().toInstant())){
if (Instant.now().isAfter(event.getDeadline().toInstant())) {
Message.send("TEAM_EVENT_OVER", player);
return;
}
if(TeamTeilnahme.nimmtTeil(team.getTeamId(), event.getEventID())){
if (TeamTeilnahme.nimmtTeil(team.getTeamId(), event.getEventID())) {
TeamTeilnahme.notTeilnehmen(team.getTeamId(), event.getEventID());
Message.send("TEAM_EVENT_LEFT", player);
}else{
} else {
TeamTeilnahme.teilnehmen(team.getTeamId(), event.getEventID());
Message.send("TEAM_EVENT_JOINED", player, event.getEventName());
Message.sendPrefixless("TEAM_EVENT_HOW_TO_LEAVE", player);
}
}
private void tp(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(args.length == 1){
if(notInTeam(player, user))
private void tp(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if (args.length == 1) {
if (notInTeam(player, user))
return;
tp(player, team);
return;
}
Team targetTeam = Team.get(args[1]);
if(targetTeam == null){
if (targetTeam == null) {
Message.send("TEAM_TP_NO_TEAM", player);
return;
}
@ -590,15 +663,15 @@ public class TeamCommand extends BasicCommand {
return info;
});
player.connect(ServerConnectRequest.builder()
.target(serverInfo)
.connectTimeout(BungeeCord.getInstance().getConfig().getServerConnectTimeout())
.retry(false)
.reason(ServerConnectEvent.Reason.PLUGIN)
.callback((success, error) -> {
if (error != null) {
Message.send("TEAM_OFFLINE", player);
}
})
.target(serverInfo)
.connectTimeout(BungeeCord.getInstance().getConfig().getServerConnectTimeout())
.retry(false)
.reason(ServerConnectEvent.Reason.PLUGIN)
.callback((success, error) -> {
if (error != null) {
Message.send("TEAM_OFFLINE", player);
}
})
.build());
/*
((UserConnection) player).connect(serverInfo, (success, error) -> {
@ -609,8 +682,8 @@ public class TeamCommand extends BasicCommand {
*/
}
private void server(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(notLeader(player, user, team))
private void server(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if (notLeader(player, user, team))
return;
if (user.isPunishedWithMessage(ChatSender.of(player), Punishment.PunishmentType.NoTeamServer)) {
return;
@ -662,10 +735,10 @@ public class TeamCommand extends BasicCommand {
}
private void changeColor(ProxiedPlayer player, SteamwarUser user, Team team) {
if(notLeader(player, user, team))
if (notLeader(player, user, team))
return;
if(notDuringEvent(player))
if (notDuringEvent(player))
return;
List<SWListInv.SWListEntry<String>> colors = new ArrayList<>();
@ -675,7 +748,8 @@ public class TeamCommand extends BasicCommand {
colors.add(new SWListInv.SWListEntry<>(item, stringSWListEntry.getObject()));
});
SWListInv<String> inv = new SWListInv<>(player, Message.parse("TEAM_COLOR_TITLE", player), colors, (click, element) -> {});
SWListInv<String> inv = new SWListInv<>(player, Message.parse("TEAM_COLOR_TITLE", player), colors, (click, element) -> {
});
inv.setCallback((click, element) -> {
inv.close();
team.setTeamColor(element);
@ -683,62 +757,54 @@ public class TeamCommand extends BasicCommand {
inv.open();
}
private boolean checkTeamName(ProxiedPlayer player, Team team, String arg){
if(arg.length() < 4 || arg.length() > 15){
private boolean checkTeamName(ProxiedPlayer player, Team team, String arg) {
if (arg.length() < 4 || arg.length() > 15) {
Message.send("TEAM_NAME_LENGHT", player);
return true;
}
Team t = Team.get(arg);
if(t != null && t.getTeamId() != team.getTeamId()){
if (t != null && t.getTeamId() != team.getTeamId()) {
Message.send("TEAM_NAME_TAKEN", player);
return true;
}
return false;
}
private boolean checkTeamKuerzel(ProxiedPlayer player, Team team, String arg){
if(arg.length() < 2 || arg.length() > 4){
private boolean checkTeamKuerzel(ProxiedPlayer player, Team team, String arg) {
if (arg.length() < 2 || arg.length() > 4) {
Message.send("TEAM_KUERZEL_LENGHT", player);
return true;
}
Team t = Team.get(arg);
if(t != null && (team == null || t.getTeamId() != team.getTeamId())){
if (t != null && (team == null || t.getTeamId() != team.getTeamId())) {
Message.send("TEAM_KUERZEL_TAKEN", player);
return true;
}
return false;
}
private boolean unwantedInTeam(ProxiedPlayer player, SteamwarUser user){
if(user.getTeam() != 0){
Message.send("TEAM_IN_TEAM", player);
return true;
}
return false;
}
private boolean notInTeam(ProxiedPlayer player, SteamwarUser user){
if(user.getTeam() == 0){
private boolean notInTeam(ProxiedPlayer player, SteamwarUser user) {
if (user.getTeam() == 0) {
Message.send("TEAM_NOT_IN_TEAM", player);
return true;
}
return false;
}
private boolean notLeader(ProxiedPlayer player, SteamwarUser user, Team team){
if(notInTeam(player, user))
private boolean notLeader(ProxiedPlayer player, SteamwarUser user, Team team) {
if (notInTeam(player, user))
return true;
if(!user.isLeader()){
if (!user.isLeader()) {
Message.send("TEAM_NOT_LEADER", player);
return true;
}
return false;
}
private boolean notDuringEvent(ProxiedPlayer player){
if(Event.get() != null){
private boolean notDuringEvent(ProxiedPlayer player) {
if (Event.get() != null) {
Message.send("TEAM_NOT_IN_EVENT", player);
return true;
}
@ -746,9 +812,9 @@ public class TeamCommand extends BasicCommand {
}
@Override
public Iterable<String> onTabComplete(CommandSender commandSender, String[] args){
public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) {
List<String> tab = new ArrayList<>();
if(args.length == 1){
if (args.length == 1) {
tab.add("create");
tab.add("join");
tab.add("invite");
@ -763,11 +829,11 @@ public class TeamCommand extends BasicCommand {
tab.add("changecolor");
tab.add("tp");
tab.add("server");
}else if(args.length == 2){
if(args[1].equalsIgnoreCase("event")){
} else if (args.length == 2) {
if (args[1].equalsIgnoreCase("event")) {
List<Event> coming = Event.getComing();
coming.forEach(event -> tab.add(event.getEventName()));
}else if(args[1].equalsIgnoreCase("join") || args[1].equalsIgnoreCase("info") || args[1].equalsIgnoreCase("tp")){
} else if (args[1].equalsIgnoreCase("join") || args[1].equalsIgnoreCase("info") || args[1].equalsIgnoreCase("tp")) {
List<Team> teams = Team.getAll();
teams.forEach(team -> {
tab.add(team.getTeamName());

Datei anzeigen

@ -412,7 +412,6 @@ TEAM_CREATE_CREATED=§7You have created the team §e{0}§7!
#Team Join
TEAM_JOIN_NO_INVITE=§7You have no pending invitation.
TEAM_JOIN_USAGE=§8/§7team join §8[§eteam§8]
TEAM_JOIN_INVITED=§7You were invited by the following teams§8: §e{0}
TEAM_JOIN_NOT_BY_TEAM=§cYou have no pending invitation from this team.
TEAM_JOIN_JOINED=§7You joined the team §e{0}§7!