0

final Material b = event.getClickedBlock().getType();

p.sendMessage(ChatColor.GRAY + "This rock contains " + b.toString().toLowerCase().replaceAll("_", " ") + ".");

Alright, so lets say b is equal to CLAY and I want to print out "clay" in the message. What I've done here works. But lets say b is equal to LAPIS_ORE and I want to print out "copper" in the message. In this case it won't work because it would print out "lapis ore" instead of "copper". In the API that I am using, copper is not a Material type, so therefore I cannot declare a variable Material LAPIS_ORE = COPPER;. How else would I be able to print out "copper" from Material type LAPIS_ORE?

I tried:

String LAPIS_ORE = "copper";

p.sendMessage("This rock contains " + b.toString() + ".");

But that still didn't work out, probably because LAPIS_ORE is not a string, so how else would I do it? If needed, how could I declare a new Material type and set it equal to LAPIS_ORE?

Edit: I can do this with a switch statement but that is very inefficient.

Edit: Fixed it! Was simpler than I thought and kind of embarassing. b.toString().toLowerCase().replaceAll("_", " ").replaceAll("GLOWING_REDSTONE_ORE", "copper ore").replaceAll("REDSTONE_ORE", "copper ore")

4

1 回答 1

0

我确定不是这样 :) 你可以很容易地让它工作...... :) 看例子一种方法: http ://forums.bukkit.org/threads/solved-checking-sign-text.57905/

好好享受...

于 2013-06-23T01:35:55.007 回答