1
0
mirror of https://e.coding.net/circlecloud/QuickShop.git synced 2024-11-21 01:48:54 +00:00

修复匹配两个物品是否相同的问题

1. 增加判断Lore信息是否相同
2. 增加判断头颅的Owner是否相同
3. 增加判断成书的标题、内容、作者是否相同
This commit is contained in:
17jiong 2018-01-29 00:05:03 +08:00
parent 55cd9e386c
commit e42701f376

View File

@ -392,9 +392,7 @@ public class Util {
}
// Calculate the chunks coordinates. These are 1,2,3 for each chunk, NOT
// location rounded to the nearest 16.
final int x = (int) Math.floor((loc.getBlockX()) / 16.0);
final int z = (int) Math.floor((loc.getBlockZ()) / 16.0);
if (loc.getWorld().isChunkLoaded(x, z)) {
if (loc.getWorld().isChunkLoaded(loc.getBlockX() >> 4, loc.getBlockZ() >> 4)) {
// System.out.println("Chunk is loaded " + x + ", " + z);
return true;
}
@ -476,6 +474,72 @@ public class Util {
return false; // one of the item stacks have a display name
}
}
if (stack1.getItemMeta().hasLore() || stack2.getItemMeta().hasLore()) {
if (stack1.getItemMeta().hasLore() && stack2.getItemMeta().hasLore()) {
if (!stack1.getItemMeta().getLore().equals(stack2.getItemMeta().getLore())) {
return false; // items have different lore
}
} else {
return false; // one of the item stacks have lore
}
}
// Not the same material and not same durability has returned to false
if (stack1.getType() == Material.SKULL_ITEM) {
if (stack1.getDurability() == 3) {
SkullMeta skullMeta1 = (SkullMeta) stack1.getItemMeta();
SkullMeta skullMeta2 = (SkullMeta) stack2.getItemMeta();
if (skullMeta1.hasOwner() || skullMeta2.hasOwner()) {
if (skullMeta1.hasOwner() && skullMeta2.hasOwner()) {
if (!skullMeta1.getOwner().equals(skullMeta1.getOwner())) {
return false;
}
} else {
return false;
}
}
}
}
if (stack1.getType() == Material.WRITTEN_BOOK) {
if (stack1.hasItemMeta() || stack2.hasItemMeta()) {
if (stack1.hasItemMeta() && stack2.hasItemMeta()) {
BookMeta bookMeta1 = (BookMeta) stack1.getItemMeta();
BookMeta bookMeta2 = (BookMeta) stack2.getItemMeta();
// title
if (bookMeta1.hasTitle() || bookMeta2.hasTitle()) {
if (bookMeta1.hasTitle() && bookMeta2.hasTitle()) {
if (!bookMeta1.getTitle().equals(bookMeta2.getTitle())) {
return false;
}
} else {
return false;
}
}
// author
if (bookMeta1.hasAuthor() || bookMeta2.hasAuthor()) {
if (bookMeta1.hasAuthor() && bookMeta2.hasAuthor()) {
if (!bookMeta1.getAuthor().equals(bookMeta2.getAuthor())) {
return false;
}
} else {
return false;
}
}
// content
if (bookMeta1.hasPages() || bookMeta2.hasPages()) {
if (bookMeta1.hasPages() && bookMeta2.hasPages()) {
if (!bookMeta1.getPages().equals(bookMeta2.getPages())) {
return false;
}
} else {
return false;
}
}
} else {
return false;
}
}
}
try {
Class.forName("org.bukkit.inventory.meta.EnchantmentStorageMeta");
final boolean book1 = stack1.getItemMeta() instanceof EnchantmentStorageMeta;