Finish applyOptions function and cleaned it up as well.
This commit is contained in:
parent
3589584e54
commit
a2ad900b5f
|
@ -14,6 +14,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
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.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
@ -23,18 +24,26 @@ 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.api.CustomPlayer;
|
||||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
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;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class CTB implements Minigame {
|
public class CTB implements Minigame {
|
||||||
|
|
||||||
final static String name = "CaptureTheBrick";
|
final static String name = "CaptureTheBrick";
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
private final List<Player> players;
|
private final List<Player> players;
|
||||||
private int bricks;
|
private final ArrayList<Location> redBrickSpawns = new ArrayList<Location>();
|
||||||
|
private final ArrayList<Location> blueBrickSpawns = new ArrayList<Location>();
|
||||||
|
private ArrayList<Location> redSpawnArea = new ArrayList<Location>();
|
||||||
|
private ArrayList<Location> blueSpawnArea = new ArrayList<Location>();
|
||||||
private World gameWorld;
|
private World gameWorld;
|
||||||
private GameState state;
|
private GameState state;
|
||||||
|
private int bricks;
|
||||||
|
private int territoryLevel;
|
||||||
|
private int boundsLevel;
|
||||||
|
|
||||||
public CTB() {
|
public CTB() {
|
||||||
this.uuid = UUID.randomUUID();
|
this.uuid = UUID.randomUUID();
|
||||||
|
@ -58,16 +67,32 @@ public class CTB implements Minigame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Location parseString(String string) {
|
||||||
|
String[] coords = string.trim().split(",");
|
||||||
|
if (coords.length == 3) {
|
||||||
|
return new Location(gameWorld, Integer.parseInt(coords[0]), Integer.parseInt(coords[1]), Integer.parseInt(coords[2]));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempts to load the game's options as a YamlConfiguration
|
||||||
|
// before processing each section in the same order as the file.
|
||||||
private boolean applyOptions() {
|
private boolean applyOptions() {
|
||||||
File configFile = new File(LevelManager.gamePath + name.toLowerCase() + "/options.yml");
|
File configFile = new File(LevelManager.gamePath + name.toLowerCase() + "/options.yml");
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
|
||||||
if (!configFile.exists()) {
|
// Set map information
|
||||||
SGM.getInstance().getCLogger().log("options.yml does not exist at " + configFile.getAbsolutePath());
|
ConfigurationSection mapInfoSection = config.getConfigurationSection("mapInfo");
|
||||||
|
if (mapInfoSection != null) {
|
||||||
|
this.bricks = mapInfoSection.getInt("brickCount");
|
||||||
|
this.territoryLevel = mapInfoSection.getInt("territory");
|
||||||
|
this.boundsLevel = mapInfoSection.getInt("boundary");
|
||||||
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process teams section
|
// Process team information
|
||||||
List<String> teamsToProcess = Arrays.asList("red", "blue");
|
List<String> teamsToProcess = Arrays.asList("red", "blue");
|
||||||
|
|
||||||
for (String teamName : teamsToProcess) {
|
for (String teamName : teamsToProcess) {
|
||||||
|
@ -76,50 +101,39 @@ public class CTB implements Minigame {
|
||||||
List<String> brickSpawns = team.getStringList("brickSpawns");
|
List<String> brickSpawns = team.getStringList("brickSpawns");
|
||||||
List<String> playerSpawnArea = team.getStringList("playerSpawnArea");
|
List<String> playerSpawnArea = team.getStringList("playerSpawnArea");
|
||||||
|
|
||||||
// Log or process team-specific values
|
// Get brick locations
|
||||||
SGM.getInstance().getCLogger().log(teamName + " Player Spawn Area: " + playerSpawnArea);
|
|
||||||
|
|
||||||
// Log each team's brick spawns
|
|
||||||
if (brickSpawns.size() >= bricks) {
|
if (brickSpawns.size() >= bricks) {
|
||||||
for (String brickSpawn : brickSpawns) {
|
for (String rawBrickLoc : brickSpawns) {
|
||||||
String[] coords = brickSpawn.split(",");
|
Location brickLoc = parseString(rawBrickLoc);
|
||||||
if (coords.length == 3) {
|
if (teamName.equals("red")) {
|
||||||
int x = Integer.parseInt(coords[0]);
|
this.redBrickSpawns.add(brickLoc);
|
||||||
int y = Integer.parseInt(coords[1]);
|
} else if (teamName.equals("blue")) {
|
||||||
int z = Integer.parseInt(coords[2]);
|
this.blueBrickSpawns.add(brickLoc);
|
||||||
// Now you have x, y, z coordinates to work with
|
|
||||||
placeBrick(new Location(gameWorld, x, y, z), teamName);
|
|
||||||
} else {
|
|
||||||
SGM.getInstance().getCLogger().error("Invalid brick spawn: " + coords[0]);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SGM.getInstance().getCLogger().error("Not enough brick spawns!");
|
SGM.getInstance().getCLogger().error("Invalid brick spawns. Please fix before trying again.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hopefully that works!
|
||||||
|
if (playerSpawnArea.size() == 2) {
|
||||||
|
for (String rawSpawnLoc : playerSpawnArea) {
|
||||||
|
Location spawnLoc = parseString(rawSpawnLoc);
|
||||||
|
if (teamName.equals("red")) {
|
||||||
|
this.redSpawnArea.add(spawnLoc);
|
||||||
|
} else if (teamName.equals("blue")) {
|
||||||
|
this.blueSpawnArea.add(spawnLoc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SGM.getInstance().getCLogger().error("Invalid spawn area. Please fix before trying again.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process terrainInfo section
|
|
||||||
ConfigurationSection terrainInfoSection = config.getConfigurationSection("terrainInfo");
|
|
||||||
if (terrainInfoSection != null) {
|
|
||||||
int territory = terrainInfoSection.getInt("territory");
|
|
||||||
int boundary = terrainInfoSection.getInt("boundary");
|
|
||||||
|
|
||||||
// Log or process terrainInfo values
|
|
||||||
SGM.getInstance().getCLogger().log("Territory: " + territory);
|
|
||||||
SGM.getInstance().getCLogger().log("Boundary: " + boundary);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Additional configuration values outside of teams and terrainInfo
|
|
||||||
String game = config.getString("game");
|
|
||||||
int brickCount = config.getInt("brickCount");
|
|
||||||
|
|
||||||
// Log or process additional configuration values
|
|
||||||
SGM.getInstance().getCLogger().log("Game: " + game);
|
|
||||||
SGM.getInstance().getCLogger().log("Brick Count: " + brickCount);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +171,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -220,7 +235,6 @@ public class CTB implements Minigame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(e.getFrom().getX() != e.getTo().getX() || e.getFrom().getZ() != e.getTo().getZ()) { // full block }
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick() {
|
public void onTick() {
|
||||||
if (state == GameState.STARTED && players.size() <= 1) {
|
if (state == GameState.STARTED && players.size() <= 1) {
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
package xyz.twovb.sgm.games.impl.capturethebrick;
|
|
||||||
/*
|
|
||||||
* Created by 2vb - 3/7/2024
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public interface CTBOptions {
|
|
||||||
int brickCount = 2;
|
|
||||||
ArrayList<Location> redBrickLocations = new ArrayList<Location>();
|
|
||||||
ArrayList<Location> blueBrickLocations = new ArrayList<Location>();
|
|
||||||
int territoryLevel = 1;
|
|
||||||
int boundaryLevel = 3;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,19 +1,23 @@
|
||||||
brickCount: 2
|
mapInfo:
|
||||||
|
brickCount: 2
|
||||||
|
territory: 1
|
||||||
|
boundary: 3
|
||||||
teams:
|
teams:
|
||||||
red:
|
red:
|
||||||
brickSpawns:
|
brickSpawns:
|
||||||
- 0,0,0
|
- 0,0,0
|
||||||
- 0,0,0
|
- 0,0,0
|
||||||
|
# The "y" coordinate does not matter for this value,
|
||||||
|
# it will always teleport the player to the highest block.
|
||||||
playerSpawnArea:
|
playerSpawnArea:
|
||||||
- 0,0
|
- 0,0,0
|
||||||
- 0,0
|
- 0,0,0
|
||||||
blue:
|
blue:
|
||||||
brickSpawns:
|
brickSpawns:
|
||||||
- 0,0,0
|
- 0,0,0
|
||||||
- 0,0,0
|
- 0,0,0
|
||||||
|
# The "y" coordinate does not matter for this value,
|
||||||
|
# it will always teleport the player to the highest block.
|
||||||
playerSpawnArea:
|
playerSpawnArea:
|
||||||
- 0,0
|
- 0,0,0
|
||||||
- 0,0
|
- 0,0,0
|
||||||
terrainInfo:
|
|
||||||
territory: 1
|
|
||||||
boundary: 3
|
|
Loading…
Reference in New Issue
Block a user