Berry_so
本帖最后由 Berry_so 于 2021-2-16 11:14 编辑

如何判定自定GUI内某槽位的某个物品是否含有配置文件路径内的String,并替换为多行Lore(即集合)

ABlueCat
本帖最后由 dengyu 于 2021-2-16 10:37 编辑
  1.                         ItemMeta test = item.getItemMeta();
  2.                         List<String> l = test.getLore();
  3.                         List<String> list2 = new ArrayList<>();
  4.                         List<String> newList = Main.getConfigList("list在配置文件的地址");
  5.                         for (String string : l)
  6.                         {
  7.                                 if (string.contains("指定字符串"))
  8.                                 {
  9.                                         string.replaceAll("指定字符串", "该字符串的第一行的目标替换字符串");
  10.                                         list2.add(string);
  11.                                         for (String str : newList)
  12.                                         {
  13.                                                 list2.add(str);
  14.                                         }
  15.                                 }
  16.                                 else
  17.                                 {
  18.                                         list2.add(string);
  19.                                 }
  20.                         }
  21.                         test.setLore(list2);
  22.                         item.setItemMeta(test);
复制代码

看看这个不知道能不能帮你(没有实际验证)

Berry_so
dengyu 发表于 2021-2-16 10:33
看看这个不知道能不能帮你(没有实际验证)

就是判定字符串以后,遍历集合,然后在遍历的时候替换嘛,这样的话我那我写个方法,每次要用的时候调用这个方法就好了吧

ABlueCat
Berry_so 发表于 2021-2-16 10:48
就是判定字符串以后,遍历集合,然后在遍历的时候替换嘛,这样的话我那我写个方法,每次要用的时候调用这 ...

差不多就是这个意思

Berry_so
dengyu 发表于 2021-2-16 10:49
差不多就是这个意思

谢大佬解惑