mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2025-12-29 11:39:16 +00:00
Started working on moving from Guice to Avaje Inject
This commit is contained in:
@@ -25,15 +25,14 @@
|
||||
|
||||
package org.geysermc.floodgate;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import io.avaje.inject.BeanScope;
|
||||
import java.util.UUID;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
import org.geysermc.floodgate.api.InstanceHolder;
|
||||
import org.geysermc.floodgate.api.ProxyModule;
|
||||
import org.geysermc.floodgate.api.ServerModule;
|
||||
import org.geysermc.floodgate.api.event.FloodgateEventBus;
|
||||
import org.geysermc.floodgate.api.handshake.HandshakeHandlers;
|
||||
import org.geysermc.floodgate.api.inject.PlatformInjector;
|
||||
@@ -44,44 +43,42 @@ import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.event.EventBus;
|
||||
import org.geysermc.floodgate.event.lifecycle.PostEnableEvent;
|
||||
import org.geysermc.floodgate.event.lifecycle.ShutdownEvent;
|
||||
import org.geysermc.floodgate.module.PostEnableModules;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
public abstract class FloodgatePlatform {
|
||||
private static final UUID KEY = UUID.randomUUID();
|
||||
private PlatformInjector injector;
|
||||
|
||||
|
||||
private BeanScope scope;
|
||||
private FloodgateConfig config;
|
||||
@Inject private Injector guice;
|
||||
|
||||
|
||||
private PlatformInjector injector;
|
||||
|
||||
public void load() {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
guice = guice != null ?
|
||||
guice.createChildInjector(loadStageModules()) :
|
||||
Guice.createInjector(loadStageModules());
|
||||
scope = BeanScope.builder()
|
||||
.bean("isProxy", boolean.class, isProxy())
|
||||
.modules(new FloodgateModule())
|
||||
.modules(isProxy() ? new ProxyModule() : new ServerModule())
|
||||
.build();
|
||||
|
||||
config = guice.getInstance(FloodgateConfig.class);
|
||||
injector = guice.getInstance(PlatformInjector.class);
|
||||
config = scope.get(FloodgateConfig.class);
|
||||
injector = scope.get(PlatformInjector.class);
|
||||
|
||||
InstanceHolder.set(
|
||||
guice.getInstance(FloodgateApi.class),
|
||||
guice.getInstance(PlayerLink.class),
|
||||
guice.getInstance(FloodgateEventBus.class),
|
||||
scope.get(FloodgateApi.class),
|
||||
scope.get(PlayerLink.class),
|
||||
scope.get(FloodgateEventBus.class),
|
||||
injector,
|
||||
guice.getInstance(PacketHandlers.class),
|
||||
guice.getInstance(HandshakeHandlers.class),
|
||||
scope.get(PacketHandlers.class),
|
||||
scope.get(HandshakeHandlers.class),
|
||||
KEY
|
||||
);
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
guice.getInstance(FloodgateLogger.class)
|
||||
scope.get(FloodgateLogger.class)
|
||||
.translatedInfo("floodgate.core.finish", endTime - startTime);
|
||||
}
|
||||
|
||||
protected abstract Module[] loadStageModules();
|
||||
|
||||
public void enable() throws RuntimeException {
|
||||
if (injector == null) {
|
||||
throw new RuntimeException("Failed to find the platform injector!");
|
||||
@@ -93,15 +90,13 @@ public abstract class FloodgatePlatform {
|
||||
throw new RuntimeException("Failed to inject the packet listener!", exception);
|
||||
}
|
||||
|
||||
this.guice = guice.createChildInjector(new PostEnableModules(postEnableStageModules()));
|
||||
// this.guice = guice.createChildInjector(new PostEnableModules(postEnableStageModules()));
|
||||
|
||||
guice.getInstance(EventBus.class).fire(new PostEnableEvent());
|
||||
scope.get(EventBus.class).fire(new PostEnableEvent());
|
||||
}
|
||||
|
||||
protected abstract Module[] postEnableStageModules();
|
||||
|
||||
public void disable() {
|
||||
guice.getInstance(EventBus.class).fire(new ShutdownEvent());
|
||||
scope.get(EventBus.class).fire(new ShutdownEvent());
|
||||
|
||||
if (injector != null && injector.canRemoveInjection()) {
|
||||
try {
|
||||
@@ -110,9 +105,9 @@ public abstract class FloodgatePlatform {
|
||||
throw new RuntimeException("Failed to remove the injection!", exception);
|
||||
}
|
||||
}
|
||||
|
||||
scope.close();
|
||||
}
|
||||
|
||||
public boolean isProxy() {
|
||||
return config.isProxy();
|
||||
}
|
||||
abstract boolean isProxy();
|
||||
}
|
||||
|
||||
@@ -25,13 +25,15 @@
|
||||
|
||||
package org.geysermc.floodgate.addon;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import io.netty.channel.Channel;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import org.geysermc.floodgate.api.inject.InjectorAddon;
|
||||
import org.geysermc.floodgate.inject.CommonPlatformInjector;
|
||||
|
||||
@Singleton
|
||||
public final class AddonManagerAddon implements InjectorAddon {
|
||||
@Inject private CommonPlatformInjector injector;
|
||||
@Inject CommonPlatformInjector injector;
|
||||
|
||||
@Override
|
||||
public void onInject(Channel channel, boolean toServer) {
|
||||
|
||||
@@ -25,10 +25,11 @@
|
||||
|
||||
package org.geysermc.floodgate.addon;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import jakarta.inject.Singleton;
|
||||
import org.geysermc.floodgate.addon.debug.ChannelInDebugHandler;
|
||||
import org.geysermc.floodgate.addon.debug.ChannelOutDebugHandler;
|
||||
import org.geysermc.floodgate.addon.debug.StateChangeDetector;
|
||||
@@ -37,21 +38,22 @@ import org.geysermc.floodgate.api.logger.FloodgateLogger;
|
||||
import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.util.Utils;
|
||||
|
||||
@Singleton
|
||||
public final class DebugAddon implements InjectorAddon {
|
||||
@Inject private FloodgateConfig config;
|
||||
@Inject private FloodgateLogger logger;
|
||||
@Inject FloodgateConfig config;
|
||||
@Inject FloodgateLogger logger;
|
||||
|
||||
@Inject
|
||||
@Named("implementationName")
|
||||
private String implementationName;
|
||||
String implementationName;
|
||||
|
||||
@Inject
|
||||
@Named("packetEncoder")
|
||||
private String packetEncoder;
|
||||
String packetEncoder;
|
||||
|
||||
@Inject
|
||||
@Named("packetDecoder")
|
||||
private String packetDecoder;
|
||||
String packetDecoder;
|
||||
|
||||
@Override
|
||||
public void onInject(Channel channel, boolean toServer) {
|
||||
|
||||
@@ -25,26 +25,28 @@
|
||||
|
||||
package org.geysermc.floodgate.addon;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import jakarta.inject.Singleton;
|
||||
import org.geysermc.floodgate.addon.packethandler.ChannelInPacketHandler;
|
||||
import org.geysermc.floodgate.addon.packethandler.ChannelOutPacketHandler;
|
||||
import org.geysermc.floodgate.api.inject.InjectorAddon;
|
||||
import org.geysermc.floodgate.packet.PacketHandlersImpl;
|
||||
import org.geysermc.floodgate.util.Utils;
|
||||
|
||||
@Singleton
|
||||
public class PacketHandlerAddon implements InjectorAddon {
|
||||
@Inject private PacketHandlersImpl packetHandlers;
|
||||
@Inject PacketHandlersImpl packetHandlers;
|
||||
|
||||
@Inject
|
||||
@Named("packetEncoder")
|
||||
private String packetEncoder;
|
||||
String packetEncoder;
|
||||
|
||||
@Inject
|
||||
@Named("packetDecoder")
|
||||
private String packetDecoder;
|
||||
String packetDecoder;
|
||||
|
||||
@Override
|
||||
public void onInject(Channel channel, boolean toServer) {
|
||||
|
||||
@@ -27,11 +27,13 @@ package org.geysermc.floodgate.addon.data;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.Random;
|
||||
import org.geysermc.floodgate.api.handshake.HandshakeData;
|
||||
import org.geysermc.floodgate.api.handshake.HandshakeHandler;
|
||||
import org.geysermc.floodgate.api.handshake.HandshakeHandlers;
|
||||
|
||||
@Singleton
|
||||
public class HandshakeHandlersImpl implements HandshakeHandlers {
|
||||
private final Random random = new Random();
|
||||
private final Int2ObjectMap<HandshakeHandler> handshakeHandlers = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
@@ -25,14 +25,16 @@
|
||||
|
||||
package org.geysermc.floodgate.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.geysermc.floodgate.crypto.FloodgateCipher;
|
||||
import org.geysermc.floodgate.scope.ProxyScope;
|
||||
import org.geysermc.floodgate.util.BedrockData;
|
||||
|
||||
@ProxyScope
|
||||
public final class ProxyFloodgateApi extends SimpleFloodgateApi {
|
||||
@Inject
|
||||
private FloodgateCipher cipher;
|
||||
FloodgateCipher cipher;
|
||||
|
||||
public byte[] createEncryptedData(BedrockData bedrockData) {
|
||||
try {
|
||||
|
||||
@@ -30,7 +30,7 @@ import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -46,10 +46,12 @@ import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.pluginmessage.PluginMessageManager;
|
||||
import org.geysermc.floodgate.pluginmessage.channel.FormChannel;
|
||||
import org.geysermc.floodgate.pluginmessage.channel.TransferChannel;
|
||||
import org.geysermc.floodgate.scope.ServerScope;
|
||||
import org.geysermc.floodgate.util.Constants;
|
||||
import org.geysermc.floodgate.util.HttpClient;
|
||||
import org.geysermc.floodgate.util.Utils;
|
||||
|
||||
@ServerScope
|
||||
public class SimpleFloodgateApi implements FloodgateApi {
|
||||
private final Map<UUID, FloodgatePlayer> players = new ConcurrentHashMap<>();
|
||||
private final Cache<UUID, FloodgatePlayer> pendingRemove =
|
||||
@@ -57,10 +59,10 @@ public class SimpleFloodgateApi implements FloodgateApi {
|
||||
.expireAfterWrite(20, TimeUnit.SECONDS)
|
||||
.build();
|
||||
|
||||
@Inject private PluginMessageManager pluginMessageManager;
|
||||
@Inject private FloodgateConfig config;
|
||||
@Inject private HttpClient httpClient;
|
||||
@Inject private FloodgateLogger logger;
|
||||
@Inject PluginMessageManager pluginMessageManager;
|
||||
@Inject FloodgateConfig config;
|
||||
@Inject HttpClient httpClient;
|
||||
@Inject FloodgateLogger logger;
|
||||
|
||||
@Override
|
||||
public String getPlayerPrefix() {
|
||||
|
||||
@@ -32,9 +32,10 @@ import cloud.commandframework.Command;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.arguments.standard.StringArgument;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import com.google.inject.Inject;
|
||||
import io.avaje.inject.Secondary;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
import org.geysermc.floodgate.api.link.LinkRequestResult;
|
||||
import org.geysermc.floodgate.api.link.PlayerLink;
|
||||
@@ -50,10 +51,11 @@ import org.geysermc.floodgate.player.audience.ProfileAudience;
|
||||
import org.geysermc.floodgate.player.audience.ProfileAudienceArgument;
|
||||
import org.geysermc.floodgate.util.Constants;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Singleton
|
||||
@Secondary
|
||||
public final class LinkAccountCommand implements FloodgateCommand {
|
||||
@Inject private FloodgateApi api;
|
||||
@Inject private FloodgateLogger logger;
|
||||
@Inject FloodgateApi api;
|
||||
@Inject FloodgateLogger logger;
|
||||
|
||||
@Override
|
||||
public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandManager) {
|
||||
|
||||
@@ -28,12 +28,14 @@ package org.geysermc.floodgate.command;
|
||||
import cloud.commandframework.Command;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import jakarta.inject.Singleton;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.platform.command.FloodgateCommand;
|
||||
import org.geysermc.floodgate.player.UserAudience;
|
||||
import org.geysermc.floodgate.util.Constants;
|
||||
|
||||
@Singleton
|
||||
public class TestCommand implements FloodgateCommand {
|
||||
@Override
|
||||
public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandManager) {
|
||||
|
||||
@@ -31,11 +31,12 @@ import cloud.commandframework.ArgumentDescription;
|
||||
import cloud.commandframework.Command;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import com.google.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
import org.geysermc.floodgate.api.link.PlayerLink;
|
||||
import org.geysermc.floodgate.command.util.Permission;
|
||||
import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.link.GlobalPlayerLinking;
|
||||
import org.geysermc.floodgate.platform.command.FloodgateCommand;
|
||||
@@ -43,11 +44,10 @@ import org.geysermc.floodgate.platform.command.TranslatableMessage;
|
||||
import org.geysermc.floodgate.player.UserAudience;
|
||||
import org.geysermc.floodgate.player.UserAudience.PlayerAudience;
|
||||
import org.geysermc.floodgate.util.Constants;
|
||||
import org.geysermc.floodgate.command.util.Permission;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Singleton
|
||||
public final class UnlinkAccountCommand implements FloodgateCommand {
|
||||
@Inject private FloodgateApi api;
|
||||
@Inject FloodgateApi api;
|
||||
|
||||
@Override
|
||||
public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandManager) {
|
||||
|
||||
@@ -33,7 +33,8 @@ import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
@@ -51,15 +52,16 @@ import org.geysermc.floodgate.player.audience.ProfileAudienceArgument;
|
||||
import org.geysermc.floodgate.util.Constants;
|
||||
import org.geysermc.floodgate.util.HttpClient;
|
||||
|
||||
@Singleton
|
||||
public class WhitelistCommand implements FloodgateCommand {
|
||||
@Inject private FloodgateConfig config;
|
||||
@Inject private HttpClient httpClient;
|
||||
@Inject private FloodgateLogger logger;
|
||||
@Inject FloodgateConfig config;
|
||||
@Inject HttpClient httpClient;
|
||||
@Inject FloodgateLogger logger;
|
||||
|
||||
@Override
|
||||
public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandManager) {
|
||||
Command.Builder<UserAudience> builder = commandManager.commandBuilder("fwhitelist",
|
||||
ArgumentDescription.of("Easy way to whitelist Bedrock players"))
|
||||
ArgumentDescription.of("Easy way to whitelist Bedrock players"))
|
||||
.permission(Permission.COMMAND_WHITELIST.get());
|
||||
|
||||
commandManager.command(builder
|
||||
|
||||
@@ -29,8 +29,8 @@ import static org.geysermc.floodgate.util.Constants.COLOR_CHAR;
|
||||
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.inject.Inject;
|
||||
import it.unimi.dsi.fastutil.Pair;
|
||||
import jakarta.inject.Inject;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BooleanSupplier;
|
||||
@@ -46,6 +46,11 @@ final class FirewallCheckSubcommand extends FloodgateSubCommand {
|
||||
@Inject
|
||||
private HttpClient httpClient;
|
||||
|
||||
@Override
|
||||
public Class<?> parent() {
|
||||
return FirewallCheckSubcommand.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "firewall";
|
||||
|
||||
@@ -32,6 +32,7 @@ import cloud.commandframework.Command;
|
||||
import cloud.commandframework.Command.Builder;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.Locale;
|
||||
import org.geysermc.floodgate.command.util.Permission;
|
||||
import org.geysermc.floodgate.platform.command.FloodgateCommand;
|
||||
@@ -39,12 +40,8 @@ import org.geysermc.floodgate.platform.command.FloodgateSubCommand;
|
||||
import org.geysermc.floodgate.platform.command.SubCommands;
|
||||
import org.geysermc.floodgate.player.UserAudience;
|
||||
|
||||
@Singleton
|
||||
public final class MainCommand extends SubCommands implements FloodgateCommand {
|
||||
public MainCommand() {
|
||||
defineSubCommand(FirewallCheckSubcommand.class);
|
||||
defineSubCommand(VersionSubcommand.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandManager) {
|
||||
Builder<UserAudience> builder = commandManager.commandBuilder(
|
||||
|
||||
@@ -29,7 +29,7 @@ import static org.geysermc.floodgate.util.Constants.COLOR_CHAR;
|
||||
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import org.geysermc.floodgate.api.logger.FloodgateLogger;
|
||||
import org.geysermc.floodgate.command.WhitelistCommand.Message;
|
||||
import org.geysermc.floodgate.command.util.Permission;
|
||||
@@ -39,11 +39,13 @@ import org.geysermc.floodgate.util.Constants;
|
||||
import org.geysermc.floodgate.util.HttpClient;
|
||||
|
||||
public class VersionSubcommand extends FloodgateSubCommand {
|
||||
@Inject
|
||||
private HttpClient httpClient;
|
||||
@Inject HttpClient httpClient;
|
||||
@Inject FloodgateLogger logger;
|
||||
|
||||
@Inject
|
||||
private FloodgateLogger logger;
|
||||
@Override
|
||||
public Class<?> parent() {
|
||||
return MainCommand.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
package org.geysermc.floodgate.config;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -38,6 +39,7 @@ import org.geysermc.configutils.loader.callback.GenericPostInitializeCallback;
|
||||
* addition to the global configuration like {@link ProxyFloodgateConfig} for the proxies.
|
||||
*/
|
||||
@Getter
|
||||
@Singleton
|
||||
public class FloodgateConfig implements GenericPostInitializeCallback<ConfigLoader> {
|
||||
private String keyFileName;
|
||||
private String usernamePrefix = "";
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
package org.geysermc.floodgate.database.config;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -42,19 +42,19 @@ public class DatabaseConfigLoader {
|
||||
|
||||
@Inject
|
||||
@Named("dataDirectory")
|
||||
private Path dataDirectory;
|
||||
Path dataDirectory;
|
||||
|
||||
@Inject
|
||||
@Named("databaseName")
|
||||
private String name;
|
||||
String name;
|
||||
|
||||
@Inject
|
||||
@Named("databaseClassLoader")
|
||||
private ClassLoader classLoader;
|
||||
ClassLoader classLoader;
|
||||
|
||||
@Inject
|
||||
@Named("databaseInitData")
|
||||
private JsonObject initData;
|
||||
JsonObject initData;
|
||||
|
||||
@Inject
|
||||
public void init() {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
package org.geysermc.floodgate.event;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
package org.geysermc.floodgate.inject;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import jakarta.inject.Inject;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -40,6 +41,11 @@ public abstract class CommonPlatformInjector implements PlatformInjector {
|
||||
|
||||
private final Map<Class<?>, InjectorAddon> addons = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
void registerAddons(Set<InjectorAddon> addons) {
|
||||
addons.forEach(this::addAddon);
|
||||
}
|
||||
|
||||
protected boolean addInjectedClient(Channel channel) {
|
||||
return injectedClients.add(channel);
|
||||
}
|
||||
|
||||
@@ -25,9 +25,8 @@
|
||||
|
||||
package org.geysermc.floodgate.link;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.name.Names;
|
||||
import io.avaje.inject.BeanScope;
|
||||
import jakarta.inject.Inject;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -44,7 +43,6 @@ import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.database.config.DatabaseConfig;
|
||||
import org.geysermc.floodgate.database.config.DatabaseConfigLoader;
|
||||
import org.geysermc.floodgate.event.lifecycle.ShutdownEvent;
|
||||
import org.geysermc.floodgate.util.InjectorHolder;
|
||||
|
||||
@Listener
|
||||
public abstract class CommonPlayerLink implements PlayerLink {
|
||||
@@ -57,17 +55,17 @@ public abstract class CommonPlayerLink implements PlayerLink {
|
||||
|
||||
@Inject
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private FloodgateLogger logger;
|
||||
FloodgateLogger logger;
|
||||
|
||||
@Inject
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private FloodgateApi api;
|
||||
FloodgateApi api;
|
||||
|
||||
@Inject
|
||||
private InjectorHolder injectorHolder;
|
||||
BeanScope scope;
|
||||
|
||||
@Inject
|
||||
private void init(FloodgateConfig config) {
|
||||
void init(FloodgateConfig config) {
|
||||
FloodgateConfig.PlayerLinkConfig linkConfig = config.getPlayerLink();
|
||||
enabled = linkConfig.isEnabled();
|
||||
allowLinking = linkConfig.isAllowed();
|
||||
@@ -94,12 +92,12 @@ public abstract class CommonPlayerLink implements PlayerLink {
|
||||
public <T extends DatabaseConfig> T getConfig(Class<T> configClass) {
|
||||
// this method is not intended to be used more than once. It'll make a new instance of
|
||||
// DatabaseConfigLoader and DatabaseConfig every time you run this method.
|
||||
return injectorHolder.get().getInstance(DatabaseConfigLoader.class).loadAs(configClass);
|
||||
return scope.get(DatabaseConfigLoader.class).loadAs(configClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return injectorHolder.get().getInstance(Key.get(String.class, Names.named("databaseName")));
|
||||
return scope.get(String.class, "databaseName");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,7 +29,7 @@ import static org.geysermc.floodgate.util.Constants.GET_BEDROCK_LINK;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import lombok.Getter;
|
||||
@@ -43,8 +43,7 @@ import org.geysermc.floodgate.util.Utils;
|
||||
|
||||
@Getter
|
||||
public class GlobalPlayerLinking extends CommonPlayerLink {
|
||||
@Inject
|
||||
private HttpClient httpClient;
|
||||
@Inject HttpClient httpClient;
|
||||
|
||||
private PlayerLink databaseImpl;
|
||||
|
||||
|
||||
@@ -29,11 +29,10 @@ import static java.util.Objects.requireNonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.name.Named;
|
||||
import com.google.inject.name.Names;
|
||||
import io.avaje.inject.BeanScope;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -53,22 +52,22 @@ import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.config.FloodgateConfig.PlayerLinkConfig;
|
||||
import org.geysermc.floodgate.event.lifecycle.ShutdownEvent;
|
||||
import org.geysermc.floodgate.util.Constants;
|
||||
import org.geysermc.floodgate.util.InjectorHolder;
|
||||
import org.geysermc.floodgate.util.Utils;
|
||||
|
||||
@Listener
|
||||
@Singleton
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class PlayerLinkHolder {
|
||||
@Inject private Injector injector;
|
||||
@Inject private FloodgateConfig config;
|
||||
@Inject private FloodgateLogger logger;
|
||||
@Inject BeanScope currentScope;
|
||||
@Inject FloodgateConfig config;
|
||||
@Inject FloodgateLogger logger;
|
||||
|
||||
@Inject
|
||||
@Named("dataDirectory")
|
||||
private Path dataDirectory;
|
||||
Path dataDirectory;
|
||||
|
||||
private URLClassLoader classLoader;
|
||||
private BeanScope childScope;
|
||||
private PlayerLink instance;
|
||||
|
||||
@NonNull
|
||||
@@ -100,7 +99,7 @@ public final class PlayerLinkHolder {
|
||||
// been found, or when global linking is enabled and own player linking is disabled.
|
||||
if (linkConfig.isEnableGlobalLinking() &&
|
||||
(files.isEmpty() || !linkConfig.isEnableOwnLinking())) {
|
||||
return injector.getInstance(GlobalPlayerLinking.class);
|
||||
return currentScope.get(GlobalPlayerLinking.class);
|
||||
}
|
||||
|
||||
if (files.isEmpty()) {
|
||||
@@ -174,26 +173,18 @@ public final class PlayerLinkHolder {
|
||||
|
||||
init = false;
|
||||
|
||||
InjectorHolder injectorHolder = new InjectorHolder();
|
||||
Injector linkInjector = injector.createChildInjector(binder -> {
|
||||
binder.bind(String.class)
|
||||
.annotatedWith(Names.named("databaseName"))
|
||||
.toInstance(databaseName);
|
||||
binder.bind(ClassLoader.class).annotatedWith(
|
||||
Names.named("databaseClassLoader")).toInstance(classLoader);
|
||||
binder.bind(JsonObject.class)
|
||||
.annotatedWith(Names.named("databaseInitData"))
|
||||
.toInstance(dbInitConfig);
|
||||
binder.bind(InjectorHolder.class)
|
||||
.toInstance(injectorHolder);
|
||||
});
|
||||
injectorHolder.set(linkInjector);
|
||||
childScope = BeanScope.builder()
|
||||
.parent(currentScope)
|
||||
.bean("databaseName", String.class, databaseName)
|
||||
.bean("databaseClassLoader", ClassLoader.class, classLoader)
|
||||
.bean("databaseInitData", JsonObject.class, dbInitConfig)
|
||||
.build();
|
||||
|
||||
instance = linkInjector.getInstance(mainClass);
|
||||
instance = childScope.get(mainClass);
|
||||
|
||||
// we use our own internal PlayerLinking when global linking is enabled
|
||||
if (linkConfig.isEnableGlobalLinking()) {
|
||||
GlobalPlayerLinking linking = linkInjector.getInstance(GlobalPlayerLinking.class);
|
||||
GlobalPlayerLinking linking = childScope.get(GlobalPlayerLinking.class);
|
||||
linking.setDatabaseImpl(instance);
|
||||
linking.load();
|
||||
return linking;
|
||||
@@ -220,6 +211,7 @@ public final class PlayerLinkHolder {
|
||||
@Subscribe
|
||||
public void onShutdown(ShutdownEvent ignored) throws Exception {
|
||||
instance.stop();
|
||||
childScope.close();
|
||||
classLoader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,24 +27,26 @@ package org.geysermc.floodgate.logger;
|
||||
|
||||
import static org.geysermc.floodgate.util.MessageFormatter.format;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.name.Named;
|
||||
import io.avaje.inject.Secondary;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.geysermc.floodgate.api.logger.FloodgateLogger;
|
||||
import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.util.LanguageManager;
|
||||
|
||||
@Secondary
|
||||
@Singleton
|
||||
public final class JavaUtilFloodgateLogger implements FloodgateLogger {
|
||||
@Inject
|
||||
@Named("logger")
|
||||
private Logger logger;
|
||||
Logger logger;
|
||||
private LanguageManager languageManager;
|
||||
|
||||
@Inject
|
||||
private void init(LanguageManager languageManager, FloodgateConfig config) {
|
||||
public void init(LanguageManager languageManager, FloodgateConfig config) {
|
||||
this.languageManager = languageManager;
|
||||
if (config.isDebug()) {
|
||||
logger.setLevel(Level.ALL);
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Floodgate
|
||||
*/
|
||||
|
||||
package org.geysermc.floodgate.module;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.multibindings.ProvidesIntoSet;
|
||||
import org.geysermc.floodgate.command.LinkAccountCommand;
|
||||
import org.geysermc.floodgate.command.TestCommand;
|
||||
import org.geysermc.floodgate.command.UnlinkAccountCommand;
|
||||
import org.geysermc.floodgate.command.WhitelistCommand;
|
||||
import org.geysermc.floodgate.command.main.MainCommand;
|
||||
import org.geysermc.floodgate.platform.command.FloodgateCommand;
|
||||
import org.geysermc.floodgate.register.CommandRegister;
|
||||
|
||||
public class CommandModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(CommandRegister.class).asEagerSingleton();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@ProvidesIntoSet
|
||||
public FloodgateCommand linkAccountCommand() {
|
||||
return new LinkAccountCommand();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@ProvidesIntoSet
|
||||
public FloodgateCommand unlinkAccountCommand() {
|
||||
return new UnlinkAccountCommand();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@ProvidesIntoSet
|
||||
public FloodgateCommand whitelistCommand() {
|
||||
return new WhitelistCommand();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@ProvidesIntoSet
|
||||
public FloodgateCommand testCommand() {
|
||||
return new TestCommand();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@ProvidesIntoSet
|
||||
public FloodgateCommand mainCommand() {
|
||||
return new MainCommand();
|
||||
}
|
||||
}
|
||||
@@ -27,14 +27,14 @@ package org.geysermc.floodgate.module;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.name.Named;
|
||||
import com.google.inject.name.Names;
|
||||
import com.google.inject.spi.InjectionListener;
|
||||
import com.google.inject.spi.TypeEncounter;
|
||||
import com.google.inject.spi.TypeListener;
|
||||
import io.netty.util.AttributeKey;
|
||||
import jakarta.inject.Named;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -42,14 +42,9 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.geysermc.event.PostOrder;
|
||||
import org.geysermc.floodgate.addon.data.HandshakeHandlersImpl;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
import org.geysermc.floodgate.api.SimpleFloodgateApi;
|
||||
import org.geysermc.floodgate.api.event.FloodgateEventBus;
|
||||
import org.geysermc.floodgate.api.handshake.HandshakeHandlers;
|
||||
import org.geysermc.floodgate.api.inject.PlatformInjector;
|
||||
import org.geysermc.floodgate.api.link.PlayerLink;
|
||||
import org.geysermc.floodgate.api.logger.FloodgateLogger;
|
||||
import org.geysermc.floodgate.api.packet.PacketHandlers;
|
||||
import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
||||
import org.geysermc.floodgate.config.ConfigLoader;
|
||||
import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
@@ -61,14 +56,11 @@ import org.geysermc.floodgate.crypto.KeyProducer;
|
||||
import org.geysermc.floodgate.event.EventBus;
|
||||
import org.geysermc.floodgate.event.lifecycle.ShutdownEvent;
|
||||
import org.geysermc.floodgate.event.util.ListenerAnnotationMatcher;
|
||||
import org.geysermc.floodgate.inject.CommonPlatformInjector;
|
||||
import org.geysermc.floodgate.link.PlayerLinkHolder;
|
||||
import org.geysermc.floodgate.packet.PacketHandlersImpl;
|
||||
import org.geysermc.floodgate.player.FloodgateHandshakeHandler;
|
||||
import org.geysermc.floodgate.pluginmessage.PluginMessageManager;
|
||||
import org.geysermc.floodgate.skin.SkinUploadManager;
|
||||
import org.geysermc.floodgate.util.Constants;
|
||||
import org.geysermc.floodgate.util.HttpClient;
|
||||
import org.geysermc.floodgate.util.LanguageManager;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@@ -78,8 +70,6 @@ public class CommonModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(EventBus.class).toInstance(eventBus);
|
||||
bind(FloodgateEventBus.class).to(EventBus.class);
|
||||
// register every class that has the Listener annotation
|
||||
bindListener(new ListenerAnnotationMatcher(), new TypeListener() {
|
||||
@Override
|
||||
@@ -103,17 +93,6 @@ public class CommonModule extends AbstractModule {
|
||||
.annotatedWith(Names.named("commonScheduledPool"))
|
||||
.toInstance(commonScheduledPool);
|
||||
|
||||
bind(HttpClient.class).in(Singleton.class);
|
||||
|
||||
bind(FloodgateApi.class).to(SimpleFloodgateApi.class);
|
||||
bind(PlatformInjector.class).to(CommonPlatformInjector.class);
|
||||
|
||||
bind(HandshakeHandlers.class).to(HandshakeHandlersImpl.class);
|
||||
bind(HandshakeHandlersImpl.class).in(Singleton.class);
|
||||
|
||||
bind(PacketHandlers.class).to(PacketHandlersImpl.class);
|
||||
bind(PacketHandlersImpl.class).asEagerSingleton();
|
||||
|
||||
install(new AutoBindModule());
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ package org.geysermc.floodgate.module;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import jakarta.inject.Singleton;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.config.ProxyFloodgateConfig;
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Floodgate
|
||||
*/
|
||||
|
||||
package org.geysermc.floodgate.module;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.multibindings.ProvidesIntoSet;
|
||||
import org.geysermc.floodgate.pluginmessage.PluginMessageChannel;
|
||||
import org.geysermc.floodgate.pluginmessage.channel.FormChannel;
|
||||
import org.geysermc.floodgate.pluginmessage.channel.PacketChannel;
|
||||
import org.geysermc.floodgate.pluginmessage.channel.SkinChannel;
|
||||
import org.geysermc.floodgate.pluginmessage.channel.TransferChannel;
|
||||
import org.geysermc.floodgate.register.PluginMessageRegister;
|
||||
|
||||
public final class PluginMessageModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(PluginMessageRegister.class).asEagerSingleton();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@ProvidesIntoSet
|
||||
public PluginMessageChannel formChannel() {
|
||||
return new FormChannel();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@ProvidesIntoSet
|
||||
public PluginMessageChannel skinChannel() {
|
||||
return new SkinChannel();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@ProvidesIntoSet
|
||||
public PluginMessageChannel transferChannel() {
|
||||
return new TransferChannel();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@ProvidesIntoSet
|
||||
public PluginMessageChannel packetChannel() {
|
||||
return new PacketChannel();
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Floodgate
|
||||
*/
|
||||
|
||||
package org.geysermc.floodgate.module;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.name.Named;
|
||||
import java.nio.file.Path;
|
||||
import org.geysermc.floodgate.api.ProxyFloodgateApi;
|
||||
import org.geysermc.floodgate.api.SimpleFloodgateApi;
|
||||
import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.config.ProxyFloodgateConfig;
|
||||
|
||||
public final class ProxyCommonModule extends CommonModule {
|
||||
public ProxyCommonModule(Path dataDirectory) {
|
||||
super(dataDirectory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
|
||||
bind(SimpleFloodgateApi.class).to(ProxyFloodgateApi.class);
|
||||
bind(ProxyFloodgateApi.class).in(Singleton.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public ProxyFloodgateConfig proxyFloodgateConfig(FloodgateConfig config) {
|
||||
return (ProxyFloodgateConfig) config;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("configClass")
|
||||
public Class<? extends FloodgateConfig> floodgateConfigClass() {
|
||||
return ProxyFloodgateConfig.class;
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Floodgate
|
||||
*/
|
||||
|
||||
package org.geysermc.floodgate.module;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.name.Named;
|
||||
import java.nio.file.Path;
|
||||
import org.geysermc.floodgate.api.SimpleFloodgateApi;
|
||||
import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
|
||||
public final class ServerCommonModule extends CommonModule {
|
||||
public ServerCommonModule(Path dataDirectory) {
|
||||
super(dataDirectory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(SimpleFloodgateApi.class).in(Singleton.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("configClass")
|
||||
public Class<? extends FloodgateConfig> floodgateConfigClass() {
|
||||
return FloodgateConfig.class;
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,10 @@ package org.geysermc.floodgate.news;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
import io.avaje.inject.PostConstruct;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -42,35 +44,32 @@ import org.geysermc.floodgate.news.data.AnnouncementData;
|
||||
import org.geysermc.floodgate.news.data.BuildSpecificData;
|
||||
import org.geysermc.floodgate.news.data.CheckAfterData;
|
||||
import org.geysermc.floodgate.platform.command.CommandUtil;
|
||||
import org.geysermc.floodgate.util.AutoBind;
|
||||
import org.geysermc.floodgate.util.Constants;
|
||||
import org.geysermc.floodgate.util.HttpClient;
|
||||
import org.geysermc.floodgate.util.HttpClient.HttpResponse;
|
||||
|
||||
@AutoBind
|
||||
@Singleton
|
||||
public class NewsChecker {
|
||||
private final Map<Integer, NewsItem> activeNewsItems = new HashMap<>();
|
||||
@Inject
|
||||
@Named("commonScheduledPool")
|
||||
private ScheduledExecutorService executorService;
|
||||
|
||||
@Inject
|
||||
private CommandUtil commandUtil;
|
||||
@Inject
|
||||
private HttpClient httpClient;
|
||||
@Inject
|
||||
private FloodgateLogger logger;
|
||||
@Named("commonScheduledPool")
|
||||
ScheduledExecutorService executorService;
|
||||
|
||||
@Inject CommandUtil commandUtil;
|
||||
@Inject HttpClient httpClient;
|
||||
@Inject FloodgateLogger logger;
|
||||
|
||||
@Inject
|
||||
@Named("gitBranch")
|
||||
private String branch;
|
||||
String branch;
|
||||
@Inject
|
||||
@Named("buildNumber")
|
||||
private int build;
|
||||
int build;
|
||||
|
||||
private boolean firstCheck;
|
||||
|
||||
@Inject
|
||||
@PostConstruct
|
||||
public void start() {
|
||||
executorService.scheduleWithFixedDelay(this::checkNews, 0, 30, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
package org.geysermc.floodgate.packet;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -40,6 +41,7 @@ import org.geysermc.floodgate.api.packet.PacketHandler;
|
||||
import org.geysermc.floodgate.api.packet.PacketHandlers;
|
||||
import org.geysermc.floodgate.api.util.TriFunction;
|
||||
|
||||
@Singleton
|
||||
public final class PacketHandlersImpl implements PacketHandlers {
|
||||
private final Map<PacketHandler, List<HandlerEntry>> handlers = new HashMap<>();
|
||||
private final Set<TriFunction<ChannelHandlerContext, Object, Boolean, Object>> globalPacketHandlers = new HashSet<>();
|
||||
|
||||
@@ -30,6 +30,8 @@ import org.geysermc.floodgate.command.util.Permission;
|
||||
import org.geysermc.floodgate.player.UserAudience;
|
||||
|
||||
public abstract class FloodgateSubCommand {
|
||||
public abstract Class<?> parent();
|
||||
|
||||
public abstract String name();
|
||||
|
||||
public abstract String description();
|
||||
|
||||
@@ -25,27 +25,15 @@
|
||||
|
||||
package org.geysermc.floodgate.platform.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import jakarta.inject.Inject;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class SubCommands {
|
||||
private final Set<Class<? extends FloodgateSubCommand>> toRegister = new HashSet<>();
|
||||
private Set<FloodgateSubCommand> subCommands;
|
||||
|
||||
public void defineSubCommand(Class<? extends FloodgateSubCommand> subCommandClass) {
|
||||
toRegister.add(subCommandClass);
|
||||
}
|
||||
Set<FloodgateSubCommand> subCommands;
|
||||
|
||||
@Inject
|
||||
public void registerSubCommands(Injector injector) {
|
||||
Set<FloodgateSubCommand> subCommandSet = new HashSet<>();
|
||||
for (Class<? extends FloodgateSubCommand> subCommand : toRegister) {
|
||||
subCommandSet.add(injector.getInstance(subCommand));
|
||||
}
|
||||
subCommands = Collections.unmodifiableSet(subCommandSet);
|
||||
public void setup(Set<FloodgateSubCommand> subCommands) {
|
||||
subCommands.removeIf(subCommand -> !subCommand.parent().isAssignableFrom(this.getClass()));
|
||||
}
|
||||
|
||||
protected Set<FloodgateSubCommand> subCommands() {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
package org.geysermc.floodgate.pluginmessage;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -34,6 +34,8 @@ public class PluginMessageManager {
|
||||
private final Map<Class<? extends PluginMessageChannel>, PluginMessageChannel> classInstanceMap = new HashMap<>();
|
||||
private final Map<String, PluginMessageChannel> identifierInstanceMap = new HashMap<>();
|
||||
|
||||
@Inject PluginMessageRegistration registration;
|
||||
|
||||
@Inject
|
||||
public void addChannels(Set<PluginMessageChannel> channels) {
|
||||
if (!classInstanceMap.isEmpty()) {
|
||||
@@ -43,6 +45,7 @@ public class PluginMessageManager {
|
||||
for (PluginMessageChannel channel : channels) {
|
||||
classInstanceMap.put(channel.getClass(), channel);
|
||||
identifierInstanceMap.put(channel.getIdentifier(), channel);
|
||||
registration.register(channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
package org.geysermc.floodgate.pluginmessage.channel;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.inject.Inject;
|
||||
import it.unimi.dsi.fastutil.shorts.Short2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap;
|
||||
import jakarta.inject.Inject;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.geysermc.cumulus.form.Form;
|
||||
@@ -44,9 +44,9 @@ public class FormChannel implements PluginMessageChannel {
|
||||
private final Short2ObjectMap<Form> storedForms = new Short2ObjectOpenHashMap<>();
|
||||
private final AtomicInteger nextFormId = new AtomicInteger(0);
|
||||
|
||||
@Inject private PluginMessageUtils pluginMessageUtils;
|
||||
@Inject private FloodgateConfig config;
|
||||
@Inject private FloodgateLogger logger;
|
||||
@Inject PluginMessageUtils pluginMessageUtils;
|
||||
@Inject FloodgateConfig config;
|
||||
@Inject FloodgateLogger logger;
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
|
||||
@@ -25,14 +25,14 @@
|
||||
|
||||
package org.geysermc.floodgate.pluginmessage.channel;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import java.util.UUID;
|
||||
import org.geysermc.floodgate.api.UnsafeFloodgateApi;
|
||||
import org.geysermc.floodgate.platform.pluginmessage.PluginMessageUtils;
|
||||
import org.geysermc.floodgate.pluginmessage.PluginMessageChannel;
|
||||
|
||||
public final class PacketChannel implements PluginMessageChannel {
|
||||
@Inject private PluginMessageUtils pluginMessageUtils;
|
||||
@Inject PluginMessageUtils pluginMessageUtils;
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
package org.geysermc.floodgate.pluginmessage.channel;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
@@ -38,9 +38,9 @@ import org.geysermc.floodgate.skin.SkinApplier;
|
||||
import org.geysermc.floodgate.skin.SkinDataImpl;
|
||||
|
||||
public class SkinChannel implements PluginMessageChannel {
|
||||
@Inject private FloodgateApi api;
|
||||
@Inject private FloodgateConfig config;
|
||||
@Inject private SkinApplier skinApplier;
|
||||
@Inject FloodgateApi api;
|
||||
@Inject FloodgateConfig config;
|
||||
@Inject SkinApplier skinApplier;
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
|
||||
@@ -25,14 +25,14 @@
|
||||
|
||||
package org.geysermc.floodgate.pluginmessage.channel;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
import org.geysermc.floodgate.platform.pluginmessage.PluginMessageUtils;
|
||||
import org.geysermc.floodgate.pluginmessage.PluginMessageChannel;
|
||||
|
||||
public class TransferChannel implements PluginMessageChannel {
|
||||
@Inject private PluginMessageUtils pluginMessageUtils;
|
||||
@Inject PluginMessageUtils pluginMessageUtils;
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
|
||||
@@ -26,9 +26,8 @@
|
||||
package org.geysermc.floodgate.register;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.Set;
|
||||
import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.platform.command.FloodgateCommand;
|
||||
@@ -39,22 +38,14 @@ import org.geysermc.floodgate.player.UserAudience;
|
||||
* is currently in use. So that the commands only have to be written once (in the common module) and
|
||||
* can be used across all platforms without the need of adding platform specific commands.
|
||||
*/
|
||||
@Singleton
|
||||
public final class CommandRegister {
|
||||
private final CommandManager<UserAudience> commandManager;
|
||||
private final FloodgateConfig config;
|
||||
private final Injector guice;
|
||||
|
||||
@Inject
|
||||
public CommandRegister(Injector guice) {
|
||||
this.commandManager = guice.getInstance(new Key<CommandManager<UserAudience>>() {});
|
||||
this.config = guice.getInstance(FloodgateConfig.class);
|
||||
this.guice = guice;
|
||||
}
|
||||
@Inject CommandManager<UserAudience> commandManager;
|
||||
@Inject FloodgateConfig config;
|
||||
|
||||
@Inject
|
||||
public void registerCommands(Set<FloodgateCommand> foundCommands) {
|
||||
for (FloodgateCommand command : foundCommands) {
|
||||
guice.injectMembers(command);
|
||||
if (command.shouldRegister(config)) {
|
||||
commandManager.command(command.buildCommand(commandManager));
|
||||
}
|
||||
|
||||
@@ -25,22 +25,31 @@
|
||||
|
||||
package org.geysermc.floodgate.register;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Qualifier;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.geysermc.floodgate.platform.listener.ListenerRegistration;
|
||||
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Inject))
|
||||
public final class ListenerRegister<T> {
|
||||
private final ListenerRegistration<T> registration;
|
||||
private final Injector guice;
|
||||
|
||||
@Singleton
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public final class ListenerRegister {
|
||||
@Inject
|
||||
public void registerListeners(Set<T> foundListeners) {
|
||||
for (T listener : foundListeners) {
|
||||
guice.injectMembers(listener);
|
||||
registration.register(listener);
|
||||
}
|
||||
ListenerRegistration registration;
|
||||
|
||||
// @Inject
|
||||
// public void registerListeners(Set<@Listener Object> foundListeners) {
|
||||
// for (Object listener : foundListeners) {
|
||||
// registration.register(listener);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Qualifier
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE_USE)
|
||||
public @interface Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Floodgate
|
||||
*/
|
||||
|
||||
package org.geysermc.floodgate.register;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import java.util.Set;
|
||||
import org.geysermc.floodgate.pluginmessage.PluginMessageChannel;
|
||||
import org.geysermc.floodgate.pluginmessage.PluginMessageManager;
|
||||
import org.geysermc.floodgate.pluginmessage.PluginMessageRegistration;
|
||||
|
||||
public class PluginMessageRegister {
|
||||
@Inject private Injector guice;
|
||||
@Inject private PluginMessageManager manager;
|
||||
@Inject private PluginMessageRegistration registration;
|
||||
|
||||
@Inject
|
||||
public void registerChannels(Set<PluginMessageChannel> channels) {
|
||||
// we can safely add the channels this way
|
||||
guice.injectMembers(manager);
|
||||
|
||||
for (PluginMessageChannel channel : channels) {
|
||||
guice.injectMembers(channel);
|
||||
registration.register(channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -23,18 +23,13 @@
|
||||
* @link https://github.com/GeyserMC/Floodgate
|
||||
*/
|
||||
|
||||
package org.geysermc.floodgate.util;
|
||||
package org.geysermc.floodgate.scope;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import jakarta.inject.Scope;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
public class InjectorHolder {
|
||||
private Injector injector;
|
||||
|
||||
public Injector get() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
public void set(Injector injector) {
|
||||
this.injector = injector;
|
||||
}
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Scope
|
||||
public @interface ProxyScope {
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -23,23 +23,13 @@
|
||||
* @link https://github.com/GeyserMC/Floodgate
|
||||
*/
|
||||
|
||||
package org.geysermc.floodgate.register;
|
||||
package org.geysermc.floodgate.scope;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import java.util.Set;
|
||||
import org.geysermc.floodgate.api.inject.InjectorAddon;
|
||||
import org.geysermc.floodgate.api.inject.PlatformInjector;
|
||||
import jakarta.inject.Scope;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
public final class AddonRegister {
|
||||
@Inject private Injector guice;
|
||||
@Inject private PlatformInjector injector;
|
||||
|
||||
@Inject
|
||||
public void registerAddons(Set<InjectorAddon> addons) {
|
||||
for (InjectorAddon addon : addons) {
|
||||
guice.injectMembers(addon);
|
||||
injector.addAddon(addon);
|
||||
}
|
||||
}
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Scope
|
||||
public @interface ServerScope {
|
||||
}
|
||||
@@ -25,11 +25,11 @@
|
||||
|
||||
package org.geysermc.floodgate.skin;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import org.geysermc.event.Listener;
|
||||
import org.geysermc.event.subscribe.Subscribe;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
@@ -42,9 +42,9 @@ public final class SkinUploadManager {
|
||||
private final Int2ObjectMap<SkinUploadSocket> connections =
|
||||
Int2ObjectMaps.synchronize(new Int2ObjectOpenHashMap<>());
|
||||
|
||||
@Inject private FloodgateApi api;
|
||||
@Inject private SkinApplier applier;
|
||||
@Inject private FloodgateLogger logger;
|
||||
@Inject FloodgateApi api;
|
||||
@Inject SkinApplier applier;
|
||||
@Inject FloodgateLogger logger;
|
||||
|
||||
public void addConnectionIfNeeded(int id, String verifyCode) {
|
||||
connections.computeIfAbsent(id, (ignored) -> {
|
||||
|
||||
@@ -27,9 +27,9 @@ package org.geysermc.floodgate.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.name.Named;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
@@ -51,7 +51,7 @@ public class HttpClient {
|
||||
private final Gson gson = new Gson();
|
||||
@Inject
|
||||
@Named("commonPool")
|
||||
private ExecutorService executorService;
|
||||
ExecutorService executorService;
|
||||
|
||||
public CompletableFuture<DefaultHttpResponse> asyncGet(String urlString) {
|
||||
return CompletableFuture.supplyAsync(() -> get(urlString), executorService);
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
package org.geysermc.floodgate.util;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.net.URL;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
@@ -45,13 +45,13 @@ import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
public final class LanguageManager {
|
||||
private final Map<String, Properties> localeMappings = new HashMap<>();
|
||||
|
||||
@Inject private FloodgateConfig config;
|
||||
@Inject private FloodgateLogger logger;
|
||||
@Inject FloodgateConfig config;
|
||||
@Inject FloodgateLogger logger;
|
||||
|
||||
/**
|
||||
* The locale used in console and as a fallback
|
||||
*/
|
||||
@Getter private String defaultLocale;
|
||||
@Getter String defaultLocale;
|
||||
|
||||
/**
|
||||
* Cleans up and formats a locale string
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
|
||||
package org.geysermc.floodgate.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
@@ -44,14 +45,18 @@ import org.geysermc.floodgate.config.FloodgateConfig;
|
||||
import org.geysermc.floodgate.config.FloodgateConfig.MetricsConfig;
|
||||
import org.geysermc.floodgate.platform.util.PlatformUtils;
|
||||
|
||||
@AutoBind
|
||||
@Singleton
|
||||
public final class Metrics {
|
||||
private final MetricsBase metricsBase;
|
||||
|
||||
@Inject
|
||||
Metrics(FloodgateConfig config, PlatformUtils platformUtils, FloodgateApi api,
|
||||
@Named("implementationName") String implementationName, FloodgateLogger logger) {
|
||||
|
||||
Metrics(
|
||||
FloodgateConfig config,
|
||||
PlatformUtils platformUtils,
|
||||
FloodgateApi api,
|
||||
@Named("implementationName") String implementationName,
|
||||
FloodgateLogger logger
|
||||
) {
|
||||
MetricsConfig metricsConfig = config.getMetrics();
|
||||
|
||||
metricsBase = new MetricsBase(
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
|
||||
package org.geysermc.floodgate.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
import io.avaje.inject.PostConstruct;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
@@ -42,11 +43,11 @@ import org.geysermc.floodgate.event.lifecycle.PostEnableEvent;
|
||||
public final class PostEnableMessages {
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
|
||||
@Inject private FloodgateConfig config;
|
||||
@Inject private FloodgateLogger logger;
|
||||
@Inject FloodgateConfig config;
|
||||
@Inject FloodgateLogger logger;
|
||||
@Inject
|
||||
@Named("commonScheduledPool")
|
||||
private ScheduledExecutorService executorService;
|
||||
ScheduledExecutorService executorService;
|
||||
|
||||
public void add(String[] message, Object... args) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@@ -60,12 +61,8 @@ public final class PostEnableMessages {
|
||||
messages.add(MessageFormatter.format(builder.toString(), args));
|
||||
}
|
||||
|
||||
@Inject
|
||||
private void init() {
|
||||
registerPrefixMessages();
|
||||
}
|
||||
|
||||
private void registerPrefixMessages() {
|
||||
@PostConstruct
|
||||
void registerPrefixMessages() {
|
||||
String prefix = config.getRawUsernamePrefix();
|
||||
|
||||
if (prefix.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user