亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何獲取字符串內的字符串(yaml)

如何獲取字符串內的字符串(yaml)

蠱毒傳說 2023-06-28 15:31:15
我正在制作一個我的世界插件,我想在字符串(棍子/鉆石)中獲取字符串,我該怎么做這是一個minecraft插件YAMLitem:  stick:    name: Stick    lore: just a stick    amount: 5    percent: 100  diamond:    name: Shiny Diamond    lore: Shiny Shiny    amount: 1    percent: 50這是我的java代碼Random r = new Random();int result = r.nextInt(getConfig().getStringList("item").size());String titem = getConfig().getStringList("item").get(result);Material itemm = Material.getMaterial(titem);int amount = getConfig().getInt(titem + ".amount");if (rand.nextInt(100) < getConfig().getInt(titem + ".percent")) {    ItemStack item = new ItemStack(itemm, amount);    SkullMeta pm = (SkullMeta) item.getItemMeta();    item.setItemMeta(pm);    monster.getWorld().dropItem(e.getEntity().getLocation(), item);}除了這個錯誤之外,它什么也沒做:在 cc.gorjoe.spigot.mobDie.Main.onEntityDeath(Main.java:50) ~[?:?]第50行對應的行String titem = getConfig().getStringList("item").get(result);
查看完整描述

1 回答

?
溫溫醬

TA貢獻1752條經驗 獲得超4個贊

好的,問題解決了,只需通過一個簡單的 for 循環即可完成


ArrayList<String> ran = new ArrayList<String>();


for (String x : getConfig().getConfigurationSection("item").getKeys(false)) {

    System.out.println(x + " oo");

    ran.add(x);

}


查看完整回答
反對 回復 2023-06-28
  • 1 回答
  • 0 關注
  • 187 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號