From c8ba1b5471a1e3443615ee1efc1335031b562cd4 Mon Sep 17 00:00:00 2001 From: Pim van der Loos Date: Sun, 28 Mar 2021 11:03:39 +0200 Subject: [PATCH] Add Checkstyle - Added Checkstyle. Currently only line length is enabled. --- checkstyle.xml | 9 ++++++++ pom.xml | 22 +++++++++++++++++++ .../armoredElytra/ArmoredElytra.java | 3 ++- .../armoredElytra/util/ArmorTier.java | 3 ++- .../armoredElytra/util/ConfigLoader.java | 22 ++++++++++++------- .../armoredElytra/util/ConfigOption.java | 16 ++++++++------ .../armoredElytra/util/XMaterial.java | 18 ++++++++++----- 7 files changed, 70 insertions(+), 23 deletions(-) create mode 100644 checkstyle.xml diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 0000000..f974fed --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/pom.xml b/pom.xml index acea152..7de594d 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,12 @@ CodeMC https://repo.codemc.org/repository/maven-public/ + + + + checkstyle + https://mvnrepository.com/artifact/com.puppycrawl.tools/checkstyle + @@ -89,6 +95,22 @@ 8 + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.1.2 + + + com.puppycrawl.tools + checkstyle + 8.41 + + + + checkstyle.xml + + diff --git a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java index c141784..d998425 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java @@ -88,7 +88,8 @@ public class ArmoredElytra extends JavaPlugin implements Listener else // Y u do dis? :( myLogger(Level.INFO, - "Stats disabled, not loading stats :(... Please consider enabling it! I am a simple man, seeing higher user numbers helps me stay motivated!"); + "Stats disabled, not loading stats :(... Please consider enabling it! I am a simple man, " + + "seeing higher user numbers helps me stay motivated!"); Bukkit.getPluginManager().registerEvents(new EventHandlers(this), this); getCommand("ArmoredElytra").setExecutor(new CommandHandler(this)); diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java b/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java index 4bd6099..99b5922 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java @@ -101,7 +101,8 @@ public enum ArmorTier // This value is the same as netherite's tier. However, with the introduction of the NETHERITE armor tier, // a new system was introduced that doesn't rely on the armor value for determining the armortier. // Therefore, when using the old backup system, it is always going to be the diamond tier instead. - // While no new elytras cna be created using the old system, some may still be around from when it was still used. + // While no new elytras can be created using the old system, some may still + // be around from when it was still used. armorValueMap.put(ArmorTier.DIAMOND.armor, ArmorTier.DIAMOND); } } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/ConfigLoader.java b/src/main/java/nl/pim16aap2/armoredElytra/util/ConfigLoader.java index dc1567f..73a3343 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/ConfigLoader.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/ConfigLoader.java @@ -92,7 +92,8 @@ public class ConfigLoader String[] bStatsComment = { "Allow this plugin to send (anonymised) stats using bStats. Please consider keeping it enabled.", - "It has a negligible impact on performance and more users on stats keeps me more motivated to support this plugin!" + "It has a negligible impact on performance and more users on stats keeps me more motivated " + + "to support this plugin!" }; String[] debugComment = { @@ -101,8 +102,10 @@ public class ConfigLoader String[] uninstallComment = { "Setting this to true will disable this plugin and remove any armored elytras it can find.", - "It will check player's inventories and their end chest upon login and any regular chest when it is opened.", - "This means it will take a while for all armored elytras to be removed from your server, but it doesn't take up ", + "It will check player's inventories and their end chest upon login and any regular" + + " chest when it is opened.", + "This means it will take a while for all armored elytras to be removed from your server, " + + "but it doesn't take up ", "a lot of resources, so you can just leave the plugin enabled and ignore it.", "Please do not forget to MAKE A BACKUP before enabling this option!" }; @@ -115,12 +118,15 @@ public class ConfigLoader "Allow more than 1 type of protection enchantment on a single armored elytra. ", "If true, you could have both blast protection and environmental protection at the same time.", "If false, the second enchantment (while crafting) will override the first. So combining an armored", - "elytra that has the protection enchantment with an enchanted book that has the blast protection enchantment", - "would result in removal of the protection enchantment and addition of the blast protection enchantment." + "elytra that has the protection enchantment with an enchanted book that " + + "has the blast protection enchantment", + "would result in removal of the protection enchantment and addition of the " + + "blast protection enchantment." }; String[] permissionsComment = { - "Globally bypass permissions for wearing and/or crafting amored elytras. Useful if permissions are unavailable." + "Globally bypass permissions for wearing and/or crafting amored elytras.", + "Useful if permissions are unavailable." }; String[] craftingInSmithingTableComment = { @@ -257,8 +263,8 @@ public class ConfigLoader } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, - "Could not save config.yml! Please contact pim16aap2 and show him the following code:"); + Bukkit.getLogger().log(Level.SEVERE, "Could not save config.yml! " + + "Please contact pim16aap2 and show him the following code:"); e.printStackTrace(); } } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/ConfigOption.java b/src/main/java/nl/pim16aap2/armoredElytra/util/ConfigOption.java index a7a85fe..08c9465 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/ConfigOption.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/ConfigOption.java @@ -1,10 +1,9 @@ package nl.pim16aap2.armoredElytra.util; -import java.util.List; - +import nl.pim16aap2.armoredElytra.ArmoredElytra; import org.bukkit.configuration.file.FileConfiguration; -import nl.pim16aap2.armoredElytra.ArmoredElytra; +import java.util.List; /* This class represent a configuration option. * The general format is: the comment followed by @@ -21,7 +20,8 @@ public class ConfigOption private final V defaultValue; private final String[] comment; - public ConfigOption(ArmoredElytra plugin, FileConfiguration config, String optionName, V defaultValue, String[] comment) + public ConfigOption(ArmoredElytra plugin, FileConfiguration config, String optionName, V defaultValue, + String[] comment) { this.plugin = plugin; this.config = config; @@ -40,7 +40,8 @@ public class ConfigOption } catch (Exception e) { - plugin.myLogger(java.util.logging.Level.WARNING, "Failed to read config value of: \"" + optionName + "\"! Using default value instead!"); + plugin.myLogger(java.util.logging.Level.WARNING, "Failed to read config value of: \"" + optionName + + "\"! Using default value instead!"); plugin.myLogger(java.util.logging.Level.WARNING, Util.exceptionToString(e)); value = defaultValue; } @@ -76,11 +77,12 @@ public class ConfigOption builder.append("\n"); int listSize = ((List) value).size(); for (int index = 0; index < listSize; ++index) - builder.append(" - " + ((List) value).get(index) + (index == listSize - 1 ? "" : "\n")); // Don't print newline at the end + // Don't print newline at the end + builder.append(" - " + ((List) value).get(index) + (index == listSize - 1 ? "" : "\n")); string += builder.toString(); } else - string += value.toString(); + string += value.toString(); return string; } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/XMaterial.java b/src/main/java/nl/pim16aap2/armoredElytra/util/XMaterial.java index 0dfc7f0..334b7fd 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/XMaterial.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/XMaterial.java @@ -55,8 +55,10 @@ import java.util.regex.Pattern; * Pre-flattening: https://minecraft.gamepedia.com/Java_Edition_data_values/Pre-flattening Materials: * https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html Materials (1.12): * https://helpch.at/docs/1.12.2/index.html?org/bukkit/Material.html Material IDs: - * https://minecraft-ids.grahamedgecombe.com/ Material Source Code: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/Material.java - * XMaterial v1: https://www.spigotmc.org/threads/329630/ + * https://minecraft-ids.grahamedgecombe.com/ Material Source Code: + *

