2017-09-08 39 views
0

該腳本檢查配置文件中的技能,並允許僅使用它們(爲了停止黑客攻擊)。從一個文件獲取整數列表

這裏是如何工作的過程我的腳本工作:

#1沒有與此技能列表特殊的.ini配置文件:

CommunityAvailableBuffs = 11517,11522; 

#2文件配置。 java從配置文件獲取一個列表並將其轉換爲整數:

public static List<Integer> COMMUNITY_AVAILABLE_BUFFS; 

final String[] allowedBuffs = 
CommunityBoard.getString("CommunityAvailableBuffs", "").split(","); 
COMMUNITY_AVAILABLE_BUFFS = new ArrayList<>(allowedBuffs.length); 
    for (String s : allowedBuffs) 
    { 
     COMMUNITY_AVAILABLE_BUFFS.add(Integer.parseInt(s)); 
    } 

#3文件HomeBoard.java從config.java文件中獲取此列表並檢查此列表中的技能。

if (!Config.COMMUNITY_AVAILABLE_BUFFS.contains(skill.getId())) 
{ 
    continue; 
} 

我的問題是如何直接在HomeBoard.java文件,而無需使用配置和config.java文件粘貼技巧列表中,我試圖用這樣的:

List<Integer> allallowedBuffs = "11517,11522"; 
final String[] allowedBuffs = CommunityBoard.getString(allallowedBuffs, "").split(","); 
allallowedBuffs = new ArrayList<>(allowedBuffs.length); 
for (String s : allowedBuffs) 
{ 
    allallowedBuffs.add(Integer.parseInt(s)); 
} 

if (!allowedBuffsend.contains(skill.getId())) 
{ 
    continue; 
} 

但不幸的是,它不起作用。

+1

什麼是不工作? –

+0

'「11517,11522」'是一個字符串不是整數 –

+0

的列表是,控制檯給了我這個錯誤: \t列表 allallowedBuffs =「11517,11522」; \t ^^^^^^^^^^^^^ 類型不匹配:無法將字符串轉換爲列表

回答

2

如果我正確理解你的問題,你可以簡單地使用下面的行來填充allallowedBuffs與一些硬編碼數據。

List<Integer> allallowedBuffs = Arrays.asList(11517,11522); 
+0

非常感謝,問題已解決! –

1

試試這個,如果是Java8

List<Integer> allallowedBuffs = List.of(11517, 11522);