Skip to content

Commit

Permalink
Guard logging code because of paper changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgH93 committed Feb 26, 2023
1 parent 1f37748 commit c847a74
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;

@SuppressWarnings({ "UnstableApiUsage", "unused" })
Expand Down Expand Up @@ -82,7 +81,15 @@ private boolean patchPluginMeta(final @NotNull PluginProviderContext context)
}
catch(Exception e)
{
context.getLogger().log(Level.SEVERE, "Failed to patch main class in PluginMeta! Falling back to Standalone mode!", e);
try
{
context.getLogger().error("Failed to patch main class in PluginMeta! Falling back to Standalone mode!", e);
}
catch(Throwable ignored)
{
System.out.println("[MarriageMaster] Failed to patch main class in PluginMeta! Falling back to Standalone mode!");
e.printStackTrace();
}
}
return false;
}
Expand All @@ -94,21 +101,34 @@ private boolean checkPcgfPluginLib(final @NotNull PluginProviderContext context)
{
if (new Version(version).olderThan(new Version(MagicValues.MIN_PCGF_PLUGIN_LIB_VERSION)))
{
context.getLogger().info("PCGF-PluginLib to old! Switching to standalone mode!");
logInfo("PCGF-PluginLib to old! Switching to standalone mode!", context);
}
else
{
context.getLogger().info("PCGF-PluginLib installed. Switching to normal mode!");
logInfo("PCGF-PluginLib installed. Switching to normal mode!", context);
return true;
}
}
else
{
context.getLogger().info("PCGF-PluginLib not installed. Switching to standalone mode!");
logInfo("PCGF-PluginLib not installed. Switching to standalone mode!", context);
}
return false;
}

//TODO remove this stupid code once the paper API stabilizes to a point where once can expect at least the logger class ot not randomly change
private void logInfo(final @NotNull String message, final @NotNull PluginProviderContext context)
{
try
{
context.getLogger().info(message);
}
catch(Throwable t)
{
System.out.println("[Minepacks] Failed to log message: " + message);
}
}

@Override
@SneakyThrows
public void classloader(@NotNull PluginClasspathBuilder pluginClasspathBuilder)
Expand All @@ -118,7 +138,7 @@ public void classloader(@NotNull PluginClasspathBuilder pluginClasspathBuilder)
File tempJarFile = File.createTempFile("IMessage", ".jar");
Class<?> utilsClass = Class.forName("at.pcgamingfreaks.MarriageMasterStandalone.libs.at.pcgamingfreaks.Utils");
Method extractMethod = utilsClass.getDeclaredMethod("extractFile", Class.class, Logger.class, String.class, File.class);
extractMethod.invoke(null, this.getClass(), pluginClasspathBuilder.getContext().getLogger(), "IMessage.jar", tempJarFile);
extractMethod.invoke(null, this.getClass(), Logger.getLogger(getClass().getSimpleName()), "IMessage.jar", tempJarFile);
pluginClasspathBuilder.addLibrary(new JarLibrary(tempJarFile.toPath()));
tempJarFile.deleteOnExit();
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<packaging>pom</packaging>

<properties>
<revision>2.6.9</revision>
<revision>2.6.10</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<bukkitVersion>1.15.2-R0.1-SNAPSHOT</bukkitVersion>
Expand Down

0 comments on commit c847a74

Please sign in to comment.