257 lines
9.7 KiB
Java

package net.knarcraft.blockhunt.arena;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SerializableAs("BlockHuntArena")
public class Arena implements ConfigurationSerializable {
/**
* The name of this arena
*/
public final String arenaName;
/**
* The maximum amount of players that can join at once
*/
public int maxPlayers;
/**
* The minimum amount of players required for the arena to start
*/
public int minPlayers;
/**
* The amount of players made into seekers when this arena starts
*/
public int amountSeekersOnStart;
/**
* The amount of seconds players have to wait in the lobby before this arena starts
*/
public int timeInLobbyUntilStart;
/**
* The amount of time seekers have to wait before they can start seeking
*/
public int waitingTimeSeeker;
/**
* The amount of seconds the game will last before hiders automatically win
*/
public int gameTime;
/**
* The amount of seconds until hiders get swords to defend themselves
*/
public int timeUntilHidersSword;
/**
* The amount of seconds left of the game when remaining hidden blocks are announced
*/
public int blockAnnouncerTime;
/**
* Whether seekers can hurt other seekers
*/
public final boolean seekersCanHurtSeekers;
/**
* Whether hiders can hurt seekers
*/
public final boolean hidersCanHurtSeekers;
/**
* Whether hiders can hurt other hiders
*/
public final boolean hidersCanHurtHiders;
/**
* Whether seekers take fall damage
*/
public final boolean seekersTakeFallDamage;
/**
* Whether hiders take fall damage
*/
public final boolean hidersTakeFallDamage;
/**
* The blocks allowed for disguises
*/
public List<ItemStack> disguiseBlocks;
/**
* The commands to be run on the seekers if the seekers win (%player%)
*/
public final List<String> seekersWinCommands;
/**
* The commands to be run on the hiders if the hiders win (%player%)
*/
public final List<String> hidersWinCommands;
/**
* The commands players are allowed to use while in this arena
* TODO: This seems to be missing a proper implementation
*/
public final List<String> allowedCommands;
/**
* The amount of tokens granted to each seeker if seekers win
*/
public int seekersTokenWin;
/**
* The amount of tokens granted to each hider if hiders win
*/
public int hidersTokenWin;
/**
* The amount of tokens granted for killing another player
*/
public int killTokens;
/**
* The players currently in this arena
*/
public final List<Player> playersInArena;
/**
* The current state of this arena
*/
public ArenaState gameState;
public ArenaLocations arenaLocations;
/**
* A timer that counts from the game duration towards 0
*/
public int timer;
public final List<Player> seekers;
public final Scoreboard scoreboard;
public Arena(String arenaName, Location corner1, Location corner2, int maxPlayers, int minPlayers, int amountSeekersOnStart,
int timeInLobbyUntilStart, int waitingTimeSeeker, int gameTime, int timeUntilHidersSword,
int blockAnnouncerTime, boolean seekersCanHurtSeekers, boolean hidersCanHurtSeekers,
boolean hidersCanHurtHiders, boolean seekersTakeFallDamage, boolean hidersTakeFallDamage,
List<ItemStack> disguiseBlocks, Location lobbyWarp, Location hidersWarp, Location seekersWarp,
Location spawnWarp, List<String> seekersWinCommands, List<String> hidersWinCommands,
List<String> allowedCommands, int seekersTokenWin, int hidersTokenWin, int killTokens,
List<Player> playersInArena, ArenaState gameState, int timer, List<Player> seekers,
Scoreboard scoreboard) {
this.arenaName = arenaName;
this.maxPlayers = maxPlayers;
this.minPlayers = minPlayers;
this.amountSeekersOnStart = amountSeekersOnStart;
this.timeInLobbyUntilStart = timeInLobbyUntilStart;
this.waitingTimeSeeker = waitingTimeSeeker;
this.gameTime = gameTime;
this.timeUntilHidersSword = timeUntilHidersSword;
this.blockAnnouncerTime = blockAnnouncerTime;
this.seekersCanHurtSeekers = seekersCanHurtSeekers;
this.hidersCanHurtHiders = hidersCanHurtHiders;
this.hidersCanHurtSeekers = hidersCanHurtSeekers;
this.seekersTakeFallDamage = seekersTakeFallDamage;
this.hidersTakeFallDamage = hidersTakeFallDamage;
this.disguiseBlocks = disguiseBlocks;
this.seekersWinCommands = seekersWinCommands;
this.hidersWinCommands = hidersWinCommands;
this.allowedCommands = allowedCommands;
this.seekersTokenWin = seekersTokenWin;
this.hidersTokenWin = hidersTokenWin;
this.killTokens = killTokens;
this.playersInArena = playersInArena;
this.gameState = gameState;
this.timer = timer;
this.seekers = seekers;
this.scoreboard = scoreboard;
this.arenaLocations = new ArenaLocations(corner1, corner2, lobbyWarp, hidersWarp, seekersWarp, spawnWarp);
}
@Override
public @NotNull Map<String, Object> serialize() {
Map<String, Object> map = new HashMap<>();
map.put("arenaName", arenaName);
map.put("pos1", arenaLocations.getCorner1());
map.put("pos2", arenaLocations.getCorner2());
map.put("maxPlayers", maxPlayers);
map.put("minPlayers", minPlayers);
map.put("amountSeekersOnStart", amountSeekersOnStart);
map.put("timeInLobbyUntilStart", timeInLobbyUntilStart);
map.put("waitingTimeSeeker", waitingTimeSeeker);
map.put("gameTime", gameTime);
map.put("timeUntilHidersSword", timeUntilHidersSword);
map.put("blockAnnouncerTime", blockAnnouncerTime);
map.put("seekersCanHurtSeekers", seekersCanHurtSeekers);
map.put("hidersCanHurtSeekers", hidersCanHurtSeekers);
map.put("hidersCanHurtHiders", hidersCanHurtHiders);
map.put("seekersTakeFallDamage", seekersTakeFallDamage);
map.put("hidersTakeFallDamage", hidersTakeFallDamage);
map.put("disguiseBlocks", disguiseBlocks);
map.put("lobbyWarp", arenaLocations.getLobbyWarp());
map.put("hidersWarp", arenaLocations.getHidersWarp());
map.put("seekersWarp", arenaLocations.getSeekersWarp());
map.put("spawnWarp", arenaLocations.getSpawnWarp());
map.put("seekersWinCommands", seekersWinCommands);
map.put("hidersWinCommands", hidersWinCommands);
map.put("allowedCommands", allowedCommands);
map.put("seekersTokenWin", seekersTokenWin);
map.put("hidersTokenWin", hidersTokenWin);
map.put("killTokens", killTokens);
return map;
}
@SuppressWarnings({"unchecked", "unused"})
public static Arena deserialize(Map<String, Object> map) {
Location loc = new Location(Bukkit.getWorld("world"), 0, 0, 0, 0, 0);
ScoreboardManager scoreboardManager = Bukkit.getScoreboardManager();
Scoreboard scoreboard = null;
if (scoreboardManager != null) {
scoreboard = scoreboardManager.getNewScoreboard();
}
return new Arena(
(String) map.getOrDefault("arenaName", "UNKNOWN_NAME"),
(Location) map.getOrDefault("pos1", loc),
(Location) map.getOrDefault("pos2", loc),
(Integer) map.getOrDefault("maxPlayers", 12),
(Integer) map.getOrDefault("minPlayers", 3),
(Integer) map.getOrDefault("amountSeekersOnStart", 1),
(Integer) map.getOrDefault("timeInLobbyUntilStart", 90),
(Integer) map.getOrDefault("waitingTimeSeeker", 20),
(Integer) map.getOrDefault("gameTime", 200),
(Integer) map.getOrDefault("timeUntilHidersSword", 30),
(Integer) map.getOrDefault("blockAnnouncerTime", 45),
(Boolean) map.getOrDefault("seekersCanHurtSeekers", false),
(Boolean) map.getOrDefault("hidersCanHurtSeekers", true),
(Boolean) map.getOrDefault("hidersCanHurtHiders", false),
(Boolean) map.getOrDefault("seekersTakeFallDamage", false),
(Boolean) map.getOrDefault("hidersTakeFallDamage", false),
(List<ItemStack>) map.getOrDefault("disguiseBlocks", new ArrayList<ItemStack>()),
(Location) map.getOrDefault("lobbyWarp", loc),
(Location) map.getOrDefault("hidersWarp", loc),
(Location) map.getOrDefault("seekersWarp", loc),
(Location) map.getOrDefault("spawnWarp", loc),
(List<String>) map.getOrDefault("seekersWinCommands", new ArrayList<String>()),
(List<String>) map.getOrDefault("hidersWinCommands", new ArrayList<String>()),
(List<String>) map.getOrDefault("allowedCommands", new ArrayList<String>()),
(Integer) map.getOrDefault("seekersTokenWin", 10),
(Integer) map.getOrDefault("hidersTokenWin", 50),
(Integer) map.getOrDefault("killTokens", 8),
new ArrayList<>(), ArenaState.WAITING, 0, new ArrayList<>(), scoreboard
);
}
}