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