Merge pull request 'merge' (#1) from guis into main
Some checks are pending
Build plugin / build (push) Waiting to run
Some checks are pending
Build plugin / build (push) Waiting to run
Reviewed-on: #1
This commit is contained in:
commit
1e74824274
34
pom.xml
34
pom.xml
|
@ -67,11 +67,20 @@
|
|||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>xyz.twovb.toolbox</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}.toolbox</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.github.stefvanschie.inventoryframework</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}.inventoryframework</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.megavex.scoreboardlibrary</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}.scoreboardlibrary</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -159,7 +168,30 @@
|
|||
<artifactId>commons-io</artifactId>
|
||||
<version>2.16.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.stefvanschie.inventoryframework</groupId>
|
||||
<artifactId>IF</artifactId>
|
||||
<version>0.10.15</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.megavex</groupId>
|
||||
<artifactId>scoreboard-library-api</artifactId>
|
||||
<version>2.1.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.megavex</groupId>
|
||||
<artifactId>scoreboard-library-implementation</artifactId>
|
||||
<version>2.1.10</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.megavex</groupId>
|
||||
<artifactId>scoreboard-library-modern</artifactId>
|
||||
<version>2.1.10</version>
|
||||
<scope>runtime</scope>
|
||||
<!-- For a Mojang mapped variant, uncomment line below (only use if you know what you're doing!): -->
|
||||
<!-- <classifier>mojmap</classifier> -->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
package xyz.twovb.sgm;
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
import dev.rollczi.litecommands.bukkit.LiteBukkitMessages;
|
||||
import dev.rollczi.litecommands.bukkit.LiteCommandsBukkit;
|
||||
import lombok.Getter;
|
||||
import net.megavex.scoreboardlibrary.api.ScoreboardLibrary;
|
||||
import net.megavex.scoreboardlibrary.api.exception.NoPacketAdapterAvailableException;
|
||||
import net.megavex.scoreboardlibrary.api.noop.NoopScoreboardLibrary;
|
||||
import net.megavex.scoreboardlibrary.api.team.TeamManager;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
@ -40,6 +49,10 @@ public final class SGM extends JavaPlugin {
|
|||
@Getter
|
||||
private LevelManager levelManager;
|
||||
|
||||
@Getter
|
||||
private ScoreboardLibrary scoreboardLibrary;
|
||||
@Getter
|
||||
private TeamManager teamManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
@ -55,12 +68,32 @@ public final class SGM extends JavaPlugin {
|
|||
BuildInfo.load(Objects.requireNonNull(this.getTextResource("build-info.yml")));
|
||||
} catch (IOException | InvalidConfigurationException ignored) {
|
||||
}
|
||||
loadScoreboard();
|
||||
loadGuis();
|
||||
registerCommands();
|
||||
registerGames();
|
||||
registerPlaceholders();
|
||||
levelManager.loadLevels();
|
||||
}
|
||||
|
||||
private void loadScoreboard() {
|
||||
try {
|
||||
scoreboardLibrary = ScoreboardLibrary.loadScoreboardLibrary(this);
|
||||
} catch (NoPacketAdapterAvailableException e) {
|
||||
// If no packet adapter was found, you can fallback to the no-op implementation:
|
||||
scoreboardLibrary = new NoopScoreboardLibrary();
|
||||
this.getCLogger().error("No scoreboard packet adapter found.");
|
||||
}
|
||||
}
|
||||
|
||||
private void loadGuis() {
|
||||
saveResource("guis/initgame.xml", false);
|
||||
saveResource("guis/mapgui.xml", false);
|
||||
saveResource("guis/teampicker.xml", false);
|
||||
saveResource("guis/activegames.xml", false);
|
||||
saveResource("guis/joingame.xml", false);
|
||||
}
|
||||
|
||||
private void registerPlaceholders() {
|
||||
PlaceholderManager pm = new PlaceholderManager();
|
||||
pm.registerPlaceholder("%commit.id%", BuildInfo.getString("commit.id"));
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
package xyz.twovb.sgm.commands.impl;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
/*
|
||||
* Created by 2vb - 2/7/2024
|
||||
*/
|
||||
|
@ -13,11 +24,13 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.entity.Player;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.Minigame;
|
||||
import xyz.twovb.sgm.games.impl.TestGame;
|
||||
import xyz.twovb.sgm.games.impl.capturethebrick.CTB;
|
||||
import xyz.twovb.sgm.games.impl.capturethebrick.guis.TeamGui;
|
||||
import xyz.twovb.sgm.guis.InitGameGui;
|
||||
import xyz.twovb.sgm.guis.JoinGameGui;
|
||||
import xyz.twovb.toolbox.api.CustomPlayer;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Command(name = "game")
|
||||
|
@ -40,9 +53,10 @@ public class GameCommand {
|
|||
|
||||
@Execute(name = "init")
|
||||
@Permission("sgm.games.init")
|
||||
void init(@Context Player player, @Arg("name") String name) {
|
||||
void init(@Context Player player, @Arg("name") Optional<String> map) {
|
||||
CustomPlayer cPlayer = new CustomPlayer(player);
|
||||
SGM.getInstance().getGameManager().initGame(new CTB(), player, name);
|
||||
new InitGameGui().getGui().show(player);
|
||||
// SGM.getInstance().getGameManager().initGame(new CTB(), player, name);
|
||||
}
|
||||
|
||||
@Execute(name = "start")
|
||||
|
@ -53,6 +67,19 @@ public class GameCommand {
|
|||
game.start();
|
||||
}
|
||||
|
||||
@Execute(name = "team join")
|
||||
@Permission("sgm.games.team")
|
||||
void teamJoin(@Context Player player, @Arg("player") Optional<Player> target) {
|
||||
// String name = LevelName.orElse(UUID.randomUUID().toString());
|
||||
Player targetPlayer = target.orElse(player);
|
||||
new TeamGui(targetPlayer).getGui().show(player);
|
||||
}
|
||||
|
||||
@Execute(name = "testjoin")
|
||||
void testjoin(@Context Player player) {
|
||||
new JoinGameGui().getGui().show(player);
|
||||
}
|
||||
|
||||
@Execute(name = "join")
|
||||
void join(@Context Player player, @Arg("id") String id) {
|
||||
CustomPlayer cPlayer = new CustomPlayer(player);
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package xyz.twovb.sgm.games;
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
/*
|
||||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
@ -11,8 +16,8 @@ import xyz.twovb.sgm.SGM;
|
|||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -25,19 +30,12 @@ public class GameManager {
|
|||
@Getter
|
||||
private final ArrayList<String> registeredGames = new ArrayList<String>();
|
||||
|
||||
private final Map<String, Class<? extends Minigame>> gameMappings = new HashMap<>();
|
||||
|
||||
public static Minigame findGame(UUID gameId) {
|
||||
return activeGames.get(gameId);
|
||||
}
|
||||
|
||||
public Minigame findGame(Player player) {
|
||||
for (Minigame game : activeGames.values()) {
|
||||
if (game.getPlayers().contains(player)) {
|
||||
return game;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isInGame(Player player) {
|
||||
for (Minigame game : activeGames.values()) {
|
||||
if (game.getPlayers().contains(player)) {
|
||||
|
@ -47,16 +45,37 @@ public class GameManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void initGame(Minigame game, CommandSender owner, String level) {
|
||||
public Minigame findGame(Player player) {
|
||||
for (Minigame game : activeGames.values()) {
|
||||
if (game.getPlayers().contains(player)) {
|
||||
return game;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void initGame(String internalName, CommandSender owner, String level) {
|
||||
try {
|
||||
Minigame game = createGameInstance(internalName);
|
||||
game.init(owner, level);
|
||||
} catch (IOException e) {
|
||||
activeGames.put(game.getGameId(), game);
|
||||
} catch (InstantiationException | IllegalAccessException | IOException | NoSuchMethodException |
|
||||
InvocationTargetException 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);
|
||||
}
|
||||
|
||||
// public void initGame(Minigame game, CommandSender owner, String 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);
|
||||
// }
|
||||
|
||||
public void addPlayerToGame(Player player, UUID gameId) {
|
||||
Minigame game = findGame(gameId);
|
||||
if (game.getState() == Minigame.GameState.READY && !game.getPlayers().contains(player) && !isInGame(player)) {
|
||||
|
@ -69,17 +88,28 @@ public class GameManager {
|
|||
game.removePlayer(player);
|
||||
}
|
||||
|
||||
public Minigame createGameInstance(String internalName) throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
|
||||
Class<? extends Minigame> gameClass = gameMappings.get(internalName);
|
||||
if (gameClass != null) {
|
||||
return gameClass.getDeclaredConstructor().newInstance();
|
||||
} else {
|
||||
throw new IllegalArgumentException("No game registered with internal name: " + internalName);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerGame(Minigame game) {
|
||||
String intName = game.getName().toLowerCase();
|
||||
try {
|
||||
SGM.getInstance().getConfigManager().loadConfig("games/" + intName + "/options.yml");
|
||||
registeredGames.add(intName);
|
||||
gameMappings.put(intName, game.getClass());
|
||||
SGM.getInstance().getCLogger().log("Registered game " + game.getName());
|
||||
} catch(IllegalArgumentException error) {
|
||||
} catch (IllegalArgumentException error) {
|
||||
String errMsg = error.getMessage();
|
||||
if (errMsg.contains("The embedded resource") && errMsg.contains("cannot be found")) {
|
||||
SGM.getInstance().getCLogger().log(game.getName() + "'s game options are nowhere to be found. Please ensure this is intended behaviour.");
|
||||
registeredGames.add(intName);
|
||||
gameMappings.put(intName, game.getClass());
|
||||
} else {
|
||||
SGM.getInstance().getCLogger().error("Failed to register game " + game.getName() + ". Reason: " + errMsg);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package xyz.twovb.sgm.games;
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
/*
|
||||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
@ -9,7 +14,6 @@ import org.bukkit.NamespacedKey;
|
|||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
|
@ -43,6 +47,8 @@ public interface Minigame extends Listener {
|
|||
|
||||
GameState getState();
|
||||
|
||||
World getWorld();
|
||||
|
||||
default void sendMessageToAllPlayers(String message) {
|
||||
for (Player player : getPlayers()) {
|
||||
CustomPlayer cPlayer = new CustomPlayer(player);
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package xyz.twovb.sgm.games.impl;
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
/*
|
||||
* Created by 2vb - 26/6/2024
|
||||
*/
|
||||
|
@ -117,6 +122,12 @@ public class TestGame implements Minigame {
|
|||
return state;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return gameWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
if (state == GameState.STARTED && players.size() <= 1) {
|
||||
|
|
|
@ -1,9 +1,31 @@
|
|||
package xyz.twovb.sgm.games.impl.capturethebrick;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 3/7/2024
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.Sidebar;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.component.ComponentSidebarLayout;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.component.SidebarComponent;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.component.animation.CollectionSidebarAnimation;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.component.animation.SidebarAnimation;
|
||||
import net.megavex.scoreboardlibrary.api.team.ScoreboardTeam;
|
||||
import net.megavex.scoreboardlibrary.api.team.TeamDisplay;
|
||||
import net.megavex.scoreboardlibrary.api.team.TeamManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
@ -11,16 +33,21 @@ import org.bukkit.World;
|
|||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.GameManager;
|
||||
import xyz.twovb.sgm.games.Minigame;
|
||||
import xyz.twovb.sgm.levels.LevelManager;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -35,18 +62,33 @@ public class CTB implements Minigame {
|
|||
private final ArrayList<Location> blueBrickSpawns = new ArrayList<Location>();
|
||||
private final ArrayList<Location> redSpawnArea = new ArrayList<Location>();
|
||||
private final ArrayList<Location> blueSpawnArea = new ArrayList<Location>();
|
||||
private final FileConfiguration messages;
|
||||
private World gameWorld;
|
||||
private GameState state;
|
||||
private int bricks;
|
||||
private int territoryLevel;
|
||||
private int boundsLevel;
|
||||
private Location spawnLoc;
|
||||
private TeamManager teamManager;
|
||||
private ScoreboardTeam redTeam;
|
||||
private ScoreboardTeam blueTeam;
|
||||
private Sidebar sb;
|
||||
private SidebarAnimation<Component> titleAnimation;
|
||||
// private @NotNull SidebarComponent title;
|
||||
private ComponentSidebarLayout layout;
|
||||
|
||||
private int taskId;
|
||||
|
||||
// private List<Player> redTeam = new ArrayList<Player>();
|
||||
// private List<Player> blueTeam = new ArrayList<Player>();
|
||||
// private Sidebar sb;
|
||||
|
||||
|
||||
public CTB() {
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.state = GameState.PRESTART;
|
||||
this.players = new ArrayList<>();
|
||||
this.messages = SGM.getInstance().getConfigManager().loadConfig("games/" + name.toLowerCase() + "/messages.yml");
|
||||
}
|
||||
|
||||
public void init(CommandSender owner, String world) throws IOException {
|
||||
|
@ -54,14 +96,65 @@ public class CTB implements Minigame {
|
|||
gameWorld = createGameWorld(world, uuid);
|
||||
gameWorld.setAutoSave(false);
|
||||
if (applyOptions(world)) {
|
||||
teamManager = SGM.getInstance().getScoreboardLibrary().createTeamManager();
|
||||
this.redTeam = teamManager.createIfAbsent("red_team");
|
||||
this.blueTeam = teamManager.createIfAbsent("blue_team");
|
||||
Bukkit.getPluginManager().registerEvents(this, SGM.getInstance());
|
||||
|
||||
setupTeamDisplay(redTeam, "Red Team", NamedTextColor.RED);
|
||||
setupTeamDisplay(blueTeam, "Blue Team", NamedTextColor.BLUE);
|
||||
|
||||
this.sb = SGM.getInstance().getScoreboardLibrary().createSidebar();
|
||||
this.titleAnimation = createGradientAnimation(Component.text("Capture The Brick", Style.style(TextDecoration.BOLD)));
|
||||
var title = SidebarComponent.animatedLine(titleAnimation);
|
||||
|
||||
SidebarComponent gameInfo = SidebarComponent.builder().addDynamicLine(() -> Component.text("Players Alive: " + getAlivePlayersCount(), NamedTextColor.YELLOW)).addDynamicLine(() -> Component.text("Red Team: " + getTeamSize(redTeam), NamedTextColor.RED)).addDynamicLine(() -> Component.text("Blue Team: " + getTeamSize(blueTeam), NamedTextColor.BLUE)).addDynamicLine(() -> Component.text("Bricks Remaining: " + bricks, NamedTextColor.GREEN)).build();
|
||||
|
||||
this.layout = new ComponentSidebarLayout(title, gameInfo);
|
||||
layout.apply(sb);
|
||||
|
||||
// buildScoreboard();
|
||||
// Ready
|
||||
state = GameState.READY;
|
||||
owner.sendMessage("A new " + name + " instance with ID " + uuid + " has been created and is now ready!");
|
||||
owner.sendMessage(ChatUtils.translate(messages.getString("system.game.ready").replace("%game%", name)));
|
||||
} else {
|
||||
owner.sendMessage("a");
|
||||
// owner.sendMessage(ChatUtils.translate(SGM.getInstance().getMessages().getString("sgm.game.cant-start")));
|
||||
owner.sendMessage(ChatUtils.translate(messages.getString("system.game.failed").replace("%cause%", "to load options.")));
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupTeamDisplay(ScoreboardTeam team, String displayName, NamedTextColor color) {
|
||||
TeamDisplay display = team.defaultDisplay();
|
||||
display.displayName(Component.text(displayName));
|
||||
display.playerColor(color);
|
||||
}
|
||||
|
||||
// private void buildScoreboard() {
|
||||
// titleAnimation = createGradientAnimation(Component.text("Capture The Brick", Style.style(TextDecoration.BOLD)));
|
||||
// title = SidebarComponent.animatedLine(titleAnimation);
|
||||
// SidebarComponent lines = SidebarComponent.builder().addDynamicLine(() -> Component.text("Red Team: " + redTeam.teamManager().players().size(), NamedTextColor.RED)).addDynamicLine(() -> Component.text("Blue Team: " + blueTeam.teamManager().players().size(), NamedTextColor.BLUE)).addDynamicLine(() -> Component.text("Bricks Remaining: " + bricks, NamedTextColor.GREEN)).build();
|
||||
// layout = new ComponentSidebarLayout(title, lines);
|
||||
// layout.apply(sb);
|
||||
// }
|
||||
|
||||
private @NotNull SidebarAnimation<Component> createGradientAnimation(@NotNull Component text) {
|
||||
float step = 1f / 8f;
|
||||
TagResolver.Single textPlaceholder = Placeholder.component("text", text);
|
||||
List<Component> frames = new ArrayList<>((int) (2f / step));
|
||||
float phase = -1f;
|
||||
|
||||
SGM.getInstance().getCLogger().log("Creating gradient animation");
|
||||
|
||||
while (phase <= 1) {
|
||||
String gradientTag = String.format("<gradient:yellow:gold:%.2f>", phase);
|
||||
Component frame = MiniMessage.miniMessage().deserialize(gradientTag + "<text>", textPlaceholder);
|
||||
frames.add(frame);
|
||||
SGM.getInstance().getCLogger().log("Phase: " + phase + ", Tag: " + gradientTag);
|
||||
phase += step;
|
||||
}
|
||||
|
||||
SGM.getInstance().getCLogger().log("Total frames: " + frames.size());
|
||||
return new CollectionSidebarAnimation<>(frames);
|
||||
}
|
||||
|
||||
private Location parseString(String string) {
|
||||
|
@ -146,8 +239,9 @@ public class CTB implements Minigame {
|
|||
sendMessageToAllPlayers("The game has started!");
|
||||
for (Player player : players) {
|
||||
player.teleport(this.spawnLoc);
|
||||
sb.addPlayer(player);
|
||||
}
|
||||
for (int i = 0; i < bricks; i++) {
|
||||
for (int i = 0; i <= bricks; i++) {
|
||||
for (Location brickLoc : redBrickSpawns) {
|
||||
placeBrick(brickLoc, "red");
|
||||
}
|
||||
|
@ -155,10 +249,35 @@ public class CTB implements Minigame {
|
|||
placeBrick(brickLoc, "blue");
|
||||
}
|
||||
}
|
||||
Bukkit.getScheduler().runTaskTimer(SGM.getInstance(), this::onTick, 0L, 1L);
|
||||
BukkitTask task = Bukkit.getScheduler().runTaskTimer(SGM.getInstance(), this::onTick, 0L, 1L);
|
||||
this.taskId = task.getTaskId();
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayerToTeam(Player player, boolean isRedTeam) {
|
||||
//TODO: make this shit fuckin better bor
|
||||
if (isRedTeam) {
|
||||
redTeam.defaultDisplay().addEntry(player.getName());
|
||||
} else {
|
||||
blueTeam.defaultDisplay().addEntry(player.getName());
|
||||
}
|
||||
teamManager.addPlayer(player);
|
||||
}
|
||||
|
||||
public void removePlayerFromTeams(Player player) {
|
||||
redTeam.defaultDisplay().removeEntry(player.getName());
|
||||
blueTeam.defaultDisplay().removeEntry(player.getName());
|
||||
teamManager.removePlayer(player);
|
||||
}
|
||||
|
||||
public int getAlivePlayersCount() {
|
||||
return (int) players.stream().filter(Player::isOnline).count();
|
||||
}
|
||||
|
||||
public int getTeamSize(ScoreboardTeam team) {
|
||||
return team.defaultDisplay().entries().size();
|
||||
}
|
||||
|
||||
private void placeBrick(Location location, String team) {
|
||||
Block brick = location.getBlock();
|
||||
if (Objects.equals(team, "red")) {
|
||||
|
@ -172,6 +291,7 @@ public class CTB implements Minigame {
|
|||
|
||||
@Override
|
||||
public void stop() {
|
||||
// TODO: make it wait before unloading world
|
||||
// Stop game logic
|
||||
state = GameState.ENDING;
|
||||
Player winner;
|
||||
|
@ -186,18 +306,28 @@ public class CTB implements Minigame {
|
|||
player.teleport(Bukkit.getServer().getWorlds().get(0).getSpawnLocation());
|
||||
}
|
||||
Bukkit.unloadWorld(gameWorld, false);
|
||||
if (teamManager != null) {
|
||||
teamManager.close();
|
||||
}
|
||||
if (sb != null) {
|
||||
sb.close();
|
||||
}
|
||||
Bukkit.getScheduler().cancelTask(this.taskId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(Player player) {
|
||||
players.add(player);
|
||||
// sb.addPlayer(player);
|
||||
player.teleport(this.spawnLoc);
|
||||
sendMessageToAllPlayers(player.getName() + " has joined the game!");
|
||||
sendMessageToAllPlayers(messages.getString("system.player.join").replace("%player%", player.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlayer(Player player) {
|
||||
players.remove(player);
|
||||
sb.removePlayer(player);
|
||||
sendMessageToAllPlayers(messages.getString("system.player.left").replace("%player%", player.getName()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -208,6 +338,14 @@ public class CTB implements Minigame {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onWorldChange(PlayerChangedWorldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (players.contains(player)) {
|
||||
removePlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
@ -238,21 +376,26 @@ public class CTB implements Minigame {
|
|||
return state;
|
||||
}
|
||||
|
||||
// @EventHandler
|
||||
// void onPlayerMove(PlayerMoveEvent event) {
|
||||
// Player player = event.getPlayer();
|
||||
// CustomPlayer cPlayer = new CustomPlayer(player);
|
||||
// cPlayer.sendMessage("move");
|
||||
// if (event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ()) {
|
||||
// cPlayer.sendMessage("move full block");
|
||||
// }
|
||||
// }
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return gameWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
for (Player player : gameWorld.getPlayers()) {
|
||||
if (!players.contains(player)) {
|
||||
sendMessageToAllPlayers(player.getName() + " IS A IMPOSTER");
|
||||
}
|
||||
}
|
||||
if (state == GameState.STARTED && players.size() <= 1) {
|
||||
this.stop();
|
||||
}
|
||||
try {
|
||||
titleAnimation.nextFrame();
|
||||
layout.apply(sb);
|
||||
} catch (IllegalStateException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package xyz.twovb.sgm.games.impl.capturethebrick.guis;
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.impl.capturethebrick.CTB;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TeamGui {
|
||||
@Getter
|
||||
private final ChestGui gui;
|
||||
|
||||
private Player target;
|
||||
|
||||
public TeamGui(Player player) {
|
||||
ChestGui loadedGui = null;
|
||||
try {
|
||||
File guiFile = new File(SGM.getInstance().getDataFolder(), "guis/teampicker.xml");
|
||||
if (guiFile.exists()) {
|
||||
byte[] fileContent = Files.readAllBytes(guiFile.toPath());
|
||||
InputStream inputStream = new ByteArrayInputStream(fileContent);
|
||||
loadedGui = ChestGui.load(this, inputStream);
|
||||
} else {
|
||||
SGM.getInstance().getLogger().log(Level.WARNING, "Could not find teampicker.xml file.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SGM.getInstance().getLogger().log(Level.SEVERE, "Error loading teampicker.xml", e);
|
||||
}
|
||||
gui = loadedGui;
|
||||
target = player;
|
||||
}
|
||||
|
||||
public void globalClick(InventoryClickEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void pickTeam(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
ItemStack clickedItem = event.getCurrentItem();
|
||||
CTB game = (CTB) SGM.getInstance().getGameManager().findGame(player);
|
||||
if (clickedItem.getType().equals(Material.RED_WOOL)) {
|
||||
game.addPlayerToTeam(target, true);
|
||||
game.sendMessageToAllPlayers(target.getName() + " RED");
|
||||
} else if (clickedItem.getType().equals(Material.BLUE_WOOL)) {
|
||||
game.addPlayerToTeam(target, false);
|
||||
game.sendMessageToAllPlayers(target.getName() + " BLUE");
|
||||
}
|
||||
}
|
||||
}
|
110
src/main/java/xyz/twovb/sgm/guis/ActiveGamesGui.java
Normal file
110
src/main/java/xyz/twovb/sgm/guis/ActiveGamesGui.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
package xyz.twovb.sgm.guis;
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
||||
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.GameManager;
|
||||
import xyz.twovb.sgm.games.Minigame;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ActiveGamesGui {
|
||||
|
||||
@Getter
|
||||
private final ChestGui gui;
|
||||
|
||||
private final String game;
|
||||
private OutlinePane mapPane;
|
||||
|
||||
public ActiveGamesGui(String game) {
|
||||
this.game = game;
|
||||
ChestGui loadedGui = null;
|
||||
try {
|
||||
File guiFile = new File(SGM.getInstance().getDataFolder(), "guis/activegames.xml");
|
||||
if (guiFile.exists()) {
|
||||
byte[] fileContent = Files.readAllBytes(guiFile.toPath());
|
||||
InputStream inputStream = new ByteArrayInputStream(fileContent);
|
||||
loadedGui = ChestGui.load(this, inputStream);
|
||||
mapPane = new OutlinePane(1, 1, 7, 1); // Define your pane layout
|
||||
loadedGui.addPane(mapPane);
|
||||
addMaps();
|
||||
} else {
|
||||
SGM.getInstance().getLogger().log(Level.WARNING, "Could not find activegames.xml file.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SGM.getInstance().getLogger().log(Level.SEVERE, "Error loading activegames.xml", e);
|
||||
}
|
||||
gui = loadedGui;
|
||||
}
|
||||
|
||||
public void globalClick(InventoryClickEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void addMaps() {
|
||||
for (Minigame game : GameManager.getActiveGames().values()) {
|
||||
// SGM.getInstance().getCLogger().log(game.getName());
|
||||
// SGM.getInstance().getCLogger().log(this.game);
|
||||
Material itemType;
|
||||
switch (game.getState()) {
|
||||
case PRESTART:
|
||||
// mapItem.setType(Material.YELLOW_WOOL);
|
||||
itemType = Material.YELLOW_WOOL;
|
||||
break;
|
||||
case READY:
|
||||
// mapItem.setType(Material.LIME_WOOL);
|
||||
itemType = Material.LIME_WOOL;
|
||||
break;
|
||||
case STARTED:
|
||||
case ENDING:
|
||||
default:
|
||||
// mapItem.setType(Material.RED_WOOL);
|
||||
itemType = Material.RED_WOOL;
|
||||
break;
|
||||
}
|
||||
ItemStack joinItem = new ItemStack(itemType);
|
||||
ItemMeta meta = joinItem.getItemMeta();
|
||||
meta.displayName(ChatUtils.translate(game.getName()));
|
||||
List<Component> lore = new ArrayList<Component>();
|
||||
lore.add(0, ChatUtils.translate("&r&7" + game.getGameId().toString()));
|
||||
if (!game.getPlayers().isEmpty()) {
|
||||
lore.add(ChatUtils.translate("&r&7Players:"));
|
||||
for (Player player : game.getPlayers()) {
|
||||
lore.add(ChatUtils.translate("&r&a" + player.getName()));
|
||||
}
|
||||
}
|
||||
meta.lore(lore);
|
||||
joinItem.setItemMeta(meta);
|
||||
mapPane.addItem(new GuiItem(joinItem, event -> {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (game.getState() == Minigame.GameState.READY) {
|
||||
SGM.getInstance().getGameManager().addPlayerToGame(player, game.getGameId());
|
||||
}
|
||||
player.closeInventory();
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
55
src/main/java/xyz/twovb/sgm/guis/InitGameGui.java
Normal file
55
src/main/java/xyz/twovb/sgm/guis/InitGameGui.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
package xyz.twovb.sgm.guis;
|
||||
/*
|
||||
* Created by 2vb - 4/7/2024
|
||||
*/
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.impl.capturethebrick.CTB;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class InitGameGui {
|
||||
|
||||
@Getter
|
||||
private final ChestGui gui;
|
||||
|
||||
public InitGameGui() {
|
||||
ChestGui loadedGui = null;
|
||||
try {
|
||||
File guiFile = new File(SGM.getInstance().getDataFolder(), "guis/initgame.xml");
|
||||
if (guiFile.exists()) {
|
||||
byte[] fileContent = Files.readAllBytes(guiFile.toPath());
|
||||
InputStream inputStream = new ByteArrayInputStream(fileContent);
|
||||
loadedGui = ChestGui.load(this, inputStream);
|
||||
} else {
|
||||
SGM.getInstance().getLogger().log(Level.WARNING, "Could not find initgame.xml file.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SGM.getInstance().getLogger().log(Level.SEVERE, "Error loading initgame.xml", e);
|
||||
}
|
||||
gui = loadedGui;
|
||||
}
|
||||
|
||||
public void globalClick(InventoryClickEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void initGame(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
String itemName = event.getCurrentItem().getItemMeta().getDisplayName().replaceAll("\\W+", "");
|
||||
player.closeInventory();
|
||||
if (SGM.getInstance().getGameManager().getRegisteredGames().contains(itemName.toLowerCase())) {
|
||||
new MapGui(itemName.toLowerCase()).getGui().show(player);
|
||||
} else {
|
||||
player.sendMessage("Please check xml");
|
||||
}
|
||||
}
|
||||
}
|
59
src/main/java/xyz/twovb/sgm/guis/JoinGameGui.java
Normal file
59
src/main/java/xyz/twovb/sgm/guis/JoinGameGui.java
Normal file
|
@ -0,0 +1,59 @@
|
|||
package xyz.twovb.sgm.guis;
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class JoinGameGui {
|
||||
|
||||
@Getter
|
||||
private final ChestGui gui;
|
||||
|
||||
public JoinGameGui() {
|
||||
ChestGui loadedGui = null;
|
||||
try {
|
||||
File guiFile = new File(SGM.getInstance().getDataFolder(), "guis/joingame.xml");
|
||||
if (guiFile.exists()) {
|
||||
byte[] fileContent = Files.readAllBytes(guiFile.toPath());
|
||||
InputStream inputStream = new ByteArrayInputStream(fileContent);
|
||||
loadedGui = ChestGui.load(this, inputStream);
|
||||
} else {
|
||||
SGM.getInstance().getLogger().log(Level.WARNING, "Could not find joingame.xml file.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SGM.getInstance().getLogger().log(Level.SEVERE, "Error loading joingame.xml", e);
|
||||
}
|
||||
gui = loadedGui;
|
||||
}
|
||||
|
||||
public void globalClick(InventoryClickEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void joinGame(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
String itemName = event.getCurrentItem().getItemMeta().getDisplayName().replaceAll("\\W+", "");
|
||||
player.closeInventory();
|
||||
if (SGM.getInstance().getGameManager().getRegisteredGames().contains(itemName.toLowerCase())) {
|
||||
new ActiveGamesGui(itemName).getGui().show(player);
|
||||
} else {
|
||||
player.sendMessage("Please check xml");
|
||||
}
|
||||
}
|
||||
}
|
82
src/main/java/xyz/twovb/sgm/guis/MapGui.java
Normal file
82
src/main/java/xyz/twovb/sgm/guis/MapGui.java
Normal file
|
@ -0,0 +1,82 @@
|
|||
package xyz.twovb.sgm.guis;
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
||||
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MapGui {
|
||||
|
||||
@Getter
|
||||
private final ChestGui gui;
|
||||
|
||||
private final String game;
|
||||
private OutlinePane mapPane;
|
||||
|
||||
public MapGui(String game) {
|
||||
this.game = game;
|
||||
ChestGui loadedGui = null;
|
||||
try {
|
||||
File guiFile = new File(SGM.getInstance().getDataFolder(), "guis/mapgui.xml");
|
||||
if (guiFile.exists()) {
|
||||
byte[] fileContent = Files.readAllBytes(guiFile.toPath());
|
||||
InputStream inputStream = new ByteArrayInputStream(fileContent);
|
||||
loadedGui = ChestGui.load(this, inputStream);
|
||||
mapPane = new OutlinePane(1, 1, 7, 1); // Define your pane layout
|
||||
loadedGui.addPane(mapPane);
|
||||
addMaps();
|
||||
} else {
|
||||
SGM.getInstance().getLogger().log(Level.WARNING, "Could not find mapgui.xml file.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SGM.getInstance().getLogger().log(Level.SEVERE, "Error loading mapgui.xml", e);
|
||||
}
|
||||
gui = loadedGui;
|
||||
}
|
||||
|
||||
public void globalClick(InventoryClickEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void addMaps() {
|
||||
List<String> enabledMaps = SGM.getInstance().getLevelManager().enabledMaps.get(this.game);
|
||||
if (enabledMaps != null) {
|
||||
for (String mapName : enabledMaps) {
|
||||
// Create button for each map
|
||||
ItemStack mapItem = new ItemStack(Material.MAP);
|
||||
ItemMeta mapMeta = mapItem.getItemMeta();
|
||||
mapMeta.setDisplayName(mapName);
|
||||
mapItem.setItemMeta(mapMeta);
|
||||
|
||||
mapPane.addItem(new GuiItem(mapItem, event -> {
|
||||
// Handle click event if needed
|
||||
// Example: navigate to the map or show map details
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
SGM.getInstance().getGameManager().initGame(this.game, player, mapName);
|
||||
player.closeInventory();
|
||||
// player.sendMessage("Clicked on map: " + mapName);
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
SGM.getInstance().getLogger().log(Level.WARNING, "No maps found for game: " + game);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,16 @@
|
|||
package xyz.twovb.sgm.levels;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
/*
|
||||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
@ -108,6 +119,7 @@ public class LevelManager {
|
|||
File yamlFile = new File(path, "sgm.yml");
|
||||
try (FileWriter writer = new FileWriter(yamlFile)) {
|
||||
yaml.dump(data, writer);
|
||||
this.cancel();
|
||||
} catch (IOException e) {
|
||||
SGM.getInstance().getCLogger().error("Error writing data file: " + e.getMessage());
|
||||
}
|
||||
|
@ -130,10 +142,20 @@ public class LevelManager {
|
|||
// This is probably gonna be funny later
|
||||
player.teleport(Bukkit.getServer().getWorlds().get(0).getSpawnLocation());
|
||||
}
|
||||
// TODO: make better
|
||||
if (!Bukkit.isTickingWorlds() && Bukkit.getServer().unloadWorld(world, true)) {
|
||||
if (mapDir.exists()) {
|
||||
FileUtils.deleteDirectory(mapDir);
|
||||
}
|
||||
File configFile = new File(levelDir + "/sgm.yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
String gameIntName = config.getString("game");
|
||||
if (SGM.getInstance().getGameManager().getRegisteredGames().contains(gameIntName)) {
|
||||
List<String> maps = enabledMaps.get(gameIntName);
|
||||
if (!maps.contains(name)) {
|
||||
enabledMaps.get(gameIntName).add(name);
|
||||
}
|
||||
}
|
||||
FileUtils.copyDirectory(levelDir, mapDir);
|
||||
FileUtils.delete(new File(mapDir + "/uid.dat"));
|
||||
loadWorld(name, LevelType.LEVEL);
|
||||
|
@ -170,8 +192,6 @@ public class LevelManager {
|
|||
block.setType(Material.STONE);
|
||||
}
|
||||
}
|
||||
// Block block = location.subtract(0, 2, 0).getBlock();
|
||||
// block.setType(Material.STONE);
|
||||
world.setSpawnLocation(location);
|
||||
world.setSpawnFlags(false, false);
|
||||
world.setGameRule(GameRule.KEEP_INVENTORY, true);
|
||||
|
@ -190,6 +210,7 @@ public class LevelManager {
|
|||
|
||||
// Load levels from levelPath
|
||||
loadWorldDir(levelPath, LevelType.LEVEL);
|
||||
loadWorldDir(mapPath, LevelType.MAP);
|
||||
}
|
||||
|
||||
private void loadWorldDir(String path, LevelType levelType) {
|
||||
|
@ -208,8 +229,10 @@ public class LevelManager {
|
|||
if (enabledMaps.containsKey(game) && levelType == LevelType.MAP) {
|
||||
enabledMaps.get(game).add(name);
|
||||
}
|
||||
if (levelType == LevelType.LEVEL) {
|
||||
// Load the world if sgm.yml exists
|
||||
loadWorld(file.getName(), levelType);
|
||||
}
|
||||
} else {
|
||||
SGM.getInstance().getCLogger().log("Skipping directory " + file.getName() + ": sgm.yml not found.");
|
||||
}
|
||||
|
|
7
src/main/resources/games/capturethebrick/messages.yml
Normal file
7
src/main/resources/games/capturethebrick/messages.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
system:
|
||||
game:
|
||||
ready: "&7A new %game% game has started and can now be joined!"
|
||||
failed: "&7%game% failed %cause%"
|
||||
player:
|
||||
join: "&7%player% has joined the game!"
|
||||
left: "&7%player% has left the game."
|
13
src/main/resources/guis/activegames.xml
Normal file
13
src/main/resources/guis/activegames.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!--
|
||||
~ Created by 2vb - 5/7/2024
|
||||
-->
|
||||
|
||||
<!--
|
||||
~ Created by 2vb - 5/7/2024
|
||||
-->
|
||||
|
||||
<chestgui title="Active Games" rows="5" onGlobalClick="globalClick">
|
||||
<outlinepane x="0" y="0" length="9" height="5" priority="lowest" repeat="true">
|
||||
<item id="black_stained_glass_pane"/>
|
||||
</outlinepane>
|
||||
</chestgui>
|
19
src/main/resources/guis/initgame.xml
Normal file
19
src/main/resources/guis/initgame.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!--
|
||||
~ Created by 2vb - 4/7/2024
|
||||
-->
|
||||
|
||||
<chestgui title="New Game" rows="3" onGlobalClick="globalClick">
|
||||
<outlinepane x="0" y="0" length="9" height="3" priority="lowest" repeat="true">
|
||||
<item id="black_stained_glass_pane">
|
||||
<displayname> </displayname>
|
||||
</item>
|
||||
</outlinepane>
|
||||
<outlinepane x="3" y="1" length="3" height="1" gap="1">
|
||||
<item id="nether_brick" onClick="initGame">
|
||||
<displayname>Capture The Brick</displayname>
|
||||
</item>
|
||||
<item id="command_block" onClick="initGame">
|
||||
<displayname>TestGame</displayname>
|
||||
</item>
|
||||
</outlinepane>
|
||||
</chestgui>
|
23
src/main/resources/guis/joingame.xml
Normal file
23
src/main/resources/guis/joingame.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<!--
|
||||
~ Created by 2vb - 5/7/2024
|
||||
-->
|
||||
|
||||
<!--
|
||||
~ Created by 2vb - 5/7/2024
|
||||
-->
|
||||
|
||||
<chestgui title="Join Game" rows="3" onGlobalClick="globalClick">
|
||||
<outlinepane x="0" y="0" length="9" height="3" priority="lowest" repeat="true">
|
||||
<item id="black_stained_glass_pane">
|
||||
<displayname></displayname>
|
||||
</item>
|
||||
</outlinepane>
|
||||
<outlinepane x="3" y="1" length="3" height="1" gap="1">
|
||||
<item id="nether_brick" onClick="joinGame">
|
||||
<displayname>Capture The Brick</displayname>
|
||||
</item>
|
||||
<item id="command_block" onClick="joinGame">
|
||||
<displayname>TestGame</displayname>
|
||||
</item>
|
||||
</outlinepane>
|
||||
</chestgui>
|
9
src/main/resources/guis/mapgui.xml
Normal file
9
src/main/resources/guis/mapgui.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<!--
|
||||
~ Created by 2vb - 4/7/2024
|
||||
-->
|
||||
|
||||
<chestgui title="Maps" rows="5" onGlobalClick="globalClick">
|
||||
<outlinepane x="0" y="0" length="9" height="5" priority="lowest" repeat="true">
|
||||
<item id="black_stained_glass_pane" />
|
||||
</outlinepane>
|
||||
</chestgui>
|
17
src/main/resources/guis/teampicker.xml
Normal file
17
src/main/resources/guis/teampicker.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
<!--
|
||||
~ Created by 2vb - 4/7/2024
|
||||
-->
|
||||
|
||||
<chestgui title="Teams" rows="3" onGlobalClick="globalClick">
|
||||
<outlinepane x="0" y="0" length="9" height="3" priority="lowest" repeat="true">
|
||||
<item id="black_stained_glass_pane" />
|
||||
</outlinepane>
|
||||
<outlinepane x="3" y="1" length="3" height="1" gap="1">
|
||||
<item id="red_wool" onClick="pickTeam">
|
||||
<displayname>Red Team</displayname>
|
||||
</item>
|
||||
<item id="blue_wool" onClick="pickTeam">
|
||||
<displayname>Blue Team</displayname>
|
||||
</item>
|
||||
</outlinepane>
|
||||
</chestgui>
|
|
@ -16,8 +16,6 @@ sgm:
|
|||
cant-start: "&7Game couldn't be started!"
|
||||
cant-join: "&7Could not join this game!"
|
||||
started: "&7Game has started!"
|
||||
joined: "&7%player% has joined the game!"
|
||||
left: "&7%player% has left the game."
|
||||
win: "&7Congratulations to %winner% for winning!"
|
||||
level:
|
||||
new: "&7A level with the name %level% has been created."
|
||||
|
|
Loading…
Reference in New Issue
Block a user