Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e39bd0bd3 | |||
| ac5dfcde26 | |||
| 8aef3ceb06 | |||
| 5155ab6302 | |||
| cd5a008637 | |||
| 58fe9a7394 | |||
| 910ebdd5bf | |||
| 5f89964f49 | |||
| 4f0bc6d12f | |||
| 9346285c08 | |||
| 19a4ec3176 | |||
| 46f64d8048 | |||
| e04608e499 | |||
| c402e2ec5a | |||
| 4437be8863 | |||
| b54c1f8d34 | |||
| a9402846b5 | |||
| c37e4b2374 | |||
| acad03fbbf | |||
| 8061645346 | |||
| b97840a320 | |||
| a5ba77a3d2 | |||
| ea383dd0f1 | |||
| 885db23fc6 | |||
| 68ab92dd7a | |||
| d9495ff839 | |||
| 0e01d8145f | |||
| ed9e379500 | |||
| a9cb2d2490 | |||
| 900937c033 | |||
| 9585fc1bdb | |||
| d8d3e8544c | |||
| a50e5fa802 | |||
| c9363ca6e8 | |||
| 222bd879d1 | |||
| 01f4a8f205 | |||
| be976b6738 | |||
| c89a818696 | |||
| 1c63eca0f7 |
@@ -5,6 +5,7 @@ MCBBS Link: [Click Here](https://www.mcbbs.net/forum.php?mod=viewthread&tid=1471
|
||||
<p align="center">
|
||||
<img src="https://img.shields.io/github/languages/code-size/HaHaWTH/AuthMeReReloaded.svg" alt="Code size"/>
|
||||
<img src="https://img.shields.io/github/repo-size/HaHaWTH/AuthMeReReloaded.svg" alt="GitHub repo size"/>
|
||||
<img src="https://www.codefactor.io/repository/github/hahawth/authmerereloaded/badge" alt="CodeFactor" />
|
||||
</p>
|
||||
|
||||
**Detailed Changes:**
|
||||
@@ -24,10 +25,24 @@ MCBBS Link: [Click Here](https://www.mcbbs.net/forum.php?mod=viewthread&tid=1471
|
||||
13. Offhand Menu compatibility(Thats amazing)
|
||||
14. Automatically fix portal stuck issue
|
||||
15. Automatically login for Bedrock players(configurable)
|
||||
16. More......
|
||||
16. Fix shulker box crash bug on legacy versions(MC 1.13-)
|
||||
17. **H2 database support**
|
||||
18. More......
|
||||
|
||||
**Download links:**
|
||||
[Releases](https://github.com/HaHaWTH/AuthMeReReloaded/releases/latest)
|
||||
[Actions(Dev builds, use at your own risk!)](https://github.com/HaHaWTH/AuthMeReReloaded/actions/workflows/maven.yml)
|
||||
|
||||
TODO: Implement HAProxy ip forward(Useful for Frp)
|
||||
|
||||
**Pull Requests and suggestions are welcome!**
|
||||
|
||||
<picture>
|
||||
<source
|
||||
media="(prefers-color-scheme: dark)"
|
||||
srcset="
|
||||
https://api.star-history.com/svg?repos=HaHaWTH/AuthMeReReloaded&type=Date&theme=dark
|
||||
"
|
||||
/>
|
||||
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=HaHaWTH/AuthMeReReloaded&type=Date" />
|
||||
</picture>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ the generated config.yml file.
|
||||
```yml
|
||||
DataSource:
|
||||
# What type of database do you want to use?
|
||||
# Valid values: SQLITE, MARIADB, MYSQL, POSTGRESQL
|
||||
# Valid values: H2, SQLITE, MARIADB, MYSQL, POSTGRESQL
|
||||
backend: SQLITE
|
||||
# Enable the database caching system, should be disabled on bungeecord environments
|
||||
# or when a website integration is being used.
|
||||
|
||||
@@ -294,7 +294,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<version>3.5.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>shaded-jar</id>
|
||||
@@ -346,10 +346,10 @@
|
||||
<pattern>com.google.gson</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.com.google.gson</shadedPattern>
|
||||
</relocation>
|
||||
<!-- <relocation>-->
|
||||
<!-- <pattern>com.cryptomorin.xseries</pattern>-->
|
||||
<!-- <shadedPattern>fr.xephi.authme.libs.com.cryptomorin.xseries</shadedPattern>-->
|
||||
<!-- </relocation>-->
|
||||
<relocation>
|
||||
<pattern>org.h2</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.org.h2</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
@@ -444,6 +444,14 @@
|
||||
<pattern>com.google.protobuf</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.com.google.protobuf</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>io.netty</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.io.netty</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.apache.commons.validator</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.org.apache.commons.validator</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
|
||||
<filters>
|
||||
@@ -511,6 +519,19 @@
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>lss233-repo</id>
|
||||
<url>https://crystal.app.lss233.com/repositories/minecraft/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>opencollab-snapshot-main</id>
|
||||
<url>https://repo.opencollab.dev/main/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>opencollab-maven-snapshots</id>
|
||||
<url>https://repo.opencollab.dev/maven-snapshots/</url>
|
||||
</repository>
|
||||
|
||||
<!-- Apache snapshots repo -->
|
||||
<repository>
|
||||
<id>apache-snapshots</id>
|
||||
@@ -629,10 +650,6 @@
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>opencollab-snapshot-main</id>
|
||||
<url>https://repo.opencollab.dev/main/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@@ -869,13 +886,19 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- <!– XSeries –>-->
|
||||
<!-- dependencies used by HAProxy feature -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.github.cryptomorin</groupId>-->
|
||||
<!-- <artifactId>XSeries</artifactId>-->
|
||||
<!-- <version>9.8.0</version>-->
|
||||
<!-- <groupId>io.netty</groupId>-->
|
||||
<!-- <artifactId>netty-codec-haproxy</artifactId>-->
|
||||
<!-- <version>4.1.104.Final</version>-->
|
||||
<!-- <scope>compile</scope>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>commons-validator</groupId>-->
|
||||
<!-- <artifactId>commons-validator</artifactId>-->
|
||||
<!-- <version>1.8.0</version>-->
|
||||
<!-- <scope>provided</scope>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- zPermissions plugin -->
|
||||
<dependency>
|
||||
@@ -1099,14 +1122,14 @@
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.44.1.0</version>
|
||||
<version>3.45.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>2.1.214</version>
|
||||
<scope>test</scope>
|
||||
<version>2.2.224</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -11,6 +11,7 @@ import fr.xephi.authme.initialization.OnShutdownPlayerSaver;
|
||||
import fr.xephi.authme.initialization.OnStartupTasks;
|
||||
import fr.xephi.authme.initialization.SettingsProvider;
|
||||
import fr.xephi.authme.initialization.TaskCloser;
|
||||
import fr.xephi.authme.listener.AdvancedShulkerFixListener;
|
||||
import fr.xephi.authme.listener.BedrockAutoLoginListener;
|
||||
import fr.xephi.authme.listener.BlockListener;
|
||||
import fr.xephi.authme.listener.DoubleLoginFixListener;
|
||||
@@ -74,7 +75,7 @@ public class AuthMe extends JavaPlugin {
|
||||
// Version and build number values
|
||||
private static String pluginVersion = "5.6.0-Fork";
|
||||
private static final String pluginBuild = "b";
|
||||
private static String pluginBuildNumber = "39";
|
||||
private static String pluginBuildNumber = "41";
|
||||
// Private instances
|
||||
private EmailService emailService;
|
||||
private CommandHandler commandHandler;
|
||||
@@ -189,22 +190,12 @@ public class AuthMe extends JavaPlugin {
|
||||
// Set up Metrics
|
||||
OnStartupTasks.sendMetrics(this, settings);
|
||||
if (settings.getProperty(SecuritySettings.SHOW_STARTUP_BANNER)) {
|
||||
String loadColorConfig = settings.getProperty(SecuritySettings.STARTUP_BANNER_COLOR);
|
||||
if (loadColorConfig.startsWith("§") && !loadColorConfig.endsWith("§") && (loadColorConfig.length() % 2 == 0)) {
|
||||
logger.info("\n" + loadColorConfig + " ___ __ __ __ ___ \n" +
|
||||
loadColorConfig + " / | __ __/ /_/ /_ / |/ /__ \n" +
|
||||
loadColorConfig + " / /| |/ / / / __/ __ \\/ /|_/ / _ \\\n" +
|
||||
loadColorConfig + " / ___ / /_/ / /_/ / / / / / / __/\n" +
|
||||
loadColorConfig + "/_/ |_\\__,_/\\__/_/ /_/_/ /_/\\___/ \n" +
|
||||
loadColorConfig + " ");
|
||||
} else {
|
||||
logger.info("\n" + " ___ __ __ __ ___ \n" +
|
||||
" / | __ __/ /_/ /_ / |/ /__ \n" +
|
||||
" / /| |/ / / / __/ __ \\/ /|_/ / _ \\\n" +
|
||||
" / ___ / /_/ / /_/ / / / / / / __/\n" +
|
||||
"/_/ |_\\__,_/\\__/_/ /_/_/ /_/\\___/ \n" +
|
||||
" ");
|
||||
}
|
||||
logger.info("\n" + " ___ __ __ __ ___ \n" +
|
||||
" / | __ __/ /_/ /_ / |/ /__ \n" +
|
||||
" / /| |/ / / / __/ __ \\/ /|_/ / _ \\\n" +
|
||||
" / ___ / /_/ / /_/ / / / / / / __/\n" +
|
||||
"/_/ |_\\__,_/\\__/_/ /_/_/ /_/\\___/ \n" +
|
||||
" ");
|
||||
}
|
||||
// Successful message
|
||||
//detect server brand with classloader
|
||||
@@ -359,6 +350,11 @@ public class AuthMe extends JavaPlugin {
|
||||
if (settings.getProperty(SecuritySettings.ANTI_GHOST_PLAYERS)) {
|
||||
pluginManager.registerEvents(injector.getSingleton(DoubleLoginFixListener.class), this);
|
||||
}
|
||||
if (settings.getProperty(SecuritySettings.ADVANCED_SHULKER_FIX) && !isClassLoaded("org.bukkit.event.player.PlayerCommandSendEvent")) {
|
||||
pluginManager.registerEvents(injector.getSingleton(AdvancedShulkerFixListener.class), this);
|
||||
} else if (settings.getProperty(SecuritySettings.ADVANCED_SHULKER_FIX) && isClassLoaded("org.bukkit.event.player.PlayerCommandSendEvent")) {
|
||||
logger.warning("You are running an 1.13+ minecraft server, advancedShulkerFix won't enable.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -426,7 +422,7 @@ public class AuthMe extends JavaPlugin {
|
||||
if (isUpdateAvailable(latestVersion)) {
|
||||
String message = "New version available! Latest:" + latestVersion + " Current:" + pluginBuild + pluginBuildNumber;
|
||||
getLogger().log(Level.WARNING, message);
|
||||
getLogger().log(Level.WARNING, "Download from here: github.com/HaHaWTH/AuthMeReReloaded/releases/latest");
|
||||
getLogger().log(Level.WARNING, "Download from here: https://github.com/HaHaWTH/AuthMeReReloaded/releases/latest");
|
||||
} else {
|
||||
getLogger().log(Level.INFO, "You are running the latest version.");
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import fr.xephi.authme.datasource.converter.LoginSecurityConverter;
|
||||
import fr.xephi.authme.datasource.converter.MySqlToSqlite;
|
||||
import fr.xephi.authme.datasource.converter.RakamakConverter;
|
||||
import fr.xephi.authme.datasource.converter.RoyalAuthConverter;
|
||||
import fr.xephi.authme.datasource.converter.SqliteToH2;
|
||||
import fr.xephi.authme.datasource.converter.SqliteToSql;
|
||||
import fr.xephi.authme.datasource.converter.VAuthConverter;
|
||||
import fr.xephi.authme.datasource.converter.XAuthConverter;
|
||||
@@ -89,6 +90,7 @@ public class ConverterCommand implements ExecutableCommand {
|
||||
.put("vauth", VAuthConverter.class)
|
||||
.put("sqlitetosql", SqliteToSql.class)
|
||||
.put("mysqltosqlite", MySqlToSqlite.class)
|
||||
.put("sqlitetoh2", SqliteToH2.class)
|
||||
.put("loginsecurity", LoginSecurityConverter.class)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.util.TeleportUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package fr.xephi.authme.command.executable.authme;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -17,6 +19,8 @@ public class VersionCommand implements ExecutableCommand {
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
@Inject
|
||||
private Settings settings;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
@@ -24,6 +28,7 @@ public class VersionCommand implements ExecutableCommand {
|
||||
sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.getPluginName() + " ABOUT ]==========");
|
||||
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.getPluginName()
|
||||
+ " v" + AuthMe.getPluginVersion() + ChatColor.GRAY + " (build: " + AuthMe.getPluginBuildNumber() + ")");
|
||||
sender.sendMessage(ChatColor.GOLD + "Database Implementation: " + ChatColor.WHITE + settings.getProperty(DatabaseSettings.BACKEND).toString());
|
||||
sender.sendMessage(ChatColor.GOLD + "Authors:");
|
||||
Collection<Player> onlinePlayers = bukkitService.getOnlinePlayers();
|
||||
printDeveloper(sender, "Gabriele C.", "sgdc3", "Project manager, Contributor", onlinePlayers);
|
||||
|
||||
@@ -4,7 +4,7 @@ package fr.xephi.authme.datasource;
|
||||
* DataSource type.
|
||||
*/
|
||||
public enum DataSourceType {
|
||||
// H2,
|
||||
H2,
|
||||
|
||||
MYSQL,
|
||||
|
||||
|
||||
@@ -1,408 +1,422 @@
|
||||
//package fr.xephi.authme.datasource;
|
||||
//
|
||||
//import com.google.common.annotations.VisibleForTesting;
|
||||
//import fr.xephi.authme.ConsoleLogger;
|
||||
//import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
//import fr.xephi.authme.datasource.columnshandler.AuthMeColumnsHandler;
|
||||
//import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
//import fr.xephi.authme.settings.Settings;
|
||||
//import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.sql.Connection;
|
||||
//import java.sql.DatabaseMetaData;
|
||||
//import java.sql.DriverManager;
|
||||
//import java.sql.PreparedStatement;
|
||||
//import java.sql.ResultSet;
|
||||
//import java.sql.SQLException;
|
||||
//import java.sql.Statement;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Collection;
|
||||
//import java.util.HashSet;
|
||||
//import java.util.List;
|
||||
//import java.util.Locale;
|
||||
//import java.util.Set;
|
||||
//
|
||||
//import static fr.xephi.authme.datasource.SqlDataSourceUtils.getNullableLong;
|
||||
//import static fr.xephi.authme.datasource.SqlDataSourceUtils.logSqlException;
|
||||
//
|
||||
///**
|
||||
// * H2 data source.
|
||||
// */
|
||||
//@SuppressWarnings({"checkstyle:AbbreviationAsWordInName"}) // Justification: Class name cannot be changed anymore
|
||||
//public class H2 extends AbstractSqlDataSource {
|
||||
//
|
||||
// private final ConsoleLogger logger = ConsoleLoggerFactory.get(H2.class);
|
||||
// private final Settings settings;
|
||||
// private final File dataFolder;
|
||||
// private final String database;
|
||||
// private final String tableName;
|
||||
// private final Columns col;
|
||||
// private Connection con;
|
||||
//
|
||||
// /**
|
||||
// * Constructor for H2.
|
||||
// *
|
||||
// * @param settings The settings instance
|
||||
// * @param dataFolder The data folder
|
||||
// * @throws SQLException when initialization of a SQL datasource failed
|
||||
// */
|
||||
// public H2(Settings settings, File dataFolder) throws SQLException {
|
||||
// this.settings = settings;
|
||||
// this.dataFolder = dataFolder;
|
||||
// this.database = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
|
||||
// this.tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE);
|
||||
// this.col = new Columns(settings);
|
||||
//
|
||||
// try {
|
||||
// this.connect();
|
||||
// this.setup();
|
||||
// } catch (Exception ex) {
|
||||
// logger.logException("Error during H2 initialization:", ex);
|
||||
// throw ex;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @VisibleForTesting
|
||||
// H2(Settings settings, File dataFolder, Connection connection) {
|
||||
// this.settings = settings;
|
||||
// this.dataFolder = dataFolder;
|
||||
// this.database = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
|
||||
// this.tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE);
|
||||
// this.col = new Columns(settings);
|
||||
// this.con = connection;
|
||||
// this.columnsHandler = AuthMeColumnsHandler.createForSqlite(con, settings);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Initializes the connection to the H2 database.
|
||||
// *
|
||||
// * @throws SQLException when an SQL error occurs while connecting
|
||||
// */
|
||||
// protected void connect() throws SQLException {
|
||||
// try {
|
||||
// Class.forName("org.h2.Driver");
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// throw new IllegalStateException("Failed to load H2 JDBC class", e);
|
||||
// }
|
||||
//
|
||||
// logger.debug("H2 driver loaded");
|
||||
// this.con = DriverManager.getConnection(this.getJdbcUrl(this.dataFolder.getAbsolutePath(), "", this.database));
|
||||
// this.columnsHandler = AuthMeColumnsHandler.createForSqlite(con, settings);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates the table if necessary, or adds any missing columns to the table.
|
||||
// *
|
||||
// * @throws SQLException when an SQL error occurs while initializing the database
|
||||
// */
|
||||
// @VisibleForTesting
|
||||
// @SuppressWarnings("checkstyle:CyclomaticComplexity")
|
||||
// protected void setup() throws SQLException {
|
||||
// try (Statement st = con.createStatement()) {
|
||||
// // Note: cannot add unique fields later on in SQLite, so we add it on initialization
|
||||
// st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
||||
// + col.ID + " INTEGER AUTO_INCREMENT, "
|
||||
// + col.NAME + " VARCHAR(255) NOT NULL UNIQUE, "
|
||||
// + "CONSTRAINT table_const_prim PRIMARY KEY (" + col.ID + "));");
|
||||
//
|
||||
// DatabaseMetaData md = con.getMetaData();
|
||||
//
|
||||
// if (isColumnMissing(md, col.REAL_NAME)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
// + col.REAL_NAME + " VARCHAR(255) NOT NULL DEFAULT 'Player';");
|
||||
// }
|
||||
//
|
||||
// if (isColumnMissing(md, col.PASSWORD)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName
|
||||
// + " ADD COLUMN " + col.PASSWORD + " VARCHAR(255) NOT NULL DEFAULT '';");
|
||||
// }
|
||||
//
|
||||
// if (!col.SALT.isEmpty() && isColumnMissing(md, col.SALT)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.SALT + " VARCHAR(255);");
|
||||
// }
|
||||
//
|
||||
// if (isColumnMissing(md, col.LAST_IP)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName
|
||||
// + " ADD COLUMN " + col.LAST_IP + " VARCHAR(40);");
|
||||
// }
|
||||
//
|
||||
// if (isColumnMissing(md, col.LAST_LOGIN)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName
|
||||
// + " ADD COLUMN " + col.LAST_LOGIN + " TIMESTAMP;");
|
||||
// }
|
||||
//
|
||||
// if (isColumnMissing(md, col.REGISTRATION_IP)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName
|
||||
// + " ADD COLUMN " + col.REGISTRATION_IP + " VARCHAR(40);");
|
||||
// }
|
||||
//
|
||||
// if (isColumnMissing(md, col.REGISTRATION_DATE)) {
|
||||
// addRegistrationDateColumn(st);
|
||||
// }
|
||||
//
|
||||
// if (isColumnMissing(md, col.LASTLOC_X)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.LASTLOC_X
|
||||
// + " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
// st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.LASTLOC_Y
|
||||
// + " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
// st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.LASTLOC_Z
|
||||
// + " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
// }
|
||||
//
|
||||
// if (isColumnMissing(md, col.LASTLOC_WORLD)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName
|
||||
// + " ADD COLUMN " + col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT 'world';");
|
||||
// }
|
||||
//
|
||||
// if (isColumnMissing(md, col.LASTLOC_YAW)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
// + col.LASTLOC_YAW + " FLOAT;");
|
||||
// }
|
||||
//
|
||||
// if (isColumnMissing(md, col.LASTLOC_PITCH)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
// + col.LASTLOC_PITCH + " FLOAT;");
|
||||
// }
|
||||
//
|
||||
// if (isColumnMissing(md, col.EMAIL)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName
|
||||
// + " ADD COLUMN " + col.EMAIL + " VARCHAR(255);");
|
||||
// }
|
||||
//
|
||||
// if (isColumnMissing(md, col.IS_LOGGED)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName
|
||||
// + " ADD COLUMN " + col.IS_LOGGED + " INT NOT NULL DEFAULT '0';");
|
||||
// }
|
||||
//
|
||||
// if (isColumnMissing(md, col.HAS_SESSION)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName
|
||||
// + " ADD COLUMN " + col.HAS_SESSION + " INT NOT NULL DEFAULT '0';");
|
||||
// }
|
||||
//
|
||||
// if (isColumnMissing(md, col.TOTP_KEY)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName
|
||||
// + " ADD COLUMN " + col.TOTP_KEY + " VARCHAR(32);");
|
||||
// }
|
||||
//
|
||||
// if (!col.PLAYER_UUID.isEmpty() && isColumnMissing(md, col.PLAYER_UUID)) {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName
|
||||
// + " ADD COLUMN " + col.PLAYER_UUID + " VARCHAR(36)");
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.columnshandler.AuthMeColumnsHandler;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import static fr.xephi.authme.datasource.SqlDataSourceUtils.getNullableLong;
|
||||
import static fr.xephi.authme.datasource.SqlDataSourceUtils.logSqlException;
|
||||
|
||||
/**
|
||||
* H2 data source.
|
||||
*/
|
||||
@SuppressWarnings({"checkstyle:AbbreviationAsWordInName"}) // Justification: Class name cannot be changed anymore
|
||||
public class H2 extends AbstractSqlDataSource {
|
||||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(H2.class);
|
||||
private final Settings settings;
|
||||
private final File dataFolder;
|
||||
private final String database;
|
||||
private final String tableName;
|
||||
private final Columns col;
|
||||
private Connection con;
|
||||
|
||||
/**
|
||||
* Constructor for H2.
|
||||
*
|
||||
* @param settings The settings instance
|
||||
* @param dataFolder The data folder
|
||||
* @throws SQLException when initialization of a SQL datasource failed
|
||||
*/
|
||||
public H2(Settings settings, File dataFolder) throws SQLException {
|
||||
this.settings = settings;
|
||||
this.dataFolder = dataFolder;
|
||||
this.database = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
|
||||
this.tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE);
|
||||
this.col = new Columns(settings);
|
||||
|
||||
try {
|
||||
this.connect();
|
||||
this.setup();
|
||||
} catch (Exception ex) {
|
||||
logger.logException("Error during H2 initialization:", ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
H2(Settings settings, File dataFolder, Connection connection) {
|
||||
this.settings = settings;
|
||||
this.dataFolder = dataFolder;
|
||||
this.database = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
|
||||
this.tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE);
|
||||
this.col = new Columns(settings);
|
||||
this.con = connection;
|
||||
this.columnsHandler = AuthMeColumnsHandler.createForSqlite(con, settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the connection to the H2 database.
|
||||
*
|
||||
* @throws SQLException when an SQL error occurs while connecting
|
||||
*/
|
||||
protected void connect() throws SQLException {
|
||||
try {
|
||||
Class.forName("org.h2.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalStateException("Failed to load H2 JDBC class", e);
|
||||
}
|
||||
|
||||
logger.debug("H2 driver loaded");
|
||||
this.con = DriverManager.getConnection(this.getJdbcUrl(this.dataFolder.getAbsolutePath(), "", this.database));
|
||||
this.columnsHandler = AuthMeColumnsHandler.createForSqlite(con, settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the table if necessary, or adds any missing columns to the table.
|
||||
*
|
||||
* @throws SQLException when an SQL error occurs while initializing the database
|
||||
*/
|
||||
@VisibleForTesting
|
||||
@SuppressWarnings("checkstyle:CyclomaticComplexity")
|
||||
protected void setup() throws SQLException {
|
||||
try (Statement st = con.createStatement()) {
|
||||
// Note: cannot add unique fields later on in SQLite, so we add it on initialization
|
||||
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
||||
+ col.ID + " INTEGER AUTO_INCREMENT, "
|
||||
+ col.NAME + " VARCHAR(255) NOT NULL UNIQUE, "
|
||||
+ "CONSTRAINT table_const_prim PRIMARY KEY (" + col.ID + "));");
|
||||
|
||||
DatabaseMetaData md = con.getMetaData();
|
||||
|
||||
if (isColumnMissing(md, col.REAL_NAME)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN IF NOT EXISTS "
|
||||
+ col.REAL_NAME + " VARCHAR(255) NOT NULL DEFAULT 'Player';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.PASSWORD)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN IF NOT EXISTS " + col.PASSWORD + " VARCHAR(255) NOT NULL DEFAULT '';");
|
||||
}
|
||||
|
||||
if (!col.SALT.isEmpty() && isColumnMissing(md, col.SALT)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN IF NOT EXISTS " + col.SALT + " VARCHAR(255);");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LAST_IP)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN IF NOT EXISTS " + col.LAST_IP + " VARCHAR(40);");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LAST_LOGIN)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN IF NOT EXISTS " + col.LAST_LOGIN + " BIGINT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.REGISTRATION_IP)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN IF NOT EXISTS " + col.REGISTRATION_IP + " VARCHAR(40);");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.REGISTRATION_DATE)) {
|
||||
addRegistrationDateColumn(st);
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_X)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN IF NOT EXISTS " + col.LASTLOC_X
|
||||
+ " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN IF NOT EXISTS " + col.LASTLOC_Y
|
||||
+ " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN IF NOT EXISTS " + col.LASTLOC_Z
|
||||
+ " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_WORLD)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN IF NOT EXISTS " + col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT 'world';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_YAW)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN IF NOT EXISTS "
|
||||
+ col.LASTLOC_YAW + " FLOAT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_PITCH)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN IF NOT EXISTS "
|
||||
+ col.LASTLOC_PITCH + " FLOAT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.EMAIL)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN IF NOT EXISTS " + col.EMAIL + " VARCHAR(255);");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.IS_LOGGED)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN IF NOT EXISTS " + col.IS_LOGGED + " INT NOT NULL DEFAULT '0';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.HAS_SESSION)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN IF NOT EXISTS " + col.HAS_SESSION + " INT NOT NULL DEFAULT '0';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.TOTP_KEY)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN IF NOT EXISTS " + col.TOTP_KEY + " VARCHAR(32);");
|
||||
}
|
||||
|
||||
if (!col.PLAYER_UUID.isEmpty() && isColumnMissing(md, col.PLAYER_UUID)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN IF NOT EXISTS " + col.PLAYER_UUID + " VARCHAR(36)");
|
||||
}
|
||||
}
|
||||
logger.info("H2 Setup finished");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a column is missing in the specified table.
|
||||
* @param columnName the name of the column to look for
|
||||
* @return true if the column is missing, false if it exists
|
||||
* @throws SQLException if an error occurs while executing SQL or accessing the result set
|
||||
* @deprecated Not work in H2, it always returns true
|
||||
*/
|
||||
@Deprecated
|
||||
private boolean isColumnMissing(DatabaseMetaData metaData, String columnName) throws SQLException {
|
||||
String query = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND COLUMN_NAME = ?";
|
||||
// try (PreparedStatement preparedStatement = con.prepareStatement(query)) {
|
||||
// preparedStatement.setString(1, tableName);
|
||||
// preparedStatement.setString(2, columnName.toUpperCase());
|
||||
// try (ResultSet rs = preparedStatement.executeQuery()) {
|
||||
// return !rs.next();
|
||||
// }
|
||||
// }
|
||||
// logger.info("H2 Setup finished");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private boolean isColumnMissing(DatabaseMetaData metaData, String columnName) throws SQLException {
|
||||
// try (ResultSet rs = metaData.getColumns(null, null, tableName, columnName)) {
|
||||
// return !rs.next();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void reload() {
|
||||
// close(con);
|
||||
// try {
|
||||
// this.connect();
|
||||
// this.setup();
|
||||
// } catch (SQLException ex) {
|
||||
// logger.logException("Error while reloading H2:", ex);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public PlayerAuth getAuth(String user) {
|
||||
// String sql = "SELECT * FROM " + tableName + " WHERE LOWER(" + col.NAME + ")=LOWER(?);";
|
||||
// try (PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
// pst.setString(1, user);
|
||||
// try (ResultSet rs = pst.executeQuery()) {
|
||||
// if (rs.next()) {
|
||||
// return buildAuthFromResultSet(rs);
|
||||
// }
|
||||
// }
|
||||
// } catch (SQLException ex) {
|
||||
// logSqlException(ex);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Set<String> getRecordsToPurge(long until) {
|
||||
// Set<String> list = new HashSet<>();
|
||||
// String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE MAX("
|
||||
// + " COALESCE(" + col.LAST_LOGIN + ", 0),"
|
||||
// + " COALESCE(" + col.REGISTRATION_DATE + ", 0)"
|
||||
// + ") < ?;";
|
||||
// try (PreparedStatement selectPst = con.prepareStatement(select)) {
|
||||
// selectPst.setLong(1, until);
|
||||
// try (ResultSet rs = selectPst.executeQuery()) {
|
||||
// while (rs.next()) {
|
||||
// list.add(rs.getString(col.NAME));
|
||||
// }
|
||||
// }
|
||||
// } catch (SQLException ex) {
|
||||
// logSqlException(ex);
|
||||
// }
|
||||
//
|
||||
// return list;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void purgeRecords(Collection<String> toPurge) {
|
||||
// String delete = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;";
|
||||
// try (PreparedStatement deletePst = con.prepareStatement(delete)) {
|
||||
// for (String name : toPurge) {
|
||||
// deletePst.setString(1, name.toLowerCase(Locale.ROOT));
|
||||
// deletePst.executeUpdate();
|
||||
// }
|
||||
// } catch (SQLException ex) {
|
||||
// logSqlException(ex);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean removeAuth(String user) {
|
||||
// String sql = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;";
|
||||
// try (PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
// pst.setString(1, user.toLowerCase(Locale.ROOT));
|
||||
// pst.executeUpdate();
|
||||
// return true;
|
||||
// } catch (SQLException ex) {
|
||||
// logSqlException(ex);
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void closeConnection() {
|
||||
// try {
|
||||
// if (con != null && !con.isClosed()) {
|
||||
// con.close();
|
||||
// }
|
||||
// } catch (SQLException ex) {
|
||||
// logSqlException(ex);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public DataSourceType getType() {
|
||||
// return DataSourceType.H2;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<PlayerAuth> getAllAuths() {
|
||||
// List<PlayerAuth> auths = new ArrayList<>();
|
||||
// String sql = "SELECT * FROM " + tableName + ";";
|
||||
// try (PreparedStatement pst = con.prepareStatement(sql); ResultSet rs = pst.executeQuery()) {
|
||||
// while (rs.next()) {
|
||||
// PlayerAuth auth = buildAuthFromResultSet(rs);
|
||||
// auths.add(auth);
|
||||
// }
|
||||
// } catch (SQLException ex) {
|
||||
// logSqlException(ex);
|
||||
// }
|
||||
// return auths;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<String> getLoggedPlayersWithEmptyMail() {
|
||||
// List<String> players = new ArrayList<>();
|
||||
// String sql = "SELECT " + col.REAL_NAME + " FROM " + tableName + " WHERE " + col.IS_LOGGED + " = 1"
|
||||
// + " AND (" + col.EMAIL + " = 'your@email.com' OR " + col.EMAIL + " IS NULL);";
|
||||
// try (Statement st = con.createStatement(); ResultSet rs = st.executeQuery(sql)) {
|
||||
// while (rs.next()) {
|
||||
// players.add(rs.getString(1));
|
||||
// }
|
||||
// } catch (SQLException ex) {
|
||||
// logSqlException(ex);
|
||||
// }
|
||||
// return players;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<PlayerAuth> getRecentlyLoggedInPlayers() {
|
||||
// List<PlayerAuth> players = new ArrayList<>();
|
||||
// String sql = "SELECT * FROM " + tableName + " ORDER BY " + col.LAST_LOGIN + " DESC LIMIT 10;";
|
||||
// try (Statement st = con.createStatement(); ResultSet rs = st.executeQuery(sql)) {
|
||||
// while (rs.next()) {
|
||||
// players.add(buildAuthFromResultSet(rs));
|
||||
// }
|
||||
// } catch (SQLException e) {
|
||||
// logSqlException(e);
|
||||
// }
|
||||
// return players;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public boolean setTotpKey(String user, String totpKey) {
|
||||
// String sql = "UPDATE " + tableName + " SET " + col.TOTP_KEY + " = ? WHERE " + col.NAME + " = ?";
|
||||
// try (PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
// pst.setString(1, totpKey);
|
||||
// pst.setString(2, user.toLowerCase(Locale.ROOT));
|
||||
// pst.executeUpdate();
|
||||
// return true;
|
||||
// } catch (SQLException e) {
|
||||
// logSqlException(e);
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException {
|
||||
// String salt = !col.SALT.isEmpty() ? row.getString(col.SALT) : null;
|
||||
//
|
||||
// return PlayerAuth.builder()
|
||||
// .name(row.getString(col.NAME))
|
||||
// .email(row.getString(col.EMAIL))
|
||||
// .realName(row.getString(col.REAL_NAME))
|
||||
// .password(row.getString(col.PASSWORD), salt)
|
||||
// .totpKey(row.getString(col.TOTP_KEY))
|
||||
// .lastLogin(getNullableLong(row, col.LAST_LOGIN))
|
||||
// .lastIp(row.getString(col.LAST_IP))
|
||||
// .registrationDate(row.getLong(col.REGISTRATION_DATE))
|
||||
// .registrationIp(row.getString(col.REGISTRATION_IP))
|
||||
// .locX(row.getDouble(col.LASTLOC_X))
|
||||
// .locY(row.getDouble(col.LASTLOC_Y))
|
||||
// .locZ(row.getDouble(col.LASTLOC_Z))
|
||||
// .locWorld(row.getString(col.LASTLOC_WORLD))
|
||||
// .locYaw(row.getFloat(col.LASTLOC_YAW))
|
||||
// .locPitch(row.getFloat(col.LASTLOC_PITCH))
|
||||
// .build();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates the column for registration date and sets all entries to the current timestamp.
|
||||
// * We do so in order to avoid issues with purging, where entries with 0 / NULL might get
|
||||
// * purged immediately on startup otherwise.
|
||||
// *
|
||||
// * @param st Statement object to the database
|
||||
// */
|
||||
// private void addRegistrationDateColumn(Statement st) throws SQLException {
|
||||
// st.executeUpdate("ALTER TABLE " + tableName
|
||||
// + " ADD COLUMN " + col.REGISTRATION_DATE + " TIMESTAMP NOT NULL DEFAULT '0';");
|
||||
//
|
||||
// // Use the timestamp from Java to avoid timezone issues in case JVM and database are out of sync
|
||||
// long currentTimestamp = System.currentTimeMillis();
|
||||
// int updatedRows = st.executeUpdate(String.format("UPDATE %s SET %s = %d;",
|
||||
// tableName, col.REGISTRATION_DATE, currentTimestamp));
|
||||
// logger.info("Created column '" + col.REGISTRATION_DATE + "' and set the current timestamp, "
|
||||
// + currentTimestamp + ", to all " + updatedRows + " rows");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// String getJdbcUrl(String dataPath, String ignored, String database) {
|
||||
// return "jdbc:h2:" + dataPath + File.separator + database + ".db";
|
||||
// }
|
||||
//
|
||||
// private static void close(Connection con) {
|
||||
// if (con != null) {
|
||||
// try {
|
||||
// con.close();
|
||||
// } catch (SQLException ex) {
|
||||
// logSqlException(ex);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
close(con);
|
||||
try {
|
||||
this.connect();
|
||||
this.setup();
|
||||
} catch (SQLException ex) {
|
||||
logger.logException("Error while reloading H2:", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerAuth getAuth(String user) {
|
||||
String sql = "SELECT * FROM " + tableName + " WHERE LOWER(" + col.NAME + ")=LOWER(?);";
|
||||
try (PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setString(1, user);
|
||||
try (ResultSet rs = pst.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
return buildAuthFromResultSet(rs);
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getRecordsToPurge(long until) {
|
||||
Set<String> list = new HashSet<>();
|
||||
String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE MAX("
|
||||
+ " COALESCE(" + col.LAST_LOGIN + ", 0),"
|
||||
+ " COALESCE(" + col.REGISTRATION_DATE + ", 0)"
|
||||
+ ") < ?;";
|
||||
try (PreparedStatement selectPst = con.prepareStatement(select)) {
|
||||
selectPst.setLong(1, until);
|
||||
try (ResultSet rs = selectPst.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
list.add(rs.getString(col.NAME));
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void purgeRecords(Collection<String> toPurge) {
|
||||
String delete = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;";
|
||||
try (PreparedStatement deletePst = con.prepareStatement(delete)) {
|
||||
for (String name : toPurge) {
|
||||
deletePst.setString(1, name.toLowerCase(Locale.ROOT));
|
||||
deletePst.executeUpdate();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAuth(String user) {
|
||||
String sql = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;";
|
||||
try (PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setString(1, user.toLowerCase(Locale.ROOT));
|
||||
pst.executeUpdate();
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeConnection() {
|
||||
try {
|
||||
if (con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceType getType() {
|
||||
return DataSourceType.H2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlayerAuth> getAllAuths() {
|
||||
List<PlayerAuth> auths = new ArrayList<>();
|
||||
String sql = "SELECT * FROM " + tableName + ";";
|
||||
try (PreparedStatement pst = con.prepareStatement(sql); ResultSet rs = pst.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
PlayerAuth auth = buildAuthFromResultSet(rs);
|
||||
auths.add(auth);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
return auths;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLoggedPlayersWithEmptyMail() {
|
||||
List<String> players = new ArrayList<>();
|
||||
String sql = "SELECT " + col.REAL_NAME + " FROM " + tableName + " WHERE " + col.IS_LOGGED + " = 1"
|
||||
+ " AND (" + col.EMAIL + " = 'your@email.com' OR " + col.EMAIL + " IS NULL);";
|
||||
try (Statement st = con.createStatement(); ResultSet rs = st.executeQuery(sql)) {
|
||||
while (rs.next()) {
|
||||
players.add(rs.getString(1));
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlayerAuth> getRecentlyLoggedInPlayers() {
|
||||
List<PlayerAuth> players = new ArrayList<>();
|
||||
String sql = "SELECT * FROM " + tableName + " ORDER BY " + col.LAST_LOGIN + " DESC LIMIT 10;";
|
||||
try (Statement st = con.createStatement(); ResultSet rs = st.executeQuery(sql)) {
|
||||
while (rs.next()) {
|
||||
players.add(buildAuthFromResultSet(rs));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logSqlException(e);
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean setTotpKey(String user, String totpKey) {
|
||||
String sql = "UPDATE " + tableName + " SET " + col.TOTP_KEY + " = ? WHERE " + col.NAME + " = ?";
|
||||
try (PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setString(1, totpKey);
|
||||
pst.setString(2, user.toLowerCase(Locale.ROOT));
|
||||
pst.executeUpdate();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
logSqlException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException {
|
||||
String salt = !col.SALT.isEmpty() ? row.getString(col.SALT) : null;
|
||||
|
||||
return PlayerAuth.builder()
|
||||
.name(row.getString(col.NAME))
|
||||
.email(row.getString(col.EMAIL))
|
||||
.realName(row.getString(col.REAL_NAME))
|
||||
.password(row.getString(col.PASSWORD), salt)
|
||||
.totpKey(row.getString(col.TOTP_KEY))
|
||||
.lastLogin(getNullableLong(row, col.LAST_LOGIN))
|
||||
.lastIp(row.getString(col.LAST_IP))
|
||||
.registrationDate(row.getLong(col.REGISTRATION_DATE))
|
||||
.registrationIp(row.getString(col.REGISTRATION_IP))
|
||||
.locX(row.getDouble(col.LASTLOC_X))
|
||||
.locY(row.getDouble(col.LASTLOC_Y))
|
||||
.locZ(row.getDouble(col.LASTLOC_Z))
|
||||
.locWorld(row.getString(col.LASTLOC_WORLD))
|
||||
.locYaw(row.getFloat(col.LASTLOC_YAW))
|
||||
.locPitch(row.getFloat(col.LASTLOC_PITCH))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the column for registration date and sets all entries to the current timestamp.
|
||||
* We do so in order to avoid issues with purging, where entries with 0 / NULL might get
|
||||
* purged immediately on startup otherwise.
|
||||
*
|
||||
* @param st Statement object to the database
|
||||
*/
|
||||
private void addRegistrationDateColumn(Statement st) throws SQLException {
|
||||
int affect = st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN IF NOT EXISTS " + col.REGISTRATION_DATE + " BIGINT NOT NULL DEFAULT '0';");
|
||||
if (affect > 0) {
|
||||
long currentTimestamp = System.currentTimeMillis();
|
||||
int updatedRows = st.executeUpdate(String.format("UPDATE %s SET %s = %d;",
|
||||
tableName, col.REGISTRATION_DATE, currentTimestamp));
|
||||
logger.info("Created column '" + col.REGISTRATION_DATE + "' and set the current timestamp, "
|
||||
+ currentTimestamp + ", to all " + updatedRows + " rows");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
String getJdbcUrl(String dataPath, String ignored, String database) {
|
||||
return "jdbc:h2:" + dataPath + File.separator + database;
|
||||
}
|
||||
|
||||
private static void close(Connection con) {
|
||||
if (con != null) {
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package fr.xephi.authme.datasource.converter;
|
||||
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.datasource.SQLite;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Converts SQLite to H2
|
||||
*
|
||||
*/
|
||||
public class SqliteToH2 extends AbstractDataSourceConverter<SQLite>{
|
||||
|
||||
private final Settings settings;
|
||||
private final File dataFolder;
|
||||
|
||||
@Inject
|
||||
SqliteToH2(Settings settings, DataSource dataSource, @DataFolder File dataFolder) {
|
||||
super(dataSource, DataSourceType.H2);
|
||||
this.settings = settings;
|
||||
this.dataFolder = dataFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SQLite getSource() throws SQLException {
|
||||
return new SQLite(settings, dataFolder);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.CacheDataSource;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.datasource.H2;
|
||||
import fr.xephi.authme.datasource.MariaDB;
|
||||
import fr.xephi.authme.datasource.MySQL;
|
||||
import fr.xephi.authme.datasource.PostgreSqlDataSource;
|
||||
@@ -76,9 +77,9 @@ public class DataSourceProvider implements Provider<DataSource> {
|
||||
case SQLITE:
|
||||
dataSource = new SQLite(settings, dataFolder);
|
||||
break;
|
||||
// case H2:
|
||||
// dataSource = new H2(settings, dataFolder);
|
||||
// break;
|
||||
case H2:
|
||||
dataSource = new H2(settings, dataFolder);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown data source type '" + dataSourceType + "'");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package fr.xephi.authme.listener;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockDispenseEvent;
|
||||
|
||||
//This fix is only for Minecraft 1.13-
|
||||
public class AdvancedShulkerFixListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onDispenserActivate(BlockDispenseEvent event) {
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (block.getY() <= 0 || block.getY() >= block.getWorld().getMaxHeight() - 1) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,86 +164,83 @@ public class GuiCaptchaHandler implements Listener {
|
||||
messages.send(playerunreg, MessageKey.GUI_CAPTCHA_VERIFIED_AUTO_BEDROCK);
|
||||
return;
|
||||
}
|
||||
|
||||
bukkitService.runTaskAsynchronously(() -> {
|
||||
bukkitService.runTask(() -> {
|
||||
randomString = sb.toString();
|
||||
Random random_blockpos = new Random();
|
||||
AtomicInteger random_num = new AtomicInteger(random_blockpos.nextInt(26));
|
||||
Inventory menu = Bukkit.createInventory(playerunreg, 27, messages.retrieveSingle(playerunreg, MessageKey.GUI_CAPTCHA_WINDOW_NAME, randomString));
|
||||
ItemStack item = new ItemStack(Material.REDSTONE_BLOCK);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
try {
|
||||
if (meta != null) {
|
||||
meta.setDisplayName(messages.retrieveSingle(playerunreg, MessageKey.GUI_CAPTCHA_CLICKABLE_NAME, randomString));
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
getLogger().log(Level.WARNING, "Unexpected error occurred while setting item meta.");
|
||||
bukkitService.runTask(() -> {
|
||||
randomString = sb.toString();
|
||||
Random random_blockpos = new Random();
|
||||
AtomicInteger random_num = new AtomicInteger(random_blockpos.nextInt(26));
|
||||
Inventory menu = Bukkit.createInventory(playerunreg, 27, messages.retrieveSingle(playerunreg, MessageKey.GUI_CAPTCHA_WINDOW_NAME, randomString));
|
||||
ItemStack item = new ItemStack(Material.REDSTONE_BLOCK);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
try {
|
||||
if (meta != null) {
|
||||
meta.setDisplayName(messages.retrieveSingle(playerunreg, MessageKey.GUI_CAPTCHA_CLICKABLE_NAME, randomString));
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
windowPacketListener = new PacketAdapter(this.plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CLOSE_WINDOW) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
Player packetPlayer = event.getPlayer();
|
||||
if (!closeReasonMap.containsKey(packetPlayer) && !authmeApi.isRegistered(packetPlayer.getName())) {
|
||||
} catch (NullPointerException e) {
|
||||
getLogger().log(Level.WARNING, "Unexpected error occurred while setting item meta.");
|
||||
}
|
||||
windowPacketListener = new PacketAdapter(this.plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CLOSE_WINDOW) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
Player packetPlayer = event.getPlayer();
|
||||
if (!closeReasonMap.containsKey(packetPlayer) && !authmeApi.isRegistered(packetPlayer.getName())) {
|
||||
if (timesLeft <= 0) {
|
||||
bukkitService.runTask(() -> {
|
||||
packetPlayer.kickPlayer(service.retrieveSingleMessage(packetPlayer, MessageKey.GUI_CAPTCHA_KICK_FAILED));
|
||||
});
|
||||
timesLeft = 3;
|
||||
} else {
|
||||
--timesLeft;
|
||||
if (timesLeft <= 0) {
|
||||
bukkitService.runTask(() -> {
|
||||
packetPlayer.kickPlayer(service.retrieveSingleMessage(packetPlayer, MessageKey.GUI_CAPTCHA_KICK_FAILED));
|
||||
});
|
||||
timesLeft = 3;
|
||||
} else {
|
||||
--timesLeft;
|
||||
if (timesLeft <= 0) {
|
||||
bukkitService.runTask(() -> {
|
||||
packetPlayer.kickPlayer(service.retrieveSingleMessage(packetPlayer, MessageKey.GUI_CAPTCHA_KICK_FAILED));
|
||||
});
|
||||
timesLeft = 3;
|
||||
return;
|
||||
}
|
||||
messages.send(packetPlayer, MessageKey.GUI_CAPTCHA_RETRY_MESSAGE, String.valueOf(timesLeft));
|
||||
event.setCancelled(true);
|
||||
random_num.set(random_blockpos.nextInt(26));
|
||||
bukkitService.runTask(() -> {
|
||||
menu.clear();
|
||||
menu.setItem(random_num.get(), item);
|
||||
packetPlayer.openInventory(menu);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
chatPacketListener = new PacketAdapter(this.plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CHAT) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
Player packetPlayer = event.getPlayer();
|
||||
if (!closeReasonMap.containsKey(packetPlayer) && !authmeApi.isRegistered(packetPlayer.getName())) {
|
||||
messages.send(packetPlayer, MessageKey.GUI_CAPTCHA_DENIED_MESSAGE);
|
||||
messages.send(packetPlayer, MessageKey.GUI_CAPTCHA_RETRY_MESSAGE, String.valueOf(timesLeft));
|
||||
event.setCancelled(true);
|
||||
random_num.set(random_blockpos.nextInt(26));
|
||||
bukkitService.runTask(() -> {
|
||||
menu.clear();
|
||||
menu.setItem(random_num.get(), item);
|
||||
packetPlayer.openInventory(menu);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
initializePacketListeners();
|
||||
//Open captcha inventory
|
||||
menu.setItem(random_num.get(), item);
|
||||
playerunreg.openInventory(menu);
|
||||
if (settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT) > 0) {
|
||||
long timeOut = settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT);
|
||||
if (settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT) > settings.getProperty(RestrictionSettings.TIMEOUT)) {
|
||||
bukkitService.runTask(() -> {
|
||||
getLogger().warning("AuthMe detected that your GUI captcha timeout seconds(" + settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT) + ") is bigger than the Login timeout seconds(" +
|
||||
settings.getProperty(RestrictionSettings.TIMEOUT) + "). To prevent issues, we will let the GUI captcha follow the Login timeout seconds, please check and modify your config.");
|
||||
});
|
||||
timeOut = settings.getProperty(RestrictionSettings.TIMEOUT);
|
||||
}
|
||||
long finalTimeOut = timeOut;
|
||||
bukkitService.runTaskLater(() -> {
|
||||
if (!closeReasonMap.containsKey(playerunreg) && !authmeApi.isRegistered(playerunreg.getName())) {
|
||||
playerunreg.kickPlayer(service.retrieveSingleMessage(playerunreg, MessageKey.GUI_CAPTCHA_KICK_TIMEOUT));
|
||||
timesLeft = 3; // Reset the attempt counter
|
||||
}
|
||||
}, finalTimeOut * 20L);
|
||||
}
|
||||
});
|
||||
};
|
||||
chatPacketListener = new PacketAdapter(this.plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CHAT) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
Player packetPlayer = event.getPlayer();
|
||||
if (!closeReasonMap.containsKey(packetPlayer) && !authmeApi.isRegistered(packetPlayer.getName())) {
|
||||
messages.send(packetPlayer, MessageKey.GUI_CAPTCHA_DENIED_MESSAGE);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
initializePacketListeners();
|
||||
//Open captcha inventory
|
||||
menu.setItem(random_num.get(), item);
|
||||
playerunreg.openInventory(menu);
|
||||
if (settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT) > 0) {
|
||||
long timeOut = settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT);
|
||||
if (settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT) > settings.getProperty(RestrictionSettings.TIMEOUT)) {
|
||||
bukkitService.runTask(() -> {
|
||||
getLogger().warning("AuthMe detected that your GUI captcha timeout seconds(" + settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT) + ") is bigger than the Login timeout seconds(" +
|
||||
settings.getProperty(RestrictionSettings.TIMEOUT) + "). To prevent issues, we will let the GUI captcha follow the Login timeout seconds, please check and modify your config.");
|
||||
});
|
||||
timeOut = settings.getProperty(RestrictionSettings.TIMEOUT);
|
||||
}
|
||||
long finalTimeOut = timeOut;
|
||||
bukkitService.runTaskLater(() -> {
|
||||
if (!closeReasonMap.containsKey(playerunreg) && !authmeApi.isRegistered(playerunreg.getName())) {
|
||||
playerunreg.kickPlayer(service.retrieveSingleMessage(playerunreg, MessageKey.GUI_CAPTCHA_KICK_TIMEOUT));
|
||||
timesLeft = 3; // Reset the attempt counter
|
||||
}
|
||||
}, finalTimeOut * 20L);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,11 +35,7 @@ public class LoginLocationFixListener implements Listener {
|
||||
|
||||
private static Material materialPortal = Material.matchMaterial("PORTAL");
|
||||
|
||||
private boolean isChecked = false;
|
||||
private boolean isGetMinHeight = false;
|
||||
private final boolean isSmartAsyncTeleport = AuthMe.settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT);
|
||||
private final boolean isFixPortalStuck = AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_PORTAL);
|
||||
private final boolean isFixGroundStuck = AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_UNDERGROUND);
|
||||
private static boolean isAvailable; // false: unchecked/method not available true: method is available
|
||||
BlockFace[] faces = {BlockFace.WEST, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.SOUTH_EAST, BlockFace.SOUTH_WEST, BlockFace.NORTH_EAST, BlockFace.NORTH_WEST};
|
||||
|
||||
static {
|
||||
@@ -49,24 +45,19 @@ public class LoginLocationFixListener implements Listener {
|
||||
materialPortal = Material.matchMaterial("NETHER_PORTAL");
|
||||
}
|
||||
}
|
||||
try {
|
||||
Method getMinHeightMethod = World.class.getMethod("getMinHeight");
|
||||
isAvailable = true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
isAvailable = false;
|
||||
}
|
||||
}
|
||||
|
||||
private int getMinHeight(World world) {
|
||||
//This keeps compatibility of 1.16.x and lower
|
||||
try {
|
||||
if (!isChecked) {
|
||||
Method getMinHeightMethod = World.class.getMethod("getMinHeight");
|
||||
getMinHeightMethod.setAccessible(true);
|
||||
isChecked = true;
|
||||
isGetMinHeight = true;
|
||||
return world.getMinHeight();
|
||||
} else if (isGetMinHeight) {
|
||||
return world.getMinHeight();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
isChecked = true;
|
||||
if (isAvailable) {
|
||||
return world.getMinHeight();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -76,7 +67,7 @@ public class LoginLocationFixListener implements Listener {
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Location JoinLocation = player.getLocation();
|
||||
if (isFixPortalStuck) {
|
||||
if (settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_PORTAL)) {
|
||||
if (!JoinLocation.getBlock().getType().equals(materialPortal) && !JoinLocation.getBlock().getRelative(BlockFace.UP).getType().equals(materialPortal)) {
|
||||
return;
|
||||
}
|
||||
@@ -84,7 +75,7 @@ public class LoginLocationFixListener implements Listener {
|
||||
boolean solved = false;
|
||||
for (BlockFace face : faces) {
|
||||
if (JoinBlock.getRelative(face).getType().equals(Material.AIR) && JoinBlock.getRelative(face).getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
|
||||
if (isSmartAsyncTeleport) {
|
||||
if (settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) {
|
||||
TeleportUtils.teleport(player, JoinBlock.getRelative(face).getLocation().add(0.5, 0.1, 0.5));
|
||||
} else {
|
||||
player.teleport(JoinBlock.getRelative(face).getLocation().add(0.5, 0.1, 0.5));
|
||||
@@ -99,14 +90,15 @@ public class LoginLocationFixListener implements Listener {
|
||||
}
|
||||
messages.send(player, MessageKey.LOCATION_FIX_PORTAL);
|
||||
}
|
||||
if (isFixGroundStuck) {
|
||||
if (settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_UNDERGROUND)) {
|
||||
Material UpType = JoinLocation.getBlock().getRelative(BlockFace.UP).getType();
|
||||
World world = player.getWorld();
|
||||
int MaxHeight = world.getMaxHeight();
|
||||
int MinHeight = getMinHeight(world);
|
||||
if (!UpType.isOccluding() && !UpType.equals(Material.LAVA)) {
|
||||
return;
|
||||
}
|
||||
for (int i = getMinHeight(world); i <= MaxHeight; i++) {
|
||||
for (int i = MinHeight; i <= MaxHeight; i++) {
|
||||
JoinLocation.setY(i);
|
||||
Block JoinBlock = JoinLocation.getBlock();
|
||||
if ((JoinBlock.getRelative(BlockFace.DOWN).getType().isBlock())
|
||||
@@ -115,7 +107,7 @@ public class LoginLocationFixListener implements Listener {
|
||||
if (JoinBlock.getRelative(BlockFace.DOWN).getType().equals(Material.LAVA)) {
|
||||
JoinBlock.getRelative(BlockFace.DOWN).setType(Material.DIRT);
|
||||
}
|
||||
if (isSmartAsyncTeleport) {
|
||||
if (settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) {
|
||||
TeleportUtils.teleport(player, JoinBlock.getLocation().add(0.5, 0.1, 0.5));
|
||||
} else {
|
||||
player.teleport(JoinBlock.getLocation().add(0.5, 0.1, 0.5));
|
||||
@@ -124,7 +116,7 @@ public class LoginLocationFixListener implements Listener {
|
||||
break;
|
||||
}
|
||||
if (i == MaxHeight) {
|
||||
if (isSmartAsyncTeleport) {
|
||||
if (settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) {
|
||||
TeleportUtils.teleport(player, JoinBlock.getLocation().add(0.5, 1.1, 0.5));
|
||||
} else {
|
||||
player.teleport(JoinBlock.getLocation().add(0.5, 1.1, 0.5));
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.listener;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.api.v3.AuthMeApi;
|
||||
import fr.xephi.authme.data.QuickCommandsProtectionManager;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
@@ -22,7 +21,6 @@ import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.util.TeleportUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
@@ -32,7 +30,6 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
//import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
@@ -54,17 +51,15 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerShearEntityEvent;
|
||||
//import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
|
||||
import static org.bukkit.Bukkit.getServer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOWED_MOVEMENT_RADIUS;
|
||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT;
|
||||
import static org.bukkit.Bukkit.getServer;
|
||||
|
||||
/**
|
||||
* Listener class for player events.
|
||||
|
||||
@@ -29,12 +29,8 @@ public class PlayerListenerHigherThan18 implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onSwitchHand(PlayerSwapHandItemsEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if ((!player.isSneaking() || !player.hasPermission("keybindings.use")) &&
|
||||
settings.getProperty(PluginSettings.MENU_UNREGISTER_COMPATIBILITY)) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
if (settings.getProperty(PluginSettings.MENU_UNREGISTER_COMPATIBILITY)) {
|
||||
if (player.isSneaking() && player.hasPermission("keybindings.use") && settings.getProperty(PluginSettings.MENU_UNREGISTER_COMPATIBILITY)) {
|
||||
event.setCancelled(true);
|
||||
Bukkit.dispatchCommand(event.getPlayer(), "help");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -94,6 +94,9 @@ public class BackupService {
|
||||
case SQLITE:
|
||||
String dbName = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
|
||||
return performFileBackup(dbName + ".db");
|
||||
case H2:
|
||||
String h2dbName = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
|
||||
return performFileBackup(h2dbName + ".mv.db");
|
||||
default:
|
||||
logger.warning("Unknown data source type '" + dataSourceType + "' for backup");
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class BukkitService implements SettingsDependent {
|
||||
* <p>
|
||||
* This task will be executed by the main server thread.
|
||||
*
|
||||
* @param task Task to be executed
|
||||
* @param task Task to be executed
|
||||
* @param delay Delay in server ticks before executing task
|
||||
* @return Task id number (-1 if scheduling failed)
|
||||
*/
|
||||
@@ -98,7 +98,7 @@ public class BukkitService implements SettingsDependent {
|
||||
* Returns a task that will run after the specified number of server
|
||||
* ticks.
|
||||
*
|
||||
* @param task the task to be run
|
||||
* @param task the task to be run
|
||||
* @param delay the ticks to wait before running the task
|
||||
* @return a BukkitTask that contains the id number
|
||||
* @throws IllegalArgumentException if plugin is null
|
||||
@@ -160,12 +160,12 @@ public class BukkitService implements SettingsDependent {
|
||||
* Schedules the given task to repeatedly run until cancelled, starting after the
|
||||
* specified number of server ticks.
|
||||
*
|
||||
* @param task the task to schedule
|
||||
* @param delay the ticks to wait before running the task
|
||||
* @param task the task to schedule
|
||||
* @param delay the ticks to wait before running the task
|
||||
* @param period the ticks to wait between runs
|
||||
* @return a BukkitTask that contains the id number
|
||||
* @throws IllegalArgumentException if plugin is null
|
||||
* @throws IllegalStateException if this was already scheduled
|
||||
* @throws IllegalStateException if this was already scheduled
|
||||
*/
|
||||
public BukkitTask runTaskTimer(BukkitRunnable task, long delay, long period) {
|
||||
return task.runTaskTimer(authMe, delay, period);
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package fr.xephi.authme.service;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.google.common.hash.HashFunction;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.maxmind.db.GeoIp2Provider;
|
||||
import com.maxmind.db.Reader;
|
||||
import com.maxmind.db.Reader.FileMode;
|
||||
@@ -13,32 +10,16 @@ import com.maxmind.db.model.CountryResponse;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||
import fr.xephi.authme.util.FileUtils;
|
||||
import fr.xephi.authme.util.InternetProtocolUtils;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Base64;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class GeoIpService {
|
||||
|
||||
|
||||
@@ -22,19 +22,16 @@ import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import java.io.DataInputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static fr.xephi.authme.util.StringUtils.isInsideString;
|
||||
|
||||
@@ -10,7 +10,7 @@ import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
||||
public final class DatabaseSettings implements SettingsHolder {
|
||||
|
||||
@Comment({"What type of database do you want to use?",
|
||||
"Valid values: SQLITE, MARIADB, MYSQL, POSTGRESQL"})
|
||||
"Valid values: H2, SQLITE, MARIADB, MYSQL, POSTGRESQL"})
|
||||
public static final Property<DataSourceType> BACKEND =
|
||||
newProperty(DataSourceType.class, "DataSource.backend", DataSourceType.SQLITE);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ public final class PluginSettings implements SettingsHolder {
|
||||
"If you are using TrMenu, don't enable this because TrMenu already implemented this."
|
||||
})
|
||||
public static final Property<Boolean> MENU_UNREGISTER_COMPATIBILITY =
|
||||
newProperty("3rdPartyFeature.compatibility.menuPlugins", true);
|
||||
newProperty("3rdPartyFeature.compatibility.menuPlugins", false);
|
||||
|
||||
@Comment({
|
||||
"Do you want to enable the session feature?",
|
||||
|
||||
@@ -4,8 +4,6 @@ import ch.jalu.configme.Comment;
|
||||
import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -35,6 +35,11 @@ public final class SecuritySettings implements SettingsHolder {
|
||||
public static final Property<Boolean> ANTI_GHOST_PLAYERS =
|
||||
newProperty("3rdPartyFeature.fixes.antiGhostPlayer", false);
|
||||
|
||||
@Comment({"(MC1.13- only)",
|
||||
"Should we fix the shulker crash bug with advanced method?"})
|
||||
public static final Property<Boolean> ADVANCED_SHULKER_FIX =
|
||||
newProperty("3rdPartyFeature.fixes.advancedShulkerFix", false);
|
||||
|
||||
@Comment({"Choose the best teleport method by server brand?",
|
||||
"(Enable this if you are using Paper)"})
|
||||
public static final Property<Boolean> SMART_ASYNC_TELEPORT =
|
||||
@@ -95,10 +100,6 @@ public final class SecuritySettings implements SettingsHolder {
|
||||
public static final Property<Boolean> SHOW_STARTUP_BANNER =
|
||||
newProperty("Plugin.banners.showBanners", true);
|
||||
|
||||
@Comment("Change the banner colors here (Default: §r)")
|
||||
public static final Property<String> STARTUP_BANNER_COLOR =
|
||||
newProperty("Plugin.banners.bannerColor", "§r");
|
||||
|
||||
@Comment("Max allowed tries before a captcha is required")
|
||||
public static final Property<Integer> MAX_LOGIN_TRIES_BEFORE_CAPTCHA =
|
||||
newProperty("Security.captcha.maxLoginTry", 8);
|
||||
|
||||
@@ -28,7 +28,7 @@ public final class PlayerUtils {
|
||||
* @return True if the player is an NPC, false otherwise
|
||||
*/
|
||||
public static boolean isNpc(Player player) {
|
||||
return player.hasMetadata("NPC");
|
||||
return player.hasMetadata("NPC") || player.getAddress() == null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ authors: [${pluginDescription.authors}]
|
||||
website: http://github.com/HaHaWTH/AuthMeReReloaded/
|
||||
description: A fork of AuthMeReloaded that contains bug fixes
|
||||
main: ${pluginDescription.main}
|
||||
version: 5.6.0-FORK-b39
|
||||
version: 5.6.0-FORK-b41
|
||||
api-version: 1.13
|
||||
softdepend:
|
||||
- Vault
|
||||
|
||||
Reference in New Issue
Block a user