Abstraction is good.

This commit is contained in:
gmcferrin 2013-01-10 09:26:01 -05:00
parent c1463c3257
commit 607d2b8bd7
7 changed files with 49 additions and 116 deletions

View File

@ -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;
}
}

View File

@ -4,23 +4,16 @@ import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; 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 static Config config = Config.getInstance();
private Player player;
private PlayerProfile profile;
private int skillLevel;
public AcrobaticsManager (Player player) { public AcrobaticsManager (Player player) {
this.player = player; super(player, SkillType.ACROBATICS);
this.profile = Users.getProfile(player);
this.skillLevel = profile.getSkillLevel(SkillType.ACROBATICS);
} }
/** /**
@ -88,16 +81,4 @@ public class AcrobaticsManager {
eventHandler.processXPGain(eventHandler.damage * Acrobatics.DODGE_XP_MODIFIER); eventHandler.processXPGain(eventHandler.damage * Acrobatics.DODGE_XP_MODIFIER);
} }
} }
protected Player getPlayer() {
return player;
}
protected PlayerProfile getProfile() {
return profile;
}
protected int getSkillLevel() {
return skillLevel;
}
} }

View File

@ -4,21 +4,14 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; 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) { public ArcheryManager (Player player) {
this.player = player; super(player, SkillType.ARCHERY);
this.profile = Users.getProfile(player);
this.skillLevel = profile.getSkillLevel(SkillType.ARCHERY);
} }
/** /**
@ -88,12 +81,4 @@ public class ArcheryManager {
eventHandler.modifyEventDamage(); eventHandler.modifyEventDamage();
} }
} }
protected int getSkillLevel() {
return skillLevel;
}
protected Player getPlayer() {
return player;
}
} }

View File

@ -9,22 +9,14 @@ import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; 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) { public MiningManager (Player player) {
this.player = player; super(player, SkillType.MINING);
this.profile = Users.getProfile(player);
this.skillLevel = profile.getSkillLevel(SkillType.MINING);
} }
/** /**
@ -174,16 +166,4 @@ public class MiningManager {
eventHandler.processDropsAndXP(); eventHandler.processDropsAndXP();
eventHandler.playSpoutSound(); eventHandler.playSpoutSound();
} }
protected int getSkillLevel() {
return skillLevel;
}
protected Player getPlayer() {
return player;
}
protected PlayerProfile getProfile() {
return profile;
}
} }

View File

@ -3,22 +3,15 @@ package com.gmail.nossr50.skills.swords;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Combat; import com.gmail.nossr50.util.Combat;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; 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) { public SwordsManager (Player player) {
this.player = player; super(player, SkillType.SWORDS);
this.profile = Users.getProfile(player);
this.skillLevel = profile.getSkillLevel(SkillType.SWORDS);
} }
/** /**
@ -94,12 +87,4 @@ public class SwordsManager {
eventHandler.applyAbilityEffects(); eventHandler.applyAbilityEffects();
} }
protected int getSkillLevel() {
return skillLevel;
}
protected Player getPlayer() {
return player;
}
} }

View File

@ -9,22 +9,16 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class TamingManager { public class TamingManager extends SkillManager {
private Player player;
private PlayerProfile profile;
private int skillLevel;
private Config configInstance; private Config configInstance;
public TamingManager (Player player) { public TamingManager (Player player) {
this.player = player; super(player, SkillType.TAMING);
this.profile = Users.getProfile(player);
this.skillLevel = profile.getSkillLevel(SkillType.TAMING);
this.configInstance = Config.getInstance(); this.configInstance = Config.getInstance();
} }
@ -282,12 +276,4 @@ public class TamingManager {
eventHandler.modifyEventDamage(); eventHandler.modifyEventDamage();
} }
} }
protected int getSkillLevel() {
return skillLevel;
}
protected Player getPlayer() {
return player;
}
} }

View File

@ -3,21 +3,14 @@ package com.gmail.nossr50.skills.unarmed;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; 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) { public UnarmedManager (Player player) {
this.player = player; super(player, SkillType.UNARMED);
this.profile = Users.getProfile(player);
this.skillLevel = profile.getSkillLevel(SkillType.UNARMED);
} }
/** /**
@ -138,12 +131,4 @@ public class UnarmedManager {
return false; return false;
} }
protected int getSkillLevel() {
return skillLevel;
}
protected Player getPlayer() {
return player;
}
} }