progress on boosters
This commit is contained in:
parent
b6cefd5403
commit
95d219d546
|
|
@ -7,19 +7,19 @@ dependencies {
|
|||
compileOnly("com.alttd:galaxy-api:1.17.1-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
from(components["java"])
|
||||
}
|
||||
}
|
||||
|
||||
repositories{
|
||||
maven {
|
||||
name = "maven"
|
||||
url = uri("http://leo:8081/")
|
||||
isAllowInsecureProtocol = true
|
||||
credentials(PasswordCredentials::class)
|
||||
}
|
||||
}
|
||||
}
|
||||
//publishing {
|
||||
// publications {
|
||||
// create<MavenPublication>("mavenJava") {
|
||||
// from(components["java"])
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// repositories{
|
||||
// maven {
|
||||
// name = "maven"
|
||||
// url = uri("http://leo:8081/")
|
||||
// isAllowInsecureProtocol = true
|
||||
// credentials(PasswordCredentials::class)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
@ -4,7 +4,7 @@ import java.util.UUID;
|
|||
|
||||
public interface Booster {
|
||||
|
||||
boolean active();
|
||||
boolean isActive();
|
||||
|
||||
void setActive(Boolean active);
|
||||
|
||||
|
|
@ -33,4 +33,6 @@ public interface Booster {
|
|||
UUID getUUID();
|
||||
|
||||
void stopBooster();
|
||||
|
||||
void saveBooster();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
id("com.github.johnrengelman.shadow") version "7.0.0"
|
||||
}
|
||||
|
||||
|
|
@ -12,6 +13,7 @@ allprojects {
|
|||
|
||||
subprojects {
|
||||
apply<JavaLibraryPlugin>()
|
||||
apply(plugin = "maven-publish")
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
|
|
@ -28,6 +30,25 @@ subprojects {
|
|||
options.encoding = Charsets.UTF_8.name()
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
from(components["java"])
|
||||
}
|
||||
}
|
||||
|
||||
configure<PublishingExtension> {
|
||||
repositories {
|
||||
maven {
|
||||
name = "nexus"
|
||||
url = uri("http://$name:8081/snapshots")
|
||||
isAllowInsecureProtocol = true
|
||||
credentials(PasswordCredentials::class)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
|
|||
117
plugin/src/main/java/com/alttd/boosters/data/Booster.java
Normal file
117
plugin/src/main/java/com/alttd/boosters/data/Booster.java
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
package com.alttd.boosters.data;
|
||||
|
||||
import com.alttd.boosters.api.BoosterType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Booster implements com.alttd.boosters.api.Booster {
|
||||
|
||||
private UUID uuid;
|
||||
private String activator;
|
||||
private Long startingTime;
|
||||
private long duration;
|
||||
private BoosterType boosterType;
|
||||
private Integer multiplier;
|
||||
private Boolean active;
|
||||
private Boolean finished;
|
||||
|
||||
public Booster(UUID uuid, BoosterType boosterType, String reason, long duration, int multiplier) {
|
||||
this.uuid = uuid;
|
||||
this.boosterType = boosterType;
|
||||
this.activator = reason;
|
||||
this.duration = duration;
|
||||
this.multiplier = multiplier;
|
||||
this.active = false;
|
||||
this.finished = false;
|
||||
saveBooster();
|
||||
}
|
||||
|
||||
public Booster(BoosterType type, String playerName, long duration, int multiplier) {
|
||||
this(UUID.randomUUID(), type, playerName, duration, multiplier);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive(Boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BoosterType getType() {
|
||||
return boosterType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(BoosterType boosterType) {
|
||||
this.boosterType = boosterType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMultiplier() {
|
||||
return multiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMultiplier(int multiplier) {
|
||||
this.multiplier = multiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getStartingTime() {
|
||||
return startingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStartingTime(long startingTime) {
|
||||
this.startingTime = startingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDuration(long duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActivator() {
|
||||
return activator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivator(String activationReason) {
|
||||
this.activator = activationReason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimeRemaining() {
|
||||
if(active) {
|
||||
return startingTime + duration - System.currentTimeMillis();
|
||||
}
|
||||
return duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopBooster() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveBooster() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ include(":velocity")
|
|||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
// Altitude - Galaxy
|
||||
maven {
|
||||
name = "maven"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ dependencies {
|
|||
// API
|
||||
implementation(project(":boosters-api"))
|
||||
// Velocity
|
||||
compileOnly("com.velocitypowered:velocity-api:1.1.5")
|
||||
annotationProcessor("com.velocitypowered:velocity-api:1.1.5")
|
||||
compileOnly("com.velocitypowered:velocity-api:3.0.0")
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.0.0")
|
||||
// DiscordLink
|
||||
compileOnly("com.alttd.proxydiscordlink:ProxyDiscordLink:1.0.0-BETA-SNAPSHOT")
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
package com.alttd.boosters;
|
||||
package com.alttd.vboosters;
|
||||
|
||||
import com.alttd.boosters.listeners.PluginMessageListener;
|
||||
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.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
|
|
@ -15,7 +18,7 @@ import org.slf4j.Logger;
|
|||
@Plugin(id = "boosterplugin", name = "BoosterPlugin", version = "1.0.0",
|
||||
description = "Easily manage all boosters on the Altitude Minecraft Server Network.",
|
||||
authors = {"destro174", "teri"},
|
||||
dependencies = {@Dependency(id = "luckperms")}
|
||||
dependencies = {@Dependency(id = "luckperms"),@Dependency(id = "proxydiscordlink")}
|
||||
)
|
||||
public class VelocityBoosters {
|
||||
|
||||
|
|
@ -54,6 +57,7 @@ public class VelocityBoosters {
|
|||
|
||||
public void loadCommands() {
|
||||
// all (proxy)commands go here
|
||||
new BoosterCommand(server);
|
||||
}
|
||||
|
||||
public ChannelIdentifier getChannelIdentifier() {
|
||||
35
velocity/src/main/java/com/alttd/vboosters/commands/BoosterCommand.java
Executable file
35
velocity/src/main/java/com/alttd/vboosters/commands/BoosterCommand.java
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
package com.alttd.vboosters.commands;
|
||||
|
||||
import com.alttd.proxydiscordlink.bot.api.DiscordSendMessage;
|
||||
import com.alttd.vboosters.VelocityBoosters;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import com.velocitypowered.api.command.BrigadierCommand;
|
||||
import com.velocitypowered.api.command.CommandMeta;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
||||
public class BoosterCommand {
|
||||
|
||||
public BoosterCommand(ProxyServer proxyServer) {
|
||||
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||
.<CommandSource>literal("booster")
|
||||
.requires(ctx -> ctx.hasPermission("command.proxy.booster"))
|
||||
.executes(context -> {
|
||||
String channelid = "776590138296893483";
|
||||
String msg = "CONSOLEUSER activated booster of type BoosterType.MMMCALL for 48 hours.";
|
||||
DiscordSendMessage.sendEmbed(Long.parseLong(channelid),"Booster Activated" , msg);
|
||||
VelocityBoosters.getPlugin().getLogger().info(msg);
|
||||
return 1;
|
||||
})
|
||||
.build();
|
||||
|
||||
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
|
||||
|
||||
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
|
||||
|
||||
CommandMeta meta = metaBuilder.build();
|
||||
|
||||
proxyServer.getCommandManager().register(meta, brigadierCommand);
|
||||
}
|
||||
}
|
||||
166
velocity/src/main/java/com/alttd/vboosters/config/Config.java
Executable file
166
velocity/src/main/java/com/alttd/vboosters/config/Config.java
Executable file
|
|
@ -0,0 +1,166 @@
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
package com.alttd.vboosters.data;
|
||||
|
||||
import com.alttd.boosters.api.BoosterType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class VelocityBooster implements com.alttd.boosters.api.Booster{
|
||||
|
||||
private UUID uuid;
|
||||
private String activator;
|
||||
private Long startingTime;
|
||||
private long duration;
|
||||
private BoosterType boosterType;
|
||||
private Integer multiplier;
|
||||
private Boolean active;
|
||||
private Boolean finished;
|
||||
|
||||
public VelocityBooster(UUID uuid, BoosterType boosterType, String reason, long duration, int multiplier) {
|
||||
this.uuid = uuid;
|
||||
this.boosterType = boosterType;
|
||||
this.activator = reason;
|
||||
this.duration = duration;
|
||||
this.multiplier = multiplier;
|
||||
this.active = false;
|
||||
this.finished = false;
|
||||
saveBooster();
|
||||
}
|
||||
|
||||
public VelocityBooster(BoosterType type, String playerName, long duration, int multiplier) {
|
||||
this(UUID.randomUUID(), type, playerName, duration, multiplier);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive(Boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BoosterType getType() {
|
||||
return boosterType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(BoosterType boosterType) {
|
||||
this.boosterType = boosterType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMultiplier() {
|
||||
return multiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMultiplier(int multiplier) {
|
||||
this.multiplier = multiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getStartingTime() {
|
||||
return startingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStartingTime(long startingTime) {
|
||||
this.startingTime = startingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDuration(long duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActivator() {
|
||||
return activator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivator(String activationReason) {
|
||||
this.activator = activationReason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimeRemaining() {
|
||||
if(active) {
|
||||
return startingTime + duration - System.currentTimeMillis();
|
||||
}
|
||||
return duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopBooster() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveBooster() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package com.alttd.boosters.listeners;
|
||||
package com.alttd.vboosters.listeners;
|
||||
|
||||
import com.alttd.boosters.VelocityBoosters;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
package com.alttd.vboosters.managers;
|
||||
|
||||
import com.alttd.boosters.api.Booster;
|
||||
import com.alttd.boosters.api.BoosterType;
|
||||
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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BoosterManager {
|
||||
|
||||
private VelocityBoosters plugin;
|
||||
|
||||
private static List<Booster> queuedBoosters;
|
||||
private static List<Booster> activeBoosters;
|
||||
private static ScheduledTask queueBoosterTask;
|
||||
private static ScheduledTask activeBoostersTask;
|
||||
|
||||
public void init() {
|
||||
plugin = VelocityBoosters.getPlugin();
|
||||
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, () -> {
|
||||
for (Booster booster: getActiveBoosters()) {
|
||||
if (booster.getTimeRemaining() <= 0) {
|
||||
|
||||
}
|
||||
}
|
||||
}).repeat(Config.activeTaskCheckFrequency, TimeUnit.SECONDS).schedule();
|
||||
}
|
||||
|
||||
public void loadBoosters() {
|
||||
for (BoosterType type : BoosterType.values()) {
|
||||
if (isBoosted(type)) {
|
||||
Booster activeBooster = getBoosted(type);
|
||||
Booster queuedBooster = getHighestBooster(type);
|
||||
if (queuedBooster != null && queuedBooster.getMultiplier() > activeBooster.getMultiplier()) {
|
||||
swapBooster(activeBooster, queuedBooster);
|
||||
}
|
||||
} else {
|
||||
Booster queuedBooster = getHighestBooster(type);
|
||||
if(queuedBooster == null)
|
||||
continue;
|
||||
activateBooster(queuedBooster);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addBooster(Booster booster) {
|
||||
BoosterType type = booster.getType();
|
||||
if(isBoosted(type)) {
|
||||
Booster activeBooster = getBoosted(type);
|
||||
Booster queuedBooster = getHighestBooster(type);
|
||||
if (queuedBooster != null && queuedBooster.getMultiplier() > activeBooster.getMultiplier()) {
|
||||
swapBooster(activeBooster, queuedBooster);
|
||||
}
|
||||
} else {
|
||||
activateBooster(booster);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
deactivateBooster(activeBooster);
|
||||
activateBooster(queuedBooster);
|
||||
}
|
||||
|
||||
public void activateBooster(Booster booster) {
|
||||
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) {
|
||||
for (Booster b : activeBoosters) {
|
||||
if (b.getType() == type && b.isActive()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Booster getBoosted(BoosterType type) {
|
||||
for (Booster b : activeBoosters) {
|
||||
if (b.getType() == type && b.isActive()) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Booster getHighestBooster(BoosterType type) {
|
||||
return getQueuedBooster(type).stream().max(Comparator.comparing(Booster::getMultiplier)).orElse(null);
|
||||
}
|
||||
|
||||
public List<Booster> getActiveBoosters() {
|
||||
return activeBoosters;
|
||||
}
|
||||
|
||||
public List<Booster> getQueuedBoosters() {
|
||||
return queuedBoosters;
|
||||
}
|
||||
|
||||
public List<Booster> getQueuedBooster(BoosterType type) {
|
||||
return getQueuedBoosters().stream().filter(booster -> booster.getType() == type).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void saveAllBoosters() {
|
||||
for (Booster b : activeBoosters) {
|
||||
b.saveBooster();
|
||||
}
|
||||
for (Booster b : queuedBoosters) {
|
||||
b.saveBooster();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.alttd.vboosters.task;
|
||||
|
||||
import com.alttd.vboosters.VelocityBoosters;
|
||||
import com.alttd.vboosters.config.Config;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BoosterTask {
|
||||
|
||||
private VelocityBoosters plugin;
|
||||
|
||||
public BoosterTask() {
|
||||
super();
|
||||
plugin = VelocityBoosters.getPlugin();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
||||
|
||||
}).repeat(Config.TaskCheckFrequency, TimeUnit.SECONDS).schedule();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user