Fixes some bugs
Fixes a problem in color parsing where a &# code would throw an exception. Makes sure to remove non-numerical characters in plugin versions to prevent an exception.
This commit is contained in:
		@@ -79,13 +79,17 @@ public final class ColorHelper {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        Pattern pattern;
 | 
					        Pattern pattern;
 | 
				
			||||||
        if (requireAmpersandInHexColors) {
 | 
					        if (requireAmpersandInHexColors) {
 | 
				
			||||||
            pattern = Pattern.compile("(&#[a-fA-F0-9]{6})");
 | 
					            pattern = Pattern.compile("&(#[a-fA-F0-9]{6})");
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            pattern = Pattern.compile("(&?#[a-fA-F0-9]{6})");
 | 
					            pattern = Pattern.compile("&?(#[a-fA-F0-9]{6})");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Matcher matcher = pattern.matcher(message);
 | 
					        Matcher matcher = pattern.matcher(message);
 | 
				
			||||||
        while (matcher.find()) {
 | 
					        while (matcher.find()) {
 | 
				
			||||||
            message = message.replace(matcher.group(), "" + ChatColor.of(matcher.group()));
 | 
					            try {
 | 
				
			||||||
 | 
					                message = message.replace(matcher.group(), "" + ChatColor.of(matcher.group()));
 | 
				
			||||||
 | 
					            } catch (IllegalArgumentException ignored) {
 | 
				
			||||||
 | 
					                //Something was matched that wasn't a proper color after all. Ignore it.
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return message;
 | 
					        return message;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -86,6 +86,8 @@ public final class UpdateChecker {
 | 
				
			|||||||
     * @return <p>True if the new version is higher than the old one</p>
 | 
					     * @return <p>True if the new version is higher than the old one</p>
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public static boolean isVersionHigher(String oldVersion, String newVersion) {
 | 
					    public static boolean isVersionHigher(String oldVersion, String newVersion) {
 | 
				
			||||||
 | 
					        oldVersion = removeNonNumericCharacters(oldVersion);
 | 
				
			||||||
 | 
					        newVersion = removeNonNumericCharacters(newVersion);
 | 
				
			||||||
        String[] oldVersionParts = oldVersion.split("\\.");
 | 
					        String[] oldVersionParts = oldVersion.split("\\.");
 | 
				
			||||||
        String[] newVersionParts = newVersion.split("\\.");
 | 
					        String[] newVersionParts = newVersion.split("\\.");
 | 
				
			||||||
        int versionLength = Math.max(oldVersionParts.length, newVersionParts.length);
 | 
					        int versionLength = Math.max(oldVersionParts.length, newVersionParts.length);
 | 
				
			||||||
@@ -99,4 +101,14 @@ public final class UpdateChecker {
 | 
				
			|||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Removes all characters except numbers and the "." character from the given version string
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param versionString <p>The version string to clean</p>
 | 
				
			||||||
 | 
					     * @return <p>The string with non-numeric characters replaced</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private static String removeNonNumericCharacters(String versionString) {
 | 
				
			||||||
 | 
					        return versionString.replaceAll("[^0-9.]", "");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user