Merge branch 'master' of github.com:Altitude-Devs/boosters into donorrank
Update donorranks branch
This commit is contained in:
commit
e2fc550011
|
|
@ -3,23 +3,18 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Galaxy
|
compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT")
|
||||||
compileOnly("com.alttd:galaxy-api:1.17.1-R0.1-SNAPSHOT")
|
compileOnly("net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT") // Minimessage
|
||||||
|
compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate
|
||||||
|
compileOnly("net.luckperms:api:5.3") // Luckperms
|
||||||
}
|
}
|
||||||
|
|
||||||
//publishing {
|
publishing {
|
||||||
// publications {
|
repositories{
|
||||||
// create<MavenPublication>("mavenJava") {
|
maven {
|
||||||
// from(components["java"])
|
name = "maven"
|
||||||
// }
|
url = uri("https://repo.destro.xyz/snapshots")
|
||||||
// }
|
credentials(PasswordCredentials::class)
|
||||||
//
|
}
|
||||||
// repositories{
|
}
|
||||||
// maven {
|
}
|
||||||
// name = "maven"
|
|
||||||
// url = uri("http://leo:8081/")
|
|
||||||
// isAllowInsecureProtocol = true
|
|
||||||
// credentials(PasswordCredentials::class)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.boosters.api;
|
package com.alttd.boosterapi;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -35,4 +35,8 @@ public interface Booster {
|
||||||
void stopBooster();
|
void stopBooster();
|
||||||
|
|
||||||
void saveBooster();
|
void saveBooster();
|
||||||
|
|
||||||
|
void finish();
|
||||||
|
|
||||||
|
boolean finished();
|
||||||
}
|
}
|
||||||
14
api/src/main/java/com/alttd/boosterapi/BoosterAPI.java
Normal file
14
api/src/main/java/com/alttd/boosterapi/BoosterAPI.java
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.alttd.boosterapi;
|
||||||
|
|
||||||
|
import net.luckperms.api.LuckPerms;
|
||||||
|
|
||||||
|
public interface BoosterAPI {
|
||||||
|
|
||||||
|
static BoosterAPI get() {
|
||||||
|
return BoosterImplementation.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
LuckPerms getLuckPerms();
|
||||||
|
|
||||||
|
void reloadConfig();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.alttd.boosterapi;
|
||||||
|
|
||||||
|
import com.alttd.boosterapi.config.Config;
|
||||||
|
import com.alttd.boosterapi.database.Database;
|
||||||
|
import net.luckperms.api.LuckPerms;
|
||||||
|
import net.luckperms.api.LuckPermsProvider;
|
||||||
|
|
||||||
|
public class BoosterImplementation implements BoosterAPI {
|
||||||
|
|
||||||
|
private static BoosterAPI instance;
|
||||||
|
|
||||||
|
private LuckPerms luckPerms;
|
||||||
|
private Database database;
|
||||||
|
|
||||||
|
public BoosterImplementation() {
|
||||||
|
instance = this;
|
||||||
|
reloadConfig();
|
||||||
|
|
||||||
|
luckPerms = getLuckPerms();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BoosterAPI get() {
|
||||||
|
if (instance == null)
|
||||||
|
instance = new BoosterImplementation();
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LuckPerms getLuckPerms() {
|
||||||
|
if(luckPerms == null)
|
||||||
|
luckPerms = LuckPermsProvider.get();
|
||||||
|
return luckPerms;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadConfig() {
|
||||||
|
Config.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.boosters.api;
|
package com.alttd.boosterapi;
|
||||||
|
|
||||||
public enum BoosterType {
|
public enum BoosterType {
|
||||||
|
|
||||||
|
|
@ -6,6 +6,23 @@ public enum BoosterType {
|
||||||
* MCMMO - implies all mcmmo skills are boosted
|
* MCMMO - implies all mcmmo skills are boosted
|
||||||
*/
|
*/
|
||||||
MCMMO("mcmmo"),
|
MCMMO("mcmmo"),
|
||||||
|
|
||||||
|
ACROBATICS("acrobatics"),
|
||||||
|
ALCHEMY("alchemy"),
|
||||||
|
ARCHERY("archery"),
|
||||||
|
AXES("axes"),
|
||||||
|
EXCAVATION("excavation"),
|
||||||
|
FISHING("fishing"),
|
||||||
|
HERBALISM("herbalism"),
|
||||||
|
MINING("mining"),
|
||||||
|
REPAIR("repair"),
|
||||||
|
SALVAGE("salvage"),
|
||||||
|
SMELTING("smelting"),
|
||||||
|
SWORDS("swords"),
|
||||||
|
TAMING("taming"),
|
||||||
|
UNARMED("unarmed"),
|
||||||
|
WOODCUTTING("woodcutting"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MYPET - Boosts MyPet exp gains
|
* MYPET - Boosts MyPet exp gains
|
||||||
*/
|
*/
|
||||||
|
|
@ -32,7 +49,7 @@ public enum BoosterType {
|
||||||
*/
|
*/
|
||||||
UNKNOWN("unknown");
|
UNKNOWN("unknown");
|
||||||
|
|
||||||
public String BoosterName;
|
public final String BoosterName;
|
||||||
BoosterType(String BoosterName) {
|
BoosterType(String BoosterName) {
|
||||||
this.BoosterName = BoosterName;
|
this.BoosterName = BoosterName;
|
||||||
}
|
}
|
||||||
|
|
@ -1,20 +1,19 @@
|
||||||
package com.alttd.vboosters.config;
|
package com.alttd.boosterapi.config;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.alttd.boosterapi.util.ALogger;
|
||||||
import com.google.common.reflect.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
import ninja.leaping.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import ninja.leaping.configurate.ConfigurationOptions;
|
import org.spongepowered.configurate.ConfigurationOptions;
|
||||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
import org.spongepowered.configurate.yaml.NodeStyle;
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class Config {
|
public final class Config {
|
||||||
|
|
@ -23,7 +22,7 @@ public final class Config {
|
||||||
|
|
||||||
private static File CONFIG_FILE;
|
private static File CONFIG_FILE;
|
||||||
public static ConfigurationNode config;
|
public static ConfigurationNode config;
|
||||||
public static YAMLConfigurationLoader configLoader;
|
public static YamlConfigurationLoader configLoader;
|
||||||
|
|
||||||
static int version;
|
static int version;
|
||||||
static boolean verbose;
|
static boolean verbose;
|
||||||
|
|
@ -32,9 +31,9 @@ public final class Config {
|
||||||
public static void init() {
|
public static void init() {
|
||||||
CONFIGPATH = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "Boosters");
|
CONFIGPATH = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "Boosters");
|
||||||
CONFIG_FILE = new File(CONFIGPATH, "config.yml");
|
CONFIG_FILE = new File(CONFIGPATH, "config.yml");
|
||||||
configLoader = YAMLConfigurationLoader.builder()
|
configLoader = YamlConfigurationLoader.builder()
|
||||||
.setFile(CONFIG_FILE)
|
.file(CONFIG_FILE)
|
||||||
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
.nodeStyle(NodeStyle.BLOCK)
|
||||||
.build();
|
.build();
|
||||||
if (!CONFIG_FILE.getParentFile().exists()) {
|
if (!CONFIG_FILE.getParentFile().exists()) {
|
||||||
if(!CONFIG_FILE.getParentFile().mkdirs()) {
|
if(!CONFIG_FILE.getParentFile().mkdirs()) {
|
||||||
|
|
@ -52,7 +51,7 @@ public final class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config = configLoader.load(ConfigurationOptions.defaults().setHeader(HEADER));
|
config = configLoader.load(ConfigurationOptions.defaults().header(HEADER));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -76,23 +75,19 @@ public final class Config {
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
method.invoke(instance);
|
method.invoke(instance);
|
||||||
} catch (InvocationTargetException | IllegalAccessException ex) {
|
} catch (InvocationTargetException | IllegalAccessException ex) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
ALogger.fatal("Error reading config", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
saveConfig();
|
||||||
configLoader.save(config);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
throw Throwables.propagate(ex.getCause());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveConfig() {
|
public static void saveConfig() {
|
||||||
try {
|
try {
|
||||||
configLoader.save(config);
|
configLoader.save(config);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
ALogger.fatal("Error saving config", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,66 +96,85 @@ public final class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void set(String path, Object def) {
|
private static void set(String path, Object def) {
|
||||||
if(config.getNode(splitPath(path)).isVirtual())
|
if(config.node(splitPath(path)).virtual()) {
|
||||||
config.getNode(splitPath(path)).setValue(def);
|
try {
|
||||||
|
config.node(splitPath(path)).set(def);
|
||||||
|
} catch (SerializationException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setString(String path, String def) {
|
private static void setString(String path, String def) {
|
||||||
try {
|
try {
|
||||||
if(config.getNode(splitPath(path)).isVirtual())
|
if(config.node(splitPath(path)).virtual())
|
||||||
config.getNode(splitPath(path)).setValue(TypeToken.of(String.class), def);
|
config.node(splitPath(path)).set(TypeToken.get(String.class), def);
|
||||||
} catch(ObjectMappingException ex) {
|
} catch(SerializationException ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean getBoolean(String path, boolean def) {
|
private static boolean getBoolean(String path, boolean def) {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getBoolean(def);
|
return config.node(splitPath(path)).getBoolean(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double getDouble(String path, double def) {
|
private static double getDouble(String path, double def) {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getDouble(def);
|
return config.node(splitPath(path)).getDouble(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getInt(String path, int def) {
|
private static int getInt(String path, int def) {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getInt(def);
|
return config.node(splitPath(path)).getInt(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getString(String path, String def) {
|
private static String getString(String path, String def) {
|
||||||
setString(path, def);
|
setString(path, def);
|
||||||
return config.getNode(splitPath(path)).getString(def);
|
return config.node(splitPath(path)).getString(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Long getLong(String path, Long def) {
|
private static Long getLong(String path, Long def) {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getLong(def);
|
return config.node(splitPath(path)).getLong(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> List<String> getList(String path, T def) {
|
private static <T> List<String> getList(String path, T def) {
|
||||||
try {
|
try {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getList(TypeToken.of(String.class));
|
return config.node(splitPath(path)).getList(TypeToken.get(String.class));
|
||||||
} catch(ObjectMappingException ex) {
|
} catch(SerializationException ex) {
|
||||||
}
|
}
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ConfigurationNode getNode(String path) {
|
/** ONLY EDIT ANYTHING BELOW THIS LINE **/
|
||||||
if(config.getNode(splitPath(path)).isVirtual()) {
|
public static String driver = "com.mysql.cj.jdbc.Driver";
|
||||||
//new RegexConfig("Dummy");
|
public static String host = "13.11.1.78";
|
||||||
}
|
public static String port = "3306";
|
||||||
config.getChildrenMap();
|
public static String database = "McTestSql";
|
||||||
return config.getNode(splitPath(path));
|
public static String user = "root";
|
||||||
|
public static String password = "foobar";
|
||||||
|
public static String options = "?MaxPooledStatements=250&useSSL=false&autoReconnect=true&maxReconnects=3";
|
||||||
|
private static void databaseSettings() {
|
||||||
|
String path = "database.";
|
||||||
|
driver = getString(path + "driver", driver);
|
||||||
|
host = getString(path + "host", host);
|
||||||
|
port = getString(path + "port", port);
|
||||||
|
database = getString(path + "database", database);
|
||||||
|
user = getString(path + "user", user);
|
||||||
|
password = getString(path + "password", password);
|
||||||
|
options = getString(path + "options", options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ONLY EDIT ANYTHING BELOW THIS LINE **/
|
|
||||||
public static Long queueTaskCheckFrequency = 1L;
|
|
||||||
public static Long activeTaskCheckFrequency = 1L;
|
public static Long activeTaskCheckFrequency = 1L;
|
||||||
private static void BoosterTaskSettings() {
|
public static Long taskCheckFrequency = 1L;
|
||||||
queueTaskCheckFrequency = getLong("task.queue-frequency", queueTaskCheckFrequency);
|
private static void boosterTaskSettings() {
|
||||||
activeTaskCheckFrequency = getLong("task.queue-frequency", activeTaskCheckFrequency);
|
activeTaskCheckFrequency = getLong("task.queue-frequency", activeTaskCheckFrequency);
|
||||||
|
taskCheckFrequency = getLong("task.check-frequency", taskCheckFrequency);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String pluginMessageChannel = "altitude:boosterplugin";
|
||||||
|
private static void pluginMessageSettings() {
|
||||||
|
pluginMessageChannel = getString("settings.message-channel", pluginMessageChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
74
api/src/main/java/com/alttd/boosterapi/config/ServerConfig.java
Executable file
74
api/src/main/java/com/alttd/boosterapi/config/ServerConfig.java
Executable file
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.alttd.boosterapi.config;
|
||||||
|
|
||||||
|
import io.leangen.geantyref.TypeToken;
|
||||||
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public final class ServerConfig {
|
||||||
|
private static final Pattern PATH_PATTERN = Pattern.compile("\\.");
|
||||||
|
|
||||||
|
private final String serverName;
|
||||||
|
private final String configPath;
|
||||||
|
private final String defaultPath;
|
||||||
|
|
||||||
|
public ServerConfig(String serverName) {
|
||||||
|
this.serverName = serverName;
|
||||||
|
this.configPath = "server-settings." + this.serverName + ".";
|
||||||
|
this.defaultPath = "server-settings.default.";
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
Config.readConfig(ServerConfig.class, this);
|
||||||
|
Config.saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object[] splitPath(String key) {
|
||||||
|
return PATH_PATTERN.split(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void set(String path, Object def) {
|
||||||
|
if(Config.config.node(splitPath(path)).virtual()) {
|
||||||
|
try {
|
||||||
|
Config.config.node(splitPath(path)).set(def);
|
||||||
|
} catch (SerializationException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setString(String path, String def) {
|
||||||
|
try {
|
||||||
|
if(Config.config.node(splitPath(path)).virtual())
|
||||||
|
Config.config.node(splitPath(path)).set(TypeToken.get(String.class), def);
|
||||||
|
} catch(SerializationException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getBoolean(String path, boolean def) {
|
||||||
|
set(defaultPath +path, def);
|
||||||
|
return Config.config.node(splitPath(configPath+path)).getBoolean(
|
||||||
|
Config.config.node(splitPath(defaultPath +path)).getBoolean(def));
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getDouble(String path, double def) {
|
||||||
|
set(defaultPath +path, def);
|
||||||
|
return Config.config.node(splitPath(configPath+path)).getDouble(
|
||||||
|
Config.config.node(splitPath(defaultPath +path)).getDouble(def));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getInt(String path, int def) {
|
||||||
|
set(defaultPath +path, def);
|
||||||
|
return Config.config.node(splitPath(configPath+path)).getInt(
|
||||||
|
Config.config.node(splitPath(defaultPath +path)).getInt(def));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getString(String path, String def) {
|
||||||
|
set(defaultPath +path, def);
|
||||||
|
return Config.config.node(splitPath(configPath+path)).getString(
|
||||||
|
Config.config.node(splitPath(defaultPath +path)).getString(def));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** DO NOT EDIT ANYTHING ABOVE **/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.alttd.boosterapi.database;
|
||||||
|
|
||||||
|
import com.alttd.boosterapi.config.Config;
|
||||||
|
import com.alttd.boosterapi.util.ALogger;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class Database {
|
||||||
|
|
||||||
|
private static Connection connection;
|
||||||
|
|
||||||
|
public static Connection getConnection() {
|
||||||
|
if (connection == null) {
|
||||||
|
try {
|
||||||
|
Class.forName(Config.driver);
|
||||||
|
|
||||||
|
connection = DriverManager.getConnection("jdbc:mysql://" + Config.host + ":" + Config.port + "/" + Config.database + Config.options, Config.user, Config.password);
|
||||||
|
} catch (ClassNotFoundException | SQLException ex) {
|
||||||
|
ALogger.fatal("Failed to connect to sql.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnect() {
|
||||||
|
if (connection != null) {
|
||||||
|
try {
|
||||||
|
connection.close();
|
||||||
|
|
||||||
|
connection = null;
|
||||||
|
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
ALogger.fatal("Failed to disconnect from sql.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
32
api/src/main/java/com/alttd/boosterapi/util/ALogger.java
Executable file
32
api/src/main/java/com/alttd/boosterapi/util/ALogger.java
Executable file
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.alttd.boosterapi.util;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||||
|
|
||||||
|
public class ALogger {
|
||||||
|
|
||||||
|
private static org.slf4j.Logger logger;
|
||||||
|
|
||||||
|
public static void init(org.slf4j.Logger log) {
|
||||||
|
logger = log;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void log(String message) {
|
||||||
|
logger.info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warn(String message) {
|
||||||
|
logger.warn(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void info(String message) {
|
||||||
|
logger.info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(String message) {
|
||||||
|
logger.error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fatal(String error, Exception exception) {
|
||||||
|
logger.error(error + "\n" + ExceptionUtils.getStackTrace(exception));
|
||||||
|
}
|
||||||
|
}
|
||||||
21
api/src/main/java/com/alttd/boosterapi/util/Utils.java
Normal file
21
api/src/main/java/com/alttd/boosterapi/util/Utils.java
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.alttd.boosterapi.util;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
import net.kyori.adventure.text.minimessage.template.TemplateResolver;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Utils {
|
||||||
|
|
||||||
|
public static Component parseMiniMessage(String message, List<Template> templates) {
|
||||||
|
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
if (templates == null) {
|
||||||
|
return miniMessage.deserialize(message);
|
||||||
|
} else {
|
||||||
|
return miniMessage.deserialize(message, TemplateResolver.templates(templates));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
package com.alttd.boosters.api;
|
|
||||||
|
|
||||||
public interface BoosterAPI {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
package com.alttd.boosters.api;
|
|
||||||
|
|
||||||
public class BoosterManager {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
plugins {
|
plugins {
|
||||||
`java-library`
|
`java-library`
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
id("com.github.johnrengelman.shadow") version "7.0.0"
|
id("com.github.johnrengelman.shadow") version "7.1.0"
|
||||||
|
id("net.minecrell.plugin-yml.bukkit") version "0.5.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
val build = System.getenv("BUILD_NUMBER") ?: "SNAPSHOT"
|
|
||||||
group = "com.alttd.boosters"
|
group = "com.alttd.boosters"
|
||||||
version = "1.0.0-BETA-$build"
|
version = "1.0.0-BETA-SNAPSHOT"
|
||||||
description = "Easily manage all boosters on the Altitude Minecraft Server Network."
|
description = "Easily manage all boosters on the Altitude Minecraft Server Network."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ subprojects {
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain {
|
toolchain {
|
||||||
languageVersion.set(JavaLanguageVersion.of(16))
|
languageVersion.set(JavaLanguageVersion.of(17))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,9 +41,8 @@ subprojects {
|
||||||
configure<PublishingExtension> {
|
configure<PublishingExtension> {
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
name = "nexus"
|
name = "maven"
|
||||||
url = uri("http://$name:8081/snapshots")
|
url = uri("https://repo.destro.xyz/snapshots/")
|
||||||
isAllowInsecureProtocol = true
|
|
||||||
credentials(PasswordCredentials::class)
|
credentials(PasswordCredentials::class)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -55,16 +54,22 @@ dependencies {
|
||||||
implementation(project(":boosters-api"))
|
implementation(project(":boosters-api"))
|
||||||
implementation(project(":plugin"))
|
implementation(project(":plugin"))
|
||||||
implementation(project(":velocity"))
|
implementation(project(":velocity"))
|
||||||
implementation("net.kyori", "adventure-text-minimessage", "4.1.0-SNAPSHOT")
|
// implementation("net.kyori", "adventure-text-minimessage", "4.2.0-SNAPSHOT")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
archiveFileName.set("${project.name}-${project.version}.jar")
|
archiveFileName.set("${project.name}-${project.version}.jar")
|
||||||
|
minimize() {
|
||||||
|
exclude { it.moduleName == "boosters-api" }
|
||||||
|
exclude { it.moduleName == "plugin" }
|
||||||
|
exclude { it.moduleName == "velocity" }
|
||||||
|
}
|
||||||
listOf(
|
listOf(
|
||||||
"net.kyori.adventure.text.minimessage"
|
"net.kyori.adventure.text.minimessage",
|
||||||
).forEach { relocate(it, "${rootProject.group}.lib.$it") }
|
"org.spongepowered.configurate"
|
||||||
|
).forEach { relocate(it, "${rootProject.name}.lib.$it") }
|
||||||
}
|
}
|
||||||
|
|
||||||
build {
|
build {
|
||||||
|
|
@ -72,3 +77,4 @@ tasks {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
|
@ -1,5 +1,5 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,39 @@
|
||||||
plugins {
|
plugins {
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
|
id("com.github.johnrengelman.shadow")
|
||||||
|
id("net.minecrell.plugin-yml.bukkit")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// API
|
// API
|
||||||
implementation(project(":boosters-api"))
|
implementation(project(":boosters-api"))
|
||||||
// Galaxy
|
// Galaxy
|
||||||
compileOnly("com.alttd:galaxy-api:1.17.1-R0.1-SNAPSHOT")
|
compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT")
|
||||||
|
// MyPet
|
||||||
|
compileOnly("de.keyle:mypet:3.12-SNAPSHOT")
|
||||||
|
// mcMMO
|
||||||
|
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.1.206")
|
||||||
|
compileOnly("com.sk89q.worldguard:worldguard-core:7.0.4") {
|
||||||
|
exclude("com.google.code.findbugs")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveFileName.set("${project.name}-${project.version}.jar")
|
||||||
|
}
|
||||||
|
|
||||||
|
build {
|
||||||
|
dependsOn(shadowJar)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bukkit {
|
||||||
|
name = rootProject.name
|
||||||
|
main = "$group.BoostersPlugin"
|
||||||
|
apiVersion = "1.18"
|
||||||
|
authors = listOf("destro174")
|
||||||
|
softDepend = listOf("MyPet", "mcMMO")
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
package com.alttd.boosters;
|
|
||||||
|
|
||||||
import com.alttd.boosters.api.BoosterAPI;
|
|
||||||
|
|
||||||
public class BoosterAPIProvider implements BoosterAPI {
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
package com.alttd.boosters;
|
package com.alttd.boosters;
|
||||||
|
|
||||||
import com.alttd.boosters.api.BoosterAPI;
|
import com.alttd.boosterapi.BoosterAPI;
|
||||||
|
import com.alttd.boosterapi.BoosterImplementation;
|
||||||
|
import com.alttd.boosterapi.config.Config;
|
||||||
|
import com.alttd.boosters.listeners.MCmmoListener;
|
||||||
|
import com.alttd.boosters.listeners.MyPetListener;
|
||||||
|
import com.alttd.boosters.listeners.PhantomSpawnListener;
|
||||||
|
import com.alttd.boosters.listeners.PluginMessage;
|
||||||
|
import com.alttd.boosters.managers.BoosterManager;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
@ -9,16 +16,32 @@ public final class BoostersPlugin extends JavaPlugin {
|
||||||
|
|
||||||
private static BoostersPlugin instance;
|
private static BoostersPlugin instance;
|
||||||
private static BoosterAPI boosterAPI;
|
private static BoosterAPI boosterAPI;
|
||||||
|
private static BoosterManager boosterManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
boosterAPI = new BoosterAPIProvider();
|
boosterAPI = new BoosterImplementation();
|
||||||
|
boosterManager = new BoosterManager();
|
||||||
|
|
||||||
|
if (getServer().getPluginManager().isPluginEnabled("MyPet")) {
|
||||||
|
registerListener(new MyPetListener());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getServer().getPluginManager().isPluginEnabled("mcMMO")) {
|
||||||
|
registerListener(new MCmmoListener());
|
||||||
|
}
|
||||||
|
|
||||||
|
registerListener(new PhantomSpawnListener());
|
||||||
|
|
||||||
|
getServer().getMessenger().registerOutgoingPluginChannel(this, Config.pluginMessageChannel);
|
||||||
|
getServer().getMessenger().registerIncomingPluginChannel(this, Config.pluginMessageChannel, new PluginMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
instance = null;
|
||||||
|
boosterAPI = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerListener(Listener... listeners) {
|
public void registerListener(Listener... listeners) {
|
||||||
|
|
@ -38,4 +61,8 @@ public final class BoostersPlugin extends JavaPlugin {
|
||||||
public BoosterAPI getAPI() {
|
public BoosterAPI getAPI() {
|
||||||
return boosterAPI;
|
return boosterAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BoosterManager getBoosterManager() {
|
||||||
|
return boosterManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package com.alttd.boosters.data;
|
package com.alttd.boosters.data;
|
||||||
|
|
||||||
import com.alttd.boosters.api.BoosterType;
|
import com.alttd.boosterapi.BoosterType;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Booster implements com.alttd.boosters.api.Booster {
|
public class Booster implements com.alttd.boosterapi.Booster {
|
||||||
|
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
private String activator;
|
private String activator;
|
||||||
|
|
@ -30,7 +30,6 @@ public class Booster implements com.alttd.boosters.api.Booster {
|
||||||
this(UUID.randomUUID(), type, playerName, duration, multiplier);
|
this(UUID.randomUUID(), type, playerName, duration, multiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return active;
|
return active;
|
||||||
|
|
@ -114,4 +113,16 @@ public class Booster implements com.alttd.boosters.api.Booster {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finish() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean finished() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
plugin/src/main/java/com/alttd/boosters/listeners/MCmmoListener.java
Executable file
32
plugin/src/main/java/com/alttd/boosters/listeners/MCmmoListener.java
Executable file
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.alttd.boosters.listeners;
|
||||||
|
|
||||||
|
import com.alttd.boosterapi.Booster;
|
||||||
|
import com.alttd.boosterapi.BoosterType;
|
||||||
|
import com.alttd.boosters.BoostersPlugin;
|
||||||
|
import com.alttd.boosters.managers.BoosterManager;
|
||||||
|
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class MCmmoListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onMcMMOExperienceEvent(McMMOPlayerXpGainEvent event) {
|
||||||
|
BoosterManager bm = BoostersPlugin.getInstance().getBoosterManager();
|
||||||
|
if (bm.isBoosted(BoosterType.MCMMO)) {
|
||||||
|
Booster b = bm.getBooster(BoosterType.MCMMO);
|
||||||
|
int multiplier = b.getMultiplier();
|
||||||
|
event.setRawXpGained(event.getRawXpGained() * multiplier);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String skillName = event.getSkill().name();
|
||||||
|
BoosterType type = BoosterType.getByName(skillName);
|
||||||
|
if (bm.isBoosted(type)) {
|
||||||
|
Booster b = bm.getBooster(type);
|
||||||
|
int multiplier = b.getMultiplier();
|
||||||
|
event.setRawXpGained(event.getRawXpGained() * multiplier);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO : add individual mcmmo skill boosters
|
||||||
|
}
|
||||||
22
plugin/src/main/java/com/alttd/boosters/listeners/MyPetListener.java
Executable file
22
plugin/src/main/java/com/alttd/boosters/listeners/MyPetListener.java
Executable file
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.alttd.boosters.listeners;
|
||||||
|
|
||||||
|
import com.alttd.boosterapi.Booster;
|
||||||
|
import com.alttd.boosterapi.BoosterType;
|
||||||
|
import com.alttd.boosters.BoostersPlugin;
|
||||||
|
import com.alttd.boosters.managers.BoosterManager;
|
||||||
|
import de.Keyle.MyPet.api.event.MyPetExpEvent;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class MyPetListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onMyPetExpEvent(MyPetExpEvent event) {
|
||||||
|
BoosterManager bm = BoostersPlugin.getInstance().getBoosterManager();
|
||||||
|
if(bm.isBoosted(BoosterType.MYPET)) {
|
||||||
|
Booster b = bm.getBooster(BoosterType.MYPET);
|
||||||
|
int multiplier = b.getMultiplier();
|
||||||
|
event.setExp(event.getExp() * multiplier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
plugin/src/main/java/com/alttd/boosters/listeners/PhantomSpawnListener.java
Executable file
22
plugin/src/main/java/com/alttd/boosters/listeners/PhantomSpawnListener.java
Executable file
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.alttd.boosters.listeners;
|
||||||
|
|
||||||
|
import com.alttd.boosterapi.BoosterType;
|
||||||
|
import com.alttd.boosters.BoostersPlugin;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class PhantomSpawnListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPhantomPreSpawn(com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent event) {
|
||||||
|
Entity spawningEntity = event.getSpawningEntity();
|
||||||
|
if (spawningEntity instanceof Player player
|
||||||
|
&& BoostersPlugin.getInstance().getBoosterManager().isBoosted(BoosterType.PHANTOM)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
event.setShouldAbortSpawn(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.alttd.boosters.listeners;
|
||||||
|
|
||||||
|
import com.alttd.boosterapi.config.Config;
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
|
||||||
|
public class PluginMessage implements PluginMessageListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPluginMessageReceived(String channel, Player player, byte[] bytes) {
|
||||||
|
if(!channel.equals(Config.pluginMessageChannel)) return;
|
||||||
|
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
||||||
|
String subChannel = in.readUTF();
|
||||||
|
// Listen to plugin messages from velocity to either activate or deactive a booster.
|
||||||
|
switch (subChannel) {
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.alttd.boosters.managers;
|
||||||
|
|
||||||
|
import com.alttd.boosterapi.Booster;
|
||||||
|
import com.alttd.boosterapi.BoosterType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BoosterManager {
|
||||||
|
|
||||||
|
private static List<Booster> activeBoosters;
|
||||||
|
|
||||||
|
public boolean isBoosted(BoosterType type) {
|
||||||
|
for (Booster b : activeBoosters) {
|
||||||
|
if (b.getType() == type && b.isActive()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Booster getBooster(BoosterType type) {
|
||||||
|
for (Booster b : activeBoosters) {
|
||||||
|
if (b.getType() == type && b.isActive()) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
# we can have gradle generate this file
|
|
||||||
name: BoosterPlugin
|
|
||||||
version: 1.0 # TODO version from gradle
|
|
||||||
main: com.alttd.boosters.BoosterPlugin
|
|
||||||
api-version: 1.17
|
|
||||||
load: STARTUP
|
|
||||||
authors: [Destro, Teriuihi]
|
|
||||||
|
|
@ -5,17 +5,20 @@ include(":velocity")
|
||||||
|
|
||||||
dependencyResolutionManagement {
|
dependencyResolutionManagement {
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
// Altitude - Galaxy
|
mavenCentral()
|
||||||
maven {
|
maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
|
||||||
name = "maven"
|
maven("https://oss.sonatype.org/content/groups/public/") // Adventure
|
||||||
url = uri("http://leo:8081/")
|
maven("https://nexus.velocitypowered.com/repository/maven-public/") // Velocity
|
||||||
isAllowInsecureProtocol = true
|
maven("https://repo.spongepowered.org/maven") // Configurate
|
||||||
//credentials(PasswordCredentials::class)
|
maven("https://nexus.neetgames.com/repository/maven-releases/") // mcMMO
|
||||||
|
maven("https://maven.enginehub.org/repo/") // worldguard
|
||||||
|
maven { // mypet
|
||||||
|
name = "GitHubPackages"
|
||||||
|
url = uri("https://maven.pkg.github.com/MyPetORG/MyPet")
|
||||||
|
credentials(PasswordCredentials::class)
|
||||||
}
|
}
|
||||||
// Velocity
|
|
||||||
maven("https://nexus.velocitypowered.com/repository/maven-public/")
|
|
||||||
}
|
}
|
||||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
plugins {
|
plugins {
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
|
id("com.github.johnrengelman.shadow")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
@ -10,4 +11,27 @@ dependencies {
|
||||||
annotationProcessor("com.velocitypowered:velocity-api:3.0.0")
|
annotationProcessor("com.velocitypowered:velocity-api:3.0.0")
|
||||||
// DiscordLink
|
// DiscordLink
|
||||||
compileOnly("com.alttd.proxydiscordlink:ProxyDiscordLink:1.0.0-BETA-SNAPSHOT")
|
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;
|
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.DiscordLink;
|
||||||
import com.alttd.proxydiscordlink.bot.api.DiscordSendMessage;
|
import com.alttd.proxydiscordlink.bot.api.DiscordSendMessage;
|
||||||
import com.alttd.vboosters.commands.BoosterCommand;
|
import com.alttd.vboosters.commands.BoosterCommand;
|
||||||
import com.alttd.vboosters.listeners.PluginMessageListener;
|
import com.alttd.vboosters.listeners.PluginMessageListener;
|
||||||
|
import com.alttd.vboosters.managers.BoosterManager;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
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.Dependency;
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
|
@ -26,6 +31,9 @@ public class VelocityBoosters {
|
||||||
private final ProxyServer server;
|
private final ProxyServer server;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
|
private BoosterAPI boosterAPI;
|
||||||
|
private BoosterManager boosterManager;
|
||||||
|
|
||||||
private ChannelIdentifier channelIdentifier = MinecraftChannelIdentifier.from("altitude:boosterplugin");
|
private ChannelIdentifier channelIdentifier = MinecraftChannelIdentifier.from("altitude:boosterplugin");
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|
@ -37,12 +45,25 @@ public class VelocityBoosters {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
|
ALogger.init(logger);
|
||||||
|
boosterAPI = new BoosterImplementation();
|
||||||
|
boosterManager = new BoosterManager(this);
|
||||||
|
|
||||||
server.getChannelRegistrar().register(channelIdentifier);
|
server.getChannelRegistrar().register(channelIdentifier);
|
||||||
server.getEventManager().register(this, new PluginMessageListener(channelIdentifier));
|
server.getEventManager().register(this, new PluginMessageListener(channelIdentifier));
|
||||||
|
|
||||||
loadCommands();
|
loadCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onShutdown(ProxyShutdownEvent event) {
|
||||||
|
boosterManager.saveAllBoosters();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadConfig() {
|
||||||
|
boosterAPI.reloadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
public static VelocityBoosters getPlugin() {
|
public static VelocityBoosters getPlugin() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
@ -64,4 +85,8 @@ public class VelocityBoosters {
|
||||||
return channelIdentifier;
|
return channelIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BoosterManager getBoosterManager() {
|
||||||
|
return boosterManager;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
package com.alttd.vboosters.data;
|
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;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class VelocityBooster implements com.alttd.boosters.api.Booster{
|
public class VelocityBooster implements Booster {
|
||||||
|
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
private String activator;
|
private String activator;
|
||||||
|
|
@ -30,7 +31,6 @@ public class VelocityBooster implements com.alttd.boosters.api.Booster{
|
||||||
this(UUID.randomUUID(), type, playerName, duration, multiplier);
|
this(UUID.randomUUID(), type, playerName, duration, multiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return active;
|
return active;
|
||||||
|
|
@ -106,12 +106,24 @@ public class VelocityBooster implements com.alttd.boosters.api.Booster{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopBooster() {
|
public void stopBooster() {
|
||||||
|
setDuration(getTimeRemaining());
|
||||||
|
setActive(false);
|
||||||
|
saveBooster();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveBooster() {
|
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;
|
package com.alttd.vboosters.managers;
|
||||||
|
|
||||||
import com.alttd.boosters.api.Booster;
|
import com.alttd.boosterapi.Booster;
|
||||||
import com.alttd.boosters.api.BoosterType;
|
import com.alttd.boosterapi.BoosterType;
|
||||||
|
import com.alttd.boosterapi.config.Config;
|
||||||
import com.alttd.vboosters.VelocityBoosters;
|
import com.alttd.vboosters.VelocityBoosters;
|
||||||
import com.alttd.vboosters.config.Config;
|
|
||||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
@ -19,27 +18,38 @@ public class BoosterManager {
|
||||||
|
|
||||||
private static List<Booster> queuedBoosters;
|
private static List<Booster> queuedBoosters;
|
||||||
private static List<Booster> activeBoosters;
|
private static List<Booster> activeBoosters;
|
||||||
private static ScheduledTask queueBoosterTask;
|
private static ScheduledTask boostersTask;
|
||||||
private static ScheduledTask activeBoostersTask;
|
|
||||||
|
|
||||||
public void init() {
|
public BoosterManager(VelocityBoosters velocityBoosters) {
|
||||||
plugin = VelocityBoosters.getPlugin();
|
plugin = velocityBoosters;
|
||||||
activeBoosters = new ArrayList<>();
|
activeBoosters = new ArrayList<>();
|
||||||
queuedBoosters = new ArrayList<>();
|
queuedBoosters = new ArrayList<>();
|
||||||
/*
|
/*
|
||||||
* This is mainly used to count down the active boosters and
|
* This is mainly used to count down the active boosters and
|
||||||
* let backend servers know if one should be activated/deactivated
|
* 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()) {
|
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();
|
}).repeat(Config.activeTaskCheckFrequency, TimeUnit.SECONDS).schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadBoosters() {
|
public void loadBoosters() {
|
||||||
|
// load boosters from datastorage and check them one by one to activate them
|
||||||
for (BoosterType type : BoosterType.values()) {
|
for (BoosterType type : BoosterType.values()) {
|
||||||
if (isBoosted(type)) {
|
if (isBoosted(type)) {
|
||||||
Booster activeBooster = getBoosted(type);
|
Booster activeBooster = getBoosted(type);
|
||||||
|
|
@ -72,27 +82,6 @@ public class BoosterManager {
|
||||||
public void removeBooster(Booster booster) {
|
public void removeBooster(Booster booster) {
|
||||||
activeBoosters.remove(booster);
|
activeBoosters.remove(booster);
|
||||||
booster.stopBooster();
|
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) {
|
public void swapBooster(Booster activeBooster, Booster queuedBooster) {
|
||||||
|
|
@ -104,20 +93,12 @@ public class BoosterManager {
|
||||||
queuedBoosters.remove(booster);
|
queuedBoosters.remove(booster);
|
||||||
activeBoosters.add(booster);
|
activeBoosters.add(booster);
|
||||||
booster.setActive(true);
|
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) {
|
public void deactivateBooster(Booster booster) {
|
||||||
queuedBoosters.add(booster);
|
queuedBoosters.add(booster);
|
||||||
activeBoosters.remove(booster);
|
activeBoosters.remove(booster);
|
||||||
booster.setActive(false);
|
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) {
|
public boolean isBoosted(BoosterType type) {
|
||||||
|
|
@ -156,11 +137,13 @@ public class BoosterManager {
|
||||||
|
|
||||||
public void saveAllBoosters() {
|
public void saveAllBoosters() {
|
||||||
for (Booster b : activeBoosters) {
|
for (Booster b : activeBoosters) {
|
||||||
b.saveBooster();
|
b.stopBooster();
|
||||||
}
|
}
|
||||||
for (Booster b : queuedBoosters) {
|
for (Booster b : queuedBoosters) {
|
||||||
b.saveBooster();
|
b.saveBooster();
|
||||||
}
|
}
|
||||||
|
activeBoosters = null;
|
||||||
|
queuedBoosters = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.alttd.vboosters.task;
|
package com.alttd.vboosters.task;
|
||||||
|
|
||||||
|
import com.alttd.boosterapi.config.Config;
|
||||||
import com.alttd.vboosters.VelocityBoosters;
|
import com.alttd.vboosters.VelocityBoosters;
|
||||||
import com.alttd.vboosters.config.Config;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ public class BoosterTask {
|
||||||
public void init() {
|
public void init() {
|
||||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
||||||
|
|
||||||
}).repeat(Config.TaskCheckFrequency, TimeUnit.SECONDS).schedule();
|
}).repeat(Config.taskCheckFrequency, TimeUnit.SECONDS).schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user