Compare commits

..

10 Commits

Author SHA1 Message Date
Len 948efe14fc Add Jenkinsfile 2024-08-04 22:35:42 +02:00
Len bafbd73d3f Fix build 2024-07-21 18:48:28 +02:00
Teriuihi 6491b1b154 Update dependencies and add new BoosterTypes
The Galaxy-API and mcMMO dependencies have been updated to newer versions and three new BoosterTypes - 'crossbows', 'maces', and 'tridents' - have been added. Also, the Java language version has been upgraded from version 17 to version 21.
2024-07-21 18:07:35 +02:00
Len 4e1c832645 Fix compile 2024-07-19 21:35:39 +02:00
Teriuihi 254acc4918 Update default storage path for configs
The storage path for configs has now been updated to a new directory. This change applies to both the init method in the BoosterFileStorage class and the Config constructor. Instead of the user home directory, configs will now be stored in the "/mnt" directory.
2024-07-19 21:27:24 +02:00
Teriuihi 4b7fdd3141 Fixed config loading issues on proxy 2023-07-18 00:43:16 +02:00
Teriuihi f15520f6a2 Made abstractconfig not static where it doesnt need to be 2023-07-17 01:46:23 +02:00
Teriuihi 4ec85a4079 Set start time of booster to current time when it exits queue 2023-07-09 04:04:14 +02:00
Teriuihi 95030d8163 Temporarily hardcoded ranks since the getStringList was not loading it from the config and just emptying it instead 2023-07-08 23:46:06 +02:00
Teriuihi 75aa05cdf5 Removed active boolean for booster since we don't use it 2023-06-30 03:52:43 +02:00
13 changed files with 83 additions and 48 deletions

20
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,20 @@
pipeline {
agent any
stages {
stage('Gradle') {
steps {
sh './gradlew build'
}
}
stage('Archive') {
steps {
archiveArtifacts artifacts: 'build/libs/', followSymlinks: false
}
}
stage('discord') {
steps {
discordSend description: "Build: ${BUILD_NUMBER}", showChangeset: true, result: currentBuild.currentResult, title: currentBuild.fullProjectName, webhookURL: env.discordwebhook
}
}
}
}

View File

