From 322ed3eda739998db7705025402a5ccac0f2dc64 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 29 Oct 2019 20:02:41 +0100 Subject: [PATCH] Teamlist fix + Eventreschedule (unteseted) + TpCommand begin (unused) --- src/de/steamwar/bungeecore/BungeeCore.java | 1 + .../commands/EventRescheduleCommand.java | 58 +++++++++++++++++ .../bungeecore/commands/FightCommand.java | 6 +- .../bungeecore/commands/TeamCommand.java | 20 +++--- .../bungeecore/commands/TpCommand.java | 44 +++++++++++++ .../steamwar/bungeecore/sql/EventFight.java | 65 ++++++++----------- 6 files changed, 143 insertions(+), 51 deletions(-) create mode 100644 src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java create mode 100644 src/de/steamwar/bungeecore/commands/TpCommand.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 926abe6..5f04e1e 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -81,6 +81,7 @@ public class BungeeCore extends Plugin { new ForgeCommand(); new EventCommand(); new EventreloadCommand(); + new EventRescheduleCommand(); new PollCommand(); new MuteCommand(); diff --git a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java new file mode 100644 index 0000000..ba0343c --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java @@ -0,0 +1,58 @@ +package de.steamwar.bungeecore.commands; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.sql.Event; +import de.steamwar.bungeecore.sql.EventFight; +import de.steamwar.bungeecore.sql.Team; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.sql.Timestamp; +import java.util.Date; +import java.util.List; +import java.util.ListIterator; + +public class EventRescheduleCommand extends BasicCommand { + + public EventRescheduleCommand() { + super("eventreschedule", "bungeecore.softreload"); + } + + @Override + public void execute(CommandSender sender, String[] args) { + if(!(sender instanceof ProxiedPlayer)) + return; + ProxiedPlayer player = (ProxiedPlayer) sender; + + if(args.length != 2){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§c/eventreschedule [Team1 (Blue)] [Team2 (Red)]"); + return; + } + + Team teamBlue = Team.get(args[0]); + Team teamRed = Team.get(args[1]); + Event event = Event.get(); + if(teamBlue == null || teamRed == null || event == null){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cEin Team ist unbekannt / Derzeit kein Event"); + return; + } + + List fights = EventFight.getEvent(event.getEventID()); + ListIterator it = fights.listIterator(fights.size()); + Timestamp now = Timestamp.from(new Date().toInstant()); + while(it.hasPrevious()){ + EventFight fight = it.previous(); + if(fight.getStartTime().after(now)) + continue; + + if(fight.getTeamBlue() == teamBlue.getTeamId() && fight.getTeamRed() == teamRed.getTeamId()){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§aKampf startet in 30s"); + fight.reschedule(); + EventFight.loadAllComingFights(); + return; + } + } + + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cKein Kampf zwischen den Teams gefunden"); + } +} diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index 1180e73..9a1a3f3 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -1,10 +1,6 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.Servertype; -import de.steamwar.bungeecore.Subserver; -import de.steamwar.bungeecore.SubserverSystem; -import de.steamwar.bungeecore.ArenaMode; +import de.steamwar.bungeecore.*; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 522093a..2d4552a 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -344,18 +344,22 @@ public class TeamCommand extends BasicCommand { BungeeCore.send(player, "§7Team §e" + team.getTeamName() + " §8[§e" + team.getTeamKuerzel() + "§8]"); BungeeCore.send(player, "§7Leader§8: " + SteamwarUser.get(team.getTeamLeader()).getUserName()); - StringBuilder sb = new StringBuilder(); - sb.append("§7Member§8: §e"); - List members = team.getMembers(); - for(int i : members){ - SteamwarUser m = SteamwarUser.get(i); - sb.append(m.getUserName()).append(" "); + if(team.getMembers().size() > 1) { + StringBuilder sb = new StringBuilder(); + sb.append("§7Member§8: §e"); + List members = team.getMembers(); + for (int i : members) { + if (i == team.getTeamLeader()) + continue; + SteamwarUser m = SteamwarUser.get(i); + sb.append(m.getUserName()).append(" "); + } + BungeeCore.send(player, sb.toString()); } - BungeeCore.send(player, sb.toString()); Set events = TeamTeilnahme.getEvents(team.getTeamId()); if(!events.isEmpty()){ - sb = new StringBuilder("§7Events§8: §e"); + StringBuilder sb = new StringBuilder("§7Events§8: §e"); for(Event e : events) sb.append(e.getEventName()).append(" "); BungeeCore.send(player, sb.toString()); diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java new file mode 100644 index 0000000..e78fdcd --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -0,0 +1,44 @@ +package de.steamwar.bungeecore.commands; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.ChatEvent; + +public class TpCommand { + + private TpCommand(){} + + public static void onTp(ChatEvent e, String[] command){ + if(!(e.getSender() instanceof ProxiedPlayer)) + return; + ProxiedPlayer player = (ProxiedPlayer) e.getSender(); + + if(command.length == 1){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§c/tp [Spieler]"); + e.setCancelled(true); + return; + } + + SteamwarUser user = SteamwarUser.get(player); + if(user == null){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spieler"); + e.setCancelled(true); + return; + } + + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(user.getUuid()); + if(target == null){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist derzeit offline"); + e.setCancelled(true); + return; + } + + if(target.getServer() == player.getServer()) + return; + + e.setCancelled(true); + //TODO: Implement Joinme-Command Option + } +} diff --git a/src/de/steamwar/bungeecore/sql/EventFight.java b/src/de/steamwar/bungeecore/sql/EventFight.java index e2f4b74..b638114 100644 --- a/src/de/steamwar/bungeecore/sql/EventFight.java +++ b/src/de/steamwar/bungeecore/sql/EventFight.java @@ -8,30 +8,37 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.util.*; +import static java.time.temporal.ChronoUnit.SECONDS; + public class EventFight implements Comparable { private static Queue fights = new PriorityQueue<>(); - private int eventID; - private int fightID; + private final int eventID; + private final int fightID; private Timestamp startTime; - private ArenaMode spielmodus; - private String map; - private int teamBlue; - private int teamRed; - private int kampfleiter; - private int ergebnis; + private final ArenaMode spielmodus; + private final String map; + private final int teamBlue; + private final int teamRed; + private final int kampfleiter; + private final int ergebnis; - private EventFight(int eventID, int fightID, Timestamp startTime, ArenaMode spielmodus, String map, int teamBlue, int teamRed, int kampfleiter, int ergebnis){ - this.eventID = eventID; - this.fightID = fightID; - this.startTime = startTime; - this.spielmodus = spielmodus; - this.map = map; - this.teamBlue = teamBlue; - this.teamRed = teamRed; - this.kampfleiter = kampfleiter; - this.ergebnis = ergebnis; + private EventFight(ResultSet rs) throws SQLException { + eventID = rs.getInt("EventID"); + fightID = rs.getInt("FightID"); + startTime = rs.getTimestamp("StartTime"); + spielmodus = ArenaMode.valueOf(rs.getString("Spielmodus")); + map = rs.getString("Map"); + teamBlue = rs.getInt("TeamBlue"); + teamRed = rs.getInt("TeamRed"); + kampfleiter = rs.getInt("Kampfleiter"); + ergebnis = rs.getInt("Ergebnis"); + } + + public void reschedule(){ + startTime = Timestamp.from(new Date().toInstant().plus(30, SECONDS)); + SQL.update("UPDATE EventFight SET StartTime = '" + startTime.toString() + "' WHERE EventID = " + eventID + " AND FightID = " + fightID); } public static void loadAllComingFights(){ @@ -39,16 +46,7 @@ public class EventFight implements Comparable { fights.clear(); try{ while(rs.next()){ - fights.add(new EventFight( - rs.getInt("EventID"), - rs.getInt("FightID"), - rs.getTimestamp("StartTime"), - ArenaMode.valueOf(rs.getString("Spielmodus")), - rs.getString("Map"), - rs.getInt("TeamBlue"), - rs.getInt("TeamRed"), - rs.getInt("Kampfleiter"), - rs.getInt("Ergebnis"))); + fights.add(new EventFight(rs)); } }catch (SQLException e){ BungeeCore.log("Failed to load EventFights", e); @@ -60,16 +58,7 @@ public class EventFight implements Comparable { List fights = new LinkedList<>(); try{ while(rs.next()) - fights.add(new EventFight( - eventID, - rs.getInt("FightID"), - rs.getTimestamp("StartTime"), - ArenaMode.valueOf(rs.getString("Spielmodus")), - rs.getString("Map"), - rs.getInt("TeamBlue"), - rs.getInt("TeamRed"), - rs.getInt("Kampfleiter"), - rs.getInt("Ergebnis"))); + fights.add(new EventFight(rs)); }catch (SQLException e){ BungeeCore.log("Failed to load EventFights", e); }