.
This commit is contained in:
parent
05d30347c9
commit
5cb75791e7
3 changed files with 9 additions and 26 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
package de.kentoj.scrow.bukkit.minigame.lobby;
|
package de.kentoj.scrow.bukkit.minigame.lobby;
|
||||||
|
|
||||||
|
import de.kentoj.scrow.bukkit.minigame.Minigame;
|
||||||
import de.kentoj.scrow.bukkit.minigame.phaseflow.LinearPhaseFlow;
|
import de.kentoj.scrow.bukkit.minigame.phaseflow.LinearPhaseFlow;
|
||||||
import de.kentoj.scrow.bukkit.minigame.phase.CompositePhase;
|
import de.kentoj.scrow.bukkit.minigame.phase.CompositePhase;
|
||||||
import de.kentoj.scrow.bukkit.minigame.phaseflow.PhaseContext;
|
import de.kentoj.scrow.bukkit.minigame.phaseflow.PhaseContext;
|
||||||
|
|
@ -15,15 +16,15 @@ import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
|
|
||||||
public class LobbyPhase extends CompositePhase<LobbyMinigame> {
|
public class LobbyPhase<T extends Minigame> extends CompositePhase<T> {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final LinearPhaseFlow subPhaseFlow = new LinearPhaseFlow("lobby");
|
private final LinearPhaseFlow subPhaseFlow = new LinearPhaseFlow("lobby");
|
||||||
|
|
||||||
public LobbyPhase(PhaseContext<LobbyMinigame> ctx) {
|
public LobbyPhase(PhaseContext<T> ctx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
PhaseContext<LobbyMinigame> subCtx = new PhaseContext<>(ctx.game(), subPhaseFlow);
|
PhaseContext<T> subCtx = new PhaseContext<>(ctx.game(), subPhaseFlow);
|
||||||
subPhaseFlow.add(new WaitForMinimumPlayersPhase<>(subCtx));
|
subPhaseFlow.add(new WaitForMinimumPlayersPhase(subCtx));
|
||||||
subPhaseFlow.add(new WaitForMaximumPlayersPhase(subCtx));
|
subPhaseFlow.add(new WaitForMaximumPlayersPhase(subCtx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package de.kentoj.scrow.bukkit.minigame.lobby;
|
package de.kentoj.scrow.bukkit.minigame.lobby;
|
||||||
|
|
||||||
import de.kentoj.scrow.bukkit.gameserver.GameServer;
|
import de.kentoj.scrow.bukkit.minigame.Minigame;
|
||||||
import de.kentoj.scrow.bukkit.minigame.phase.Phase;
|
import de.kentoj.scrow.bukkit.minigame.phase.Phase;
|
||||||
import de.kentoj.scrow.bukkit.minigame.phaseflow.PhaseContext;
|
import de.kentoj.scrow.bukkit.minigame.phaseflow.PhaseContext;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
@ -8,36 +8,18 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class WaitForMaximumPlayersPhase extends Phase<LobbyMinigame> {
|
class WaitForMaximumPlayersPhase<T extends Minigame> extends Phase<T> {
|
||||||
|
|
||||||
private int secsLeft;
|
private int secsLeft;
|
||||||
private CompletableFuture<GameServer> deployedServer;
|
|
||||||
|
|
||||||
public WaitForMaximumPlayersPhase(PhaseContext<LobbyMinigame> ctx) {
|
public WaitForMaximumPlayersPhase(PhaseContext<T> ctx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
|
|
||||||
var delayedExecutor = CompletableFuture.delayedExecutor(3, TimeUnit.MINUTES);
|
|
||||||
ctx.game().setDestroyGameServer(CompletableFuture.runAsync(() -> {
|
|
||||||
synchronized (ctx.game().getGameServer()) {
|
|
||||||
ctx.game().getGameServer().destroy();
|
|
||||||
}
|
|
||||||
}, delayedExecutor));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
this.secsLeft = 5;
|
this.secsLeft = 5;
|
||||||
ctx.listeners().on(PlayerQuitEvent.class, this::onQuit);
|
ctx.listeners().on(PlayerQuitEvent.class, this::onQuit);
|
||||||
|
|
||||||
/*
|
|
||||||
this.deployedServer=Tasks.supplyAsync(() ->
|
|
||||||
gameServers.deployServer(ctx.game().getGameName()))
|
|
||||||
.mapSync(server -> {
|
|
||||||
ctx.game().setGameServer(server);
|
|
||||||
return server;
|
|
||||||
}).toFuture()
|
|
||||||
ctx.game().setGameServer();
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onQuit(PlayerQuitEvent ev) {
|
private void onQuit(PlayerQuitEvent ev) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import de.kentoj.scrow.bukkit.minigame.phase.Phase;
|
||||||
import de.kentoj.scrow.bukkit.minigame.phaseflow.PhaseContext;
|
import de.kentoj.scrow.bukkit.minigame.phaseflow.PhaseContext;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
public class WaitForMinimumPlayersPhase<T extends Minigame> extends Phase<T> {
|
class WaitForMinimumPlayersPhase<T extends Minigame> extends Phase<T> {
|
||||||
|
|
||||||
public WaitForMinimumPlayersPhase(PhaseContext<T> ctx) {
|
public WaitForMinimumPlayersPhase(PhaseContext<T> ctx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue