Skip to content

Commit

Permalink
Port to latest TwoConfig and merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Nov 21, 2024
1 parent 7a252c5 commit 32226bf
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 26 deletions.
7 changes: 3 additions & 4 deletions src/main/java/club/sk1er/patcher/Patcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.awt.*;
import java.io.*;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

@Mod(modid = "@ID@", name = "@NAME@", version = Patcher.VERSION, clientSideOnly = true)
@Mod(modid = "@MOD_ID@", name = "@MOD_NAME@", version = Patcher.VERSION, clientSideOnly = true)
public class Patcher {

@Mod.Instance("patcher")
Expand All @@ -77,7 +76,7 @@ public class Patcher {
// extra branches will be 1.x.x+branch-y
public static final String VERSION = "@VER@";

private final Logger logger = LogManager.getLogger("Patcher");
private static final Logger logger = LogManager.getLogger("Patcher");
private final File logsDirectory = new File(Minecraft.getMinecraft().mcDataDir + File.separator + "logs" + File.separator);

/**
Expand Down Expand Up @@ -421,7 +420,7 @@ public PatcherSoundConfig getPatcherSoundConfig() {
return patcherSoundConfig;
}

public Logger getLogger() {
public static Logger getLogger() {
return logger;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/club/sk1er/patcher/config/PatcherConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,7 @@ public PatcherConfig() {
// try {
// FileUtils.writeStringToFile(ConfigUtils.getProfileFile("patcher-not-migrated.json"), FileUtils.readFileToString(ConfigUtils.getProfileFile("patcher.json"), StandardCharsets.UTF_8), StandardCharsets.UTF_8);
// } catch (IOException e) {
// Patcher.instance.getLogger().error("Failed to copy over Patcher config before migration.", e);
// Patcher.getLogger().error("Failed to copy over Patcher config before migration.", e);
// }
// save();
//}
Expand Down Expand Up @@ -2019,7 +2019,7 @@ public PatcherConfig() {

//hideIf("keyboardLayout", () -> !SystemUtils.IS_OS_LINUX);
} catch (Exception e) {
Patcher.instance.getLogger().error("Failed to access property.", e);
Patcher.getLogger().error("Failed to access property.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class PatcherSoundConfig
// try {
// dummyField = getClass().getDeclaredField("dummyBooleanForMigratorDONTTOUCH");
// } catch (Exception e) {
// Patcher.instance.getLogger().error("Failed to get dummy field for migrator, this is a bug!", e);
// Patcher.getLogger().error("Failed to get dummy field for migrator, this is a bug!", e);
// }
// try {
// for (Map.Entry<ResourceLocation, SoundEventAccessorComposite> entry : soundRegistry.entrySet()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/club/sk1er/patcher/hooks/FontRendererHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void establishSize() {
try (final InputStream stream = mc.getResourceManager().getResource(fontRendererAccessor.getLocationFontTexture()).getInputStream()) {
specWidth = ImageIO.read(stream).getWidth();
} catch (IOException e) {
Patcher.instance.getLogger().error("Failed to read font texture while establishing size.", e);
Patcher.getLogger().error("Failed to read font texture while establishing size.", e);
}

regularCharDim = specWidth;
Expand Down Expand Up @@ -98,7 +98,7 @@ public void create() {
try (final InputStream stream = mc.getResourceManager().getResource(fontRendererAccessor.getLocationFontTexture()).getInputStream()) {
bufferedImage.getGraphics().drawImage(ImageIO.read(stream), 0, 16 * texSheetDim, null);
} catch (IOException e) {
Patcher.instance.getLogger().error("Failed to draw texture sheet.", e);
Patcher.getLogger().error("Failed to draw texture sheet.", e);
}

glTextureId = new DynamicTexture(bufferedImage).getGlTextureId();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/club/sk1er/patcher/hooks/MinecraftHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static boolean fullscreen() {
Display.setResizable(true);
return true;
} catch (LWJGLException e) {
Patcher.instance.getLogger().error("Failed to toggle fullscreen.", e);
Patcher.getLogger().error("Failed to toggle fullscreen.", e);
}
return false;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public void fix(boolean fullscreen) {

Display.setResizable(!fullscreen);
} catch (LWJGLException e) {
Patcher.instance.getLogger().error("Failed to update screen type.", e);
Patcher.getLogger().error("Failed to update screen type.", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static boolean validateResourcePackUrl(S48PacketResourcePackSend packet)
url = URLDecoder.decode(url.substring("level://".length()), StandardCharsets.UTF_8.toString());

if (isLevelProtocol && (url.contains("..") || !url.endsWith("/resources.zip"))) {
Patcher.instance.getLogger().warn("Malicious server tried to access {}", url);
Patcher.getLogger().warn("Malicious server tried to access {}", url);
if (Minecraft.getMinecraft().thePlayer != null) {
ChatUtilities.sendNotification("Patcher", "&c&lThe current server has attempted to be malicious but we have stopped them.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void reloadOptiFineLanguage() {
return;
} catch (Exception e) {
if (Patcher.instance != null) {
Patcher.instance.getLogger().error("Failed to reload OptiFine language. If this is causing issues, please report this to https://polyfrost.org/discord", e);
Patcher.getLogger().error("Failed to reload OptiFine language. If this is causing issues, please report this to https://polyfrost.org/discord", e);
}
return;
}
Expand All @@ -46,7 +46,7 @@ public static void reloadOptiFineLanguage() {
langMethod.invoke(null);
} catch (Exception e) {
if (Patcher.instance != null) {
Patcher.instance.getLogger().error("Failed to reload OptiFine language. If this is causing issues, please report this to https://polyfrost.org/discord", e);
Patcher.getLogger().error("Failed to reload OptiFine language. If this is causing issues, please report this to https://polyfrost.org/discord", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class ServerListEntryNormalMixin_ResolveCrash {
try {
prepareServerIcon();
} catch (Exception e) {
Patcher.instance.getLogger().error("Failed to prepare server icon, setting to default.", e);
Patcher.getLogger().error("Failed to prepare server icon, setting to default.", e);
server.setBase64EncodedIconData(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ModelLoader_SkipFirstBaking(IResourceManager p_i46085_1_, TextureMap p_i4
private void patcher$skipFirstBaking(CallbackInfoReturnable<IRegistry<ModelResourceLocation, IBakedModel>> cir) {
if (!patcher$firstLoad)
{
Patcher.instance.getLogger().info("Saved " + (System.currentTimeMillis() - patcher$lastTime) + "ms by skipping first model baking.");
Patcher.getLogger().info("Saved " + (System.currentTimeMillis() - patcher$lastTime) + "ms by skipping first model baking.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static int getTextColor(int index, int originalColor) {
return originalColor;
} catch (Throwable t) {
caughtError = true;
Patcher.instance.getLogger().error("Unable to get OptiFine's Custom Color", t);
Patcher.getLogger().error("Unable to get OptiFine's Custom Color", t);
return originalColor;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void handle(String value) {

if (!found) return;
} catch (MalformedURLException e) {
Patcher.instance.getLogger().error("Error during url lookup: " + value, e);
Patcher.getLogger().error("Error during url lookup: " + value, e);
return;
}
}
Expand Down Expand Up @@ -192,7 +192,7 @@ private void loadUrl(String url) {
image = TextureUtil.readBufferedImage(stream);
}
} catch (Exception e) {
Patcher.instance.getLogger().error("Failed to load an image preview from {}", url, e);
Patcher.getLogger().error("Failed to load an image preview from {}", url, e);
} finally {
if (connection != null) connection.disconnect();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void run() {
}
} catch (Exception e) {
ChatUtilities.sendNotification("Screenshot Manager", "Failed to capture screenshot. " + e.getMessage());
Patcher.instance.getLogger().error("Failed to capture screenshot.", e);
Patcher.getLogger().error("Failed to capture screenshot.", e);
}
}

Expand Down Expand Up @@ -261,7 +261,7 @@ public void main() {
copyScreenshot(true);
} catch (HeadlessException e) {
ChatUtilities.sendNotification("Screenshot Manager", "&cFailed to copy screenshot to clipboard.");
Patcher.instance.getLogger().error("Failed to copy screenshot to clipboard.", e);
Patcher.getLogger().error("Failed to copy screenshot to clipboard.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void watch() {
key.reset();
}
} catch (Exception e) {
Patcher.instance.getLogger().error("Failed to watch for new saves.", e);
Patcher.getLogger().error("Failed to watch for new saves.", e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private static int getQuery() {
try {
return GL15.glGenQueries();
} catch (Throwable throwable) {
Patcher.instance.getLogger().error(
Patcher.getLogger().error(
"Failed to run GL15.glGenQueries(). User's computer is likely too old to support OpenGL 1.5, Entity Culling has been force disabled.",
throwable
);
Expand All @@ -157,7 +157,7 @@ private static int getQuery() {
//try {
// UDesktop.browse(new URI("https://polyfrost.org/discord"));
//} catch (URISyntaxException e) {
// Patcher.instance.getLogger().error("Failed to open support discord.", e);
// Patcher.getLogger().error("Failed to open support discord.", e);
// ChatUtilities.sendMessage("Failed to open https://polyfrost.org/discord.");
//}
//todo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void initGui(GuiScreenEvent.InitGuiEvent.Post event) {
this.mc.getSoundHandler().onResourceManagerReload(this.mc.getResourceManager());
} catch (Exception e) {
Notifications.enqueue(Notifications.Type.Error, "Patcher", "Failed to reinitialize OpenAL.");
Patcher.instance.getLogger().error("Failed to reinitialize OpenAL.", e);
Patcher.getLogger().error("Failed to reinitialize OpenAL.", e);
}

this.changedDevice = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void createAL() throws LWJGLException {
AL.create();
}
} catch (Throwable e) {
Patcher.instance.getLogger().error("Failed to create device, using system default.", e);
Patcher.getLogger().error("Failed to create device, using system default.", e);
AL.destroy();
AL.create();
}
Expand Down

0 comments on commit 32226bf

Please sign in to comment.