Merge branch 'master' of github.com:Altitude-Devs/boosters into donorrank
Update donorranks branch
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
plugins {
|
||||
`maven-publish`
|
||||
id("com.github.johnrengelman.shadow")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -10,4 +11,27 @@ dependencies {
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.0.0")
|
||||
// DiscordLink
|
||||
compileOnly("com.alttd.proxydiscordlink:ProxyDiscordLink:1.0.0-BETA-SNAPSHOT")
|
||||
|
||||
implementation("mysql:mysql-connector-java:8.0.27") // mysql
|
||||
implementation("org.spongepowered", "configurate-yaml", "4.1.2")
|
||||
implementation("net.kyori", "adventure-text-minimessage", "4.1.0-SNAPSHOT") {
|
||||
exclude("net.kyori")
|
||||
exclude("net.kyori.examination")
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
shadowJar {
|
||||
archiveFileName.set("${project.name}-${project.version}.jar")
|
||||
listOf(
|
||||
"net.kyori.adventure.text.minimessage",
|
||||
"org.spongepowered.configurate"
|
||||
).forEach { relocate(it, "${rootProject.name}.lib.$it") }
|
||||
}
|
||||
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.alttd.vboosters;
|
||||
|
||||
import com.alttd.boosterapi.BoosterAPI;
|
||||
import com.alttd.boosterapi.BoosterImplementation;
|
||||
import com.alttd.boosterapi.util.ALogger;
|
||||
import com.alttd.proxydiscordlink.DiscordLink;
|
||||
import com.alttd.proxydiscordlink.bot.api.DiscordSendMessage;
|
||||
import com.alttd.vboosters.commands.BoosterCommand;
|
||||
import com.alttd.vboosters.listeners.PluginMessageListener;
|
||||
import com.alttd.vboosters.managers.BoosterManager;
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||
import com.velocitypowered.api.plugin.Dependency;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
@@ -26,6 +31,9 @@ public class VelocityBoosters {
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
|
||||
private BoosterAPI boosterAPI;
|
||||
private BoosterManager boosterManager;
|
||||
|
||||
private ChannelIdentifier channelIdentifier = MinecraftChannelIdentifier.from("altitude:boosterplugin");
|
||||
|
||||
@Inject
|
||||
@@ -37,12 +45,25 @@ public class VelocityBoosters {
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
ALogger.init(logger);
|
||||
boosterAPI = new BoosterImplementation();
|
||||
boosterManager = new BoosterManager(this);
|
||||
|
||||
server.getChannelRegistrar().register(channelIdentifier);
|
||||
server.getEventManager().register(this, new PluginMessageListener(channelIdentifier));
|
||||
|
||||
loadCommands();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onShutdown(ProxyShutdownEvent event) {
|
||||
boosterManager.saveAllBoosters();
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
boosterAPI.reloadConfig();
|
||||
}
|
||||
|
||||
public static VelocityBoosters getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
@@ -64,4 +85,8 @@ public class VelocityBoosters {
|
||||
return channelIdentifier;
|
||||
}
|
||||
|
||||
public BoosterManager getBoosterManager() {
|
||||
return boosterManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
package com.alttd.vboosters.config;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.ConfigurationOptions;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class Config {
|
||||
private static final Pattern PATH_PATTERN = Pattern.compile("\\.");
|
||||
private static final String HEADER = "";
|
||||
|
||||
private static File CONFIG_FILE;
|
||||
public static ConfigurationNode config;
|
||||
public static YAMLConfigurationLoader configLoader;
|
||||
|
||||
static int version;
|
||||
static boolean verbose;
|
||||
|
||||
public static File CONFIGPATH;
|
||||
public static void init() {
|
||||
CONFIGPATH = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "Boosters");
|
||||
CONFIG_FILE = new File(CONFIGPATH, "config.yml");
|
||||
configLoader = YAMLConfigurationLoader.builder()
|
||||
.setFile(CONFIG_FILE)
|
||||
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
||||
.build();
|
||||
if (!CONFIG_FILE.getParentFile().exists()) {
|
||||
if(!CONFIG_FILE.getParentFile().mkdirs()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!CONFIG_FILE.exists()) {
|
||||
try {
|
||||
if(!CONFIG_FILE.createNewFile()) {
|
||||
return;
|
||||
}
|
||||
} catch (IOException error) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
config = configLoader.load(ConfigurationOptions.defaults().setHeader(HEADER));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
verbose = getBoolean("verbose", true);
|
||||
version = getInt("config-version", 1);
|
||||
|
||||
readConfig(Config.class, null);
|
||||
try {
|
||||
configLoader.save(config);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void readConfig(Class<?> clazz, Object instance) {
|
||||
for (Method method : clazz.getDeclaredMethods()) {
|
||||
if (Modifier.isPrivate(method.getModifiers())) {
|
||||
if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
|
||||
try {
|
||||
method.setAccessible(true);
|
||||
method.invoke(instance);
|
||||
} catch (InvocationTargetException | IllegalAccessException ex) {
|
||||
throw Throwables.propagate(ex.getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
configLoader.save(config);
|
||||
} catch (IOException ex) {
|
||||
throw Throwables.propagate(ex.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveConfig() {
|
||||
try {
|
||||
configLoader.save(config);
|
||||
} catch (IOException ex) {
|
||||
throw Throwables.propagate(ex.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
private static Object[] splitPath(String key) {
|
||||
return PATH_PATTERN.split(key);
|
||||
}
|
||||
|
||||
private static void set(String path, Object def) {
|
||||
if(config.getNode(splitPath(path)).isVirtual())
|
||||
config.getNode(splitPath(path)).setValue(def);
|
||||
}
|
||||
|
||||
private static void setString(String path, String def) {
|
||||
try {
|
||||
if(config.getNode(splitPath(path)).isVirtual())
|
||||
config.getNode(splitPath(path)).setValue(TypeToken.of(String.class), def);
|
||||
} catch(ObjectMappingException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean getBoolean(String path, boolean def) {
|
||||
set(path, def);
|
||||
return config.getNode(splitPath(path)).getBoolean(def);
|
||||
}
|
||||
|
||||
private static double getDouble(String path, double def) {
|
||||
set(path, def);
|
||||
return config.getNode(splitPath(path)).getDouble(def);
|
||||
}
|
||||
|
||||
private static int getInt(String path, int def) {
|
||||
set(path, def);
|
||||
return config.getNode(splitPath(path)).getInt(def);
|
||||
}
|
||||
|
||||
private static String getString(String path, String def) {
|
||||
setString(path, def);
|
||||
return config.getNode(splitPath(path)).getString(def);
|
||||
}
|
||||
|
||||
private static Long getLong(String path, Long def) {
|
||||
set(path, def);
|
||||
return config.getNode(splitPath(path)).getLong(def);
|
||||
}
|
||||
|
||||
private static <T> List<String> getList(String path, T def) {
|
||||
try {
|
||||
set(path, def);
|
||||
return config.getNode(splitPath(path)).getList(TypeToken.of(String.class));
|
||||
} catch(ObjectMappingException ex) {
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private static ConfigurationNode getNode(String path) {
|
||||
if(config.getNode(splitPath(path)).isVirtual()) {
|
||||
//new RegexConfig("Dummy");
|
||||
}
|
||||
config.getChildrenMap();
|
||||
return config.getNode(splitPath(path));
|
||||
}
|
||||
|
||||
/** ONLY EDIT ANYTHING BELOW THIS LINE **/
|
||||
public static Long queueTaskCheckFrequency = 1L;
|
||||
public static Long activeTaskCheckFrequency = 1L;
|
||||
private static void BoosterTaskSettings() {
|
||||
queueTaskCheckFrequency = getLong("task.queue-frequency", queueTaskCheckFrequency);
|
||||
activeTaskCheckFrequency = getLong("task.queue-frequency", activeTaskCheckFrequency);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.alttd.vboosters.data;
|
||||
|
||||
import com.alttd.boosters.api.BoosterType;
|
||||
import com.alttd.boosterapi.Booster;
|
||||
import com.alttd.boosterapi.BoosterType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class VelocityBooster implements com.alttd.boosters.api.Booster{
|
||||
public class VelocityBooster implements Booster {
|
||||
|
||||
private UUID uuid;
|
||||
private String activator;
|
||||
@@ -30,7 +31,6 @@ public class VelocityBooster implements com.alttd.boosters.api.Booster{
|
||||
this(UUID.randomUUID(), type, playerName, duration, multiplier);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
@@ -106,12 +106,24 @@ public class VelocityBooster implements com.alttd.boosters.api.Booster{
|
||||
|
||||
@Override
|
||||
public void stopBooster() {
|
||||
|
||||
setDuration(getTimeRemaining());
|
||||
setActive(false);
|
||||
saveBooster();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveBooster() {
|
||||
// logic to save to yaml or to db
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
finished = true;
|
||||
stopBooster();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean finished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.alttd.vboosters.managers;
|
||||
|
||||
import com.alttd.boosters.api.Booster;
|
||||
import com.alttd.boosters.api.BoosterType;
|
||||
import com.alttd.boosterapi.Booster;
|
||||
import com.alttd.boosterapi.BoosterType;
|
||||
import com.alttd.boosterapi.config.Config;
|
||||
import com.alttd.vboosters.VelocityBoosters;
|
||||
import com.alttd.vboosters.config.Config;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -19,27 +18,38 @@ public class BoosterManager {
|
||||
|
||||
private static List<Booster> queuedBoosters;
|
||||
private static List<Booster> activeBoosters;
|
||||
private static ScheduledTask queueBoosterTask;
|
||||
private static ScheduledTask activeBoostersTask;
|
||||
private static ScheduledTask boostersTask;
|
||||
|
||||
public void init() {
|
||||
plugin = VelocityBoosters.getPlugin();
|
||||
public BoosterManager(VelocityBoosters velocityBoosters) {
|
||||
plugin = velocityBoosters;
|
||||
activeBoosters = new ArrayList<>();
|
||||
queuedBoosters = new ArrayList<>();
|
||||
/*
|
||||
* This is mainly used to count down the active boosters and
|
||||
* let backend servers know if one should be activated/deactivated
|
||||
*/
|
||||
activeBoostersTask = plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
||||
boostersTask = plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
||||
for (Booster booster: getActiveBoosters()) {
|
||||
if (booster.getTimeRemaining() <= 0) {
|
||||
|
||||
if (booster.getTimeRemaining() > 0) continue;
|
||||
booster.finish();
|
||||
// send data to the backend servers to let them know the booster is no longer active
|
||||
}
|
||||
getActiveBoosters().removeIf(Booster::finished);
|
||||
for (BoosterType type : BoosterType.values()) {
|
||||
if (!isBoosted(type)) { // activate a queud booster if needed
|
||||
Booster queuedBooster = getHighestBooster(type);
|
||||
if (queuedBooster == null)
|
||||
continue;
|
||||
activateBooster(queuedBooster);
|
||||
// send an update to the backend servers to let them know this booster is active
|
||||
}
|
||||
}
|
||||
getQueuedBoosters().removeIf(Booster::finished);
|
||||
}).repeat(Config.activeTaskCheckFrequency, TimeUnit.SECONDS).schedule();
|
||||
}
|
||||
|
||||
public void loadBoosters() {
|
||||
// load boosters from datastorage and check them one by one to activate them
|
||||
for (BoosterType type : BoosterType.values()) {
|
||||
if (isBoosted(type)) {
|
||||
Booster activeBooster = getBoosted(type);
|
||||
@@ -72,27 +82,6 @@ public class BoosterManager {
|
||||
public void removeBooster(Booster booster) {
|
||||
activeBoosters.remove(booster);
|
||||
booster.stopBooster();
|
||||
// final TextComponent message = new TextComponent(booster.getType().name() + " by " + booster.getPlayerName() + " has ended.");
|
||||
// message.setColor(ChatColor.DARK_PURPLE);
|
||||
// message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( "Duration" + booster.getTimeLeft()).create() ));
|
||||
// plugin.getServer().broadcast(message);
|
||||
|
||||
// for(Booster qb : queuedBoosters) {
|
||||
// boolean active = false;
|
||||
// BoosterType qType = qb.getType();
|
||||
// if(qType == booster.getType()) {
|
||||
// for(Booster b : activeBoosters) {
|
||||
// if(b.getType() == qType) {
|
||||
// active = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if(!active) {
|
||||
// activateBooster(qb);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public void swapBooster(Booster activeBooster, Booster queuedBooster) {
|
||||
@@ -104,20 +93,12 @@ public class BoosterManager {
|
||||
queuedBoosters.remove(booster);
|
||||
activeBoosters.add(booster);
|
||||
booster.setActive(true);
|
||||
// final TextComponent message = new TextComponent(booster.getType().name() + " activated by " + booster.getPlayerName());
|
||||
// message.setColor(ChatColor.DARK_PURPLE);
|
||||
// message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( "Duration" + booster.getTimeLeft()).create() ));
|
||||
// plugin.getServer().broadcast(message);
|
||||
}
|
||||
|
||||
public void deactivateBooster(Booster booster) {
|
||||
queuedBoosters.add(booster);
|
||||
activeBoosters.remove(booster);
|
||||
booster.setActive(false);
|
||||
// final TextComponent message = new TextComponent(booster.getType().name() + " activated by " + booster.getPlayerName());
|
||||
// message.setColor(ChatColor.DARK_PURPLE);
|
||||
// message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( "Duration" + booster.getTimeLeft()).create() ));
|
||||
// plugin.getServer().broadcast(message);
|
||||
}
|
||||
|
||||
public boolean isBoosted(BoosterType type) {
|
||||
@@ -156,11 +137,13 @@ public class BoosterManager {
|
||||
|
||||
public void saveAllBoosters() {
|
||||
for (Booster b : activeBoosters) {
|
||||
b.saveBooster();
|
||||
b.stopBooster();
|
||||
}
|
||||
for (Booster b : queuedBoosters) {
|
||||
b.saveBooster();
|
||||
}
|
||||
activeBoosters = null;
|
||||
queuedBoosters = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.alttd.vboosters.task;
|
||||
|
||||
import com.alttd.boosterapi.config.Config;
|
||||
import com.alttd.vboosters.VelocityBoosters;
|
||||
import com.alttd.vboosters.config.Config;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class BoosterTask {
|
||||
public void init() {
|
||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
||||
|
||||
}).repeat(Config.TaskCheckFrequency, TimeUnit.SECONDS).schedule();
|
||||
}).repeat(Config.taskCheckFrequency, TimeUnit.SECONDS).schedule();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user