From d08aba15eefdd4d73804c864378efd31c8a66fa8 Mon Sep 17 00:00:00 2001 From: muhammadeko Date: Fri, 6 May 2022 07:42:40 +0700 Subject: [PATCH] Implement suggestion #4 and cleaning some import files --- build.gradle | 3 +- src/main/java/me/exzork/gcauth/GCAuth.java | 39 +++---------------- .../gcauth/handler/ChangePasswordHandler.java | 1 - .../handler/GCAuthAuthenticationHandler.java | 2 - .../exzork/gcauth/handler/LoginHandler.java | 1 - .../gcauth/handler/RegisterHandler.java | 1 - 6 files changed, 7 insertions(+), 40 deletions(-) diff --git a/build.gradle b/build.gradle index 5459942..29533d7 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ sourceCompatibility = 17 targetCompatibility = 17 group 'me.exzork.gcauth' -version '2.1.0' +version '2.1.2' repositories { mavenCentral() @@ -42,5 +42,4 @@ jar{ exclude("META-INF/NOTICE") } destinationDir = file(".") - } \ No newline at end of file diff --git a/src/main/java/me/exzork/gcauth/GCAuth.java b/src/main/java/me/exzork/gcauth/GCAuth.java index e901075..216df4d 100644 --- a/src/main/java/me/exzork/gcauth/GCAuth.java +++ b/src/main/java/me/exzork/gcauth/GCAuth.java @@ -3,23 +3,9 @@ package me.exzork.gcauth; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import emu.grasscutter.Grasscutter; -import emu.grasscutter.database.DatabaseHelper; -import emu.grasscutter.game.Account; import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass; import emu.grasscutter.plugin.Plugin; -import emu.grasscutter.server.dispatch.DispatchHttpJsonHandler; -import emu.grasscutter.server.dispatch.json.ComboTokenReqJson; -import emu.grasscutter.server.dispatch.json.ComboTokenResJson; -import emu.grasscutter.server.dispatch.json.LoginResultJson; -import emu.grasscutter.server.dispatch.json.LoginTokenRequestJson; -import emu.grasscutter.server.event.dispatch.QueryAllRegionsEvent; -import emu.grasscutter.server.event.dispatch.QueryCurrentRegionEvent; -import express.Express; import me.exzork.gcauth.handler.*; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.util.ssl.SslContextFactory; import java.io.File; import java.io.FileReader; @@ -30,10 +16,12 @@ import java.nio.file.Files; public class GCAuth extends Plugin { private static Config config; - private static final File configFile = new File(Grasscutter.getConfig().PLUGINS_FOLDER+"GCAuth/config.json"); + private File configFile; private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + @Override - public void onLoad() { + public void onEnable() { + configFile = new File(getDataFolder().toPath()+ "/config.json"); if (!configFile.exists()) { try { Files.createDirectories(configFile.toPath().getParent()); @@ -42,10 +30,6 @@ public class GCAuth extends Plugin { } } loadConfig(); - } - - @Override - public void onEnable() { if(Grasscutter.getDispatchServer().registerAuthHandler(new GCAuthAuthenticationHandler())) { Grasscutter.getLogger().info("[GCAuth] GCAuth Enabled!"); @@ -64,7 +48,7 @@ public class GCAuth extends Plugin { } } - public static void loadConfig() { + public void loadConfig() { try (FileReader file = new FileReader(configFile)) { config = gson.fromJson(file,Config.class); saveConfig(); @@ -74,23 +58,12 @@ public class GCAuth extends Plugin { } } - public static void saveConfig() { + public void saveConfig() { try (FileWriter file = new FileWriter(configFile)) { file.write(gson.toJson(config)); } catch (Exception e) { Grasscutter.getLogger().error("[GCAuth] Unable to save config file."); } } - - - public static class RegionData { - QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp parsedRegionQuery; - String Base64; - - public RegionData(QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp prq, String b64) { - this.parsedRegionQuery = prq; - this.Base64 = b64; - } - } public static Config getConfig() {return config;} } diff --git a/src/main/java/me/exzork/gcauth/handler/ChangePasswordHandler.java b/src/main/java/me/exzork/gcauth/handler/ChangePasswordHandler.java index 0da7621..20ffd43 100644 --- a/src/main/java/me/exzork/gcauth/handler/ChangePasswordHandler.java +++ b/src/main/java/me/exzork/gcauth/handler/ChangePasswordHandler.java @@ -6,7 +6,6 @@ import emu.grasscutter.game.Account; import express.http.HttpContextHandler; import express.http.Request; import express.http.Response; -import me.exzork.gcauth.GCAuth; import me.exzork.gcauth.json.AuthResponseJson; import me.exzork.gcauth.json.ChangePasswordAccount; import me.exzork.gcauth.utils.Authentication; diff --git a/src/main/java/me/exzork/gcauth/handler/GCAuthAuthenticationHandler.java b/src/main/java/me/exzork/gcauth/handler/GCAuthAuthenticationHandler.java index 926dfa2..af5497b 100644 --- a/src/main/java/me/exzork/gcauth/handler/GCAuthAuthenticationHandler.java +++ b/src/main/java/me/exzork/gcauth/handler/GCAuthAuthenticationHandler.java @@ -2,14 +2,12 @@ package me.exzork.gcauth.handler; import emu.grasscutter.Grasscutter; -import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.Account; import emu.grasscutter.server.dispatch.authentication.AuthenticationHandler; import emu.grasscutter.server.dispatch.json.LoginAccountRequestJson; import emu.grasscutter.server.dispatch.json.LoginResultJson; import express.http.Request; import express.http.Response; -import me.exzork.gcauth.GCAuth; import me.exzork.gcauth.utils.Authentication; import java.io.IOException; diff --git a/src/main/java/me/exzork/gcauth/handler/LoginHandler.java b/src/main/java/me/exzork/gcauth/handler/LoginHandler.java index fedee7e..5cf89bc 100644 --- a/src/main/java/me/exzork/gcauth/handler/LoginHandler.java +++ b/src/main/java/me/exzork/gcauth/handler/LoginHandler.java @@ -6,7 +6,6 @@ import emu.grasscutter.game.Account; import express.http.HttpContextHandler; import express.http.Request; import express.http.Response; -import me.exzork.gcauth.GCAuth; import me.exzork.gcauth.json.AuthResponseJson; import me.exzork.gcauth.json.LoginGenerateToken; import me.exzork.gcauth.utils.Authentication; diff --git a/src/main/java/me/exzork/gcauth/handler/RegisterHandler.java b/src/main/java/me/exzork/gcauth/handler/RegisterHandler.java index dee818b..39e6a04 100644 --- a/src/main/java/me/exzork/gcauth/handler/RegisterHandler.java +++ b/src/main/java/me/exzork/gcauth/handler/RegisterHandler.java @@ -7,7 +7,6 @@ import emu.grasscutter.game.Account; import express.http.HttpContextHandler; import express.http.Request; import express.http.Response; -import me.exzork.gcauth.GCAuth; import me.exzork.gcauth.json.AuthResponseJson; import me.exzork.gcauth.json.RegisterAccount; import me.exzork.gcauth.utils.Authentication;