From dd90ee1ced5bc169bfd642d2d3ccd5e04bbe31a6 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 13 Mar 2024 13:36:13 +0100 Subject: [PATCH 1/2] Use new Referee table, Multi spectate server support Signed-off-by: Lixfel --- CommonCore | 2 +- src/de/steamwar/bungeecore/EventStarter.java | 11 ++--------- .../bungeecore/listeners/EventModeListener.java | 11 +++-------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/CommonCore b/CommonCore index bfc72dd..a473e59 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit bfc72ddcb77199bbb8eb19bdfc50744f7234745a +Subproject commit a473e59048a73aae4b40ecb5d6d6b79f0791a138 diff --git a/src/de/steamwar/bungeecore/EventStarter.java b/src/de/steamwar/bungeecore/EventStarter.java index b2992f3..3a45996 100644 --- a/src/de/steamwar/bungeecore/EventStarter.java +++ b/src/de/steamwar/bungeecore/EventStarter.java @@ -20,12 +20,9 @@ package de.steamwar.bungeecore; import de.steamwar.sql.EventFight; -import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; -import de.steamwar.sql.Event; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.scheduler.ScheduledTask; import java.sql.Timestamp; @@ -63,13 +60,9 @@ public class EventStarter implements Runnable { Team red = Team.get(next.getTeamRed()); //Don't start EventServer if not the event bungee - if(BungeeCore.EVENT_MODE || !Event.get(next.getEventID()).spectateSystem()) { + if(BungeeCore.EVENT_MODE || next.getSpectatePort() == 0) { ServerStarter starter = new ServerStarter().event(next); - ProxiedPlayer leiter = ProxyServer.getInstance().getPlayer(SteamwarUser.get(next.getKampfleiter()).getUUID()); - if(leiter != null) - starter.send(leiter); - starter.callback(subserver -> { eventServer.put(blue.getTeamId(), subserver); eventServer.put(red.getTeamId(), subserver); @@ -79,7 +72,7 @@ public class EventStarter implements Runnable { new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/event " + blue.getTeamKuerzel()), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName()); } else { Message.broadcast("EVENT_FIGHT_BROADCAST", "EVENT_FIGHT_BROADCAST_HOVER", - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/spectate"), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName()); + new ClickEvent(ClickEvent.Action.RUN_COMMAND, next.getSpectatePort() == 2222 ? "/spectate" : "/spectate2"), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName()); } } } diff --git a/src/de/steamwar/bungeecore/listeners/EventModeListener.java b/src/de/steamwar/bungeecore/listeners/EventModeListener.java index 4d2b23f..c221dba 100644 --- a/src/de/steamwar/bungeecore/listeners/EventModeListener.java +++ b/src/de/steamwar/bungeecore/listeners/EventModeListener.java @@ -1,10 +1,7 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.Message; -import de.steamwar.sql.EventFight; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.TeamTeilnahme; -import de.steamwar.sql.Event; +import de.steamwar.sql.*; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.event.EventHandler; @@ -24,10 +21,8 @@ public class EventModeListener extends BasicListener { if(TeamTeilnahme.nimmtTeil(user.getTeam(), event.getEventID())) return; - for(EventFight eventFight : EventFight.getEvent(event.getEventID())){ - if(eventFight.getKampfleiter() == user.getId()) - return; - } + if(Referee.get(event.getEventID()).contains(user.getId())) + return; e.getPlayer().disconnect(TextComponent.fromLegacyText(Message.parse("EVENTMODE_KICK", e.getPlayer()))); } -- 2.39.5 From 628e7b093cf7d77515a2f6b94f66a6239f15dd65 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 14 Mar 2024 09:31:30 +0100 Subject: [PATCH 2/2] More elegant port solution Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/BungeeCore.java | 4 ++++ src/de/steamwar/bungeecore/EventStarter.java | 23 ++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 643921c..1870422 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -312,6 +312,10 @@ public class BungeeCore extends Plugin { final Configuration server = servers.getSection(serverName); List cmds = server.getStringList("commands"); String cmd = cmds.remove(0); + + if(server.contains("spectatePort")) + EventStarter.addSpectateServer(server.getInt("spectatePort"), cmd); + new ServerSwitchCommand( cmd, serverName, diff --git a/src/de/steamwar/bungeecore/EventStarter.java b/src/de/steamwar/bungeecore/EventStarter.java index 3a45996..60ad454 100644 --- a/src/de/steamwar/bungeecore/EventStarter.java +++ b/src/de/steamwar/bungeecore/EventStarter.java @@ -23,34 +23,33 @@ import de.steamwar.sql.EventFight; import de.steamwar.sql.Team; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.scheduler.ScheduledTask; import java.sql.Timestamp; +import java.util.HashMap; import java.util.Map; import java.util.Queue; import java.util.concurrent.TimeUnit; import static de.steamwar.bungeecore.Storage.eventServer; -public class EventStarter implements Runnable { +public class EventStarter { - private static ScheduledTask task = null; + private static final Map spectatePorts = new HashMap<>(); - EventStarter(){ + public static void addSpectateServer(int port, String command) { + spectatePorts.put(port, command); + } + + public EventStarter() { EventFight.loadAllComingFights(); - - if(task != null) - task.cancel(); - - ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), this, 1, 10, TimeUnit.SECONDS); + ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), this::run, 1, 10, TimeUnit.SECONDS); } public static Map getEventServer() { return eventServer; } - @Override - public void run() { + private void run() { eventServer.entrySet().removeIf(entry -> Subserver.getSubserver(entry.getValue().getServer()) == null); Queue fights = EventFight.getFights(); @@ -72,7 +71,7 @@ public class EventStarter implements Runnable { new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/event " + blue.getTeamKuerzel()), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName()); } else { Message.broadcast("EVENT_FIGHT_BROADCAST", "EVENT_FIGHT_BROADCAST_HOVER", - new ClickEvent(ClickEvent.Action.RUN_COMMAND, next.getSpectatePort() == 2222 ? "/spectate" : "/spectate2"), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName()); + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + spectatePorts.get(next.getSpectatePort())), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName()); } } } -- 2.39.5