From cf5a3953d9e704b6513d3b61022e945c4fcdd158 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 17 Apr 2020 14:14:49 +1200 Subject: [PATCH] Clean up file accesser --- .../me/libraryaddict/disguise/LibsDisguises.java | 5 +++++ .../disguise/utilities/DisguiseUtilities.java | 5 ++--- .../disguise/utilities/LibsPremium.java | 14 ++++++-------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java index d2e25dd8..4191d120 100644 --- a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -144,6 +144,11 @@ public class LibsDisguises extends JavaPlugin { new MetricsInitalizer(); } + @Override + public File getFile() { + return super.getFile(); + } + @Override public void onDisable() { DisguiseUtilities.saveDisguises(); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index fa5b4ef5..cc6ed739 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -940,9 +940,8 @@ public class DisguiseUtilities { cachedNames.addAll(Arrays.asList(profileCache.list())); - invalidFile = new File( - LibsDisguises.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getFile()) - .getName().toLowerCase().matches(".*((crack)|(null)|(leak)).*"); + invalidFile = LibsDisguises.getInstance().getFile().getName().toLowerCase() + .matches(".*((crack)|(null)|(leak)).*"); for (String key : savedDisguises.list()) { try { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java b/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java index 5012ad14..97a2f0ea 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java @@ -64,8 +64,8 @@ public class LibsPremium { * @param userID * @return true if userID does not contain __USER__ */ - private static Boolean isPremium(String userID) { - return !userID.contains("__USER__") && !getResourceID().equals("81"); + private static Boolean isPremium(String resourceID, String userID) { + return !userID.contains("__USER__") && !resourceID.equals("81"); } public static Boolean isAPIPlugin() { @@ -76,7 +76,7 @@ public class LibsPremium { * Returns true if this plugin is premium */ public static Boolean isPremium() { - return thisPluginIsPaidFor == null ? isPremium(getUserID()) : thisPluginIsPaidFor; + return thisPluginIsPaidFor == null ? isPremium(getResourceID(), getUserID()) : thisPluginIsPaidFor; } /** @@ -142,7 +142,7 @@ public class LibsPremium { userId = (String) c.getMethod("getUserID").invoke(null); resourceId = (String) c.getMethod("getResourceID").invoke(null); downloadId = (String) c.getMethod("getDownloadID").invoke(null); - premium = isPremium(userId); + premium = isPremium(resourceId, userId); } String pluginBuildDate = "??/??/????"; @@ -306,7 +306,7 @@ public class LibsPremium { } pluginInformation = new PluginInformation(getUserID(), getResourceID(), getDownloadID(), - isPremium(getUserID()), version, buildNo, pluginBuildDate); + isPremium(getResourceID(), getUserID()), version, buildNo, pluginBuildDate); } if (!isPremium() || !LibsDisguises.getInstance().isReleaseBuild()) { @@ -351,9 +351,7 @@ public class LibsPremium { } if (!foundBetter) { - File f = new File( - LibsDisguises.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation() - .getFile()); + File f = LibsDisguises.getInstance().getFile(); FileUtil.copy(f, new File(LibsDisguises.getInstance().getDataFolder(), f.getName()));