From c062482e1f2618d6bb58735dea493781efe01bdf Mon Sep 17 00:00:00 2001 From: Alexander B Date: Tue, 5 Jan 2021 21:29:22 +0100 Subject: [PATCH] Implemented human-readable monster-name --- eu/railduction/ruakij/spawnerDrops/Main.java | 17 +++++++++++++++++ .../spawnerDrops/listener/OnBlockBreak.java | 8 +++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/eu/railduction/ruakij/spawnerDrops/Main.java b/eu/railduction/ruakij/spawnerDrops/Main.java index 5ce0b87..da270a8 100644 --- a/eu/railduction/ruakij/spawnerDrops/Main.java +++ b/eu/railduction/ruakij/spawnerDrops/Main.java @@ -57,4 +57,21 @@ public class Main extends JavaPlugin { public static String serialiseLocation(Location loc){ return loc.getWorld().getName()+";"+loc.getBlockX()+";"+loc.getBlockY()+";"+loc.getBlockZ(); } + + public static String stringHumanReadable(String str){ + + str = str.replace("_", " "); + String[] strData = str.split(" "); + str = ""; + for (int i = 0; i < strData.length; i++) { + String tmpStr = strData[i].substring(0, 1).toUpperCase(); + strData[i] = tmpStr + strData[i].substring(1).toLowerCase(); + + str += strData[i]; + if(i < strData.length-1) + str += " "; + } + + return str; + } } diff --git a/eu/railduction/ruakij/spawnerDrops/listener/OnBlockBreak.java b/eu/railduction/ruakij/spawnerDrops/listener/OnBlockBreak.java index 2bc5ccc..e44bf6c 100644 --- a/eu/railduction/ruakij/spawnerDrops/listener/OnBlockBreak.java +++ b/eu/railduction/ruakij/spawnerDrops/listener/OnBlockBreak.java @@ -128,7 +128,13 @@ public class OnBlockBreak implements Listener { BlockStateMeta bsm = (BlockStateMeta)item.getItemMeta(); bsm.setBlockState(cs); - bsm.setDisplayName(dropConfig.getString("item.name").replace("{mob-type}", cs.getSpawnedType().name())); + + String item_name_conf = dropConfig.getString("item.name"); + if(item_name_conf != null && item_name_conf != ""){ + String mobTypeName = Main.stringHumanReadable(cs.getSpawnedType().name()); + bsm.setDisplayName(dropConfig.getString("item.name").replace("{mob-type}", mobTypeName)); + } + item.setItemMeta(bsm); e.getBlock().setType(Material.AIR);