Skip to content

Commit

Permalink
simpler mysql fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mdxd44 committed Jan 1, 2024
1 parent 6638ba4 commit f18b928
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions src/main/java/net/elytrium/limboauth/LimboAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.dao.GenericRawResults;
import com.j256.ormlite.db.DatabaseType;
import com.j256.ormlite.field.DatabaseFieldConfig;
import com.j256.ormlite.field.FieldType;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.UpdateBuilder;
Expand Down Expand Up @@ -55,9 +54,6 @@
import io.whitfin.siphash.SipHasher;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -82,7 +78,6 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -326,33 +321,18 @@ public void reload() {
this.nicknameValidationPattern = Pattern.compile(Settings.IMP.MAIN.ALLOWED_NICKNAME_REGEX);

try {
this.playerDao = DaoManager.createDao(this.connectionSource, RegisteredPlayer.class);

// fuck ormlite
if (!this.connectionSource.getDatabaseType().isCreateIndexIfNotExistsSupported()) {
Field fieldConfigField = FieldType.class.getDeclaredField("fieldConfig");
fieldConfigField.setAccessible(true);
for (FieldType fieldType : this.playerDao.getTableInfo().getFieldTypes()) {
if (fieldType.getIndexName() != null) {
((DatabaseFieldConfig) fieldConfigField.get(fieldType)).setIndex(false);
}
try {
TableUtils.createTableIfNotExists(this.connectionSource, RegisteredPlayer.class);
} catch (SQLException e) {
if (!e.getMessage().contains("CREATE INDEX")) {
throw e;
}
}

Method doCreateTable = TableUtils.class.getDeclaredMethod("doCreateTable", Dao.class, boolean.class);
doCreateTable.setAccessible(true);
doCreateTable.invoke(null, this.playerDao, true);

Matcher format = Pattern.compile("%s")
.matcher("declare continue handler for sqlstate '42000' begin end; create index `AUTH_%s_idx` on `AUTH`(`%s`);");
this.playerDao.executeRawNoArgs(format.replaceAll(RegisteredPlayer.PREMIUM_UUID_FIELD));
this.playerDao.executeRawNoArgs(format.replaceAll(RegisteredPlayer.IP_FIELD));

this.playerDao = DaoManager.createDao(this.connectionSource, RegisteredPlayer.class);
this.migrateDb(this.playerDao);
} catch (SQLException e) {
throw new SQLRuntimeException(e);
} catch (NoSuchFieldException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
throw new ReflectionException(e);
}

CommandManager manager = this.server.getCommandManager();
Expand Down

0 comments on commit f18b928

Please sign in to comment.