mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 10:22:29 +00:00
Added configurable item spawn delay after join
This might fix the issue, that items won't be spawned after joining.
This commit is contained in:
parent
af3b6612b1
commit
f511ff66a0
@ -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
|
||||
|
@ -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<String>() : plugin.getConfig().getConfigurationSection("shop-limits.group").getKeys(true);
|
||||
shopLimits_player = (plugin.getConfig().getConfigurationSection("shop-limits.player") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.player").getKeys(true);
|
||||
blacklist = (plugin.getConfig().getStringList("blacklist") == null) ? new ArrayList<String>() : 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");
|
||||
|
@ -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,12 +25,21 @@ public class ShopItemListener implements Listener {
|
||||
this.shopUtils = plugin.getShopUtils();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent e) {
|
||||
|
@ -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);
|
||||
|
@ -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".
|
||||
|
Loading…
Reference in New Issue
Block a user