Dedicated messages file.

This commit is contained in:
2vb 2024-07-04 19:57:48 -07:00
parent a99da2da56
commit ab94e7f557
5 changed files with 21 additions and 18 deletions

View File

@ -9,7 +9,7 @@ import org.bukkit.NamespacedKey;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import xyz.twovb.sgm.SGM; import xyz.twovb.sgm.SGM;
@ -63,6 +63,7 @@ public interface Minigame extends Listener {
} }
} }
enum GameState { enum GameState {
PRESTART, READY, STARTED, ENDING PRESTART, READY, STARTED, ENDING
} }

View File

@ -11,6 +11,7 @@ import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
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;
@ -21,6 +22,7 @@ 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.utils.ChatUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -31,6 +33,8 @@ 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 List<Player> redTeam;
private List<Player> blueTeam;
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 final ArrayList<Location> redSpawnArea = new ArrayList<Location>(); private final ArrayList<Location> redSpawnArea = new ArrayList<Location>();
@ -41,12 +45,14 @@ public class CTB implements Minigame {
private int territoryLevel; private int territoryLevel;
private int boundsLevel; private int boundsLevel;
private Location spawnLoc; private Location spawnLoc;
private FileConfiguration messages;
public CTB() { public CTB() {
this.uuid = UUID.randomUUID(); this.uuid = UUID.randomUUID();
this.state = GameState.PRESTART; this.state = GameState.PRESTART;
this.players = new ArrayList<>(); this.players = new ArrayList<>();
this.messages = SGM.getInstance().getConfigManager().loadConfig("games/" + name.toLowerCase() + "/messages.yml");
} }
public void init(CommandSender owner, String world) throws IOException { public void init(CommandSender owner, String world) throws IOException {
@ -56,12 +62,11 @@ public class CTB implements Minigame {
if (applyOptions(world)) { if (applyOptions(world)) {
Bukkit.getPluginManager().registerEvents(this, SGM.getInstance()); 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(ChatUtils.translate(messages.getString("system.game.ready").replace("%game%", name)));
} else { } else {
owner.sendMessage("a"); owner.sendMessage(ChatUtils.translate(messages.getString("system.game.failed").replace("%cause%", "to load options.")));
// owner.sendMessage(ChatUtils.translate(SGM.getInstance().getMessages().getString("sgm.game.cant-start"))); Bukkit.getServer().unloadWorld(gameWorld, false);
} }
} }
private Location parseString(String string) { private Location parseString(String string) {
@ -172,6 +177,7 @@ public class CTB implements Minigame {
@Override @Override
public void stop() { public void stop() {
// TODO: make it wait before unloading world
// Stop game logic // Stop game logic
state = GameState.ENDING; state = GameState.ENDING;
Player winner; Player winner;
@ -192,7 +198,7 @@ public class CTB implements Minigame {
public void addPlayer(Player player) { public void addPlayer(Player player) {
players.add(player); players.add(player);
player.teleport(this.spawnLoc); player.teleport(this.spawnLoc);
sendMessageToAllPlayers(player.getName() + " has joined the game!"); sendMessageToAllPlayers(messages.getString("system.player.join").replace("%player%", player.getName()));
} }
@Override @Override
@ -238,16 +244,6 @@ public class CTB implements Minigame {
return state; return state;
} }
// @EventHandler
// void onPlayerMove(PlayerMoveEvent event) {
// Player player = event.getPlayer();
// CustomPlayer cPlayer = new CustomPlayer(player);
// cPlayer.sendMessage("move");
// if (event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ()) {
// cPlayer.sendMessage("move full block");
// }
// }
@Override @Override
public void onTick() { public void onTick() {
if (state == GameState.STARTED && players.size() <= 1) { if (state == GameState.STARTED && players.size() <= 1) {

View File

@ -130,6 +130,7 @@ public class LevelManager {
// This is probably gonna be funny later // This is probably gonna be funny later
player.teleport(Bukkit.getServer().getWorlds().get(0).getSpawnLocation()); player.teleport(Bukkit.getServer().getWorlds().get(0).getSpawnLocation());
} }
// TODO: make better
if (!Bukkit.isTickingWorlds() && Bukkit.getServer().unloadWorld(world, true)) { if (!Bukkit.isTickingWorlds() && Bukkit.getServer().unloadWorld(world, true)) {
if (mapDir.exists()) { if (mapDir.exists()) {
FileUtils.deleteDirectory(mapDir); FileUtils.deleteDirectory(mapDir);

View File

@ -0,0 +1,7 @@
system:
game:
ready: "&7A new %game% game has started and can now be joined!"
failed: "&7%game% failed %cause%"
player:
join: "&7%player% has joined the game!"
left: "&7%player% has left the game."

View File

@ -16,8 +16,6 @@ sgm:
cant-start: "&7Game couldn't be started!" cant-start: "&7Game couldn't be started!"
cant-join: "&7Could not join this game!" cant-join: "&7Could not join this game!"
started: "&7Game has started!" started: "&7Game has started!"
joined: "&7%player% has joined the game!"
left: "&7%player% has left the game."
win: "&7Congratulations to %winner% for winning!" win: "&7Congratulations to %winner% for winning!"
level: level:
new: "&7A level with the name %level% has been created." new: "&7A level with the name %level% has been created."