diff --git a/DiscordRPC_lmodule/src/main/java/pro/gravit/launchermodules/discordrpc/ClientModule.java b/DiscordRPC_lmodule/src/main/java/pro/gravit/launchermodules/discordrpc/ClientModule.java index 2399385c..d2c84ce1 100644 --- a/DiscordRPC_lmodule/src/main/java/pro/gravit/launchermodules/discordrpc/ClientModule.java +++ b/DiscordRPC_lmodule/src/main/java/pro/gravit/launchermodules/discordrpc/ClientModule.java @@ -71,25 +71,37 @@ private void launcherInit(ClientEngineInitPhase phase) } private void exitHandler(ClientExitPhase phase) { - if(isClosed) return; - isClosed = true; + if (isClosed(true)) return; if(DiscordRPC.thr != null) DiscordRPC.thr.interrupt(); if(DiscordRPC.lib != null) DiscordRPC.lib.Discord_Shutdown(); if(RequestEventWatcher.INSTANCE != null) Request.service.unregisterEventHandler(RequestEventWatcher.INSTANCE); } - public static boolean isClosed = false; + private static final Object lock = new Object(); + private static volatile boolean isClosed = false; private void exitByStartClient(ClientProcessBuilderParamsWrittedEvent event) { - if(isClosed) return; + if (isClosed(true)) return; try { - isClosed = true; if(DiscordRPC.thr != null) DiscordRPC.thr.interrupt(); if(DiscordRPC.lib != null) DiscordRPC.lib.Discord_Shutdown(); if(RequestEventWatcher.INSTANCE != null) Request.service.unregisterEventHandler(RequestEventWatcher.INSTANCE); } catch (Throwable ignored) { + } + } + /** + * @param flag Set closed to true? + * @return Current closed. + */ + public static boolean isClosed(boolean flag) { + boolean ret; + synchronized(lock) { + ret = isClosed; + if (flag) isClosed = true; + lock.notify(); } + return ret; } public static void main(String[] args) { diff --git a/DiscordRPC_lmodule/src/main/java/pro/gravit/launchermodules/discordrpc/DiscordRPC.java b/DiscordRPC_lmodule/src/main/java/pro/gravit/launchermodules/discordrpc/DiscordRPC.java index 7bc91c42..0d460edc 100644 --- a/DiscordRPC_lmodule/src/main/java/pro/gravit/launchermodules/discordrpc/DiscordRPC.java +++ b/DiscordRPC_lmodule/src/main/java/pro/gravit/launchermodules/discordrpc/DiscordRPC.java @@ -45,7 +45,7 @@ static void onConfig(String appId, String firstLine, String secondLine, String l break; } } - if(!ClientModule.isClosed) + if(!ClientModule.isClosed(false)) lib.Discord_Shutdown(); }, "RPC"); thr.setDaemon(true); diff --git a/LegacySupport_module/src/main/java/pro/gravit/launchermodules/legacysupport/MojangTextureProvider.java b/LegacySupport_module/src/main/java/pro/gravit/launchermodules/legacysupport/MojangTextureProvider.java index 73dcd17b..b0c465e0 100644 --- a/LegacySupport_module/src/main/java/pro/gravit/launchermodules/legacysupport/MojangTextureProvider.java +++ b/LegacySupport_module/src/main/java/pro/gravit/launchermodules/legacysupport/MojangTextureProvider.java @@ -77,9 +77,7 @@ private CacheData getCached(UUID uuid, String username) { JsonObject property0 = property.getAsJsonObject(); if (property0.get("name").getAsString().equals("textures")) { byte[] asBytes = Base64.getDecoder().decode(property0.get("value").getAsString()); - String asString = new String(asBytes, StandardCharsets.UTF_8); - JsonParser parser = new JsonParser(); - texturesProperty = parser.parse(asString).getAsJsonObject(); + texturesProperty = JsonParser.parseString(new String(asBytes, StandardCharsets.UTF_8)).getAsJsonObject(); break; } }