This commit is contained in:
parent
5d0035282d
commit
994ec8d2c9
|
@ -11,13 +11,13 @@ import xyz.twovb.sgm.commands.handlers.InvalidArgsHandler;
|
|||
import xyz.twovb.sgm.commands.handlers.NoPermissionsHandler;
|
||||
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.toolbox.managers.ConfigManager;
|
||||
import xyz.twovb.toolbox.managers.DatabaseManager;
|
||||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.utils.CustomLogger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class SGM extends JavaPlugin {
|
||||
|
@ -31,8 +31,11 @@ public final class SGM extends JavaPlugin {
|
|||
@Getter
|
||||
private CustomLogger cLogger;
|
||||
private ConfigManager configManager;
|
||||
// @Getter
|
||||
// private DatabaseManager databaseManager;
|
||||
|
||||
@Getter
|
||||
private DatabaseManager databaseManager;
|
||||
private GameManager gameManager;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -40,6 +43,7 @@ public final class SGM extends JavaPlugin {
|
|||
instance = this;
|
||||
cLogger = new CustomLogger(this);
|
||||
configManager = new ConfigManager(this);
|
||||
gameManager = new GameManager();
|
||||
Messages = configManager.loadConfig("messages.yml");
|
||||
this.saveDefaultConfig();
|
||||
BuildInfo = new YamlConfiguration();
|
||||
|
@ -49,18 +53,18 @@ public final class SGM extends JavaPlugin {
|
|||
}
|
||||
registerCommands();
|
||||
registerPlaceholders();
|
||||
connectToDatabase();
|
||||
// connectToDatabase();
|
||||
}
|
||||
|
||||
private void connectToDatabase() {
|
||||
databaseManager = new DatabaseManager();
|
||||
try {
|
||||
databaseManager.connect(DatabaseManager.DatabaseType.SQLITE, this, "sgm");
|
||||
cLogger.log("Connected to database!");
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
// private void connectToDatabase() {
|
||||
// databaseManager = new DatabaseManager();
|
||||
// try {
|
||||
// databaseManager.connect(DatabaseManager.DatabaseType.SQLITE, this, "sgm");
|
||||
// cLogger.log("Connected to database!");
|
||||
// } catch (SQLException | ClassNotFoundException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
private void registerPlaceholders() {
|
||||
PlaceholderManager pm = new PlaceholderManager();
|
||||
|
@ -74,14 +78,18 @@ public final class SGM extends JavaPlugin {
|
|||
LiteCommandsBukkit.builder().commands(new SGMCommand(), new LevelCommand()).invalidUsage(new InvalidArgsHandler()).missingPermission(new NoPermissionsHandler()).message(LiteBukkitMessages.PLAYER_NOT_FOUND, input -> Messages.getString("commands.invalid-player").replace("%player%", input)).message(LiteBukkitMessages.PLAYER_ONLY, input -> Messages.getString("commands.player-only")).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
try {
|
||||
databaseManager.close();
|
||||
} catch (SQLException e) {
|
||||
cLogger.error(e);
|
||||
}
|
||||
private void registerGames() {
|
||||
gameManager.registerGame(new TestGame());
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onDisable() {
|
||||
// try {
|
||||
// databaseManager.close();
|
||||
// } catch (SQLException e) {
|
||||
// cLogger.error(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package xyz.twovb.sgm.commands.impl;
|
||||
|
||||
/*
|
||||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
@ -22,14 +23,14 @@ public class LevelCommand {
|
|||
|
||||
@Execute(name = "create")
|
||||
@Permission("sgm.levels.create")
|
||||
void create(@Context CommandSender sender, @Arg("name") Optional<String> LevelName) {
|
||||
void create(@Context CommandSender sender, @Arg("name") Optional<String> LevelName, @Arg("game") String game) {
|
||||
LevelManager mm = new LevelManager();
|
||||
String name = LevelName.orElse(UUID.randomUUID().toString());
|
||||
if (mm.createLevel(name)) {
|
||||
sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(SGM.getInstance().getMessages().getString("sgm.level.new"), sender).replace("%level%", name)));
|
||||
} else {
|
||||
sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(SGM.getInstance().getMessages().getString("sgm.level.exists"), sender).replace("%level%", name)));
|
||||
}
|
||||
// if (mm.createLevel(name, game)) {
|
||||
// sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(SGM.getInstance().getMessages().getString("sgm.level.new"), sender).replace("%level%", name)));
|
||||
// } else {
|
||||
// sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(SGM.getInstance().getMessages().getString("sgm.level.exists"), sender).replace("%level%", name)));
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package xyz.twovb.sgm.games;
|
||||
|
||||
/*
|
||||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
@ -15,6 +16,9 @@ public class GameManager {
|
|||
@Getter
|
||||
private static Map<UUID, Minigame> activeGames;
|
||||
|
||||
@Getter
|
||||
private Map<String, Minigame> registeredGames;
|
||||
|
||||
public static Minigame findGame(UUID gameId) {
|
||||
return activeGames.get(gameId);
|
||||
}
|
||||
|
@ -54,4 +58,8 @@ public class GameManager {
|
|||
game.removePlayer(player);
|
||||
}
|
||||
|
||||
public void registerGame(Minigame game) {
|
||||
registeredGames.put(game.getName().toLowerCase(), game);
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,7 @@ import java.util.UUID;
|
|||
|
||||
public class TestGame implements Minigame {
|
||||
|
||||
final String name = "TestGame";
|
||||
final static String name = "TestGame";
|
||||
private final UUID uuid;
|
||||
private CommandSender owner;
|
||||
private GameState state;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package xyz.twovb.sgm.levels;
|
||||
|
||||
/*
|
||||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package xyz.twovb.sgm.levels;
|
||||
|
||||
/*
|
||||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
@ -6,29 +7,42 @@ package xyz.twovb.sgm.levels;
|
|||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.Minigame;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class LevelManager {
|
||||
|
||||
public enum Result {
|
||||
SUCCESS,
|
||||
WORLD_EXISTS,
|
||||
INVALID_ARGS,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
private final String path = SGM.getInstance().getDataFolder().getPath() + "/levels/";
|
||||
|
||||
public boolean createLevel(String name) {
|
||||
public Result createLevel(String name, String game) {
|
||||
if (SGM.getInstance().getGameManager().getRegisteredGames().containsKey(game.toLowerCase())) {
|
||||
return Result.INVALID_ARGS;
|
||||
}
|
||||
WorldCreator wc = new WorldCreator(path + name, new NamespacedKey(SGM.getInstance(), "level_" + name));
|
||||
if (new File(path + name).exists()) {
|
||||
return false;
|
||||
return Result.WORLD_EXISTS;
|
||||
}
|
||||
wc.type(WorldType.FLAT);
|
||||
wc.generatorSettings("{\"layers\": [{\"block\": \"air\", \"height\": 1}], \"biome\":\"plains\"}");
|
||||
wc.generateStructures(false);
|
||||
World world = wc.createWorld();
|
||||
assert world != null;
|
||||
if (world == null) {
|
||||
return Result.UNKNOWN;
|
||||
}
|
||||
Location location = new Location(world, 0, 0, 0);
|
||||
Block block = location.subtract(0, 1, 0).getBlock();
|
||||
block.setType(Material.STONE);
|
||||
world.setSpawnLocation(location);
|
||||
world.setSpawnFlags(false, false);
|
||||
return true;
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
// public void deleteLevel(String name) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user