我需要寫一張支票。它的本質是:應該返回true或者false,如果玩家擁有一個存在於配置庫中的東西(只有他),否則返回false。如何從config.yml加載id列表?
-3
A
回答
0
因此,這裏是你的問題的解決方案:
@SuppressWarnings("deprecation")
public boolean hasInInv(Player p) {
List<String> list = getConfig().getStringList("List");
for(ItemStack i : p.getInventory().getContents()) {
if(i != null) {
boolean found = false;
for(String st : list) {
if(st.startsWith("" + i.getTypeId())) {
if(st.startsWith(i.getTypeId() + ":")) {
try {
byte data = Byte.parseByte(st.replaceFirst(i.getTypeId() + ":", ""));
if(data != i.getDurability()) {
continue;
} else {
found = true;
break;
}
} catch(Exception ex) {
System.out.println("Error in Config: " + st + " is not a valid Item");
return false;
}
}
found = true;
break;
}
}
if(!found) {
return false;
}
}
}
return true;
}
而且配置應顯示這樣的:
List:
- 1
- 2
- 3
- 4
- '17:3'
- '17:1'
相關問題
- 1. 如何從玩家庫存配置中加載ID列表? [Bukkit]
- 2. 如何Symfony2的config.yml
- 3. laravel 4急於加載的ID列表
- 4. 如何根據ID列表加載用戶?
- 5. 如何從列表中獲取ID?
- 6. 如何在頁面加載時從localStorage加載jPlayer播放列表?
- 7. 如何從DataReader加載列數據?
- 8. Routing config.yml
- 9. 如何重新加載列表視圖
- 10. 如何加載到組合列表
- 11. 如何在hibernate中加載commandLink列表?
- 12. 如何爲DropdownList加載列表
- 13. 如何重新加載列表WinJS
- 14. 如何重新加載列表視圖?
- 15. 如何將數據加載到列表
- 16. 如何更新表列ID?
- 17. 如何遍歷ID列表
- 18. 如何從Java中的對象內的列表中加載列表
- 19. 如何等待從Parse.com返回列表加載到列表視圖
- 20. 從Apple ID的ID中添加曲目到iTunes播放列表
- 21. 如何從Firebase數據列表加載AutoCompleteTextView?
- 22. 如何從多個數組加載數據到列表視圖?
- 23. 如何從外部R代碼文件加載功能列表?
- 24. 如何從Python中的列表中加載字典?
- 25. 如何從XML加載數據到列表
- 26. AxWMPlib:如何從外部文件加載播放列表
- 27. jQuery手機:如何從列表視圖加載詳細頁面
- 28. 如何從資源中將值加載到數組列表中
- 29. 如何從數據庫加載組合框的列表?
- 30. 分機Js:如何從列表中加載商店<String>
在你存儲什麼樣的格式在您的配置文件中的項目?我們可以看到一些代碼保存/加載的內容和一個示例配置文件? –
可能的重複[如何從配置中加載播放器清單的ID列表? \ [Bukkit \]](http://stackoverflow.com/questions/30965375/how-to-load-id-list-from-config-for-player-inventory-bukkit) –