Added api stuff so you can actually add new skills and made it *mostyl*

work
This commit is contained in:
ile123ile 2014-08-30 20:26:21 -07:00
parent d47a51b91d
commit cf01241e2d
6 changed files with 99 additions and 23 deletions

View File

@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
import com.gmail.nossr50.runnables.skills.BleedTimerTask; import com.gmail.nossr50.runnables.skills.BleedTimerTask;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
@ -12,31 +13,35 @@ public final class AbilityAPI {
private AbilityAPI() {} private AbilityAPI() {}
public static boolean berserkEnabled(Player player) { public static boolean berserkEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.berserk); return abilityEnabled(player, AbilityType.berserk);
} }
public static boolean gigaDrillBreakerEnabled(Player player) { public static boolean gigaDrillBreakerEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.gigaDrillBreaker); return abilityEnabled(player, AbilityType.gigaDrillBreaker);
} }
public static boolean greenTerraEnabled(Player player) { public static boolean greenTerraEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.greenTerra); return abilityEnabled(player, AbilityType.greenTerra);
} }
public static boolean serratedStrikesEnabled(Player player) { public static boolean serratedStrikesEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.serratedStrikes); return abilityEnabled(player, AbilityType.serratedStrikes);
} }
public static boolean skullSplitterEnabled(Player player) { public static boolean skullSplitterEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.skullSplitter); return abilityEnabled(player, AbilityType.skullSplitter);
} }
public static boolean superBreakerEnabled(Player player) { public static boolean superBreakerEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.superBreaker); return abilityEnabled(player, AbilityType.superBreaker);
} }
public static boolean treeFellerEnabled(Player player) { public static boolean treeFellerEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.treeFeller); return abilityEnabled(player, AbilityType.treeFeller);
}
public static boolean abilityEnabled(Player player, AbilityType ability) {
return UserManager.getPlayer(player).getAbilityMode(ability);
} }
public static boolean isAnyAbilityEnabled(Player player) { public static boolean isAnyAbilityEnabled(Player player) {
@ -82,8 +87,16 @@ public final class AbilityAPI {
public static void setTreeFellerCooldown(Player player, long cooldown) { public static void setTreeFellerCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).setAbilityDATS(AbilityType.treeFeller, cooldown); UserManager.getPlayer(player).setAbilityDATS(AbilityType.treeFeller, cooldown);
} }
public static void setAbilityCooldown(Player player, AbilityType ability, long cooldown) {
UserManager.getPlayer(player).setAbilityDATS(ability, cooldown);
}
public static boolean isBleeding(LivingEntity entity) { public static boolean isBleeding(LivingEntity entity) {
return BleedTimerTask.isBleeding(entity); return BleedTimerTask.isBleeding(entity);
} }
public static SecondaryAbility createSecondaryAbility(String name) {
return new SecondaryAbility(name);
}
} }

View File

@ -3,7 +3,16 @@ package com.gmail.nossr50.api;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.Color;
import com.gmail.nossr50.commands.skills.SkillCommand;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.datatypes.skills.SkillType.SkillUseType;
import com.gmail.nossr50.skills.SkillManager;
import com.google.common.collect.ImmutableList;
public final class SkillAPI { public final class SkillAPI {
private SkillAPI() {} private SkillAPI() {}
@ -89,4 +98,24 @@ public final class SkillAPI {
return skills; return skills;
} }
public static SkillType createSkill(String name, Class<? extends SkillManager> managerClass, Class<? extends SkillCommand> commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, List<SecondaryAbility> secondaryAbilities) {
return SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, secondaryAbilities);
}
public static SkillType createSkill(String name, Class<? extends SkillManager> managerClass, Class<? extends SkillCommand> commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, AbilityType ability, ToolType tool, List<SecondaryAbility> secondaryAbilities) {
return SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ability, tool, secondaryAbilities);
}
public static SkillType createSkill(String name, Class<? extends SkillManager> managerClass, Class<? extends SkillCommand> commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, SecondaryAbility... secondaryAbilities) {
return SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ImmutableList.copyOf(secondaryAbilities));
}
public static SkillType createSkill(String name, Class<? extends SkillManager> managerClass, Class<? extends SkillCommand> commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, AbilityType ability, ToolType tool, SecondaryAbility... secondaryAbilities) {
return SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ability, tool, ImmutableList.copyOf(secondaryAbilities));
}
public static void loadNewSkills() {
SkillType.setUpSkillTypes();
}
} }

