mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-27 04:25:14 +01:00
Work around issue with serialising explorer maps
This is due to a bug in CraftBukkit not properly supporting localised/translatable display names when serialising item meta. This also adds/improves the message when no valid item ID could be generated.
This commit is contained in:
parent
355fa58ac4
commit
8cd89bf8ee
@ -74,12 +74,15 @@ public class MaterialUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Additional checks as serialisation and de-serialisation might lead to different item meta
|
||||
// This would only be done if the items share the same item meta type so it shouldn't be too inefficient
|
||||
// Special check for books as their pages might change when serialising (See SPIGOT-3206)
|
||||
// Special check for explorer maps/every item with a localised name (See SPIGOT-4672)
|
||||
return one.getType() == two.getType()
|
||||
&& one.getDurability() == two.getDurability()
|
||||
&& one.getData().equals(two.getData())
|
||||
&& one.hasItemMeta() && two.hasItemMeta()
|
||||
&& one.getItemMeta() instanceof BookMeta && two.getItemMeta() instanceof BookMeta
|
||||
&& one.getItemMeta().getClass() == two.getItemMeta().getClass()
|
||||
&& one.getItemMeta().serialize().equals(two.getItemMeta().serialize());
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.Acrobot.ChestShop.Configuration.Messages.iteminfo;
|
||||
|
||||
/**
|
||||
@ -43,13 +45,17 @@ public class ItemInfo implements CommandExecutor {
|
||||
try {
|
||||
sender.sendMessage(ChatColor.WHITE + "Full Name: " + ChatColor.GRAY + MaterialUtil.getName(item));
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Full Name Error: " + e.getMessage());
|
||||
sender.sendMessage(ChatColor.RED + "Error while generating full name. Please contact an admin or take a look at the console/log!");
|
||||
ChestShop.getPlugin().getLogger().log(Level.SEVERE, "Error while generating full item name", e);
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
sender.sendMessage(ChatColor.WHITE + "Shop Sign: " + ChatColor.GRAY + MaterialUtil.getSignName(item));
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Shop Sign Error: " + e.getMessage());
|
||||
sender.sendMessage(ChatColor.RED + "Error while generating shop sign name. Please contact an admin or take a look at the console/log!");
|
||||
ChestShop.getPlugin().getLogger().log(Level.SEVERE, "Error while generating shop sign item name", e);
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemInfoEvent event = new ItemInfoEvent(sender, item);
|
||||
|
@ -32,6 +32,8 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.Acrobot.Breeze.Utils.BlockUtil.isSign;
|
||||
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType;
|
||||
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
|
||||
@ -82,7 +84,14 @@ public class PlayerInteract implements Listener {
|
||||
if (ChestShopSign.hasPermission(player, OTHER_NAME_CREATE, sign)) {
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
if (!MaterialUtil.isEmpty(item)) {
|
||||
String itemCode = MaterialUtil.getSignName(item);
|
||||
String itemCode;
|
||||
try {
|
||||
itemCode = MaterialUtil.getSignName(item);
|
||||
} catch (IllegalArgumentException e) {
|
||||
player.sendMessage(ChatColor.RED + "Error while generating shop sign item name. Please contact an admin or take a look at the console/log!");
|
||||
com.Acrobot.ChestShop.ChestShop.getPlugin().getLogger().log(Level.SEVERE, "Error while generating shop sign item name", e);
|
||||
return;
|
||||
}
|
||||
String[] lines = sign.getLines();
|
||||
lines[ITEM_LINE] = itemCode;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user