This commit is contained in:
parent
f36f81ba23
commit
c9d84f25b7
|
@ -11,6 +11,7 @@ import net.megavex.scoreboardlibrary.api.ScoreboardLibrary;
|
|||
import net.megavex.scoreboardlibrary.api.exception.NoPacketAdapterAvailableException;
|
||||
import net.megavex.scoreboardlibrary.api.noop.NoopScoreboardLibrary;
|
||||
import net.megavex.scoreboardlibrary.api.team.TeamManager;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
@ -18,6 +19,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
import xyz.twovb.sgm.commands.handlers.InvalidArgsHandler;
|
||||
import xyz.twovb.sgm.commands.handlers.NoPermissionsHandler;
|
||||
import xyz.twovb.sgm.commands.impl.GameCommand;
|
||||
import xyz.twovb.sgm.commands.impl.JailCommand;
|
||||
import xyz.twovb.sgm.commands.impl.LevelCommand;
|
||||
import xyz.twovb.sgm.commands.impl.SGMCommand;
|
||||
import xyz.twovb.sgm.games.GameManager;
|
||||
|
@ -28,6 +30,7 @@ import xyz.twovb.toolbox.managers.ConfigManager;
|
|||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.utils.CustomLogger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -50,8 +53,6 @@ public final class SGM extends JavaPlugin {
|
|||
|
||||
@Getter
|
||||
private ScoreboardLibrary scoreboardLibrary;
|
||||
@Getter
|
||||
private TeamManager teamManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
@ -102,7 +103,20 @@ public final class SGM extends JavaPlugin {
|
|||
}
|
||||
|
||||
private void registerCommands() {
|
||||
LiteCommandsBukkit.builder().commands(new SGMCommand(), new LevelCommand(), new GameCommand()).invalidUsage(new InvalidArgsHandler()).missingPermission(new NoPermissionsHandler()).message(LiteBukkitMessages.PLAYER_NOT_FOUND, input -> Messages.getString("commands.invalid-player").replace("%player%", input)).message(LiteBukkitMessages.PLAYER_ONLY, input -> Messages.getString("commands.player-only")).build();
|
||||
LiteCommandsBukkit.builder().commands(
|
||||
// @formatter:off
|
||||
new SGMCommand(),
|
||||
new LevelCommand(),
|
||||
new GameCommand(),
|
||||
new JailCommand())
|
||||
// @formatter:on
|
||||
// @formatter:off
|
||||
.invalidUsage(new InvalidArgsHandler())
|
||||
.missingPermission(new NoPermissionsHandler())
|
||||
.message(LiteBukkitMessages.PLAYER_NOT_FOUND, input -> Messages.getString("commands.invalid-player").replace("%player%", input))
|
||||
.message(LiteBukkitMessages.PLAYER_ONLY, input -> Messages.getString("commands.player-only"))
|
||||
// @formatter:on
|
||||
.build();
|
||||
}
|
||||
|
||||
private void registerGames() {
|
||||
|
|
|
@ -50,7 +50,12 @@ public class GameCommand {
|
|||
@Permission("sgm.games.start")
|
||||
void start(@Context Player player) {
|
||||
Minigame game = SGM.getInstance().getGameManager().findGame(player);
|
||||
game.start();
|
||||
if (game == null) {
|
||||
CustomPlayer cPlayer = new CustomPlayer(player);
|
||||
cPlayer.sendMessage(SGM.getInstance().getMessages().getString("sgm.game.not-found"));
|
||||
} else {
|
||||
game.start(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Execute(name = "team")
|
||||
|
|
30
src/main/java/xyz/twovb/sgm/commands/impl/JailCommand.java
Normal file
30
src/main/java/xyz/twovb/sgm/commands/impl/JailCommand.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package xyz.twovb.sgm.commands.impl;
|
||||
/*
|
||||
* Created by 2vb - 6/7/2024
|
||||
*/
|
||||
|
||||
import dev.rollczi.litecommands.annotations.argument.Arg;
|
||||
import dev.rollczi.litecommands.annotations.command.Command;
|
||||
import dev.rollczi.litecommands.annotations.context.Context;
|
||||
import dev.rollczi.litecommands.annotations.execute.Execute;
|
||||
import dev.rollczi.litecommands.annotations.permission.Permission;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.impl.capturethebrick.CTB;
|
||||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
@Command(name = "jail")
|
||||
@Permission("twovb.debug")
|
||||
public class JailCommand {
|
||||
|
||||
@Execute
|
||||
void command(@Context Player player, @Arg("target") Player target) {
|
||||
CTB game = (CTB) SGM.getInstance().getGameManager().findGame(player);
|
||||
if (game != null) {
|
||||
game.addPlayerToJail(target);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -23,7 +23,7 @@ public interface Minigame extends Listener {
|
|||
|
||||
void init(CommandSender owner, String world) throws IOException;
|
||||
|
||||
void start();
|
||||
void start(CommandSender sender);
|
||||
|
||||
void stop();
|
||||
|
||||
|
@ -53,11 +53,13 @@ public interface Minigame extends Listener {
|
|||
default World createGameWorld(String name, UUID id) throws IOException {
|
||||
File mapDir = new File(LevelManager.mapPath + name);
|
||||
String tempName = name + "_" + id;
|
||||
String worldPath = LevelManager.gamePath + "/worlds/";
|
||||
File tempDir = new File(worldPath + tempName);
|
||||
// String worldPath = LevelManager.gamePath + "/worlds/";
|
||||
File tempDir = new File(LevelManager.gameWorldsPath + tempName);
|
||||
// File tempDir = new File(worldPath + tempName);
|
||||
if (tempDir.mkdirs()) {
|
||||
FileUtils.copyDirectory(mapDir, tempDir);
|
||||
WorldCreator wc = new WorldCreator(worldPath + tempName, new NamespacedKey(SGM.getInstance(), tempName));
|
||||
WorldCreator wc = new WorldCreator(LevelManager.gameWorldsPath + tempName, new NamespacedKey(SGM.getInstance(), tempName));
|
||||
// WorldCreator wc = new WorldCreator(worldPath + tempName, new NamespacedKey(SGM.getInstance(), tempName));
|
||||
return wc.createWorld();
|
||||
} else {
|
||||
return null;
|
||||
|
|
|
@ -43,7 +43,7 @@ public class TestGame implements Minigame {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
public void start(CommandSender sender) {
|
||||
if (state == GameState.READY) {
|
||||
state = GameState.STARTED;
|
||||
sendMessageToAllPlayers("The game has started!");
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
|||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.Sidebar;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.component.ComponentSidebarLayout;
|
||||
|
@ -32,14 +33,18 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.GameManager;
|
||||
import xyz.twovb.sgm.games.Minigame;
|
||||
import xyz.twovb.sgm.games.impl.capturethebrick.events.PlayerJailedEvent;
|
||||
import xyz.twovb.sgm.levels.LevelManager;
|
||||
import xyz.twovb.toolbox.api.CustomPlayer;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
import xyz.twovb.toolbox.utils.CustomLogger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -49,13 +54,19 @@ import java.util.*;
|
|||
public class CTB implements Minigame {
|
||||
|
||||
final static String name = "CaptureTheBrick";
|
||||
final static FileConfiguration messages = SGM.getInstance().getConfigManager().loadConfig("games/" + name.toLowerCase() + "/messages.yml");
|
||||
private final UUID uuid;
|
||||
private final ArrayList<Location> redBrickSpawns = new ArrayList<Location>();
|
||||
private final ArrayList<Location> blueBrickSpawns = new ArrayList<Location>();
|
||||
private final ArrayList<Location> redSpawnArea = new ArrayList<Location>();
|
||||
private final ArrayList<Location> blueSpawnArea = new ArrayList<Location>();
|
||||
private final FileConfiguration messages;
|
||||
// private final FileConfiguration messages;
|
||||
private final ArrayList<Player> players = new ArrayList<Player>();
|
||||
private final HashMap<Player, CtbData.PlayerState> playerStateMap = new HashMap<>();
|
||||
ScoreboardTeam redTeam;
|
||||
ScoreboardTeam blueTeam;
|
||||
private Location redJail;
|
||||
private Location blueJail;
|
||||
private World gameWorld;
|
||||
private GameState state;
|
||||
private int bricks;
|
||||
|
@ -63,8 +74,6 @@ public class CTB implements Minigame {
|
|||
private int boundsLevel;
|
||||
private Location spawnLoc;
|
||||
private TeamManager teamManager;
|
||||
private ScoreboardTeam redTeam;
|
||||
private ScoreboardTeam blueTeam;
|
||||
private Sidebar sb;
|
||||
private SidebarAnimation<Component> headerAnimation;
|
||||
private ComponentSidebarLayout layout;
|
||||
|
@ -75,7 +84,11 @@ public class CTB implements Minigame {
|
|||
public CTB() {
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.state = GameState.PRESTART;
|
||||
this.messages = SGM.getInstance().getConfigManager().loadConfig("games/" + name.toLowerCase() + "/messages.yml");
|
||||
// this.messages = SGM.getInstance().getConfigManager().loadConfig("games/" + name.toLowerCase() + "/messages.yml");
|
||||
}
|
||||
|
||||
public static FileConfiguration getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public void init(CommandSender owner, String world) throws IOException {
|
||||
|
@ -84,7 +97,7 @@ public class CTB implements Minigame {
|
|||
gameWorld.setAutoSave(false);
|
||||
if (applyOptions(world)) {
|
||||
this.owner = owner;
|
||||
teamManager = SGM.getInstance().getScoreboardLibrary().createTeamManager();
|
||||
this.teamManager = SGM.getInstance().getScoreboardLibrary().createTeamManager();
|
||||
this.redTeam = teamManager.createIfAbsent("red_team");
|
||||
this.blueTeam = teamManager.createIfAbsent("blue_team");
|
||||
Bukkit.getPluginManager().registerEvents(this, SGM.getInstance());
|
||||
|
@ -105,8 +118,10 @@ public class CTB implements Minigame {
|
|||
return Component.text(time, NamedTextColor.GRAY);
|
||||
})
|
||||
.addBlankLine()
|
||||
.addDynamicLine(() -> ChatUtils.translate("<red><bold>Red: " + getBrickCount(redTeam)))
|
||||
.addDynamicLine(() -> ChatUtils.translate("<blue><bold>Blue: " + getBrickCount(blueTeam)))
|
||||
// .addDynamicLine(() -> ChatUtils.translate("<red><bold>Red: " + getBrickCount(redTeam)))
|
||||
// .addDynamicLine(() -> ChatUtils.translate("<blue><bold>Blue: " + getBrickCount(blueTeam)))
|
||||
.addDynamicLine(() -> ChatUtils.translate("<red>Red: <bold>" + getBrickCount(redTeam)))
|
||||
.addDynamicLine(() -> ChatUtils.translate("<blue>Blue: <bold>" + getBrickCount(blueTeam)))
|
||||
.addBlankLine()
|
||||
.build();
|
||||
// @formatter:on
|
||||
|
@ -116,7 +131,10 @@ public class CTB implements Minigame {
|
|||
|
||||
// Ready
|
||||
state = GameState.READY;
|
||||
owner.sendMessage(ChatUtils.translate(messages.getString("system.game.ready").replace("%game%", name)));
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
CustomPlayer customPlayer = new CustomPlayer(player);
|
||||
customPlayer.sendMessage(messages.getString("system.game.ready").replace("%game%", name));
|
||||
}
|
||||
} else {
|
||||
owner.sendMessage(ChatUtils.translate(messages.getString("system.game.failed").replace("%cause%", "to load options.")));
|
||||
this.stop();
|
||||
|
@ -133,14 +151,51 @@ public class CTB implements Minigame {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (checkStart()) {
|
||||
public void onTick() {
|
||||
try {
|
||||
headerAnimation.nextFrame();
|
||||
layout.apply(sb);
|
||||
} catch (IllegalStateException ignored) {
|
||||
}
|
||||
|
||||
for (Player player : gameWorld.getPlayers()) {
|
||||
if (!players.contains(player)) {
|
||||
// for (Player gamePlayer : players) {
|
||||
// gamePlayer.hidePlayer(SGM.getInstance(), player);
|
||||
// }
|
||||
sendMessageToAllPlayers(player.getName() + " IS A IMPOSTER");
|
||||
}
|
||||
}
|
||||
for (Player player : players) {
|
||||
Location playerLoc = player.getLocation();
|
||||
Location blockCheck = new Location(gameWorld, playerLoc.getBlockX(), territoryLevel, playerLoc.getBlockZ());
|
||||
Block territoryCheck = gameWorld.getBlockAt(blockCheck);
|
||||
switch (territoryCheck.getType()) {
|
||||
case RED_CONCRETE:
|
||||
player.sendActionBar(ChatUtils.translate("<red><bold>ʀᴇᴅ ᴛᴇʀʀɪᴛᴏʀʏ"));
|
||||
break;
|
||||
case BLUE_CONCRETE:
|
||||
player.sendActionBar(ChatUtils.translate("<blue><bold>ʙʟᴜᴇ ᴛᴇʀʀɪᴛᴏʀʏ"));
|
||||
break;
|
||||
case WHITE_CONCRETE:
|
||||
player.sendActionBar(ChatUtils.translate("<gray><bold>ɴᴇᴜᴛʀᴀʟ"));
|
||||
break;
|
||||
default:
|
||||
player.sendActionBar(ChatUtils.translate("<dark_gray><bold>???"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(CommandSender sender) {
|
||||
if (checkStart(sender)) {
|
||||
for (Player player : players) {
|
||||
player.teleport(this.spawnLoc);
|
||||
sb.addPlayer(player);
|
||||
playerStateMap.put(player, CtbData.PlayerState.Free);
|
||||
}
|
||||
for (int i = 1; i <= this.bricks; i++) {
|
||||
SGM.getInstance().getCLogger().log(i);
|
||||
for (int i = 0; i <= this.bricks - 1; i++) {
|
||||
placeBrick(redBrickSpawns.get(i), redTeam);
|
||||
placeBrick(blueBrickSpawns.get(i), blueTeam);
|
||||
}
|
||||
|
@ -149,15 +204,23 @@ public class CTB implements Minigame {
|
|||
|
||||
state = GameState.STARTED;
|
||||
sendMessageToAllPlayers("The game has started!");
|
||||
|
||||
CustomLogger logger = SGM.getInstance().getCLogger();
|
||||
|
||||
for (ScoreboardTeam team : teamManager.teams()) {
|
||||
logger.log(team.name());
|
||||
logger.log(team.defaultDisplay().entries());
|
||||
logger.log(team.teamManager().players());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we should be starting rn
|
||||
private boolean checkStart() {
|
||||
private boolean checkStart(CommandSender sender) {
|
||||
if (state != GameState.READY) return false;
|
||||
for (Player player : players) {
|
||||
if (!redTeam.teamManager().players().contains(player) && !blueTeam.teamManager().players().contains(player)) {
|
||||
this.owner.sendMessage("All players need to be on a team!");
|
||||
if (!teamManager.players().contains(player)) {
|
||||
sender.sendMessage("All players need to be on a team!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -190,22 +253,6 @@ public class CTB implements Minigame {
|
|||
Bukkit.getScheduler().cancelTask(this.taskId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
for (Player player : gameWorld.getPlayers()) {
|
||||
if (!players.contains(player)) {
|
||||
sendMessageToAllPlayers(player.getName() + " IS A IMPOSTER");
|
||||
}
|
||||
}
|
||||
if (state == GameState.STARTED && players.size() <= 1) {
|
||||
this.stop();
|
||||
}
|
||||
try {
|
||||
headerAnimation.nextFrame();
|
||||
layout.apply(sb);
|
||||
} catch (IllegalStateException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(Player player) {
|
||||
|
@ -248,6 +295,73 @@ public class CTB implements Minigame {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!players.contains(player)) return; // Check if player is in your list of tracked players
|
||||
if (this.state != GameState.STARTED) return; // Check if the game state is started
|
||||
|
||||
Location from = event.getFrom();
|
||||
Location to = event.getTo();
|
||||
|
||||
if (from.getBlockX() == to.getBlockX() && from.getBlockZ() == to.getBlockZ()) {
|
||||
return; // Player hasn't moved block coordinates, ignore
|
||||
}
|
||||
|
||||
if (playerStateMap.get(player) != CtbData.PlayerState.Jailed) return; // Check player state
|
||||
|
||||
Location fake = new Location(gameWorld, 0, -1, 0); // Your 'fake' location
|
||||
|
||||
// Calculate distance squared from 'fake' location to player's current location
|
||||
double distanceSquared = fake.distanceSquared(player.getLocation());
|
||||
|
||||
// Check if player is outside the 3 block radius
|
||||
if (distanceSquared > 9) { // 9 is 3 squared (3*3)
|
||||
// Teleport player back to 'fake' location
|
||||
player.teleport(fake);
|
||||
}
|
||||
}
|
||||
|
||||
// @EventHandler
|
||||
// void onPlayerMove(PlayerMoveEvent event) {
|
||||
// if (!(event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ())) return;
|
||||
// Player player = event.getPlayer();
|
||||
// if (!players.contains(player)) return;
|
||||
// if (this.state != GameState.STARTED) return;
|
||||
// if (playerStateMap.get(player) != CtbData.PlayerState.Jailed) return;
|
||||
// Location fake = new Location(gameWorld, 0, -1, 0);
|
||||
// double check = fake.distanceSquared(player.getLocation());
|
||||
// player.sendMessage(String.valueOf(check));
|
||||
// if (check >= 15) {
|
||||
// player.teleport(player.getLocation());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
@EventHandler
|
||||
void onPlayerJail(PlayerJailedEvent event) {
|
||||
CustomPlayer player = new CustomPlayer(event.getJailed());
|
||||
player.sendMessage(messages.getString("system.player.jail.info"));
|
||||
for (String teamMembers : getTeam(player.player()).defaultDisplay().entries()) {
|
||||
Player teamPlayer = Bukkit.getServer().getPlayerExact(teamMembers);
|
||||
CustomPlayer teamMember = new CustomPlayer(teamPlayer);
|
||||
SGM.getInstance().getCLogger().log(teamMember.player().getName());
|
||||
if (teamMember == player) continue;
|
||||
teamMember.sendMessage(LegacyComponentSerializer.legacyAmpersand().serialize(event.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayerToJail(Player player) {
|
||||
playerStateMap.replace(player, CtbData.PlayerState.Free, CtbData.PlayerState.Jailed);
|
||||
PlayerJailedEvent jailedEvent = new PlayerJailedEvent(player);
|
||||
jailedEvent.callEvent();
|
||||
// CustomPlayer cPlayer = new CustomPlayer(player);
|
||||
// cPlayer.sendMessage(messages.getString("system.player.jail.info"));
|
||||
}
|
||||
|
||||
public void freePlayerFromJail(Player player) {
|
||||
playerStateMap.replace(player, CtbData.PlayerState.Jailed, CtbData.PlayerState.Free);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> getPlayers() {
|
||||
return players;
|
||||
|
@ -273,21 +387,28 @@ public class CTB implements Minigame {
|
|||
return gameWorld;
|
||||
}
|
||||
|
||||
|
||||
public void addPlayerToTeam(Player player, boolean isRedTeam) {
|
||||
//TODO: make this shit fuckin better bor
|
||||
if (isRedTeam) {
|
||||
redTeam.defaultDisplay().addEntry(player.getName());
|
||||
} else {
|
||||
public void addPlayerToTeam(Player player, CtbData.Teams team) {
|
||||
if (team.equals(CtbData.Teams.Blue)) {
|
||||
blueTeam.defaultDisplay().addEntry(player.getName());
|
||||
} else if (team.equals(CtbData.Teams.Red)) {
|
||||
redTeam.defaultDisplay().addEntry(player.getName());
|
||||
}
|
||||
teamManager.addPlayer(player);
|
||||
this.teamManager.addPlayer(player);
|
||||
}
|
||||
|
||||
public void removePlayerFromTeams(Player player) {
|
||||
redTeam.defaultDisplay().removeEntry(player.getName());
|
||||
blueTeam.defaultDisplay().removeEntry(player.getName());
|
||||
teamManager.removePlayer(player);
|
||||
this.teamManager.removePlayer(player);
|
||||
}
|
||||
|
||||
public ScoreboardTeam getTeam(Player player) {
|
||||
for (ScoreboardTeam team : teamManager.teams()) {
|
||||
if (team.defaultDisplay().entries().contains(player.getName())) {
|
||||
return team;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void placeBrick(Location location, ScoreboardTeam team) {
|
||||
|
@ -298,7 +419,6 @@ public class CTB implements Minigame {
|
|||
if (team.equals(blueTeam)) {
|
||||
brick.setType(Material.BLUE_WOOL);
|
||||
}
|
||||
// SGM.getInstance().getCLogger().log("Placed " + brick.getType() + " at " + location);
|
||||
}
|
||||
|
||||
private void setupTeamDisplay(ScoreboardTeam team, String displayName, NamedTextColor color) {
|
||||
|
@ -388,6 +508,8 @@ public class CTB implements Minigame {
|
|||
if (team != null) {
|
||||
List<String> brickSpawns = team.getStringList("brickSpawns");
|
||||
List<String> playerSpawnArea = team.getStringList("playerSpawnArea");
|
||||
this.redJail = parseString(teamName + "jail");
|
||||
this.blueJail = parseString(teamName + "jail");
|
||||
|
||||
// Get brick locations
|
||||
if (brickSpawns.size() >= this.bricks) {
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package xyz.twovb.sgm.games.impl.capturethebrick;
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
public class CtbData {
|
||||
|
||||
public enum PlayerState {
|
||||
Free, Invulnerable, Tagged, Jailed
|
||||
}
|
||||
|
||||
public enum Teams {
|
||||
Red, Blue
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package xyz.twovb.sgm.games.impl.capturethebrick.events;
|
||||
/*
|
||||
* Created by 2vb - 7/7/2024
|
||||
*/
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.twovb.sgm.games.impl.capturethebrick.CTB;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
public class PlayerJailedEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
private final Player jailed;
|
||||
private boolean isCancelled;
|
||||
|
||||
private Component message;
|
||||
|
||||
public PlayerJailedEvent(Player jailed) {
|
||||
this.jailed = jailed;
|
||||
this.isCancelled = false;
|
||||
this.message = ChatUtils.translate(CTB.getMessages().getString("system.player.jail.notify").replace("%player%", jailed.getName()));
|
||||
}
|
||||
|
||||
public Player getJailed() {
|
||||
return this.jailed;
|
||||
}
|
||||
|
||||
public Component getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(Component message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.isCancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.isCancelled = cancelled;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -12,6 +12,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.impl.capturethebrick.CTB;
|
||||
import xyz.twovb.sgm.games.impl.capturethebrick.CtbData;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
|
@ -52,10 +53,10 @@ public class TeamGui {
|
|||
ItemStack clickedItem = event.getCurrentItem();
|
||||
CTB game = (CTB) SGM.getInstance().getGameManager().findGame(player);
|
||||
if (clickedItem.getType().equals(Material.RED_WOOL)) {
|
||||
game.addPlayerToTeam(target, true);
|
||||
game.addPlayerToTeam(target, CtbData.Teams.Red);
|
||||
game.sendMessageToAllPlayers(target.getName() + " RED");
|
||||
} else if (clickedItem.getType().equals(Material.BLUE_WOOL)) {
|
||||
game.addPlayerToTeam(target, false);
|
||||
game.addPlayerToTeam(target, CtbData.Teams.Blue);
|
||||
game.sendMessageToAllPlayers(target.getName() + " BLUE");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ public class LevelManager {
|
|||
|
||||
public static final String gamePath = SGM.getInstance().getDataFolder().getPath() + "/games/";
|
||||
|
||||
public static final String gameWorldsPath = gamePath + "worlds/";
|
||||
|
||||
public static final String mapPath = SGM.getInstance().getDataFolder().getPath() + "/maps/";
|
||||
|
||||
public HashMap<String, List<String>> enabledMaps = new HashMap<>();
|
||||
|
@ -196,6 +198,15 @@ public class LevelManager {
|
|||
enabledMaps.put(game, new ArrayList<>()); // Initialize an empty ArrayList for each game
|
||||
}
|
||||
|
||||
try {
|
||||
File gameWorldsDir = new File(gameWorldsPath);
|
||||
if (gameWorldsDir.exists()) {
|
||||
FileUtils.cleanDirectory(gameWorldsDir);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// Load levels from levelPath
|
||||
loadWorldDir(levelPath, LevelType.LEVEL);
|
||||
loadWorldDir(mapPath, LevelType.MAP);
|
||||
|
|
|
@ -5,3 +5,6 @@ system:
|
|||
player:
|
||||
join: "&7%player% has joined the game!"
|
||||
left: "&7%player% has left the game."
|
||||
jail:
|
||||
notify: "&7%player% has been jailed!"
|
||||
info: "&7You have been jailed! You can not leave until you get freed by a player or Jailbreak."
|
|
@ -13,6 +13,7 @@ teams:
|
|||
playerSpawnArea:
|
||||
- 0,0,0
|
||||
- 0,0,0
|
||||
jail: 0,0,0
|
||||
blue:
|
||||
brickSpawns:
|
||||
- 0,0,0
|
||||
|
@ -21,4 +22,5 @@ teams:
|
|||
# it will always teleport the player to the highest block.
|
||||
playerSpawnArea:
|
||||
- 0,0,0
|
||||
- 0,0,0
|
||||
- 0,0,0
|
||||
jail: 0,0,0
|
||||
|
|
Loading…
Reference in New Issue
Block a user