Use the provided Logger instead of System.out and System.err, inform the user how many disguises failed to load. Inform the user how many settings are missing from their config

This commit is contained in:
libraryaddict 2018-08-14 12:42:35 +12:00
parent 53b0491f57
commit f3d8a18e11
10 changed files with 103 additions and 72 deletions

View File

@ -1,11 +1,8 @@
package me.libraryaddict.disguise;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseParser;
import me.libraryaddict.disguise.utilities.*;
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
@ -209,7 +206,7 @@ public class DisguiseConfig {
setModifySeeFriendlyInvisibles(config.getBoolean("Scoreboard.SeeFriendlyInvisibles"));
if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) {
System.out.println("[LibsDisguises] You must purchase the plugin to use saved disguises!");
DisguiseUtilities.getLogger().warning("You must purchase the plugin to use saved disguises!");
}
try {
@ -222,10 +219,29 @@ public class DisguiseConfig {
disablePushing = DisguisePushing.valueOf(option);
}
catch (Exception ex) {
System.out.println("[LibsDisguises] Cannot parse '" + config.getString("SelfDisguisesScoreboard") +
DisguiseUtilities.getLogger().info("Cannot parse '" + config.getString("SelfDisguisesScoreboard") +
"' to a valid option for SelfDisguisesTeam");
}
loadCustomDisguises();
int missingConfigs = 0;
for (String key : config.getDefaultSection().getKeys(true)) {
if (config.contains(key, true)) {
continue;
}
missingConfigs++;
}
if (missingConfigs > 0) {
DisguiseUtilities.getLogger().warning(
"Your config is missing " + missingConfigs + " options! Please consider regenerating your config!");
}
}
static void loadCustomDisguises() {
customDisguises.clear();
File disguisesFile = new File("plugins/LibsDisguises/disguises.yml");
@ -241,12 +257,14 @@ public class DisguiseConfig {
return;
}
int failedCustomDisguises = 0;
for (String key : section.getKeys(false)) {
String toParse = section.getString(key);
if (getCustomDisguise(toParse) != null) {
System.err.println(
"[LibsDisguises] Cannot create the custom disguise '" + key + "' as there is a name conflict!");
DisguiseUtilities.getLogger()
.severe("Cannot create the custom disguise '" + key + "' as there is a name conflict!");
continue;
}
@ -257,21 +275,27 @@ public class DisguiseConfig {
customDisguises.put(key, disguise);
System.out.println("[LibsDisguises] Loaded custom disguise " + key);
DisguiseUtilities.getLogger().info("Loaded custom disguise " + key);
}
catch (DisguiseParseException e) {
System.err.println("[LibsDisguises] Error while loading custom disguise '" + key + "'" +
DisguiseUtilities.getLogger().severe("Error while loading custom disguise '" + key + "'" +
(e.getMessage() == null ? "" : ": " + e.getMessage()));
if (e.getMessage() == null)
e.printStackTrace();
failedCustomDisguises++;
}
catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("[LibsDisguises] Loaded " + customDisguises.size() + " custom disguise" +
if (failedCustomDisguises > 0) {
DisguiseUtilities.getLogger().severe("Failed to load " + failedCustomDisguises + " custom disguises");
}
DisguiseUtilities.getLogger().info("Loaded " + customDisguises.size() + " custom disguise" +
(customDisguises.size() == 1 ? "" : "s"));
}

View File

@ -94,8 +94,8 @@ public class DisguiseListener implements Listener {
});
}
catch (Exception ex) {
System.out.print(String
.format("[LibsDisguises] Failed to check for update: %s", ex.getMessage()));
DisguiseUtilities.getLogger().warning(String
.format("Failed to check for update: %s", ex.getMessage()));
}
}
}, 0, (20 * 60 * 60 * 6)); // Check every 6 hours

View File

