有工作代碼如何使這個單一變量成(NAMEA或名稱B或NameC)
else if (command.equalsIgnoreCase("noclip") && !playerName.equalsIgnoreCase("Tom")) {
PlayerHandler.messageToAll = (playerName
+ " tried to noclip and has been autobanned!");
appendToBanned(playerName);
disconnected = true;
,因爲它說,不等於湯姆,我是誰可以使用的只有一個命令。但是,我想爲此命令添加多個用戶。
我想說以下,但它不工作...我怎麼會正確地說這(java)?
else if (command.equalsIgnoreCase("noclip") && !playerName.equalsIgnoreCase("Tom" || "Tommy" || "Mod Tom")) {
PlayerHandler.messageToAll = (playerName
+ " tried to noclip and has been autobanned!");
appendToBanned(playerName);
disconnected = true;
您使用某種類型的集合。在這個特定的情況下,'HashSet'似乎是一個不錯的選擇。 – Mephy 2014-09-19 06:28:35
這將是最好有一個用戶/播放器對象和playerName.equalsIgnoreCase(player.getName())或如果player.isPlayer(用戶名)..但解決您當前的問題&&(playerName.equalsIgnoreCase(「湯姆」)| | playerName.equalsIgnoreCase(「Tommy」)) – 2014-09-19 06:31:04
我建議檢查用戶權限,而不是用戶。然後將用戶放入組中。所以你可能有一個組「noclippers」並添加用戶。然後你會檢查用戶是否在noclippers組(如果該組有權利的話)。 – Fildor 2014-09-19 06:31:45