Compare commits

...

12 Commits

Author SHA1 Message Date
0fd7a9f35e Added hive2hive dependency
Some checks failed
spigotresourcesync/pipeline/head There was a failure building this commit
2024-11-23 02:27:48 +00:00
4bb1cd7277 Changed coverage to Jacoco
All checks were successful
spigotresourcesync/pipeline/head This commit looks good
2024-11-14 03:24:41 +00:00
7e2c68bad8 Added maven failsafe
All checks were successful
spigotresourcesync/pipeline/head This commit looks good
2024-11-14 03:13:44 +00:00
5574342811 Added test and coverage results
All checks were successful
spigotresourcesync/pipeline/head This commit looks good
2024-11-14 03:07:16 +00:00
6bb54c5cdb Added Jenkinsfile
All checks were successful
spigotresourcesync/pipeline/head This commit looks good
2024-11-14 01:00:17 +00:00
cfe2575b3c packaging workflow depends on test workflow now
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/package Pipeline was successful
2024-11-12 07:01:32 +00:00
11e3ca739b Fixed synchroniser deleting source directory
All checks were successful
ci/woodpecker/manual/test Pipeline was successful
ci/woodpecker/manual/package Pipeline was successful
2024-11-12 06:59:36 +00:00
ab9f4b0525 Added sync command 2024-11-12 06:51:42 +00:00
a4f595594d Loosened api-version specification 2024-11-11 09:04:03 +00:00
971a4ffdce Added 'api-version' target 2024-11-11 08:58:33 +00:00
71de030ea0 Added a few VSCode tools to devcontainer 2024-11-11 08:55:26 +00:00
b500fecadf Added ensured overwrite 2024-11-11 08:53:29 +00:00
20 changed files with 395 additions and 14 deletions

View File

@ -16,7 +16,9 @@
"vscode": {
"extensions": [
"redhat.java",
"redhat.vscode-xml"
"redhat.vscode-xml",
"piotrpalarz.vscode-gitignore-generator",
"Gruntfuggly.todo-tree"
]
}
}

4
.gitignore vendored
View File

