/**
* Parses an {@link Crowbar} from a given {@link ItemStack}.
*
* @param stack
* the stack to parse from
* @return the {@link Crowbar} instance
*/
public static Optional<Crowbar> fromStack(ItemStack stack) {
if (stack == null || !stack.hasItemMeta()) {
return Optional.absent();
}
ItemMeta meta = stack.getItemMeta();
if (!meta.hasDisplayName() || !meta.hasLore() || !meta.getDisplayName().equals(CROWBAR_NAME)) {
return Optional.absent();
}
Crowbar crowbar = new Crowbar();
List<String> loreList = meta.getLore();
for (String lore : loreList) {
lore = ChatColor.stripColor(lore);
int length = lore.length();
for (int i = 0; i < length; i++) {
char character = lore.charAt(i);
if (Character.isDigit(character)) {
int amount = Integer.parseInt(String.valueOf(character));
if (lore.startsWith(END_FRAME_USE_TAG)) {
crowbar.setEndFrameUses(amount);
break;
} else if (lore.startsWith(SPAWNER_USE_TAG)) {
crowbar.setSpawnerUses(amount);
break;
}
}
}
}
return Optional.of(crowbar);
}
Crowbar.java 文件源码
java
阅读 21
收藏 0
点赞 0
评论 0
项目:HCFCore
作者:
评论列表
文章目录