idk what im doing rn but just in case smth breaks
This commit is contained in:
parent
049b5da27c
commit
3ea2b796a5
7
pom.xml
7
pom.xml
|
@ -153,6 +153,13 @@
|
|||
<artifactId>snakeyaml</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.16.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
|
|
|
@ -12,7 +12,11 @@ import dev.rollczi.litecommands.annotations.permission.Permission;
|
|||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.impl.TestGame;
|
||||
import xyz.twovb.toolbox.api.CustomPlayer;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Command(name = "game")
|
||||
public class GameCommand {
|
||||
|
@ -29,13 +33,20 @@ public class GameCommand {
|
|||
builder.append(", ");
|
||||
}
|
||||
}
|
||||
sender.sendMessage(builder.toString());
|
||||
sender.sendMessage(ChatUtils.translate(builder.toString()));
|
||||
}
|
||||
|
||||
@Execute(name = "start")
|
||||
@Permission("sgm.games.start")
|
||||
void game(@Context Player player, @Arg("name") String name) {
|
||||
CustomPlayer cPlayer = new CustomPlayer(player);
|
||||
SGM.getInstance().getGameManager().createGame(new TestGame(), player, name);
|
||||
}
|
||||
|
||||
@Execute(name = "join")
|
||||
void join(@Context Player player, @Arg("id") String id) {
|
||||
CustomPlayer cPlayer = new CustomPlayer(player);
|
||||
SGM.getInstance().getGameManager().addPlayerToGame(player, UUID.fromString(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,15 +22,11 @@ public class SGMCommand {
|
|||
builder.append("\n");
|
||||
builder.append(SGM.getInstance().getMessages().getString("main-command.lines.3"));
|
||||
builder.append("\n");
|
||||
builder.append("Enabled games:");
|
||||
builder.append("\n");
|
||||
for (String game : SGM.getInstance().getGameManager().getRegisteredGames()) {
|
||||
gameBuilder.append(game);
|
||||
gameBuilder.append(", ");
|
||||
}
|
||||
builder.append(gameBuilder.toString());
|
||||
String string = builder.toString();
|
||||
sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(string, sender)));
|
||||
}
|
||||
|
||||
@Execute(name = "a")
|
||||
void a(@Context CommandSender sender) {}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,10 @@ 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.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -49,7 +52,12 @@ public class GameManager {
|
|||
|
||||
public void createGame(Minigame game, CommandSender owner, String level) {
|
||||
// World world = createGameWorld(level);
|
||||
game.init(owner, level);
|
||||
try {
|
||||
game.init(owner, level);
|
||||
} catch (IOException e) {
|
||||
SGM.getInstance().getCLogger().error(e.getMessage());
|
||||
owner.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(SGM.getInstance().getMessages().getString("sgm.game.cant-start"), owner)));
|
||||
}
|
||||
activeGames.put(game.getGameId(), game);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ package xyz.twovb.sgm.games;
|
|||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
|
@ -14,12 +16,14 @@ import xyz.twovb.sgm.SGM;
|
|||
import xyz.twovb.sgm.levels.LevelManager;
|
||||
import xyz.twovb.toolbox.api.CustomPlayer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface Minigame extends Listener {
|
||||
|
||||
void init(CommandSender owner, String world);
|
||||
void init(CommandSender owner, String world) throws IOException;
|
||||
|
||||
void start();
|
||||
|
||||
|
@ -48,8 +52,20 @@ public interface Minigame extends Listener {
|
|||
}
|
||||
}
|
||||
|
||||
default World createGameWorld(String name) {
|
||||
WorldCreator wc = new WorldCreator(LevelManager.path + name, new NamespacedKey(SGM.getInstance(), name + "-" + UUID.randomUUID()));
|
||||
default World createGameWorld(String name, UUID id) throws IOException {
|
||||
File levelDir = new File(LevelManager.path + name);
|
||||
// if (Bukkit.getWorld(new NamespacedKey(SGM.getInstance(), "level_" + name)) != null) {
|
||||
// World levelWorld = Bukkit.getWorld(new NamespacedKey(SGM.getInstance(), "level_" + name));
|
||||
// if (levelWorld != null && levelWorld.getPlayerCount() == 0 && !Bukkit.isTickingWorlds()) {
|
||||
// Bukkit.getServer().unloadWorld(levelWorld, true);
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
String tempName = name + "_" + id;
|
||||
File tempDir = new File(LevelManager.gamePath + tempName);
|
||||
FileUtils.copyDirectory(levelDir, tempDir);
|
||||
WorldCreator wc = new WorldCreator(LevelManager.gamePath + name, new NamespacedKey(SGM.getInstance(), name + "-" + UUID.randomUUID()));
|
||||
World world = wc.createWorld();
|
||||
if (world == null) return null;
|
||||
world.setAutoSave(false);
|
||||
|
|
|
@ -15,6 +15,7 @@ import xyz.twovb.sgm.SGM;
|
|||
import xyz.twovb.sgm.games.GameManager;
|
||||
import xyz.twovb.sgm.games.Minigame;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -34,11 +35,11 @@ public class TestGame implements Minigame {
|
|||
this.players = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void init(CommandSender owner, String world) {
|
||||
public void init(CommandSender owner, String world) throws IOException {
|
||||
// Perform initialization logic here
|
||||
Bukkit.getPluginManager().registerEvents(this, SGM.getInstance());
|
||||
this.owner = owner;
|
||||
gameWorld = createGameWorld(world);
|
||||
gameWorld = createGameWorld(world, uuid);
|
||||
state = GameState.READY;
|
||||
owner.sendMessage("A new " + name + " instance with ID " + uuid + " has been created and is now ready!");
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ public class LevelManager {
|
|||
|
||||
public static final String path = SGM.getInstance().getDataFolder().getPath() + "/levels/";
|
||||
|
||||
public static final String gamePath = SGM.getInstance().getDataFolder().getPath() + "/games/";
|
||||
|
||||
public HashMap<String, List<String>> enabledMaps = new HashMap<>();
|
||||
|
||||
private static void loadWorld(String worldName) {
|
||||
|
@ -59,7 +61,7 @@ public class LevelManager {
|
|||
return CreationResult.UNKNOWN;
|
||||
}
|
||||
Location location = new Location(world, 0, 0, 0);
|
||||
Block block = location.subtract(0, 1, 0).getBlock();
|
||||
Block block = location.subtract(0, 2, 0).getBlock();
|
||||
block.setType(Material.STONE);
|
||||
world.setSpawnLocation(location);
|
||||
world.setSpawnFlags(false, false);
|
||||
|
|
Loading…
Reference in New Issue
Block a user