mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Add normalization of the Item Name (e.g. GOLD_SWORD -> Gold Sword), test incl.
Fixes test error
This commit is contained in:
parent
198c902b8f
commit
295144ad42
@ -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);
|
||||
}
|
||||
|
@ -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('_', ' ');
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,6 @@ public class PlanGamemodeChangeListener implements Listener {
|
||||
*/
|
||||
public PlanGamemodeChangeListener(Plan plugin) {
|
||||
handler = plugin.getHandler();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user