diff --git a/src/main/java/de/epiceric/shopchest/ShopChest.java b/src/main/java/de/epiceric/shopchest/ShopChest.java index 6f9cf3d..5ac4ad7 100644 --- a/src/main/java/de/epiceric/shopchest/ShopChest.java +++ b/src/main/java/de/epiceric/shopchest/ShopChest.java @@ -288,8 +288,6 @@ public class ShopChest extends JavaPlugin { debug(e); } - initializeShops(); - debug("Registering listeners..."); getServer().getPluginManager().registerEvents(new HologramUpdateListener(this), this); getServer().getPluginManager().registerEvents(new ShopItemListener(this), this); @@ -300,6 +298,7 @@ public class ShopChest extends JavaPlugin { if (!Utils.getServerVersion().equals("v1_8_R1")) getServer().getPluginManager().registerEvents(new BlockExplodeListener(this), this); + initializeShops(); } @Override diff --git a/src/main/java/de/epiceric/shopchest/config/Config.java b/src/main/java/de/epiceric/shopchest/config/Config.java index 4607089..32d14c7 100644 --- a/src/main/java/de/epiceric/shopchest/config/Config.java +++ b/src/main/java/de/epiceric/shopchest/config/Config.java @@ -106,6 +106,9 @@ public class Config { /** Whether the item amount should be calculated to fit the available money or inventory space **/ public boolean auto_calculate_item_amount; + /** Delay in ticks after a player joins, when the shop item spawn packets should be sent to the player **/ + public long item_spawn_delay; + /** Amount the hologram should be lifted **/ public double two_line_hologram_lift; @@ -283,6 +286,7 @@ public class Config { shopLimits_group = (plugin.getConfig().getConfigurationSection("shop-limits.group") == null) ? new HashSet() : plugin.getConfig().getConfigurationSection("shop-limits.group").getKeys(true); shopLimits_player = (plugin.getConfig().getConfigurationSection("shop-limits.player") == null) ? new HashSet() : plugin.getConfig().getConfigurationSection("shop-limits.player").getKeys(true); blacklist = (plugin.getConfig().getStringList("blacklist") == null) ? new ArrayList() : plugin.getConfig().getStringList("blacklist"); + item_spawn_delay = plugin.getConfig().getLong("item-spawn-delay"); buy_greater_or_equal_sell = plugin.getConfig().getBoolean("buy-greater-or-equal-sell"); hopper_protection = plugin.getConfig().getBoolean("hopper-protection"); two_line_prices = plugin.getConfig().getBoolean("two-line-prices"); diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopItemListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopItemListener.java index 6977518..bef7326 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopItemListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopItemListener.java @@ -15,8 +15,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.*; import org.bukkit.event.player.*; -import java.lang.reflect.InvocationTargetException; - public class ShopItemListener implements Listener { private ShopUtils shopUtils; @@ -27,10 +25,19 @@ public class ShopItemListener implements Listener { this.shopUtils = plugin.getShopUtils(); } - @EventHandler - public void onPlayerJoin(PlayerJoinEvent e) { - for (Shop shop : plugin.getShopUtils().getShops()) { - shop.getItem().setVisible(e.getPlayer(), true); + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerJoin(final PlayerJoinEvent e) { + long spawnDelay = plugin.getShopChestConfig().item_spawn_delay; + + if (spawnDelay > 0) { + Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { + @Override + public void run() { + for (Shop shop : plugin.getShopUtils().getShops()) { + shop.getItem().setVisible(e.getPlayer(), true); + } + } + }, spawnDelay); } } diff --git a/src/main/java/de/epiceric/shopchest/utils/Utils.java b/src/main/java/de/epiceric/shopchest/utils/Utils.java index 0e1ac51..692774b 100644 --- a/src/main/java/de/epiceric/shopchest/utils/Utils.java +++ b/src/main/java/de/epiceric/shopchest/utils/Utils.java @@ -196,8 +196,10 @@ public class Utils { */ public static boolean sendPacket(ShopChest plugin, Object packet, Player player) { try { - if (packet == null) + if (packet == null) { + plugin.debug("Failed to send packet: Packet is null"); return false; + } Class packetClass = Class.forName("net.minecraft.server." + getServerVersion() + ".Packet"); Object nmsPlayer = player.getClass().getMethod("getHandle").invoke(player); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a95111c..ee75da1 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -18,6 +18,12 @@ show-shop-items: true # The file may get large! Please enable this setting when reporting bugs. enable-debug-log: false +# Set the delay in ticks (20 ticks = 1 second) after a player joins, when the spawn packets of the +# floating shop item should be sent to the player. If you experience errors, that the items won't spawn +# after joining, you may increase this value a bit. You can also set this to '0' to send the packets +# without a delay after joining. +item-spawn-delay: 20 + # Set whether the buy- and sell price should be arranged below each other. # The first line will be the buy price with the message "message.hologram.only-buy", # the second line will be the sell price with the message "message.hologram.only-sell".