diff --git a/src/main/java/com/gmail/nossr50/skills/SkillManager.java b/src/main/java/com/gmail/nossr50/skills/SkillManager.java new file mode 100644 index 000000000..31cef8270 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/skills/SkillManager.java @@ -0,0 +1,31 @@ +package com.gmail.nossr50.skills; + +import org.bukkit.entity.Player; + +import com.gmail.nossr50.datatypes.PlayerProfile; +import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.util.Users; + +public abstract class SkillManager { + protected Player player; + protected PlayerProfile profile; + protected int skillLevel; + + public SkillManager(Player player, SkillType skill) { + this.player = player; + this.profile = Users.getProfile(player); + this.skillLevel = profile.getSkillLevel(skill); + } + + public Player getPlayer() { + return player; + } + + public PlayerProfile getProfile() { + return profile; + } + + public int getSkillLevel() { + return skillLevel; + } +} diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java index 059d4ce57..358705876 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java @@ -4,23 +4,16 @@ import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; import com.gmail.nossr50.config.Config; -import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.Users; -public class AcrobaticsManager { +public class AcrobaticsManager extends SkillManager { private static Config config = Config.getInstance(); - private Player player; - private PlayerProfile profile; - private int skillLevel; - public AcrobaticsManager (Player player) { - this.player = player; - this.profile = Users.getProfile(player); - this.skillLevel = profile.getSkillLevel(SkillType.ACROBATICS); + super(player, SkillType.ACROBATICS); } /** @@ -88,16 +81,4 @@ public class AcrobaticsManager { eventHandler.processXPGain(eventHandler.damage * Acrobatics.DODGE_XP_MODIFIER); } } - - protected Player getPlayer() { - return player; - } - - protected PlayerProfile getProfile() { - return profile; - } - - protected int getSkillLevel() { - return skillLevel; - } } diff --git a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java index 25da631cf..e087933e6 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java @@ -4,21 +4,14 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; -import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.Users; - -public class ArcheryManager { - private Player player; - private PlayerProfile profile; - private int skillLevel; +public class ArcheryManager extends SkillManager { public ArcheryManager (Player player) { - this.player = player; - this.profile = Users.getProfile(player); - this.skillLevel = profile.getSkillLevel(SkillType.ARCHERY); + super(player, SkillType.ARCHERY); } /** @@ -88,12 +81,4 @@ public class ArcheryManager { eventHandler.modifyEventDamage(); } } - - protected int getSkillLevel() { - return skillLevel; - } - - protected Player getPlayer() { - return player; - } } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index b674a56a8..820b7e310 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -9,22 +9,14 @@ import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.player.PlayerInteractEvent; import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.Users; - -public class MiningManager { - private Player player; - private PlayerProfile profile; - private int skillLevel; +public class MiningManager extends SkillManager{ public MiningManager (Player player) { - this.player = player; - this.profile = Users.getProfile(player); - - this.skillLevel = profile.getSkillLevel(SkillType.MINING); + super(player, SkillType.MINING); } /** @@ -174,16 +166,4 @@ public class MiningManager { eventHandler.processDropsAndXP(); eventHandler.playSpoutSound(); } - - protected int getSkillLevel() { - return skillLevel; - } - - protected Player getPlayer() { - return player; - } - - protected PlayerProfile getProfile() { - return profile; - } } diff --git a/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java b/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java index 62c482c01..6057bc637 100644 --- a/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java @@ -3,22 +3,15 @@ package com.gmail.nossr50.skills.swords; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.Combat; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.Users; - -public class SwordsManager { - private Player player; - private PlayerProfile profile; - private int skillLevel; +public class SwordsManager extends SkillManager { public SwordsManager (Player player) { - this.player = player; - this.profile = Users.getProfile(player); - this.skillLevel = profile.getSkillLevel(SkillType.SWORDS); + super(player, SkillType.SWORDS); } /** @@ -94,12 +87,4 @@ public class SwordsManager { eventHandler.applyAbilityEffects(); } - - protected int getSkillLevel() { - return skillLevel; - } - - protected Player getPlayer() { - return player; - } } diff --git a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java index 7737a14c1..6dc282a49 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -9,22 +9,16 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.config.Config; -import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.Users; -public class TamingManager { - private Player player; - private PlayerProfile profile; - private int skillLevel; +public class TamingManager extends SkillManager { private Config configInstance; public TamingManager (Player player) { - this.player = player; - this.profile = Users.getProfile(player); - this.skillLevel = profile.getSkillLevel(SkillType.TAMING); + super(player, SkillType.TAMING); this.configInstance = Config.getInstance(); } @@ -282,12 +276,4 @@ public class TamingManager { eventHandler.modifyEventDamage(); } } - - protected int getSkillLevel() { - return skillLevel; - } - - protected Player getPlayer() { - return player; - } } diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java index 37de84145..47a3d6022 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java @@ -3,21 +3,14 @@ package com.gmail.nossr50.skills.unarmed; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; -import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.Users; - -public class UnarmedManager { - private Player player; - private PlayerProfile profile; - private int skillLevel; +public class UnarmedManager extends SkillManager { public UnarmedManager (Player player) { - this.player = player; - this.profile = Users.getProfile(player); - this.skillLevel = profile.getSkillLevel(SkillType.UNARMED); + super(player, SkillType.UNARMED); } /** @@ -138,12 +131,4 @@ public class UnarmedManager { return false; } - - protected int getSkillLevel() { - return skillLevel; - } - - protected Player getPlayer() { - return player; - } }