Skip to content

Commit

Permalink
feature: /arena list command
Browse files Browse the repository at this point in the history
  • Loading branch information
utfunderscore committed Jun 10, 2024
1 parent 68f8a3a commit 44fddca
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ private Arena loadArena(ArenaMeta arenaMeta) throws IOException, WorldEditExcept
List<ArenaMeta> list = new ArrayList<>();
for (ArenaMeta arenaMeta : availableArenas) {
if (predicate.test(arenaMeta)) {
if (cachedArenas.getOrDefault(arenaMeta, new ArrayDeque<>()).isEmpty()) {
logger.info("Failed to find available arena for " + arenaMeta.getName() + ", low cache level");
continue;
}
list.add(arenaMeta);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.Subcommand;
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.meta.ArenaMeta;
import com.readutf.inari.core.arena.selection.SelectionManager;
import com.readutf.inari.core.arena.stores.gridworld.GridArenaManager;
import com.readutf.inari.core.utils.ColorUtils;
import com.readutf.inari.core.utils.WorldCuboid;
import lombok.AllArgsConstructor;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.List;

Expand Down Expand Up @@ -47,41 +44,15 @@ public void createArena(Player player, String name) {

}

@Subcommand( "testload" )
public void testLoad(Player player) {
@Subcommand( "list" )
public void listArenas(Player player) {
List<ArenaMeta> allArenas = arenaManager.findAvailableArenas(arenaMeta -> true);

try {


List<ArenaMeta> availableArenas = arenaManager.findAvailableArenas(arenaMeta -> true);

availableArenas.stream().findFirst().ifPresent(arenaMeta -> {
try {
arenaManager.load(arenaMeta).thenAccept(arena -> {


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

System.out.println(arena);

player.teleport(arena.getBounds().getMin().toLocation(GridArenaManager.getActiveArenasWorld()));

new BukkitRunnable() {
@Override
public void run() {
arenaManager.unload(arena);
}
}.runTaskLater(javaPlugin, 20 * 5);
});


} catch (ArenaLoadException e) {
e.getException().printStackTrace();
}
});
} catch (Exception e) {
e.printStackTrace();
player.sendMessage(ColorUtils.color("&aAvailable Arenas:"));
for (ArenaMeta allArena : allArenas) {
player.sendMessage(ColorUtils.color(" &8* &f%s &7(%s markers)".formatted(allArena.getName(), allArena.getNumOfMarkers())));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public InariDemo() {
public void onEnable() {

WorldEditSelectionManager worldEditSelectionManager = new WorldEditSelectionManager();
this.arenaManager = new SchematicArenaManager(this, new TileEntityScanner(), new WorldEditLoader(this), new File(getDataFolder(), "arenas"));
this.arenaManager = new SchematicArenaManager(this, new TileEntityScanner(), new WorldEditLoader(this), new File(getDataFolder(), "schematics"));
// this.arenaManager = new GridArenaManager(this, getDataFolder(), new TileEntityScanner());
this.gameManager = new GameManager();
this.gameEventManager = new GameEventManager(this, gameManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public class GameCommand extends BaseCommand {

private final ArenaManager arenaManager;
private final GameStarterManager gameStarterManager;



@SneakyThrows
@Subcommand("start") @CommandCompletion("@gametypes @arena @players")
public void start(Player player, String gameName, String arenaName, String... players) {
Expand Down

0 comments on commit 44fddca

Please sign in to comment.