Large config rewrite, updating creates incompatibility with older versions of LD. Probably need to clean up configs a bit more.
This commit is contained in:
@@ -43,9 +43,10 @@ public class DisguiseAPI {
|
||||
DisguiseConfig.removeCustomDisguise(disguiseName);
|
||||
DisguiseConfig.addCustomDisguise(disguiseName, disguiseInfo);
|
||||
|
||||
File disguisesFile = new File("plugins/LibsDisguises/disguises.yml");
|
||||
File disguisesFile = new File(LibsDisguises.getInstance().getDataFolder(), "configs/disguises.yml");
|
||||
|
||||
if (!disguisesFile.exists()) {
|
||||
disguisesFile.getParentFile().mkdirs();
|
||||
disguisesFile.createNewFile();
|
||||
}
|
||||
|
||||
@@ -143,9 +144,8 @@ public class DisguiseAPI {
|
||||
}
|
||||
}
|
||||
for (Method method : entity.getClass().getMethods()) {
|
||||
if ((doSneak || !method.getName().equals("setSneaking")) &&
|
||||
(doSprint || !method.getName().equals("setSprinting")) && method.getParameterTypes().length == 0 &&
|
||||
method.getReturnType() != void.class) {
|
||||
if ((doSneak || !method.getName().equals("setSneaking")) && (doSprint || !method.getName().equals("setSprinting")) &&
|
||||
method.getParameterTypes().length == 0 && method.getReturnType() != void.class) {
|
||||
Class methodReturn = method.getReturnType();
|
||||
|
||||
if (methodReturn == float.class || methodReturn == Float.class || methodReturn == Double.class) {
|
||||
@@ -160,12 +160,11 @@ public class DisguiseAPI {
|
||||
watcherMethod.getParameterTypes().length == 1) {
|
||||
int firstCapitalWatcher = firstCapital(watcherMethod.getName());
|
||||
|
||||
if (firstCapitalWatcher > 0 && method.getName().substring(firstCapitalMethod)
|
||||
.equalsIgnoreCase(watcherMethod.getName().substring(firstCapitalWatcher))) {
|
||||
if (firstCapitalWatcher > 0 &&
|
||||
method.getName().substring(firstCapitalMethod).equalsIgnoreCase(watcherMethod.getName().substring(firstCapitalWatcher))) {
|
||||
Class methodParam = watcherMethod.getParameterTypes()[0];
|
||||
|
||||
if (methodParam == float.class || methodParam == Float.class ||
|
||||
methodParam == Double.class) {
|
||||
if (methodParam == float.class || methodParam == Float.class || methodParam == Double.class) {
|
||||
methodParam = double.class;
|
||||
} else if (methodParam == AnimalColor.class) {
|
||||
methodParam = DyeColor.class;
|
||||
@@ -190,8 +189,7 @@ public class DisguiseAPI {
|
||||
value = AnimalColor.valueOf(((DyeColor) value).name());
|
||||
}
|
||||
}
|
||||
if (value instanceof Boolean && !(Boolean) value &&
|
||||
watcherMethod.getDeclaringClass() == FlagWatcher.class) {
|
||||
if (value instanceof Boolean && !(Boolean) value && watcherMethod.getDeclaringClass() == FlagWatcher.class) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@@ -4,9 +4,9 @@ import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.config.ConfigLoader;
|
||||
import me.libraryaddict.disguise.utilities.modded.ModdedEntity;
|
||||
import me.libraryaddict.disguise.utilities.modded.ModdedManager;
|
||||
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
||||
@@ -17,20 +17,15 @@ import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import me.libraryaddict.disguise.utilities.translations.TranslateType;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
@@ -63,12 +58,6 @@ public class DisguiseConfig {
|
||||
@Getter
|
||||
@Setter
|
||||
private static boolean collectPacketsEnabled;
|
||||
/**
|
||||
* No setter provided as this cannot be changed after startup
|
||||
*/
|
||||
@Setter(value = AccessLevel.PRIVATE)
|
||||
@Getter
|
||||
private static boolean disableCommands;
|
||||
@Getter
|
||||
@Setter
|
||||
private static boolean disableFriendlyInvisibles;
|
||||
@@ -277,6 +266,12 @@ public class DisguiseConfig {
|
||||
@Getter
|
||||
@Setter
|
||||
private static String lastPluginUpdateVersion;
|
||||
@Getter
|
||||
@Setter
|
||||
private static boolean contactMojangServers;
|
||||
@Getter
|
||||
@Setter(AccessLevel.PROTECTED)
|
||||
private static int disguiseRadiusMax;
|
||||
|
||||
public static boolean isArmorstandsName() {
|
||||
return getPlayerNameType() == PlayerNameType.ARMORSTANDS;
|
||||
@@ -322,22 +317,6 @@ public class DisguiseConfig {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!LibsDisguises.getInstance().getConfig().getDefaults().getBoolean("AutoUpdate")) {
|
||||
updaterTask = Bukkit.getScheduler().runTaskTimer(LibsDisguises.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Set<TargetedDisguise> disguises : DisguiseUtilities.getDisguises().values()) {
|
||||
for (Disguise disguise : disguises) {
|
||||
disguise.getWatcher().setSprinting(true);
|
||||
disguise.getWatcher().setHelmet(new ItemStack(Material.LEATHER_HELMET));
|
||||
}
|
||||
}
|
||||
}
|
||||
}, TimeUnit.HOURS.toSeconds(1) * 20, (20 * TimeUnit.MINUTES.toSeconds(10)));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (updaterTask == null != startTask) {
|
||||
return;
|
||||
}
|
||||
@@ -560,75 +539,9 @@ public class DisguiseConfig {
|
||||
TranslateType.refreshTranslations();
|
||||
}
|
||||
|
||||
public static void saveDefaultConfig() {
|
||||
DisguiseUtilities.getLogger().info("Config is out of date! Now updating it!");
|
||||
String[] string = ReflectionManager.getResourceAsString(LibsDisguises.getInstance().getFile(), "config.yml").split("\n");
|
||||
FileConfiguration savedConfig = LibsDisguises.getInstance().getConfig();
|
||||
|
||||
StringBuilder section = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < string.length; i++) {
|
||||
String s = string[i];
|
||||
|
||||
if (s.trim().startsWith("#") || !s.contains(":")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String rawKey = s.split(":")[0];
|
||||
|
||||
if (section.length() > 0) {
|
||||
int matches = StringUtils.countMatches(rawKey, " ");
|
||||
|
||||
int allowed = 0;
|
||||
|
||||
for (int a = 0; a < matches; a++) {
|
||||
allowed = section.indexOf(".", allowed) + 1;
|
||||
}
|
||||
|
||||
section = new StringBuilder(section.substring(0, allowed));
|
||||
}
|
||||
|
||||
String key = (rawKey.startsWith(" ") ? section.toString() : "") + rawKey.trim();
|
||||
|
||||
if (savedConfig.isConfigurationSection(key)) {
|
||||
section.append(key).append(".");
|
||||
} else if (savedConfig.isSet(key)) {
|
||||
String rawVal = s.split(":")[1].trim();
|
||||
Object val = savedConfig.get(key);
|
||||
|
||||
if (savedConfig.isString(key) && !rawVal.equals("true") && !rawVal.equals("false")) {
|
||||
val = "'" + StringEscapeUtils.escapeJava(val.toString().replace(ChatColor.COLOR_CHAR + "", "&")) + "'";
|
||||
}
|
||||
|
||||
string[i] = rawKey + ": " + val;
|
||||
}
|
||||
}
|
||||
|
||||
File config = new File(LibsDisguises.getInstance().getDataFolder(), "config.yml");
|
||||
|
||||
try {
|
||||
if (config.exists()) {
|
||||
config.renameTo(new File(config.getParentFile(), "config-old.yml"));
|
||||
|
||||
DisguiseUtilities.getLogger().info("Old config has been copied to config-old.yml");
|
||||
}
|
||||
|
||||
config.createNewFile();
|
||||
|
||||
try (PrintWriter out = new PrintWriter(config)) {
|
||||
out.write(StringUtils.join(string, "\n"));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadConfig() {
|
||||
// Always save the default config
|
||||
LibsDisguises.getInstance().saveDefaultConfig();
|
||||
// Redundant for the first load, however other plugins may call loadConfig() at a later stage where we
|
||||
// definitely want to reload it.
|
||||
LibsDisguises.getInstance().reloadConfig();
|
||||
ConfigLoader configLoader = new ConfigLoader();
|
||||
configLoader.saveMissingConfigs();
|
||||
|
||||
loadModdedDisguiseTypes();
|
||||
|
||||
@@ -650,10 +563,9 @@ public class DisguiseConfig {
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationSection config = LibsDisguises.getInstance().getConfig();
|
||||
ConfigurationSection config = configLoader.load();
|
||||
|
||||
PacketsManager.setViewDisguisesListener(true);
|
||||
disableCommands = config.getBoolean("DisableCommands");
|
||||
|
||||
setAddEntityAnimations(config.getBoolean("AddEntityAnimations"));
|
||||
setAnimationPacketsEnabled(config.getBoolean("PacketsEnabled.Animation"));
|
||||
@@ -719,6 +631,8 @@ public class DisguiseConfig {
|
||||
setSaveUserPreferences(config.getBoolean("SaveUserPreferences"));
|
||||
setPlayerDisguisesSkinExpiresMove(config.getInt("PlayerDisguisesTablistExpiresMove"));
|
||||
setViewSelfDisguisesDefault(config.getBoolean("ViewSelfDisguisesDefault"));
|
||||
setContactMojangServers(config.getBoolean("ContactMojangServers"));
|
||||
setDisguiseRadiusMax(config.getInt("DisguiseRadiusMax"));
|
||||
|
||||
if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) {
|
||||
DisguiseUtilities.getLogger().warning("You must purchase the plugin to use saved disguises!");
|
||||
@@ -826,19 +740,11 @@ public class DisguiseConfig {
|
||||
}
|
||||
}
|
||||
|
||||
int missingConfigs = 0;
|
||||
|
||||
for (String key : config.getDefaultSection().getKeys(true)) {
|
||||
if (config.contains(key, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
missingConfigs++;
|
||||
}
|
||||
int missingConfigs = doOutput(config, false, true).size();
|
||||
|
||||
if (missingConfigs > 0) {
|
||||
if (config.getBoolean("UpdateConfig", true)) {
|
||||
saveDefaultConfig();
|
||||
configLoader.saveDefaultConfigs();
|
||||
DisguiseUtilities.getLogger().info("Config has been auto-updated!");
|
||||
} else if (!verbose) {
|
||||
DisguiseUtilities.getLogger().warning("Your config is missing " + missingConfigs + " options! Please consider regenerating your config!");
|
||||
@@ -850,7 +756,7 @@ public class DisguiseConfig {
|
||||
}
|
||||
|
||||
public static void loadModdedDisguiseTypes() {
|
||||
File disguisesFile = new File("plugins/LibsDisguises/disguises.yml");
|
||||
File disguisesFile = new File(LibsDisguises.getInstance().getDataFolder(), "configs/disguises.yml");
|
||||
|
||||
if (!disguisesFile.exists()) {
|
||||
return;
|
||||
@@ -929,9 +835,18 @@ public class DisguiseConfig {
|
||||
new ModdedManager(channels);
|
||||
}
|
||||
|
||||
public static ArrayList<String> doOutput(boolean informChangedUnknown, boolean informMissing) {
|
||||
return doOutput(new ConfigLoader().load(), informChangedUnknown, informMissing);
|
||||
}
|
||||
|
||||
public static ArrayList<String> doOutput(ConfigurationSection config, boolean informChangedUnknown, boolean informMissing) {
|
||||
HashMap<String, Object> configs = new HashMap<>();
|
||||
ConfigurationSection defaultSection = config.getDefaultSection();
|
||||
|
||||
if (defaultSection == null) {
|
||||
defaultSection = new ConfigLoader().loadDefaults();
|
||||
}
|
||||
|
||||
ArrayList<String> returns = new ArrayList<>();
|
||||
|
||||
for (String key : defaultSection.getKeys(true)) {
|
||||
@@ -975,7 +890,7 @@ public class DisguiseConfig {
|
||||
static void loadCustomDisguises() {
|
||||
customDisguises.clear();
|
||||
|
||||
File disguisesFile = new File("plugins/LibsDisguises/disguises.yml");
|
||||
File disguisesFile = new File(LibsDisguises.getInstance().getDataFolder(), "configs/disguises.yml");
|
||||
|
||||
if (!disguisesFile.exists()) {
|
||||
return;
|
||||
|
@@ -82,7 +82,7 @@ public class LibsDisguises extends JavaPlugin {
|
||||
|
||||
Bukkit.getPluginManager().enablePlugin(plugin);
|
||||
} else {
|
||||
getLogger().severe("Please restar the server to complete the ProtocolLib update!");
|
||||
getLogger().severe("Please restart the server to complete the ProtocolLib update!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -119,8 +119,18 @@ public class LibsDisguises extends JavaPlugin {
|
||||
"plugin will continue to load, but it will look like a mugging victim");
|
||||
}
|
||||
|
||||
if (!new File(getDataFolder(), "disguises.yml").exists()) {
|
||||
saveResource("disguises.yml", false);
|
||||
File disguiseFile = new File(getDataFolder(), "configs/disguises.yml");
|
||||
|
||||
if (!disguiseFile.exists()) {
|
||||
disguiseFile.getParentFile().mkdirs();
|
||||
|
||||
File oldFile = new File(getDataFolder(), "disguises.yml");
|
||||
|
||||
if (oldFile.exists()) {
|
||||
oldFile.renameTo(disguiseFile);
|
||||
} else {
|
||||
saveResource("configs/disguises.yml", false);
|
||||
}
|
||||
}
|
||||
|
||||
YamlConfiguration pluginYml = ReflectionManager.getPluginYAML(getFile());
|
||||
@@ -209,31 +219,26 @@ public class LibsDisguises extends JavaPlugin {
|
||||
}
|
||||
|
||||
registerCommand("libsdisguises", new LibsDisguisesCommand());
|
||||
|
||||
if (!DisguiseConfig.isDisableCommands()) {
|
||||
registerCommand("disguise", new DisguiseCommand());
|
||||
registerCommand("undisguise", new UndisguiseCommand());
|
||||
registerCommand("disguiseplayer", new DisguisePlayerCommand());
|
||||
registerCommand("undisguiseplayer", new UndisguisePlayerCommand());
|
||||
registerCommand("undisguiseentity", new UndisguiseEntityCommand());
|
||||
registerCommand("disguiseentity", new DisguiseEntityCommand());
|
||||
registerCommand("disguiseradius", new DisguiseRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
|
||||
registerCommand("undisguiseradius", new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
|
||||
registerCommand("disguisehelp", new DisguiseHelpCommand());
|
||||
registerCommand("disguiseclone", new DisguiseCloneCommand());
|
||||
registerCommand("disguiseviewself", new DisguiseViewSelfCommand());
|
||||
registerCommand("disguiseviewbar", new DisguiseViewBarCommand());
|
||||
registerCommand("disguisemodify", new DisguiseModifyCommand());
|
||||
registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand());
|
||||
registerCommand("disguisemodifyplayer", new DisguiseModifyPlayerCommand());
|
||||
registerCommand("disguisemodifyradius", new DisguiseModifyRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
|
||||
registerCommand("copydisguise", new CopyDisguiseCommand());
|
||||
registerCommand("grabskin", new GrabSkinCommand());
|
||||
registerCommand("savedisguise", new SaveDisguiseCommand());
|
||||
registerCommand("grabhead", new GrabHeadCommand());
|
||||
} else {
|
||||
getLogger().info("Commands has been disabled, as per config");
|
||||
}
|
||||
registerCommand("disguise", new DisguiseCommand());
|
||||
registerCommand("undisguise", new UndisguiseCommand());
|
||||
registerCommand("disguiseplayer", new DisguisePlayerCommand());
|
||||
registerCommand("undisguiseplayer", new UndisguisePlayerCommand());
|
||||
registerCommand("undisguiseentity", new UndisguiseEntityCommand());
|
||||
registerCommand("disguiseentity", new DisguiseEntityCommand());
|
||||
registerCommand("disguiseradius", new DisguiseRadiusCommand());
|
||||
registerCommand("undisguiseradius", new UndisguiseRadiusCommand());
|
||||
registerCommand("disguisehelp", new DisguiseHelpCommand());
|
||||
registerCommand("disguiseclone", new DisguiseCloneCommand());
|
||||
registerCommand("disguiseviewself", new DisguiseViewSelfCommand());
|
||||
registerCommand("disguiseviewbar", new DisguiseViewBarCommand());
|
||||
registerCommand("disguisemodify", new DisguiseModifyCommand());
|
||||
registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand());
|
||||
registerCommand("disguisemodifyplayer", new DisguiseModifyPlayerCommand());
|
||||
registerCommand("disguisemodifyradius", new DisguiseModifyRadiusCommand());
|
||||
registerCommand("copydisguise", new CopyDisguiseCommand());
|
||||
registerCommand("grabskin", new GrabSkinCommand());
|
||||
registerCommand("savedisguise", new SaveDisguiseCommand());
|
||||
registerCommand("grabhead", new GrabHeadCommand());
|
||||
|
||||
unregisterCommands(false);
|
||||
|
||||
|
@@ -29,12 +29,9 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||
private int maxRadius = 30;
|
||||
private ArrayList<Class<? extends Entity>> validClasses = new ArrayList<>();
|
||||
|
||||
public DisguiseRadiusCommand(int maxRadius) {
|
||||
this.maxRadius = maxRadius;
|
||||
|
||||
public DisguiseRadiusCommand() {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
Class c = type.getEntityClass();
|
||||
|
||||
@@ -131,9 +128,9 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
|
||||
|
||||
int radius = Integer.parseInt(args[starting]);
|
||||
|
||||
if (radius > maxRadius) {
|
||||
LibsMsg.LIMITED_RADIUS.send(sender, maxRadius);
|
||||
radius = maxRadius;
|
||||
if (radius > DisguiseConfig.getDisguiseRadiusMax()) {
|
||||
LibsMsg.LIMITED_RADIUS.send(sender, DisguiseConfig.getDisguiseRadiusMax());
|
||||
radius = DisguiseConfig.getDisguiseRadiusMax();
|
||||
}
|
||||
|
||||
String[] newArgs = new String[args.length - (starting + 1)];
|
||||
@@ -291,7 +288,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
|
||||
return;
|
||||
}
|
||||
|
||||
LibsMsg.DRADIUS_HELP1.send(sender, maxRadius);
|
||||
LibsMsg.DRADIUS_HELP1.send(sender, DisguiseConfig.getDisguiseRadiusMax());
|
||||
LibsMsg.CAN_USE_DISGS.send(sender, StringUtils.join(allowedDisguises, LibsMsg.CAN_USE_DISGS_SEPERATOR.get()));
|
||||
|
||||
if (allowedDisguises.contains("player")) {
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -31,7 +30,7 @@ public class LDConfig implements LDCommand {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
ArrayList<String> returns = DisguiseConfig.doOutput(LibsDisguises.getInstance().getConfig(), true, true);
|
||||
ArrayList<String> returns = DisguiseConfig.doOutput(true, true);
|
||||
|
||||
if (returns.isEmpty()) {
|
||||
LibsMsg.USING_DEFAULT_CONFIG.send(sender);
|
||||
|
@@ -3,6 +3,7 @@ package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
import lombok.Data;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.utilities.config.ConfigLoader;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
@@ -22,6 +23,7 @@ import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 18/06/2020.
|
||||
@@ -120,35 +122,42 @@ public class LDUploadLogs implements LDCommand {
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
if (lastUsed + TimeUnit.MINUTES.toMillis(3) > System.currentTimeMillis()) {
|
||||
sender.sendMessage(ChatColor.RED +
|
||||
"You last used this command under 3 minutes ago! Restart the server or wait for this timer to " +
|
||||
"disappear!");
|
||||
sender.sendMessage(ChatColor.RED + "You last used this command under 3 minutes ago! Restart the server or wait for this timer to " + "disappear!");
|
||||
return;
|
||||
}
|
||||
|
||||
File latest = new File("logs/latest.log");
|
||||
File disguises = new File(LibsDisguises.getInstance().getDataFolder(), "disguises.yml");
|
||||
File config = new File(LibsDisguises.getInstance().getDataFolder(), "config.yml");
|
||||
File disguises = new File(LibsDisguises.getInstance().getDataFolder(), "configs/disguises.yml");
|
||||
|
||||
List<File> configs =
|
||||
new ConfigLoader().getConfigs().stream().map(f -> new File(LibsDisguises.getInstance().getDataFolder(), f)).collect(Collectors.toList());
|
||||
|
||||
StringBuilder configText = new StringBuilder();
|
||||
|
||||
for (File config : configs) {
|
||||
if (configText.length() != 0) {
|
||||
configText.append("\n\n================\n\n");
|
||||
}
|
||||
|
||||
try {
|
||||
configText.append(new String(Files.readAllBytes(config.toPath())));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (isTooBig(latest)) {
|
||||
sender.sendMessage(ChatColor.RED +
|
||||
"Your latest.log file is too big! It should be less than 512kb! Please restart and run this " +
|
||||
"command again!");
|
||||
sender.sendMessage(
|
||||
ChatColor.RED + "Your latest.log file is too big! It should be less than 512kb! Please restart and run this " + "command again!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isTooBig(disguises)) {
|
||||
sender.sendMessage(ChatColor.RED +
|
||||
"Your disguises.yml is too big! You'll need to trim that file down before using this command! It " +
|
||||
sender.sendMessage(ChatColor.RED + "Your disguises.yml is too big! You'll need to trim that file down before using this command! It " +
|
||||
"should be less than 512kb!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isTooBig(config)) {
|
||||
sender.sendMessage(ChatColor.RED + "Your config.yml is too big! It should be less than 512kb!");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String latestText = new String(Files.readAllBytes(latest.toPath()));
|
||||
|
||||
@@ -166,8 +175,7 @@ public class LDUploadLogs implements LDCommand {
|
||||
|
||||
lastFind = nextLine + 2;
|
||||
|
||||
if (!str.contains("Starting minecraft server version") && !str.contains("Loading properties") &&
|
||||
!str.contains("This server is running")) {
|
||||
if (!str.contains("Starting minecraft server version") && !str.contains("Loading properties") && !str.contains("This server is running")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -176,8 +184,7 @@ public class LDUploadLogs implements LDCommand {
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
sender.sendMessage(
|
||||
ChatColor.RED + "Your latest.log is too old! Please restart the server and try again!");
|
||||
sender.sendMessage(ChatColor.RED + "Your latest.log is too old! Please restart the server and try again!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -188,12 +195,10 @@ public class LDUploadLogs implements LDCommand {
|
||||
public void run() {
|
||||
try {
|
||||
String disguiseText = new String(Files.readAllBytes(disguises.toPath()));
|
||||
StringBuilder configText = new StringBuilder(new String(Files.readAllBytes(config.toPath())));
|
||||
|
||||
configText.append("\n================\n");
|
||||
configText.append("\n\n================\n");
|
||||
|
||||
ArrayList<String> modified =
|
||||
DisguiseConfig.doOutput(LibsDisguises.getInstance().getConfig(), true, true);
|
||||
ArrayList<String> modified = DisguiseConfig.doOutput(true, true);
|
||||
|
||||
for (String s : modified) {
|
||||
configText.append("\n").append(s);
|
||||
@@ -203,8 +208,10 @@ public class LDUploadLogs implements LDCommand {
|
||||
configText.append("\nUsing default config!");
|
||||
}
|
||||
|
||||
String ctext = configText.toString().replaceAll("\n? *#[^\n]*", "");
|
||||
|
||||
URL latestPaste = new GuestPaste("latest.log", latestText).paste();
|
||||
URL configPaste = new GuestPaste("LibsDisguises config.yml", configText.toString()).paste();
|
||||
URL configPaste = new GuestPaste("LibsDisguises config.yml", ctext).paste();
|
||||
URL disguisesPaste = new GuestPaste("LibsDisguises disguises.yml", disguiseText).paste();
|
||||
|
||||
lastUsed = System.currentTimeMillis();
|
||||
@@ -216,12 +223,10 @@ public class LDUploadLogs implements LDCommand {
|
||||
|
||||
// Console can't click :(
|
||||
if (sender instanceof Player) {
|
||||
sender.sendMessage(ChatColor.GOLD +
|
||||
"Click on the below message to have it appear in your chat input");
|
||||
sender.sendMessage(ChatColor.GOLD + "Click on the below message to have it appear in your chat input");
|
||||
}
|
||||
|
||||
String text = "My log file: " + latestPaste + ", my config file: " + configPaste +
|
||||
" and my disguises file: " + disguisesPaste;
|
||||
String text = "My log file: " + latestPaste + ", my config file: " + configPaste + " and my disguises file: " + disguisesPaste;
|
||||
|
||||
ComponentBuilder builder = new ComponentBuilder("");
|
||||
builder.append(text);
|
||||
@@ -243,7 +248,11 @@ public class LDUploadLogs implements LDCommand {
|
||||
}
|
||||
|
||||
private boolean isTooBig(File file) {
|
||||
return file.exists() && file.length() >= 512 * 1024;
|
||||
return file.exists() && isTooBig(file.length());
|
||||
}
|
||||
|
||||
private boolean isTooBig(long length) {
|
||||
return length >= 512 * 1024;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package me.libraryaddict.disguise.commands.modify;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
@@ -26,12 +27,6 @@ import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||
private int maxRadius = 30;
|
||||
|
||||
public DisguiseModifyRadiusCommand(int maxRadius) {
|
||||
this.maxRadius = maxRadius;
|
||||
}
|
||||
|
||||
private Collection<Entity> getNearbyEntities(CommandSender sender, int radius) {
|
||||
Location center;
|
||||
|
||||
@@ -77,8 +72,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
||||
|
||||
Collections.sort(classes);
|
||||
|
||||
LibsMsg.DMODRADIUS_USABLE.send(sender,
|
||||
ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN));
|
||||
LibsMsg.DMODRADIUS_USABLE.send(sender, ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -124,9 +118,9 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
||||
|
||||
int radius = Integer.parseInt(args[starting]);
|
||||
|
||||
if (radius > maxRadius) {
|
||||
LibsMsg.LIMITED_RADIUS.send(sender, maxRadius);
|
||||
radius = maxRadius;
|
||||
if (radius > DisguiseConfig.getDisguiseRadiusMax()) {
|
||||
LibsMsg.LIMITED_RADIUS.send(sender, DisguiseConfig.getDisguiseRadiusMax());
|
||||
radius = DisguiseConfig.getDisguiseRadiusMax();
|
||||
}
|
||||
|
||||
String[] newArgs = new String[args.length - (starting + 1)];
|
||||
@@ -154,10 +148,11 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
||||
|
||||
Disguise disguise;
|
||||
|
||||
if (sender instanceof Player)
|
||||
if (sender instanceof Player) {
|
||||
disguise = DisguiseAPI.getDisguise((Player) sender, entity);
|
||||
else
|
||||
} else {
|
||||
disguise = DisguiseAPI.getDisguise(entity);
|
||||
}
|
||||
|
||||
if (disguise == null) {
|
||||
continue;
|
||||
@@ -174,18 +169,15 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
||||
tempArgs = DisguiseParser.parsePlaceholders(tempArgs, sender, entity);
|
||||
|
||||
try {
|
||||
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), tempArgs,
|
||||
"DisguiseModifyRadius");
|
||||
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), tempArgs, "DisguiseModifyRadius");
|
||||
modifiedDisguises++;
|
||||
}
|
||||
catch (DisguiseParseException ex) {
|
||||
} catch (DisguiseParseException ex) {
|
||||
if (ex.getMessage() != null) {
|
||||
DisguiseUtilities.sendMessage(sender, ex.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
@@ -238,8 +230,9 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
||||
}
|
||||
|
||||
// Not a valid radius
|
||||
if (starting == 1 || args.length == 1 || !isInteger(args[1]))
|
||||
if (starting == 1 || args.length == 1 || !isInteger(args[1])) {
|
||||
return filterTabs(tabs, origArgs);
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length <= starting || !isInteger(args[starting])) {
|
||||
@@ -248,9 +241,9 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
||||
|
||||
int radius = Integer.parseInt(args[starting]);
|
||||
|
||||
if (radius > maxRadius) {
|
||||
LibsMsg.LIMITED_RADIUS.send(sender, maxRadius);
|
||||
radius = maxRadius;
|
||||
if (radius > DisguiseConfig.getDisguiseRadiusMax()) {
|
||||
LibsMsg.LIMITED_RADIUS.send(sender, DisguiseConfig.getDisguiseRadiusMax());
|
||||
radius = DisguiseConfig.getDisguiseRadiusMax();
|
||||
}
|
||||
|
||||
starting++;
|
||||
@@ -260,15 +253,17 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
||||
for (Entity entity : getNearbyEntities(sender, radius)) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(entity);
|
||||
|
||||
if (disguise == null)
|
||||
if (disguise == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DisguiseType disguiseType = disguise.getType();
|
||||
|
||||
for (Method method : ParamInfoManager.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
|
||||
for (String arg : args) {
|
||||
if (!method.getName().equalsIgnoreCase(arg) || usedOptions.contains(arg))
|
||||
if (!method.getName().equalsIgnoreCase(arg) || usedOptions.contains(arg)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
usedOptions.add(arg);
|
||||
}
|
||||
@@ -291,7 +286,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
||||
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
|
||||
|
||||
LibsMsg.DMODRADIUS_HELP1.send(sender, maxRadius);
|
||||
LibsMsg.DMODRADIUS_HELP1.send(sender, DisguiseConfig.getDisguiseRadiusMax());
|
||||
LibsMsg.DMODIFY_HELP3.send(sender, StringUtils.join(allowedDisguises, LibsMsg.CAN_USE_DISGS_SEPERATOR.get()));
|
||||
|
||||
LibsMsg.DMODRADIUS_HELP2.send(sender);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package me.libraryaddict.disguise.commands.undisguise;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -13,12 +14,6 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class UndisguiseRadiusCommand implements CommandExecutor {
|
||||
private int maxRadius = 30;
|
||||
|
||||
public UndisguiseRadiusCommand(int maxRadius) {
|
||||
this.maxRadius = maxRadius;
|
||||
}
|
||||
|
||||
private boolean isNumeric(String string) {
|
||||
try {
|
||||
Integer.parseInt(string);
|
||||
@@ -43,16 +38,19 @@ public class UndisguiseRadiusCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (sender.hasPermission("libsdisguises.undisguiseradius")) {
|
||||
int radius = maxRadius;
|
||||
int radius = DisguiseConfig.getDisguiseRadiusMax();
|
||||
|
||||
if (args.length > 0) {
|
||||
if (!isNumeric(args[0])) {
|
||||
LibsMsg.NOT_NUMBER.send(sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
radius = Integer.parseInt(args[0]);
|
||||
if (radius > maxRadius) {
|
||||
LibsMsg.LIMITED_RADIUS.send(sender, maxRadius);
|
||||
radius = maxRadius;
|
||||
|
||||
if (radius > DisguiseConfig.getDisguiseRadiusMax()) {
|
||||
LibsMsg.LIMITED_RADIUS.send(sender, DisguiseConfig.getDisguiseRadiusMax());
|
||||
radius = DisguiseConfig.getDisguiseRadiusMax();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -469,7 +469,7 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
};
|
||||
|
||||
WrappedGameProfile gameProfile = DisguiseUtilities
|
||||
.getProfileFromMojang(this.skinToUse, currentLookup, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
|
||||
.getProfileFromMojang(this.skinToUse, currentLookup, DisguiseConfig.isContactMojangServers());
|
||||
|
||||
if (gameProfile != null) {
|
||||
setSkin(gameProfile);
|
||||
@@ -635,7 +635,7 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
};
|
||||
|
||||
WrappedGameProfile gameProfile = DisguiseUtilities
|
||||
.getProfileFromMojang(this.skinToUse, currentLookup, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
|
||||
.getProfileFromMojang(this.skinToUse, currentLookup, DisguiseConfig.isContactMojangServers());
|
||||
|
||||
if (gameProfile != null) {
|
||||
setSkin(gameProfile);
|
||||
|
@@ -161,7 +161,7 @@ public class DisguiseUtilities {
|
||||
private static final HashSet<UUID> selfDisguised = new HashSet<>();
|
||||
private static final HashMap<UUID, String> preDisguiseTeam = new HashMap<>();
|
||||
private static final HashMap<UUID, String> disguiseTeam = new HashMap<>();
|
||||
private static final File profileCache = new File("plugins/LibsDisguises/GameProfiles");
|
||||
private static final File profileCache = new File("plugins/LibsDisguises/SavedSkins");
|
||||
private static final File savedDisguises = new File("plugins/LibsDisguises/SavedDisguises");
|
||||
@Getter
|
||||
private static Gson gson;
|
||||
@@ -1124,7 +1124,7 @@ public class DisguiseUtilities {
|
||||
|
||||
DisguiseUtilities.refreshTrackers(disguise);
|
||||
}
|
||||
}, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
|
||||
}, DisguiseConfig.isContactMojangServers());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1271,7 +1271,13 @@ public class DisguiseUtilities {
|
||||
gson = gsonBuilder.create();
|
||||
|
||||
if (!profileCache.exists()) {
|
||||
profileCache.mkdirs();
|
||||
File old = new File(profileCache.getParentFile(), "GameProfiles");
|
||||
|
||||
if (old.exists() && old.isDirectory()) {
|
||||
old.renameTo(profileCache);
|
||||
} else {
|
||||
profileCache.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
if (!savedDisguises.exists()) {
|
||||
@@ -1331,13 +1337,7 @@ public class DisguiseUtilities {
|
||||
Method m = CompileMethods.class.getMethod("main", String[].class);
|
||||
|
||||
if ((!m.isAnnotationPresent(CompileMethods.CompileMethodsIntfer.class) ||
|
||||
m.getAnnotation(CompileMethods.CompileMethodsIntfer.class).user().matches("[0-9]+")) &&
|
||||
!DisguiseConfig.doOutput(LibsDisguises.getInstance().getConfig(), true, false).isEmpty()) {
|
||||
/*File f = new File(LibsDisguises.getInstance().getDataFolder(), "config.yml");
|
||||
File f2 = new File(f.getParentFile(), "config-older.yml");
|
||||
f2.delete();
|
||||
f.renameTo(f2);
|
||||
LibsDisguises.getInstance().saveDefaultConfig();*/
|
||||
m.getAnnotation(CompileMethods.CompileMethodsIntfer.class).user().matches("[0-9]+")) && !DisguiseConfig.doOutput(true, false).isEmpty()) {
|
||||
DisguiseConfig.setViewDisguises(false);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
@@ -0,0 +1,191 @@
|
||||
package me.libraryaddict.disguise.utilities.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ClassGetter;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 31/01/2021.
|
||||
*/
|
||||
public class ConfigLoader {
|
||||
@Getter
|
||||
private final List<String> configs = new ArrayList<>();
|
||||
|
||||
public ConfigLoader() {
|
||||
for (String s : ClassGetter.getEntriesForPackage(ConfigLoader.class, "configs")) {
|
||||
if (!s.endsWith(".yml")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (s.endsWith("/disguises.yml") || s.endsWith("/sounds.yml")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
configs.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveMissingConfigs() {
|
||||
File oldFile = new File(LibsDisguises.getInstance().getDataFolder(), "config.yml");
|
||||
boolean migrated = oldFile.exists();
|
||||
|
||||
for (String config : configs) {
|
||||
File f = new File(LibsDisguises.getInstance().getDataFolder(), config);
|
||||
|
||||
if (f.exists()) {
|
||||
migrated = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
saveDefaultConfig(config);
|
||||
}
|
||||
|
||||
if (migrated) {
|
||||
DisguiseUtilities.getLogger().info("Migrated old config system to new config system");
|
||||
oldFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public YamlConfiguration loadDefaults() {
|
||||
YamlConfiguration globalConfig = new YamlConfiguration();
|
||||
|
||||
for (String config : configs) {
|
||||
try {
|
||||
YamlConfiguration c = new YamlConfiguration();
|
||||
c.loadFromString(ReflectionManager.getResourceAsString(LibsDisguises.getInstance().getFile(), config));
|
||||
|
||||
for (String k : c.getKeys(true)) {
|
||||
if (c.isConfigurationSection(k)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
globalConfig.set(k, c.get(k));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return globalConfig;
|
||||
}
|
||||
|
||||
public YamlConfiguration load() {
|
||||
YamlConfiguration globalConfig = new YamlConfiguration();
|
||||
|
||||
for (String config : configs) {
|
||||
YamlConfiguration c = YamlConfiguration.loadConfiguration(new File(LibsDisguises.getInstance().getDataFolder(), config));
|
||||
|
||||
for (String k : c.getKeys(true)) {
|
||||
if (c.isConfigurationSection(k)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
globalConfig.set(k, c.get(k));
|
||||
}
|
||||
}
|
||||
|
||||
return globalConfig;
|
||||
}
|
||||
|
||||
public void saveDefaultConfigs() {
|
||||
for (String config : configs) {
|
||||
saveDefaultConfig(config);
|
||||
}
|
||||
|
||||
File f = new File(LibsDisguises.getInstance().getDataFolder(), "config.yml");
|
||||
|
||||
f.delete();
|
||||
}
|
||||
|
||||
public void saveDefaultConfig(String name) {
|
||||
DisguiseUtilities.getLogger().info("Config " + name + " is out of date (Or missing)! Now refreshing it!");
|
||||
String ourConfig = ReflectionManager.getResourceAsString(LibsDisguises.getInstance().getFile(), name);
|
||||
YamlConfiguration savedConfig = null;
|
||||
|
||||
File loadFrom = new File(LibsDisguises.getInstance().getDataFolder(), name);
|
||||
File configFile = loadFrom;
|
||||
|
||||
if (!loadFrom.exists()) {
|
||||
loadFrom = new File(LibsDisguises.getInstance().getDataFolder(), "config.yml");
|
||||
}
|
||||
|
||||
if (loadFrom.exists()) {
|
||||
savedConfig = YamlConfiguration.loadConfiguration(loadFrom);
|
||||
} else {
|
||||
try {
|
||||
savedConfig = new YamlConfiguration();
|
||||
savedConfig.loadFromString(ourConfig);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
String[] string = ourConfig.split("\n");
|
||||
|
||||
StringBuilder section = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < string.length; i++) {
|
||||
String s = string[i];
|
||||
|
||||
if (s.trim().startsWith("#") || !s.contains(":")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String rawKey = s.split(":")[0];
|
||||
|
||||
if (section.length() > 0) {
|
||||
int matches = StringUtils.countMatches(rawKey, " ");
|
||||
|
||||
int allowed = 0;
|
||||
|
||||
for (int a = 0; a < matches; a++) {
|
||||
allowed = section.indexOf(".", allowed) + 1;
|
||||
}
|
||||
|
||||
section = new StringBuilder(section.substring(0, allowed));
|
||||
}
|
||||
|
||||
String key = (rawKey.startsWith(" ") ? section.toString() : "") + rawKey.trim();
|
||||
|
||||
if (savedConfig.isConfigurationSection(key)) {
|
||||
section.append(key).append(".");
|
||||
} else if (savedConfig.isSet(key)) {
|
||||
String rawVal = s.split(":")[1].trim();
|
||||
Object val = savedConfig.get(key);
|
||||
|
||||
if (savedConfig.isString(key) && !rawVal.equals("true") && !rawVal.equals("false")) {
|
||||
val = "'" + StringEscapeUtils.escapeJava(val.toString().replace(ChatColor.COLOR_CHAR + "", "&")) + "'";
|
||||
}
|
||||
|
||||
string[i] = rawKey + ": " + val;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (!configFile.getParentFile().exists()) {
|
||||
configFile.mkdirs();
|
||||
}
|
||||
|
||||
configFile.delete();
|
||||
configFile.createNewFile();
|
||||
|
||||
try (PrintWriter out = new PrintWriter(configFile)) {
|
||||
out.write(StringUtils.join(string, "\n"));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -27,7 +27,7 @@ public class DisguiseCommandConfig {
|
||||
private boolean enabled;
|
||||
}
|
||||
|
||||
private File commandConfig = new File(LibsDisguises.getInstance().getDataFolder(), "commands.yml");
|
||||
private File commandConfig = new File(LibsDisguises.getInstance().getDataFolder(), "configs/plugin-commands.yml");
|
||||
private HashMap<String, DisguiseCommand> commands = new HashMap<>();
|
||||
private boolean modifyCommands = false;
|
||||
|
||||
@@ -87,13 +87,19 @@ public class DisguiseCommandConfig {
|
||||
section.set("aliases", command.getAliases());
|
||||
}
|
||||
|
||||
String configString = config.saveToString();
|
||||
|
||||
configString = configString.replaceAll("\n([a-zA-Z])", "\n\n$1");
|
||||
|
||||
String s =
|
||||
"# The following can be changed to modify how the disguise commands are registered\n# This will only work on server startup\nModifyCommands: " +
|
||||
modifyCommands + "\n\n" + config.saveToString();
|
||||
modifyCommands + "\n\n" + configString;
|
||||
|
||||
commandConfig.delete();
|
||||
|
||||
try {
|
||||
commandConfig.getParentFile().mkdirs();
|
||||
|
||||
commandConfig.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@@ -95,18 +95,14 @@ public class DisguiseListener implements Listener {
|
||||
|
||||
// If build number is null, or not a number. Then we can't check snapshots regardless
|
||||
return !plugin.isNumberedBuild();
|
||||
|
||||
// Check snapshots
|
||||
}
|
||||
|
||||
private void runUpdateScheduler() {
|
||||
boolean autoUpdate = plugin.getConfig().getBoolean("AutoUpdateDev");
|
||||
|
||||
if (!plugin.getConfig().getBoolean("NotifyUpdate")) {
|
||||
if (!DisguiseConfig.isNotifyUpdate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (autoUpdate && !isCheckReleases()) {
|
||||
if (DisguiseConfig.isAutoUpdate() && !isCheckReleases()) {
|
||||
DisguiseUtilities.getLogger().info("Plugin will attempt to auto update when new builds are ready! Check config to disable.");
|
||||
}
|
||||
}
|
||||
|
@@ -95,6 +95,7 @@ public class Metrics {
|
||||
"Check out https://bStats.org/ to learn more :)").copyDefaults(true);
|
||||
try {
|
||||
config.save(configFile);
|
||||
DisguiseUtilities.getLogger().info("Saved bStats config");
|
||||
}
|
||||
catch (IOException ignored) {
|
||||
}
|
||||
|
@@ -221,12 +221,12 @@ public class MetricsInitalizer {
|
||||
}
|
||||
});
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("commands") {
|
||||
/*metrics.addCustomChart(new Metrics.SimplePie("commands") {
|
||||
@Override
|
||||
public String getValue() {
|
||||
return DisguiseConfig.isDisableCommands() ? "Enabled" : "Disabled";
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("spigot") {
|
||||
@Override
|
||||
@@ -241,7 +241,7 @@ public class MetricsInitalizer {
|
||||
}
|
||||
});
|
||||
|
||||
final boolean updates = plugin.getConfig().getBoolean("NotifyUpdate");
|
||||
final boolean updates = DisguiseConfig.isNotifyUpdate();
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("updates") {
|
||||
@Override
|
||||
|
@@ -22,8 +22,31 @@ public class ClassGetter {
|
||||
return getClassesForPackage(Entity.class, pkgname);
|
||||
}
|
||||
|
||||
public static ArrayList<String> getEntriesForPackage(String pkgname) {
|
||||
return getEntriesForPackage(Entity.class, pkgname);
|
||||
}
|
||||
|
||||
public static ArrayList<Class<?>> getClassesForPackage(Class runFrom, String pkgname) {
|
||||
ArrayList<Class<?>> classes = new ArrayList<>();
|
||||
ArrayList<String> list = getEntriesForPackage(runFrom, pkgname);
|
||||
ArrayList<Class<?>> classList = new ArrayList<>();
|
||||
|
||||
for (String s : list) {
|
||||
if (!s.endsWith(".class")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Class<?> c = loadClass(s.replace(".class", "").replace('/', '.'));
|
||||
|
||||
if (c != null) {
|
||||
classList.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
return classList;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getEntriesForPackage(Class runFrom, String pkgname) {
|
||||
ArrayList<String> classes = new ArrayList<>();
|
||||
// String relPath = pkgname.replace('.', '/');
|
||||
|
||||
// Get a File object for the package
|
||||
@@ -36,16 +59,11 @@ public class ClassGetter {
|
||||
processJarfile(resource, pkgname, classes);
|
||||
} else {
|
||||
for (File f : new File(resource.getPath() + "/" + pkgname.replace(".", "/")).listFiles()) {
|
||||
if (!f.getName().endsWith(".class") || f.getName().contains("$")) {
|
||||
if (f.getName().contains("$")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
classes.add(Class.forName(pkgname + "." + f.getName().replace(".class", "")));
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
classes.add(pkgname + "/" + f.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,16 +74,12 @@ public class ClassGetter {
|
||||
private static Class<?> loadClass(String className) {
|
||||
try {
|
||||
return Class.forName(className);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException("Unexpected ClassNotFoundException loading class '" + className + "'");
|
||||
}
|
||||
catch (NoClassDefFoundError e) {
|
||||
} catch (ClassNotFoundException | NoClassDefFoundError e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes) {
|
||||
private static void processJarfile(URL resource, String pkgname, ArrayList<String> classes) {
|
||||
try {
|
||||
String relPath = pkgname.replace('.', '/');
|
||||
String resPath = URLDecoder.decode(resource.getPath(), "UTF-8");
|
||||
@@ -79,22 +93,18 @@ public class ClassGetter {
|
||||
JarEntry entry = entries.nextElement();
|
||||
String entryName = entry.getName();
|
||||
String className = null;
|
||||
if (entryName.endsWith(".class") && entryName.startsWith(relPath) &&
|
||||
entryName.length() > (relPath.length() + "/".length())) {
|
||||
className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
|
||||
}
|
||||
if (className != null) {
|
||||
Class<?> c = loadClass(className);
|
||||
|
||||
if (c != null) {
|
||||
classes.add(c);
|
||||
}
|
||||
if (entryName.startsWith(relPath) && entryName.length() > (relPath.length() + "/".length())) {
|
||||
className = entryName.replace('\\', '/');
|
||||
}
|
||||
|
||||
if (className != null) {
|
||||
classes.add(className);
|
||||
}
|
||||
}
|
||||
|
||||
jarFile.close();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@@ -29,10 +29,18 @@ public class SoundManager {
|
||||
}
|
||||
|
||||
private void loadCustomSounds() {
|
||||
File f = new File(LibsDisguises.getInstance().getDataFolder(), "sounds.yml");
|
||||
File f = new File(LibsDisguises.getInstance().getDataFolder(), "configs/sounds.yml");
|
||||
|
||||
if (!f.exists()) {
|
||||
LibsDisguises.getInstance().saveResource("sounds.yml", false);
|
||||
f.getParentFile().mkdirs();
|
||||
|
||||
File old = new File(LibsDisguises.getInstance().getDataFolder(), "sounds.yml");
|
||||
|
||||
if (old.exists()) {
|
||||
old.renameTo(f);
|
||||
} else {
|
||||
LibsDisguises.getInstance().saveResource("configs/sounds.yml", false);
|
||||
}
|
||||
}
|
||||
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(f);
|
||||
@@ -55,8 +63,7 @@ public class SoundManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<String> list = section.getStringList(
|
||||
type.name().charAt(0) + type.name().substring(1).toLowerCase(Locale.ENGLISH));
|
||||
List<String> list = section.getStringList(type.name().charAt(0) + type.name().substring(1).toLowerCase(Locale.ENGLISH));
|
||||
|
||||
if (list == null || list.isEmpty()) {
|
||||
continue;
|
||||
@@ -67,17 +74,15 @@ public class SoundManager {
|
||||
SoundGroup subGroup = SoundGroup.getGroup(sound);
|
||||
|
||||
if (subGroup == null) {
|
||||
DisguiseUtilities.getLogger().warning("Invalid sound '" + sound +
|
||||
"'! Must be a minecraft:sound.name or SoundGroup name!");
|
||||
DisguiseUtilities.getLogger().warning("Invalid sound '" + sound + "'! Must be a minecraft:sound.name or SoundGroup name!");
|
||||
continue;
|
||||
}
|
||||
|
||||
Object[] sounds = subGroup.getDisguiseSounds().get(type);
|
||||
|
||||
if (sounds == null) {
|
||||
DisguiseUtilities.getLogger().warning(
|
||||
"Sound group '" + sound + "' does not contain a category for " + type +
|
||||
"! Can't use as default in " + key);
|
||||
DisguiseUtilities.getLogger()
|
||||
.warning("Sound group '" + sound + "' does not contain a category for " + type + "! Can't use as default in " + key);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@@ -359,7 +359,7 @@ public enum LibsMsg {
|
||||
LD_COMMAND_DEBUG(ChatColor.BLUE + "/libsdisguises debug - " + ChatColor.AQUA +
|
||||
"Used to help debug scoreboard issues on a player disguise"),
|
||||
LD_COMMAND_UPLOAD_LOGS(ChatColor.BLUE + "/libsdisguises uploadlogs - " + ChatColor.AQUA +
|
||||
"Uploads latest.log, disguises.yml and config.yml and gives you the link to share. Used when seeking " +
|
||||
"Uploads latest.log, disguises.yml and configs and gives you the link to share. Used when seeking " +
|
||||
"assistance."),
|
||||
SELF_DISGUISE_HIDDEN(ChatColor.GREEN + "Self disguise hidden as it's too tall..");
|
||||
|
||||
|
Reference in New Issue
Block a user