Add Checkstyle

- Added Checkstyle. Currently only line length is enabled.
This commit is contained in:
Pim van der Loos 2021-03-28 11:03:39 +02:00
parent 95909f2978
commit c8ba1b5471
No known key found for this signature in database
GPG Key ID: C16F020ADAE6D5A8
7 changed files with 70 additions and 23 deletions

9
checkstyle.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" ?><!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"https://checkstyle.org/dtds/configuration_1_2.dtd">
<module name="Checker">
<module name="LineLength">
<property name="max" value="120"/>
</module>
</module>

22
pom.xml
View File

@ -17,6 +17,12 @@
<id>CodeMC</id> <id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public/</url> <url>https://repo.codemc.org/repository/maven-public/</url>
</repository> </repository>
<!-- checkstyle -->
<repository>
<id>checkstyle</id>
<url>https://mvnrepository.com/artifact/com.puppycrawl.tools/checkstyle</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -89,6 +95,22 @@
<target>8</target> <target>8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.41</version>
</dependency>
</dependencies>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -88,7 +88,8 @@ public class ArmoredElytra extends JavaPlugin implements Listener
else else
// Y u do dis? :( // Y u do dis? :(
myLogger(Level.INFO, 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); Bukkit.getPluginManager().registerEvents(new EventHandlers(this), this);
getCommand("ArmoredElytra").setExecutor(new CommandHandler(this)); getCommand("ArmoredElytra").setExecutor(new CommandHandler(this));

View File

@ -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, // 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. // 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. // 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); armorValueMap.put(ArmorTier.DIAMOND.armor, ArmorTier.DIAMOND);
} }
} }

View File

@ -92,7 +92,8 @@ public class ConfigLoader
String[] bStatsComment = String[] bStatsComment =
{ {
"Allow this plugin to send (anonymised) stats using bStats. Please consider keeping it enabled.", "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 = String[] debugComment =
{ {
@ -101,8 +102,10 @@ public class ConfigLoader
String[] uninstallComment = String[] uninstallComment =
{ {
"Setting this to true will disable this plugin and remove any armored elytras it can find.", "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.", "It will check player's inventories and their end chest upon login and any regular" +
"This means it will take a while for all armored elytras to be removed from your server, but it doesn't take up ", " 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.", "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!" "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. ", "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 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", "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", "elytra that has the protection enchantment with an enchanted book that " +
"would result in removal of the protection enchantment and addition of the blast protection enchantment." "has the blast protection enchantment",
"would result in removal of the protection enchantment and addition of the " +
"blast protection enchantment."
}; };
String[] permissionsComment = 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 = String[] craftingInSmithingTableComment =
{ {
@ -257,8 +263,8 @@ public class ConfigLoader
} }
catch (IOException e) catch (IOException e)
{ {
Bukkit.getLogger().log(Level.SEVERE, Bukkit.getLogger().log(Level.SEVERE, "Could not save config.yml! " +
"Could not save config.yml! Please contact pim16aap2 and show him the following code:"); "Please contact pim16aap2 and show him the following code:");
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -1,10 +1,9 @@
package nl.pim16aap2.armoredElytra.util; package nl.pim16aap2.armoredElytra.util;
import java.util.List; import nl.pim16aap2.armoredElytra.ArmoredElytra;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import nl.pim16aap2.armoredElytra.ArmoredElytra; import java.util.List;
/* This class represent a configuration option. /* This class represent a configuration option.
* The general format is: the comment followed by * The general format is: the comment followed by
@ -21,7 +20,8 @@ public class ConfigOption<V>
private final V defaultValue; private final V defaultValue;
private final String[] comment; 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.plugin = plugin;
this.config = config; this.config = config;
@ -40,7 +40,8 @@ public class ConfigOption<V>
} }
catch (Exception e) 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)); plugin.myLogger(java.util.logging.Level.WARNING, Util.exceptionToString(e));
value = defaultValue; value = defaultValue;
} }
@ -76,11 +77,12 @@ public class ConfigOption<V>
builder.append("\n"); builder.append("\n");
int listSize = ((List<?>) value).size(); int listSize = ((List<?>) value).size();
for (int index = 0; index < listSize; ++index) 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(); string += builder.toString();
} }
else else
string += value.toString(); string += value.toString();
return string; return string;
} }

View File

@ -55,8 +55,10 @@ import java.util.regex.Pattern;
* Pre-flattening: https://minecraft.gamepedia.com/Java_Edition_data_values/Pre-flattening Materials: * 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://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://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 * https://minecraft-ids.grahamedgecombe.com/ Material Source Code:
* XMaterial v1: https://www.spigotmc.org/threads/329630/ * <p>
* 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 * @author Crypto Morin
* @version 5.0.0 * @version 5.0.0
@ -394,8 +396,10 @@ public enum XMaterial
boolean duplicated = isDuplicated(name); boolean duplicated = isDuplicated(name);
// Do basic number and boolean checks before accessing more complex enum stuff. // 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? // Maybe we can simplify (ISFLAT || !duplicated) with the (!ISFLAT && duplicated)
// if (!Boolean.valueOf(Boolean.getBoolean(Boolean.TRUE.toString())).equals(Boolean.FALSE.booleanValue())) return null; // 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) if (data <= 0 && !duplicated)
{ {
// Apparently the transform method is more efficient than toJavaUtil() // Apparently the transform method is more efficient than toJavaUtil()
@ -600,7 +604,8 @@ public enum XMaterial
* <p> * <p>
* <b>{@code REGEX} Examples</b> * <b>{@code REGEX} Examples</b>
* <pre> * <pre>
* {@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} * {@code "REGEX:^.{1,3}$" -> Material names that have 3 letters only: BED, MAP, AIR}
* </pre> * </pre>
* <p> * <p>
@ -789,7 +794,8 @@ public enum XMaterial
} }
/** /**
* The data value of this material <a href="https://minecraft.gamepedia.com/Java_Edition_data_values/Pre-flattening">pre-flattening</a>. * The data value of this material
* <a href="https://minecraft.gamepedia.com/Java_Edition_data_values/Pre-flattening">pre-flattening</a>.
* <p> * <p>
* Can be accessed with {@link ItemStack#getData()} then {@code MaterialData#getData()} or {@link * Can be accessed with {@link ItemStack#getData()} then {@code MaterialData#getData()} or {@link
* ItemStack#getDurability()} if not damageable. * ItemStack#getDurability()} if not damageable.