From 295144ad42b77cf8988cea28994aaf68ebfce1fd Mon Sep 17 00:00:00 2001 From: Fuzzlemann Date: Mon, 14 Aug 2017 22:14:29 +0200 Subject: [PATCH] Add normalization of the Item Name (e.g. GOLD_SWORD -> Gold Sword), test incl. Fixes test error --- .../data/additional/PluginConfigSectionHandler.java | 2 +- .../djrapitops/plan/data/handling/KillHandling.java | 12 ++++++++++++ .../plan/data/listeners/PlanDeathEventListener.java | 3 ++- .../data/listeners/PlanGamemodeChangeListener.java | 1 - .../plan/data/handling/KillHandlingTest.java | 10 ++++++++++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginConfigSectionHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginConfigSectionHandler.java index 008a58c3e..6388ae57d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginConfigSectionHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginConfigSectionHandler.java @@ -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); } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handling/KillHandling.java b/Plan/src/main/java/com/djrapitops/plan/data/handling/KillHandling.java index 75042f01f..ce4535c22 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/handling/KillHandling.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/handling/KillHandling.java @@ -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('_', ' '); + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanDeathEventListener.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanDeathEventListener.java index dc7f59cce..723830e56 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanDeathEventListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanDeathEventListener.java @@ -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; } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanGamemodeChangeListener.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanGamemodeChangeListener.java index 6a5333848..51b49efb4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanGamemodeChangeListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanGamemodeChangeListener.java @@ -29,7 +29,6 @@ public class PlanGamemodeChangeListener implements Listener { */ public PlanGamemodeChangeListener(Plan plugin) { handler = plugin.getHandler(); - } /** diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java index 6663fea02..8f9971caa 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java @@ -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"); + } }