arena: challenger idling 1 min in the options gets sent back to the tribune
This commit is contained in:
1 parent
92a655e107
commit
f6ac150a8f
1 file changed
+20
@@ -16,6 +16,7 @@ import org.bukkit.Sound;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TextDisplay;
|
import org.bukkit.entity.TextDisplay;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -33,6 +34,8 @@ final class Lobby implements PadLobby.Listener {
|
|||||||
private static final double PUSH_MARGIN = 0.4;
|
private static final double PUSH_MARGIN = 0.4;
|
||||||
/** How long a full lobby waits for the challenger to close the options. */
|
/** How long a full lobby waits for the challenger to close the options. */
|
||||||
private static final int CHOOSING_SECONDS = 20;
|
private static final int CHOOSING_SECONDS = 20;
|
||||||
|
/** Whoever keeps the options open this long without clicking anything gets sent off the pad. */
|
||||||
|
private static final int MENU_IDLE_TICKS = 60 * 20;
|
||||||
|
|
||||||
private final Arena arena;
|
private final Arena arena;
|
||||||
private final Region[] regions;
|
private final Region[] regions;
|
||||||
@@ -40,6 +43,8 @@ final class Lobby implements PadLobby.Listener {
|
|||||||
private final TextDisplay[] displays = new TextDisplay[PadLobby.PADS];
|
private final TextDisplay[] displays = new TextDisplay[PadLobby.PADS];
|
||||||
private final Map<UUID, Long> lastPushSound = new HashMap<>();
|
private final Map<UUID, Long> lastPushSound = new HashMap<>();
|
||||||
private long ticks;
|
private long ticks;
|
||||||
|
private @Nullable UUID menuViewer;
|
||||||
|
private int menuIdleTicks;
|
||||||
|
|
||||||
Lobby(Arena arena, Region[] regions) {
|
Lobby(Arena arena, Region[] regions) {
|
||||||
this.arena = arena;
|
this.arena = arena;
|
||||||
@@ -59,12 +64,23 @@ final class Lobby implements PadLobby.Listener {
|
|||||||
else if(state == Arena.PlayerState.TRIBUNE) this.checkEnter(player);
|
else if(state == Arena.PlayerState.TRIBUNE) this.checkEnter(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.checkMenuIdle();
|
||||||
this.pads.tick(this.arena.hasFreeSlot());
|
this.pads.tick(this.arena.hasFreeSlot());
|
||||||
|
|
||||||
if(this.ticks % 3 == 0) this.drawParticles();
|
if(this.ticks % 3 == 0) this.drawParticles();
|
||||||
if(this.ticks % 5 == 0) this.updateDisplays();
|
if(this.ticks % 5 == 0) this.updateDisplays();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkMenuIdle() {
|
||||||
|
if(this.menuViewer == null || ++this.menuIdleTicks < MENU_IDLE_TICKS) return;
|
||||||
|
Player player = Bukkit.getPlayer(this.menuViewer);
|
||||||
|
this.menuViewer = null;
|
||||||
|
if(player == null || !ModeMenu.isOpen(player)) return;
|
||||||
|
this.arena.toTribune(player);
|
||||||
|
player.sendMessage(Style.message("Du hast eine Minute lang nichts ausgewählt und wurdest vom Feld geschickt."));
|
||||||
|
Style.play(player, Sound.BLOCK_NOTE_BLOCK_BASS, 0.6f);
|
||||||
|
}
|
||||||
|
|
||||||
private void checkLeave(Player player) {
|
private void checkLeave(Player player) {
|
||||||
int pad = this.pads.padOf(player.getUniqueId());
|
int pad = this.pads.padOf(player.getUniqueId());
|
||||||
if(pad != -1 && this.isOn(player, pad, 0)) return;
|
if(pad != -1 && this.isOn(player, pad, 0)) return;
|
||||||
@@ -108,6 +124,7 @@ final class Lobby implements PadLobby.Listener {
|
|||||||
int ownSize = menu.ownSize;
|
int ownSize = menu.ownSize;
|
||||||
int opponentSize = menu.opponentSize;
|
int opponentSize = menu.opponentSize;
|
||||||
FightMode mode = menu.mode;
|
FightMode mode = menu.mode;
|
||||||
|
this.menuIdleTicks = 0;
|
||||||
switch(click) {
|
switch(click) {
|
||||||
case ModeMenu.OwnSize(int size) -> ownSize = size;
|
case ModeMenu.OwnSize(int size) -> ownSize = size;
|
||||||
case ModeMenu.OpponentSize(int size) -> opponentSize = size;
|
case ModeMenu.OpponentSize(int size) -> opponentSize = size;
|
||||||
@@ -152,6 +169,8 @@ final class Lobby implements PadLobby.Listener {
|
|||||||
int pad = this.pads.challengerPad();
|
int pad = this.pads.challengerPad();
|
||||||
InteractSounds.of(player).open();
|
InteractSounds.of(player).open();
|
||||||
ModeMenu.open(player, pad, this.pads.size(pad), this.pads.size(1 - pad), this.pads.mode());
|
ModeMenu.open(player, pad, this.pads.size(pad), this.pads.size(1 - pad), this.pads.mode());
|
||||||
|
this.menuViewer = player.getUniqueId();
|
||||||
|
this.menuIdleTicks = 0;
|
||||||
this.pads.setChoosing(player.getUniqueId(), true);
|
this.pads.setChoosing(player.getUniqueId(), true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -160,6 +179,7 @@ final class Lobby implements PadLobby.Listener {
|
|||||||
* The challenger closed the options: a full lobby starts counting down now.
|
* The challenger closed the options: a full lobby starts counting down now.
|
||||||
*/
|
*/
|
||||||
void menuClosed(Player player) {
|
void menuClosed(Player player) {
|
||||||
|
if(player.getUniqueId().equals(this.menuViewer)) this.menuViewer = null;
|
||||||
this.pads.setChoosing(player.getUniqueId(), false);
|
this.pads.setChoosing(player.getUniqueId(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user