Merge remote-tracking branch 'upstream/master'

Conflicts:
	src/main/java/com/gmail/nossr50/api/ExperienceAPI.java
	src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java
	src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java
	src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java
This commit is contained in:
ile123ile 2014-09-01 20:38:32 -07:00
commit a23e8d4c96
10 changed files with 159 additions and 38 deletions

View File

@ -7,6 +7,9 @@ Key:
! Change
- Removal
Version 1.5.01-api
+ Added skill api!
Version 1.5.01-dev
+ Added new child skill; Salvage
+ Added UUID support!
@ -21,6 +24,7 @@ Version 1.5.01-dev
+ Added API to ExperienceAPI to get the amount of XP needed for a level
+ Added API class SkillAPI used to get a list of valid skill names
+ Added API events for hardcore features, McMMOPlayerPreDeathPenaltyEvent, McMMOPlayerStatLossEvent and McMMOPlayerVampirismEvent
+ Added API to ExperienceAPI to specify if XP can be shared
+ Added options to tools.yml and armor.yml config files to set a pretty repair material name
+ Added full support for repairables in tools.yml and armor.yml config files
+ Added magical mod config file import command, for Cauldron 1.7+. Check wiki for usage

View File

@ -10,9 +10,11 @@ import com.gmail.nossr50.api.exceptions.InvalidFormulaTypeException;
import com.gmail.nossr50.api.exceptions.InvalidPlayerException;
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
import com.gmail.nossr50.api.exceptions.InvalidXPGainReasonException;
import com.gmail.nossr50.api.exceptions.McMMOPlayerNotFoundException;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.XPGainReason;
@ -86,7 +88,30 @@ public final class ExperienceAPI {
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addRawXP(Player player, String skillType, float XP, String xpGainReason) {
UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason));
addRawXP(player, skillType, XP, xpGainReason, false);
}
/**
* Adds raw XP to the player.
* </br>
* This function is designed for API usage.
*
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
* @param xpGainReason The reason to gain XP
* @param isUnshared true if the XP cannot be shared with party members
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addRawXP(Player player, String skillType, float XP, String xpGainReason, boolean isUnshared) {
if (isUnshared) {
getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason));
return;
}
getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason));
}
/**
@ -168,7 +193,7 @@ public final class ExperienceAPI {
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addMultipliedXP(Player player, String skillType, int XP, String xpGainReason) {
UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason));
getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason));
}
/**
@ -218,9 +243,32 @@ public final class ExperienceAPI {
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addModifiedXP(Player player, String skillType, int XP, String xpGainReason) {
addModifiedXP(player, skillType, XP, xpGainReason, false);
}
/**
* Adds XP to the player, calculates for XP Rate and skill modifier.
* </br>
* This function is designed for API usage.
*
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
* @param xpGainReason The reason to gain XP
* @param isUnshared true if the XP cannot be shared with party members
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addModifiedXP(Player player, String skillType, int XP, String xpGainReason, boolean isUnshared) {
SkillType skill = getSkillType(skillType);
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason));
if (isUnshared) {
getPlayer(player).beginUnsharedXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason));
return;
}
getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason));
}
/**
@ -274,7 +322,31 @@ public final class ExperienceAPI {
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addXP(Player player, String skillType, int XP, String xpGainReason) {
UserManager.getPlayer(player).beginXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason));
addXP(player, skillType, XP, xpGainReason, false);
}
/**
* Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills,
* and party sharing.
* </br>
* This function is designed for API usage.
*
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
* @param xpGainReason The reason to gain XP
* @param isUnshared true if the XP cannot be shared with party members
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addXP(Player player, String skillType, int XP, String xpGainReason, boolean isUnshared) {
if (isUnshared) {
getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason));
return;
}
getPlayer(player).beginXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason));
}
/**
@ -290,7 +362,7 @@ public final class ExperienceAPI {
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static int getXP(Player player, String skillType) {
return UserManager.getPlayer(player).getSkillXpLevel(getNonChildSkillType(skillType));
return getPlayer(player).getSkillXpLevel(getNonChildSkillType(skillType));
}
/**
@ -341,7 +413,7 @@ public final class ExperienceAPI {
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static float getXPRaw(Player player, String skillType) {
return UserManager.getPlayer(player).getSkillXpLevelRaw(getNonChildSkillType(skillType));
return getPlayer(player).getSkillXpLevelRaw(getNonChildSkillType(skillType));
}
/**
@ -392,7 +464,7 @@ public final class ExperienceAPI {
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static int getXPToNextLevel(Player player, String skillType) {
return UserManager.getPlayer(player).getXpToLevel(getNonChildSkillType(skillType));
return getPlayer(player).getXpToLevel(getNonChildSkillType(skillType));
}
/**
@ -445,7 +517,7 @@ public final class ExperienceAPI {
public static int getXPRemaining(Player player, String skillType) {
SkillType skill = getNonChildSkillType(skillType);
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
PlayerProfile profile = getPlayer(player).getProfile();
return profile.getXpToLevel(skill) - profile.getSkillXpLevel(skill);
}
@ -503,7 +575,7 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid
*/
public static void addLevel(Player player, String skillType, int levels) {
UserManager.getPlayer(player).addLevels(getSkillType(skillType), levels);
getPlayer(player).addLevels(getSkillType(skillType), levels);
}
/**
@ -581,7 +653,7 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid
*/
public static int getLevel(Player player, String skillType) {
return UserManager.getPlayer(player).getSkillLevel(getSkillType(skillType));
return getPlayer(player).getSkillLevel(getSkillType(skillType));
}
/**
@ -626,7 +698,7 @@ public final class ExperienceAPI {
* @return the power level of the player
*/
public static int getPowerLevel(Player player) {
return UserManager.getPlayer(player).getPowerLevel();
return getPlayer(player).getPowerLevel();
}
/**
@ -777,7 +849,7 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid
*/
public static void setLevel(Player player, String skillType, int skillLevel) {
UserManager.getPlayer(player).modifySkill(getSkillType(skillType), skillLevel);
getPlayer(player).modifySkill(getSkillType(skillType), skillLevel);
}
/**
@ -826,7 +898,7 @@ public final class ExperienceAPI {
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static void setXP(Player player, String skillType, int newValue) {
UserManager.getPlayer(player).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
getPlayer(player).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
}
/**
@ -877,7 +949,7 @@ public final class ExperienceAPI {
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static void removeXP(Player player, String skillType, int xp) {
UserManager.getPlayer(player).removeXp(getNonChildSkillType(skillType), xp);
getPlayer(player).removeXp(getNonChildSkillType(skillType), xp);
}
/**
@ -1019,4 +1091,12 @@ public final class ExperienceAPI {
return formulaType;
}
private static McMMOPlayer getPlayer(Player player) throws McMMOPlayerNotFoundException {
if (!UserManager.hasPlayerDataKey(player)) {
throw new McMMOPlayerNotFoundException(player);
}
return UserManager.getPlayer(player);
}
}

View File

@ -16,7 +16,6 @@ import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.skills.SkillAbilityManager;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.child.ChildConfig;
import com.gmail.nossr50.skills.child.FamilyTree;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandRegistrationManager;
import com.gmail.nossr50.util.player.UserManager;

View File

@ -0,0 +1,11 @@
package com.gmail.nossr50.api.exceptions;
import org.bukkit.entity.Player;
public class McMMOPlayerNotFoundException extends RuntimeException {
private static final long serialVersionUID = 761917904993202836L;
public McMMOPlayerNotFoundException(Player player) {
super("McMMOPlayer object was not found for: " + player.getName() + " " + player.getUniqueId());
}
}

View File

@ -17,6 +17,7 @@ import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.ModConfigType;
import com.gmail.nossr50.util.Misc;
public class McImportCommand implements CommandExecutor {
int fileAmount;
@ -49,6 +50,7 @@ public class McImportCommand implements CommandExecutor {
String line;
String materialName;
String modName;
// While not at the end of the file
while ((line = in.readLine()) != null) {
@ -65,19 +67,16 @@ public class McImportCommand implements CommandExecutor {
}
materialName = split2[0];
String[] materialSplit = materialName.split("_");
if (materialSplit.length > 1) {
// Categorise each material under a mod config type
ModConfigType type = ModConfigType.getModConfigType(materialName);
// Categorise each material under a mod config type
ModConfigType type = ModConfigType.getModConfigType(materialName);
if (!materialNames.containsKey(type)) {
materialNames.put(type, new ArrayList<String>());
}
materialNames.get(type).add(materialName);
continue;
if (!materialNames.containsKey(type)) {
materialNames.put(type, new ArrayList<String>());
}
materialNames.get(type).add(materialName);
continue;
}
}
catch (FileNotFoundException e) {
@ -104,7 +103,7 @@ public class McImportCommand implements CommandExecutor {
HashMap<String, ArrayList<String>> materialNamesType = new HashMap<String, ArrayList<String>>();
for (String materialName : materialNames.get(modConfigType)) {
String modName = materialName.split("_")[0].toLowerCase();
String modName = Misc.getModName(materialName);
if (!materialNamesType.containsKey(modName)) {
materialNamesType.put(modName, new ArrayList<String>());

View File

@ -408,15 +408,21 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
String[] character = line.split(":");
int uuidIndex = getUUIDIndexFromLine(character);
int nameIndex = getNameIndexFromLine(character);
boolean shouldCheckName = false;
if (uuidIndex == -1 && nameIndex == -1) {
continue;
}
else if(uuidIndex != -1) {
if ((uuid != null && (!character[uuidIndex].split(",")[1].equalsIgnoreCase(uuid.toString()) && !character[uuidIndex].split(",")[1].equalsIgnoreCase("NULL")))) {
continue;
else if(uuidIndex != -1 && uuid != null) {
if (((!character[uuidIndex].split(",")[1].equalsIgnoreCase(uuid.toString())))) {
if(!character[uuidIndex].split(",")[1].equalsIgnoreCase("NULL")) {
continue;
}
else {
shouldCheckName = true;
}
}
}
else if(nameIndex != -1) {
if(shouldCheckName && nameIndex != -1) {
if (uuid == null && !character[nameIndex].split(",")[1].equalsIgnoreCase(playerName)) {
continue;
}

View File

@ -37,9 +37,7 @@ public class McrankCommandDisplayTask extends BukkitRunnable {
if (useChat) {
displayChat();
}
if(sender instanceof Player) {
mcMMO.p.getServer().getPlayerExact(playerName).removeMetadata(mcMMO.databaseCommandKey, mcMMO.p);
}
((Player) sender).removeMetadata(mcMMO.databaseCommandKey, mcMMO.p);
}
private void displayChat() {

View File

@ -42,6 +42,9 @@ public class MctopCommandDisplayTask extends BukkitRunnable {
displayChat();
}
if (sender instanceof Player) {
((Player) sender).removeMetadata(mcMMO.databaseCommandKey, mcMMO.p);
}
sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip"));
}
@ -62,9 +65,6 @@ public class MctopCommandDisplayTask extends BukkitRunnable {
sender.sendMessage(String.format("%2d. %s%s - %s%s", place, ChatColor.GREEN, stat.name, ChatColor.WHITE, stat.statVal));
place++;
}
if (sender instanceof Player) {
((Player) sender).removeMetadata(mcMMO.databaseCommandKey, mcMMO.p);
}
}
private void displayBoard() {

View File

@ -25,7 +25,9 @@ public final class HardcoreManager {
for (SkillType skillType : SkillType.getNonChildSkills()) {
if (!skillType.getHardcoreStatLossEnabled()) {
break;
levelChanged.put(skillType.toString(), 0);
experienceChanged.put(skillType.toString(), 0F);
continue;
}
int playerSkillLevel = playerProfile.getSkillLevel(skillType);
@ -64,7 +66,9 @@ public final class HardcoreManager {
for (SkillType skillType : SkillType.getNonChildSkills()) {
if (!skillType.getHardcoreVampirismEnabled()) {
break;
levelChanged.put(skillType.toString(), 0);
experienceChanged.put(skillType.toString(), 0F);
continue;
}
int killerSkillLevel = killerProfile.getSkillLevel(skillType);

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.util;
import java.util.Collection;
import java.util.Random;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
@ -15,6 +16,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.events.items.McMMOItemSpawnEvent;
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableSet;
public final class Misc {
private static Random random = new Random();
@ -36,6 +38,8 @@ public final class Misc {
public static final float LEVELUP_PITCH = 0.5F; // Reduced to differentiate between vanilla level-up
public static final float LEVELUP_VOLUME = 0.75F; // Use max volume always
public static final Set<String> modNames = ImmutableSet.of("LOTR", "BUILDCRAFT", "ENDERIO", "ENHANCEDBIOMES", "IC2", "METALLURGY", "FORESTRY", "GALACTICRAFT", "RAILCRAFT", "TWILIGHTFOREST", "THAUMCRAFT", "GRAVESTONEMOD", "GROWTHCRAFT", "ARCTICMOBS", "DEMONMOBS", "INFERNOMOBS", "SWAMPMOBS", "MARICULTURE", "MINESTRAPPOLATION");
private Misc() {};
public static float getFizzPitch() {
@ -123,6 +127,22 @@ public final class Misc {
}
}
public static String getModName(String materialName) {
for (String mod : modNames) {
if (materialName.contains(mod)) {
return mod;
}
}
String[] materialSplit = materialName.split("_");
if (materialSplit.length > 1) {
return materialSplit[0].toLowerCase();
}
return "UnknownMods";
}
public static Random getRandom() {
return random;
}