Require options file for game to be registered.
This commit is contained in:
parent
eb8ac97572
commit
86957224b2
|
@ -14,6 +14,7 @@ import xyz.twovb.sgm.commands.impl.LevelCommand;
|
|||
import xyz.twovb.sgm.commands.impl.SGMCommand;
|
||||
import xyz.twovb.sgm.games.GameManager;
|
||||
import xyz.twovb.sgm.games.impl.TestGame;
|
||||
import xyz.twovb.sgm.games.impl.capturethebrick.CTB;
|
||||
import xyz.twovb.sgm.levels.LevelManager;
|
||||
import xyz.twovb.toolbox.managers.ConfigManager;
|
||||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
|
@ -72,6 +73,7 @@ public final class SGM extends JavaPlugin {
|
|||
}
|
||||
|
||||
private void registerGames() {
|
||||
gameManager.registerGame(new CTB());
|
||||
gameManager.registerGame(new TestGame());
|
||||
}
|
||||
|
||||
|
|
|
@ -21,12 +21,10 @@ public class SGMCommand {
|
|||
builder.append(SGM.getInstance().getMessages().getString("main-command.lines.2"));
|
||||
builder.append("\n");
|
||||
builder.append(SGM.getInstance().getMessages().getString("main-command.lines.3"));
|
||||
builder.append("\n");
|
||||
String string = builder.toString();
|
||||
sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(string, sender)));
|
||||
}
|
||||
|
||||
@Execute(name = "a")
|
||||
void a(@Context CommandSender sender) {}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import xyz.twovb.sgm.SGM;
|
|||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -69,8 +70,19 @@ public class GameManager {
|
|||
}
|
||||
|
||||
public void registerGame(Minigame game) {
|
||||
registeredGames.add(game.getName().toLowerCase());
|
||||
String intName = game.getName().toLowerCase();
|
||||
try {
|
||||
SGM.getInstance().getConfigManager().loadConfig("games/" + intName + "/options.yml");
|
||||
registeredGames.add(intName);
|
||||
SGM.getInstance().getCLogger().log("Registered game " + game.getName());
|
||||
} catch(IllegalArgumentException error) {
|
||||
String errMsg = error.getMessage();
|
||||
if (errMsg.contains("The embedded resource") && errMsg.contains("cannot be found")) {
|
||||
SGM.getInstance().getCLogger().log(game.getName() + "'s game options are nowhere to be found. Skipping.");
|
||||
} else {
|
||||
SGM.getInstance().getCLogger().error("Failed to register game " + game.getName() + ". Reason: " + errMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -30,7 +30,6 @@ public class LevelManager {
|
|||
|
||||
public static final String mapPath = SGM.getInstance().getDataFolder().getPath() + "/maps/";
|
||||
|
||||
// todo: make it the actual map and not levels
|
||||
public HashMap<String, List<String>> enabledMaps = new HashMap<>();
|
||||
|
||||
private static void loadWorld(String worldName, LevelType type) {
|
||||
|
@ -48,7 +47,6 @@ public class LevelManager {
|
|||
case GAME -> new WorldCreator(gamePath + worldName, new NamespacedKey(SGM.getInstance(), key));
|
||||
case MAP -> new WorldCreator(mapPath + worldName, new NamespacedKey(SGM.getInstance(), key));
|
||||
};
|
||||
// WorldCreator wc = new WorldCreator(levelPath + worldName, new NamespacedKey(SGM.getInstance(), key));
|
||||
World world = wc.createWorld();
|
||||
if (world != null) {
|
||||
SGM.getInstance().getCLogger().log("Loaded world: " + worldName);
|
||||
|
@ -61,8 +59,8 @@ public class LevelManager {
|
|||
// probably rewriting tmr
|
||||
// these are opposite
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("name", name);
|
||||
data.put("game", game);
|
||||
data.put("name", name);
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
Yaml yaml = new Yaml(options);
|
||||
|
@ -123,7 +121,6 @@ public class LevelManager {
|
|||
world.setSpawnLocation(location);
|
||||
world.setSpawnFlags(false, false);
|
||||
genDataFile(level, name, game.toLowerCase());
|
||||
enabledMaps.get(game).add(name);
|
||||
return LevelResult.SUCCESS;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user