Skip to content

Commit

Permalink
🐛 Fix Runtime issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-MX committed Sep 18, 2024
1 parent d77670c commit f65c89f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
build
common/build
gameserver/build
proxy/build
proxy/build
run/
9 changes: 1 addition & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ tasks {
mergeServiceFiles()
}
runVelocity {
// velocityVersion(libs.versions.velocity.api.get())
velocityVersion(libs.versions.velocity.get())
}
// withType(xyz.jpenilla.runtask.task.AbstractRun::class) {
// javaLauncher.set(javaToolchains.launcherFor {
// languageVersion = JavaLanguageVersion.of(17)
// vendor = JvmVendorSpec.JETBRAINS
// })
// jvmArgs("-XX:+AllowEnhancedClassRedefinition", "-XX:+AllowRedefinitionToAddDeleteMethods")
// }
}
14 changes: 10 additions & 4 deletions src/main/java/com/mattmx/reconnect/ReconnectVelocity.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public ReconnectVelocity(@Nullable ProxyServer server, @Nullable Logger logger,
StorageManager.registerStorageMethod(new MariaDbStorage());
StorageManager.registerStorageMethod(new SQLiteStorage());
StorageManager.registerStorageMethod(new YamlStorage());
StorageManager.registerStorageMethod(new LuckPermsStorage());
if (proxy.getPluginManager().isLoaded("luckperms")) {
StorageManager.registerStorageMethod(new LuckPermsStorage());
}

ReconnectCommand.register(this);

loadStorage();

checker = new UpdateChecker();

if (checker.get("https://api.github.com/repos/Matt-MX/ReconnectVelocity/releases/latest")
Expand All @@ -82,9 +82,13 @@ public void loadStorage() {
Objects.requireNonNull(method, "That storage method is invalid!");

// Shutdown current manager
getStorageManager().end();
if (storage != null) {
storage.end();
}

storage = StorageManager.createStorageManager(method);

getLogger().info("Using {} as storage method!", storage.getStorageMethod().getId());
}

@SuppressWarnings({"ResultOfMethodCallIgnored"})
Expand Down Expand Up @@ -114,6 +118,8 @@ public void saveDefaultConfig() {

@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
loadStorage();

getProxy().getEventManager().register(this, new ReconnectListener(this));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mattmx.reconnect.storage;

import com.mattmx.reconnect.ReconnectCommand;
import com.mattmx.reconnect.ReconnectVelocity;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.model.user.User;
Expand All @@ -18,6 +19,7 @@ public void init() {
ReconnectVelocity.get().getLogger().warn("LuckPerms is not installed!");
exception.printStackTrace();
}
ReconnectVelocity.get().getLogger().info("LuckPerms found!");
}

@Override
Expand Down Expand Up @@ -55,6 +57,6 @@ public String getLastServer(String uuid) {

@Override
public String getMethod() {
return null;
return "luckperms";
}
}
23 changes: 8 additions & 15 deletions src/main/java/com/mattmx/reconnect/storage/StorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,31 @@

public class StorageManager {
private static final HashMap<String, StorageMethod> methods = new HashMap<>();
private @Nullable StorageMethod currentStorageMethod;
private final @NotNull StorageMethod currentStorageMethod;

public StorageManager(@NotNull StorageMethod method) {
this.currentStorageMethod = method;
}

public void init() {
Objects.requireNonNull(currentStorageMethod, "Storage not initialized! Can't call init until it is initialized.").init();
currentStorageMethod.init();
}

public void end() {
Objects.requireNonNull(currentStorageMethod, "Storage not initialized! Can't call end until it is initialized.").save();
currentStorageMethod.save();
}

public @NotNull StorageMethod getStorageMethod() {
if (this.currentStorageMethod == null) {
throw new RuntimeException("There has been no Storage Method set!");
}

return this.currentStorageMethod;
}

public void setCurrentStorageMethod(@NotNull StorageMethod currentStorageMethod) {
this.currentStorageMethod = currentStorageMethod;
}

public static void registerStorageMethod(@NotNull StorageMethod method) {
methods.put(method.getId(), method);
}

public static StorageManager createStorageManager(@NotNull StorageMethod method) {
StorageManager manager = new StorageManager();
manager.setCurrentStorageMethod(method);

StorageManager manager = new StorageManager(method);
manager.init();

return manager;
}

Expand Down

0 comments on commit f65c89f

Please sign in to comment.