+ * https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/Material.java XMaterial + * v1: https://www.spigotmc.org/threads/329630/ * * @author Crypto Morin * @version 5.0.0 @@ -394,8 +396,10 @@ public enum XMaterial boolean duplicated = isDuplicated(name); // Do basic number and boolean checks before accessing more complex enum stuff. - // Maybe we can simplify (ISFLAT || !duplicated) with the (!ISFLAT && duplicated) under it to save a few nanoseconds? - // if (!Boolean.valueOf(Boolean.getBoolean(Boolean.TRUE.toString())).equals(Boolean.FALSE.booleanValue())) return null; + // Maybe we can simplify (ISFLAT || !duplicated) with the (!ISFLAT && duplicated) + // under it to save a few nanoseconds? + // if (!Boolean.valueOf(Boolean.getBoolean(Boolean.TRUE.toString())).equals(Boolean.FALSE.booleanValue())) + // return null; if (data <= 0 && !duplicated) { // Apparently the transform method is more efficient than toJavaUtil() @@ -600,7 +604,8 @@ public enum XMaterial *

* {@code REGEX} Examples *

-     *     {@code "REGEX:^.+_.+_.+$" -> Every Material with 3 underlines or more: SHULKER_SPAWN_EGG, SILVERFISH_SPAWN_EGG, SKELETON_HORSE_SPAWN_EGG}
+     *     {@code "REGEX:^.+_.+_.+$" -> Every Material with 3 underlines or more: SHULKER_SPAWN_EGG,
+     *     SILVERFISH_SPAWN_EGG, SKELETON_HORSE_SPAWN_EGG}
      *     {@code "REGEX:^.{1,3}$" -> Material names that have 3 letters only: BED, MAP, AIR}
      * 
*

@@ -789,7 +794,8 @@ public enum XMaterial } /** - * The data value of this material pre-flattening. + * The data value of this material + * pre-flattening. *

* Can be accessed with {@link ItemStack#getData()} then {@code MaterialData#getData()} or {@link * ItemStack#getDurability()} if not damageable.