Alot of shit
This commit is contained in:
@ -1,10 +1,21 @@
|
||||
package rip.tilly.bedwars.game;
|
||||
|
||||
import io.netty.util.internal.ConcurrentSet;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.github.paperspigot.Title;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.arena.Arena;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -15,10 +26,138 @@ import java.util.UUID;
|
||||
@Setter
|
||||
public class Game {
|
||||
|
||||
private final UUID gameId = UUID.randomUUID();
|
||||
private final List<GameTeam> teams;
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
||||
public Game(GameTeam... teams) {
|
||||
private final Set<Entity> entitiesToRemove = new ConcurrentSet<>();
|
||||
|
||||
private final List<GameTeam> teams;
|
||||
private final Arena arena;
|
||||
|
||||
private final UUID gameId = UUID.randomUUID();
|
||||
|
||||
private CopiedArena copiedArena;
|
||||
private GameState gameState = GameState.STARTING;
|
||||
private int countdown = 6;
|
||||
private int durationTimer;
|
||||
|
||||
public Game(Arena arena, GameTeam... teams) {
|
||||
this.arena = arena;
|
||||
this.teams = Arrays.asList(teams);
|
||||
}
|
||||
|
||||
public GameTeam getTeamByName(String name) {
|
||||
return this.teams.stream().filter(team -> team.getPlayerTeam().getName().equalsIgnoreCase(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public String getDuration() {
|
||||
return TimeUtils.formatIntoMMSS(durationTimer);
|
||||
}
|
||||
|
||||
public void addEntityToRemove(Entity entity) {
|
||||
this.entitiesToRemove.add(entity);
|
||||
}
|
||||
|
||||
public void removeEntityToRemove(Entity entity) {
|
||||
this.entitiesToRemove.remove(entity);
|
||||
}
|
||||
|
||||
public void clearEntitiesToRemove() {
|
||||
this.entitiesToRemove.clear();
|
||||
}
|
||||
|
||||
public void broadcastTitle(String message, String subMessage) {
|
||||
Title title = new Title(message, subMessage, 5, 20, 5);
|
||||
this.teams.forEach(team -> team.playingPlayers().forEach(player -> player.sendTitle(title)));
|
||||
}
|
||||
|
||||
public void broadcast(String message) {
|
||||
this.teams.forEach(team -> team.playingPlayers().forEach(player -> player.sendMessage(CC.translate(message))));
|
||||
}
|
||||
|
||||
public void broadcastSound(Sound sound) {
|
||||
this.teams.forEach(team -> team.playingPlayers().forEach(player -> player.playSound(player.getLocation(), sound, 10, 1)));
|
||||
}
|
||||
|
||||
public int decrementCountdown() {
|
||||
return --this.countdown;
|
||||
}
|
||||
|
||||
public void incrementDuration() {
|
||||
++this.durationTimer;
|
||||
}
|
||||
|
||||
public boolean isPartyMatch() {
|
||||
return (this.teams.get(0).getAllPlayers().size() >= 2 || this.teams.get(1).getAllPlayers().size() >= 2);
|
||||
}
|
||||
|
||||
public boolean isPlaceable(Location location, Game game) {
|
||||
double minX = game.getCopiedArena().getMin().getX();
|
||||
double minZ = game.getCopiedArena().getMin().getZ();
|
||||
double maxX = game.getCopiedArena().getMax().getX();
|
||||
double maxZ = game.getCopiedArena().getMax().getZ();
|
||||
|
||||
if (minX > maxX) {
|
||||
double lastMinX = minX;
|
||||
minX = maxX;
|
||||
maxX = lastMinX;
|
||||
}
|
||||
|
||||
if (minZ > maxZ) {
|
||||
double lastMinZ = minZ;
|
||||
minZ = maxZ;
|
||||
maxZ = lastMinZ;
|
||||
}
|
||||
|
||||
if (location.getX() >= minX && location.getX() <= maxX && location.getZ() >= minZ && location.getZ() <= maxZ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInside(Location location, Game game) {
|
||||
double aMinX = game.getCopiedArena().getTeamAmin().getX();
|
||||
double aMinZ = game.getCopiedArena().getTeamAmin().getZ();
|
||||
double aMaxX = game.getCopiedArena().getTeamAmax().getX();
|
||||
double aMaxZ = game.getCopiedArena().getTeamAmax().getZ();
|
||||
|
||||
if (aMinX > aMaxX) {
|
||||
double lastMinX = aMinX;
|
||||
aMinX = aMaxX;
|
||||
aMaxX = lastMinX;
|
||||
}
|
||||
|
||||
if (aMinZ > aMaxZ) {
|
||||
double lastMinZ = aMinZ;
|
||||
aMinZ = aMaxZ;
|
||||
aMaxZ = lastMinZ;
|
||||
}
|
||||
|
||||
if (location.getX() <= aMinX && location.getX() >= aMaxX && location.getZ() <= aMinZ && location.getZ() >= aMaxZ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
double bMinX = game.getCopiedArena().getTeamBmin().getX();
|
||||
double bMinZ = game.getCopiedArena().getTeamBmin().getZ();
|
||||
double bMaxX = game.getCopiedArena().getTeamBmax().getX();
|
||||
double bMaxZ = game.getCopiedArena().getTeamBmax().getZ();
|
||||
|
||||
if (bMinX > bMaxX) {
|
||||
double lastMinX = bMinX;
|
||||
bMinX = bMaxX;
|
||||
bMaxX = lastMinX;
|
||||
}
|
||||
|
||||
if (bMinZ > bMaxZ) {
|
||||
double lastMinZ = bMinZ;
|
||||
bMinZ = bMaxZ;
|
||||
bMaxZ = lastMinZ;
|
||||
}
|
||||
|
||||
if (location.getX() <= bMinX && location.getX() >= bMaxX && location.getZ() <= bMinZ && location.getZ() >= bMaxZ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
18
src/main/java/rip/tilly/bedwars/game/GameRequest.java
Normal file
18
src/main/java/rip/tilly/bedwars/game/GameRequest.java
Normal file
@ -0,0 +1,18 @@
|
||||
package rip.tilly.bedwars.game;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import rip.tilly.bedwars.game.arena.Arena;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class GameRequest {
|
||||
|
||||
private final UUID requester;
|
||||
private final UUID requested;
|
||||
|
||||
private final Arena arena;
|
||||
private final boolean party;
|
||||
}
|
7
src/main/java/rip/tilly/bedwars/game/GameState.java
Normal file
7
src/main/java/rip/tilly/bedwars/game/GameState.java
Normal file
@ -0,0 +1,7 @@
|
||||
package rip.tilly.bedwars.game;
|
||||
|
||||
public enum GameState {
|
||||
STARTING,
|
||||
FIGHTING,
|
||||
ENDING
|
||||
}
|
@ -26,17 +26,19 @@ public class GameTeam {
|
||||
private final List<UUID> playingPlayers = new ArrayList<>();
|
||||
private UUID leader;
|
||||
|
||||
private final int id;
|
||||
private final PlayerTeam playerTeam;
|
||||
|
||||
public GameTeam(UUID leader, List<UUID> allPlayers, PlayerTeam playerTeam) {
|
||||
public GameTeam(UUID leader, List<UUID> allPlayers, int id, PlayerTeam playerTeam) {
|
||||
this.leader = leader;
|
||||
this.allPlayers = allPlayers;
|
||||
this.playingPlayers.addAll(allPlayers);
|
||||
|
||||
this.id = id;
|
||||
this.playerTeam = playerTeam;
|
||||
}
|
||||
|
||||
public void removePlayer(UUID uuid) {
|
||||
public void killPlayer(UUID uuid) {
|
||||
this.playingPlayers.remove(uuid);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
package rip.tilly.bedwars.game.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
import rip.tilly.bedwars.game.GameTeam;
|
||||
|
||||
@Getter
|
||||
public class GameEndEvent extends GameEvent {
|
||||
|
||||
private final GameTeam winningTeam;
|
||||
private final GameTeam losingTeam;
|
||||
|
||||
public GameEndEvent(Game game, GameTeam winningTeam, GameTeam losingTeam) {
|
||||
super(game);
|
||||
|
||||
this.winningTeam = winningTeam;
|
||||
this.losingTeam = losingTeam;
|
||||
}
|
||||
}
|
24
src/main/java/rip/tilly/bedwars/game/events/GameEvent.java
Normal file
24
src/main/java/rip/tilly/bedwars/game/events/GameEvent.java
Normal file
@ -0,0 +1,24 @@
|
||||
package rip.tilly.bedwars.game.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class GameEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
private final Game game;
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package rip.tilly.bedwars.game.events;
|
||||
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
|
||||
public class GameStartEvent extends GameEvent {
|
||||
public GameStartEvent(Game game) {
|
||||
super(game);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user