1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2025-12-19 14:59:20 +00:00

Merge remote-tracking branch 'origin/development' into feature/auto-binding

# Conflicts:
#	core/src/main/java/org/geysermc/floodgate/FloodgatePlatform.java
This commit is contained in:
Tim203
2022-08-30 09:27:15 +02:00
12 changed files with 121 additions and 24 deletions

View File

@@ -1,6 +1,7 @@
dependencies {
api("org.geysermc", "common", Versions.geyserVersion)
api("org.geysermc.cumulus", "cumulus", Versions.cumulusVersion)
api("org.geysermc.event", "events", Versions.eventsVersion)
compileOnly("io.netty", "netty-transport", Versions.nettyVersion)
}

View File

@@ -26,6 +26,7 @@
object Versions {
const val geyserVersion = "2.0.4-SNAPSHOT"
const val cumulusVersion = "1.1"
const val eventsVersion = "1.0-SNAPSHOT"
const val configUtilsVersion = "1.0-SNAPSHOT"
const val spigotVersion = "1.13-R0.1-SNAPSHOT"
const val fastutilVersion = "8.5.3"
@@ -34,7 +35,6 @@ object Versions {
const val snakeyamlVersion = "1.28"
const val cloudVersion = "1.5.0"
const val bstatsVersion = "3.0.0"
const val mbassadorVersion = "1.3.2"
const val javaWebsocketVersion = "1.5.2"

View File

@@ -18,7 +18,6 @@ dependencies {
api("cloud.commandframework", "cloud-core", Versions.cloudVersion)
api("org.yaml", "snakeyaml", Versions.snakeyamlVersion)
api("org.bstats", "bstats-base", Versions.bstatsVersion)
api("net.engio", "mbassador", Versions.mbassadorVersion)
}
// present on all platforms

View File

@@ -29,7 +29,6 @@ import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Module;
import java.util.UUID;
import net.engio.mbassy.bus.common.PubSubSupport;
import org.geysermc.floodgate.api.FloodgateApi;
import org.geysermc.floodgate.api.InstanceHolder;
import org.geysermc.floodgate.api.handshake.HandshakeHandlers;
@@ -37,6 +36,7 @@ import org.geysermc.floodgate.api.inject.PlatformInjector;
import org.geysermc.floodgate.api.link.PlayerLink;
import org.geysermc.floodgate.api.packet.PacketHandlers;
import org.geysermc.floodgate.config.FloodgateConfig;
import org.geysermc.floodgate.event.EventBus;
import org.geysermc.floodgate.event.PostEnableEvent;
import org.geysermc.floodgate.event.ShutdownEvent;
import org.geysermc.floodgate.module.PostInitializeModule;
@@ -70,11 +70,11 @@ public class FloodgatePlatform {
this.guice = guice.createChildInjector(new PostInitializeModule(postInitializeModules));
guice.getInstance(PubSubSupport.class).publish(new PostEnableEvent());
guice.getInstance(EventBus.class).fire(new PostEnableEvent());
}
public void disable() {
guice.getInstance(PubSubSupport.class).publish(new ShutdownEvent());
guice.getInstance(EventBus.class).fire(new ShutdownEvent());
if (injector != null && injector.canRemoveInjection()) {
try {

View File

@@ -0,0 +1,53 @@
/*
* 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.event;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import org.geysermc.event.bus.impl.EventBusImpl;
import org.geysermc.event.subscribe.Subscribe;
import org.geysermc.event.subscribe.Subscriber;
@SuppressWarnings("unchecked")
public final class EventBus extends EventBusImpl<Object, EventSubscriber<?>> {
@Override
protected <H, T, B extends Subscriber<T>> B makeSubscription(
Class<T> eventClass,
Subscribe subscribe,
H listener,
BiConsumer<H, T> handler) {
return (B) new EventSubscriber<>(
eventClass, subscribe.postOrder(), subscribe.ignoreCancelled(), listener, handler
);
}
@Override
protected <T, B extends Subscriber<T>> B makeSubscription(
Class<T> eventClass,
Consumer<T> handler) {
return (B) new EventSubscriber<>(eventClass, handler);
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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.event;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import org.geysermc.event.PostOrder;
import org.geysermc.event.subscribe.impl.SubscriberImpl;
public final class EventSubscriber<E> extends SubscriberImpl<E> {
EventSubscriber(Class<E> eventClass, Consumer<E> handler) {
super(eventClass, handler);
}
<H> EventSubscriber(
Class<E> eventClass,
PostOrder postOrder,
boolean ignoreCancelled,
H handlerInstance,
BiConsumer<H, E> handler) {
super(eventClass, postOrder, ignoreCancelled, handlerInstance, handler);
}
}

View File

@@ -27,7 +27,7 @@ package org.geysermc.floodgate.event.util;
import com.google.inject.TypeLiteral;
import com.google.inject.matcher.AbstractMatcher;
import net.engio.mbassy.listener.Listener;
import org.geysermc.event.Listener;
public class ListenerAnnotationMatcher extends AbstractMatcher<TypeLiteral<?>> {
@Override

View File

@@ -34,8 +34,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import lombok.AccessLevel;
import lombok.Getter;
import net.engio.mbassy.listener.Handler;
import net.engio.mbassy.listener.Listener;
import org.geysermc.event.Listener;
import org.geysermc.event.subscribe.Subscribe;
import org.geysermc.floodgate.api.FloodgateApi;
import org.geysermc.floodgate.api.link.LinkRequest;
import org.geysermc.floodgate.api.link.PlayerLink;
@@ -107,7 +107,7 @@ public abstract class CommonPlayerLink implements PlayerLink {
executorService.shutdown();
}
@Handler
@Subscribe
public void onShutdown(ShutdownEvent ignored) {
stop();
}

View File

@@ -36,9 +36,6 @@ import com.google.inject.spi.TypeListener;
import io.netty.util.AttributeKey;
import java.nio.file.Path;
import lombok.RequiredArgsConstructor;
import net.engio.mbassy.bus.MBassador;
import net.engio.mbassy.bus.common.PubSubSupport;
import net.engio.mbassy.bus.error.IPublicationErrorHandler.ConsoleLogger;
import org.geysermc.floodgate.addon.data.HandshakeHandlersImpl;
import org.geysermc.floodgate.api.FloodgateApi;
import org.geysermc.floodgate.api.SimpleFloodgateApi;
@@ -55,6 +52,7 @@ import org.geysermc.floodgate.crypto.AesKeyProducer;
import org.geysermc.floodgate.crypto.Base64Topping;
import org.geysermc.floodgate.crypto.FloodgateCipher;
import org.geysermc.floodgate.crypto.KeyProducer;
import org.geysermc.floodgate.event.EventBus;
import org.geysermc.floodgate.event.util.ListenerAnnotationMatcher;
import org.geysermc.floodgate.inject.CommonPlatformInjector;
import org.geysermc.floodgate.link.PlayerLinkLoader;
@@ -68,17 +66,17 @@ import org.geysermc.floodgate.util.HttpClient;
@RequiredArgsConstructor
public class CommonModule extends AbstractModule {
private final PubSubSupport<Object> eventBus = new MBassador<>(new ConsoleLogger(true));
private final EventBus eventBus = new EventBus();
private final Path dataDirectory;
@Override
protected void configure() {
bind(PubSubSupport.class).toInstance(eventBus);
bind(EventBus.class).toInstance(eventBus);
// register every class that has the Listener annotation
bindListener(new ListenerAnnotationMatcher(), new TypeListener() {
@Override
public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
encounter.register((InjectionListener<I>) eventBus::subscribe);
encounter.register((InjectionListener<I>) eventBus::register);
}
});

View File

@@ -37,8 +37,8 @@ import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import net.engio.mbassy.listener.Handler;
import net.engio.mbassy.listener.Listener;
import org.geysermc.event.Listener;
import org.geysermc.event.subscribe.Subscribe;
import org.geysermc.floodgate.api.logger.FloodgateLogger;
import org.geysermc.floodgate.command.util.Permission;
import org.geysermc.floodgate.event.ShutdownEvent;
@@ -209,7 +209,7 @@ public class NewsChecker {
executorService.shutdown();
}
@Handler
@Subscribe
public void onShutdown(ShutdownEvent ignored) {
shutdown();
}

View File

@@ -37,10 +37,10 @@ import java.util.concurrent.Executors;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.engio.mbassy.listener.Handler;
import net.engio.mbassy.listener.Listener;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.event.Listener;
import org.geysermc.event.subscribe.Subscribe;
import org.geysermc.floodgate.event.ShutdownEvent;
// resources are properly closed and ignoring the original stack trace is intended
@@ -162,7 +162,7 @@ public class HttpClient {
return null;
}
@Handler
@Subscribe
public void onShutdown(ShutdownEvent ignored) {
executorService.shutdown();
}

View File

@@ -28,8 +28,8 @@ package org.geysermc.floodgate.util;
import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import net.engio.mbassy.listener.Handler;
import net.engio.mbassy.listener.Listener;
import org.geysermc.event.Listener;
import org.geysermc.event.subscribe.Subscribe;
import org.geysermc.floodgate.api.logger.FloodgateLogger;
import org.geysermc.floodgate.config.FloodgateConfig;
import org.geysermc.floodgate.event.PostEnableEvent;
@@ -91,7 +91,7 @@ public final class PostEnableMessages {
}
}
@Handler
@Subscribe
public void onPostEnable(PostEnableEvent ignored) {
new Thread(() -> {
// normally proxies don't have a lot of plugins, so proxies don't need to sleep as long