2025-06-26 01:18:01 +03:00
|
|
|
package hdvtdev.blockAndSeek;
|
|
|
|
|
|
2025-06-28 00:36:06 +03:00
|
|
|
|
2025-07-02 17:49:15 +03:00
|
|
|
import org.bukkit.Location;
|
2025-07-01 03:25:09 +03:00
|
|
|
import org.bukkit.Material;
|
2025-07-02 17:49:15 +03:00
|
|
|
import org.bukkit.World;
|
2025-07-01 03:25:09 +03:00
|
|
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
2025-06-26 01:18:01 +03:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2025-06-28 00:36:06 +03:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2025-07-02 17:49:15 +03:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2025-06-26 01:18:01 +03:00
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
import java.util.*;
|
2025-06-26 01:18:01 +03:00
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
public class BlockAndSeekMap implements ConfigurationSerializable {
|
|
|
|
|
|
|
|
|
|
private List<Integer> spawn;
|
|
|
|
|
private List<Integer> lobby;
|
|
|
|
|
private int duration;
|
|
|
|
|
private int minPlayers;
|
|
|
|
|
private int maxPlayers;
|
|
|
|
|
private List<Block> blocks;
|
|
|
|
|
|
|
|
|
|
public BlockAndSeekMap() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BlockAndSeekMap(List<Integer> spawn, List<Integer> lobby, int duration, int minPlayers, int maxPlayers,
|
|
|
|
|
List<Block> blocks) {
|
|
|
|
|
this.spawn = spawn;
|
|
|
|
|
this.lobby = lobby;
|
|
|
|
|
this.duration = duration;
|
|
|
|
|
this.minPlayers = minPlayers;
|
|
|
|
|
this.maxPlayers = maxPlayers;
|
|
|
|
|
this.blocks = blocks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Integer> getSpawn() {
|
|
|
|
|
return spawn;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-02 17:49:15 +03:00
|
|
|
public Location getSpawnLocation(@Nullable World world) {
|
|
|
|
|
return new Location(world, spawn.getFirst(), spawn.get(1), spawn.get(2));
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
public void setSpawn(List<Integer> spawn) {
|
|
|
|
|
this.spawn = spawn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Integer> getLobby() {
|
|
|
|
|
return lobby;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-02 17:49:15 +03:00
|
|
|
public Location getLobbyLocation(@Nullable World world) {
|
|
|
|
|
return new Location(world, lobby.getFirst(), lobby.get(1), lobby.get(2));
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
public void setLobby(List<Integer> lobby) {
|
|
|
|
|
this.lobby = lobby;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getDuration() {
|
|
|
|
|
return duration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setDuration(int duration) {
|
|
|
|
|
this.duration = duration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getMinPlayers() {
|
|
|
|
|
return minPlayers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setMinPlayers(int minPlayers) {
|
|
|
|
|
this.minPlayers = minPlayers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getMaxPlayers() {
|
|
|
|
|
return maxPlayers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setMaxPlayers(int maxPlayers) {
|
|
|
|
|
this.maxPlayers = maxPlayers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Block> getBlocks() {
|
|
|
|
|
return blocks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setBlocks(List<Block> blocks) {
|
|
|
|
|
this.blocks = blocks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isReady() {
|
|
|
|
|
return !spawn.isEmpty() && !lobby.isEmpty() && duration > 0 && !blocks.isEmpty() && minPlayers > 0 && maxPlayers > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static BlockAndSeekMap defaultMap() {
|
|
|
|
|
return new BlockAndSeekMap(List.of(), List.of(), 0, 0, 0, List.of());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Set<MapStatus> check() {
|
|
|
|
|
Set<MapStatus> status = new HashSet<>();
|
|
|
|
|
if (spawn.isEmpty()) status.add(MapStatus.SPAWN_REQUIRED);
|
|
|
|
|
if (lobby.isEmpty()) status.add(MapStatus.LOBBY_REQUIRED);
|
|
|
|
|
if (duration <= 0) status.add(MapStatus.DURATION_REQUIRED);
|
|
|
|
|
if (minPlayers <= 0) status.add(MapStatus.MIN_PLAYERS_REQUIRED);
|
|
|
|
|
if (maxPlayers <= 0) status.add(MapStatus.MAX_PLAYERS_REQUIRED);
|
|
|
|
|
if (blocks.isEmpty()) status.add(MapStatus.BLOCKS_REQUIRED);
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public @NotNull Map<String, Object> serialize() {
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
map.put("spawn", spawn);
|
|
|
|
|
map.put("lobby", lobby);
|
|
|
|
|
map.put("duration", duration);
|
|
|
|
|
map.put("min-players", minPlayers);
|
|
|
|
|
map.put("max-players", maxPlayers);
|
|
|
|
|
List<Map<String, Object>> serBlocks = new ArrayList<>();
|
|
|
|
|
for (Block block : blocks) {
|
|
|
|
|
serBlocks.add(block.toMap());
|
|
|
|
|
}
|
|
|
|
|
map.put("blocks", serBlocks);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@NotNull
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public static BlockAndSeekMap deserialize(@NotNull Map<String, Object> args) {
|
|
|
|
|
|
|
|
|
|
BlockAndSeekMap map = new BlockAndSeekMap();
|
|
|
|
|
map.setSpawn((List<Integer>) args.get("spawn"));
|
|
|
|
|
map.setLobby((List<Integer>) args.get("lobby"));
|
|
|
|
|
map.setDuration((int) args.get("duration"));
|
|
|
|
|
map.setMinPlayers((int) args.get("min-players"));
|
|
|
|
|
map.setMaxPlayers((int) args.get("max-players"));
|
|
|
|
|
map.setBlocks(((List<Map<String, Object>>) args.get("blocks")).stream().map(Block::fromMap).toList());
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
return String.format("BlockAndSeekMap[spawn=%s, lobby=%s, duration=%s, minPlayers=%s, maxPlayers=%s, blocks=%s]", spawn, lobby, duration, minPlayers, maxPlayers, blocks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum MapStatus {
|
|
|
|
|
SPAWN_REQUIRED,
|
|
|
|
|
LOBBY_REQUIRED,
|
|
|
|
|
DURATION_REQUIRED,
|
|
|
|
|
BLOCKS_REQUIRED,
|
|
|
|
|
MIN_PLAYERS_REQUIRED,
|
|
|
|
|
MAX_PLAYERS_REQUIRED
|
|
|
|
|
}
|
2025-06-26 01:18:01 +03:00
|
|
|
|
2025-06-28 00:36:06 +03:00
|
|
|
public record Block(@NotNull ItemStack block, int chance) {
|
2025-07-01 03:25:09 +03:00
|
|
|
public Map<String, Object> toMap() {
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
map.put("block", block.getType().name());
|
|
|
|
|
map.put("chance", chance);
|
|
|
|
|
return map;
|
|
|
|
|
}
|
2025-06-26 01:18:01 +03:00
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
public static Block fromMap(Map<String, Object> map) {
|
|
|
|
|
return new Block(new ItemStack(Material.valueOf(((String) map.get("block")).toUpperCase())), (int) map.get("chance"));
|
|
|
|
|
}
|
2025-06-26 01:18:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|