From 73ad900387e65cd965764180f9e12c361a8e958c Mon Sep 17 00:00:00 2001 From: Pim van der Loos Date: Sun, 28 Mar 2021 13:01:08 +0200 Subject: [PATCH] Enable more style checks and fix violations --- checkstyle.xml | 68 ++++++++++++++++++- .../armoredElytra/ArmoredElytra.java | 4 +- .../armoredElytra/handlers/LoginHandler.java | 7 +- .../lib/armorequip/ArmorEquipEvent.java | 4 +- .../lib/armorequip/ArmorListener.java | 15 ++-- .../lib/armorequip/ArmorType.java | 2 +- .../armoredElytra/util/ArmorTierName.java | 4 -- .../armoredElytra/util/UpdateChecker.java | 18 ++--- .../armoredElytra/util/UpdateManager.java | 3 +- .../armoredElytra/util/XMaterial.java | 3 +- 10 files changed, 100 insertions(+), 28 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 71c5fe0..c019309 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -6,14 +6,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + diff --git a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java index d998425..7a19fb6 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java @@ -162,7 +162,9 @@ public class ArmoredElytra extends JavaPlugin implements Listener private void readMessages() { - armorTierNames.put(ArmorTier.NONE, new ArmorTierName("NONE", "NONE")); // Shouldn't be used. + // Shouldn't be used. + armorTierNames.put(ArmorTier.NONE, new ArmorTierName("NONE", "NONE")); + armorTierNames.put(ArmorTier.LEATHER, new ArmorTierName(messages.getString(Message.TIER_LEATHER), messages.getString(Message.TIER_SHORT_LEATHER))); armorTierNames.put(ArmorTier.GOLD, new ArmorTierName(messages.getString(Message.TIER_GOLD), diff --git a/src/main/java/nl/pim16aap2/armoredElytra/handlers/LoginHandler.java b/src/main/java/nl/pim16aap2/armoredElytra/handlers/LoginHandler.java index 555e428..921670e 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/handlers/LoginHandler.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/handlers/LoginHandler.java @@ -1,5 +1,6 @@ package nl.pim16aap2.armoredElytra.handlers; +import nl.pim16aap2.armoredElytra.ArmoredElytra; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -7,16 +8,14 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.scheduler.BukkitRunnable; -import nl.pim16aap2.armoredElytra.ArmoredElytra; - public class LoginHandler implements Listener { private final ArmoredElytra plugin; - private final String message; + private final String message; public LoginHandler(ArmoredElytra plugin, String message) { - this.plugin = plugin; + this.plugin = plugin; this.message = message; } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/lib/armorequip/ArmorEquipEvent.java b/src/main/java/nl/pim16aap2/armoredElytra/lib/armorequip/ArmorEquipEvent.java index 5d18d00..7e64d40 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/lib/armorequip/ArmorEquipEvent.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/lib/armorequip/ArmorEquipEvent.java @@ -42,7 +42,7 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable * * @return A list of handlers handling this event. */ - public final static HandlerList getHandlerList() + public static HandlerList getHandlerList() { return handlers; } @@ -120,7 +120,7 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable } public enum EquipMethod - {// These have got to be the worst documentations ever. + { /** * When you shift click an armor piece to equip or unequip */ diff --git a/src/main/java/nl/pim16aap2/armoredElytra/lib/armorequip/ArmorListener.java b/src/main/java/nl/pim16aap2/armoredElytra/lib/armorequip/ArmorListener.java index a98e101..cb84051 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/lib/armorequip/ArmorListener.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/lib/armorequip/ArmorListener.java @@ -41,7 +41,8 @@ public class ArmorListener implements Listener if (e.isCancelled()) return; if (e.getAction() == InventoryAction.NOTHING) - return;// Why does this get called if nothing happens?? + // Why does this get called if nothing happens?? + return; if (e.getClick().equals(ClickType.SHIFT_LEFT) || e.getClick().equals(ClickType.SHIFT_RIGHT)) shift = true; if (e.getClick().equals(ClickType.NUMBER_KEY)) @@ -102,7 +103,8 @@ public class ArmorListener implements Listener ItemStack oldArmorPiece = e.getCurrentItem(); if (numberkey) if (e.getClickedInventory().getType().equals(InventoryType.PLAYER)) - { // Prevents shit in the 2by2 crafting + { + // Prevents shit in the 2by2 crafting // e.getClickedInventory() == The players inventory // e.getHotBarButton() == key people are pressing to equip or unequip the item // to or from. @@ -111,7 +113,8 @@ public class ArmorListener implements Listener // slot ;-; ItemStack hotbarItem = e.getClickedInventory().getItem(e.getHotbarButton()); if (!isAirOrNull(hotbarItem)) - { // Equipping + { + // Equipping newArmorType = ArmorType.matchType(hotbarItem); newArmorPiece = hotbarItem; oldArmorPiece = e.getClickedInventory().getItem(e.getSlot()); @@ -150,7 +153,8 @@ public class ArmorListener implements Listener { final Player player = e.getPlayer(); if (e.getClickedBlock() != null && e.getAction() == Action.RIGHT_CLICK_BLOCK) - { // Having both of these checks is useless, might as well do it though. + { + // Having both of these checks is useless, might as well do it though. // Some blocks have actions when you right click them which stops the client // from equipping the armor in hand. Material mat = e.getClickedBlock().getType(); @@ -191,7 +195,8 @@ public class ArmorListener implements Listener // Can't replace armor using this method making getCursor() useless. ArmorType type = ArmorType.matchType(event.getOldCursor()); if (event.getRawSlots().isEmpty()) - return;// Idk if this will ever happen + // Idk if this will ever happen + return; if (type != null && type.getSlot() == event.getRawSlots().stream().findFirst().orElse(0)) { ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent((Player) event.getWhoClicked(), EquipMethod.DRAG, diff --git a/src/main/java/nl/pim16aap2/armoredElytra/lib/armorequip/ArmorType.java b/src/main/java/nl/pim16aap2/armoredElytra/lib/armorequip/ArmorType.java index 43cb5fb..4059796 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/lib/armorequip/ArmorType.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/lib/armorequip/ArmorType.java @@ -27,7 +27,7 @@ public enum ArmorType * @param itemStack The ItemStack to parse the type of. * @return The parsed ArmorType. (null if none were found.) */ - public final static ArmorType matchType(final ItemStack itemStack) + public static final ArmorType matchType(final ItemStack itemStack) { if (itemStack == null || itemStack.getType().equals(Material.AIR)) return null; diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTierName.java b/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTierName.java index ea397f9..9457977 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTierName.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTierName.java @@ -1,10 +1,6 @@ -/** - * - */ package nl.pim16aap2.armoredElytra.util; /** - * * @author Pim */ public class ArmorTierName diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/UpdateChecker.java b/src/main/java/nl/pim16aap2/armoredElytra/util/UpdateChecker.java index 54ca770..a285571 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/UpdateChecker.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/UpdateChecker.java @@ -36,7 +36,7 @@ import java.util.regex.Pattern; */ public final class UpdateChecker { - public static final VersionScheme VERSION_SCHEME_DECIMAL = (first, second) -> + public static final IVersionScheme VERSION_SCHEME_DECIMAL = (first, second) -> { String[] firstSplit = splitVersionInfo(first), secondSplit = splitVersionInfo(second); if (firstSplit == null || secondSplit == null) @@ -65,9 +65,9 @@ public final class UpdateChecker private final ArmoredElytra plugin; private final int pluginID; - private final VersionScheme versionScheme; + private final IVersionScheme versionScheme; - private UpdateChecker(final ArmoredElytra plugin, final int pluginID, final VersionScheme versionScheme) + private UpdateChecker(final ArmoredElytra plugin, final int pluginID, final IVersionScheme versionScheme) { this.plugin = plugin; this.pluginID = pluginID; @@ -186,7 +186,7 @@ public final class UpdateChecker * @param versionScheme a custom version scheme parser. Cannot be null * @return the UpdateChecker instance */ - public static UpdateChecker init(final ArmoredElytra plugin, final int pluginID, final VersionScheme versionScheme) + public static UpdateChecker init(final ArmoredElytra plugin, final int pluginID, final IVersionScheme versionScheme) { Preconditions.checkArgument(pluginID > 0, "Plugin ID must be greater than 0"); @@ -237,7 +237,7 @@ public final class UpdateChecker * A functional interface to compare two version Strings with similar version schemes. */ @FunctionalInterface - public interface VersionScheme + public interface IVersionScheme { /** @@ -259,9 +259,11 @@ public final class UpdateChecker { /** - * A new update is available for download on SpigotMC. + * A new update is available for download. + *

+ * This is the only reason that requires an update. */ - NEW_UPDATE, // The only reason that requires an update + NEW_UPDATE, /** * A successful connection to the SpiGet API could not be established. @@ -311,7 +313,7 @@ public final class UpdateChecker private final String newestVersion; private final long age; - { // An actual use for initializer blocks. This is madness! + { lastResult = this; } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/UpdateManager.java b/src/main/java/nl/pim16aap2/armoredElytra/util/UpdateManager.java index bfefcd7..640c854 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/UpdateManager.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/UpdateManager.java @@ -70,7 +70,8 @@ public final class UpdateManager { checkForUpdates(); } - }.runTaskTimer(plugin, 0L, 864000L); // Run immediately, then every 12 hours. + // Run immediately, then every 12 hours. + }.runTaskTimer(plugin, 0L, 864000L); } else { diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/XMaterial.java b/src/main/java/nl/pim16aap2/armoredElytra/util/XMaterial.java index 334b7fd..c01328f 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/XMaterial.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/XMaterial.java @@ -729,7 +729,8 @@ public enum XMaterial for (String legacy : this.legacy) { if (legacy.isEmpty()) - break; // Left-side suggestion list + // Left-side suggestion list + break; if (name.equals(legacy)) return true; }