Loading in boosters (still untested) started on having proxy communicate booster updates to the server
This commit is contained in:
parent
6b95f89fd6
commit
8b4178122e
|
|
@ -28,6 +28,11 @@ public abstract class BoosterStorage {
|
||||||
mapper.enable(SerializationFeature.INDENT_OUTPUT);
|
mapper.enable(SerializationFeature.INDENT_OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reload() {
|
||||||
|
boosters.clear();
|
||||||
|
loadBoosters();
|
||||||
|
}
|
||||||
|
|
||||||
public Map<UUID, Booster> getBoosters() {
|
public Map<UUID, Booster> getBoosters() {
|
||||||
return boosters;
|
return boosters;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import com.alttd.boosters.listeners.MyPetListener;
|
||||||
import com.alttd.boosters.listeners.PhantomSpawnListener;
|
import com.alttd.boosters.listeners.PhantomSpawnListener;
|
||||||
import com.alttd.boosters.listeners.PluginMessage;
|
import com.alttd.boosters.listeners.PluginMessage;
|
||||||
import com.alttd.boosters.managers.BoosterManager;
|
import com.alttd.boosters.managers.BoosterManager;
|
||||||
|
import com.alttd.boosters.storage.ServerBoosterStorage;
|
||||||
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;
|
||||||
|
|
@ -36,6 +37,7 @@ public final class BoostersPlugin extends JavaPlugin {
|
||||||
|
|
||||||
getServer().getMessenger().registerOutgoingPluginChannel(this, Config.pluginMessageChannel);
|
getServer().getMessenger().registerOutgoingPluginChannel(this, Config.pluginMessageChannel);
|
||||||
getServer().getMessenger().registerIncomingPluginChannel(this, Config.pluginMessageChannel, new PluginMessage());
|
getServer().getMessenger().registerIncomingPluginChannel(this, Config.pluginMessageChannel, new PluginMessage());
|
||||||
|
ServerBoosterStorage.getServerBoosterStorage(); //this loads the boosters in
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,16 @@
|
||||||
package com.alttd.boosters.listeners;
|
package com.alttd.boosters.listeners;
|
||||||
|
|
||||||
|
import com.alttd.boosterapi.Booster;
|
||||||
import com.alttd.boosterapi.config.Config;
|
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.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PluginMessage implements PluginMessageListener {
|
public class PluginMessage implements PluginMessageListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -15,8 +20,30 @@ public class PluginMessage implements PluginMessageListener {
|
||||||
String subChannel = in.readUTF();
|
String subChannel = in.readUTF();
|
||||||
// Listen to plugin messages from velocity to either activate or deactive a booster.
|
// Listen to plugin messages from velocity to either activate or deactive a booster.
|
||||||
switch (subChannel) {
|
switch (subChannel) {
|
||||||
default:
|
case "activate" -> {
|
||||||
break;
|
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 -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import com.alttd.vboosters.commands.BoosterCommand;
|
||||||
import com.alttd.vboosters.commands.DonorRankCommand;
|
import com.alttd.vboosters.commands.DonorRankCommand;
|
||||||
import com.alttd.vboosters.listeners.PluginMessageListener;
|
import com.alttd.vboosters.listeners.PluginMessageListener;
|
||||||
import com.alttd.vboosters.managers.BoosterManager;
|
import com.alttd.vboosters.managers.BoosterManager;
|
||||||
|
import com.alttd.vboosters.storage.VelocityBoosterStorage;
|
||||||
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;
|
||||||
|
|
@ -54,6 +55,7 @@ public class VelocityBoosters {
|
||||||
server.getEventManager().register(this, new PluginMessageListener(channelIdentifier));
|
server.getEventManager().register(this, new PluginMessageListener(channelIdentifier));
|
||||||
|
|
||||||
loadCommands();
|
loadCommands();
|
||||||
|
VelocityBoosterStorage.getVelocityBoosterStorage(); //this loads the boosters in
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,9 @@ public class VelocityBooster implements Booster {
|
||||||
setDuration(getTimeRemaining());
|
setDuration(getTimeRemaining());
|
||||||
setActive(false);
|
setActive(false);
|
||||||
saveBooster();
|
saveBooster();
|
||||||
|
if (!finished) {
|
||||||
|
//TODO send plugin message that its stopped
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -136,6 +139,7 @@ public class VelocityBooster implements Booster {
|
||||||
public void finish() { //TODO finish it on the servers as well
|
public void finish() { //TODO finish it on the servers as well
|
||||||
finished = true;
|
finished = true;
|
||||||
stopBooster();
|
stopBooster();
|
||||||
|
//TODO send plugin message that this is finished
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user