Skip to content

Commit

Permalink
feat: More verbose logging and stores all relevant logs per game
Browse files Browse the repository at this point in the history
  • Loading branch information
utfunderscore committed Mar 13, 2024
1 parent 1177ab1 commit 49c9b00
Show file tree
Hide file tree
Showing 90 changed files with 511 additions and 200 deletions.
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ gradle-app.setting
.idea/*
gradle/*

Core/build/*
Development/build/*
Core/build/

Development/build/
Development/run/*
Core/run/*
*/build/*
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import com.readutf.inari.core.arena.marker.Marker;
import com.readutf.inari.core.arena.marker.MarkerScanner;
import com.readutf.inari.core.logging.GameLoggerFactory;
import com.readutf.inari.core.logging.Logger;
import com.readutf.inari.core.logging.LoggerManager;
import com.readutf.inari.core.logging.LoggerFactory;
import com.readutf.inari.core.utils.WorldCuboid;
import org.bukkit.Chunk;
import org.bukkit.World;
Expand All @@ -16,7 +17,7 @@

public class TileEntityScanner implements MarkerScanner {

private static Logger logger = LoggerManager.getInstance().getLogger(TileEntityScanner.class);
private static Logger logger = LoggerFactory.getLogger(TileEntityScanner.class);

@Override
public List<Marker> scan(WorldCuboid worldCuboid) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.readutf.inari.core.arena.stores.gridloader;

import com.google.gson.Gson;
import com.mojang.authlib.minecraft.client.ObjectMapper;
import com.readutf.inari.core.arena.ActiveArena;
import com.readutf.inari.core.arena.stores.gridloader.grid.GridPositionManager;
import com.readutf.inari.core.arena.Arena;
import com.readutf.inari.core.arena.ArenaManager;
import com.readutf.inari.core.arena.exceptions.ArenaLoadException;
import com.readutf.inari.core.arena.exceptions.ArenaStoreException;
import com.readutf.inari.core.arena.marker.MarkerScanner;
import com.readutf.inari.core.arena.meta.ArenaMeta;
import com.readutf.inari.core.arena.stores.gridloader.grid.GridPositionManager;
import com.readutf.inari.core.arena.stores.gridloader.loader.ArenaBuildLoader;
import com.readutf.inari.core.game.Game;
import com.readutf.inari.core.logging.Logger;
import com.readutf.inari.core.logging.LoggerManager;
import com.readutf.inari.core.utils.*;
import com.readutf.inari.core.logging.LoggerFactory;
import com.readutf.inari.core.utils.Cuboid;
import com.readutf.inari.core.utils.Position;
import com.readutf.inari.core.utils.WorldCuboid;
import com.readutf.inari.core.utils.WorldEditUtils;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEdit;
Expand All @@ -30,7 +31,6 @@
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.generator.WorldInfo;
import org.bukkit.material.MaterialData;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -51,7 +51,7 @@ public class SchematicArenaManager extends ArenaManager {

private @Getter static final WorldCreator worldCreator;
private @Getter static final World world;
private static Logger logger = LoggerManager.getInstance().getLogger(SchematicArenaManager.class);
private static Logger logger = LoggerFactory.getLogger(SchematicArenaManager.class);

static {

Expand Down Expand Up @@ -90,7 +90,7 @@ public SchematicArenaManager(JavaPlugin javaPlugin, MarkerScanner markerScanner,
public void save(WorldCuboid worldCuboid, Arena arena) throws ArenaStoreException {

File arenaFolder = new File(arenasFolder, arena.getName());
if (arenaFolder.mkdirs()) logger.fine("Created arena folder");
if (arenaFolder.mkdirs()) logger.info("Created arena folder");

arena = arena.makeRelative();

Expand Down Expand Up @@ -158,7 +158,7 @@ public void unload(Arena arena) {

gridPositionManager.free(new GridPositionManager.GridSpace((int) min.getX(), (int) min.getZ()));

logger.fine("Unloaded arena " + arena.getName());
logger.info("Unloaded arena " + arena.getName());
}

public Arena loadArena(ArenaMeta arenaMeta) throws IOException, WorldEditException {
Expand Down Expand Up @@ -210,7 +210,7 @@ private File setupArenasFolder(File pluginFolder) {
final File arenasFolder;
arenasFolder = new File(pluginFolder, "arenas");
if (arenasFolder.mkdirs()) {
logger.fine("Created arenas folder");
logger.info("Created arenas folder");
}
return arenasFolder;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.readutf.inari.core.arena.stores.gridloader.grid;

import com.readutf.inari.core.logging.GameLoggerFactory;
import com.readutf.inari.core.logging.Logger;
import com.readutf.inari.core.logging.LoggerManager;
import com.readutf.inari.core.logging.LoggerFactory;
import lombok.Getter;

import java.util.ArrayDeque;

public class GridPositionManager {

private static Logger logger = LoggerManager.getInstance().getLogger(GridPositionManager.class);
private static Logger logger = LoggerFactory.getLogger(GridPositionManager.class);

private final ArrayDeque<GridSpace> recentlyFreed = new ArrayDeque<>();
private final int spaceBetween;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import com.readutf.inari.core.arena.exceptions.ArenaStoreException;
import com.readutf.inari.core.arena.stores.gridloader.loader.ArenaBuildLoader;
import com.readutf.inari.core.logging.GameLoggerFactory;
import com.readutf.inari.core.logging.Logger;
import com.readutf.inari.core.logging.LoggerManager;
import com.readutf.inari.core.logging.LoggerFactory;
import com.readutf.inari.core.utils.Position;
import com.readutf.inari.core.utils.WorldCuboid;
import com.readutf.inari.core.utils.WorldEditUtils;
Expand Down Expand Up @@ -33,7 +34,7 @@

public class WorldEditLoader implements ArenaBuildLoader {

private static final Logger logger = LoggerManager.getInstance().getLogger(WorldEditLoader.class);
private static final Logger logger = LoggerFactory.getLogger(WorldEditLoader.class);

private final Map<String, Clipboard> clipboards;

Expand All @@ -43,24 +44,29 @@ public WorldEditLoader() {

@Override
public void pasteSchematic(World world, File arenaFolder, Position origin) throws IOException {
long start = System.currentTimeMillis();


long schematicStart = System.currentTimeMillis();
Clipboard clipboard = clipboards.getOrDefault(arenaFolder.getName(), null);
if(clipboard == null) {
ClipboardReader reader = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getReader(new FileInputStream(new File(arenaFolder, "arena.schematic")));
clipboard = reader.read();
clipboards.put(arenaFolder.getName(), clipboard);
}

logger.info("Loaded schematic in " + (System.currentTimeMillis() - schematicStart) + "ms");
long pasteStart = System.currentTimeMillis();

try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(world))) {
Operation pasteOperation = new ClipboardHolder(clipboard).createPaste(editSession)
.to(BlockVector3.at(origin.getX(), origin.getY(), origin.getZ()))
.ignoreAirBlocks(true)
.ignoreAirBlocks(false)
.build();

Operations.complete(pasteOperation);
}

logger.fine("Pasted schematic at " + origin + " in " + (System.currentTimeMillis() - start) + "ms");
logger.info("Pasted schematic at " + origin + " in " + (System.currentTimeMillis() - pasteStart) + "ms");
}

@Override
Expand All @@ -87,7 +93,7 @@ public void saveSchematic(WorldCuboid worldCuboid, File arenaFolder) throws Aren
throw new ArenaStoreException(e.getMessage());
}

logger.fine("Saved schematic in " + (System.currentTimeMillis() - start) + "ms");
logger.info("Saved schematic in " + (System.currentTimeMillis() - start) + "ms");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testLoad(Player player) {

player.sendMessage(ChatColor.GREEN + "Loaded arena " + arenaMeta.getName());

player.teleport(arena.getBounds().getMin().toLocation(SchematicArenaManager.getWorld()));
// player.teleport(arena.getBounds().getMin().toLocation(SchematicArenaManager.getWorld()));

new BukkitRunnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.readutf.inari.core.game.GameManager;
import com.readutf.inari.core.game.events.GameEvent;
import com.readutf.inari.core.logging.Logger;
import com.readutf.inari.core.logging.LoggerManager;
import com.readutf.inari.core.logging.LoggerFactory;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
Expand All @@ -29,7 +29,7 @@

public class GameEventManager implements Listener {

private static final Logger logger = LoggerManager.getInstance().getLogger(GameEventManager.class);
private static final Logger logger = LoggerFactory.getLogger(GameEventManager.class);

private final JavaPlugin javaPlugin;
private final Map<UUID, Map<Class<? extends Event>, List<GameEventListener>>> gameIdToEventMethod;
Expand Down
8 changes: 7 additions & 1 deletion Core/src/main/java/com/readutf/inari/core/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.stream.JsonReader;
import com.readutf.inari.core.InariCore;
import com.readutf.inari.core.arena.ActiveArena;
import com.readutf.inari.core.event.GameEventManager;
import com.readutf.inari.core.event.testlistener.TestListener;
Expand All @@ -22,6 +23,8 @@
import com.readutf.inari.core.game.stage.RoundCreator;
import com.readutf.inari.core.game.task.GameThread;
import com.readutf.inari.core.game.team.Team;
import com.readutf.inari.core.logging.GameLoggerFactory;
import com.readutf.inari.core.logging.store.FlatFileLogStore;
import com.readutf.inari.core.utils.serialize.ConfigurationSerializableAdapter;
import com.readutf.inari.core.utils.serialize.ItemStackAdapter;
import lombok.Getter;
Expand Down Expand Up @@ -59,6 +62,7 @@ public class Game {
private final SpectatorManager spectatorManager;
private final GameThread gameThread;
private final Map<String, String> attributes;
private final GameLoggerFactory loggerFactory;

private SpawnFinder playerSpawnFinder;
private @NotNull GameState gameState;
Expand All @@ -69,6 +73,7 @@ public class Game {

protected Game(JavaPlugin javaPlugin, GameEventManager gameEventManager, ActiveArena intialArena, List<Team> playerTeams, RoundCreator... stageCreators) {
this.gameId = UUID.randomUUID();
this.loggerFactory = new GameLoggerFactory(this, gameId1 -> new FlatFileLogStore(gameId1, javaPlugin.getDataFolder()));
this.javaPlugin = javaPlugin;
this.arena = intialArena;
this.playerTeams = playerTeams;
Expand Down Expand Up @@ -132,7 +137,7 @@ private void startNextRound() throws GameException {
}

for (Player alivePlayers : getOnlineAndAlivePlayers()) {
alivePlayers.teleport(playerSpawnFinder.findSpawn(this, alivePlayers));
alivePlayers.teleport(playerSpawnFinder.findSpawn(alivePlayers));
}

currentRound.roundStart();
Expand Down Expand Up @@ -164,6 +169,7 @@ public void endGame(Team winner, GameEndReason reason) {
gameThread.cancel();
spectatorManager.shutdown();
gameEventManager.unregisterGame(this);
loggerFactory.shutdown();
GameManager.getInstance().removeGame(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.readutf.inari.core.arena.ActiveArena;
import com.readutf.inari.core.event.GameEventManager;
import com.readutf.inari.core.game.spawning.SpawnFinder;
import com.readutf.inari.core.game.spawning.SpawnFinderFactory;
import com.readutf.inari.core.game.stage.RoundCreator;
import com.readutf.inari.core.game.team.Team;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -26,13 +27,13 @@ public GameBuilder(GameCreator gameCreator) {
this.game = gameCreator.create();
}

public GameBuilder setPlayerSpawnHandler( SpawnFinder spawnFinder) {
game.setPlayerSpawnFinder(spawnFinder);
public GameBuilder setPlayerSpawnHandler( SpawnFinderFactory spawnFinderFactory) {
game.setPlayerSpawnFinder(spawnFinderFactory.create(game));
return this;
}

public GameBuilder setSpectatorSpawnHandler( SpawnFinder spawnFinder) {
game.setSpectatorSpawnFinder(spawnFinder);
public GameBuilder setSpectatorSpawnHandler( SpawnFinderFactory spawnFinderFactory) {
game.setSpectatorSpawnFinder(spawnFinderFactory.create(game));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum GameEndReason {
TIME,
ENEMIES_ELIMINATED,
OBJECTIVES_COMPLETED,
CANCELLED, NO_ROUNDS_LEFT;
CANCELLED,
NO_ROUNDS_LEFT;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.readutf.inari.core.game.exception.GameException;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.Collection;
Expand All @@ -24,6 +25,11 @@ public GameManager() {
}

public void startGame(Game game) throws GameException {

if(!Bukkit.isPrimaryThread()) {
throw new GameException("Game must be started on the main thread.");
}

idToGame.put(game.getGameId(), game);
for (UUID allPlayer : game.getAllPlayers()) {
playerToGame.put(allPlayer, game);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.readutf.inari.core.event.GameEventHandler;
import com.readutf.inari.core.game.Game;
import com.readutf.inari.core.game.events.GameDeathEvent;
import com.readutf.inari.core.logging.GameLoggerFactory;
import com.readutf.inari.core.logging.Logger;
import com.readutf.inari.core.logging.LoggerManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
Expand All @@ -16,12 +16,13 @@

public class DeathManager {

private static final Logger logger = LoggerManager.getInstance().getLogger(DeathManager.class);

private final Game game;
private final Logger logger;
private final Map<UUID, UUID> lastDamager;

public DeathManager(Game game) {
this.logger = game.getLoggerFactory().getLogger(DeathManager.class);
this.game = game;
this.lastDamager = new HashMap<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

public interface SpawnFinder {

@NotNull Location findSpawn(Game game, Player player) throws GameException;
@NotNull Location findSpawn(Player player) throws GameException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.readutf.inari.core.game.spawning;

import com.readutf.inari.core.game.Game;

public interface SpawnFinderFactory {

SpawnFinder create(Game game);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.readutf.inari.core.game.Game;
import com.readutf.inari.core.game.exception.GameException;
import com.readutf.inari.core.game.spawning.SpawnFinder;
import com.readutf.inari.core.logging.GameLoggerFactory;
import com.readutf.inari.core.logging.Logger;
import com.readutf.inari.core.logging.LoggerManager;
import com.readutf.inari.core.utils.NumberUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
Expand All @@ -16,16 +16,18 @@

public class TeamBasedSpawning implements SpawnFinder {

private static Logger logger = LoggerManager.getInstance().getLogger(TeamBasedSpawning.class);

private final Game game;
private final String prefix;
private final Logger logger;

public TeamBasedSpawning(String prefix) {
public TeamBasedSpawning(Game game, String prefix) {
this.game = game;
this.prefix = prefix;
this.logger = game.getLoggerFactory().getLogger(TeamBasedSpawning.class);
}

@Override
public @NotNull Location findSpawn(Game game, Player player) throws GameException {
public @NotNull Location findSpawn(Player player) throws GameException {
int teamId = game.getTeamIndex(player.getUniqueId()) + 1;
List<Location> spawnLocations = getTeamSpawns(game.getArena()).getOrDefault(teamId, null);

Expand Down
Loading

0 comments on commit 49c9b00

Please sign in to comment.