From 4b5de17bb61a108820545f117928e14899ab0f86 Mon Sep 17 00:00:00 2001 From: Pim van der Loos Date: Thu, 18 Apr 2019 17:11:18 +0200 Subject: [PATCH] Fix formating - Removed all remaining tabs (not sure how to got through the last cleanup). - Updated some comments. --- .../handlers/FlyDurabilityHandler.java | 30 ++--- .../nbtEditor/GetArmorValueOld.java | 1 - .../armoredElytra/nbtEditor/NBTEditor.java | 8 +- .../pim16aap2/armoredElytra/util/Action.java | 2 +- .../armoredElytra/util/ArmorTier.java | 30 ++--- .../armoredElytra/util/Messages.java | 116 +++++++++--------- .../pim16aap2/armoredElytra/util/Update.java | 4 +- .../nl/pim16aap2/armoredElytra/util/Util.java | 32 ++--- 8 files changed, 110 insertions(+), 113 deletions(-) diff --git a/src/main/java/nl/pim16aap2/armoredElytra/handlers/FlyDurabilityHandler.java b/src/main/java/nl/pim16aap2/armoredElytra/handlers/FlyDurabilityHandler.java index 626d190..f0632b5 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/handlers/FlyDurabilityHandler.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/handlers/FlyDurabilityHandler.java @@ -10,21 +10,21 @@ import nl.pim16aap2.armoredElytra.util.ArmorTier; public class FlyDurabilityHandler implements Listener { - private final NBTEditor nbtEditor; + private final NBTEditor nbtEditor; - public FlyDurabilityHandler(NBTEditor nbtEditor) - { - this.nbtEditor = nbtEditor; - } + public FlyDurabilityHandler(NBTEditor nbtEditor) + { + this.nbtEditor = nbtEditor; + } - // Do not decrease elytra durability while flying. This also cancels durability decrease when - // it should (i.e. getting hit) while flying, but I don't really care. - @EventHandler - public void onItemDamage(PlayerItemDamageEvent e) - { - if (e.getItem().getType() == Material.ELYTRA) - if (nbtEditor.getArmorTier(e.getItem()) != ArmorTier.NONE) - if (e.getPlayer().isFlying()) - e.setCancelled(true); - } + // Do not decrease elytra durability while flying. This also cancels durability decrease when + // it should (i.e. getting hit) while flying, but I don't really care. + @EventHandler + public void onItemDamage(PlayerItemDamageEvent e) + { + if (e.getItem().getType() == Material.ELYTRA) + if (nbtEditor.getArmorTier(e.getItem()) != ArmorTier.NONE) + if (e.getPlayer().isFlying()) + e.setCancelled(true); + } } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/GetArmorValueOld.java b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/GetArmorValueOld.java index 3ebe5f3..29d4e97 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/GetArmorValueOld.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/GetArmorValueOld.java @@ -17,7 +17,6 @@ public class GetArmorValueOld implements GetArmorValue int pos = nbtString.indexOf(",Slot:\"chest\",AttributeName:\"generic.armor\""); if (pos > 0) { - // If so, get the value of the generic.armor attribute. pos--; String stringAtPos = nbtString.substring(pos, pos + 1); return Integer.parseInt(stringAtPos); diff --git a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java index d672061..bc88f69 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java @@ -74,8 +74,7 @@ public class NBTEditor return; } - // Old versions use the old format. It is assumed here that all versions from 1.13.2 on will use the - // new format. Might want to put this in a nice interface instead of an ugly boolean. + // Old versions use the old format. It is assumed here that all versions from 1.13.2 on will use the new format. // Spigot's 1.13.1 uses the old format, but 1.13.2 uses the new format. They share the same version number though. if (version.equals("v1_9_R1" ) || version.equals("v1_9_R2" ) || version.equals("v1_10_R1") || version.equals("v1_11_R1") || version.equals("v1_12_R1") || version.equals("v1_13_R1") || @@ -113,8 +112,8 @@ public class NBTEditor NBTTagInt = getNMSClass("NBTTagInt"); NBTTagIntCtor = NBTTagInt.getConstructor(int.class); - NBTTagCompound = getNMSClass("NBTTagCompound"); - setTag = NBTTagCompound.getMethod("set", String.class, NBTBase); + NBTTagCompound = getNMSClass("NBTTagCompound"); + setTag = NBTTagCompound.getMethod("set", String.class, NBTBase); NBTTagList = getNMSClass("NBTTagList"); addCompound = NBTTagList.getMethod("add", NBTBase); @@ -219,7 +218,6 @@ public class NBTEditor } } - private Class getNMSClass(String name) throws ClassNotFoundException { return Class.forName(NMSbase + name); diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/Action.java b/src/main/java/nl/pim16aap2/armoredElytra/util/Action.java index 092da80..a9bd2a4 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/Action.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/Action.java @@ -2,5 +2,5 @@ package nl.pim16aap2.armoredElytra.util; public enum Action { - NONE, REPAIR, ENCHANT, COMBINE, CREATE, BLOCK + NONE, REPAIR, ENCHANT, COMBINE, CREATE, BLOCK } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java b/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java index 8bc7af0..60393d8 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java @@ -4,31 +4,31 @@ import org.bukkit.Material; public enum ArmorTier { - // Tier: tier armor-value, tier armor-toughness, repair - NONE (0 , 0 , null ), - LEATHER (3 , 0 , Material.LEATHER ), - GOLD (5 , 0 , Material.GOLD_INGOT), - CHAIN (5 , 0 , Material.IRON_INGOT), - IRON (6 , 0 , Material.IRON_INGOT), - DIAMOND (8 , 2 , Material.DIAMOND ); - - private int armor; - private int toughness; - private Material repair; + // Tier: armor-value, armor-toughness, repair + NONE (0 , 0 , null ), + LEATHER (3 , 0 , Material.LEATHER ), + GOLD (5 , 0 , Material.GOLD_INGOT), + CHAIN (5 , 0 , Material.IRON_INGOT), + IRON (6 , 0 , Material.IRON_INGOT), + DIAMOND (8 , 2 , Material.DIAMOND ); - private ArmorTier (int armor, int toughness, Material repair) + private int armor; + private int toughness; + private Material repair; + + private ArmorTier (int armor, int toughness, Material repair) { this.armor = armor; this.toughness = toughness; this.repair = repair; } - + // return the armor value of a tier. public static int getArmor (ArmorTier tier) { return tier.armor; } - + // return the armor toughness of a tier. public static int getToughness (ArmorTier tier) { return tier.toughness; } - + // return the repair item of a tier public static Material getRepairItem (ArmorTier tier) { return tier.repair; } } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/Messages.java b/src/main/java/nl/pim16aap2/armoredElytra/util/Messages.java index 96080f7..427ed3a 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/Messages.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/Messages.java @@ -13,67 +13,67 @@ import nl.pim16aap2.armoredElytra.ArmoredElytra; public class Messages { - private Map messageMap = new HashMap(); + private Map messageMap = new HashMap<>(); private ArmoredElytra plugin; private String locale; private File textFile; - - public Messages(ArmoredElytra plugin) - { - this.plugin = plugin; - this.locale = plugin.getLocale(); - textFile = new File(plugin.getDataFolder(), locale + ".txt"); - readFile(); - } - - // Read locale file. - private void readFile() - { - // Load the default en_US from the resources. - plugin.saveResource("en_US.txt", true); - try (BufferedReader br = new BufferedReader(new FileReader(this.textFile))) - { - String sCurrentLine; + public Messages(ArmoredElytra plugin) + { + this.plugin = plugin; + locale = plugin.getLocale(); + textFile = new File(plugin.getDataFolder(), locale + ".txt"); + readFile(); + } - while ((sCurrentLine = br.readLine()) != null) - { - String key, value; - String[] parts = sCurrentLine.split("=", 2); - key = parts[0]; - value = parts[1].replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1"); - String[] newLineSplitter = value.split("\\\\n"); // Wut? Can I haz more backslash? - - String values = newLineSplitter[0]; - - for (int idx = 1; idx < newLineSplitter.length; ++idx) - values += "\n" + newLineSplitter[idx]; - - this.messageMap.put(key, values); - } - br.close(); - } - catch (FileNotFoundException e) - { - plugin.myLogger(Level.SEVERE, "Locale file " + this.locale + ".txt does not exist!"); - } - catch (IOException e) - { - plugin.myLogger(Level.SEVERE, "Could not read locale file! (" + this.locale + ".txt)"); - e.printStackTrace(); - } - } - - // Get a string from a key. Returns "null" if null. - public String getString(String key) - { - String value = null; - value = this.messageMap.get(key); - if (value == null) - { - value = "ArmoredElytra: Translation not found! Contact server admin!"; - plugin.myLogger(Level.WARNING, "Failed to get translation for key " + key); - } - return value; - } + // Read locale file. + private void readFile() + { + // Load the default en_US from the resources. + plugin.saveResource("en_US.txt", true); + + try (BufferedReader br = new BufferedReader(new FileReader(textFile))) + { + String sCurrentLine; + + while ((sCurrentLine = br.readLine()) != null) + { + String key, value; + String[] parts = sCurrentLine.split("=", 2); + key = parts[0]; + value = parts[1].replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1"); + String[] newLineSplitter = value.split("\\\\n"); // Wut? Can I haz more backslash? + + String values = newLineSplitter[0]; + + for (int idx = 1; idx < newLineSplitter.length; ++idx) + values += "\n" + newLineSplitter[idx]; + + messageMap.put(key, values); + } + br.close(); + } + catch (FileNotFoundException e) + { + plugin.myLogger(Level.SEVERE, "Locale file " + locale + ".txt does not exist!"); + } + catch (IOException e) + { + plugin.myLogger(Level.SEVERE, "Could not read locale file! (" + locale + ".txt)"); + e.printStackTrace(); + } + } + + // Get a string from a key. Returns "null" if null. + public String getString(String key) + { + String value = null; + value = messageMap.get(key); + if (value == null) + { + value = "ArmoredElytra: Translation not found! Contact server admin!"; + plugin.myLogger(Level.WARNING, "Failed to get translation for key " + key); + } + return value; + } } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/Update.java b/src/main/java/nl/pim16aap2/armoredElytra/util/Update.java index 43f1478..1605d4f 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/Update.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/Update.java @@ -133,7 +133,7 @@ public class Update JSONObject latest = (JSONObject) array.get(array.size() - 1); // Get the version's title - this.versionName = (String) latest.get(API_NAME_VALUE); + versionName = (String) latest.get(API_NAME_VALUE); } } catch (IOException e) @@ -141,7 +141,7 @@ public class Update // There was an error reading the query. // Does not print stacktrace, so people won't see any errors from this plugin // when Bukkit Dev's servers are down, - // So people won't think the plugin is broken, while the actualy problem is + // So people won't think the plugin is broken, while the actual problem is // much, much smaller. latestVersion will be null, though, which will prompt a // warning in the log instead. diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/Util.java b/src/main/java/nl/pim16aap2/armoredElytra/util/Util.java index 123b344..5338721 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/Util.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/Util.java @@ -8,8 +8,8 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public class Util -{ - // Check if an item is broken or not. +{ + // Check if an item is broken or not. public static boolean isBroken(ItemStack item) { return item.getDurability() >= item.getType().getMaxDurability(); @@ -19,7 +19,7 @@ public class Util public static ArmorTier armorToTier(Material item) { ArmorTier ret = ArmorTier.NONE; - + switch (item) { case LEATHER_CHESTPLATE: @@ -42,12 +42,12 @@ public class Util } return ret; } - + // Check if mat is a chest plate. public static boolean isChestPlate(Material mat) { - if (mat == Material.LEATHER_CHESTPLATE || mat == Material.GOLD_CHESTPLATE || - mat == Material.CHAINMAIL_CHESTPLATE || mat == Material.IRON_CHESTPLATE || + if (mat == Material.LEATHER_CHESTPLATE || mat == Material.GOLD_CHESTPLATE || + mat == Material.CHAINMAIL_CHESTPLATE || mat == Material.IRON_CHESTPLATE || mat == Material.DIAMOND_CHESTPLATE) return true; return false; @@ -69,22 +69,22 @@ public class Util ret += 16; return ret; } - + public static boolean playerHasCraftPerm(Player player, ArmorTier armorTier) { - return ((armorTier == ArmorTier.LEATHER && player.hasPermission("armoredelytra.craft.leather")) || - (armorTier == ArmorTier.GOLD && player.hasPermission("armoredelytra.craft.gold" )) || - (armorTier == ArmorTier.CHAIN && player.hasPermission("armoredelytra.craft.chain" )) || - (armorTier == ArmorTier.IRON && player.hasPermission("armoredelytra.craft.iron" )) || + return ((armorTier == ArmorTier.LEATHER && player.hasPermission("armoredelytra.craft.leather")) || + (armorTier == ArmorTier.GOLD && player.hasPermission("armoredelytra.craft.gold" )) || + (armorTier == ArmorTier.CHAIN && player.hasPermission("armoredelytra.craft.chain" )) || + (armorTier == ArmorTier.IRON && player.hasPermission("armoredelytra.craft.iron" )) || (armorTier == ArmorTier.DIAMOND && player.hasPermission("armoredelytra.craft.diamond"))); } - + public static boolean playerHasWearPerm(Player player, ArmorTier armorTier) { - return ((armorTier == ArmorTier.LEATHER && player.hasPermission("armoredelytra.wear.leather" )) || - (armorTier == ArmorTier.GOLD && player.hasPermission("armoredelytra.wear.gold" )) || - (armorTier == ArmorTier.CHAIN && player.hasPermission("armoredelytra.wear.chain" )) || - (armorTier == ArmorTier.IRON && player.hasPermission("armoredelytra.wear.iron" )) || + return ((armorTier == ArmorTier.LEATHER && player.hasPermission("armoredelytra.wear.leather" )) || + (armorTier == ArmorTier.GOLD && player.hasPermission("armoredelytra.wear.gold" )) || + (armorTier == ArmorTier.CHAIN && player.hasPermission("armoredelytra.wear.chain" )) || + (armorTier == ArmorTier.IRON && player.hasPermission("armoredelytra.wear.iron" )) || (armorTier == ArmorTier.DIAMOND && player.hasPermission("armoredelytra.wear.diamond" ))); } }