Skip to content

Commit

Permalink
Better hook into geyser, resource filtering and general fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SageSphinx63920 committed Apr 2, 2024
1 parent 7125ccf commit 463cdae
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 108 deletions.
20 changes: 18 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.sage.minecraft</groupId>
<artifactId>keklist</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Keklist</name>
Expand Down Expand Up @@ -148,8 +148,18 @@
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>*.yml</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>*.yml</exclude>
</excludes>
</resource>
</resources>
</build>
Expand Down Expand Up @@ -250,6 +260,12 @@
<version>5.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geysermc.geyser</groupId>
<artifactId>api</artifactId>
<version>2.2.3-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!-- Provided via custom loader -->
<dependency>
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/de/hdg/keklist/Keklist.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import de.hdg.keklist.events.ListPingEvent;
import de.hdg.keklist.events.PreLoginKickEvent;
import de.hdg.keklist.events.ServerWhitelistChangeEvent;
import de.hdg.keklist.extentions.GeyserEventRegistrar;
import de.hdg.keklist.extentions.PlaceholderAPIExtension;
import de.hdg.keklist.extentions.context.BlacklistedCalculator;
import de.hdg.keklist.extentions.context.WhitelistedCalculator;
Expand Down Expand Up @@ -44,6 +45,7 @@
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.geysermc.floodgate.api.FloodgateApi;
import org.geysermc.geyser.api.GeyserApi;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -65,6 +67,7 @@ public final class Keklist extends JavaPlugin {
private PlaceholderAPIExtension placeholders;
private ContextManager contextManager;
private final List<ContextCalculator<Player>> registeredCalculators = new ArrayList<>();
private GeyserApi geyserApi;

/* Global */
private static @Getter DB database;
Expand Down Expand Up @@ -116,7 +119,7 @@ public void onLoad() {
//set debug mode
debug = getConfig().getBoolean("debug");

updateChecker = new UpdateChecker("simpig-city", "Keklist", getPluginMeta().getVersion(), true, getLogger());
//updateChecker = new UpdateChecker("simpig-city", "Keklist", getPluginMeta().getVersion(), true, getLogger());

//SQL
if (getConfig().getBoolean("mariadb.enabled")) {
Expand Down Expand Up @@ -192,6 +195,20 @@ public void onEnable() {
}
}

// Geyser hook
if (Bukkit.getPluginManager().getPlugin("Geyser-Spigot") != null) {
geyserApi = GeyserApi.api();

// We will not set the prefix if geyser is not enabled as the proxy could provide a different prefix than the floodgate api on sub server does
if(geyserApi.usernamePrefix() != null) {
getConfig().set("floodgate.prefix", geyserApi.usernamePrefix());
getLogger().info(translations.get("geyser.prefix", geyserApi.usernamePrefix()));
}

GeyserEventRegistrar eventRegistrar = new GeyserEventRegistrar(geyserApi, this);
eventRegistrar.registerEvents();
}

// Update checker
// TODO : Uncomment this when the plugin is *publicly* released
/*if (getConfig().getBoolean("update.check"))
Expand All @@ -204,7 +221,7 @@ public void onEnable() {
}
}, 0, getConfig().getInt("update.interval"), java.util.concurrent.TimeUnit.HOURS);*/

updateChecker.setUpdateMessage(translations.get("update.message", getPluginMeta().getVersion()));
//updateChecker.setUpdateMessage(translations.get("update.message", getPluginMeta().getVersion()));

}

Expand Down
47 changes: 47 additions & 0 deletions src/main/java/de/hdg/keklist/events/GeyserConnectionEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package de.hdg.keklist.events;

import de.hdg.keklist.Keklist;
import de.hdg.keklist.extentions.WebhookManager;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.geysermc.geyser.api.event.connection.ConnectionRequestEvent;

import java.sql.ResultSet;
import java.sql.SQLException;

public class GeyserConnectionEvent {

private static final FileConfiguration config = Keklist.getInstance().getConfig();

public static void onConnectionRequestEvent(ConnectionRequestEvent event) {
String ip = event.getInetSocketAddress().getAddress().getHostAddress();

try (ResultSet rsIp = Keklist.getDatabase().onQuery("SELECT * FROM blacklistIp WHERE ip = ?", ip)) {
if (rsIp.next()) {
if (config.getBoolean("blacklist.allow-join-with-admin")) {
for (Player player : Keklist.getInstance().getServer().getOnlinePlayers()) {
if (player.hasPermission(config.getString("blacklist.admin-permission"))) {
return;
}
}
}

if (Keklist.getInstance().getConfig().getBoolean("chat-notify"))
Bukkit.broadcast(Keklist.getInstance().getMiniMessage().deserialize(Keklist.getTranslations().get("notify.kick", ip)), "keklist.notify.kicked");

if (Keklist.getWebhookManager() != null)
Keklist.getWebhookManager().fireBlacklistEvent(WebhookManager.EVENT_TYPE.BLACKLIST_KICK, ip, rsIp.getString("byPlayer"), null, System.currentTimeMillis());

Bukkit.getConsoleSender().sendMessage(Keklist.getInstance().getMiniMessage().deserialize(Keklist.getTranslations().get("notify.kick", ip)));

event.setCancelled(true);
}
} catch (SQLException e) {
Keklist.getInstance().getLogger().severe(Keklist.getTranslations().get("geyser.events.error", e.getMessage()));
Keklist.getInstance().getLogger().severe(Keklist.getTranslations().get("geyser.events.fallback"));
event.setCancelled(true);
}

}
}
2 changes: 1 addition & 1 deletion src/main/java/de/hdg/keklist/events/PreLoginKickEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void onPreLogin(AsyncPlayerPreLoginEvent event) {
client.newCall(request).enqueue(new PreLoginKickEvent.WebhooknameCallback(WebhookManager.EVENT_TYPE.WHITELIST_KICK, event.getAddress().getHostAddress(), null, System.currentTimeMillis()));
} else {
if (Keklist.getWebhookManager() != null)
Keklist.getWebhookManager().fireWhitelistEvent(WebhookManager.EVENT_TYPE.WHITELIST_KICK, event.getName()+ " (" + event.getAddress().getHostAddress() + ")", null, System.currentTimeMillis());
Keklist.getWebhookManager().fireWhitelistEvent(WebhookManager.EVENT_TYPE.WHITELIST_KICK, event.getName() + " (" + event.getAddress().getHostAddress() + ")", null, System.currentTimeMillis());

if (Keklist.getInstance().getConfig().getBoolean("chat-notify"))
Bukkit.broadcast(Keklist.getInstance().getMiniMessage().deserialize(Keklist.getTranslations().get("notify.kick", event.getName())), "keklist.notify.kicked");
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/de/hdg/keklist/extentions/GeyserEventRegistrar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.hdg.keklist.extentions;

import de.hdg.keklist.Keklist;
import de.hdg.keklist.events.GeyserConnectionEvent;
import lombok.SneakyThrows;
import org.geysermc.event.PostOrder;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.event.EventRegistrar;
import org.geysermc.geyser.api.event.connection.ConnectionRequestEvent;

public class GeyserEventRegistrar implements EventRegistrar {

private final GeyserApi geyserApi;
private final Keklist keklist;

public GeyserEventRegistrar(GeyserApi geyserApi, Keklist keklist) {
this.geyserApi = geyserApi;
this.keklist = keklist;
}

@SneakyThrows
public void registerEvents() {
geyserApi.eventBus().subscribe(this, ConnectionRequestEvent.class, GeyserConnectionEvent::onConnectionRequestEvent, PostOrder.FIRST);
keklist.getLogger().info(Keklist.getTranslations().get("geyser.events.registered"));
}
}
16 changes: 10 additions & 6 deletions src/main/java/de/hdg/keklist/util/KeklistConfigUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,31 @@ public void updateConfig() {
newConfig.load(reader);
FileConfigurationOptions newOptions = newConfig.options();

boolean update = false;

for (String key : newConfig.getKeys(true)) {
if (!oldConfig.getKeys(true).contains(key)) {
oldConfig.set(key, newConfig.get(key));

if(Keklist.isDebug())
plugin.getLogger().info("Added new config value: " + key);
update = true;
}

if (Keklist.isDebug())
plugin.getLogger().info("Added new config value: " + key);

oldConfig.setComments(key, newConfig.getComments(key));
oldConfig.setInlineComments(key, newConfig.getInlineComments(key));
}

oldConfig.save(new File(plugin.getDataFolder(), "config.yml"));
plugin.reloadConfig();

plugin.getLogger().info("Config updated to version: " + newConfig.get("config_version") + "!");
if (update)
plugin.getLogger().info("Config updated to version: " + newConfig.get("config_version") + "!");

reader.close();
} catch (IOException | InvalidConfigurationException e) {
plugin.getLogger().severe("Error while updating config! Please report this to the developer!");
plugin.getLogger().severe(e.getMessage());
plugin.getLogger().severe("Error while updating config! Please report this to the developer!");
plugin.getLogger().severe(e.getMessage());
}
}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/lang/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@
"keklist.manage.disabled": "<red>This command is disabled due to security reasons! <grey><i>This can be enabled in the config.",

"floodgate.api-key-not-set": "<orange>You did not set the Floodgate API key in the config! Either get the floodgate uuid from https://mcprofile.io using the UUID directly or the floodgate user must be in the server's cache otherwise the request will fail!",
"geyser.prefix": "Geyser detected, using prefix: %s",
"geyser.events.registered": "Geyser events registered!",
"geyser.events.error": "An error occurred while checking the IP blacklist on geyser: %s",
"geyser.events.fallback": "Fallback to deny connection.",

"http.error": "<red>Could not connect to the Mojang-API!",
"http.not-found": "<red>Could not find the player! More information: %s",
Expand Down
93 changes: 0 additions & 93 deletions src/main/resources/config.yml

This file was deleted.

9 changes: 6 additions & 3 deletions src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Keklist
version: '1.0.0'
version: ${project.version}
main: de.hdg.keklist.Keklist
api-version: '1.20'
description: Custom made white and blacklist with many features!
description: ${project.description}
authors: [ "hdgamer1404Jonas", "SageSphinx63920" ]
website: https://keklist.pages.dev
loader: de.hdg.keklist.KeklistLoader
Expand All @@ -26,7 +26,10 @@ dependencies:

PlaceholderAPI:
required: false


Geyser-Spigot:
load: BEFORE
required: false

permissions:
keklist.gui.use:
Expand Down
2 changes: 1 addition & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mvn package -f pom.xml
mkdir -p ./testserver/plugins
cp ./target/keklist-1.0-SNAPSHOT.jar ./testserver/plugins
cp ./target/keklist-*.*.*-SNAPSHOT.jar ./testserver/plugins

cd ./testserver || exit

Expand Down

0 comments on commit 463cdae

Please sign in to comment.