From d46b52b101994f68bafcd6d88156b8b65d1ecb29 Mon Sep 17 00:00:00 2001 From: Sindusk Date: Sun, 1 Apr 2018 22:09:39 -0400 Subject: [PATCH] Minor code cleanup. --- .../java/mod/sin/armoury/ArmourTweaks.java | 2 +- src/main/java/mod/sin/armoury/ArmouryMod.java | 40 +-- .../java/mod/sin/armoury/CombatTweaks.java | 1 - .../java/mod/sin/armoury/ShieldTweaks.java | 6 +- .../java/mod/sin/armoury/WeaponTweaks.java | 324 +++++++++--------- 5 files changed, 179 insertions(+), 194 deletions(-) diff --git a/src/main/java/mod/sin/armoury/ArmourTweaks.java b/src/main/java/mod/sin/armoury/ArmourTweaks.java index e03ab13..f20aecf 100644 --- a/src/main/java/mod/sin/armoury/ArmourTweaks.java +++ b/src/main/java/mod/sin/armoury/ArmourTweaks.java @@ -105,7 +105,7 @@ public class ArmourTweaks { if(mod.enableArmourMovementModifications){ logger.info("Starting armour movement modifications..."); for(String armourName : mod.armourMovement.keySet()){ - int armourTemplate = 0; + int armourTemplate; if(mod.armourNameToItemTemplate.containsKey(armourName)){ armourTemplate = mod.armourNameToItemTemplate.get(armourName); }else{ diff --git a/src/main/java/mod/sin/armoury/ArmouryMod.java b/src/main/java/mod/sin/armoury/ArmouryMod.java index 0333c07..9944190 100644 --- a/src/main/java/mod/sin/armoury/ArmouryMod.java +++ b/src/main/java/mod/sin/armoury/ArmouryMod.java @@ -34,8 +34,8 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene // Armour Mapping public String[] armourTypes = {"cloth", "leather", "studded", "chain", "plate", "drake", "dragonscale", // Worn armour pieces "scale", "ring", "splint"}; // Used by the system but not worn by players - public HashMap armourTypeReduction = new HashMap(); - public HashMap armourTypeReference = new HashMap(); + public HashMap armourTypeReduction = new HashMap<>(); + public HashMap armourTypeReference = new HashMap<>(); // Armour modifiers public float adamantineMaterialMod = 0.05f; public float glimmersteelMaterialMod = 0.1f; @@ -49,10 +49,10 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene public float plateArmourLimitFactor = -0.3f; public float drakeArmourLimitFactor = -0.3f; public float dragonscaleArmourLimitFactor = -0.3f; - public HashMap armourReductionOverride = new HashMap(); + public HashMap armourReductionOverride = new HashMap<>(); // Armour movement public boolean enableArmourMovementModifications = true; - public HashMap armourMovement = new HashMap(); + public HashMap armourMovement = new HashMap<>(); // - Shield configuration -- // public boolean enableShieldDamageEnchants = true; @@ -65,13 +65,13 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene public boolean fixSavedSwingTimer = true; public boolean betterDualWield = true; // HIGHLY EXPERIMENTAL // Weapon variable changes - public HashMap weaponDamage = new HashMap(); - public HashMap weaponSpeed = new HashMap(); - public HashMap weaponCritChance = new HashMap(); - public HashMap weaponReach = new HashMap(); - public HashMap weaponWeightGroup = new HashMap(); - public HashMap weaponParryPercent = new HashMap(); - public HashMap weaponSkillPenalty = new HashMap(); + public HashMap weaponDamage = new HashMap<>(); + public HashMap weaponSpeed = new HashMap<>(); + public HashMap weaponCritChance = new HashMap<>(); + public HashMap weaponReach = new HashMap<>(); + public HashMap weaponWeightGroup = new HashMap<>(); + public HashMap weaponParryPercent = new HashMap<>(); + public HashMap weaponSkillPenalty = new HashMap<>(); public ArmouryMod(){ this.logger = Logger.getLogger(this.getClass().getName()); @@ -177,7 +177,7 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene double newVal = Double.parseDouble(split[1]); weaponSkillPenalty.put(weaponId, newVal); } else { - //Debug("Unknown config property: " + name); + Debug("Unknown config property: " + name); } } } catch (Exception e) { @@ -251,15 +251,15 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene WeaponTweaks.onServerStarted(this); } - public HashMap armourNameToItemTemplate = new HashMap(); + public HashMap armourNameToItemTemplate = new HashMap<>(); - public ArrayList clothArmour = new ArrayList(); - public ArrayList leatherArmour = new ArrayList(); - public ArrayList studdedArmour = new ArrayList(); - public ArrayList chainArmour = new ArrayList(); - public ArrayList plateArmour = new ArrayList(); - public ArrayList drakeArmour = new ArrayList(); - public ArrayList dragonscaleArmour = new ArrayList(); + public ArrayList clothArmour = new ArrayList<>(); + public ArrayList leatherArmour = new ArrayList<>(); + public ArrayList studdedArmour = new ArrayList<>(); + public ArrayList chainArmour = new ArrayList<>(); + public ArrayList plateArmour = new ArrayList<>(); + public ArrayList drakeArmour = new ArrayList<>(); + public ArrayList dragonscaleArmour = new ArrayList<>(); private void addArmour(ArrayList typeList, int itemTemplate){ ItemTemplate it = ItemTemplateFactory.getInstance().getTemplateOrNull(itemTemplate); diff --git a/src/main/java/mod/sin/armoury/CombatTweaks.java b/src/main/java/mod/sin/armoury/CombatTweaks.java index c293e2b..1b5d43f 100644 --- a/src/main/java/mod/sin/armoury/CombatTweaks.java +++ b/src/main/java/mod/sin/armoury/CombatTweaks.java @@ -117,7 +117,6 @@ public class CombatTweaks { + "}" + "$_ = $proceed($$);" + "communicator.sendAddSpellEffect($1, 100000, this.limitingArmourFactor*100.0f);"); - return; } } }); diff --git a/src/main/java/mod/sin/armoury/ShieldTweaks.java b/src/main/java/mod/sin/armoury/ShieldTweaks.java index 873a950..8dc8257 100644 --- a/src/main/java/mod/sin/armoury/ShieldTweaks.java +++ b/src/main/java/mod/sin/armoury/ShieldTweaks.java @@ -19,9 +19,9 @@ import javassist.NotFoundException; public class ShieldTweaks { public static Logger logger = Logger.getLogger(ShieldTweaks.class.getName()); public static boolean checkShieldSpeed(Item shield){ - if(shield != null && shield.getSpellSpeedBonus() > Server.rand.nextInt(500)){ - return true; - } + if ((shield != null)) { + return (shield.getSpellSpeedBonus() > Server.rand.nextInt(500)); + } return false; } diff --git a/src/main/java/mod/sin/armoury/WeaponTweaks.java b/src/main/java/mod/sin/armoury/WeaponTweaks.java index 26025e9..4520741 100644 --- a/src/main/java/mod/sin/armoury/WeaponTweaks.java +++ b/src/main/java/mod/sin/armoury/WeaponTweaks.java @@ -41,188 +41,174 @@ public class WeaponTweaks { try { Weapon cw; ItemTemplate it; - String tweakType = ""; - if(mod.weaponDamage.keySet() != null){ - tweakType = "damage"; - logger.info("Beginning weapon "+tweakType+" tweaks..."); - for(int id : mod.weaponDamage.keySet()){ - it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); - if(it == null){ - logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid."); - continue; - } - cw = weapons.get(id); - if(cw == null){ - logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); - continue; - } - float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "damage")); - float newValue = mod.weaponDamage.get(id); - String diff = ""; - if(newValue > oldValue){ - diff = "+"+(newValue-oldValue); - }else{ - diff = String.valueOf(newValue-oldValue); - } - logger.info("Setting damage on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); - ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "damage"), newValue); + String tweakType; + tweakType = "damage"; + logger.info("Beginning weapon "+tweakType+" tweaks..."); + for(int id : mod.weaponDamage.keySet()){ + it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); + if(it == null){ + logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid."); + continue; } + cw = weapons.get(id); + if(cw == null){ + logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); + continue; + } + float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "damage")); + float newValue = mod.weaponDamage.get(id); + String diff; + if(newValue > oldValue){ + diff = "+"+(newValue-oldValue); + }else{ + diff = String.valueOf(newValue-oldValue); + } + logger.info("Setting damage on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); + ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "damage"), newValue); } - if(mod.weaponSpeed.keySet() != null){ - tweakType = "speed"; - logger.info("Beginning weapon "+tweakType+" tweaks..."); - for(int id : mod.weaponSpeed.keySet()){ - it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); - if(it == null){ - logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration."); - continue; - } - cw = weapons.get(id); - if(cw == null){ - logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); - continue; - } - float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "speed")); - float newValue = mod.weaponSpeed.get(id); - String diff = ""; - if(newValue > oldValue){ - diff = "+"+(newValue-oldValue); - }else{ - diff = String.valueOf(newValue-oldValue); - } - logger.info("Setting speed on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); - ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "speed"), newValue); + tweakType = "speed"; + logger.info("Beginning weapon "+tweakType+" tweaks..."); + for(int id : mod.weaponSpeed.keySet()){ + it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); + if(it == null){ + logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration."); + continue; } + cw = weapons.get(id); + if(cw == null){ + logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); + continue; + } + float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "speed")); + float newValue = mod.weaponSpeed.get(id); + String diff; + if(newValue > oldValue){ + diff = "+"+(newValue-oldValue); + }else{ + diff = String.valueOf(newValue-oldValue); + } + logger.info("Setting speed on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); + ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "speed"), newValue); } - if(mod.weaponCritChance.keySet() != null){ - tweakType = "crit chance"; - logger.info("Beginning weapon "+tweakType+" tweaks..."); - for(int id : mod.weaponCritChance.keySet()){ - it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); - if(it == null){ - logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration."); - continue; - } - cw = weapons.get(id); - if(cw == null){ - logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); - continue; - } - float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "critchance")); - float newValue = mod.weaponCritChance.get(id); - String diff = ""; - if(newValue > oldValue){ - diff = "+"+(newValue-oldValue); - }else{ - diff = String.valueOf(newValue-oldValue); - } - logger.info("Setting crit chance on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); - ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "critchance"), newValue); + tweakType = "crit chance"; + logger.info("Beginning weapon "+tweakType+" tweaks..."); + for(int id : mod.weaponCritChance.keySet()){ + it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); + if(it == null){ + logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration."); + continue; } + cw = weapons.get(id); + if(cw == null){ + logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); + continue; + } + float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "critchance")); + float newValue = mod.weaponCritChance.get(id); + String diff; + if(newValue > oldValue){ + diff = "+"+(newValue-oldValue); + }else{ + diff = String.valueOf(newValue-oldValue); + } + logger.info("Setting crit chance on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); + ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "critchance"), newValue); } - if(mod.weaponReach.keySet() != null){ - tweakType = "reach"; - logger.info("Beginning weapon "+tweakType+" tweaks..."); - for(int id : mod.weaponReach.keySet()){ - it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); - if(it == null){ - logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration."); - continue; - } - cw = weapons.get(id); - if(cw == null){ - logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); - continue; - } - int oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "reach")); - int newValue = mod.weaponReach.get(id); - String diff = ""; - if(newValue > oldValue){ - diff = "+"+(newValue-oldValue); - }else{ - diff = String.valueOf(newValue-oldValue); - } - logger.info("Setting reach on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); - ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "reach"), newValue); + tweakType = "reach"; + logger.info("Beginning weapon "+tweakType+" tweaks..."); + for(int id : mod.weaponReach.keySet()){ + it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); + if(it == null){ + logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration."); + continue; } + cw = weapons.get(id); + if(cw == null){ + logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); + continue; + } + int oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "reach")); + int newValue = mod.weaponReach.get(id); + String diff; + if(newValue > oldValue){ + diff = "+"+(newValue-oldValue); + }else{ + diff = String.valueOf(newValue-oldValue); + } + logger.info("Setting reach on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); + ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "reach"), newValue); } - if(mod.weaponWeightGroup.keySet() != null){ - tweakType = "weight group"; - logger.info("Beginning weapon "+tweakType+" tweaks..."); - for(int id : mod.weaponWeightGroup.keySet()){ - it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); - if(it == null){ - logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration."); - continue; - } - cw = weapons.get(id); - if(cw == null){ - logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); - continue; - } - int oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "weightGroup")); - int newValue = mod.weaponWeightGroup.get(id); - String diff = ""; - if(newValue > oldValue){ - diff = "+"+(newValue-oldValue); - }else{ - diff = String.valueOf(newValue-oldValue); - } - logger.info("Setting weight group on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); - ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "weightGroup"), newValue); + tweakType = "weight group"; + logger.info("Beginning weapon "+tweakType+" tweaks..."); + for(int id : mod.weaponWeightGroup.keySet()){ + it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); + if(it == null){ + logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration."); + continue; } + cw = weapons.get(id); + if(cw == null){ + logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); + continue; + } + int oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "weightGroup")); + int newValue = mod.weaponWeightGroup.get(id); + String diff; + if(newValue > oldValue){ + diff = "+"+(newValue-oldValue); + }else{ + diff = String.valueOf(newValue-oldValue); + } + logger.info("Setting weight group on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); + ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "weightGroup"), newValue); } - if(mod.weaponParryPercent.keySet() != null){ - tweakType = "parry percent"; - logger.info("Beginning weapon "+tweakType+" tweaks..."); - for(int id : mod.weaponParryPercent.keySet()){ - it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); - if(it == null){ - logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration."); - continue; - } - cw = weapons.get(id); - if(cw == null){ - logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); - continue; - } - float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "parryPercent")); - float newValue = mod.weaponParryPercent.get(id); - String diff = ""; - if(newValue > oldValue){ - diff = "+"+(newValue-oldValue); - }else{ - diff = String.valueOf(newValue-oldValue); - } - logger.info("Setting parry percent on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); - ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "parryPercent"), newValue); + tweakType = "parry percent"; + logger.info("Beginning weapon "+tweakType+" tweaks..."); + for(int id : mod.weaponParryPercent.keySet()){ + it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); + if(it == null){ + logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration."); + continue; } + cw = weapons.get(id); + if(cw == null){ + logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); + continue; + } + float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "parryPercent")); + float newValue = mod.weaponParryPercent.get(id); + String diff; + if(newValue > oldValue){ + diff = "+"+(newValue-oldValue); + }else{ + diff = String.valueOf(newValue-oldValue); + } + logger.info("Setting parry percent on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); + ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "parryPercent"), newValue); } - if(mod.weaponSkillPenalty.keySet() != null){ - tweakType = "skill penalty"; - logger.info("Beginning weapon "+tweakType+" tweaks..."); - for(int id : mod.weaponSkillPenalty.keySet()){ - it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); - if(it == null){ - logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration."); - continue; - } - cw = weapons.get(id); - if(cw == null){ - logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); - continue; - } - double oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "skillPenalty")); - double newValue = mod.weaponSkillPenalty.get(id); - String diff = ""; - if(newValue > oldValue){ - diff = "+"+(newValue-oldValue); - }else{ - diff = String.valueOf(newValue-oldValue); - } - logger.info("Setting skill penalty on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); - ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "skillPenalty"), newValue); + tweakType = "skill penalty"; + logger.info("Beginning weapon "+tweakType+" tweaks..."); + for(int id : mod.weaponSkillPenalty.keySet()){ + it = ItemTemplateFactory.getInstance().getTemplateOrNull(id); + if(it == null){ + logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration."); + continue; } + cw = weapons.get(id); + if(cw == null){ + logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid."); + continue; + } + double oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "skillPenalty")); + double newValue = mod.weaponSkillPenalty.get(id); + String diff; + if(newValue > oldValue){ + diff = "+"+(newValue-oldValue); + }else{ + diff = String.valueOf(newValue-oldValue); + } + logger.info("Setting skill penalty on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")"); + ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "skillPenalty"), newValue); } } catch (IllegalArgumentException | IllegalAccessException | ClassCastException | NoSuchFieldException e) { e.printStackTrace();