This commit is contained in:
parent
a2ad900b5f
commit
a99da2da56
|
@ -16,15 +16,11 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import xyz.twovb.sgm.SGM;
|
import xyz.twovb.sgm.SGM;
|
||||||
import xyz.twovb.sgm.games.GameManager;
|
import xyz.twovb.sgm.games.GameManager;
|
||||||
import xyz.twovb.sgm.games.Minigame;
|
import xyz.twovb.sgm.games.Minigame;
|
||||||
import xyz.twovb.sgm.levels.LevelManager;
|
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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -37,13 +33,15 @@ public class CTB implements Minigame {
|
||||||
private final List<Player> players;
|
private final List<Player> players;
|
||||||
private final ArrayList<Location> redBrickSpawns = new ArrayList<Location>();
|
private final ArrayList<Location> redBrickSpawns = new ArrayList<Location>();
|
||||||
private final ArrayList<Location> blueBrickSpawns = new ArrayList<Location>();
|
private final ArrayList<Location> blueBrickSpawns = new ArrayList<Location>();
|
||||||
private ArrayList<Location> redSpawnArea = new ArrayList<Location>();
|
private final ArrayList<Location> redSpawnArea = new ArrayList<Location>();
|
||||||
private ArrayList<Location> blueSpawnArea = new ArrayList<Location>();
|
private final ArrayList<Location> blueSpawnArea = new ArrayList<Location>();
|
||||||
private World gameWorld;
|
private World gameWorld;
|
||||||
private GameState state;
|
private GameState state;
|
||||||
private int bricks;
|
private int bricks;
|
||||||
private int territoryLevel;
|
private int territoryLevel;
|
||||||
private int boundsLevel;
|
private int boundsLevel;
|
||||||
|
private Location spawnLoc;
|
||||||
|
|
||||||
|
|
||||||
public CTB() {
|
public CTB() {
|
||||||
this.uuid = UUID.randomUUID();
|
this.uuid = UUID.randomUUID();
|
||||||
|
@ -53,18 +51,17 @@ public class CTB implements Minigame {
|
||||||
|
|
||||||
public void init(CommandSender owner, String world) throws IOException {
|
public void init(CommandSender owner, String world) throws IOException {
|
||||||
// Perform initialization logic here
|
// Perform initialization logic here
|
||||||
Bukkit.getPluginManager().registerEvents(this, SGM.getInstance());
|
|
||||||
gameWorld = createGameWorld(world, uuid);
|
gameWorld = createGameWorld(world, uuid);
|
||||||
gameWorld.setAutoSave(false);
|
gameWorld.setAutoSave(false);
|
||||||
try {
|
if (applyOptions(world)) {
|
||||||
if (applyOptions()) {
|
Bukkit.getPluginManager().registerEvents(this, SGM.getInstance());
|
||||||
state = GameState.READY;
|
state = GameState.READY;
|
||||||
owner.sendMessage("A new " + name + " instance with ID " + uuid + " has been created and is now ready!");
|
owner.sendMessage("A new " + name + " instance with ID " + uuid + " has been created and is now ready!");
|
||||||
}
|
} else {
|
||||||
} catch (Exception ex) {
|
owner.sendMessage("a");
|
||||||
owner.sendMessage(ChatUtils.translate(SGM.getInstance().getMessages().getString("sgm.game.cant-start")));
|
// owner.sendMessage(ChatUtils.translate(SGM.getInstance().getMessages().getString("sgm.game.cant-start")));
|
||||||
SGM.getInstance().getCLogger().error(ex.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Location parseString(String string) {
|
private Location parseString(String string) {
|
||||||
|
@ -78,8 +75,10 @@ public class CTB implements Minigame {
|
||||||
|
|
||||||
// Attempts to load the game's options as a YamlConfiguration
|
// Attempts to load the game's options as a YamlConfiguration
|
||||||
// before processing each section in the same order as the file.
|
// before processing each section in the same order as the file.
|
||||||
private boolean applyOptions() {
|
private boolean applyOptions(String worldName) {
|
||||||
File configFile = new File(LevelManager.gamePath + name.toLowerCase() + "/options.yml");
|
File configFile = new File(LevelManager.mapPath + worldName + "/sgm.yml");
|
||||||
|
SGM.getInstance().getCLogger().log(configFile.getPath());
|
||||||
|
SGM.getInstance().getCLogger().log(configFile.getAbsolutePath());
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
|
||||||
// Set map information
|
// Set map information
|
||||||
|
@ -88,7 +87,9 @@ public class CTB implements Minigame {
|
||||||
this.bricks = mapInfoSection.getInt("brickCount");
|
this.bricks = mapInfoSection.getInt("brickCount");
|
||||||
this.territoryLevel = mapInfoSection.getInt("territory");
|
this.territoryLevel = mapInfoSection.getInt("territory");
|
||||||
this.boundsLevel = mapInfoSection.getInt("boundary");
|
this.boundsLevel = mapInfoSection.getInt("boundary");
|
||||||
|
this.spawnLoc = parseString(mapInfoSection.getString("spawn"));
|
||||||
} else {
|
} else {
|
||||||
|
SGM.getInstance().getCLogger().error("Invalid map info. Please fix before trying again.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,12 +132,33 @@ public class CTB implements Minigame {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
SGM.getInstance().getCLogger().error("Invalid teams. Please fix before trying again.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
if (state == GameState.READY) {
|
||||||
|
state = GameState.STARTED;
|
||||||
|
sendMessageToAllPlayers("The game has started!");
|
||||||
|
for (Player player : players) {
|
||||||
|
player.teleport(this.spawnLoc);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < bricks; i++) {
|
||||||
|
for (Location brickLoc : redBrickSpawns) {
|
||||||
|
placeBrick(brickLoc, "red");
|
||||||
|
}
|
||||||
|
for (Location brickLoc : blueBrickSpawns) {
|
||||||
|
placeBrick(brickLoc, "blue");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskTimer(SGM.getInstance(), this::onTick, 0L, 1L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void placeBrick(Location location, String team) {
|
private void placeBrick(Location location, String team) {
|
||||||
Block brick = location.getBlock();
|
Block brick = location.getBlock();
|
||||||
if (Objects.equals(team, "red")) {
|
if (Objects.equals(team, "red")) {
|
||||||
|
@ -148,18 +170,6 @@ public class CTB implements Minigame {
|
||||||
SGM.getInstance().getCLogger().log("Placed " + brick.getType() + " at " + location);
|
SGM.getInstance().getCLogger().log("Placed " + brick.getType() + " at " + location);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start() {
|
|
||||||
if (state == GameState.READY) {
|
|
||||||
state = GameState.STARTED;
|
|
||||||
sendMessageToAllPlayers("The game has started!");
|
|
||||||
for (Player player : players) {
|
|
||||||
player.teleport(player.getWorld().getSpawnLocation());
|
|
||||||
}
|
|
||||||
Bukkit.getScheduler().runTaskTimer(SGM.getInstance(), this::onTick, 0L, 1L);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
// Stop game logic
|
// Stop game logic
|
||||||
|
@ -172,13 +182,16 @@ public class CTB implements Minigame {
|
||||||
players.clear(); // Clear player list
|
players.clear(); // Clear player list
|
||||||
GameManager.getActiveGames().remove(uuid);
|
GameManager.getActiveGames().remove(uuid);
|
||||||
HandlerList.unregisterAll(this);
|
HandlerList.unregisterAll(this);
|
||||||
|
for (Player player : gameWorld.getPlayers()) {
|
||||||
|
player.teleport(Bukkit.getServer().getWorlds().get(0).getSpawnLocation());
|
||||||
|
}
|
||||||
|
Bukkit.unloadWorld(gameWorld, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPlayer(Player player) {
|
public void addPlayer(Player player) {
|
||||||
players.add(player);
|
players.add(player);
|
||||||
player.teleport(gameWorld.getSpawnLocation());
|
player.teleport(this.spawnLoc);
|
||||||
player.teleport(new Location(gameWorld, 0, 0, 0));
|
|
||||||
sendMessageToAllPlayers(player.getName() + " has joined the game!");
|
sendMessageToAllPlayers(player.getName() + " has joined the game!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,15 +238,15 @@ public class CTB implements Minigame {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
// @EventHandler
|
||||||
void onPlayerMove(PlayerMoveEvent event) {
|
// void onPlayerMove(PlayerMoveEvent event) {
|
||||||
Player player = event.getPlayer();
|
// Player player = event.getPlayer();
|
||||||
CustomPlayer cPlayer = new CustomPlayer(player);
|
// CustomPlayer cPlayer = new CustomPlayer(player);
|
||||||
cPlayer.sendMessage("move");
|
// cPlayer.sendMessage("move");
|
||||||
if (event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ()) {
|
// if (event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ()) {
|
||||||
cPlayer.sendMessage("move full block");
|
// cPlayer.sendMessage("move full block");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick() {
|
public void onTick() {
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
package xyz.twovb.sgm.levels;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Created by 2vb - 4/6/2024
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.bukkit.World;
|
|
||||||
|
|
||||||
public interface Level {
|
|
||||||
String getName();
|
|
||||||
|
|
||||||
World getWorld();
|
|
||||||
}
|
|
|
@ -34,7 +34,8 @@ public class LevelManager {
|
||||||
|
|
||||||
public HashMap<String, List<String>> enabledMaps = new HashMap<>();
|
public HashMap<String, List<String>> enabledMaps = new HashMap<>();
|
||||||
|
|
||||||
private static void loadWorld(String worldName, LevelType type) {
|
// This isn't really used rn but I can't be bothered to do anything thb
|
||||||
|
public void loadWorld(String worldName, LevelType type) {
|
||||||
// Check if the world is already loaded
|
// Check if the world is already loaded
|
||||||
String key = type.toString().toLowerCase() + "_" + worldName;
|
String key = type.toString().toLowerCase() + "_" + worldName;
|
||||||
WorldCreator wc = null;
|
WorldCreator wc = null;
|
||||||
|
@ -130,6 +131,9 @@ public class LevelManager {
|
||||||
player.teleport(Bukkit.getServer().getWorlds().get(0).getSpawnLocation());
|
player.teleport(Bukkit.getServer().getWorlds().get(0).getSpawnLocation());
|
||||||
}
|
}
|
||||||
if (!Bukkit.isTickingWorlds() && Bukkit.getServer().unloadWorld(world, true)) {
|
if (!Bukkit.isTickingWorlds() && Bukkit.getServer().unloadWorld(world, true)) {
|
||||||
|
if (mapDir.exists()) {
|
||||||
|
FileUtils.deleteDirectory(mapDir);
|
||||||
|
}
|
||||||
FileUtils.copyDirectory(levelDir, mapDir);
|
FileUtils.copyDirectory(levelDir, mapDir);
|
||||||
FileUtils.delete(new File(mapDir + "/uid.dat"));
|
FileUtils.delete(new File(mapDir + "/uid.dat"));
|
||||||
loadWorld(name, LevelType.LEVEL);
|
loadWorld(name, LevelType.LEVEL);
|
||||||
|
@ -158,10 +162,22 @@ public class LevelManager {
|
||||||
return LevelResult.UNKNOWN;
|
return LevelResult.UNKNOWN;
|
||||||
}
|
}
|
||||||
Location location = new Location(world, 0.5, 0, 0.5);
|
Location location = new Location(world, 0.5, 0, 0.5);
|
||||||
Block block = location.subtract(0, 2, 0).getBlock();
|
// Create a 3x3 stone platform
|
||||||
block.setType(Material.STONE);
|
for (int x = -1; x <= 1; x++) {
|
||||||
|
for (int z = -1; z <= 1; z++) {
|
||||||
|
Location blockLocation = location.clone().add(x, -2, z);
|
||||||
|
Block block = blockLocation.getBlock();
|
||||||
|
block.setType(Material.STONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Block block = location.subtract(0, 2, 0).getBlock();
|
||||||
|
// block.setType(Material.STONE);
|
||||||
world.setSpawnLocation(location);
|
world.setSpawnLocation(location);
|
||||||
world.setSpawnFlags(false, false);
|
world.setSpawnFlags(false, false);
|
||||||
|
world.setGameRule(GameRule.KEEP_INVENTORY, true);
|
||||||
|
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
||||||
|
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
||||||
|
world.setTime(1000);
|
||||||
genDataFile(level, name, game.toLowerCase());
|
genDataFile(level, name, game.toLowerCase());
|
||||||
return LevelResult.SUCCESS;
|
return LevelResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ mapInfo:
|
||||||
brickCount: 2
|
brickCount: 2
|
||||||
territory: 1
|
territory: 1
|
||||||
boundary: 3
|
boundary: 3
|
||||||
|
spawn: 0,0,0
|
||||||
teams:
|
teams:
|
||||||
red:
|
red:
|
||||||
brickSpawns:
|
brickSpawns:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user