uhhh
This commit is contained in:
@ -4,8 +4,11 @@ import io.netty.util.internal.ConcurrentSet;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.github.paperspigot.Title;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.arena.Arena;
|
||||
@ -13,15 +16,9 @@ import rip.tilly.bedwars.game.arena.CopiedArena;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
import rip.tilly.bedwars.utils.TimeUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class Game {
|
||||
@ -29,9 +26,13 @@ public class Game {
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
||||
private final Set<Entity> entitiesToRemove = new ConcurrentSet<>();
|
||||
private final Set<Location> placedBlocksLocations = new ConcurrentSet<>();
|
||||
private final Set<UUID> spectators = new ConcurrentSet<>();
|
||||
private final Set<Integer> runnables = new HashSet<>();
|
||||
|
||||
private final List<GameTeam> teams;
|
||||
private final Arena arena;
|
||||
private final GameType gameType;
|
||||
|
||||
private final UUID gameId = UUID.randomUUID();
|
||||
|
||||
@ -39,9 +40,11 @@ public class Game {
|
||||
private GameState gameState = GameState.STARTING;
|
||||
private int countdown = 6;
|
||||
private int durationTimer;
|
||||
private int winningTeamId;
|
||||
|
||||
public Game(Arena arena, GameTeam... teams) {
|
||||
public Game(Arena arena, GameType gameType, GameTeam... teams) {
|
||||
this.arena = arena;
|
||||
this.gameType = gameType;
|
||||
this.teams = Arrays.asList(teams);
|
||||
}
|
||||
|
||||
@ -66,7 +69,7 @@ public class Game {
|
||||
}
|
||||
|
||||
public void broadcastTitle(String message, String subMessage) {
|
||||
Title title = new Title(message, subMessage, 5, 20, 5);
|
||||
Title title = new Title(CC.translate(message), CC.translate(subMessage), 5, 20, 5);
|
||||
this.teams.forEach(team -> team.playingPlayers().forEach(player -> player.sendTitle(title)));
|
||||
}
|
||||
|
||||
@ -78,6 +81,13 @@ public class Game {
|
||||
this.teams.forEach(team -> team.playingPlayers().forEach(player -> player.playSound(player.getLocation(), sound, 10, 1)));
|
||||
}
|
||||
|
||||
public void broadcastWithSound(String message, Sound sound) {
|
||||
this.teams.forEach(team -> team.playingPlayers().forEach(player -> {
|
||||
player.sendMessage(CC.translate(message));
|
||||
player.playSound(player.getLocation(), sound, 10, 1);
|
||||
}));
|
||||
}
|
||||
|
||||
public int decrementCountdown() {
|
||||
return --this.countdown;
|
||||
}
|
||||
@ -90,6 +100,30 @@ public class Game {
|
||||
return (this.teams.get(0).getAllPlayers().size() >= 2 || this.teams.get(1).getAllPlayers().size() >= 2);
|
||||
}
|
||||
|
||||
public void addSpectator(UUID uuid) {
|
||||
this.spectators.add(uuid);
|
||||
}
|
||||
|
||||
public void removeSpectator(UUID uuid) {
|
||||
this.spectators.remove(uuid);
|
||||
}
|
||||
|
||||
public Stream<Player> spectatorPlayers() {
|
||||
return this.spectators.stream().map(this.plugin.getServer()::getPlayer).filter(Objects::nonNull);
|
||||
}
|
||||
|
||||
public void addRunnable(int id) {
|
||||
this.runnables.add(id);
|
||||
}
|
||||
|
||||
public void addPlacedBlock(Block block) {
|
||||
this.placedBlocksLocations.add(block.getLocation());
|
||||
}
|
||||
|
||||
public void removePlacedBlock(Block block) {
|
||||
this.placedBlocksLocations.remove(block.getLocation());
|
||||
}
|
||||
|
||||
public boolean isPlaceable(Location location, Game game) {
|
||||
double minX = game.getCopiedArena().getMin().getX();
|
||||
double minZ = game.getCopiedArena().getMin().getZ();
|
||||
@ -160,4 +194,19 @@ public class Game {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBreakable(Block block) {
|
||||
if (placedBlocksLocations.contains(block.getLocation())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Material material = block.getType();
|
||||
switch (material) {
|
||||
case BED:
|
||||
case BED_BLOCK:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user