LibsDisguises/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java

56 lines
1.7 KiB
Java
Raw Normal View History

2017-06-02 15:51:03 +02:00
package me.libraryaddict.disguise.utilities;
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
/**
* Created by libraryaddict on 2/06/2017.
*/
public class LibsPremium {
2017-06-02 15:51:03 +02:00
private static Boolean thisPluginIsPaidFor;
public static Boolean isPremium() {
return thisPluginIsPaidFor == null ? !"%%__USER__%%".contains("__USER__") : thisPluginIsPaidFor;
}
public static void check(String version) {
2017-06-02 15:51:03 +02:00
thisPluginIsPaidFor = isPremium();
if (!isPremium()) {
File[] files = new File("plugins/LibsDisguises/").listFiles();
if (files == null)
return;
for (File file : files) {
2017-06-02 15:51:03 +02:00
if (!file.isFile())
continue;
if (!file.getName().endsWith(".jar"))
continue;
try (URLClassLoader cl = new URLClassLoader(new URL[]{file.toURI().toURL()})) {
Class c = cl.loadClass(LibsPremium.class.getName());
2017-06-02 15:51:03 +02:00
Method m = c.getMethod("isPremium");
thisPluginIsPaidFor = (Boolean) m.invoke(null);
if (isPremium()) {
DisguiseUtilities.getLogger().info("Found a premium Lib's Disguises jar, premium enabled!");
2017-06-02 15:51:03 +02:00
break;
} else {
DisguiseUtilities.getLogger().warning(
"You have a non-premium Lib's Disguises jar (" + file.getName() + ") in the folder!");
}
2017-06-02 15:51:03 +02:00
}
catch (Exception ex) {
// Don't print off errors
}
}
}
}
}