This commit is contained in:
parent
994ec8d2c9
commit
894b9c2fe0
11
pom.xml
11
pom.xml
|
@ -116,7 +116,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.papermc.paper</groupId>
|
<groupId>io.papermc.paper</groupId>
|
||||||
<artifactId>paper-api</artifactId>
|
<artifactId>paper-api</artifactId>
|
||||||
<version>1.20.6-R0.1-SNAPSHOT</version>
|
<version>1.21-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -145,8 +145,15 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>xyz.twovb</groupId>
|
<groupId>xyz.twovb</groupId>
|
||||||
<artifactId>Toolbox</artifactId>
|
<artifactId>Toolbox</artifactId>
|
||||||
<version>0.2</version>
|
<version>0.2-FIX</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.yaml/snakeyaml -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
|
@ -45,27 +45,17 @@ public final class SGM extends JavaPlugin {
|
||||||
configManager = new ConfigManager(this);
|
configManager = new ConfigManager(this);
|
||||||
gameManager = new GameManager();
|
gameManager = new GameManager();
|
||||||
Messages = configManager.loadConfig("messages.yml");
|
Messages = configManager.loadConfig("messages.yml");
|
||||||
this.saveDefaultConfig();
|
// this.saveDefaultConfig();
|
||||||
BuildInfo = new YamlConfiguration();
|
BuildInfo = new YamlConfiguration();
|
||||||
try {
|
try {
|
||||||
BuildInfo.load(Objects.requireNonNull(this.getTextResource("build-info.yml")));
|
BuildInfo.load(Objects.requireNonNull(this.getTextResource("build-info.yml")));
|
||||||
} catch (IOException | InvalidConfigurationException ignored) {
|
} catch (IOException | InvalidConfigurationException ignored) {
|
||||||
}
|
}
|
||||||
registerCommands();
|
registerCommands();
|
||||||
|
registerGames();
|
||||||
registerPlaceholders();
|
registerPlaceholders();
|
||||||
// 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 registerPlaceholders() {
|
private void registerPlaceholders() {
|
||||||
PlaceholderManager pm = new PlaceholderManager();
|
PlaceholderManager pm = new PlaceholderManager();
|
||||||
pm.registerPlaceholder("%commit.id%", BuildInfo.getString("commit.id"));
|
pm.registerPlaceholder("%commit.id%", BuildInfo.getString("commit.id"));
|
||||||
|
@ -82,6 +72,16 @@ public final class SGM extends JavaPlugin {
|
||||||
gameManager.registerGame(new TestGame());
|
gameManager.registerGame(new TestGame());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public void onDisable() {
|
// public void onDisable() {
|
||||||
// try {
|
// try {
|
||||||
|
|
|
@ -9,9 +9,14 @@ import dev.rollczi.litecommands.annotations.command.Command;
|
||||||
import dev.rollczi.litecommands.annotations.context.Context;
|
import dev.rollczi.litecommands.annotations.context.Context;
|
||||||
import dev.rollczi.litecommands.annotations.execute.Execute;
|
import dev.rollczi.litecommands.annotations.execute.Execute;
|
||||||
import dev.rollczi.litecommands.annotations.permission.Permission;
|
import dev.rollczi.litecommands.annotations.permission.Permission;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import xyz.twovb.sgm.SGM;
|
import xyz.twovb.sgm.SGM;
|
||||||
import xyz.twovb.sgm.levels.LevelManager;
|
import xyz.twovb.sgm.levels.LevelManager;
|
||||||
|
import xyz.twovb.toolbox.api.CustomPlayer;
|
||||||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||||
|
|
||||||
|
@ -19,18 +24,38 @@ import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Command(name = "level")
|
@Command(name = "level")
|
||||||
|
@Permission("sgm.levels")
|
||||||
public class LevelCommand {
|
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, @Arg("game") String game) {
|
void create(@Context CommandSender sender, @Arg("game") String game, @Arg("name") Optional<String> LevelName) {
|
||||||
LevelManager mm = new LevelManager();
|
|
||||||
String name = LevelName.orElse(UUID.randomUUID().toString());
|
String name = LevelName.orElse(UUID.randomUUID().toString());
|
||||||
// if (mm.createLevel(name, game)) {
|
LevelManager.CreationResult result = LevelManager.createLevel(name, game);
|
||||||
// sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(SGM.getInstance().getMessages().getString("sgm.level.new"), sender).replace("%level%", name)));
|
switch (result) {
|
||||||
// } else {
|
case SUCCESS:
|
||||||
// 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.new"), sender).replace("%level%", name)));
|
||||||
// }
|
break;
|
||||||
|
case WORLD_EXISTS:
|
||||||
|
sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(SGM.getInstance().getMessages().getString("sgm.level.exists"), sender).replace("%level%", name)));
|
||||||
|
break;
|
||||||
|
case INVALID_ARGS:
|
||||||
|
sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(SGM.getInstance().getMessages().getString("sgm.game.not-found"), sender)));
|
||||||
|
break;
|
||||||
|
case UNKNOWN:
|
||||||
|
default:
|
||||||
|
sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(SGM.getInstance().getMessages().getString("commands.unknown-error"), sender).replace("%error%", "(UNKNOWN)")));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Execute(name = "edit")
|
||||||
|
@Permission("sgm.levels.edit")
|
||||||
|
void edit(@Context Player player, @Arg("name") String name) {
|
||||||
|
CustomPlayer cPlayer = new CustomPlayer(player);
|
||||||
|
World world = LevelManager.getLevel(name);
|
||||||
|
player.teleport(world.getSpawnLocation());
|
||||||
|
cPlayer.sendMessage("<red>tele&aport");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,17 +7,20 @@ package xyz.twovb.sgm.games;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import xyz.twovb.sgm.SGM;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class GameManager {
|
public class GameManager {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static Map<UUID, Minigame> activeGames;
|
private static Map<UUID, Minigame> activeGames = new HashMap<UUID, Minigame>();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private Map<String, Minigame> registeredGames;
|
private ArrayList<String> registeredGames = new ArrayList<>();
|
||||||
|
|
||||||
public static Minigame findGame(UUID gameId) {
|
public static Minigame findGame(UUID gameId) {
|
||||||
return activeGames.get(gameId);
|
return activeGames.get(gameId);
|
||||||
|
@ -59,7 +62,9 @@ public class GameManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerGame(Minigame game) {
|
public void registerGame(Minigame game) {
|
||||||
registeredGames.put(game.getName().toLowerCase(), game);
|
registeredGames.add(game.getName().toLowerCase());
|
||||||
|
SGM.getInstance().getCLogger().log("Registered game " + game.getName());
|
||||||
|
SGM.getInstance().getCLogger().log(registeredGames);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -6,43 +6,66 @@ package xyz.twovb.sgm.levels;
|
||||||
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
|
import org.yaml.snakeyaml.Yaml;
|
||||||
import xyz.twovb.sgm.SGM;
|
import xyz.twovb.sgm.SGM;
|
||||||
import xyz.twovb.sgm.games.Minigame;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class LevelManager {
|
public class LevelManager {
|
||||||
|
|
||||||
public enum Result {
|
public static final String path = SGM.getInstance().getDataFolder().getPath() + "/levels/";
|
||||||
SUCCESS,
|
|
||||||
WORLD_EXISTS,
|
|
||||||
INVALID_ARGS,
|
|
||||||
UNKNOWN
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String path = SGM.getInstance().getDataFolder().getPath() + "/levels/";
|
public static CreationResult createLevel(String name, String game) {
|
||||||
|
File level = new File(path + name);
|
||||||
public Result createLevel(String name, String game) {
|
if (!SGM.getInstance().getGameManager().getRegisteredGames().contains(game.toLowerCase())) {
|
||||||
if (SGM.getInstance().getGameManager().getRegisteredGames().containsKey(game.toLowerCase())) {
|
return CreationResult.INVALID_ARGS;
|
||||||
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 (level.exists()) {
|
||||||
return Result.WORLD_EXISTS;
|
return CreationResult.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();
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
return Result.UNKNOWN;
|
return CreationResult.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 Result.SUCCESS;
|
genDataFile(level, name, game.toLowerCase());
|
||||||
|
return CreationResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void genDataFile(File path, String name, String game) {
|
||||||
|
Map<String, Object> data = new HashMap<>();
|
||||||
|
data.put("name", name);
|
||||||
|
data.put("game", game);
|
||||||
|
DumperOptions options = new DumperOptions();
|
||||||
|
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
|
Yaml yaml = new Yaml(options);
|
||||||
|
File yamlFile = new File(path + "/sgm.yml");
|
||||||
|
try (FileWriter writer = new FileWriter(yamlFile)) {
|
||||||
|
yaml.dump(data, writer);
|
||||||
|
} catch (IOException e) {
|
||||||
|
SGM.getInstance().getCLogger().error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static World getLevel(String name) {
|
||||||
|
return Bukkit.getWorld(new NamespacedKey(SGM.getInstance(), "level_" + name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum CreationResult {
|
||||||
|
SUCCESS, WORLD_EXISTS, INVALID_ARGS, UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void deleteLevel(String name) {
|
// public void deleteLevel(String name) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ commands:
|
||||||
player-only: "&7You must be a player to run this command."
|
player-only: "&7You must be a player to run this command."
|
||||||
no-permissions: "&7You do not have the required permission &e%permission%&7 to do this."
|
no-permissions: "&7You do not have the required permission &e%permission%&7 to do this."
|
||||||
wrong-args: "&7Invalid command usage. %usage%"
|
wrong-args: "&7Invalid command usage. %usage%"
|
||||||
|
unknown-error: "&7An unknown error has occurred. %error%"
|
||||||
sgm:
|
sgm:
|
||||||
game:
|
game:
|
||||||
new: "&7A new %game% has started and can now be joined!"
|
new: "&7A new %game% has started and can now be joined!"
|
||||||
|
|
|
@ -2,7 +2,7 @@ name: '${project.name}'
|
||||||
version: 'Git-${git.commit.id.abbrev}-${project.version}'
|
version: 'Git-${git.commit.id.abbrev}-${project.version}'
|
||||||
main: '${project.mainClass}'
|
main: '${project.mainClass}'
|
||||||
author: '2vb'
|
author: '2vb'
|
||||||
api-version: '1.20'
|
api-version: '1.21'
|
||||||
softdepend: [PlaceholderAPI]
|
softdepend: [PlaceholderAPI]
|
||||||
permissions:
|
permissions:
|
||||||
sgm.levels:
|
sgm.levels:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user