Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Commit 4dd41bf

Browse files
committed
[PP-2]: Trigger game state change event when plugins are loaded
1 parent 4897b0e commit 4dd41bf

8 files changed

Lines changed: 125 additions & 46 deletions

File tree

.github/workflows/build.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build Plugin
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up JDK 21
18+
uses: actions/setup-java@v4
19+
with:
20+
java-version: '21'
21+
distribution: 'temurin'
22+
23+
- name: Make gradlew executable
24+
run: chmod +x gradlew
25+
26+
- name: Setup Gradle
27+
uses: gradle/gradle-build-action@v2
28+
with:
29+
gradle-version: wrapper
30+
31+
- name: Build with Gradle
32+
run: ./gradlew build
33+
34+
- name: Upload build artifacts
35+
uses: actions/upload-artifact@v4
36+
if: always()
37+
with:
38+
name: plugin-jar
39+
path: build/libs/*.jar
40+
retention-days: 30

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import net.minecrell.pluginyml.paper.PaperPluginDescription
33
plugins {
44
java
55
`java-library`
6-
id("com.mineplex.sdk.plugin") version "1.17.0"
6+
id("com.mineplex.sdk.plugin") version "1.18.4"
77
id("net.minecrell.plugin-yml.paper") version "0.6.0"
88
}
99

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,44 @@
11
package com.plexprison.serverpersistence;
22

3+
import com.plexprison.serverpersistence.game.EmptyGame;
34
import lombok.Getter;
45
import org.bukkit.event.Listener;
6+
import org.bukkit.plugin.Plugin;
7+
import org.bukkit.plugin.PluginManager;
58
import org.bukkit.plugin.java.JavaPlugin;
9+
import org.bukkit.scheduler.BukkitRunnable;
610

711
@Getter
812
public class ServerPersistence extends JavaPlugin implements Listener {
913

1014
@Override
1115
public void onEnable() {
12-
16+
// Wait for all other plugins to be enabled
17+
new BukkitRunnable() {
18+
@Override
19+
public void run() {
20+
final PluginManager pluginManager = ServerPersistence.this.getServer().getPluginManager();
21+
boolean allPluginsEnabled = true;
22+
23+
// Check if all plugins except this one are enabled
24+
for (final Plugin plugin : pluginManager.getPlugins()) {
25+
if (!plugin.equals(ServerPersistence.this) && !plugin.isEnabled()) {
26+
allPluginsEnabled = false;
27+
break;
28+
}
29+
}
30+
31+
if (allPluginsEnabled) {
32+
// All plugins are enabled, call setState
33+
ServerPersistence.setState();
34+
this.cancel();
35+
}
36+
}
37+
}.runTaskTimer(this, 1L, 1L); // Check every tick until all plugins are enabled
38+
}
39+
40+
private static void setState() {
41+
new EmptyGame().setup();
1342
}
1443

1544
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.plexprison.serverpersistence.game;
2+
3+
import com.mineplex.studio.sdk.modules.MineplexModuleManager;
4+
import com.mineplex.studio.sdk.modules.game.*;
5+
import com.mineplex.studio.sdk.modules.game.event.PostMineplexGameStateChangeEvent;
6+
import com.mineplex.studio.sdk.modules.game.event.PreMineplexGameStateChangeEvent;
7+
import com.mineplex.studio.sdk.modules.world.MineplexWorld;
8+
import lombok.NonNull;
9+
import org.bukkit.entity.Player;
10+
11+
public class EmptyGame implements SingleWorldMineplexGame {
12+
13+
@Override
14+
public @NonNull MineplexWorld getGameWorld() {
15+
return null;
16+
}
17+
18+
@Override
19+
public @NonNull String getName() {
20+
return "";
21+
}
22+
23+
@Override
24+
public @NonNull MineplexGameMechanicFactory getGameMechanicFactory() {
25+
return MineplexModuleManager.getRegisteredModule(MineplexGameMechanicFactory.class);
26+
}
27+
28+
@Override
29+
public @NonNull GameState getGameState() {
30+
return BuiltInGameState.PRE_START;
31+
}
32+
33+
@Override
34+
public void setGameState(@NonNull final GameState gameState) {
35+
36+
}
37+
38+
@Override
39+
public @NonNull PlayerState getPlayerState(@NonNull final Player player) {
40+
return BuiltInPlayerState.ALIVE;
41+
}
42+
43+
@Override
44+
public void setup() {
45+
(new PreMineplexGameStateChangeEvent(this, BuiltInGameState.PREPARING, BuiltInGameState.PRE_START)).callEvent();
46+
(new PostMineplexGameStateChangeEvent(this, BuiltInGameState.PREPARING, BuiltInGameState.PRE_START)).callEvent();
47+
}
48+
49+
@Override
50+
public void teardown() {
51+
52+
}
53+
}

src/main/resources/examples/coins-example.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/main/resources/examples/subscription-example.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/main/resources/plugin.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)