@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) throws UnsupportedOperationException {
final Object i = item.getSingle(e);
if (i == null || i instanceof ItemStack && ((ItemStack) i).getType() == Material.AIR)
return;
ItemMeta meta = i instanceof ItemStack ? ((ItemStack) i).getItemMeta() : (ItemMeta) ((ItemType) i).getItemMeta();
if (meta == null)
meta = Bukkit.getItemFactory().getItemMeta(Material.STONE);
final Number n = line != null ? line.getSingle(e) : null;
List<String> lore = meta.hasLore() ? new ArrayList<String>(meta.getLore()) : new ArrayList<String>();
if (n == null) {
if (line != null)
return;
switch (mode) {
case SET:
assert delta != null;
lore = Arrays.asList((String) delta[0]);
break;
case ADD:
assert delta != null;
lore.add((String) delta[0]);
break;
case DELETE:
lore = null;
break;
case REMOVE:
case REMOVE_ALL:
assert delta != null;
if (SkriptConfig.caseSensitive.value()) {
lore = Arrays.asList((mode == ChangeMode.REMOVE ? StringUtils.join(lore, "\n").replaceFirst(Pattern.quote((String) delta[0]), "") : StringUtils.join(lore, "\n").replace((CharSequence) delta[0], "")).split("\n"));
} else {
final Matcher m = Pattern.compile(Pattern.quote((String) delta[0]), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE).matcher(StringUtils.join(lore, "\n"));
lore = Arrays.asList((mode == ChangeMode.REMOVE ? m.replaceFirst("") : m.replaceAll("")).split("\n"));
}
break;
case RESET:
assert false;
break;
}
} else {
final int l = Math2.fit(0, n.intValue() - 1, 99); // TODO figure out the actual maximum
for (int j = lore.size(); j <= l; j++)
lore.add("");
switch (mode) {
case SET:
assert delta != null;
lore.set(l, (String) delta[0]);
break;
case DELETE:
lore.remove(l);
break;
case ADD:
assert delta != null;
lore.set(l, lore.get(l) + (String) delta[0]);
break;
case REMOVE:
case REMOVE_ALL:
assert delta != null;
if (SkriptConfig.caseSensitive.value()) {
lore.set(l, mode == ChangeMode.REMOVE ? lore.get(l).replaceFirst(Pattern.quote((String) delta[0]), "") : lore.get(l).replace((CharSequence) delta[0], ""));
} else {
final Matcher m = Pattern.compile(Pattern.quote((String) delta[0]), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE).matcher(lore.get(l));
lore.set(l, mode == ChangeMode.REMOVE ? m.replaceFirst("") : m.replaceAll(""));
}
break;
case RESET:
assert false;
return;
}
}
meta.setLore(lore == null || lore.size() == 0 ? null : lore);
if (i instanceof ItemStack)
((ItemStack) i).setItemMeta(meta);
else
((ItemType) i).setItemMeta(meta);
if (ChangerUtils.acceptsChange(item, ChangeMode.SET, i.getClass())) {