Code cleanup and also something works but i cant remember lol

This commit is contained in:
2vb 2024-07-02 19:51:33 -07:00
parent 38101ea022
commit 24e267b31b
8 changed files with 49 additions and 31 deletions

View File

@ -13,8 +13,7 @@ import xyz.twovb.sgm.commands.impl.GameCommand;
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.GameManager;
//import xyz.twovb.sgm.games.impl.TestGame; import xyz.twovb.sgm.games.impl.TestGame;
import xyz.twovb.sgm.games.impl.*;
import xyz.twovb.sgm.levels.LevelManager; import xyz.twovb.sgm.levels.LevelManager;
import xyz.twovb.toolbox.managers.ConfigManager; import xyz.twovb.toolbox.managers.ConfigManager;
import xyz.twovb.toolbox.managers.PlaceholderManager; import xyz.twovb.toolbox.managers.PlaceholderManager;

View File

@ -24,6 +24,7 @@ public class InvalidArgsHandler implements InvalidUsageHandler<CommandSender> {
builder.insert(0, "\n"); builder.insert(0, "\n");
if (schematic.isOnlyFirst()) { if (schematic.isOnlyFirst()) {
// borken idk why ill fix later // borken idk why ill fix later
// TODO: figure out how its broken and then fix it:)
message = message.replace("%usage%", "\n&8 - &7" + schematic.first()); message = message.replace("%usage%", "\n&8 - &7" + schematic.first());
} else { } else {
List<String> schemes = schematic.all(); List<String> schemes = schematic.all();

View File

@ -1,10 +1,5 @@
package xyz.twovb.sgm.commands.impl; package xyz.twovb.sgm.commands.impl;
/*
* Created by 2vb - 2/7/2024
*/
/* /*
* Created by 2vb - 2/7/2024 * Created by 2vb - 2/7/2024
*/ */
@ -14,20 +9,33 @@ 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.World; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import xyz.twovb.sgm.SGM; import xyz.twovb.sgm.SGM;
import xyz.twovb.sgm.levels.LevelManager;
import xyz.twovb.toolbox.api.CustomPlayer; import xyz.twovb.toolbox.api.CustomPlayer;
@Command(name = "game") @Command(name = "game")
public class GameCommand { public class GameCommand {
@Execute()
void execute(@Context CommandSender sender) {
StringBuilder builder = new StringBuilder();
builder.insert(0, "&7Enabled games:");
builder.append("\n");
for (int i = 0; i < SGM.getInstance().getGameManager().getRegisteredGames().size(); i++) {
String game = SGM.getInstance().getGameManager().getRegisteredGames().get(i);
builder.append(game);
if (i < SGM.getInstance().getGameManager().getRegisteredGames().size() - 1) {
builder.append(", ");
}
}
sender.sendMessage(builder.toString());
}
@Execute(name = "start") @Execute(name = "start")
@Permission("sgm.games.start") @Permission("sgm.games.start")
void game(@Context Player player, @Arg("name") String name) { void game(@Context Player player, @Arg("name") String name) {
CustomPlayer cPlayer = new CustomPlayer(player); CustomPlayer cPlayer = new CustomPlayer(player);
cPlayer.sendMessage(SGM.getInstance().getGameManager().enabledLevels.toString());
} }
} }

View File

@ -9,8 +9,6 @@ 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.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -20,6 +18,7 @@ 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;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -27,11 +26,19 @@ import java.util.UUID;
@Permission("sgm.levels") @Permission("sgm.levels")
public class LevelCommand { public class LevelCommand {
@Execute()
void execute(@Context CommandSender sender) {
for (String game : SGM.getInstance().getLevelManager().enabledMaps.keySet()) {
List<String> maps = SGM.getInstance().getLevelManager().enabledMaps.get(game);
sender.sendMessage("Game: " + game + ", Maps: " + maps);
}
}
@Execute(name = "create") @Execute(name = "create")
@Permission("sgm.levels.create") @Permission("sgm.levels.create")
void create(@Context CommandSender sender, @Arg("game") String game, @Arg("name") Optional<String> LevelName) { void create(@Context CommandSender sender, @Arg("game") String game, @Arg("name") Optional<String> LevelName) {
String name = LevelName.orElse(UUID.randomUUID().toString()); String name = LevelName.orElse(UUID.randomUUID().toString());
LevelManager.CreationResult result = LevelManager.createLevel(name, game); LevelManager.CreationResult result = SGM.getInstance().getLevelManager().createLevel(name, game);
switch (result) { switch (result) {
case SUCCESS: case SUCCESS:
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)));

View File

@ -17,13 +17,9 @@ import java.util.UUID;
public class GameManager { public class GameManager {
@Getter @Getter
private static Map<UUID, Minigame> activeGames = new HashMap<UUID, Minigame>(); private static final Map<UUID, Minigame> activeGames = new HashMap<UUID, Minigame>();
@Getter @Getter
private ArrayList<String> registeredGames = new ArrayList<String>(); private final ArrayList<String> registeredGames = new ArrayList<String>();
@Getter
public Map<String, String> enabledLevels = new HashMap<String, String>();
public static Minigame findGame(UUID gameId) { public static Minigame findGame(UUID gameId) {
return activeGames.get(gameId); return activeGames.get(gameId);
@ -68,9 +64,7 @@ public class GameManager {
registeredGames.add(game.getName().toLowerCase()); registeredGames.add(game.getName().toLowerCase());
SGM.getInstance().getCLogger().log("Registered game " + game.getName()); SGM.getInstance().getCLogger().log("Registered game " + game.getName());
SGM.getInstance().getCLogger().log(registeredGames); SGM.getInstance().getCLogger().log(registeredGames);
registeredGames.add("testgame1"); registeredGames.add("ctb");
registeredGames.add("testgame2");
registeredGames.add("testgame3");
} }
} }

View File

@ -14,24 +14,28 @@ import java.util.UUID;
public interface Minigame extends Listener { public interface Minigame extends Listener {
enum GameState {
PRESTART,
READY,
STARTED,
ENDING
}
void init(CommandSender owner); void init(CommandSender owner);
void start(); void start();
void stop(); void stop();
void addPlayer(Player player); void addPlayer(Player player);
void removePlayer(Player player); void removePlayer(Player player);
List<Player> getPlayers(); List<Player> getPlayers();
void onTick(); void onTick();
String getName(); String getName();
UUID getGameId(); UUID getGameId();
GameState getState(); GameState getState();
CommandSender getOwner(); CommandSender getOwner();
default void sendMessageToAllPlayers(String message) { default void sendMessageToAllPlayers(String message) {
for (Player player : getPlayers()) { for (Player player : getPlayers()) {
CustomPlayer cPlayer = new CustomPlayer(player); CustomPlayer cPlayer = new CustomPlayer(player);
@ -39,4 +43,8 @@ public interface Minigame extends Listener {
} }
} }
enum GameState {
PRESTART, READY, STARTED, ENDING
}
} }

View File

@ -8,5 +8,6 @@ import org.bukkit.World;
public interface Level { public interface Level {
String getName(); String getName();
World getWorld(); World getWorld();
} }

View File

@ -42,7 +42,7 @@ public class LevelManager {
} }
} }
public static CreationResult createLevel(String name, String game) { public CreationResult createLevel(String name, String game) {
File level = new File(path + name); File level = new File(path + name);
if (!SGM.getInstance().getGameManager().getRegisteredGames().contains(game.toLowerCase())) { if (!SGM.getInstance().getGameManager().getRegisteredGames().contains(game.toLowerCase())) {
return CreationResult.INVALID_ARGS; return CreationResult.INVALID_ARGS;
@ -64,7 +64,7 @@ public class LevelManager {
world.setSpawnLocation(location); world.setSpawnLocation(location);
world.setSpawnFlags(false, false); world.setSpawnFlags(false, false);
genDataFile(level, name, game.toLowerCase()); genDataFile(level, name, game.toLowerCase());
SGM.getInstance().getGameManager().enabledLevels.put(game, name); enabledMaps.get(game).add(name);
return CreationResult.SUCCESS; return CreationResult.SUCCESS;
} }