This commit is contained in:
2022-12-21 14:00:43 -05:00
parent 6c4776f88a
commit 23e5740ee1
12 changed files with 62 additions and 55 deletions

View File

@@ -2,6 +2,7 @@ package org.lunamc.letthemeatcake;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import java.util.ArrayList;
import java.util.List;
@@ -11,10 +12,18 @@ public class Game {
private boolean openStatus;
private List<Player> players;
private BukkitTask queueTimer;
public Game(JavaPlugin plugin) {
this.plugin = plugin;
openStatus = true;
players = new ArrayList<>();
startQueueTimer();
queueTimer.cancel();
}
public List<Player> getPlayers() {
return players;
}
/**
@@ -23,6 +32,10 @@ public class Game {
* @return 0 if the player has been added, 1 if the game is full
*/
public int addPlayer(Player player) {
if (players.size() >= 2 || queueTimer.isCancelled()) {
startQueueTimer();
}
players.add(player);
if (players.size() == 8) {
openStatus = false;
@@ -65,6 +78,17 @@ public class Game {
return 1;
}
public void startQueueTimer() {
queueTimer = plugin.getServer().getScheduler().runTaskLater(
plugin,
() -> {
openStatus = false;
start();
},
200L
);
}
public void start() {
openStatus = false;
}

View File

@@ -1,20 +0,0 @@
package org.lunamc.letthemeatcake;
import java.util.ArrayList;
import java.util.List;
public class GamesManager {
private static List<Game> games = new ArrayList<>();
public static void addToGame() {
for (Game game : games) {
if (game.isOpen()) {
switch (game.addPlayers()) {
case 0: {} // Success
case 1: {} // Full
case 2: {} // Success and Full
}
}
}
}
}

View File

@@ -7,8 +7,14 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class JoinGameCommand implements CommandExecutor {
private static List<Game> games = new ArrayList<>();
private static List<Player> playerQueue = new ArrayList<>();
private final JavaPlugin plugin;
public JoinGameCommand(JavaPlugin plugin) {
@@ -18,9 +24,12 @@ public class JoinGameCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (sender instanceof Player player) {
for (Game game : games) {
if (game.isOpen()) {
game.addPlayer(player);
}
}
}
return true;
}
}

View File

@@ -1,10 +1,7 @@
package org.lunamc.letthemeatcake;
import com.grinderwolf.swm.api.SlimePlugin;
import com.grinderwolf.swm.api.exceptions.CorruptedWorldException;
import com.grinderwolf.swm.api.exceptions.NewerFormatException;
import com.grinderwolf.swm.api.exceptions.UnknownWorldException;
import com.grinderwolf.swm.api.exceptions.WorldInUseException;
import com.grinderwolf.swm.api.exceptions.*;
import com.grinderwolf.swm.api.loaders.SlimeLoader;
import com.grinderwolf.swm.api.world.SlimeWorld;
import com.grinderwolf.swm.api.world.properties.SlimeProperties;
@@ -12,6 +9,7 @@ import com.grinderwolf.swm.api.world.properties.SlimePropertyMap;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
public final class LetThemEatCake extends JavaPlugin {
@@ -22,7 +20,8 @@ public final class LetThemEatCake extends JavaPlugin {
@Override
public void onEnable() {
this.getCommand("join").setExecutor(new JoinGameCommand(this));
loadSWM();
}
@Override
@@ -38,11 +37,18 @@ public final class LetThemEatCake extends JavaPlugin {
swm = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager");
swmLoader = swm.getLoader("file");
File worldDir = new File(new File("").getAbsolutePath().replace('\\', '/') + "/import_worlds/");
worldDir.mkdirs();
System.out.println(worldDir.getAbsolutePath());
try {
swmWorld = swm.loadWorld(swmLoader, "map", true, properties);
swm.importWorld(new File(worldDir.getAbsolutePath().replace('\\', '/') + "/steve"), "steve", swmLoader);
swmWorld = swm.loadWorld(swmLoader, "steve", true, properties);
swm.generateWorld(swmWorld);
} catch (UnknownWorldException | IOException | CorruptedWorldException | NewerFormatException | WorldInUseException e) {
e.printStackTrace();
} catch (InvalidWorldException | WorldLoadedException | WorldAlreadyExistsException | WorldTooBigException e) {
throw new RuntimeException(e);
}
}
}