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;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.player.PlayerTeam;
|
||||
import rip.tilly.bedwars.playerdata.PlayerTeam;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -12,10 +12,6 @@ import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class GameTeam {
|
||||
@ -29,6 +25,8 @@ public class GameTeam {
|
||||
private final int id;
|
||||
private final PlayerTeam playerTeam;
|
||||
|
||||
private boolean hasBed = true;
|
||||
|
||||
public GameTeam(UUID leader, List<UUID> allPlayers, int id, PlayerTeam playerTeam) {
|
||||
this.leader = leader;
|
||||
this.allPlayers = allPlayers;
|
||||
@ -49,4 +47,8 @@ public class GameTeam {
|
||||
public Stream<Player> playingPlayers() {
|
||||
return this.playingPlayers.stream().map(this.plugin.getServer()::getPlayer).filter(Objects::nonNull);
|
||||
}
|
||||
|
||||
public void destroyBed() {
|
||||
this.hasBed = false;
|
||||
}
|
||||
}
|
||||
|
32
src/main/java/rip/tilly/bedwars/game/GameType.java
Normal file
32
src/main/java/rip/tilly/bedwars/game/GameType.java
Normal file
@ -0,0 +1,32 @@
|
||||
package rip.tilly.bedwars.game;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum GameType {
|
||||
|
||||
V1(10, "1v1", Arrays.asList(" ", "&9You have to start somewhere,", "&9so why not start here?"),
|
||||
Material.WOOD_SWORD,
|
||||
0, 2),
|
||||
V2(12, "2v2", Arrays.asList(" ", "&9Adapt, overcome and conquer,", "&9you are advancing rapidly."),
|
||||
Material.STONE_SWORD,
|
||||
0, 4),
|
||||
V3(14, "3v3", Arrays.asList(" ", "&9How crazy is this, it seems", "&9like it was just yesterday", "&9since you started."),
|
||||
Material.IRON_SWORD,
|
||||
0, 6),
|
||||
V4(16, "4v4", Arrays.asList(" ", "&9You are now a master of BedWars,", "&9you are now capable of going", "&9up against the undefeated PvP Bot", "&7(Coming soon...)"),
|
||||
Material.DIAMOND_SWORD, 0, 8);
|
||||
|
||||
private final int slot;
|
||||
private final String name;
|
||||
private final List<String> lore;
|
||||
private final Material material;
|
||||
private final int data;
|
||||
private final int queueAmount;
|
||||
}
|
@ -12,10 +12,6 @@ import java.util.List;
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class Arena {
|
||||
|
||||
private final String name;
|
||||
|
@ -10,10 +10,6 @@ import rip.tilly.bedwars.utils.CustomLocation;
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class CopiedArena {
|
||||
|
||||
private CustomLocation a;
|
||||
|
@ -1,19 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
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