Automagically copy and delete premium jars in the LibsDisguises folder
This commit is contained in:
@@ -7,6 +7,7 @@ import me.libraryaddict.disguise.utilities.plugin.PluginInformation;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.util.FileUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
@@ -312,6 +313,53 @@ public class LibsPremium {
|
||||
doSecondaryCheck(version);
|
||||
} else {
|
||||
DisguiseUtilities.getLogger().info("Registered to: " + getSanitizedUser(getUserID()));
|
||||
|
||||
boolean foundBetter = false;
|
||||
|
||||
// Lets not do any sanity checks since it won't affect legit users
|
||||
for (File f : LibsDisguises.getInstance().getDataFolder().listFiles()) {
|
||||
if (f.isDirectory() || !f.getName().endsWith(".jar")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
PluginInformation info = getInformation(f);
|
||||
|
||||
if (info.getBuildNumber() == null || !info.getBuildNumber().matches("[0-9]+")) {
|
||||
f.delete();
|
||||
DisguiseUtilities.getLogger().info("Ew, I don't recognize " + f.getName());
|
||||
continue;
|
||||
} else if (Integer.parseInt(info.getBuildNumber()) <
|
||||
Integer.parseInt(LibsDisguises.getInstance().getBuildNo())) {
|
||||
f.delete();
|
||||
DisguiseUtilities.getLogger().info("Ew, " + f.getName() + " is so old");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!info.isLegit()) {
|
||||
f.delete();
|
||||
DisguiseUtilities.getLogger().info("Ew, I saw something nasty in " + f.getName());
|
||||
continue;
|
||||
}
|
||||
|
||||
foundBetter = true;
|
||||
break;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundBetter) {
|
||||
File f = new File(
|
||||
LibsDisguises.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation()
|
||||
.getFile());
|
||||
|
||||
FileUtil.copy(f, new File(LibsDisguises.getInstance().getDataFolder(), f.getName()));
|
||||
|
||||
DisguiseUtilities.getLogger().info("Copied " + f.getName() +
|
||||
" to the plugin folder! This is incase you want to use dev builds.");
|
||||
}
|
||||
}
|
||||
|
||||
if (isPremium()) {
|
||||
|
@@ -0,0 +1,22 @@
|
||||
package me.libraryaddict.disguise.utilities.modded;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 14/04/2020.
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class CustomEntity {
|
||||
@Setter
|
||||
private Object entityType;
|
||||
private final String name;
|
||||
private final boolean living;
|
||||
private final String mod;
|
||||
private final String[] versions;
|
||||
private final String required;
|
||||
@Setter
|
||||
private int typeId;
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
package me.libraryaddict.disguise.utilities.modded;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 14/04/2020.
|
||||
*/
|
||||
public class ModdedManager {
|
||||
private static final HashMap<NamespacedKey, CustomEntity> entities = new HashMap<>();
|
||||
|
||||
public static void registerCustomEntity(NamespacedKey name, CustomEntity entity, boolean register) {
|
||||
if (entities.keySet().stream().anyMatch(n -> n.toString().equalsIgnoreCase(name.toString()))) {
|
||||
throw new IllegalArgumentException(name + " has already been registered");
|
||||
}
|
||||
|
||||
if (entities.values().stream().anyMatch(n -> n.getName().equalsIgnoreCase(entity.getName()))) {
|
||||
throw new IllegalArgumentException("Modded entity " + entity.getName() + " has already been registered");
|
||||
}
|
||||
|
||||
if (register) {
|
||||
Object entityType = ReflectionManager.registerEntityType(name);
|
||||
int entityId = ReflectionManager.getEntityTypeId(entityType);
|
||||
|
||||
entity.setTypeId(entityId);
|
||||
entity.setEntityType(entityType);
|
||||
} else {
|
||||
Object entityType = ReflectionManager.getEntityType(name);
|
||||
int entityId = ReflectionManager.getEntityTypeId(entityType);
|
||||
|
||||
entity.setTypeId(entityId);
|
||||
entity.setEntityType(entityType);
|
||||
}
|
||||
|
||||
entities.put(name, entity);
|
||||
}
|
||||
|
||||
public static CustomEntity getCustomEntity(NamespacedKey name) {
|
||||
return entities.get(name);
|
||||
}
|
||||
|
||||
public static CustomEntity getCustomEntity(String name) {
|
||||
for (CustomEntity entity : entities.values()) {
|
||||
if (!entity.getName().equalsIgnoreCase(name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ArrayList<DisguisePerm> getDisguiseTypes() {
|
||||
ArrayList<DisguisePerm> perms = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<NamespacedKey, CustomEntity> entry : entities.entrySet()) {
|
||||
perms.add(new DisguisePerm(
|
||||
entry.getValue().isLiving() ? DisguiseType.CUSTOM_LIVING : DisguiseType.CUSTOM_MISC,
|
||||
entry.getValue().getName()));
|
||||
}
|
||||
|
||||
return perms;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user