From 21474173228c72ab26846e0e5dbd02bec0bc5a96 Mon Sep 17 00:00:00 2001 From: t00thpick1 Date: Fri, 22 Aug 2014 15:16:40 -0400 Subject: [PATCH 1/8] This seems easier. --- .../nossr50/database/SQLDatabaseManager.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index b21a99c18..5b8927552 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -29,9 +29,7 @@ import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.runnables.database.UUIDUpdateAsyncTask; import com.gmail.nossr50.util.Misc; -import snaq.db.CacheConnection; import snaq.db.ConnectionPool; -import snaq.db.ConnectionValidator; public final class SQLDatabaseManager implements DatabaseManager { private static final String ALL_QUERY_VERSION = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing+alchemy"; @@ -72,26 +70,23 @@ public final class SQLDatabaseManager implements DatabaseManager { 0 /*No Minimum really needed*/, Config.getInstance().getMySQLMaxPoolSize(PoolIdentifier.MISC) /*max pool size */, Config.getInstance().getMySQLMaxConnections(PoolIdentifier.MISC) /*max num connections*/, - 0 /* idle timeout of connections */, + 400 /* idle timeout of connections */, connectionString, connectionProperties); - miscPool.setValidator(new mcMMOValidator()); loadPool = new ConnectionPool("mcMMO-Load-Pool", 1 /*Minimum of one*/, Config.getInstance().getMySQLMaxPoolSize(PoolIdentifier.LOAD) /*max pool size */, Config.getInstance().getMySQLMaxConnections(PoolIdentifier.LOAD) /*max num connections*/, - 0 /* idle timeout of connections */, + 400 /* idle timeout of connections */, connectionString, connectionProperties); - loadPool.setValidator(new mcMMOValidator()); savePool = new ConnectionPool("mcMMO-Save-Pool", 1 /*Minimum of one*/, Config.getInstance().getMySQLMaxPoolSize(PoolIdentifier.SAVE) /*max pool size */, Config.getInstance().getMySQLMaxConnections(PoolIdentifier.SAVE) /*max num connections*/, - 0 /* idle timeout of connections */, + 400 /* idle timeout of connections */, connectionString, connectionProperties); - savePool.setValidator(new mcMMOValidator()); miscPool.init(); // Init first connection miscPool.registerShutdownHook(); // Auto release on jvm exit just in case loadPool.init(); @@ -1609,12 +1604,4 @@ public final class SQLDatabaseManager implements DatabaseManager { LOAD, SAVE; } - - private class mcMMOValidator implements ConnectionValidator { - @Override - public boolean isValid(Connection connection) throws SQLException { - return connection instanceof CacheConnection && connection.isValid(0); - } - - } } From 087a0b079ff3a44791cd988c9c8235c83ba74f37 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Fri, 22 Aug 2014 11:19:46 -0700 Subject: [PATCH 2/8] Fixed bug with new Death API --- src/main/java/com/gmail/nossr50/util/HardcoreManager.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/HardcoreManager.java b/src/main/java/com/gmail/nossr50/util/HardcoreManager.java index 2c3e1a7c0..b8119096b 100644 --- a/src/main/java/com/gmail/nossr50/util/HardcoreManager.java +++ b/src/main/java/com/gmail/nossr50/util/HardcoreManager.java @@ -25,7 +25,9 @@ public final class HardcoreManager { for (SkillType skillType : SkillType.NON_CHILD_SKILLS) { 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.NON_CHILD_SKILLS) { if (!skillType.getHardcoreVampirismEnabled()) { - break; + levelChanged.put(skillType.toString(), 0); + experienceChanged.put(skillType.toString(), 0F); + continue; } int killerSkillLevel = killerProfile.getSkillLevel(skillType); From b61c65636ba39ca78ec22b171ecdcfdf986f8e99 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Fri, 22 Aug 2014 11:49:16 -0700 Subject: [PATCH 3/8] Add new ExperienceAPI method to specify if XP can be shared --- Changelog.txt | 1 + .../com/gmail/nossr50/api/ExperienceAPI.java | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/Changelog.txt b/Changelog.txt index 8056f3361..082c80d2b 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -21,6 +21,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 diff --git a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java index 56b9f8563..4e05a0136 100644 --- a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java +++ b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java @@ -86,6 +86,29 @@ 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) { + addRawXP(player, skillType, XP, xpGainReason, false); + } + + /** + * Adds raw XP to the player. + *
+ * 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) { + UserManager.getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason)); + return; + } + UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason)); } @@ -218,8 +241,31 @@ 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. + *
+ * 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); + if (isUnshared) { + UserManager.getPlayer(player).beginUnsharedXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason)); + return; + } + UserManager.getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason)); } @@ -274,6 +320,30 @@ 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) { + addXP(player, skillType, XP, xpGainReason, false); + } + + /** + * Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills, + * and party sharing. + *
+ * 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) { + UserManager.getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason)); + return; + } + UserManager.getPlayer(player).beginXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason)); } From 48d3280e5ef18970ffddb60951cee7ed97991266 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Fri, 22 Aug 2014 13:27:05 -0700 Subject: [PATCH 4/8] Make sure that player has McMMOPlayer object before calling API --- .../com/gmail/nossr50/api/ExperienceAPI.java | 48 +++++++++++-------- .../McMMOPlayerNotFoundException.java | 11 +++++ 2 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/api/exceptions/McMMOPlayerNotFoundException.java diff --git a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java index 4e05a0136..ec2492605 100644 --- a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java +++ b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java @@ -5,14 +5,16 @@ import java.util.UUID; import org.bukkit.entity.Player; -import com.gmail.nossr50.api.exceptions.InvalidFormulaTypeException; -import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.mcMMO; +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; @@ -105,11 +107,11 @@ public final class ExperienceAPI { */ public static void addRawXP(Player player, String skillType, float XP, String xpGainReason, boolean isUnshared) { if (isUnshared) { - UserManager.getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason)); + getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason)); return; } - UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason)); + getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason)); } /** @@ -191,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)); } /** @@ -262,11 +264,11 @@ public final class ExperienceAPI { SkillType skill = getSkillType(skillType); if (isUnshared) { - UserManager.getPlayer(player).beginUnsharedXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason)); + getPlayer(player).beginUnsharedXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason)); return; } - UserManager.getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason)); + getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason)); } /** @@ -340,11 +342,11 @@ public final class ExperienceAPI { */ public static void addXP(Player player, String skillType, int XP, String xpGainReason, boolean isUnshared) { if (isUnshared) { - UserManager.getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason)); + getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason)); return; } - UserManager.getPlayer(player).beginXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason)); + getPlayer(player).beginXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason)); } /** @@ -360,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)); } /** @@ -411,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)); } /** @@ -462,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)); } /** @@ -515,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); } @@ -573,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); } /** @@ -651,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)); } /** @@ -696,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(); } /** @@ -847,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); } /** @@ -896,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); } /** @@ -947,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); } /** @@ -1089,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); + } } diff --git a/src/main/java/com/gmail/nossr50/api/exceptions/McMMOPlayerNotFoundException.java b/src/main/java/com/gmail/nossr50/api/exceptions/McMMOPlayerNotFoundException.java new file mode 100644 index 000000000..d087631cd --- /dev/null +++ b/src/main/java/com/gmail/nossr50/api/exceptions/McMMOPlayerNotFoundException.java @@ -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()); + } +} From 7da661546f9ce9282b80932d4b767291da59f26f Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Sun, 24 Aug 2014 09:21:40 -0700 Subject: [PATCH 5/8] Fixed bug where processing message would always get displayed and the player could never execute /mctop or /mcrank if chat display was disabled. --- .../runnables/commands/McrankCommandDisplayTask.java | 2 +- .../nossr50/runnables/commands/MctopCommandDisplayTask.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java index afbfea0c7..0f933fe44 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java @@ -37,6 +37,7 @@ public class McrankCommandDisplayTask extends BukkitRunnable { if (useChat) { displayChat(); } + ((Player) sender).removeMetadata(mcMMO.databaseCommandKey, mcMMO.p); } private void displayChat() { @@ -57,7 +58,6 @@ public class McrankCommandDisplayTask extends BukkitRunnable { rank = skills.get(null); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", (rank == null ? LocaleLoader.getString("Commands.mcrank.Unranked") : rank))); - player.removeMetadata(mcMMO.databaseCommandKey, mcMMO.p); } public void displayBoard() { diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java index bdc4ba455..b7c63199b 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java @@ -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() { From 9d7faf9ed9fb92a67d82030d2d5948e682f62118 Mon Sep 17 00:00:00 2001 From: Shevchik Date: Sun, 24 Aug 2014 23:20:01 +0400 Subject: [PATCH 6/8] Fix database loading data for wrong player Fixes #2223 --- .../gmail/nossr50/database/FlatfileDatabaseManager.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java index 13284b993..e36bafe8c 100644 --- a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java @@ -470,7 +470,12 @@ public final class FlatfileDatabaseManager implements DatabaseManager { // Find if the line contains the player we want. String[] character = line.split(":"); - if ((uuid != null && (!character[41].equalsIgnoreCase(uuid.toString()) && !character[41].equalsIgnoreCase("NULL"))) || (uuid == null && !character[0].equalsIgnoreCase(playerName))) { + // Compare names because we don't have a valid uuid for that player even if input uuid is not null + if (character[41].equalsIgnoreCase("NULL") && !character[0].equalsIgnoreCase(playerName)) { + continue; + } + // If input uuid is not null then we should compare uuids + else if ((uuid != null && !character[41].equalsIgnoreCase(uuid.toString())) || (!character[0].equalsIgnoreCase(playerName))) { continue; } From 56cb5c092f10c6d6946019069134ee28ab47b9b4 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Tue, 26 Aug 2014 21:55:35 +0200 Subject: [PATCH 7/8] Should be this --- .../com/gmail/nossr50/database/FlatfileDatabaseManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java index e36bafe8c..5c6eb3810 100644 --- a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java @@ -475,7 +475,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager { continue; } // If input uuid is not null then we should compare uuids - else if ((uuid != null && !character[41].equalsIgnoreCase(uuid.toString())) || (!character[0].equalsIgnoreCase(playerName))) { + else if ((uuid != null && !character[41].equalsIgnoreCase(uuid.toString())) || (uuid == null && !character[0].equalsIgnoreCase(playerName))) { continue; } From eac5d1ee7ac73437d0ea467cf76e857920d16c98 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Sun, 31 Aug 2014 19:10:49 +0200 Subject: [PATCH 8/8] Improve auto mod config generator --- .../nossr50/commands/McImportCommand.java | 21 +++++++++---------- .../java/com/gmail/nossr50/util/Misc.java | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/McImportCommand.java b/src/main/java/com/gmail/nossr50/commands/McImportCommand.java index a372dca0d..17a755048 100644 --- a/src/main/java/com/gmail/nossr50/commands/McImportCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McImportCommand.java @@ -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()); - } - - materialNames.get(type).add(materialName); - continue; + if (!materialNames.containsKey(type)) { + materialNames.put(type, new ArrayList()); } + + materialNames.get(type).add(materialName); + continue; } } catch (FileNotFoundException e) { @@ -104,7 +103,7 @@ public class McImportCommand implements CommandExecutor { HashMap> materialNamesType = new HashMap>(); 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()); diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 6a21339cc..18f6f8253 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -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; @@ -16,6 +17,8 @@ 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 +39,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 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 +128,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; }