This commit is contained in:
parent
994ec8d2c9
commit
894b9c2fe0
11
pom.xml
11
pom.xml
|
@ -116,7 +116,7 @@
|
|||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.20.6-R0.1-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -145,8 +145,15 @@
|
|||
<dependency>
|
||||
<groupId>xyz.twovb</groupId>
|
||||
<artifactId>Toolbox</artifactId>
|
||||
<version>0.2</version>
|
||||
<version>0.2-FIX</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.yaml/snakeyaml -->
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
|
|
|
@ -45,27 +45,17 @@ public final class SGM extends JavaPlugin {
|
|||
configManager = new ConfigManager(this);
|
||||
gameManager = new GameManager();
|
||||
Messages = configManager.loadConfig("messages.yml");
|
||||
this.saveDefaultConfig();
|
||||
// this.saveDefaultConfig();
|
||||
BuildInfo = new YamlConfiguration();
|
||||
try {
|
||||
BuildInfo.load(Objects.requireNonNull(this.getTextResource("build-info.yml")));
|
||||
} catch (IOException | InvalidConfigurationException ignored) {
|
||||
}
|
||||
registerCommands();
|
||||
registerGames();
|
||||
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() {
|
||||
PlaceholderManager pm = new PlaceholderManager();
|
||||
pm.registerPlaceholder("%commit.id%", BuildInfo.getString("commit.id"));
|
||||
|
@ -82,6 +72,16 @@ public final class SGM extends JavaPlugin {
|
|||
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
|
||||
// public void onDisable() {
|
||||
// try {
|
||||
|
|
|
@ -9,9 +9,14 @@ import dev.rollczi.litecommands.annotations.command.Command;
|
|||
import dev.rollczi.litecommands.annotations.context.Context;
|
||||
import dev.rollczi.litecommands.annotations.execute.Execute;
|
||||
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.entity.Player;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.levels.LevelManager;
|
||||
import xyz.twovb.toolbox.api.CustomPlayer;
|
||||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
|
@ -19,18 +24,38 @@ import java.util.Optional;
|
|||
import java.util.UUID;
|
||||
|
||||
@Command(name = "level")
|
||||
@Permission("sgm.levels")
|
||||
public class LevelCommand {
|
||||
|
||||
@Execute(name = "create")
|
||||
@Permission("sgm.levels.create")
|
||||
void create(@Context CommandSender sender, @Arg("name") Optional<String> LevelName, @Arg("game") String game) {
|
||||
LevelManager mm = new LevelManager();
|
||||
void create(@Context CommandSender sender, @Arg("game") String game, @Arg("name") Optional<String> LevelName) {
|
||||
String name = LevelName.orElse(UUID.randomUUID().toString());
|
||||
// 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)));
|
||||
// }
|
||||
LevelManager.CreationResult result = LevelManager.createLevel(name, game);
|
||||
switch (result) {
|
||||
case SUCCESS:
|
||||
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 org.bukkit.command.CommandSender;
|
||||
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.UUID;
|
||||
|
||||
public class GameManager {
|
||||
|
||||
@Getter
|
||||
private static Map<UUID, Minigame> activeGames;
|
||||
private static Map<UUID, Minigame> activeGames = new HashMap<UUID, Minigame>();
|
||||
|
||||
@Getter
|
||||
private Map<String, Minigame> registeredGames;
|
||||
private ArrayList<String> registeredGames = new ArrayList<>();
|
||||
|
||||
public static Minigame findGame(UUID gameId) {
|
||||
return activeGames.get(gameId);
|
||||
|
@ -59,7 +62,9 @@ public class GameManager {
|
|||
}
|
||||
|
||||
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.block.Block;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.Minigame;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class LevelManager {
|
||||
|
||||
public enum Result {
|
||||
SUCCESS,
|
||||
WORLD_EXISTS,
|
||||
INVALID_ARGS,
|
||||
UNKNOWN
|
||||
}
|
||||
public static final String path = SGM.getInstance().getDataFolder().getPath() + "/levels/";
|
||||
|
||||
private final String path = SGM.getInstance().getDataFolder().getPath() + "/levels/";
|
||||
|
||||
public Result createLevel(String name, String game) {
|
||||
if (SGM.getInstance().getGameManager().getRegisteredGames().containsKey(game.toLowerCase())) {
|
||||
return Result.INVALID_ARGS;
|
||||
public static CreationResult createLevel(String name, String game) {
|
||||
File level = new File(path + name);
|
||||
if (!SGM.getInstance().getGameManager().getRegisteredGames().contains(game.toLowerCase())) {
|
||||
return CreationResult.INVALID_ARGS;
|
||||
}
|
||||
WorldCreator wc = new WorldCreator(path + name, new NamespacedKey(SGM.getInstance(), "level_" + name));
|
||||
if (new File(path + name).exists()) {
|
||||
return Result.WORLD_EXISTS;
|
||||
if (level.exists()) {
|
||||
return CreationResult.WORLD_EXISTS;
|
||||
}
|
||||
wc.type(WorldType.FLAT);
|
||||
wc.generatorSettings("{\"layers\": [{\"block\": \"air\", \"height\": 1}], \"biome\":\"plains\"}");
|
||||
wc.generateStructures(false);
|
||||
World world = wc.createWorld();
|
||||
if (world == null) {
|
||||
return Result.UNKNOWN;
|
||||
return CreationResult.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 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) {
|
||||
|
|
|
@ -8,6 +8,7 @@ commands:
|
|||
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."
|
||||
wrong-args: "&7Invalid command usage. %usage%"
|
||||
unknown-error: "&7An unknown error has occurred. %error%"
|
||||
sgm:
|
||||
game:
|
||||
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}'
|
||||
main: '${project.mainClass}'
|
||||
author: '2vb'
|
||||
api-version: '1.20'
|
||||
api-version: '1.21'
|
||||
softdepend: [PlaceholderAPI]
|
||||
permissions:
|
||||
sgm.levels:
|
||||
|
|
Loading…
Reference in New Issue
Block a user