我是bukkit jython / python插件编码器,但我被困在这里。我有一个由服务器预生成的array.array(so ArrayList),并返回在线播放器列表。
就是这样:
online = Bukkit.getOnlinePlayers()
那么我想要什么? (查看#hashcomments)
我创建了这个HashMap():
channelList = HashMap()
@hook.command("channel", usage="/channel [channelname]", desc="Use this command to join an channel!",
aliases = ["c", "cjoin", "cj"])
def channel(sender, command, args):
channel = args[0]
channelList.put(sender, channel) #so if player does /channel balkan command it puts his name and channel (balkan in this case) in hashmap...
sender.sendMessage("%sYou've successfully joined %s %s %s channel!"%(bukkit.ChatColor.DARK_AQUA, bukkit.ChatColor.AQUA, channel, bukkit.ChatColor.DARK_AQUA))
return True
@hook.event("player.PlayerChatEvent", "NORMAL")
def onPlayerChatEvent(event):
p = event.getPlayer()
message = event.getMessage()
messagesubstring = message[:1]
event.setCancelled(1)
playername = event.getPlayer().getDisplayName()
if messagesubstring == "!":
plist1 = #How do I get this list? It's list of players that are in HashMap with "balkan" as second hashmap argument...
userChannel = "balkan"
online = Bukkit.getOnlinePlayers()
lenghtonline = len(online)
b = lenghtonline - 1
a = 0
if a <= b:
if channelList.get(p) == userChannel:
plist1.sendMessage("blabla")
提前致谢!
答案 0 :(得分:0)
您可以使用HashMap.entrySet()
来迭代HashMap
:
Java:
for(Entry<String, String> e: channelList.entrySet()){
if(userChannel.equals(e.getValue()){
pist1.add(e.getKey());
}
}
在Jython中你可能需要像这样调用:
Iterator<Entry<String, String>> it = channelList.entrySet().iterator();
while(it.hasNext()){
Entry<String, String> e = it.next();
...
}