force spectator flight
This commit is contained in:
parent
853ca07431
commit
66f9ad1011
3 changed files with 95 additions and 91 deletions
|
@ -23,8 +23,6 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
import net.tylermurphy.hideAndSeek.util.WinType;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
||||||
|
@ -38,7 +36,7 @@ public class Stop implements ICommand {
|
||||||
}
|
}
|
||||||
if(Game.status == Status.STARTING || Game.status == Status.PLAYING) {
|
if(Game.status == Status.STARTING || Game.status == Status.PLAYING) {
|
||||||
Game.broadcastMessage(abortPrefix + message("STOP"));
|
Game.broadcastMessage(abortPrefix + message("STOP"));
|
||||||
Game.stop();
|
Game.end();
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS"));
|
sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -348,4 +348,5 @@ public class EventListener implements Listener {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -152,7 +152,7 @@ public class Game {
|
||||||
}, 20 * 30);
|
}, 20 * 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void end(WinType type){
|
public static void stop(WinType type){
|
||||||
if(status == Status.STANDBY || status == Status.ENDING) return;
|
if(status == Status.STANDBY || status == Status.ENDING) return;
|
||||||
status = Status.ENDING;
|
status = Status.ENDING;
|
||||||
for(Player player : Board.getPlayers()) {
|
for(Player player : Board.getPlayers()) {
|
||||||
|
@ -176,10 +176,10 @@ public class Game {
|
||||||
winners.add(Board.getFirstSeeker().getUniqueId());
|
winners.add(Board.getFirstSeeker().getUniqueId());
|
||||||
Database.playerInfo.addWins(players, winners, Board.getHiderKills(), Board.getHiderDeaths(), Board.getSeekerKills(), Board.getSeekerDeaths(), type);
|
Database.playerInfo.addWins(players, winners, Board.getHiderKills(), Board.getHiderDeaths(), Board.getSeekerKills(), Board.getSeekerDeaths(), type);
|
||||||
}
|
}
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, Game::stop, 5*20);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, Game::end, 5*20);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void stop(){
|
public static void end(){
|
||||||
if(status == Status.STANDBY) return;
|
if(status == Status.STANDBY) return;
|
||||||
tick = 0;
|
tick = 0;
|
||||||
countdownTime = -1;
|
countdownTime = -1;
|
||||||
|
@ -235,64 +235,6 @@ public class Game {
|
||||||
Board.reloadLobbyBoards();
|
Board.reloadLobbyBoards();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNotSetup() {
|
|
||||||
if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return true;
|
|
||||||
if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return true;
|
|
||||||
if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return true;
|
|
||||||
if(mapSaveEnabled) {
|
|
||||||
File destenation = new File(Main.root + File.separator + getGameWorld());
|
|
||||||
if (!destenation.exists()) return true;
|
|
||||||
}
|
|
||||||
return saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getGameWorld(){
|
|
||||||
if(mapSaveEnabled) return "hideandseek_"+spawnWorld;
|
|
||||||
else return spawnWorld;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onTick() {
|
|
||||||
if(isNotSetup()) return;
|
|
||||||
if(status == Status.STANDBY) whileWaiting();
|
|
||||||
else if(status == Status.STARTING) whileStarting();
|
|
||||||
else if(status == Status.PLAYING) whilePlaying();
|
|
||||||
tick++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void resetWorldborder(String worldName){
|
|
||||||
worldBorder = new Border();
|
|
||||||
worldBorder.resetWorldborder(worldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void broadcastMessage(String message) {
|
|
||||||
for(Player player : Board.getPlayers()) {
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void resetPlayer(Player player) {
|
|
||||||
player.getInventory().clear();
|
|
||||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
|
||||||
player.removePotionEffect(effect.getType());
|
|
||||||
}
|
|
||||||
if (Board.isSeeker(player)) {
|
|
||||||
if(pvpEnabled)
|
|
||||||
for(ItemStack item : Items.SEEKER_ITEMS)
|
|
||||||
player.getInventory().addItem(item);
|
|
||||||
for(PotionEffect effect : Items.SEEKER_EFFECTS)
|
|
||||||
player.addPotionEffect(effect);
|
|
||||||
} else if (Board.isHider(player)) {
|
|
||||||
if(pvpEnabled)
|
|
||||||
for(ItemStack item : Items.HIDER_ITEMS)
|
|
||||||
player.getInventory().addItem(item);
|
|
||||||
for(PotionEffect effect : Items.HIDER_EFFECTS)
|
|
||||||
player.addPotionEffect(effect);
|
|
||||||
if(glowEnabled) {
|
|
||||||
player.getInventory().addItem(glowPowerupItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void join(Player player){
|
public static void join(Player player){
|
||||||
if(Game.status == Status.STANDBY || Game.status == Status.ENDING) {
|
if(Game.status == Status.STANDBY || Game.status == Status.ENDING) {
|
||||||
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
|
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
|
||||||
|
@ -369,39 +311,40 @@ public class Game {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeItems(Player player){
|
public static void onTick() {
|
||||||
for(ItemStack si : Items.SEEKER_ITEMS)
|
if(isNotSetup()) return;
|
||||||
for(ItemStack i : player.getInventory().getContents())
|
if(status == Status.STANDBY) whileWaiting();
|
||||||
if(si.isSimilar(i)) player.getInventory().remove(i);
|
else if(status == Status.STARTING) whileStarting();
|
||||||
for(ItemStack hi : Items.HIDER_ITEMS)
|
else if(status == Status.PLAYING) whilePlaying();
|
||||||
for(ItemStack i : player.getInventory().getContents())
|
tick++;
|
||||||
if(hi.isSimilar(i)) player.getInventory().remove(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void whileWaiting() {
|
private static void whileWaiting() {
|
||||||
if(lobbyCountdownEnabled){
|
if(!lobbyCountdownEnabled) return;
|
||||||
if(lobbyMin <= Board.size()){
|
if(lobbyMin <= Board.size()){
|
||||||
if(countdownTime == -1)
|
if(countdownTime == -1)
|
||||||
countdownTime = countdown;
|
countdownTime = countdown;
|
||||||
if(Board.size() >= changeCountdown)
|
if(Board.size() >= changeCountdown)
|
||||||
countdownTime = Math.min(countdownTime, 10);
|
countdownTime = Math.min(countdownTime, 10);
|
||||||
if(tick % 20 == 0) {
|
if(tick % 20 == 0) {
|
||||||
countdownTime--;
|
countdownTime--;
|
||||||
Board.reloadLobbyBoards();
|
Board.reloadLobbyBoards();
|
||||||
}
|
|
||||||
if(countdownTime == 0){
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
countdownTime = -1;
|
|
||||||
}
|
}
|
||||||
|
if(countdownTime == 0){
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
countdownTime = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void whileStarting(){
|
private static void whileStarting(){
|
||||||
|
for(Player spectator : Board.getSpectators()){
|
||||||
|
spectator.setFlying(spectator.getAllowFlight());
|
||||||
|
}
|
||||||
checkWinConditions();
|
checkWinConditions();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void whilePlaying() {
|
private static void whilePlaying() {
|
||||||
for(Player hider : Board.getHiders()) {
|
for(Player hider : Board.getHiders()) {
|
||||||
int distance = 100, temp = 100;
|
int distance = 100, temp = 100;
|
||||||
|
@ -432,6 +375,9 @@ public class Game {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for(Player spectator : Board.getSpectators()){
|
||||||
|
spectator.setFlying(spectator.getAllowFlight());
|
||||||
|
}
|
||||||
if(tick%20 == 0) {
|
if(tick%20 == 0) {
|
||||||
if(gameLength > 0) {
|
if(gameLength > 0) {
|
||||||
Board.reloadGameBoards();
|
Board.reloadGameBoards();
|
||||||
|
@ -444,25 +390,84 @@ public class Game {
|
||||||
checkWinConditions();
|
checkWinConditions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void resetWorldborder(String worldName){
|
||||||
|
worldBorder = new Border();
|
||||||
|
worldBorder.resetWorldborder(worldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void broadcastMessage(String message) {
|
||||||
|
for(Player player : Board.getPlayers()) {
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNotSetup() {
|
||||||
|
if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return true;
|
||||||
|
if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return true;
|
||||||
|
if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return true;
|
||||||
|
if(mapSaveEnabled) {
|
||||||
|
File destenation = new File(Main.root + File.separator + getGameWorld());
|
||||||
|
if (!destenation.exists()) return true;
|
||||||
|
}
|
||||||
|
return saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getGameWorld(){
|
||||||
|
if(mapSaveEnabled) return "hideandseek_"+spawnWorld;
|
||||||
|
else return spawnWorld;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void resetPlayer(Player player) {
|
||||||
|
player.getInventory().clear();
|
||||||
|
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||||
|
player.removePotionEffect(effect.getType());
|
||||||
|
}
|
||||||
|
if (Board.isSeeker(player)) {
|
||||||
|
if(pvpEnabled)
|
||||||
|
for(ItemStack item : Items.SEEKER_ITEMS)
|
||||||
|
player.getInventory().addItem(item);
|
||||||
|
for(PotionEffect effect : Items.SEEKER_EFFECTS)
|
||||||
|
player.addPotionEffect(effect);
|
||||||
|
} else if (Board.isHider(player)) {
|
||||||
|
if(pvpEnabled)
|
||||||
|
for(ItemStack item : Items.HIDER_ITEMS)
|
||||||
|
player.getInventory().addItem(item);
|
||||||
|
for(PotionEffect effect : Items.HIDER_EFFECTS)
|
||||||
|
player.addPotionEffect(effect);
|
||||||
|
if(glowEnabled) {
|
||||||
|
player.getInventory().addItem(glowPowerupItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeItems(Player player){
|
||||||
|
for(ItemStack si : Items.SEEKER_ITEMS)
|
||||||
|
for(ItemStack i : player.getInventory().getContents())
|
||||||
|
if(si.isSimilar(i)) player.getInventory().remove(i);
|
||||||
|
for(ItemStack hi : Items.HIDER_ITEMS)
|
||||||
|
for(ItemStack i : player.getInventory().getContents())
|
||||||
|
if(hi.isSimilar(i)) player.getInventory().remove(i);
|
||||||
|
}
|
||||||
|
|
||||||
private static void checkWinConditions(){
|
private static void checkWinConditions(){
|
||||||
if(Board.sizeHider() < 1) {
|
if(Board.sizeHider() < 1) {
|
||||||
if(hiderLeave){
|
if(hiderLeave){
|
||||||
if (announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_QUIT"));
|
if (announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_QUIT"));
|
||||||
else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_QUIT"));
|
else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_QUIT"));
|
||||||
end(WinType.NONE);
|
stop(WinType.NONE);
|
||||||
} else {
|
} else {
|
||||||
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"));
|
||||||
end(WinType.SEEKER_WIN);
|
stop(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"));
|
||||||
end(WinType.NONE);
|
stop(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"));
|
||||||
end(WinType.HIDER_WIN);
|
stop(WinType.HIDER_WIN);
|
||||||
}
|
}
|
||||||
hiderLeave = false;
|
hiderLeave = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue