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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user