diff --git a/build.gradle b/build.gradle
index 008c3f1..a6fbaa7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -48,18 +48,6 @@ targetCompatibility = JavaVersion.VERSION_17
mainClassName = ''
-sourceSets {
- main {
- java {
- srcDirs = ['src/']
- }
- resources {
- srcDirs = ['src/']
- exclude '**/*.java', '**/*.kt'
- }
- }
-}
-
repositories {
mavenCentral()
@@ -70,6 +58,9 @@ repositories {
maven {
url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/')
}
+ maven {
+ url = uri('https://repo.papermc.io/repository/maven-public/')
+ }
}
dependencies {
@@ -86,4 +77,16 @@ dependencies {
compileOnly swdep("Spigot-1.19")
compileOnly swdep("WorldEdit-1.15")
compileOnly swdep("SpigotCore")
+
+ testImplementation swdep("SpigotCore")
+ testImplementation(platform('org.junit:junit-bom:5.10.0'))
+ testImplementation('org.junit.jupiter:junit-jupiter')
+ testImplementation 'com.github.seeseemelk:MockBukkit-v1.20:3.9.0'
+}
+
+test {
+ useJUnitPlatform()
+ testLogging {
+ events "passed", "skipped", "failed"
+ }
}
\ No newline at end of file
diff --git a/src/de/steamwar/towerrun/TowerRun.java b/src/main/java/de/steamwar/towerrun/TowerRun.java
similarity index 89%
rename from src/de/steamwar/towerrun/TowerRun.java
rename to src/main/java/de/steamwar/towerrun/TowerRun.java
index 9f93eb9..f9c8e7a 100644
--- a/src/de/steamwar/towerrun/TowerRun.java
+++ b/src/main/java/de/steamwar/towerrun/TowerRun.java
@@ -27,12 +27,16 @@ import de.steamwar.towerrun.listener.IngameListener;
import de.steamwar.towerrun.listener.LobbyListener;
import de.steamwar.towerrun.listener.NotLobbyListener;
import lombok.Getter;
+import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.plugin.java.JavaPluginLoader;
import org.bukkit.plugin.java.annotation.dependency.Dependency;
import org.bukkit.plugin.java.annotation.plugin.Description;
import org.bukkit.plugin.java.annotation.plugin.Plugin;
import org.bukkit.plugin.java.annotation.plugin.author.Author;
+import java.io.File;
+
@Plugin(name = "TowerRun", version = "0.0.1")
@Dependency(value = "SpigotCore")
@Dependency(value = "WorldEdit")
@@ -45,18 +49,20 @@ public class TowerRun extends JavaPlugin {
private static TowerRun instance;
@Getter
private static Message message;
+ @Getter
+ private static LobbyCountdown lobbyCountdown;
@Override
public void onEnable() {
instance = this;
message = new Message("TowerRun", getClassLoader());
-
+ saveDefaultConfig();
new LobbyListener();
new IngameListener();
new GlobalListener();
new LobbyListener();
new NotLobbyListener();
- new LobbyCountdown();
+ lobbyCountdown = new LobbyCountdown();
new EndCountdown();
}
}
diff --git a/src/de/steamwar/towerrun/config/Config.java b/src/main/java/de/steamwar/towerrun/config/Config.java
similarity index 100%
rename from src/de/steamwar/towerrun/config/Config.java
rename to src/main/java/de/steamwar/towerrun/config/Config.java
diff --git a/src/de/steamwar/towerrun/config/WorldConfig.java b/src/main/java/de/steamwar/towerrun/config/WorldConfig.java
similarity index 100%
rename from src/de/steamwar/towerrun/config/WorldConfig.java
rename to src/main/java/de/steamwar/towerrun/config/WorldConfig.java
diff --git a/src/de/steamwar/towerrun/countdowns/EndCountdown.java b/src/main/java/de/steamwar/towerrun/countdowns/EndCountdown.java
similarity index 100%
rename from src/de/steamwar/towerrun/countdowns/EndCountdown.java
rename to src/main/java/de/steamwar/towerrun/countdowns/EndCountdown.java
diff --git a/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java b/src/main/java/de/steamwar/towerrun/countdowns/LobbyCountdown.java
similarity index 98%
rename from src/de/steamwar/towerrun/countdowns/LobbyCountdown.java
rename to src/main/java/de/steamwar/towerrun/countdowns/LobbyCountdown.java
index d0e7b21..de85a4f 100644
--- a/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java
+++ b/src/main/java/de/steamwar/towerrun/countdowns/LobbyCountdown.java
@@ -24,6 +24,7 @@ import de.steamwar.towerrun.config.Config;
import de.steamwar.towerrun.game.TowerRunGame;
import de.steamwar.towerrun.state.GameStateToggleListener;
import de.steamwar.towerrun.state.GameStates;
+import lombok.Getter;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@@ -31,6 +32,7 @@ import org.bukkit.scheduler.BukkitTask;
import java.util.EnumSet;
+@Getter
public class LobbyCountdown extends GameStateToggleListener {
private BukkitTask task;
diff --git a/src/de/steamwar/towerrun/game/TowerRunGame.java b/src/main/java/de/steamwar/towerrun/game/TowerRunGame.java
similarity index 100%
rename from src/de/steamwar/towerrun/game/TowerRunGame.java
rename to src/main/java/de/steamwar/towerrun/game/TowerRunGame.java
diff --git a/src/de/steamwar/towerrun/game/TowerRunPlayer.java b/src/main/java/de/steamwar/towerrun/game/TowerRunPlayer.java
similarity index 89%
rename from src/de/steamwar/towerrun/game/TowerRunPlayer.java
rename to src/main/java/de/steamwar/towerrun/game/TowerRunPlayer.java
index db445dd..87347d8 100644
--- a/src/de/steamwar/towerrun/game/TowerRunPlayer.java
+++ b/src/main/java/de/steamwar/towerrun/game/TowerRunPlayer.java
@@ -20,7 +20,6 @@
package de.steamwar.towerrun.game;
import de.steamwar.towerrun.config.WorldConfig;
-import lombok.ToString;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
@@ -47,11 +46,4 @@ public record TowerRunPlayer(Player player) {
player.teleport(WorldConfig.SPAWN);
player.setVelocity(new Vector(0, 0, 0));
}
-
- @Override
- public String toString() {
- return "TowerRunPlayer{" +
- "player=" + player.getName() +
- '}';
- }
}
diff --git a/src/de/steamwar/towerrun/listener/GlobalListener.java b/src/main/java/de/steamwar/towerrun/listener/GlobalListener.java
similarity index 100%
rename from src/de/steamwar/towerrun/listener/GlobalListener.java
rename to src/main/java/de/steamwar/towerrun/listener/GlobalListener.java
diff --git a/src/de/steamwar/towerrun/listener/IngameListener.java b/src/main/java/de/steamwar/towerrun/listener/IngameListener.java
similarity index 100%
rename from src/de/steamwar/towerrun/listener/IngameListener.java
rename to src/main/java/de/steamwar/towerrun/listener/IngameListener.java
diff --git a/src/de/steamwar/towerrun/listener/LobbyListener.java b/src/main/java/de/steamwar/towerrun/listener/LobbyListener.java
similarity index 100%
rename from src/de/steamwar/towerrun/listener/LobbyListener.java
rename to src/main/java/de/steamwar/towerrun/listener/LobbyListener.java
diff --git a/src/de/steamwar/towerrun/listener/NotLobbyListener.java b/src/main/java/de/steamwar/towerrun/listener/NotLobbyListener.java
similarity index 100%
rename from src/de/steamwar/towerrun/listener/NotLobbyListener.java
rename to src/main/java/de/steamwar/towerrun/listener/NotLobbyListener.java
diff --git a/src/de/steamwar/towerrun/state/GameState.java b/src/main/java/de/steamwar/towerrun/state/GameState.java
similarity index 100%
rename from src/de/steamwar/towerrun/state/GameState.java
rename to src/main/java/de/steamwar/towerrun/state/GameState.java
diff --git a/src/de/steamwar/towerrun/state/GameStateBukkitListener.java b/src/main/java/de/steamwar/towerrun/state/GameStateBukkitListener.java
similarity index 100%
rename from src/de/steamwar/towerrun/state/GameStateBukkitListener.java
rename to src/main/java/de/steamwar/towerrun/state/GameStateBukkitListener.java
diff --git a/src/de/steamwar/towerrun/state/GameStateListener.java b/src/main/java/de/steamwar/towerrun/state/GameStateListener.java
similarity index 100%
rename from src/de/steamwar/towerrun/state/GameStateListener.java
rename to src/main/java/de/steamwar/towerrun/state/GameStateListener.java
diff --git a/src/de/steamwar/towerrun/state/GameStateToggleListener.java b/src/main/java/de/steamwar/towerrun/state/GameStateToggleListener.java
similarity index 100%
rename from src/de/steamwar/towerrun/state/GameStateToggleListener.java
rename to src/main/java/de/steamwar/towerrun/state/GameStateToggleListener.java
diff --git a/src/de/steamwar/towerrun/state/GameStates.java b/src/main/java/de/steamwar/towerrun/state/GameStates.java
similarity index 100%
rename from src/de/steamwar/towerrun/state/GameStates.java
rename to src/main/java/de/steamwar/towerrun/state/GameStates.java
diff --git a/src/de/steamwar/towerrun/winconditions/FirstOutsideWincondition.java b/src/main/java/de/steamwar/towerrun/winconditions/FirstOutsideWincondition.java
similarity index 100%
rename from src/de/steamwar/towerrun/winconditions/FirstOutsideWincondition.java
rename to src/main/java/de/steamwar/towerrun/winconditions/FirstOutsideWincondition.java
diff --git a/src/de/steamwar/towerrun/winconditions/LastOutsideWincondition.java b/src/main/java/de/steamwar/towerrun/winconditions/LastOutsideWincondition.java
similarity index 100%
rename from src/de/steamwar/towerrun/winconditions/LastOutsideWincondition.java
rename to src/main/java/de/steamwar/towerrun/winconditions/LastOutsideWincondition.java
diff --git a/src/de/steamwar/towerrun/winconditions/LastRemainingWincondition.java b/src/main/java/de/steamwar/towerrun/winconditions/LastRemainingWincondition.java
similarity index 100%
rename from src/de/steamwar/towerrun/winconditions/LastRemainingWincondition.java
rename to src/main/java/de/steamwar/towerrun/winconditions/LastRemainingWincondition.java
diff --git a/src/de/steamwar/towerrun/winconditions/OutsideWincondition.java b/src/main/java/de/steamwar/towerrun/winconditions/OutsideWincondition.java
similarity index 100%
rename from src/de/steamwar/towerrun/winconditions/OutsideWincondition.java
rename to src/main/java/de/steamwar/towerrun/winconditions/OutsideWincondition.java
diff --git a/src/de/steamwar/towerrun/winconditions/WinCondition.java b/src/main/java/de/steamwar/towerrun/winconditions/WinCondition.java
similarity index 100%
rename from src/de/steamwar/towerrun/winconditions/WinCondition.java
rename to src/main/java/de/steamwar/towerrun/winconditions/WinCondition.java
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
new file mode 100644
index 0000000..7b4cfb2
--- /dev/null
+++ b/src/main/resources/config.yml
@@ -0,0 +1,6 @@
+minPlayers: 2
+lobbyTimer: 30
+
+destroyable:
+ - WHITE_WOOL
+ - FIRE
\ No newline at end of file
diff --git a/src/main/resources/world.yml b/src/main/resources/world.yml
new file mode 100644
index 0000000..54be90d
--- /dev/null
+++ b/src/main/resources/world.yml
@@ -0,0 +1,33 @@
+tower:
+ regions:
+ 1:
+ minX: 61
+ maxX: 128
+ minZ: 308
+ maxZ: 340
+ 2:
+ minX: 97
+ maxX: 128
+ minZ: 273
+ maxZ: 340
+ escapeHeight: 12
+ spawn:
+ x: 116
+ y: 167
+ z: 297
+ yaw: 0.0
+ pitch: 0.0
+ doors:
+ 1:
+ x: 117
+ y: 167
+ z: 309
+ 2:
+ x: 116
+ y: 167
+ z: 309
+ lavaY: 220
+
+winconditions:
+ - LAST_REMAINING
+ - LAST_OUTSIDE
\ No newline at end of file
diff --git a/src/test/java/de/steamwar/towerrun/TowerRunTests.java b/src/test/java/de/steamwar/towerrun/TowerRunTests.java
new file mode 100644
index 0000000..8bb3870
--- /dev/null
+++ b/src/test/java/de/steamwar/towerrun/TowerRunTests.java
@@ -0,0 +1,77 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2023 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.towerrun;
+import be.seeseemelk.mockbukkit.MockBukkit;
+import be.seeseemelk.mockbukkit.ServerMock;
+import be.seeseemelk.mockbukkit.WorldMock;
+import be.seeseemelk.mockbukkit.entity.PlayerMock;
+import de.steamwar.towerrun.mocks.WorldMockWithFolder;
+import org.bukkit.GameMode;
+import org.bukkit.Location;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class TowerRunTests {
+
+ private ServerMock server;
+ private WorldMock world;
+ private TowerRun plugin;
+
+ @BeforeEach
+ public void setup() {
+ server = MockBukkit.mock();
+ world = new WorldMockWithFolder();
+ server.addWorld(world);
+ plugin = MockBukkit.load(TowerRun.class);
+ }
+
+ @AfterEach
+ public void teardown() {
+ MockBukkit.unmock();
+ }
+
+ @Test
+ void playerJoin() {
+ PlayerMock playerMock = server.addPlayer();
+ playerMock.assertGameMode(GameMode.SURVIVAL);
+ playerMock.assertTeleported(new Location(playerMock.getWorld(), 116, 167, 297), 2);
+ playerMock.disconnect();
+ }
+
+ @Test
+ void lobbyCountdown() {
+ server.getScheduler().performOneTick();
+ PlayerMock playerOne = server.addPlayer();
+ server.getScheduler().performTicks(20);
+ assertEquals(30, TowerRun.getLobbyCountdown().getTimer());
+ PlayerMock playerTwo = server.addPlayer();
+ server.getScheduler().performTicks(20);
+ assertEquals(29, TowerRun.getLobbyCountdown().getTimer());
+ server.getScheduler().performTicks(19 * 20);
+ assertEquals(10, TowerRun.getLobbyCountdown().getTimer());
+ playerTwo.disconnect();
+ server.getScheduler().performTicks(20);
+ assertEquals(30, TowerRun.getLobbyCountdown().getTimer());
+ playerOne.disconnect();
+ }
+}
diff --git a/src/test/java/de/steamwar/towerrun/mocks/WorldMockWithFolder.java b/src/test/java/de/steamwar/towerrun/mocks/WorldMockWithFolder.java
new file mode 100644
index 0000000..146090e
--- /dev/null
+++ b/src/test/java/de/steamwar/towerrun/mocks/WorldMockWithFolder.java
@@ -0,0 +1,32 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2023 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.towerrun.mocks;
+
+import be.seeseemelk.mockbukkit.WorldMock;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+
+public class WorldMockWithFolder extends WorldMock {
+ @Override
+ public @NotNull File getWorldFolder() {
+ return new File("src/test/resources/world");
+ }
+}
diff --git a/src/test/resources/world/config.yml b/src/test/resources/world/config.yml
new file mode 100644
index 0000000..54be90d
--- /dev/null
+++ b/src/test/resources/world/config.yml
@@ -0,0 +1,33 @@
+tower:
+ regions:
+ 1:
+ minX: 61
+ maxX: 128
+ minZ: 308
+ maxZ: 340
+ 2:
+ minX: 97
+ maxX: 128
+ minZ: 273
+ maxZ: 340
+ escapeHeight: 12
+ spawn:
+ x: 116
+ y: 167
+ z: 297
+ yaw: 0.0
+ pitch: 0.0
+ doors:
+ 1:
+ x: 117
+ y: 167
+ z: 309
+ 2:
+ x: 116
+ y: 167
+ z: 309
+ lavaY: 220
+
+winconditions:
+ - LAST_REMAINING
+ - LAST_OUTSIDE
\ No newline at end of file