summaryrefslogtreecommitdiffstats
path: root/src/Enchantments.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-04-10 19:09:21 +0200
committermadmaxoft <github@xoft.cz>2014-04-10 19:09:37 +0200
commit22d56d1a3f4849ec62a99933b2f2e15182e73c46 (patch)
tree2fdb803ef580fedd51338fe475b1af8d05adadba /src/Enchantments.cpp
parentInfoReg uses cCompositeChat for subcommand lists. (diff)
downloadcuberite-22d56d1a3f4849ec62a99933b2f2e15182e73c46.tar
cuberite-22d56d1a3f4849ec62a99933b2f2e15182e73c46.tar.gz
cuberite-22d56d1a3f4849ec62a99933b2f2e15182e73c46.tar.bz2
cuberite-22d56d1a3f4849ec62a99933b2f2e15182e73c46.tar.lz
cuberite-22d56d1a3f4849ec62a99933b2f2e15182e73c46.tar.xz
cuberite-22d56d1a3f4849ec62a99933b2f2e15182e73c46.tar.zst
cuberite-22d56d1a3f4849ec62a99933b2f2e15182e73c46.zip
Diffstat (limited to '')
-rw-r--r--src/Enchantments.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp
index 1d8188e96..9d4e23e0a 100644
--- a/src/Enchantments.cpp
+++ b/src/Enchantments.cpp
@@ -49,21 +49,17 @@ void cEnchantments::AddFromString(const AString & a_StringSpec)
LOG("%s: Malformed enchantment decl: \"%s\", skipping.", __FUNCTION__, itr->c_str());
continue;
}
- int id = atoi(Split[0].c_str());
- if ((id == 0) && (Split[0] != "0"))
+ int id = StringToEnchantmentID(Split[0]);
+ if (id < 0)
{
- id = StringToEnchantmentID(Split[0]);
+ LOG("%s: Failed to parse enchantment \"%s\", skipping.", __FUNCTION__, Split[0].c_str());
+ continue;
}
int lvl = atoi(Split[1].c_str());
- if (
- ((id <= 0) && (Split[0] != "0")) ||
- ((lvl == 0) && (Split[1] != "0"))
- )
+ if ((lvl == 0) && (Split[1] != "0"))
{
- // Numbers failed to parse
- LOG("%s: Failed to parse enchantment declaration for numbers: \"%s\" and \"%s\", skipping.",
- __FUNCTION__, Split[0].c_str(), Split[1].c_str()
- );
+ // Level failed to parse
+ LOG("%s: Failed to parse enchantment level \"%s\", skipping.", __FUNCTION__, Split[1].c_str());
continue;
}
SetLevel(id, lvl);
@@ -150,7 +146,7 @@ bool cEnchantments::IsEmpty(void) const
int cEnchantments::StringToEnchantmentID(const AString & a_EnchantmentName)
{
- struct
+ static const struct
{
int m_Value;
const char * m_Name;
@@ -181,6 +177,15 @@ int cEnchantments::StringToEnchantmentID(const AString & a_EnchantmentName)
{ enchLuckOfTheSea, "LuckOfTheSea"},
{ enchLure, "Lure"},
} ;
+
+ // First try to parse as a number:
+ int id = atoi(a_EnchantmentName.c_str());
+ if ((id != 0) || (a_EnchantmentName == "0"))
+ {
+ return id;
+ }
+
+ // It wasn't a number, do a lookup:
for (size_t i = 0; i < ARRAYCOUNT(EnchantmentNames); i++)
{
if (NoCaseCompare(EnchantmentNames[i].m_Name, a_EnchantmentName) == 0)