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

74 lines
2.7 KiB
Java
Raw Normal View History

2017-06-02 15:51:03 +02:00
package me.libraryaddict.disguise.utilities;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
2018-10-23 23:11:37 +02:00
import org.bukkit.configuration.file.YamlConfiguration;
2017-06-02 15:51:03 +02:00
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);
2018-10-23 23:11:37 +02:00
String pluginVersion;
YamlConfiguration config = ReflectionManager.getPluginYaml(cl);
2018-10-23 23:11:37 +02:00
pluginVersion = config.getString("version");
2017-06-02 15:51:03 +02:00
if (isPremium()) {
2018-10-23 23:11:37 +02:00
// Found a premium Lib's Disguises jar (v5.2.6), premium enabled!
DisguiseUtilities.getLogger()
.info("Found a premium Lib's Disguises jar (v" + pluginVersion + "), premium enabled!");
2017-06-02 15:51:03 +02:00
break;
} else {
2018-10-23 23:11:37 +02:00
// You have a non-premium Lib's Disguises jar (LibsDisguises.jar v5.2.6) in the folder!
DisguiseUtilities.getLogger().warning(
2018-10-23 23:11:37 +02:00
"You have a non-premium Lib's Disguises jar (" + file.getName() + " v" + pluginVersion +
") in the folder!");
}
2017-06-02 15:51:03 +02:00
}
catch (ClassNotFoundException ex) {
DisguiseUtilities.getLogger()
.warning("Found an unrecognized jar in the LibsDisguises folder (" + file.getName() + ")");
}
2017-06-02 15:51:03 +02:00
catch (Exception ex) {
DisguiseUtilities.getLogger().warning("Error while trying to handle the file " + file.getName());
2018-10-23 23:11:37 +02:00
ex.printStackTrace();
2017-06-02 15:51:03 +02:00
// Don't print off errors
}
}
}
}
}