@ -44,18 +44,15 @@ public class LibsDisguises extends JavaPlugin {
if (ReflectionManager.getMinecraftVersion().startsWith("1.13")) {
if (!LibsPremium.isPremium()) {
System.out.println("[LibsDisguises] You must purchase the plugin to use 1.13!");
System.out.println(
"[LibsDisguises] This will be released free two weeks after all bugs have been fixed!");
System.out.println(
"[LibsDisguises] If you've already purchased the plugin, place the purchased jar inside the " +
"Lib's Disguises plugin folder");
getLogger().severe("You must purchase the plugin to use 1.13!");
getLogger().severe("This will be released free two weeks after all bugs have been fixed!");
getLogger().severe("If you've already purchased the plugin, place the purchased jar inside the " +
"Lib's Disguises plugin folder");
return;
}
} else {
System.out.println(
"[LibsDisguises] You're using the wrong version of Lib's Disguises for your server! This is " +
"intended for 1.13!");
getLogger().severe("You're using the wrong version of Lib's Disguises for your server! This is " +
"intended for 1.13!");
return;
}
@ -368,7 +365,7 @@ public class LibsDisguises extends JavaPlugin {
}
if (watcherClass == null) {
System.err.println("Error loading " + disguiseType.name() + ", FlagWatcher not assigned");
getLogger().severe("Error loading " + disguiseType.name() + ", FlagWatcher not assigned");
continue;
}
@ -510,11 +507,9 @@ public class LibsDisguises extends JavaPlugin {
MetaIndex flagType = MetaIndex.getFlag(watcherClass, watch.getIndex());
if (flagType == null) {
System.err.println("[LibsDisguises] MetaIndex not found for " + disguiseType + "! Index: " +
watch.getIndex());
System.err.println("[LibsDisguises] Value: " + watch.getRawValue() + " (" +
watch.getRawValue().getClass() + ") (" + nmsEntity.getClass() + ") & " +
watcherClass.getSimpleName());
getLogger().severe("MetaIndex not found for " + disguiseType + "! Index: " + watch.getIndex());
getLogger().severe("Value: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() +
") (" + nmsEntity.getClass() + ") & " + watcherClass.getSimpleName());
continue;
}
@ -525,19 +520,19 @@ public class LibsDisguises extends JavaPlugin {
if (ourValue != nmsValue &&
((ourValue == null || nmsValue == null) || ourValue.getClass() != nmsValue.getClass())) {
System.err.println("[LibsDisguises] MetaIndex mismatch for " + disguiseType + "! Index: " +
watch.getIndex());
System.err.println("[LibsDisguises] MetaIndex: " + flagType.getDefault() + " (" +
getLogger().severe("[MetaIndex mismatch for " + disguiseType + "! Index: " + watch.getIndex());
getLogger().severe("MetaIndex: " + flagType.getDefault() + " (" +
flagType.getDefault().getClass() + ") (" + nmsEntity.getClass() + ") & " +
watcherClass.getSimpleName());
System.err.println("[LibsDisguises] Minecraft: " + watch.getRawValue() + " (" +
watch.getRawValue().getClass() + ")");
getLogger().severe("Minecraft: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() +
")");
}
}
for (MetaIndex index : indexes) {
System.out.println("[LibsDisguises] " + disguiseType + " has MetaIndex remaining! " +
index.getFlagWatcher().getSimpleName() + " at index " + index.getIndex());
getLogger().warning(
disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() +
" at index " + index.getIndex());
}
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
@ -566,13 +561,12 @@ public class LibsDisguises extends JavaPlugin {
disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
}
catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) {
System.out.print("[LibsDisguises] Uh oh! Trouble while making values for the disguise " +
disguiseType.name() + "!");
System.out.print("[LibsDisguises] Before reporting this error, " +
getLogger().severe("Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
getLogger().severe("Before reporting this error, " +
"please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
System.out.print("[LibsDisguises] Development builds are available at (ProtocolLib) " +
"http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) http://server.o2gaming" +
".com:8080/job/LibsDisguises%201.9+/");
getLogger().severe("Development builds are available at (ProtocolLib) " +
"http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) https://ci.md-5" +
".net/job/LibsDisguises/");
ex.printStackTrace();
}

View File

@ -9,6 +9,7 @@ import com.comphenix.protocol.wrappers.nbt.NbtBase;
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import com.comphenix.protocol.wrappers.nbt.NbtType;
import me.libraryaddict.disguise.disguisetypes.watchers.*;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Particle;
@ -389,10 +390,10 @@ public class MetaIndex<Y> {
continue;
if (found != null) {
System.err.println(
entry.getKey().getSimpleName() + " has multiple FlagType's registered for the index " +
i + " (" + type.getFlagWatcher().getSimpleName() + ", " +
found.getFlagWatcher().getSimpleName() + ")");
DisguiseUtilities.getLogger().severe(entry.getKey().getSimpleName() +
" has multiple FlagType's registered for the index " + i + " (" +
type.getFlagWatcher().getSimpleName() + ", " + found.getFlagWatcher().getSimpleName() +
")");
continue loop;
}
@ -402,11 +403,13 @@ public class MetaIndex<Y> {
if (found != null)
continue;
System.err.println(entry.getKey().getSimpleName() + " has no FlagType registered for the index " + i);
DisguiseUtilities.getLogger()
.severe(entry.getKey().getSimpleName() + " has no FlagType registered for the index " + i);
}
}
}
@Deprecated
public static void printMetadata() {
ArrayList<String> toPrint = new ArrayList<>();
@ -501,8 +504,8 @@ public class MetaIndex<Y> {
continue;
}
System.err.println(
"[LibsDisguises] MetaIndex " + metaIndex.getFlagWatcher().getSimpleName() + " at index " +
DisguiseUtilities.getLogger()
.severe("MetaIndex " + metaIndex.getFlagWatcher().getSimpleName() + " at index " +
metaIndex.getIndex() + " has already registered this! (" + metaIndex.getDefault() +
"," + index.getDefault() + ")");
}

View File

@ -276,7 +276,7 @@ public enum DisguiseSound {
Object soundEffect = ReflectionManager.getCraftSound(sound);
if (disguiseSounds.containsKey(soundEffect)) {
System.out.println("Already doing " + sound);
DisguiseUtilities.getLogger().severe("Already doing " + sound);
}
disguiseSounds.put(soundEffect, type);

View File

@ -50,6 +50,7 @@ import java.io.FileReader;
import java.io.PrintWriter;
import java.lang.reflect.*;
import java.util.*;
import java.util.logging.Logger;
import java.util.regex.Pattern;
public class DisguiseUtilities {
@ -111,7 +112,7 @@ public class DisguiseUtilities {
if (!DisguiseConfig.isSaveEntityDisguises() && !DisguiseConfig.isSavePlayerDisguises())
return;
System.out.println("[LibsDisguises] Now saving disguises..");
getLogger().info("Now saving disguises..");
for (HashSet<TargetedDisguise> list : disguisesInUse.values()) {
for (TargetedDisguise disg : list) {
@ -127,7 +128,7 @@ public class DisguiseUtilities {
}
}
System.out.println("[LibsDisguises] Saved disguises.");
getLogger().info("Saved disguises.");
}
public static boolean hasGameProfile(String playername) {
@ -239,7 +240,7 @@ public class DisguiseUtilities {
return gson.fromJson(cached, Disguise[].class);
}
catch (Exception e) {
System.out.println("Malformed disguise for " + entityUUID);
getLogger().severe("Malformed disguise for " + entityUUID);
e.printStackTrace();
}
@ -795,8 +796,8 @@ public class DisguiseUtilities {
catch (Exception e) {
runnables.remove(playerName);
System.out.print("[LibsDisguises] Error when fetching " + playerName +
"'s uuid from mojang: " + e.getMessage());
getLogger().severe("Error when fetching " + playerName + "'s uuid from mojang: " +
e.getMessage());
}
}
});
@ -1513,6 +1514,10 @@ public class DisguiseUtilities {
return libsDisguises;
}
public static Logger getLogger() {
return getPlugin().getLogger();
}
/**
* Method to send a packet to the self disguise, translate his entity ID to the fake id.
*/

View File

@ -175,7 +175,7 @@ public enum LibsMsg {
public String get(Object... strings) {
if (StringUtils.countMatches(getRaw(), "%s") != strings.length) {
System.out.println("[LibsDisguises] Mismatch in messages, incorrect parameters supplied for " + name() +
DisguiseUtilities.getLogger().severe("Mismatch in messages, incorrect parameters supplied for " + name() +
". Please inform plugin author.");
}

View File

@ -58,11 +58,12 @@ public class LibsPremium {
thisPluginIsPaidFor = (Boolean) m.invoke(null);
if (isPremium()) {
System.out.println("[LibsDisguises] Found a premium Lib's Disguises jar, premium enabled!");
DisguiseUtilities.getLogger().info("Found a premium Lib's Disguises jar, premium enabled!");
break;
} else {
System.out.println("[LibsDisguises] You have a non-premium Lib's Disguises jar in the folder!");
DisguiseUtilities.getLogger()
.warning("You have a non-premium Lib's Disguises jar (" + file.getName() + ") in the folder!");
}
}
catch (Exception ex) {

View File

@ -36,7 +36,7 @@ public enum TranslateType {
}
if (!LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) {
System.out.println("[LibsDisguises] You must purchase the plugin to use translations!");
DisguiseUtilities.getLogger().severe("You must purchase the plugin to use translations!");
}
TranslateFiller.fillConfigs();
@ -74,11 +74,11 @@ public enum TranslateType {
translated.clear();
if (LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) {
System.out.println("[LibsDisguises] Loading translations: " + name());
DisguiseUtilities.getLogger().info("Loading translations: " + name());
}
if (!getFile().exists()) {
System.out.println("[LibsDisguises] Translations for " + name() + " missing! Skipping...");
DisguiseUtilities.getLogger().info("Translations for " + name() + " missing! Skipping...");
return;
}
@ -93,22 +93,23 @@ public enum TranslateType {
String value = config.getString(key);
if (value == null) {
System.err.println("Translation for " + name() + " has a null value for the key '" + key + "'");
DisguiseUtilities.getLogger()
.severe("Translation for " + name() + " has a null value for the key '" + key + "'");
} else {
String newKey = ChatColor.translateAlternateColorCodes('&', key);
if (translated.containsKey(newKey)) {
if (dupes++ < 5) {
System.out.println(
"[LibsDisguises] Alert! Duplicate translation entry for " + key + " in " + name() +
DisguiseUtilities.getLogger()
.severe("Alert! Duplicate translation entry for " + key + " in " + name() +
" translations!");
continue;
} else {
System.out.println(
"[LibsDisguises] Too many duplicated keys! It's likely that this file was mildly " +
DisguiseUtilities.getLogger()
.severe("Too many duplicated keys! It's likely that this file was mildly " +
"corrupted by a previous bug!");
System.out.println(
"[LibsDisguises] Delete the file, or you can remove every line after the first " +
DisguiseUtilities.getLogger()
.severe("Delete the file, or you can remove every line after the first " +
"duplicate message!");
break;
}
@ -123,7 +124,7 @@ public enum TranslateType {
}
if (LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) {
System.out.println("[LibsDisguises] Loaded " + translated.size() + " translations for " + name());
DisguiseUtilities.getLogger().info("Loaded " + translated.size() + " translations for " + name());
}
}

View File

@ -37,19 +37,22 @@ public class UpdateChecker {
*/
private String getSpigotVersion() {
try {
HttpURLConnection con = (HttpURLConnection) new URL("https://www.spigotmc.org/api/general.php").openConnection();
HttpURLConnection con = (HttpURLConnection) new URL("https://www.spigotmc.org/api/general.php")
.openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.getOutputStream().write(
("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=32453").getBytes("UTF-8"));
con.getOutputStream()
.write(("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=32453")
.getBytes("UTF-8"));
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
if (version.length() <= 10) {
return version;
}
}
catch (Exception ex) {
System.out.print("[LibsDisguises] Failed to check for a update on spigot.");
DisguiseUtilities.getLogger().warning("Failed to check for a update on spigot.");
}
return null;
}