Added config value "maximal-item-distance"

This should fix the issue, that shop items are despawning and not spawning again after the chunk unloads.
The item spawn delay was removed.
This commit is contained in:
Eric 2016-08-17 21:26:55 +02:00
parent 15099eca36
commit be52d2c623
3 changed files with 38 additions and 24 deletions

View File

@ -106,15 +106,15 @@ 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;
/** The maximum distance between a player and a shop to see the hologram **/
public double maximal_distance;
/** The maximum distance between a player and a shop to see the shop item **/
public double maximal_item_distance;
/** The price a player has to pay in order to create a normal shop **/
public double shop_creation_price_normal;
@ -286,7 +286,6 @@ 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");
@ -298,6 +297,7 @@ public class Config {
remove_shop_on_error = plugin.getConfig().getBoolean("remove-shop-on-error");
two_line_hologram_lift = plugin.getConfig().getDouble("two-line-hologram-lift");
maximal_distance = plugin.getConfig().getDouble("maximal-distance");
maximal_item_distance = plugin.getConfig().getDouble("maximal-item-distance");
shop_creation_price_normal = plugin.getConfig().getDouble("shop-creation-price.normal");
shop_creation_price_admin = plugin.getConfig().getDouble("shop-creation-price.admin");
default_limit = plugin.getConfig().getInt("shop-limits.default");

View File

@ -25,19 +25,37 @@ public class ShopItemListener implements Listener {
this.shopUtils = plugin.getShopUtils();
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(final PlayerJoinEvent e) {
long spawnDelay = plugin.getShopChestConfig().item_spawn_delay;
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
Player p = e.getPlayer();
for (Shop shop : shopUtils.getShops()) {
if (shop.getLocation().distance(p.getLocation()) <= plugin.getShopChestConfig().maximal_item_distance) {
shop.getItem().setVisible(p, true);
} else {
shop.getItem().setVisible(p, false);
}
}
}
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 onPlayerTeleport(PlayerTeleportEvent e) {
Player p = e.getPlayer();
for (Shop shop : shopUtils.getShops()) {
if (shop.getLocation().distance(e.getTo()) <= plugin.getShopChestConfig().maximal_item_distance) {
shop.getItem().setVisible(p, true);
} else {
shop.getItem().setVisible(p, false);
}
}
}
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent e) {
Player p = e.getPlayer();
for (Shop shop : shopUtils.getShops()) {
if (shop.getLocation().distance(p.getLocation()) <= plugin.getShopChestConfig().maximal_item_distance) {
shop.getItem().setVisible(p, true);
}
}
}

View File

@ -18,12 +18,6 @@ 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".
@ -60,10 +54,12 @@ append-potion-level-to-item-name: false
# This might be useful if you're removing shop chests with WorldEdit, resetting plots, or similar
remove-shop-on-error: false
# Set the maximal distance to the shop where the player can see the hologram.
# Value MUST be a number (e.g. 1, 1.5, 2.75, ...)
# Set the maximal distance (in blocks) to the shop where the player can see the hologram.
maximal-distance: 1.75
# Set the maximal distance (in blocks) to the shop where the player can see the floatig shop item.
maximal-item-distance: 40
# Set the time in seconds between automatic shop reloads.
# You can set this to 0 to disable automatic shop reloads.
auto-reload-time: 1200