From 3ee6cb2ada52d0dfc3b0aec0e3d8611ef6e2923c Mon Sep 17 00:00:00 2001
From: Smart123s <28480228+Smart123s@users.noreply.github.com>
Date: Sat, 23 Oct 2021 10:09:04 +0200
Subject: [PATCH] Create stub GeyserService
The FloodgateService and GeyserService classes are not merged,
because Geyser can work without Floodgate.
Added Geyser as 'softdepends' in plugin.yml and bungee.yml
to make it load before FastLogin.
Also made Floodgate a soft dependency in bungee.yml.
---
bukkit/pom.xml | 8 ++
.../fastlogin/bukkit/FastLoginBukkit.java | 12 +++
bukkit/src/main/resources/plugin.yml | 2 +
bungee/pom.xml | 8 ++
.../fastlogin/bungee/FastLoginBungee.java | 12 +++
bungee/src/main/resources/bungee.yml | 3 +
core/pom.xml | 8 ++
.../fastlogin/core/hooks/GeyserService.java | 74 +++++++++++++++++++
.../fastlogin/core/shared/PlatformPlugin.java | 3 +
.../fastlogin/velocity/FastLoginVelocity.java | 6 ++
10 files changed, 136 insertions(+)
create mode 100644 core/src/main/java/com/github/games647/fastlogin/core/hooks/GeyserService.java
diff --git a/bukkit/pom.xml b/bukkit/pom.xml
index 4910e090..a19fc13f 100644
--- a/bukkit/pom.xml
+++ b/bukkit/pom.xml
@@ -209,6 +209,14 @@
provided
+
+
+ org.geysermc
+ connector
+ 1.4.3-SNAPSHOT
+ provided
+
+
fr.xephi
diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java
index 25e3d00a..15915cc0 100644
--- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java
+++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java
@@ -36,6 +36,7 @@ import com.github.games647.fastlogin.bukkit.task.DelayedAuthHook;
import com.github.games647.fastlogin.core.CommonUtil;
import com.github.games647.fastlogin.core.PremiumStatus;
import com.github.games647.fastlogin.core.hooks.FloodgateService;
+import com.github.games647.fastlogin.core.hooks.GeyserService;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
@@ -53,6 +54,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
+import org.geysermc.connector.GeyserConnector;
import org.geysermc.floodgate.api.FloodgateApi;
import org.slf4j.Logger;
@@ -71,6 +73,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin core;
private FloodgateService floodgateService;
+ private GeyserService geyserService;
private PremiumPlaceholder premiumPlaceholder;
@@ -146,6 +149,10 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPluginprovided
+
+
+ org.geysermc
+ connector
+ 1.4.3-SNAPSHOT
+ provided
+
+
me.vik1395
diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java
index 0dcd99e7..76547e6a 100644
--- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java
+++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java
@@ -34,6 +34,7 @@ import com.github.games647.fastlogin.core.AsyncScheduler;
import com.github.games647.fastlogin.core.CommonUtil;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import com.github.games647.fastlogin.core.hooks.FloodgateService;
+import com.github.games647.fastlogin.core.hooks.GeyserService;
import com.github.games647.fastlogin.core.message.ChangePremiumMessage;
import com.github.games647.fastlogin.core.message.ChannelMessage;
import com.github.games647.fastlogin.core.message.NamespaceKey;
@@ -60,6 +61,7 @@ import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginManager;
import net.md_5.bungee.api.scheduler.GroupedThreadFactory;
+import org.geysermc.connector.GeyserConnector;
import org.geysermc.floodgate.api.FloodgateApi;
import org.slf4j.Logger;
@@ -73,6 +75,7 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin core;
private AsyncScheduler scheduler;
private FloodgateService floodgateService;
+ private GeyserService geyserService;
private Logger logger;
@Override
@@ -90,6 +93,10 @@ public class FastLoginBungee extends Plugin implements PlatformPluginprovided
+
+
+ org.geysermc
+ connector
+ 1.4.3-SNAPSHOT
+ provided
+
+
com.github.games647
diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/GeyserService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/GeyserService.java
new file mode 100644
index 00000000..cba87850
--- /dev/null
+++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/GeyserService.java
@@ -0,0 +1,74 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015-2021
+ *
+ * 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.
+ */
+package com.github.games647.fastlogin.core.hooks;
+
+import java.util.UUID;
+
+import com.github.games647.fastlogin.core.shared.FastLoginCore;
+
+import org.geysermc.connector.GeyserConnector;
+import org.geysermc.connector.network.session.GeyserSession;
+
+public class GeyserService {
+
+ private final GeyserConnector geyser;
+ private final FastLoginCore, ?, ?> core;
+
+ public GeyserService(GeyserConnector geyser, FastLoginCore, ?, ?> core) {
+ this.geyser = geyser;
+ this.core = core;
+ }
+
+ /**
+ * The Geyser API does not support querying players by name, so this function
+ * iterates over every online Geyser Player and checks if the requested
+ * username can be found
+ *
+ * @param username the name of the player
+ * @return GeyserSession if found, null otherwise
+ */
+ public GeyserSession getGeyserPlayer(String username) {
+ for (GeyserSession gSess : geyser.getSessionManager().getSessions().values()) {
+ if (gSess.getName().equals(username)) {
+ return gSess;
+ }
+ }
+
+ return null;
+ }
+
+ public GeyserSession getGeyserPlayer(UUID uuid) {
+ return geyser.getPlayerByUuid(uuid);
+ }
+
+ public boolean isGeyserPlayer(UUID uuid) {
+ return getGeyserPlayer(uuid) != null;
+ }
+
+ public boolean isGeyserConnection(String username) {
+ return getGeyserPlayer(username) != null;
+ }
+}
diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java
index aba983a3..1268a865 100644
--- a/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java
+++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java
@@ -27,6 +27,7 @@ package com.github.games647.fastlogin.core.shared;
import com.github.games647.fastlogin.core.AsyncScheduler;
import com.github.games647.fastlogin.core.hooks.FloodgateService;
+import com.github.games647.fastlogin.core.hooks.GeyserService;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.nio.file.Path;
@@ -56,6 +57,8 @@ public interface PlatformPlugin {
FloodgateService getFloodgateService();
+ GeyserService getGeyserService();
+
default ThreadFactory getThreadFactory() {
return new ThreadFactoryBuilder()
.setNameFormat(getName() + " Pool Thread #%1$d")
diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java
index 68edf7a0..69ae0899 100644
--- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java
+++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java
@@ -27,6 +27,7 @@ package com.github.games647.fastlogin.velocity;
import com.github.games647.fastlogin.core.AsyncScheduler;
import com.github.games647.fastlogin.core.hooks.FloodgateService;
+import com.github.games647.fastlogin.core.hooks.GeyserService;
import com.github.games647.fastlogin.core.message.ChangePremiumMessage;
import com.github.games647.fastlogin.core.message.ChannelMessage;
import com.github.games647.fastlogin.core.message.SuccessMessage;
@@ -144,6 +145,11 @@ public class FastLoginVelocity implements PlatformPlugin {
return null;
}
+ @Override
+ public GeyserService getGeyserService() {
+ return null;
+ }
+
public FastLoginCore getCore() {
return core;
}