diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index c46cd317..8531389b 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -755,3 +755,5 @@ DC_SCHEMUPLOAD_IGNORED=Skipping `{0}`, not a schematic file. DC_SCHEMUPLOAD_INVCHAR=`{0}` has invalid characters in its name. DC_SCHEMUPLOAD_SUCCESS=`{0}` was uploaded successfully. DC_SCHEMUPLOAD_ERROR=An error has occured during the upload of `{0}`. For more information ask a Developer. + +EVENT_VOTE_SUCCESS=§aYour teams vote was accepted! diff --git a/VelocityCore/src/de/steamwar/velocitycore/EventStarter.java b/VelocityCore/src/de/steamwar/velocitycore/EventStarter.java index 15c16b64..54d17747 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/EventStarter.java +++ b/VelocityCore/src/de/steamwar/velocitycore/EventStarter.java @@ -24,6 +24,7 @@ import de.steamwar.messages.Message; import de.steamwar.persistent.Subserver; import de.steamwar.sql.EventFight; import de.steamwar.sql.Team; +import de.steamwar.velocitycore.commands.EventCommand; import net.kyori.adventure.text.event.ClickEvent; import java.sql.Timestamp; @@ -42,6 +43,19 @@ public class EventStarter { spectatePorts.put(port, command); } + private static final Map VOTES = new HashMap<>(); + private static final Map VOTES_REVERSE = new HashMap<>(); + + static { + VOTES.put("MissileWars", 0); + VOTES.put("TowerRun", 1); + VOTES.put("TNTLeague", 2); + + VOTES_REVERSE.put(0, "MissileWars"); + VOTES_REVERSE.put(1, "TowerRun"); + VOTES_REVERSE.put(2, "TNTLeague"); + } + public EventStarter() { EventFight.loadAllComingFights(); VelocityCore.schedule(this::run).repeat(10, TimeUnit.SECONDS).schedule(); @@ -63,6 +77,24 @@ public class EventStarter { //Don't start EventServer if not the event bungee String command; if(VelocityCore.get().getConfig().isEventmode() || next.getSpectatePort() == null) { + ArenaMode blueVote = ArenaMode.getByChat(EventCommand.TEAM_VOTES.getOrDefault(blue.getTeamId(), "TowerRun")); + ArenaMode redVote = ArenaMode.getByChat(EventCommand.TEAM_VOTES.getOrDefault(red.getTeamId(), "TowerRun")); + + ArenaMode mode = blueVote; + + if (!blueVote.getInternalName().equals(redVote.getInternalName())) { + mode = ArenaMode.getByChat(VOTES_REVERSE.get(3 - VOTES.get(blueVote.getInternalName()) - VOTES.get(redVote.getInternalName()))); + } + + next.update( + next.getStartTime(), + mode.getInternalName(), + mode.getRandomMap(), + next.getTeamBlue(), + next.getTeamRed(), + next.getSpectatePort() + ); + ServerStarter starter = new ServerStarter().event(next); starter.callback(subserver -> { diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/EventCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/EventCommand.java index b57d6aad..d718073b 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/EventCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/EventCommand.java @@ -27,6 +27,7 @@ import de.steamwar.messages.Chatter; import de.steamwar.messages.PlayerChatter; import de.steamwar.persistent.Subserver; import de.steamwar.sql.*; +import de.steamwar.velocitycore.ArenaMode; import de.steamwar.velocitycore.EventStarter; import de.steamwar.velocitycore.SubserverSystem; @@ -48,6 +49,39 @@ public class EventCommand extends SWCommand { return (sender, value, messageSender) -> Event.get() == null; } + public static final Map TEAM_VOTES = new HashMap<>(); + + @Register("vote") + public void eventVote(@Validator(value = "noEvent", invert = true) PlayerChatter sender, ArenaMode gamemode) { + if (!TeamTeilnahme.nimmtTeil(sender.user().getTeam(), Event.get().getEventID())) { + return; + } + + TEAM_VOTES.put(sender.user().getTeam(), gamemode.getChatName()); + sender.system("EVENT_VOTE_SUCCESS"); + } + + @ClassMapper(value = ArenaMode.class, local = true) + public TypeMapper eventGamemode() { + return new TypeMapper<>() { + @Override + public ArenaMode map(Chatter sender, PreviousArguments previousArguments, String s) { + ArenaMode mode = ArenaMode.getByChat(s); + + if (tabCompletes(null, previousArguments, null).contains(mode.getChatName())) { + return mode; + } + + return null; + } + + @Override + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { + return Arrays.asList("TowerRun", "MissileWars", "TNTLeague"); + } + }; + } + @Register public void noCurrentEvent(@Validator("noEvent") Chatter sender) { sender.system("EVENT_NO_CURRENT");