Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build

on:
push:
branches: [ main, develop, copilot/** ]
pull_request:
branches: [ main, develop ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
cache: maven

- name: Build and install Ponder to local Maven repository
run: |
cd dependencies/Ponder
git checkout v0.14
chmod +x gradlew
./gradlew build publishToMavenLocal -x test

- name: Build SimpleSkills with Maven
run: mvn clean compile --batch-mode --update-snapshots
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "dependencies/Ponder"]
path = dependencies/Ponder
url = https://github.com/Preponderous-Software/Ponder.git
1 change: 1 addition & 0 deletions dependencies/Ponder
Submodule Ponder added at d2b809
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<dependency>
<groupId>com.github.Preponderous-Software</groupId>
<artifactId>Ponder</artifactId>
<version>v1.0</version>
<version>v0.14</version>
</dependency>
<dependency>
<groupId>com.github.cryptomorin</groupId>
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/dansplugins/simpleskills/SimpleSkills.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Timer;
import java.util.TimerTask;

/**
* @author Daniel Stephenson
Expand All @@ -44,6 +46,7 @@ public class SimpleSkills extends PonderBukkitPlugin {
private final StorageService storageService = new StorageService(playerRecordRepository, skillRepository, messageService, configService, experienceCalculator, log);
private final ChanceCalculator chanceCalculator = new ChanceCalculator(playerRecordRepository, configService, skillRepository, messageService, experienceCalculator, log);
private final PlayerJoinEventListener playerJoinEventListener = new PlayerJoinEventListener(playerRecordRepository, log);
private Timer autosaveTimer;


/**
Expand All @@ -64,13 +67,15 @@ public void onEnable() {
registerEventListeners();
initializeCommandService();
checkFilesVersion();
startAutosave();
}

/**
* This runs when the server stops.
*/
@Override
public void onDisable() {
stopAutosave();
log.debug("Saving files.");
storageService.save();
log.debug("Saving language files.");
Expand Down Expand Up @@ -208,4 +213,36 @@ private void initializeSkills() {
skillRepository.addSkill(new Strength(configService, log, playerRecordRepository, this, messageService, chanceCalculator));
}

/**
* Starts the autosave scheduler which saves data every 5 minutes.
*/
private void startAutosave() {
log.debug("Starting autosave task.");
autosaveTimer = new Timer(true);
autosaveTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (!isEnabled()) {
autosaveTimer.cancel();
return;
}
Bukkit.getScheduler().runTask(SimpleSkills.this, () -> {
log.debug("Autosaving files.");
storageService.save();
});
}
}, 1000 * 60 * 5, 1000 * 60 * 5);
}

/**
* Stops the autosave scheduler.
*/
private void stopAutosave() {
if (autosaveTimer != null) {
log.debug("Stopping autosave task.");
autosaveTimer.cancel();
autosaveTimer = null;
}
}

}
Loading