Add normalization of the Item Name (e.g. GOLD_SWORD -> Gold Sword), test incl.

Fixes test error
This commit is contained in:
Fuzzlemann 2017-08-14 22:14:29 +02:00
parent 198c902b8f
commit 295144ad42
5 changed files with 25 additions and 3 deletions

View File

@ -54,8 +54,8 @@ public class PluginConfigSectionHandler {
String pluginName = dataSource.getSourcePlugin();
if (!section.getBoolean(pluginName + ".Enabled")) {
return false;
}
String source = dataSource.placeholder;
return section.getBoolean(pluginName + ".Data." + source);
}

View File

@ -4,6 +4,8 @@ import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.KillData;
import main.java.com.djrapitops.plan.data.UserData;
import org.apache.commons.lang3.text.WordUtils;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -54,4 +56,14 @@ public class KillHandling {
data.setMobKills(data.getMobKills() + 1);
}
}
/**
* Normalizes a material name
*
* @param material The material
* @return The normalized material name
*/
public static String normalizeMaterialName(Material material) {
return WordUtils.capitalizeFully(material.name(), '_').replace('_', ' ');
}
}

View File

@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.data.listeners;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
import main.java.com.djrapitops.plan.data.handling.KillHandling;
import main.java.com.djrapitops.plan.data.handling.info.DeathInfo;
import main.java.com.djrapitops.plan.data.handling.info.KillInfo;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
@ -68,7 +69,7 @@ public class PlanDeathEventListener implements Listener {
}
}
handler.addToPool(new KillInfo(killer.getUniqueId(), time, dead, itemInHand.name()));
handler.addToPool(new KillInfo(killer.getUniqueId(), time, dead, KillHandling.normalizeMaterialName(itemInHand)));
return;
}

View File

@ -29,7 +29,6 @@ public class PlanGamemodeChangeListener implements Listener {
*/
public PlanGamemodeChangeListener(Plan plugin) {
handler = plugin.getHandler();
}
/**

View File

@ -14,6 +14,7 @@ import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
import main.java.com.djrapitops.plan.database.tables.UsersTable;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.junit.After;
@ -132,4 +133,13 @@ public class KillHandlingTest {
assertEquals(exp, result);
}
@Test
public void testNormalizeMaterialName() {
Material material = Material.GOLD_SWORD;
String name = material.name();
String normalizedName = KillHandling.normalizeMaterialName(material);
assertEquals(name, "GOLD_SWORD");
assertEquals(normalizedName, "Gold Sword");
}
}