Java Code Examples for org.bukkit.inventory.ItemStack#getLore()

The following examples show how to use org.bukkit.inventory.ItemStack#getLore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LegacyItemTag.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public String get(ItemStack item) {
  final List<String> lore = item.getLore();
  if (lore == null || lore.isEmpty()) return null;

  final Matcher matcher = regex.matcher(lore.get(0));
  return matcher.find() ? decode(matcher.group(1)) : null;
}
 
Example 2
Source File: LegacyItemTag.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void set(ItemStack item, String value) {
  List<String> lore = item.getLore();

  // If the item has no lore, ensure there is at least 1 line.
  if (lore == null || lore.isEmpty()) {
    item.setLore(Collections.singletonList(""));
    lore = item.getLore();
  }

  lore.set(0, sequence + encode(value) + sequence + regex.matcher(lore.get(0)).replaceAll(""));
  item.setLore(lore);
}
 
Example 3
Source File: LegacyItemTag.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void clear(ItemStack item) {
  final List<String> lore = item.getLore();
  if (lore == null || lore.isEmpty()) return;

  String line = lore.get(0);
  lore.set(0, line = regex.matcher(line).replaceAll(""));
  if (line.isEmpty()) lore.remove(0);

  item.setLore(lore);
}