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.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) {
@ -83,7 +88,15 @@ public final class AbilityAPI {
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);
}
}

View File

@ -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<? 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
writeMissingRows(connection, id);
addNewSkills(connection);
statement = connection.prepareStatement(
"SELECT "
+ com.gmail.nossr50.util.StringUtils.createStringFromList(SkillType.getLowerSkillNames(), "s.", ", ")
@ -1471,6 +1473,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)) {
return cachedUserIDs.get(uuid);

View File

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

View File

@ -280,6 +280,7 @@ public class SkillType {
public static void setUpSkillTypes()
{
Collections.sort(skillNames);
lowerSkillNames = new ArrayList<String>();
for(SkillType skill : nonChildSkills) {
if(skill != null) {
lowerSkillNames.add(skill.getName());