@ -3,7 +3,7 @@ plugins {
}
dependencies {
compileOnly("com.alttd:Galaxy-API:1.19.2-R0.1-SNAPSHOT")
compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT")
compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate
compileOnly("net.luckperms:api:5.3") // Luckperms

View File

@ -58,13 +58,6 @@ abstract class AbstractConfig {
} catch (IOException e) {
e.printStackTrace();
}
readConfig(clazz, null);
try {
configLoader.save(config);
} catch (IOException e) {
e.printStackTrace();
}
}
protected void readConfig(Class<?> clazz, Object instance) {
@ -114,7 +107,7 @@ abstract class AbstractConfig {
saveConfig();
}
protected static void setString(String path, String def) {
protected void setString(String path, String def) {
try {
if(config.node(splitPath(path)).virtual())
config.node(splitPath(path)).set(io.leangen.geantyref.TypeToken.get(String.class), def);
@ -123,34 +116,53 @@ abstract class AbstractConfig {
}
}
protected static boolean getBoolean(String prefix, String path, boolean def) {
protected boolean getBoolean(String prefix, String path, boolean def) {
set(prefix, path, def);
return config.node(splitPath(path)).getBoolean(def);
}
protected static double getDouble(String prefix, String path, double def) {
protected double getDouble(String prefix, String path, double def) {
set(prefix, path, def);
return config.node(splitPath(path)).getDouble(def);
}
protected static int getInt(String prefix, String path, int def) {
protected int getInt(String prefix, String path, int def) {
set(prefix, path, def);
return config.node(splitPath(path)).getInt(def);
}
protected static String getString(String prefix, String path, String def) {
protected String getString(String prefix, String path, String def) {
setString(path, def);
return config.node(splitPath(path)).getString(def);
}
protected static Long getLong(String prefix, String path, Long def) {
protected Long getLong(String prefix, String path, Long def) {
set(prefix, path, def);
return config.node(splitPath(path)).getLong(def);
}
protected static <T> List<String> getList(String prefix, String path, T def) {
private void setStringList(String prefix, String path, List<String> def) {
path = prefix + path;
System.out.println("Setting: " + def);
if(config.node(splitPath(path)).virtual()) {
try {
config.node(splitPath(path)).setList(TypeToken.get(String.class), def);
} catch (SerializationException e) {
e.printStackTrace();
}
} else {
try {
config.node(splitPath(path)).setList(TypeToken.get(String.class), def);
} catch (SerializationException e) {
e.printStackTrace();
}
}
saveConfig();
}
protected List<String> getStringList(String prefix, String path, List<String> def) {
try {
set(prefix, path, def);
setStringList(prefix, path, def);
return config.node(splitPath(path)).getList(TypeToken.get(String.class));
} catch(SerializationException ex) {
ex.printStackTrace();

View File

@ -27,7 +27,7 @@ public class BoosterFileStorage {
}
private void init() {
File CONFIG_PATH = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "Boosters");
File CONFIG_PATH = new File(File.separator + "mnt" + File.separator + "configs" + File.separator + "Boosters");
if (!CONFIG_PATH.exists()) {
if (!CONFIG_PATH.mkdir())
logger.severe("Unable to create json storage directory");
@ -123,14 +123,7 @@ public class BoosterFileStorage {
parser.nextValue();
double multiplier = parser.getValueAsDouble();
jsonToken = parser.nextToken();
if (jsonToken != JsonToken.FIELD_NAME || !"running".equals(parser.getCurrentName()))
return error("Didn't find running at expected location");
parser.nextValue();
boolean running = parser.getValueAsBoolean();
parser.nextValue();
return Optional.of(new Booster(boosterUUID, activatorName, boosterType, startingTime, duration, multiplier, running));
return Optional.of(new Booster(boosterUUID, activatorName, boosterType, startingTime, duration, multiplier));
}
private Optional<Booster> error(String error) {
@ -160,7 +153,6 @@ public class BoosterFileStorage {
generator.writeNumberField("startingTime", booster.getStartingTime().toEpochMilli());
generator.writeNumberField("duration", booster.getDuration().toMillis());
generator.writeNumberField("multiplier", booster.getMultiplier());
generator.writeBooleanField("running", booster.getRunning());
generator.writeEndObject();
}

View File

@ -11,8 +11,8 @@ public final class Config extends AbstractConfig {
Config(Logger logger) {
super(
new File(System.getProperty("user.home") + File.separator
+ "share" + File.separator
new File(File.separator
+ "mnt" + File.separator
+ "configs" + File.separator
+ "Boosters"),
"config.yml", logger, Config.class);
@ -20,7 +20,7 @@ public final class Config extends AbstractConfig {
public static void reload(Logger logger) {
config = new Config(logger);
config.readConfig(Config.class, null);
config.readConfig(Config.class, config);
}
public static class LOGGING {
@ -47,7 +47,7 @@ public final class Config extends AbstractConfig {
UPDATE_FREQUENCY_MINUTES = config.getInt(prefix, "update-frequency-minutes", UPDATE_FREQUENCY_MINUTES);
BOOST_ANNOUNCE_CHANNEL = config.getLong(prefix, "boost-announce-channel", BOOST_ANNOUNCE_CHANNEL);
PLUGIN_MESSAGE_CHANNEL = config.getString(prefix, "plugin-message-channel", PLUGIN_MESSAGE_CHANNEL);
DONOR_RANKS = config.getList(prefix, "donor-ranks", DONOR_RANKS);
// DONOR_RANKS = config.getStringList(prefix, "donor-ranks", DONOR_RANKS);
}
}

View File

@ -15,7 +15,6 @@ public class Booster implements Comparable<Booster> {
private Duration duration;
private final BoosterType boosterType;
private final Double multiplier;
private Boolean running;
public Booster(UUID boosterUUID, BoosterType boosterType, String reason, Duration duration, double multiplier) {
this.boosterUUID = boosterUUID;
@ -23,7 +22,6 @@ public class Booster implements Comparable<Booster> {
this.activatorName = reason;
this.duration = duration;
this.multiplier = multiplier;
this.running = false;
this.startingTime = Instant.now();
}
@ -32,14 +30,13 @@ public class Booster implements Comparable<Booster> {
}
public Booster(UUID boosterUUID, String activatorName, BoosterType boosterType, Instant startingTime,
Duration duration, double multiplier, boolean running) {
Duration duration, double multiplier) {
this.boosterUUID = boosterUUID;
this.activatorName = activatorName;
this.boosterType = boosterType;
this.startingTime = startingTime;
this.duration = duration;
this.multiplier = multiplier;
this.running = running;
}
public void updateDuration() {
@ -48,6 +45,10 @@ public class Booster implements Comparable<Booster> {
duration = duration.minus(elapsedTime);
}
public void updateTimeAfterReActivate() {
startingTime = Instant.now();
}
public double useMultiplier(double exp) {
return exp * (multiplier + 1);
}
@ -76,10 +77,6 @@ public class Booster implements Comparable<Booster> {
return multiplier;
}
public Boolean getRunning() {
return running;
}
@Override
public boolean equals(Object o) {
if (this == o)
@ -114,7 +111,6 @@ public class Booster implements Comparable<Booster> {
", duration=" + duration +
", boosterType=" + boosterType +
", multiplier=" + multiplier +
", running=" + running +
'}';
}
}

View File

@ -41,7 +41,14 @@ public class BoosterCache {
return;
}
LinkedList<Booster> list = boosters.get(boosterType);
Booster oldActive = null;
if (list.size() > 1) {
oldActive = list.get(0);
}
list.sort(Booster::compareTo);
if (oldActive != null && !list.get(0).getBoosterUUID().equals(oldActive.getBoosterUUID())) {
oldActive.updateDuration();
}
}
public synchronized Optional<Booster> getActiveBooster(BoosterType boosterType) {
@ -101,6 +108,11 @@ public class BoosterCache {
list.removeIf(filterBooster -> filterBooster.getBoosterUUID().equals(booster.getBoosterUUID()));
boosters.put(boosterType, list);
updateOrder(boosterType);
LinkedList<Booster> updatedBoosterList = boosters.get(boosterType);
if (updatedBoosterList.size() > 0) {
Booster nextBooster = updatedBoosterList.get(0);
nextBooster.updateTimeAfterReActivate();
}
boosterFileStorage.saveBoosters(boosters.values().stream().flatMap(List::stream).collect(Collectors.toList()));
}

View File

@ -26,6 +26,9 @@ public enum BoosterType {
TAMING("taming", MCMMO),
UNARMED("unarmed", MCMMO),
WOODCUTTING("woodcutting", MCMMO),
CROSSBOWS("crossbows", MCMMO),
MACES("maces", MCMMO),
TRIDENTS("tridents", MCMMO),
/**
* MYPET - Boosts MyPet exp gains

View File

@ -1,25 +1,25 @@
plugins {
`java-library`
`maven-publish`
id("com.github.johnrengelman.shadow") version "7.1.0"
id("io.github.goooler.shadow") version "8.1.8"
}
allprojects {
group = "com.alttd.boosters"
version = "1.0.0-BETA-SNAPSHOT"
description = "Easily manage all boosters on the Altitude Minecraft Server Network."
}
subprojects {
apply<JavaLibraryPlugin>()
apply(plugin = "maven-publish")
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
languageVersion.set(JavaLanguageVersion.of(21))
}
}
}
subprojects {
tasks {
withType<JavaCompile> {
options.encoding = Charsets.UTF_8.name()

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1,6 +1,6 @@
plugins {
`maven-publish`
id("com.github.johnrengelman.shadow")
id("io.github.goooler.shadow")
id("net.minecrell.plugin-yml.bukkit") version "0.5.1"
}
@ -8,11 +8,11 @@ dependencies {
// API
implementation(project(":boosters-api"))
// Galaxy
compileOnly("com.alttd:Galaxy-API:1.19.2-R0.1-SNAPSHOT")
compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT")
// MyPet
compileOnly("de.keyle:mypet:3.12-SNAPSHOT")
// mcMMO
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.1.206") {
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.2.004") {
exclude("com.sk89q.worldguard")
}

View File

@ -1,6 +1,6 @@
plugins {
`maven-publish`
id("com.github.johnrengelman.shadow")
id("io.github.goooler.shadow")
}
dependencies {