2017-06-02 15:51:03 +02:00
|
|
|
package me.libraryaddict.disguise.utilities;
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
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.
|
|
|
|
*/
|
2017-06-08 17:09:28 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-03 13:18:11 +01:00
|
|
|
public static void check(String version) {
|
2017-06-02 15:51:03 +02:00
|
|
|
thisPluginIsPaidFor = isPremium();
|
|
|
|
|
2018-08-05 10:34:02 +02:00
|
|
|
if (!isPremium()) {
|
2017-06-08 17:06:58 +02:00
|
|
|
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;
|
|
|
|
|
2018-02-03 13:18:11 +01:00
|
|
|
try (URLClassLoader cl = new URLClassLoader(new URL[]{file.toURI().toURL()})) {
|
2017-06-08 17:09:28 +02:00
|
|
|
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;
|
|
|
|
|
2018-12-16 02:47:42 +01:00
|
|
|
YamlConfiguration config = ReflectionManager.getPluginYaml(cl);
|
2018-10-23 23:11:37 +02:00
|
|
|
|
2018-12-16 02:47:42 +01:00
|
|
|
pluginVersion = config.getString("version");
|
2017-06-02 15:51:03 +02:00
|
|
|
|
2018-02-15 22:51:15 +01: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!");
|
2018-02-15 22:51:15 +01:00
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
break;
|
2018-02-15 22:51:15 +01:00
|
|
|
} 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!
|
2018-09-13 08:56:46 +02:00
|
|
|
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!");
|
2018-02-15 22:51:15 +01:00
|
|
|
}
|
2017-06-02 15:51:03 +02:00
|
|
|
}
|
2018-12-19 03:10:15 +01: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) {
|
2018-12-19 03:10:15 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|