mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2024-11-14 23:15:10 +01:00
Added reload-timer (can be configured)
This commit is contained in:
parent
1d22e28954
commit
225c59c2ea
@ -232,7 +232,7 @@ public class Commands extends BukkitCommand {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
player.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.RELOADED_SHOPS, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(ShopUtils.reloadShops()))));
|
||||
player.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.RELOADED_SHOPS, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(ShopUtils.reloadShops(true)))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@ package de.epiceric.shopchest;
|
||||
|
||||
import de.epiceric.shopchest.config.Config;
|
||||
import de.epiceric.shopchest.config.Regex;
|
||||
import de.epiceric.shopchest.event.ShopReloadEvent;
|
||||
import de.epiceric.shopchest.language.LanguageUtils;
|
||||
import de.epiceric.shopchest.language.LocalizedMessage;
|
||||
import de.epiceric.shopchest.listeners.*;
|
||||
@ -26,6 +27,7 @@ import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
@ -187,6 +189,18 @@ public class ShopChest extends JavaPlugin {
|
||||
database = new MySQL(this);
|
||||
}
|
||||
|
||||
if (config.auto_reload_time > 0) {
|
||||
Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ShopReloadEvent event = new ShopReloadEvent(Bukkit.getConsoleSender());
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) getLogger().info(LanguageUtils.getMessage(LocalizedMessage.Message.RELOADED_SHOPS, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(ShopUtils.reloadShops(true)))));
|
||||
}
|
||||
}, config.auto_reload_time * 20, config.auto_reload_time * 20);
|
||||
}
|
||||
|
||||
lockette = getServer().getPluginManager().getPlugin("Lockette") != null;
|
||||
lwc = getServer().getPluginManager().getPlugin("LWC") != null;
|
||||
|
||||
@ -287,7 +301,7 @@ public class ShopChest extends JavaPlugin {
|
||||
* Initializes the shops
|
||||
*/
|
||||
private void initializeShops() {
|
||||
int count = ShopUtils.reloadShops();
|
||||
int count = ShopUtils.reloadShops(false);
|
||||
getLogger().info("Initialized " + String.valueOf(count) + " Shops");
|
||||
}
|
||||
|
||||
@ -381,7 +395,7 @@ public class ShopChest extends JavaPlugin {
|
||||
/**
|
||||
* Provides a reader for a text file located inside the jar.
|
||||
* The returned reader will read text with the UTF-8 charset.
|
||||
* @param file - the filename of the resource to load
|
||||
* @param file the filename of the resource to load
|
||||
* @return null if getResource(String) returns null
|
||||
* @throws IllegalArgumentException - if file is null
|
||||
*/
|
||||
|
@ -105,6 +105,9 @@ public class Config {
|
||||
/** The default shop limit for players and groups that are not listed in {@link #shopLimits_player} or in {@link #shopLimits_group} **/
|
||||
public int default_limit;
|
||||
|
||||
/** The time between automatic shop reloads (if set to 0, the timer will be disabled) **/
|
||||
public int auto_reload_time;
|
||||
|
||||
/** The main command of ShopChest <i>(default: shop)</i> **/
|
||||
public String main_command_name;
|
||||
|
||||
@ -272,6 +275,7 @@ public class Config {
|
||||
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");
|
||||
auto_reload_time = plugin.getConfig().getInt("auto-reload-time");
|
||||
main_command_name = plugin.getConfig().getString("main-command-name");
|
||||
language_file = plugin.getConfig().getString("language-file");
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package de.epiceric.shopchest.event;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@ -11,18 +11,18 @@ import org.bukkit.event.HandlerList;
|
||||
public class ShopReloadEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Player player;
|
||||
private CommandSender sender;
|
||||
private boolean cancelled;
|
||||
|
||||
public ShopReloadEvent(Player player) {
|
||||
this.player = player;
|
||||
public ShopReloadEvent(CommandSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Player who is involved in this event
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -195,8 +195,8 @@ public class ShopUtils {
|
||||
* Reload the shops
|
||||
* @return Amount of shops, which were reloaded
|
||||
*/
|
||||
public static int reloadShops() {
|
||||
plugin.getShopChestConfig().reload(false, true);
|
||||
public static int reloadShops(boolean reloadConfig) {
|
||||
if (reloadConfig) plugin.getShopChestConfig().reload(false, true);
|
||||
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
ShopUtils.removeShop(shop, false);
|
||||
|
@ -23,6 +23,10 @@ remove-shop-on-error: false
|
||||
# Value MUST be a number (e.g. 1, 1.5, 2.75, ...)
|
||||
maximal-distance: 1.75
|
||||
|
||||
# Set the time in seconds between automatic shop reloads.
|
||||
# You can set this to 0 to disable automatic shop reloads.
|
||||
auto-reload-time: 1200
|
||||
|
||||
# Set the price a player has to pay in order to create...
|
||||
# You can set this to 0 to disable costs.
|
||||
# Value MUST be a number (e.g. 1, 1.5, 2.75, ...)
|
||||
|
Loading…
Reference in New Issue
Block a user