Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
[Fix] 属性支持库 MetaLibrary 函数 getLores() 错误的集合返回值, 应为 List 已修复
Browse files Browse the repository at this point in the history
  • Loading branch information
u2g committed Mar 29, 2017
1 parent 044ba70 commit d2b6e1d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.bukkit.inventory.ItemStack;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -705,6 +706,18 @@ public Set<String> getLores(ItemStack itemStack, boolean ignoreColor) {
return base.getLores(itemStack, ignoreColor);
}

@Override
public List<String> getLore(ItemStack itemStack) {

return base.getLore(itemStack);
}

@Override
public List<String> getLore(ItemStack itemStack, boolean ignoreColor) {

return base.getLore(itemStack, ignoreColor);
}

@Override
public ItemStack setLore(ItemStack itemStack, String... lore) {

Expand Down
42 changes: 35 additions & 7 deletions src/main/java/com/minecraft/moonlake/api/item/MetaExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,16 @@ public ItemStack takeDurability(ItemStack itemStack, int durability) {
}

@Override
@Deprecated
@SuppressWarnings("deprecation")
public Set<String> getLores(ItemStack itemStack) {

return getLores(itemStack, false);
}

@Override
@Deprecated
@SuppressWarnings("deprecation")
public Set<String> getLores(ItemStack itemStack, boolean ignoreColor) {

Validate.notNull(itemStack, "The itemstack object is null.");
Expand All @@ -137,6 +141,30 @@ public Set<String> getLores(ItemStack itemStack, boolean ignoreColor) {
return new HashSet<>(StringUtil.stripColor(itemMeta.getLore()));
}

@Override
public List<String> getLore(ItemStack itemStack) {

return getLore(itemStack, false);
}

@Override
public List<String> getLore(ItemStack itemStack, boolean ignoreColor) {

Validate.notNull(itemStack, "The itemstack object is null.");

ItemMeta itemMeta = itemStack.getItemMeta();

if(itemMeta == null || !itemMeta.hasLore()) {

return null;
}
if(!ignoreColor) {

return itemMeta.getLore();
}
return StringUtil.stripColor(itemMeta.getLore());
}

@Override
public ItemStack setLore(ItemStack itemStack, String... lore) {

Expand Down Expand Up @@ -169,11 +197,11 @@ public ItemStack addLore(ItemStack itemStack, String... lore) {

return itemStack;
}
Set<String> sourceLore = getLores(itemStack);
List<String> sourceLore = getLore(itemStack);

if(sourceLore == null) {

sourceLore = new HashSet<>();
sourceLore = new ArrayList<>();
}
sourceLore.addAll(Arrays.asList(lore));

Expand All @@ -190,11 +218,11 @@ public ItemStack addLore(ItemStack itemStack, Collection<? extends String> lore)

return itemStack;
}
Set<String> sourceLore = getLores(itemStack);
List<String> sourceLore = getLore(itemStack);

if(sourceLore == null) {

sourceLore = new HashSet<>();
sourceLore = new ArrayList<>();
}
sourceLore.addAll(lore);

Expand All @@ -214,7 +242,7 @@ public boolean hasLore(ItemStack itemStack) {

Validate.notNull(itemStack, "The itemstack object is null.");

Set<String> lore = getLores(itemStack);
List<String> lore = getLore(itemStack);

return lore != null && lore.size() > 0;
}
Expand All @@ -233,7 +261,7 @@ public boolean containLore(ItemStack itemStack, Collection<? extends String> lor
Validate.notNull(itemStack, "The itemstack object is null.");
Validate.notNull(lore, "The itemstack lore object is null.");

Set<String> sourceLore = getLores(itemStack);
List<String> sourceLore = getLore(itemStack);

if(sourceLore == null) {

Expand Down Expand Up @@ -267,7 +295,7 @@ public boolean containLoreIgnoreColor(ItemStack itemStack, Collection<? extends
Validate.notNull(itemStack, "The itemstack object is null.");
Validate.notNull(lore, "The itemstack lore object is null.");

Set<String> sourceLore = getLores(itemStack, true);
List<String> sourceLore = getLore(itemStack, true);

if(sourceLore == null) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.bukkit.inventory.ItemStack;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -100,22 +101,43 @@ public interface MetaLibrary extends AttributeLibrary {
ItemStack takeDurability(ItemStack itemStack, int durability);

/**
* 获取物品栈的标签信息
* 获取物品栈的标签信息 (警告: 入门时犯错使用了无序集合)
*
* @param itemStack 物品栈
* @return 标签信息 没有则返回 null
* @deprecated 已过时, 将于 v1.9-a5 删除. 请使用 {@link #getLore(ItemStack)}
*/
@Deprecated
Set<String> getLores(ItemStack itemStack);

/**
* 获取物品栈的标签信息
* 获取物品栈的标签信息 (警告: 入门时犯错使用了无序集合)
*
* @param itemStack 物品栈
* @param ignoreColor 是否忽略颜色
* @return 标签信息 没有则返回 null
* @deprecated 已过时, 将于 v1.9-a5 删除. 请使用 {@link #getLore(ItemStack, boolean)}
*/
@Deprecated
Set<String> getLores(ItemStack itemStack, boolean ignoreColor);

/**
* 获取物品栈的标签信息
*
* @param itemStack 物品栈
* @return 标签信息 没有则返回 null
*/
List<String> getLore(ItemStack itemStack);

/**
* 获取物品栈的标签信息
*
* @param itemStack 物品栈
* @param ignoreColor 是否忽略颜色
* @return 标签信息 没有则返回 null
*/
List<String> getLore(ItemStack itemStack, boolean ignoreColor);

/**
* 将物品栈设置标签信息
*
Expand Down

0 comments on commit d2b6e1d

Please sign in to comment.