Minor change to item finder

This commit is contained in:
fullwall 2012-03-25 16:43:24 +08:00
parent 1d20cd17d1
commit fd4b07f7e3

View File

@ -15,6 +15,7 @@ import net.citizensnpcs.util.Messaging;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
@ -33,6 +34,7 @@ import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import com.google.common.base.Splitter;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.gson.internal.Pair;
@ -129,6 +131,7 @@ public class EventListen implements Listener {
}
}
// If the NPC isn't a close talker
// TODO: move this into text.class
if (isSettingFulfilled(player, Setting.TALK_ITEM) && !npc.getTrait(Text.class).shouldTalkClose())
npc.getTrait(Text.class).sendText(player);
@ -205,10 +208,14 @@ public class EventListen implements Listener {
}
private boolean isSettingFulfilled(Player player, Setting setting) {
try {
return player.getItemInHand().getTypeId() == setting.asInt();
} catch (NumberFormatException ex) {
return setting.asString().equals("*");
String parts = setting.asString();
if (parts.contains("*"))
return true;
for (String part : Splitter.on(',').split(parts)) {
if (Material.matchMaterial(part) == player.getItemInHand().getType()) {
return true;
}
}
return false;
}
}