Compare commits

..

No commits in common. "948efe14fc420115ee92299ea60701b14d72018f" and "36a7b0cf68f91e9438809b91fb0f505f3b308e8b" have entirely different histories.

13 changed files with 48 additions and 83 deletions

20
Jenkinsfile vendored
View File

@ -1,20 +0,0 @@
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.21-R0.1-SNAPSHOT")
compileOnly("com.alttd:Galaxy-API:1.19.2-R0.1-SNAPSHOT")
compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate
compileOnly("net.luckperms:api:5.3") // Luckperms

View File

@ -58,6 +58,13 @@ 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) {
@ -107,7 +114,7 @@ abstract class AbstractConfig {
saveConfig();
}
protected void setString(String path, String def) {
protected static 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);
@ -116,53 +123,34 @@ abstract class AbstractConfig {
}
}
protected boolean getBoolean(String prefix, String path, boolean def) {
protected static boolean getBoolean(String prefix, String path, boolean def) {
set(prefix, path, def);
return config.node(splitPath(path)).getBoolean(def);
}
protected double getDouble(String prefix, String path, double def) {
protected static double getDouble(String prefix, String path, double def) {
set(prefix, path, def);
return config.node(splitPath(path)).getDouble(def);
}
protected int getInt(String prefix, String path, int def) {
protected static int getInt(String prefix, String path, int def) {
set(prefix, path, def);
return config.node(splitPath(path)).getInt(def);
}
protected String getString(String prefix, String path, String def) {
protected static String getString(String prefix, String path, String def) {
setString(path, def);
return config.node(splitPath(path)).getString(def);
}
protected Long getLong(String prefix, String path, Long def) {
protected static Long getLong(String prefix, String path, Long def) {
set(prefix, path, def);
return config.node(splitPath(path)).getLong(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) {
protected static <T> List<String> getList(String prefix, String path, T def) {
try {
setStringList(prefix, path, def);
set(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(File.separator + "mnt" + File.separator + "configs" + File.separator + "Boosters");
File CONFIG_PATH = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "Boosters");
if (!CONFIG_PATH.exists()) {
if (!CONFIG_PATH.mkdir())
logger.severe("Unable to create json storage directory");
@ -123,7 +123,14 @@ public class BoosterFileStorage {
parser.nextValue();
double multiplier = parser.getValueAsDouble();
return Optional.of(new Booster(boosterUUID, activatorName, boosterType, startingTime, duration, multiplier));
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));
}
private Optional<Booster> error(String error) {
@ -153,6 +160,7 @@ 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(File.separator
+ "mnt" + File.separator
new File(System.getProperty("user.home") + File.separator
+ "share" + 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, config);
config.readConfig(Config.class, null);
}
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.getStringList(prefix, "donor-ranks", DONOR_RANKS);
DONOR_RANKS = config.getList(prefix, "donor-ranks", DONOR_RANKS);
}
}

View File

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

View File

@ -41,14 +41,7 @@ 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) {
@ -108,11 +101,6 @@ 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,9 +26,6 @@ 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("io.github.goooler.shadow") version "8.1.8"
id("com.github.johnrengelman.shadow") version "7.1.0"
}
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(21))
languageVersion.set(JavaLanguageVersion.of(17))
}
}
}
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-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1,6 +1,6 @@
plugins {
`maven-publish`
id("io.github.goooler.shadow")
id("com.github.johnrengelman.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.21-R0.1-SNAPSHOT")
compileOnly("com.alttd:Galaxy-API:1.19.2-R0.1-SNAPSHOT")
// MyPet
compileOnly("de.keyle:mypet:3.12-SNAPSHOT")
// mcMMO
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.2.004") {
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.1.206") {
exclude("com.sk89q.worldguard")
}

View File

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