From cf01241e2da710e8bd2a9d5b334e9eaf108d7fd0 Mon Sep 17 00:00:00 2001 From: ile123ile Date: Sat, 30 Aug 2014 20:26:21 -0700 Subject: [PATCH] Added api stuff so you can actually add new skills and made it *mostyl* work --- .../com/gmail/nossr50/api/AbilityAPI.java | 27 +++++++++++---- .../java/com/gmail/nossr50/api/SkillAPI.java | 29 ++++++++++++++++ .../nossr50/database/SQLDatabaseManager.java | 33 +++++++++++++++++++ .../datatypes/skills/SecondaryAbility.java | 2 +- .../nossr50/datatypes/skills/SkillType.java | 29 ++++++++-------- src/main/java/com/gmail/nossr50/mcMMO.java | 2 +- 6 files changed, 99 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/api/AbilityAPI.java b/src/main/java/com/gmail/nossr50/api/AbilityAPI.java index 8aff76f20..7dc7da5ff 100644 --- a/src/main/java/com/gmail/nossr50/api/AbilityAPI.java +++ b/src/main/java/com/gmail/nossr50/api/AbilityAPI.java @@ -5,6 +5,7 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.datatypes.player.McMMOPlayer; 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.util.player.UserManager; @@ -12,31 +13,35 @@ public final class AbilityAPI { private AbilityAPI() {} public static boolean berserkEnabled(Player player) { - return UserManager.getPlayer(player).getAbilityMode(AbilityType.berserk); + return abilityEnabled(player, AbilityType.berserk); } public static boolean gigaDrillBreakerEnabled(Player player) { - return UserManager.getPlayer(player).getAbilityMode(AbilityType.gigaDrillBreaker); + return abilityEnabled(player, AbilityType.gigaDrillBreaker); } public static boolean greenTerraEnabled(Player player) { - return UserManager.getPlayer(player).getAbilityMode(AbilityType.greenTerra); + return abilityEnabled(player, AbilityType.greenTerra); } public static boolean serratedStrikesEnabled(Player player) { - return UserManager.getPlayer(player).getAbilityMode(AbilityType.serratedStrikes); + return abilityEnabled(player, AbilityType.serratedStrikes); } public static boolean skullSplitterEnabled(Player player) { - return UserManager.getPlayer(player).getAbilityMode(AbilityType.skullSplitter); + return abilityEnabled(player, AbilityType.skullSplitter); } public static boolean superBreakerEnabled(Player player) { - return UserManager.getPlayer(player).getAbilityMode(AbilityType.superBreaker); + return abilityEnabled(player, AbilityType.superBreaker); } 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) { @@ -82,8 +87,16 @@ public final class AbilityAPI { public static void setTreeFellerCooldown(Player player, long 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) { return BleedTimerTask.isBleeding(entity); } + + public static SecondaryAbility createSecondaryAbility(String name) { + return new SecondaryAbility(name); + } } diff --git a/src/main/java/com/gmail/nossr50/api/SkillAPI.java b/src/main/java/com/gmail/nossr50/api/SkillAPI.java index 58a1c7da4..2bb80b171 100644 --- a/src/main/java/com/gmail/nossr50/api/SkillAPI.java +++ b/src/main/java/com/gmail/nossr50/api/SkillAPI.java @@ -3,7 +3,16 @@ package com.gmail.nossr50.api; import java.util.ArrayList; 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.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 { private SkillAPI() {} @@ -89,4 +98,24 @@ public final class SkillAPI { return skills; } + + public static SkillType createSkill(String name, Class managerClass, Class commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, List secondaryAbilities) { + return SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, secondaryAbilities); + } + + public static SkillType createSkill(String name, Class managerClass, Class commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, AbilityType ability, ToolType tool, List secondaryAbilities) { + return SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ability, tool, secondaryAbilities); + } + + public static SkillType createSkill(String name, Class managerClass, Class 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 managerClass, Class 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(); + } } diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index 17302b4eb..7e6311c27 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -595,6 +595,8 @@ public final class SQLDatabaseManager implements DatabaseManager { // There is such a user writeMissingRows(connection, id); + addNewSkills(connection); + statement = connection.prepareStatement( "SELECT " + 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) { if (cachedUserIDs.containsKey(uuid)) { diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/SecondaryAbility.java b/src/main/java/com/gmail/nossr50/datatypes/skills/SecondaryAbility.java index 130825b6f..692d5cb0f 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/SecondaryAbility.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/SecondaryAbility.java @@ -85,7 +85,7 @@ public class SecondaryAbility { private String name; - private SecondaryAbility(String name) { + public SecondaryAbility(String name) { this.name = name; } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java b/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java index 2c4a6b37e..29b145b3b 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java @@ -69,21 +69,21 @@ public class SkillType { private static List miscSkills = new ArrayList(); - 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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)); private String name; @@ -280,6 +280,7 @@ public class SkillType { public static void setUpSkillTypes() { Collections.sort(skillNames); + lowerSkillNames = new ArrayList(); for(SkillType skill : nonChildSkills) { if(skill != null) { lowerSkillNames.add(skill.getName()); diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index df79cb695..d1eed8d36 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -120,7 +120,7 @@ public class mcMMO extends JavaPlugin { public final static String databaseCommandKey = "mcMMO: Processing Database Command"; public static FixedMetadataValue metadataValue; - + /** * Things to be run when the plugin is enabled. */