mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-01 17:36:46 +01:00
Made a factory method for abilities
This commit is contained in:
parent
65400bcfae
commit
eb81f7ca96
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.api;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -97,6 +98,10 @@ public final class AbilityAPI {
|
||||
return BleedTimerTask.isBleeding(entity);
|
||||
}
|
||||
|
||||
public static AbilityType createAbility(String name, String skillName, final Material... materials) {
|
||||
return AbilityType.createAbility(name, skillName, materials);
|
||||
}
|
||||
|
||||
public static SecondaryAbility createSecondaryAbility(String name, String skillName) {
|
||||
return createSecondaryAbility(name, skillName, 0, 100);
|
||||
}
|
||||
|
@ -108,6 +108,40 @@ public class AbilityType {
|
||||
"Mining.Blast.Other.On",
|
||||
"Mining.Blast.Refresh",
|
||||
null);
|
||||
|
||||
static {
|
||||
abilityTypes.add(berserk);
|
||||
abilityNames.add(berserk.getUnprettyName());
|
||||
lowerAbilityNames.add(berserk.getUnprettyName().toLowerCase());
|
||||
|
||||
abilityTypes.add(superBreaker);
|
||||
abilityNames.add(superBreaker.getUnprettyName());
|
||||
lowerAbilityNames.add(superBreaker.getUnprettyName().toLowerCase());
|
||||
|
||||
abilityTypes.add(gigaDrillBreaker);
|
||||
abilityNames.add(gigaDrillBreaker.getUnprettyName());
|
||||
lowerAbilityNames.add(gigaDrillBreaker.getUnprettyName().toLowerCase());
|
||||
|
||||
abilityTypes.add(greenTerra);
|
||||
abilityNames.add(greenTerra.getUnprettyName());
|
||||
lowerAbilityNames.add(greenTerra.getUnprettyName().toLowerCase());
|
||||
|
||||
abilityTypes.add(skullSplitter);
|
||||
abilityNames.add(skullSplitter.getUnprettyName());
|
||||
lowerAbilityNames.add(skullSplitter.getUnprettyName().toLowerCase());
|
||||
|
||||
abilityTypes.add(treeFeller);
|
||||
abilityNames.add(treeFeller.getUnprettyName());
|
||||
lowerAbilityNames.add(treeFeller.getUnprettyName().toLowerCase());
|
||||
|
||||
abilityTypes.add(serratedStrikes);
|
||||
abilityNames.add(serratedStrikes.getUnprettyName());
|
||||
lowerAbilityNames.add(serratedStrikes.getUnprettyName().toLowerCase());
|
||||
|
||||
abilityTypes.add(blastMining);
|
||||
abilityNames.add(blastMining.getUnprettyName());
|
||||
lowerAbilityNames.add(blastMining.getUnprettyName().toLowerCase());
|
||||
}
|
||||
|
||||
private String name;
|
||||
private String abilityOn;
|
||||
@ -123,9 +157,33 @@ public class AbilityType {
|
||||
this.abilityPlayer = abilityPlayer;
|
||||
this.abilityRefresh = abilityRefresh;
|
||||
this.abilityPlayerOff = abilityPlayerOff;
|
||||
abilityTypes.add(this);
|
||||
abilityNames.add(this.getUnprettyName());
|
||||
lowerAbilityNames.add(this.getUnprettyName().toLowerCase());
|
||||
}
|
||||
|
||||
private AbilityType(String name, String skillName) {
|
||||
String capitalizedName = StringUtils.createPrettyStringWithSpacer(name, "");
|
||||
String capitalizedSkill = StringUtils.getCapitalized(skillName);
|
||||
this.name = name;
|
||||
this.abilityOn = capitalizedSkill + ".Skills." + capitalizedName + "On";
|
||||
this.abilityOff = capitalizedSkill + ".Skills." + capitalizedName + "Off";
|
||||
this.abilityPlayer = capitalizedSkill + ".Skills." + capitalizedName + "Other.On";
|
||||
this.abilityRefresh = capitalizedSkill + ".Skills." + capitalizedName + "Refresh";
|
||||
this.abilityPlayerOff = capitalizedSkill + ".Skills." + capitalizedName + "Other.Off";
|
||||
}
|
||||
|
||||
public static AbilityType createAbility(String name, String skillName, final Material... materials) {
|
||||
AbilityType ability = new AbilityType(name, skillName) {
|
||||
@Override
|
||||
public boolean blockCheck(BlockState blockState) {
|
||||
for(Material material : materials) {
|
||||
return blockState.getType() == material;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
abilityTypes.add(ability);
|
||||
abilityNames.add(ability.getUnprettyName());
|
||||
lowerAbilityNames.add(ability.getUnprettyName().toLowerCase());
|
||||
return ability;
|
||||
}
|
||||
|
||||
public int getCooldown() {
|
||||
|
@ -72,17 +72,6 @@ public class ToolType {
|
||||
return raiseTool;
|
||||
}
|
||||
|
||||
public static ToolType createToolType(String toolName, final Material material) {
|
||||
ToolType tool = new ToolType(toolName) {
|
||||
@Override
|
||||
public boolean inHand(ItemStack itemStack) {
|
||||
return itemStack.getType() == material;
|
||||
}
|
||||
};
|
||||
tools.add(tool);
|
||||
return tool;
|
||||
}
|
||||
|
||||
public static ToolType createToolType(String toolName, final Material... materials) {
|
||||
ToolType tool = new ToolType(toolName) {
|
||||
@Override
|
||||
|
@ -20,7 +20,7 @@ public class StringUtils {
|
||||
public static String getCapitalized(String target) {
|
||||
return target.substring(0, 1).toUpperCase() + target.substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
public static String getPrettyItemString(Material material) {
|
||||
return createPrettyEnumString(material.toString());
|
||||
}
|
||||
@ -59,6 +59,10 @@ public class StringUtils {
|
||||
}
|
||||
|
||||
private static String createPrettyEnumString(String baseString) {
|
||||
return createPrettyStringWithSpacer(baseString, " ");
|
||||
}
|
||||
|
||||
public static String createPrettyStringWithSpacer(String baseString, String spacer) {
|
||||
String[] substrings = baseString.split("_");
|
||||
String prettyString = "";
|
||||
int size = 1;
|
||||
@ -67,7 +71,7 @@ public class StringUtils {
|
||||
prettyString = prettyString.concat(getCapitalized(string));
|
||||
|
||||
if (size < substrings.length) {
|
||||
prettyString = prettyString.concat(" ");
|
||||
prettyString = prettyString.concat(spacer);
|
||||
}
|
||||
|
||||
size++;
|
||||
|
Loading…
Reference in New Issue
Block a user