View File

@ -595,6 +595,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
// There is such a user // There is such a user
writeMissingRows(connection, id); writeMissingRows(connection, id);
addNewSkills(connection);
statement = connection.prepareStatement( statement = connection.prepareStatement(
"SELECT " "SELECT "
+ com.gmail.nossr50.util.StringUtils.createStringFromList(SkillType.getLowerSkillNames(), "s.", ", ") + com.gmail.nossr50.util.StringUtils.createStringFromList(SkillType.getLowerSkillNames(), "s.", ", ")
@ -1470,6 +1472,37 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
} }
} }
private void addNewSkills(Connection connection) {
Statement statement = null;
try {
statement = connection.createStatement();
for (String skill : SkillType.getLowerSkillNames()) {
try {
statement.executeQuery("SELECT `" + skill + "` FROM `" + tablePrefix + "skills` LIMIT 1");
}
catch (SQLException ex) {
mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Fishing...");
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD `" + skill + "` int(10) NOT NULL DEFAULT '0'");
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "experience` ADD `" + skill + "` int(10) NOT NULL DEFAULT '0'");
}
}
}
catch (SQLException ex) {
printErrors(ex);
}
finally {
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
}
}
private int getUserID(final Connection connection, final String playerName, final UUID uuid) { private int getUserID(final Connection connection, final String playerName, final UUID uuid) {
if (cachedUserIDs.containsKey(uuid)) { if (cachedUserIDs.containsKey(uuid)) {

View File

@ -85,7 +85,7 @@ public class SecondaryAbility {
private String name; private String name;
private SecondaryAbility(String name) { public SecondaryAbility(String name) {
this.name = name; this.name = name;
} }

View File

@ -69,21 +69,21 @@ public class SkillType {
private static List<SkillType> miscSkills = new ArrayList<SkillType>(); private static List<SkillType> miscSkills = new ArrayList<SkillType>();
public static final SkillType acrobatics = createSkill("ACROBATICS" , AcrobaticsManager.class , AcrobaticsCommand.class , false, Color.WHITE, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.dodge, SecondaryAbility.gracefullRoll, SecondaryAbility.roll)); public static final SkillType acrobatics = createSkill("ACROBATICS" , AcrobaticsManager.class , AcrobaticsCommand.class , false, Color.WHITE, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.dodge, SecondaryAbility.gracefullRoll, SecondaryAbility.roll));
public static final SkillType alchemy = createSkill("ALCHEMY" , AlchemyManager.class , AlchemyCommand.class , false, Color.FUCHSIA, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.catalysis, SecondaryAbility.concoctions)); public static final SkillType alchemy = createSkill("ALCHEMY" , AlchemyManager.class , AlchemyCommand.class , false, Color.FUCHSIA, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.catalysis, SecondaryAbility.concoctions));
public static final SkillType archery = createSkill("ARCHERY" , ArcheryManager.class , ArcheryCommand.class , false, Color.MAROON, SkillUseType.COMBAT, ImmutableList.of(SecondaryAbility.daze, SecondaryAbility.retrieve, SecondaryAbility.skillShot)); public static final SkillType archery = createSkill("ARCHERY" , ArcheryManager.class , ArcheryCommand.class , false, Color.MAROON, SkillUseType.COMBAT, ImmutableList.of(SecondaryAbility.daze, SecondaryAbility.retrieve, SecondaryAbility.skillShot));
public static final SkillType axes = createSkill("AXES" , AxesManager.class , AxesCommand.class , false, Color.AQUA, SkillUseType.COMBAT, AbilityType.skullSplitter, ToolType.AXE, ImmutableList.of(SecondaryAbility.armorImpact, SecondaryAbility.axeMastery, SecondaryAbility.criticalHit, SecondaryAbility.greaterImpact)); public static final SkillType axes = createSkill("AXES" , AxesManager.class , AxesCommand.class , false, Color.AQUA, SkillUseType.COMBAT, AbilityType.skullSplitter, ToolType.AXE, ImmutableList.of(SecondaryAbility.armorImpact, SecondaryAbility.axeMastery, SecondaryAbility.criticalHit, SecondaryAbility.greaterImpact));
public static final SkillType excavation = createSkill("EXCAVATION" , ExcavationManager.class , ExcavationCommand.class , false, Color.fromRGB(139, 69, 19), SkillUseType.GATHERING, AbilityType.gigaDrillBreaker, ToolType.SHOVEL, ImmutableList.of(SecondaryAbility.excavationTreasureHunter)); public static final SkillType excavation = createSkill("EXCAVATION" , ExcavationManager.class , ExcavationCommand.class , false, Color.fromRGB(139, 69, 19), SkillUseType.GATHERING, AbilityType.gigaDrillBreaker, ToolType.SHOVEL, ImmutableList.of(SecondaryAbility.excavationTreasureHunter));
public static final SkillType fishing = createSkill("FISHING" , FishingManager.class , FishingCommand.class , false, Color.NAVY, SkillUseType.GATHERING, ImmutableList.of(SecondaryAbility.fishermansDiet, SecondaryAbility.fishingTreasureHunter, SecondaryAbility.iceFishing, SecondaryAbility.magicHunter, SecondaryAbility.masterAngler, SecondaryAbility.shake)); public static final SkillType fishing = createSkill("FISHING" , FishingManager.class , FishingCommand.class , false, Color.NAVY, SkillUseType.GATHERING, ImmutableList.of(SecondaryAbility.fishermansDiet, SecondaryAbility.fishingTreasureHunter, SecondaryAbility.iceFishing, SecondaryAbility.magicHunter, SecondaryAbility.masterAngler, SecondaryAbility.shake));
public static final SkillType herbalism = createSkill("HERBALISM" , HerbalismManager.class , HerbalismCommand.class , false, Color.GREEN, SkillUseType.GATHERING, AbilityType.greenTerra, ToolType.HOE, ImmutableList.of(SecondaryAbility.farmersDiet, SecondaryAbility.greenThumbPlant, SecondaryAbility.greenThumbBlock, SecondaryAbility.herbalismDoubleDrops, SecondaryAbility.hylianLuck, SecondaryAbility.shroomThumb)); public static final SkillType herbalism = createSkill("HERBALISM" , HerbalismManager.class , HerbalismCommand.class , false, Color.GREEN, SkillUseType.GATHERING, AbilityType.greenTerra, ToolType.HOE, ImmutableList.of(SecondaryAbility.farmersDiet, SecondaryAbility.greenThumbPlant, SecondaryAbility.greenThumbBlock, SecondaryAbility.herbalismDoubleDrops, SecondaryAbility.hylianLuck, SecondaryAbility.shroomThumb));
public static final SkillType mining = createSkill("MINING" , MiningManager.class , MiningCommand.class , false, Color.GRAY, SkillUseType.GATHERING, AbilityType.superBreaker, ToolType.PICKAXE, ImmutableList.of(SecondaryAbility.miningDoubleDrops)); public static final SkillType mining = createSkill("MINING" , MiningManager.class , MiningCommand.class , false, Color.GRAY, SkillUseType.GATHERING, AbilityType.superBreaker, ToolType.PICKAXE, ImmutableList.of(SecondaryAbility.miningDoubleDrops));
public static final SkillType repair = createSkill("REPAIR" , RepairManager.class , RepairCommand.class , false, Color.SILVER, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.arcaneForging, SecondaryAbility.repairMastery, SecondaryAbility.superRepair)); public static final SkillType repair = createSkill("REPAIR" , RepairManager.class , RepairCommand.class , false, Color.SILVER, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.arcaneForging, SecondaryAbility.repairMastery, SecondaryAbility.superRepair));
public static final SkillType salvage = createSkill("SALVAGE" , SalvageManager.class , SalvageCommand.class , true, Color.ORANGE, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.advancedSalvage, SecondaryAbility.arcaneSalvage)); public static final SkillType salvage = createSkill("SALVAGE" , SalvageManager.class , SalvageCommand.class , true, Color.ORANGE, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.advancedSalvage, SecondaryAbility.arcaneSalvage));
public static final SkillType smelting = createSkill("SMELTING" , SmeltingManager.class , SmeltingCommand.class , true, Color.YELLOW, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.fluxMining, SecondaryAbility.fuelEfficiency, SecondaryAbility.secondSmelt)); public static final SkillType smelting = createSkill("SMELTING" , SmeltingManager.class , SmeltingCommand.class , true, Color.YELLOW, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.fluxMining, SecondaryAbility.fuelEfficiency, SecondaryAbility.secondSmelt));
public static final SkillType swords = createSkill("SWORDS" , SwordsManager.class , SwordsCommand.class , false, Color.fromRGB(178, 34, 34), SkillUseType.COMBAT, AbilityType.serratedStrikes, ToolType.SWORD, ImmutableList.of(SecondaryAbility.bleed, SecondaryAbility.counter)); public static final SkillType swords = createSkill("SWORDS" , SwordsManager.class , SwordsCommand.class , false, Color.fromRGB(178, 34, 34), SkillUseType.COMBAT, AbilityType.serratedStrikes, ToolType.SWORD, ImmutableList.of(SecondaryAbility.bleed, SecondaryAbility.counter));
public static final SkillType taming = createSkill("TAMING" , TamingManager.class , TamingCommand.class , false, Color.PURPLE, SkillUseType.COMBAT, ImmutableList.of(SecondaryAbility.beastLore, SecondaryAbility.callOfTheWild, SecondaryAbility.enviromentallyAware, SecondaryAbility.fastFood, SecondaryAbility.gore, SecondaryAbility.holyHound, SecondaryAbility.sharpenedClaws, SecondaryAbility.shockProof, SecondaryAbility.thickFur)); public static final SkillType taming = createSkill("TAMING" , TamingManager.class , TamingCommand.class , false, Color.PURPLE, SkillUseType.COMBAT, ImmutableList.of(SecondaryAbility.beastLore, SecondaryAbility.callOfTheWild, SecondaryAbility.enviromentallyAware, SecondaryAbility.fastFood, SecondaryAbility.gore, SecondaryAbility.holyHound, SecondaryAbility.sharpenedClaws, SecondaryAbility.shockProof, SecondaryAbility.thickFur));
public static final SkillType unarmed = createSkill("UNARMED" , UnarmedManager.class , UnarmedCommand.class , false, Color.BLACK, SkillUseType.COMBAT, AbilityType.berserk, ToolType.FISTS, ImmutableList.of(SecondaryAbility.blockCracker, SecondaryAbility.deflect, SecondaryAbility.disarm, SecondaryAbility.ironArm, SecondaryAbility.ironGrip)); public static final SkillType unarmed = createSkill("UNARMED" , UnarmedManager.class , UnarmedCommand.class , false, Color.BLACK, SkillUseType.COMBAT, AbilityType.berserk, ToolType.FISTS, ImmutableList.of(SecondaryAbility.blockCracker, SecondaryAbility.deflect, SecondaryAbility.disarm, SecondaryAbility.ironArm, SecondaryAbility.ironGrip));
public static final SkillType woodcutting = createSkill("WOODCUTTING", WoodcuttingManager.class , WoodcuttingCommand.class , false, Color.OLIVE, SkillUseType.GATHERING, AbilityType.treeFeller, ToolType.AXE, ImmutableList.of(SecondaryAbility.leafBlower, SecondaryAbility.woodcuttingDoubleDrops)); public static final SkillType woodcutting = createSkill("WOODCUTTING", WoodcuttingManager.class , WoodcuttingCommand.class , false, Color.OLIVE, SkillUseType.GATHERING, AbilityType.treeFeller, ToolType.AXE, ImmutableList.of(SecondaryAbility.leafBlower, SecondaryAbility.woodcuttingDoubleDrops));
private String name; private String name;
@ -280,6 +280,7 @@ public class SkillType {
public static void setUpSkillTypes() public static void setUpSkillTypes()
{ {
Collections.sort(skillNames); Collections.sort(skillNames);
lowerSkillNames = new ArrayList<String>();
for(SkillType skill : nonChildSkills) { for(SkillType skill : nonChildSkills) {
if(skill != null) { if(skill != null) {
lowerSkillNames.add(skill.getName()); lowerSkillNames.add(skill.getName());

View File

@ -120,7 +120,7 @@ public class mcMMO extends JavaPlugin {
public final static String databaseCommandKey = "mcMMO: Processing Database Command"; public final static String databaseCommandKey = "mcMMO: Processing Database Command";
public static FixedMetadataValue metadataValue; public static FixedMetadataValue metadataValue;
/** /**
* Things to be run when the plugin is enabled. * Things to be run when the plugin is enabled.
*/ */