Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = '1.7.2'

defaultTasks 'clean', 'shadowJar'

sourceCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
Expand All @@ -32,7 +32,7 @@ dependencies {

compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
compileOnly 'net.md-5:bungeecord-api:1.21-R0.1-SNAPSHOT'
compileOnly 'com.velocitypowered:velocity-api:3.3.0-SNAPSHOT'
compileOnly 'com.velocitypowered:velocity-api:3.1.1-SNAPSHOT'

compileOnly 'me.clip:placeholderapi:2.11.6'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,24 @@ public TwoFactorAuthenticationPlaceholders(TwoFactorAuthentication plugin) {

@Override
public String onPlaceholderRequest(Player player, String identifier) {
return switch (identifier.toLowerCase()) {
case "is_enabled" -> plugin.getAuthHandler().is2FAEnabled(player.getUniqueId())
? MessageHandler.TwoFAMessages.KEYWORD_ENABLED.getMessage()
: MessageHandler.TwoFAMessages.KEYWORD_DISABLED.getMessage();
case "time_since_enabled" -> {
switch (identifier.toLowerCase()) {
case "is_enabled":
return plugin.getAuthHandler().is2FAEnabled(player.getUniqueId())
? MessageHandler.TwoFAMessages.KEYWORD_ENABLED.getMessage()
: MessageHandler.TwoFAMessages.KEYWORD_DISABLED.getMessage();
case "time_since_enabled":
long enableDate = plugin.getAuthHandler().getStorageHandler().getEnableDate(player.getUniqueId());
yield enableDate == -1 ? "Not Enabled"
return enableDate == -1 ? "Not Enabled"
: TimeUtils.parseTime(System.currentTimeMillis() - enableDate);
}
case "key" -> plugin.getAuthHandler().getStorageHandler()
.getKey(player.getUniqueId());
case "is_required" -> player.hasPermission(Constants.demandPermission)
? MessageHandler.TwoFAMessages.KEYWORD_REQUIRED.getMessage()
: MessageHandler.TwoFAMessages.KEYWORD_NOT_REQUIRED.getMessage();
default -> null;
};

case "key":
return plugin.getAuthHandler().getStorageHandler()
.getKey(player.getUniqueId());
case "is_required":
return player.hasPermission(Constants.demandPermission)
? MessageHandler.TwoFAMessages.KEYWORD_REQUIRED.getMessage()
: MessageHandler.TwoFAMessages.KEYWORD_NOT_REQUIRED.getMessage();
default:
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.lielamar.auth.bukkit.communication.ProxyAuthCommunication;
import com.lielamar.auth.bukkit.utils.cmd.StandaloneCommand;
import com.lielamar.auth.bukkit.utils.cmd.SuperCommand;
import com.lielamar.auth.bukkit.utils.version.Version;
import com.lielamar.auth.shared.handlers.MessageHandler;
import com.lielamar.auth.shared.utils.Constants;
import org.bukkit.Bukkit;
Expand All @@ -16,6 +17,8 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
Expand All @@ -40,7 +43,7 @@ public boolean runCommand(@NotNull CommandSender commandSender, @NotNull String[
Date now = new Date();

commandSender.sendMessage(ChatColor.GREEN + "Creating a Bug Report file...");

PrintWriter writer;
try {
File dataFolder = this.plugin.getDataFolder();
if (!dataFolder.exists()) {
Expand All @@ -58,7 +61,7 @@ public boolean runCommand(@NotNull CommandSender commandSender, @NotNull String[
}

FileWriter fileWriter = new FileWriter(file, true);
PrintWriter writer = new PrintWriter(fileWriter);
writer = new PrintWriter(fileWriter);

writer.println("Server Java and OS");
writer.println("- Java Runtime Version: " + System.getProperty("java.runtime.version"));
Expand All @@ -85,7 +88,7 @@ public boolean runCommand(@NotNull CommandSender commandSender, @NotNull String[
writer.println("");

writer.println("Communication Method & Proxies: ");
writer.println("- Using Bungeecord: " + Class.forName("org.spigotmc.SpigotConfig").getField("bungee").getBoolean(null));
writer.println("- Proxy Software: " + getProxy());
writer.println("- Is Proxy Loaded: " + (this.plugin.getAuthHandler().getAuthCommunicationHandler() instanceof ProxyAuthCommunication));
writer.println("- Communication Method in config: " + this.plugin.getConfigHandler().getCommunicationMethod().name());
writer.println("- Communication Timeout in config: " + this.plugin.getConfigHandler().getCommunicationTimeout() + " ticks");
Expand All @@ -107,7 +110,6 @@ public boolean runCommand(@NotNull CommandSender commandSender, @NotNull String[
commandSender.sendMessage(ChatColor.GREEN + "Created a Bug Report file, Use this for your Bug Report! :)");
} catch (IOException | ClassNotFoundException | NoSuchFieldException | IllegalAccessException exception) {
exception.printStackTrace();

commandSender.sendMessage(ChatColor.RED + "Failed to create a Bug Report file!");
}
return false;
Expand All @@ -132,4 +134,55 @@ public void noPermissionEvent(@NotNull CommandSender commandSender) {
public String[] getAliases() {
return new String[]{"print", "info", "report"};
}

private String getProxy() throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException {
if (isUsingBungee()) {
return "BUNGEE";
} else if (isUsingVelocity()) {
return "VELOCITY";
} else {
return "NONE";
}
}

private boolean isUsingBungee() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
return Class.forName("org.spigotmc.SpigotConfig").getField("bungee").getBoolean(null);
}

// This should detect if using velocity above and from paper version 1.13.1 build 377
// commit https://github.com/PaperMC/paper/commit/7141632abfd3ede89a1e3749c4e40ef6d0be8574
private boolean isUsingVelocity() {
if (Version.getInstance().getServerVersion().above(Version.ServerVersion.v1_19)) {
try {
Class<?> globalConfigClass = Class.forName("io.papermc.paper.configuration.GlobalConfiguration"); // Replace with the actual package name
Object globalConfigInstance = globalConfigClass.getMethod("get").invoke(null);

Field proxiesField = globalConfigClass.getDeclaredField("proxies");
proxiesField.setAccessible(true);
Object proxiesInstance = proxiesField.get(globalConfigInstance);

Field velocityField = proxiesInstance.getClass().getDeclaredField("velocity");
velocityField.setAccessible(true);
Object velocityInstance = velocityField.get(proxiesInstance);

Field enabledField = velocityInstance.getClass().getDeclaredField("enabled");
enabledField.setAccessible(true);
return enabledField.getBoolean(velocityInstance);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | NoSuchFieldException | InvocationTargetException e) {
e.printStackTrace();
return false;
}
} else {
try {
Class<?> paperConfigClass = Class.forName("com.destroystokyo.paper.PaperConfig");
Field velocitySupportField = paperConfigClass.getDeclaredField("velocitySupport");
velocitySupportField.setAccessible(true);

return velocitySupportField.getBoolean(null);
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
return false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -216,7 +211,7 @@ public void run() {

ItemStack mapItem;

if (version.above(Version.ServerVersion.v1_13_0)) {
if (version.above(Version.ServerVersion.v1_13)) {
mapItem = new ItemStack(Material.FILLED_MAP);

if (mapItem.getItemMeta() instanceof MapMeta) {
Expand Down Expand Up @@ -336,7 +331,7 @@ public void removeQRItem(Player player) {
}
});

if (version.above(Version.ServerVersion.v1_9_0)) {
if (version.above(Version.ServerVersion.v1_9)) {
if (isQRCodeItem(player.getInventory().getItemInOffHand())) {
player.getInventory().setItemInOffHand(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ public BukkitDependencyHandler(TwoFactorAuthentication plugin) {
super(new BukkitLibraryManager(plugin));
}

private void loadBukkitDependencies() {
@Override
protected void loadDependencies() {
super.loadDependencies();
Library library;

String commonsCodecVersion = "1.17.1"; // Updated to match Gradle build file
String hikariCpVersion = "5.1.0"; // Updated to match Gradle build file
String h2Version = "2.3.230"; // Updated to match Gradle build file
String mysqlVersion = "9.0.0"; // Updated to match Gradle build file
Expand All @@ -24,71 +25,63 @@ private void loadBukkitDependencies() {
String slf4jVersion = "2.0.13"; // Updated to match Gradle build file
String log4jVersion = "2.23.1"; // Updated to match Gradle build file

logger.info("Loading library Commons-Codec v{}", commonsCodecVersion);
library = Library.builder()
.groupId("commons-codec")
.artifactId("commons-codec")
.version(commonsCodecVersion)
.build();
loader.loadLibrary(library);

logger.info("Loading library HikariCP v{}", hikariCpVersion);
logger.info("Loading library HikariCP v" + hikariCpVersion);
library = Library.builder()
.groupId("com.zaxxer")
.artifactId("HikariCP")
.version(hikariCpVersion)
.build();
loader.loadLibrary(library);

logger.info("Loading library H2 v{}", h2Version);
logger.info("Loading library H2 v" + h2Version);
library = Library.builder()
.groupId("com.h2database")
.artifactId("h2")
.version(h2Version)
.build();
loader.loadLibrary(library);

logger.info("Loading library MySQL v{}", mysqlVersion);
logger.info("Loading library MySQL v" + mysqlVersion);
library = Library.builder()
.groupId("com.mysql")
.artifactId("mysql-connector-j")
.version(mysqlVersion)
.build();
loader.loadLibrary(library);

logger.info("Loading library MariaDB v{}", mariaDBVersion);
logger.info("Loading library MariaDB v" + mariaDBVersion);
library = Library.builder()
.groupId("org.mariadb.jdbc")
.artifactId("mariadb-java-client")
.version(mariaDBVersion)
.build();
loader.loadLibrary(library);

logger.info("Loading library PostgreSQL v{}", postgresVersion);
logger.info("Loading library PostgreSQL v" + postgresVersion);
library = Library.builder()
.groupId("org.postgresql")
.artifactId("postgresql")
.version(postgresVersion)
.build();
loader.loadLibrary(library);

logger.info("Loading library MongoDB v{}", mongoDBVersion);
logger.info("Loading library MongoDB v" + mongoDBVersion);
library = Library.builder()
.groupId("org.mongodb")
.artifactId("mongodb-driver-sync")
.version(mongoDBVersion)
.build();
loader.loadLibrary(library);

logger.info("Loading library Slf4j v{}", slf4jVersion);
logger.info("Loading library Slf4j v" + slf4jVersion);
library = Library.builder()
.groupId("org.slf4j")
.artifactId("slf4j-api")
.version(slf4jVersion)
.build();
loader.loadLibrary(library);

logger.info("Loading library Log4j v{}", log4jVersion);
logger.info("Loading library Log4j v" + log4jVersion);
library = Library.builder()
.groupId("org.apache.logging.log4j")
.artifactId("log4j-core")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,12 @@ public void onItemDrop(PlayerDropItemEvent event) {
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onItemPickup(EntityPickupItemEvent event) {
if (!this.plugin.getConfigHandler().getDisabledEvents().getOrDefault(event.getClass(), true)
|| !event.getEntityType().equals(EntityType.PLAYER)) {
public void onItemPickup(PlayerPickupItemEvent event) {
if (!this.plugin.getConfigHandler().getDisabledEvents().getOrDefault(event.getClass(), true)) {
return;
}

if (this.plugin.getAuthHandler().needsToAuthenticate(event.getEntity().getUniqueId())) {
if (this.plugin.getAuthHandler().needsToAuthenticate(event.getPlayer().getUniqueId())) {
event.setCancelled(true);
} else if (this.plugin.getAuthHandler().isQRCodeItem(event.getItem().getItemStack())) {
event.getItem().remove();
Expand Down
Loading