leaveOnEnd added to config file

This commit is contained in:
Tyler Murphy 2022-05-04 12:22:23 -04:00
parent 061611ef30
commit 590ab6c0e8
4 changed files with 60 additions and 18 deletions

View file

@ -74,7 +74,8 @@ public class Config {
lobbyCountdownEnabled, lobbyCountdownEnabled,
seekerPing, seekerPing,
bungeeLeave, bungeeLeave,
lobbyItemStartAdmin; lobbyItemStartAdmin,
leaveOnEnd;
public static int public static int
minPlayers, minPlayers,
@ -219,6 +220,7 @@ public class Config {
teleportToExit = config.getBoolean("teleportToExit"); teleportToExit = config.getBoolean("teleportToExit");
locale = config.getString("locale", "local"); locale = config.getString("locale", "local");
blockedCommands = config.getStringList("blockedCommands"); blockedCommands = config.getStringList("blockedCommands");
leaveOnEnd = config.getBoolean("leaveOnEnd");
blockedInteracts = new ArrayList<>(); blockedInteracts = new ArrayList<>();
List<String> tempInteracts = config.getStringList("blockedInteracts"); List<String> tempInteracts = config.getStringList("blockedInteracts");
for(String id : tempInteracts){ for(String id : tempInteracts){

View file

@ -153,6 +153,24 @@ public class Game {
}, 20 * 30); }, 20 * 30);
} }
public static void end(WinType type){
if(status == Status.STANDBY || status == Status.ENDING) return;
status = Status.ENDING;
for(Player player : Board.getPlayers()) {
player.getInventory().clear();
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
if(Version.atLeast("1.9")){
for(Player temp : Board.getPlayers()) {
Packet.setGlow(player, temp, false);
}
}
}
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> stop(type), 5*20);
}
public static void stop(WinType type){ public static void stop(WinType type){
if(status == Status.STANDBY) return; if(status == Status.STANDBY) return;
tick = 0; tick = 0;
@ -171,24 +189,38 @@ public class Game {
} }
worldBorder.resetWorldborder("hideandseek_"+spawnWorld); worldBorder.resetWorldborder("hideandseek_"+spawnWorld);
for(Player player : Board.getPlayers()) { for(Player player : Board.getPlayers()) {
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
Board.createLobbyBoard(player);
player.setGameMode(GameMode.ADVENTURE);
Board.addHider(player);
player.getInventory().clear();
if(lobbyStartItem != null && (!lobbyItemStartAdmin || player.isOp()))
player.getInventory().setItem(lobbyItemStartPosition, lobbyStartItem);
if(lobbyLeaveItem != null)
player.getInventory().setItem(lobbyItemLeavePosition, lobbyLeaveItem);
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
if(Version.atLeast("1.9")){ if(Version.atLeast("1.9")){
for(Player temp : Board.getPlayers()) { for(Player temp : Board.getPlayers()) {
Packet.setGlow(player, temp, false); Packet.setGlow(player, temp, false);
} }
} }
if(leaveOnEnd){
Board.removeBoard(player);
Board.remove(player);
player.getInventory().clear();
if(bungeeLeave) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(leaveServer);
player.sendPluginMessage(Main.plugin, "BungeeCord", out.toByteArray());
} else {
player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
}
} else {
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
Board.createLobbyBoard(player);
player.setGameMode(GameMode.ADVENTURE);
Board.addHider(player);
player.getInventory().clear();
if(lobbyStartItem != null && (!lobbyItemStartAdmin || player.isOp()))
player.getInventory().setItem(lobbyItemStartPosition, lobbyStartItem);
if(lobbyLeaveItem != null)
player.getInventory().setItem(lobbyItemLeavePosition, lobbyLeaveItem);
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
}
} }
EventListener.temp_loc.clear(); EventListener.temp_loc.clear();
worldLoader.unloadMap(); worldLoader.unloadMap();
@ -390,15 +422,15 @@ public class Game {
if(Board.sizeHider() < 1) { if(Board.sizeHider() < 1) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND")); if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND"));
else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND")); else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND"));
stop(WinType.SEEKER_WIN); end(WinType.SEEKER_WIN);
} else if(Board.sizeSeeker() < 1) { } else if(Board.sizeSeeker() < 1) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT")); if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
else broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT")); else broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
stop(WinType.NONE); end(WinType.NONE);
} else if(timeLeft < 1) { } else if(timeLeft < 1) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
stop(WinType.HIDER_WIN); end(WinType.HIDER_WIN);
} }
} }

View file

@ -22,5 +22,6 @@ package net.tylermurphy.hideAndSeek.util;
public enum Status { public enum Status {
STANDBY, STANDBY,
STARTING, STARTING,
PLAYING PLAYING,
ENDING
} }

View file

@ -44,6 +44,13 @@ autoJoin: false
# default: false # default: false
teleportToExit: false teleportToExit: false
# Normally when the game ends, players are set back to the lobby to play another game.
# You can disable this, and empty the lobby after the game finishes. This is like everyone
# running /hs leave at the end of the game. Players will leave either to the exit position
# or another server depending what you have `leaveType` set too.
# default: false
leaveOnEnd: false
# What do you want to happen when a player leaves the lobby. If you are running a single server, maybe you want to send # What do you want to happen when a player leaves the lobby. If you are running a single server, maybe you want to send
# them to the world hub. But if you are running a bungee-cord or velocity server, maybe you want to send them to the servers # them to the world hub. But if you are running a bungee-cord or velocity server, maybe you want to send them to the servers
# hub. # hub.