@ -127,4 +127,6 @@ buildtools/*
!buildtools/install.sh
devserver/*
!devserver/start.sh
!devserver/loadplugin.sh
!devserver/server.properties
!devserver/loadplugin.sh
!devserver/bukkit.yml

15
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Development Server",
"request": "attach",
"hostName": "localhost",
"port": 5005,
}
]
}

47
.vscode/tasks.json vendored
View File

@ -2,6 +2,7 @@
"version": "2.0.0",
"tasks": [
{
"label": "Build Plugin to Development Server",
"type": "java (buildArtifact)",
"targetPath": "${workspaceFolder}/devserver/plugins/${workspaceFolderBasename}.jar",
"elements": [
@ -9,7 +10,49 @@
"${dependencies}"
],
"problemMatcher": [],
"label": "Build SpigotResourceSync to plugins"
},
{
"label": "Install Development Server",
"type": "shell",
"command": "${workspaceFolder}/buildtools/install.sh",
"options": {
"cwd": "${workspaceFolder}/buildtools"
},
"problemMatcher": []
},
{
"label": "Start Development Server",
"type": "shell",
"isBackground": true,
"command": "${workspaceFolder}/devserver/start.sh",
"options": {
"cwd": "${workspaceFolder}/devserver"
},
"dependsOn": [
"Build Plugin to Development Server",
],
"problemMatcher": [
{
"source": "Spigot Server",
"fileLocation": [
"autoDetect",
"${workspaceFolder}/src"
],
"pattern": [
{
"regexp": "^\\[\\d\\d:\\d\\d:\\d\\d\\] \\[[\\w\\s]+\/(\\w+)\\]: ([\\w \".()?]+\n[\\w \".()?:]+)$",
"severity": 1,
"message": 2
},
{
"regexp": "^\\s+at ([\\w.$]+)\\((\\w+\\.java):(\\d+)\\) ~\\[.+:.+\\]$",
"file": 2,
"line": 3,
"loop": true
}
]
}
]
}
]
],
}

7
.woodpecker/package.yml Normal file
View File

@ -0,0 +1,7 @@
steps:
- name: package
image: maven:3.9.9-eclipse-temurin-21-alpine
commands:
- mvn package
depends_on:
- test

5
.woodpecker/test.yml Normal file
View File

@ -0,0 +1,5 @@
steps:
- name: test
image: maven:3.9.9-eclipse-temurin-21-alpine
commands:
- mvn test

29
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,29 @@
pipeline {
agent {
kubernetes {
cloud 'rsys-devel'
defaultContainer 'maven'
inheritFrom 'maven'
}
}
stages {
stage("validate") {
steps {
sh "mvn validate"
}
}
stage("test") {
steps {
sh "mvn test"
xunit checksName: '', tools: [JUnit(excludesPattern: '', pattern: 'target/surefire-reports/TEST-*.xml', stopProcessingIfError: true)]
recordCoverage(tools: [[pattern: 'target/site/jacoco/jacoco.xml']])
}
}
stage("deploy") {
steps {
sh "mvn package"
archiveArtifacts artifacts: 'target/*.jar', fingerprint: true, followSymlinks: false, onlyIfSuccessful: true
}
}
}
}

32
devserver/bukkit.yml Normal file
View File

@ -0,0 +1,32 @@
settings:
allow-end: true
warn-on-overload: false
permissions-file: permissions.yml
update-folder: update
plugin-profiling: false
connection-throttle: 4000
query-plugins: true
deprecated-verbose: default
shutdown-message: Server closed
minimum-api: none
use-map-color-cache: true
spawn-limits:
monsters: 70
animals: 10
water-animals: 5
water-ambient: 20
water-underground-creature: 5
axolotls: 5
ambient: 15
chunk-gc:
period-in-ticks: 600
ticks-per:
animal-spawns: 400
monster-spawns: 1
water-spawns: 1
water-ambient-spawns: 1
water-underground-creature-spawns: 1
axolotl-spawns: 1
ambient-spawns: 1
autosave: 6000
aliases: now-in-commands.yml

View File

@ -0,0 +1,61 @@
#Minecraft server properties
#Tue Nov 12 06:44:35 UTC 2024
allow-flight=false
allow-nether=true
broadcast-console-to-ops=true
broadcast-rcon-to-ops=true
debug=false
difficulty=easy
enable-command-block=false
enable-jmx-monitoring=false
enable-query=false
enable-rcon=false
enable-status=true
enforce-secure-profile=true
enforce-whitelist=false
entity-broadcast-range-percentage=100
force-gamemode=false
function-permission-level=2
gamemode=survival
generate-structures=true
generator-settings={}
hardcore=false
hide-online-players=false
initial-disabled-packs=
initial-enabled-packs=vanilla
level-name=world
level-seed=
level-type=minecraft\:normal
log-ips=true
max-chained-neighbor-updates=1000000
max-players=20
max-tick-time=600000
max-world-size=29999984
motd=A Minecraft Server
network-compression-threshold=256
online-mode=true
op-permission-level=4
player-idle-timeout=0
prevent-proxy-connections=false
pvp=true
query.port=25565
rate-limit=0
rcon.password=
rcon.port=25575
require-resource-pack=false
resource-pack=
resource-pack-id=
resource-pack-prompt=
resource-pack-sha1=
server-ip=
server-port=25565
simulation-distance=10
spawn-animals=true
spawn-monsters=true
spawn-npcs=true
spawn-protection=16
sync-chunk-writes=true
text-filtering-config=
use-native-transport=true
view-distance=10
white-list=false

View File

@ -1,3 +1,5 @@
#!/bin/sh
java -Xmx2G -XX:+UseG1GC -jar spigot.jar nogui
echo "Server started"
java -Xmx2G -XX:+UseG1GC -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -jar spigot.jar nogui
echo "Server stopped"

39
pom.xml
View File

@ -47,6 +47,11 @@
<artifactId>jackson-core</artifactId>
<version>2.18.0</version>
</dependency>
<dependency>
<groupId>org.hive2hive</groupId>
<artifactId>org.hive2hive.core</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
@ -54,5 +59,37 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.2</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,57 @@
package solutions.reslate.entertainment.spigotresourcesync;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class CommandController implements CommandExecutor {
private Set<String> names;
private Map<String, Command> commands;
public CommandController() {
super();
names = new HashSet<>();
names.add("resourcesync");
names.add("ressync");
commands = new HashMap<>();
}
public void registerCommand(Command command) {
if (command == null) throw new IllegalArgumentException("Command cannot be null!");
this.commands.put(command.getName(), command);
for (String alias : command.getAliases()) {
this.commands.put(alias, command);
}
}
public void deregisterCommand(Command command) {
this.deregisterCommand(command.getName());
}
public void deregisterCommand(String commandName) {
if (commandName == null || commandName.isBlank()) throw new IllegalArgumentException("Command name cannot be null or blank.");
Command removed = this.commands.remove(commandName);
for (String alias : removed.getAliases()) {
this.commands.remove(alias);
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0) return false;
if (commands.containsKey(args[0])) {
Command subcommand = commands.get(args[0]);
return subcommand.execute(sender, label, Arrays.copyOfRange(args, 1, args.length));
}
return false;
}
}

View File

@ -5,12 +5,14 @@ import java.io.File;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import solutions.reslate.entertainment.spigotresourcesync.commands.SyncCommand;
import solutions.reslate.entertainment.spigotresourcesync.serialisation.JacksonYamlSerialiser;
import solutions.reslate.entertainment.spigotresourcesync.synchronisation.ApacheCommonsIOSynchroniser;
public class SpigotResourceSync extends JavaPlugin {
private ConfigManager configManager;
private SyncListManager syncListManager;
private CommandController commandController;
@Override
public void onDisable() {
@ -26,11 +28,15 @@ public class SpigotResourceSync extends JavaPlugin {
if (configManager.getConfiguration().getSyncOnLoad()) {
syncListManager.synchroniseAllSyncList();
}
commandController = new CommandController();
commandController.registerCommand(new SyncCommand(syncListManager));
super.onLoad();
}
@Override
public void onEnable() {
getLogger().info(getName());
getCommand(getName()).setExecutor(commandController);
super.onEnable();
}
@ -48,6 +54,6 @@ public class SpigotResourceSync extends JavaPlugin {
public void saveDefaultConfig() {
configManager.resetConfiguration();
configManager.flush();
super.saveDefaultConfig();
}
}

View File

@ -36,6 +36,21 @@ public class SyncListManager implements ObjectLoadListener<Configuration> {
logger.info("Done synchronising.");
}
public void synchroniseGroupSyncList(String group) {
logger.info("Synchronising group sync pairs...");
for (SyncPair syncPair : this.configuration.getSyncList().gatherGroupSyncPairs(group)) {
File source = new File(syncPair.getSource());
File dest = new File(syncPair.getDestination());
try {
synchroniser.sync(source, dest);
logger.info(String.format("Synchronised \"%s\" to \"%s\"!", source.getName(), dest.getName()));
} catch (IOException e) {
logger.warning(String.format("Failed to synchronise \"%s\" to \"%s\". %s", source.getAbsolutePath(), dest.getAbsolutePath(), e.getMessage()));
}
}
logger.info("Done synchronising.");
}
@Override
public void objectLoaded(Configuration obj) {
logger.info("Updating synchronisation list due to recently loading configuration...");

View File

@ -0,0 +1,38 @@
package solutions.reslate.entertainment.spigotresourcesync.commands;
import java.util.ArrayList;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import solutions.reslate.entertainment.spigotresourcesync.SyncListManager;
public class SyncCommand extends Command {
private SyncListManager syncListManager;
public SyncCommand(SyncListManager syncListManager) {
super(
"sync",
"Synchronise based off your configurations.",
"sync [sync group name]",
new ArrayList<>()
);
this.syncListManager = syncListManager;
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (args.length > 1) return false;
if (args.length == 1) {
String groupName = args[0];
syncListManager.synchroniseGroupSyncList(groupName);
sender.sendMessage(String.format("Synchronisation of \"%s\" complete!", groupName));
} else {
syncListManager.synchroniseAllSyncList();
sender.sendMessage("Synchronisation of all items complete!");
}
return true;
}
}

View File

@ -2,6 +2,7 @@ package solutions.reslate.entertainment.spigotresourcesync.data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@ -17,12 +18,17 @@ public class SyncList implements Serializable {
this.syncPairs = new LinkedHashMap<>();
}
public List<SyncPair> gatherAllSyncPairs() {
public SequencedCollection<SyncPair> gatherAllSyncPairs() {
List<SyncPair> allSyncPairs = new ArrayList<>();
for (SequencedCollection<SyncPair> syncPairs : this.syncPairs.values()) {
allSyncPairs.addAll(syncPairs);
}
return allSyncPairs;
return Collections.unmodifiableSequencedCollection(allSyncPairs);
}
public SequencedCollection<SyncPair> gatherGroupSyncPairs(String groupName) {
if (!this.syncPairs.containsKey(groupName)) throw new IllegalArgumentException(String.format("\"%s\" group does not exist!", groupName));
return Collections.unmodifiableSequencedCollection(this.syncPairs.get(groupName));
}
public void addSynchronisationPair(String source, String dest, String group) {
@ -52,8 +58,8 @@ public class SyncList implements Serializable {
}
}
public List<String> gatherSynchronisationGroups() {
return new ArrayList<>(this.syncPairs.keySet());
public SequencedCollection<String> gatherSynchronisationGroups() {
return Collections.unmodifiableSequencedCollection(new ArrayList<>(this.syncPairs.keySet()));
}
public SequencedMap<String, SequencedCollection<SyncPair>> getSyncPairs() {

View File

@ -19,7 +19,7 @@ public class ApacheCommonsIOSynchroniser implements Synchroniser {
if (dest.isDirectory()) {
FileUtils.copyDirectory(source, dest);
} else {
throw new IOException("Cannot synchronise directy to non-directory!");
throw new IOException("Cannot synchronise directory to non-directory!");
// TODO add more detail to error message.
}
} else {

View File

@ -1,3 +1,9 @@
name: SpigotResourceSync
version: 1.0.0
main: solutions.reslate.entertainment.spigotresourcesync.SpigotResourceSync
main: solutions.reslate.entertainment.spigotresourcesync.SpigotResourceSync
api-version: '1.20'
commands:
spigotresourcesync:
description: Tool suite for synchronisation resources across directories.
usage: See "/spigotresourcesync help" for help.

View File

@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Logger;
import org.junit.jupiter.api.Test;
@ -27,6 +28,6 @@ public class TestConfigManager {
assumeTrue(dummyConfig.exists());
ConfigManager finalConfigManager = new ConfigManager(dummyConfig, dummySerialiser, logger);
finalConfigManager.load();
assertEquals(dummySyncPair, finalConfigManager.getConfiguration().getSyncList().gatherAllSyncPairs().get(0));
assertEquals(dummySyncPair, new ArrayList<>(finalConfigManager.getConfiguration().getSyncList().gatherAllSyncPairs()).get(1));
}
}

View File

@ -0,0 +1,17 @@
package solutions.reslate.entertainment.spigotresourcesync.data;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import org.junit.jupiter.api.Test;
public class TestSyncList {
@Test
void testGatherSyncGroup() {
SyncList dummyList = new SyncList();
dummyList.addSynchronisationPair("abc", "def", "a");
dummyList.addSynchronisationPair("ghi", "jkl", "a");
dummyList.addSynchronisationPair("123", "456", "b");
assertEquals(new SyncPair("abc", "def"), dummyList.gatherGroupSyncPairs("a").getFirst());
}
}