StockAbility Checker and small clean up

Check if there is already a stockability enabled or if there is one when
someone makes a new (fan made) ability. this allows you to create
ability with same name as default ones as long as you turn off the
default one. Also cleaned up some small parts, and will clean up the
command class in feature
This commit is contained in:
runefist 2014-09-21 23:45:16 +02:00
parent 03ee42a6a6
commit 4ccbd9b106
4 changed files with 39 additions and 32 deletions

View file

@ -19,6 +19,7 @@ public class AbilityModuleManager {
private final AbilityLoader<AbilityModule> loader;
public static HashSet<String> abilities;
public static HashSet<String> disabledStockAbilities;
public static List<String> waterbendingabilities;
public static List<String> airbendingabilities;
public static List<String> earthbendingabilities;
@ -143,11 +144,19 @@ public class AbilityModuleManager {
}
}
for (AbilityModule ab: ability) {
if (abilities.contains(ab.getName())) {
continue;
}
ab.onThisLoad();
abilities.add(ab.getName());
//To check if EarthBlast == Earthblast or for example, EarthBlast == EARTHBLAST
for(String enabledAbility : abilities){
if(enabledAbility.equalsIgnoreCase(ab.getName())){
continue;
}
}
ab.onThisLoad();
abilities.add(ab.getName());
for (StockAbilities a: StockAbilities.values()) {
if (a.name().equalsIgnoreCase(ab.getName())){
disabledStockAbilities.add(a.name());
}
}
if (ab.getElement() == Element.Air.toString()) airbendingabilities.add(ab.getName());
if (ab.getElement() == Element.Water.toString()) waterbendingabilities.add(ab.getName());
if (ab.getElement() == Element.Earth.toString()) earthbendingabilities.add(ab.getName());

View file

@ -87,7 +87,10 @@ public class Commands {
exe = new CommandExecutor() {
@Override
public boolean onCommand(CommandSender s, Command c, String label, String[] args) {
if (args.length == 0) {
for(int i = 0; i < args.length; i++){
args[i] = args[i].toLowerCase();
}
if (args.length == 0) {
s.sendMessage(ChatColor.RED + "/bending help [Ability/Command] " + ChatColor.YELLOW + "Display help.");
s.sendMessage(ChatColor.RED + "/bending choose [Element] " + ChatColor.YELLOW + "Choose an element.");
s.sendMessage(ChatColor.RED + "/bending bind [Ability] # " + ChatColor.YELLOW + "Bind an ability.");

View file

@ -143,9 +143,20 @@ public class Methods {
* @return true if ability exists
*/
public static boolean abilityExists(String string) {
if (getAbility(string) == null) return false;
return true;
for (String st: AbilityModuleManager.abilities) {
if (string.equalsIgnoreCase(st))
return true;
}
return false;
}
public static boolean isDisabledStockAbility(String string){
for (String st : AbilityModuleManager.disabledStockAbilities){
if (string.equalsIgnoreCase(st))
return true;
}
return false;
}
public static void addTempAirBlock(Block block) {
if (movedearth.containsKey(block)) {
@ -173,27 +184,7 @@ public class Methods {
*/
public static void bindAbility(Player player, String ability) {
int slot = player.getInventory().getHeldItemSlot() + 1;
BendingPlayer bPlayer = getBendingPlayer(player.getName());
bPlayer.getAbilities().put(slot, ability);
if (isAirAbility(ability)) {
player.sendMessage(getAirColor() + "Succesfully bound " + ability + " to slot " + slot);
}
else if (isWaterAbility(ability)) {
player.sendMessage(getWaterColor() + "Succesfully bound " + ability + " to slot " + slot);
}
else if (isEarthAbility(ability)) {
player.sendMessage(getEarthColor() + "Succesfully bound " + ability + " to slot " + slot);
}
else if (isFireAbility(ability)) {
player.sendMessage(getFireColor() + "Succesfully bound " + ability + " to slot " + slot);
}
else if (isChiAbility(ability)) {
player.sendMessage(getChiColor() + "Succesfully bound " + ability + " to slot " + slot);
} else {
player.sendMessage(getAvatarColor() + "Successfully bound " + ability + " to slot " + slot);
}
saveAbility(bPlayer, slot, ability);
bindAbility(player,ability, slot);
}
/**
@ -951,7 +942,9 @@ public class Methods {
if (isRegionProtectedFromBuild(player, "IceBlast", location))
continue;
if (isIcebendable(block)) {
return block;
if (TempBlock.isTempBlock(block))
continue;
return block;
}
}
return null;

View file

@ -351,7 +351,8 @@ public class PKListener implements Listener {
}
if (!player.isSneaking() && Methods.canBend(player.getName(), abil)) {
if (Methods.isDisabledStockAbility(abil))
return;
if (Methods.isAirAbility(abil)) {
if (Methods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Air.CanBendWithWeapons")) {
return;
@ -687,7 +688,8 @@ public class PKListener implements Listener {
String abil = Methods.getBoundAbility(player);
if (abil == null) return;
if (Methods.canBend(player.getName(), abil)) {
if (Methods.isDisabledStockAbility(abil))
return;
if (Methods.isAirAbility(abil)) {
if (Methods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Air.CanBendWithWeapons")) {