From 3671cf09daa89e76fbd81648143a191d2964c9e3 Mon Sep 17 00:00:00 2001 From: sandtechnology Date: Tue, 7 Apr 2020 13:10:43 +0800 Subject: [PATCH] Implement missed item name features and event Former-commit-id: b36977fcb5213c2eb45df91d00eaf2e667cd8bd2 --- .../quickshop/shop/VirtualDisplayItem.java | 26 +++++++++++++++---- .../quickshop/util/SentryErrorReporter.java | 24 ++++++++++------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java index 709ab1b70..36908f6e1 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java @@ -25,12 +25,8 @@ import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedDataWatcher; -import java.lang.reflect.InvocationTargetException; -import java.util.*; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.ConcurrentSkipListSet; -import java.util.concurrent.atomic.AtomicInteger; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; @@ -42,8 +38,15 @@ import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.maxgamer.quickshop.event.ShopDisplayItemSpawnEvent; import org.maxgamer.quickshop.util.Util; +import java.lang.reflect.InvocationTargetException; +import java.util.*; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.atomic.AtomicInteger; + public class VirtualDisplayItem extends DisplayItem { @@ -157,6 +160,12 @@ public class VirtualDisplayItem extends DisplayItem { //List Type are more complex //Create a DataWatcher WrappedDataWatcher wpw = new WrappedDataWatcher(); + //https://wiki.vg/index.php?title=Entity_metadata#Entity + if (plugin.getConfig().getBoolean("shop.display-item-use-name")) { + wpw.setObject(2,WrappedDataWatcher.Registry.getChatComponentSerializer(true),Optional.of(WrappedChatComponent.fromText(Util.getItemStackName(shop.getItem())).getHandle())); + wpw.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3,WrappedDataWatcher.Registry.get(Boolean.class)),true); + } + //Must in the certain slot:https://wiki.vg/Entity_metadata#Item //For 1.13 is 6, and 1.14+ is 7 switch (version) { @@ -276,6 +285,13 @@ public class VirtualDisplayItem extends DisplayItem { @Override public void spawn() { + ShopDisplayItemSpawnEvent shopDisplayItemSpawnEvent = new ShopDisplayItemSpawnEvent(shop, originalItemStack, DisplayType.VIRTUALITEM); + Bukkit.getPluginManager().callEvent(shopDisplayItemSpawnEvent); + if (shopDisplayItemSpawnEvent.isCancelled()) { + Util.debugLog( + "Canceled the displayItem spawning because a plugin setCancelled the spawning event, usually this is a QuickShop Add on"); + return; + } load(); sendFakeItemToAll(); isDisplay = true; diff --git a/src/main/java/org/maxgamer/quickshop/util/SentryErrorReporter.java b/src/main/java/org/maxgamer/quickshop/util/SentryErrorReporter.java index 31a3396e8..5f6ee61e2 100644 --- a/src/main/java/org/maxgamer/quickshop/util/SentryErrorReporter.java +++ b/src/main/java/org/maxgamer/quickshop/util/SentryErrorReporter.java @@ -24,16 +24,6 @@ import io.sentry.SentryClientFactory; import io.sentry.context.Context; import io.sentry.event.BreadcrumbBuilder; import io.sentry.event.UserBuilder; -import java.io.IOException; -import java.net.ProtocolException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; -import java.util.logging.Filter; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.plugin.InvalidPluginException; @@ -45,6 +35,17 @@ import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.util.paste.Paste; import org.maxgamer.quickshop.watcher.UpdateWatcher; +import java.io.IOException; +import java.net.ProtocolException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import java.util.logging.Filter; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + /** * Auto report errors to qs's sentry. */ @@ -344,6 +345,9 @@ public class SentryErrorReporter { if (level != Level.WARNING && level != Level.SEVERE) { return true; } + if(record.getThrown()==null){ + return true; + } if (Util.isDevMode()) { sendError(record.getThrown(), record.getMessage()); return true;