From 3f24e54be2df39f6c737687d14cd524c416241dc Mon Sep 17 00:00:00 2001
From: phinner <62483793+phinner@users.noreply.github.com>
Date: Sat, 9 Dec 2023 20:28:47 +0100
Subject: [PATCH] chore: ok
---
.../xpdustry/hexed/HexedPluginReloaded.java | 2 +
.../generation/RouterFestHexedGenerator.java | 23 ++--
.../hexed/commands/HexedStartCommand.java | 117 ------------------
3 files changed, 9 insertions(+), 133 deletions(-)
delete mode 100644 src/main/java/com/xpdustry/hexed/commands/HexedStartCommand.java
diff --git a/src/main/java/com/xpdustry/hexed/HexedPluginReloaded.java b/src/main/java/com/xpdustry/hexed/HexedPluginReloaded.java
index b37156d..415ad05 100644
--- a/src/main/java/com/xpdustry/hexed/HexedPluginReloaded.java
+++ b/src/main/java/com/xpdustry/hexed/HexedPluginReloaded.java
@@ -26,6 +26,7 @@
import com.xpdustry.hexed.api.generation.ImmutableSchematic;
import com.xpdustry.hexed.api.generation.MapGenerator;
import com.xpdustry.hexed.api.generation.MapLoader;
+import com.xpdustry.hexed.api.generation.RouterFestHexedGenerator;
import com.xpdustry.hexed.api.generation.SimpleHexedMapContext;
import fr.xpdustry.distributor.api.plugin.AbstractMindustryPlugin;
import java.io.IOException;
@@ -114,6 +115,7 @@ public void onInit() {
}
this.generators.put("anuke", new AnukeHexedGenerator());
+ this.generators.put("router-fest", new RouterFestHexedGenerator());
this.state = new SimpleHexedState(this.defaultBase, Collections.emptyList());
this.addListener(new HexedLogic(this));
diff --git a/src/main/java/com/xpdustry/hexed/api/generation/RouterFestHexedGenerator.java b/src/main/java/com/xpdustry/hexed/api/generation/RouterFestHexedGenerator.java
index 2710d9c..007157c 100644
--- a/src/main/java/com/xpdustry/hexed/api/generation/RouterFestHexedGenerator.java
+++ b/src/main/java/com/xpdustry/hexed/api/generation/RouterFestHexedGenerator.java
@@ -16,23 +16,20 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package com.xpdustry.hexed.generation;
+package com.xpdustry.hexed.api.generation;
-import com.xpdustry.hexed.model.Hex;
-import com.xpdustry.hexed.model.SquareHex;
+import com.xpdustry.hexed.api.model.Hex;
+import com.xpdustry.hexed.api.model.Square;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import mindustry.Vars;
import mindustry.content.Blocks;
-import mindustry.game.Schematic;
import mindustry.game.Schematics;
import mindustry.world.blocks.environment.Floor;
-public final class RouterFestHexedGenerator implements MapGenerator {
-
- private static final RouterFestHexedGenerator INSTANCE = new RouterFestHexedGenerator();
+public class RouterFestHexedGenerator implements MapGenerator {
private static final int HEX_MAP_SIZE = 8;
private static final int HEX_SIZE = 49;
@@ -48,12 +45,6 @@ public final class RouterFestHexedGenerator implements MapGenerator {
tile.setBlock(Blocks.air);
@@ -151,9 +142,9 @@ public HexedMapContext generate() {
return context;
}
- private Schematic getRouterBase() {
+ private ImmutableSchematic getRouterBase() {
try (final var stream = this.getClass().getResourceAsStream("/router.msch")) {
- return Schematics.read(Objects.requireNonNull(stream));
+ return new ImmutableSchematic(Schematics.read(Objects.requireNonNull(stream)));
} catch (final IOException e) {
throw new RuntimeException("Failed to load the router base schematic.", e);
}
diff --git a/src/main/java/com/xpdustry/hexed/commands/HexedStartCommand.java b/src/main/java/com/xpdustry/hexed/commands/HexedStartCommand.java
deleted file mode 100644
index 40b218f..0000000
--- a/src/main/java/com/xpdustry/hexed/commands/HexedStartCommand.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * HexedPluginReloaded, A reimplementation of the hexed gamemode, with more features and better performances.
- *
- * Copyright (C) 2023 Xpdustry
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package com.xpdustry.hexed.commands;
-
-import arc.util.CommandHandler;
-import cloud.commandframework.annotations.Argument;
-import cloud.commandframework.annotations.CommandDescription;
-import cloud.commandframework.annotations.CommandMethod;
-import cloud.commandframework.annotations.CommandPermission;
-import com.xpdustry.hexed.HexedPluginReloaded;
-import com.xpdustry.hexed.generation.AnukeHexedGenerator;
-import com.xpdustry.hexed.generation.HexedMapContext;
-import com.xpdustry.hexed.generation.MapGenerator;
-import com.xpdustry.hexed.generation.MapLoader;
-import com.xpdustry.hexed.generation.RouterFestHexedGenerator;
-import fr.xpdustry.distributor.api.command.sender.CommandSender;
-import fr.xpdustry.distributor.api.plugin.PluginListener;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Map;
-import mindustry.Vars;
-import mindustry.game.Schematic;
-import mindustry.game.Schematics;
-import org.checkerframework.checker.nullness.qual.Nullable;
-
-public final class HexedStartCommand implements PluginListener {
-
- private static final Map> GENERATORS = Map.of(
- "anuke", AnukeHexedGenerator.getInstance(),
- "routerfest", RouterFestHexedGenerator.getInstance());
-
- private final HexedPluginReloaded hexed;
- private final Path customBasesDirectory;
-
- public HexedStartCommand(final HexedPluginReloaded hexed) {
- this.hexed = hexed;
- this.customBasesDirectory = this.hexed.getDirectory().resolve("bases");
- }
-
- @CommandMethod("hexed [generator] [base]")
- @CommandDescription("Begin hosting with the Hexed game mode.")
- @CommandPermission("com.xpdustry.hexed.start")
- public void onHexedCommand(
- final CommandSender sender,
- final @Argument("generator") @Nullable String name,
- final @Argument("base") @Nullable String base) {
- if (Vars.state.isGame()) {
- sender.sendWarning("Stop the server first.");
- return;
- }
-
- if (name != null && !GENERATORS.containsKey(name)) {
- sender.sendWarning("Unknown generator " + name + ".");
- return;
- }
-
- Schematic schematic = null;
- if (base != null) {
- final var file = this.customBasesDirectory.resolve(base + ".msch");
- if (Files.exists(file)) {
- try (final var stream = Files.newInputStream(file)) {
- schematic = Schematics.read(stream);
- } catch (final IOException e) {
- throw new RuntimeException("Failed to load the base schematic in the custom bases directory", e);
- }
- } else {
- sender.sendWarning("No custom base schematic named " + base + " found.");
- return;
- }
- }
-
- final MapGenerator generator =
- name == null ? AnukeHexedGenerator.getInstance() : GENERATORS.get(name);
- if (generator == null) {
- sender.sendWarning("Generator named " + name + " not found.");
- return;
- }
-
- try (final var loader = MapLoader.create()) {
- final var context = loader.load(generator);
- sender.sendMessage("Map generated.");
- this.hexed.getHexedState().setHexes(context.getHexes());
- this.hexed.getHexedState().setBaseSchematic(schematic == null ? context.getBaseSchematic() : schematic);
- sender.sendMessage("Server started.");
- } catch (final Exception e) {
- sender.sendWarning("Failed to hexed with generator " + generator + ": " + e.getMessage());
- this.hexed.getLogger().error("Oh no", e);
- }
- }
-
- @Override
- public void onPluginClientCommandsRegistration(final CommandHandler handler) {
- this.hexed.getClientCommandManager().getAnnotationParser().parse(this);
- }
-
- @Override
- public void onPluginServerCommandsRegistration(final CommandHandler handler) {
- this.hexed.getServerCommandManager().getAnnotationParser().parse(this);
- }
-}