Loading in boosters (still untested) started on having proxy communicate booster updates to the server

This commit is contained in:
Stijn 2022-08-01 21:39:26 +02:00
parent 6b95f89fd6
commit 8b4178122e
5 changed files with 42 additions and 2 deletions

View File

@ -28,6 +28,11 @@ public abstract class BoosterStorage {
mapper.enable(SerializationFeature.INDENT_OUTPUT);
}
public void reload() {
boosters.clear();
loadBoosters();
}
public Map<UUID, Booster> getBoosters() {
return boosters;
}

View File

@ -8,6 +8,7 @@ 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 com.alttd.boosters.storage.ServerBoosterStorage;
import org.bukkit.command.CommandExecutor;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
@ -36,6 +37,7 @@ public final class BoostersPlugin extends JavaPlugin {
getServer().getMessenger().registerOutgoingPluginChannel(this, Config.pluginMessageChannel);
getServer().getMessenger().registerIncomingPluginChannel(this, Config.pluginMessageChannel, new PluginMessage());
ServerBoosterStorage.getServerBoosterStorage(); //this loads the boosters in
}
@Override

View File

@ -1,11 +1,16 @@
package com.alttd.boosters.listeners;
import com.alttd.boosterapi.Booster;
import com.alttd.boosterapi.config.Config;
import com.alttd.boosterapi.util.ALogger;
import com.alttd.boosters.storage.ServerBoosterStorage;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import java.util.UUID;
public class PluginMessage implements PluginMessageListener {
@Override
@ -15,8 +20,30 @@ public class PluginMessage implements PluginMessageListener {
String subChannel = in.readUTF();
// Listen to plugin messages from velocity to either activate or deactive a booster.
switch (subChannel) {
default:
break;
case "activate" -> {
ServerBoosterStorage.getServerBoosterStorage().reload();
//TODO maybe make this add one thing to the map without resetting it to avoid having to clear it
// (still need to load it all to get that one booster though)
}
case "finish" -> {
UUID uuid = UUID.fromString(in.readUTF());
Booster booster = ServerBoosterStorage.getServerBoosterStorage().getBoosters().get(uuid);
if (booster == null) {
ALogger.error("Tried to finish booster that was never loaded [" + uuid + "]");
break;
}
booster.finish();
}
case "stop" -> {
UUID uuid = UUID.fromString(in.readUTF());
Booster booster = ServerBoosterStorage.getServerBoosterStorage().getBoosters().get(uuid);
if (booster == null) {
ALogger.error("Tried to stop booster that was never loaded [" + uuid + "]");
break;
}
booster.stopBooster();
}
default -> {}
}
}
}

View File

@ -9,6 +9,7 @@ import com.alttd.vboosters.commands.BoosterCommand;
import com.alttd.vboosters.commands.DonorRankCommand;
import com.alttd.vboosters.listeners.PluginMessageListener;
import com.alttd.vboosters.managers.BoosterManager;
import com.alttd.vboosters.storage.VelocityBoosterStorage;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
@ -54,6 +55,7 @@ public class VelocityBoosters {
server.getEventManager().register(this, new PluginMessageListener(channelIdentifier));
loadCommands();
VelocityBoosterStorage.getVelocityBoosterStorage(); //this loads the boosters in
}
@Subscribe

View File

@ -124,6 +124,9 @@ public class VelocityBooster implements Booster {
setDuration(getTimeRemaining());
setActive(false);
saveBooster();
if (!finished) {
//TODO send plugin message that its stopped
}
}
@Override
@ -136,6 +139,7 @@ public class VelocityBooster implements Booster {
public void finish() { //TODO finish it on the servers as well
finished = true;
stopBooster();
//TODO send plugin message that this is finished
}
@Override