Skip to content

Commit

Permalink
Merge pull request #29 from bridgelol/main
Browse files Browse the repository at this point in the history
Add floodgate hook for bedrock player detection and set default encoding to UTF-8
  • Loading branch information
heychazza committed May 26, 2023
2 parents 2f6ac03 + f341662 commit 45bc52e
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 2 deletions.
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ subprojects {
archiveFileName.set("${project.name}-analyse-${rootProject.version}.jar")
}

tasks {
compileJava {
options.encoding = "UTF-8"
}
}

repositories {
mavenCentral()
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") {
Expand Down
7 changes: 7 additions & 0 deletions bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
group = rootProject.group
version = rootProject.version

repositories {
maven {
url = uri("https://repo.opencollab.dev/maven-snapshots/")
}
}

dependencies {
implementation(project(":sdk"))
implementation("it.unimi.dsi:fastutil:8.5.6")

compileOnly("org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT")
compileOnly("dev.dejvokep:boosted-yaml:1.3")
compileOnly("me.clip:placeholderapi:2.11.3")
compileOnly("org.geysermc.floodgate:api:2.2.0-SNAPSHOT")
}

tasks.named("shadowJar", ShadowJar::class.java) {
Expand Down
14 changes: 13 additions & 1 deletion bukkit/src/main/java/net/analyse/plugin/AnalysePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.analyse.plugin.event.PlayerQuitListener;
import net.analyse.plugin.event.ProxyMessageListener;
import net.analyse.plugin.event.ServerLoadListener;
import net.analyse.plugin.hook.FloodgateHook;
import net.analyse.plugin.hook.PlaceholderAPIExpansionHook;
import net.analyse.plugin.hook.PlaceholderAPIStatisticsHook;
import net.analyse.plugin.manager.CommandManager;
Expand Down Expand Up @@ -45,6 +46,7 @@ public final class AnalysePlugin extends JavaPlugin implements Platform {
private HeartbeatManager heartbeatManager;
private ModuleManager moduleManager;
private ProxyMessageListener proxyMessageListener;
private FloodgateHook floodgateHook;

/**
* Starts the Bukkit platform.
Expand Down Expand Up @@ -84,6 +86,7 @@ public void onEnable() {

// Set the values.
config.getYamlDocument().set("hooks.placeholderapi.enabled", papiEnabled);
config.getYamlDocument().set("hooks.floodgate.enabled", Bukkit.getPluginManager().isPluginEnabled("floodgate"));
config.getYamlDocument().set("hooks.placeholderapi.enabled-stats", papiStatistics);

config.getYamlDocument().set("settings.excluded-players", excludedPlayers);
Expand Down Expand Up @@ -172,10 +175,15 @@ public void onEnable() {
}

if(Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
log("PlaceholderAPI found. Registering placeholders..");
log("Hooked into PlaceholderAPI.");
new PlaceholderAPIExpansionHook(this).register();
}

if(config.isBedrockFloodgateHook() && Bukkit.getPluginManager().isPluginEnabled("floodgate")) {
log("Hooked into Floodgate.");
floodgateHook = new FloodgateHook();
}

// Load modules.
try {
Class.forName("org.bukkit.event.server.ServerLoadEvent");
Expand Down Expand Up @@ -260,6 +268,10 @@ public HeartbeatManager getHeartbeatManager() {
return heartbeatManager;
}

public FloodgateHook getFloodgateHook() {
return floodgateHook;
}

@Override
public PlatformType getType() {
return PlatformType.BUKKIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.Maps;
import net.analyse.plugin.AnalysePlugin;
import net.analyse.plugin.hook.FloodgateHook;
import net.analyse.sdk.obj.AnalysePlayer;
import net.analyse.sdk.platform.PlatformConfig;
import net.analyse.sdk.platform.PlayerType;
Expand Down Expand Up @@ -63,7 +64,11 @@ public void onJoin(PlayerJoinEvent event) {
}

// Bedrock Tracking
if(analyseConfig.getBedrockPrefix() != null && player.getName().startsWith(analyseConfig.getBedrockPrefix())) {
if (! analyseConfig.isBedrockFloodgateHook()) {
if (analyseConfig.getBedrockPrefix() != null && player.getName().startsWith(analyseConfig.getBedrockPrefix())) {
player.setType(PlayerType.BEDROCK);
}
} else if (platform.getFloodgateHook().isBedrock(event.getPlayer())) {
player.setType(PlayerType.BEDROCK);
}

Expand Down
12 changes: 12 additions & 0 deletions bukkit/src/main/java/net/analyse/plugin/hook/FloodgateHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.analyse.plugin.hook;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.geysermc.floodgate.api.FloodgateApi;

public class FloodgateHook {
public boolean isBedrock(Player player) {
if(! Bukkit.getPluginManager().isPluginEnabled("floodgate")) return false;
return FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId());
}
}
5 changes: 5 additions & 0 deletions bukkit/src/main/resources/platform/bukkit/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ hooks:
enabled: true
enabled-stats:
- 'enter_placeholder_here'
floodgate:
enabled: true

settings:
# Excluded Players (UUID)
Expand All @@ -16,6 +18,9 @@ settings:

# Bedrock Username Prefix
# The prefix to distinguish between Java and Bedrock players.
#
# Note: It will use the prefix from the floodgate plugin
# when 'hooks.floodgate.enabled' is set to 'true'.
bedrock-prefix: "."

# Minimum Playtime (Seconds)
Expand Down
1 change: 1 addition & 0 deletions bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ main: net.analyse.plugin.AnalysePlugin
api-version: 1.19
softdepend:
- PlaceholderAPI
- floodgate
commands:
analyse:
description: The main command
2 changes: 2 additions & 0 deletions sdk/src/main/java/net/analyse/sdk/platform/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ default PlatformConfig loadPlatformConfig(YamlDocument configFile) throws IOExce
config.setEnabledPapiStatistics(configFile.getStringList("hooks.placeholderapi.enabled-stats"));
}

config.setBedrockFloodgateHook(configFile.getBoolean("hooks.floodgate.enabled"));

config.setServerToken(configFile.getString("server.token"));
config.setEncryptionKey(configFile.getString("server.encryption-key"));
config.setDebugEnabled(configFile.getBoolean("debug", false));
Expand Down
19 changes: 19 additions & 0 deletions sdk/src/main/java/net/analyse/sdk/platform/PlatformConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class PlatformConfig {
private boolean useServerFirstJoinedAt;

private List<String> enabledPapiStatistics;
private boolean bedrockFloodgateHook;

private String serverToken;
private String encryptionKey;
Expand Down Expand Up @@ -74,6 +75,15 @@ public void setEnabledPapiStatistics(List<String> enabledPapiStatistics) {
this.enabledPapiStatistics = enabledPapiStatistics != null ? enabledPapiStatistics : Collections.emptyList();
}

/**
* Sets the optional Bedrock Floodgate API hook
*
* @param bedrockFloodgateHook Whether we should use the Floodgate API to detect Bedrock players instead.
*/
public void setBedrockFloodgateHook(boolean bedrockFloodgateHook) {
this.bedrockFloodgateHook = bedrockFloodgateHook;
}

/**
* Sets the server token.
*
Expand Down Expand Up @@ -201,6 +211,15 @@ public String getBedrockPrefix() {
return bedrockPrefix;
}

/**
* Returns whether Analyse should hook into Floodgate.
*
* @return The {@link Boolean} that represents whether Analyse should hook into Floodgate's API or not.
*/
public boolean isBedrockFloodgateHook() {
return bedrockFloodgateHook;
}

/**
* Checks if the debug mode is enabled.
*
Expand Down

0 comments on commit 45bc52e

Please sign in to comment.