mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-09 16:47:36 +01:00
Add ability to reload discount and restriction module (Resolves #252)
This commit is contained in:
parent
4acd3efda1
commit
e520544d3a
@ -1,6 +1,7 @@
|
|||||||
package com.Acrobot.ChestShop.Commands;
|
package com.Acrobot.ChestShop.Commands;
|
||||||
|
|
||||||
import com.Acrobot.ChestShop.ChestShop;
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
|
import com.Acrobot.ChestShop.Events.ChestShopReloadEvent;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
@ -12,7 +13,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
public class Version implements CommandExecutor {
|
public class Version implements CommandExecutor {
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
if (args.length > 0 && args[0].equals("reload")) {
|
if (args.length > 0 && args[0].equals("reload")) {
|
||||||
ChestShop.getPlugin().loadConfig();
|
ChestShop.callEvent(new ChestShopReloadEvent(sender));
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.DARK_GREEN + "The config was reloaded.");
|
sender.sendMessage(ChatColor.DARK_GREEN + "The config was reloaded.");
|
||||||
return true;
|
return true;
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.Acrobot.ChestShop.Events;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a plugin reload call
|
||||||
|
*
|
||||||
|
* @author Acrobot
|
||||||
|
*/
|
||||||
|
public class ChestShopReloadEvent extends Event {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private CommandSender sender;
|
||||||
|
|
||||||
|
public ChestShopReloadEvent(CommandSender sender) {
|
||||||
|
this.sender = sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return CommandSender who initiated the call
|
||||||
|
*/
|
||||||
|
public CommandSender getSender() {
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,7 @@ package com.Acrobot.ChestShop.Listeners.Modules;
|
|||||||
|
|
||||||
import com.Acrobot.Breeze.Utils.PriceUtil;
|
import com.Acrobot.Breeze.Utils.PriceUtil;
|
||||||
import com.Acrobot.ChestShop.ChestShop;
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
import com.Acrobot.ChestShop.Containers.AdminInventory;
|
import com.Acrobot.ChestShop.Events.ChestShopReloadEvent;
|
||||||
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
|
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
|
||||||
import com.Acrobot.ChestShop.Permission;
|
import com.Acrobot.ChestShop.Permission;
|
||||||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
||||||
@ -28,6 +28,10 @@ public class DiscountModule implements Listener {
|
|||||||
private Set<String> groupList = new HashSet<String>();
|
private Set<String> groupList = new HashSet<String>();
|
||||||
|
|
||||||
public DiscountModule() {
|
public DiscountModule() {
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load() {
|
||||||
config = YamlConfiguration.loadConfiguration(ChestShop.loadFile("discounts.yml"));
|
config = YamlConfiguration.loadConfiguration(ChestShop.loadFile("discounts.yml"));
|
||||||
|
|
||||||
config.options().header("This file is for discount management. You are able to do that:\n" +
|
config.options().header("This file is for discount management. You are able to do that:\n" +
|
||||||
@ -45,6 +49,11 @@ public class DiscountModule implements Listener {
|
|||||||
groupList = config.getKeys(false);
|
groupList = config.getKeys(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onReload(ChestShopReloadEvent event) {
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPreTransaction(PreTransactionEvent event) {
|
public void onPreTransaction(PreTransactionEvent event) {
|
||||||
if (event.getTransactionType() != BUY || !NameManager.isAdminShop(event.getOwnerAccount().getUuid())) {
|
if (event.getTransactionType() != BUY || !NameManager.isAdminShop(event.getOwnerAccount().getUuid())) {
|
||||||
|
@ -2,6 +2,7 @@ package com.Acrobot.ChestShop.Listeners.Modules;
|
|||||||
|
|
||||||
import com.Acrobot.Breeze.Utils.PriceUtil;
|
import com.Acrobot.Breeze.Utils.PriceUtil;
|
||||||
import com.Acrobot.ChestShop.ChestShop;
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
|
import com.Acrobot.ChestShop.Events.ChestShopReloadEvent;
|
||||||
import com.Acrobot.ChestShop.Events.ItemParseEvent;
|
import com.Acrobot.ChestShop.Events.ItemParseEvent;
|
||||||
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -34,6 +35,10 @@ public class PriceRestrictionModule implements Listener {
|
|||||||
private static final double INVALID_PATH = Double.MIN_VALUE;
|
private static final double INVALID_PATH = Double.MIN_VALUE;
|
||||||
|
|
||||||
public PriceRestrictionModule() {
|
public PriceRestrictionModule() {
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load() {
|
||||||
File file = new File(ChestShop.getFolder(), "priceLimits.yml");
|
File file = new File(ChestShop.getFolder(), "priceLimits.yml");
|
||||||
|
|
||||||
configuration = YamlConfiguration.loadConfiguration(file);
|
configuration = YamlConfiguration.loadConfiguration(file);
|
||||||
@ -92,6 +97,11 @@ public class PriceRestrictionModule implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onReload(ChestShopReloadEvent event) {
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPreShopCreation(PreShopCreationEvent event) {
|
public void onPreShopCreation(PreShopCreationEvent event) {
|
||||||
ItemParseEvent parseEvent = new ItemParseEvent(event.getSignLine(ITEM_LINE));
|
ItemParseEvent parseEvent = new ItemParseEvent(event.getSignLine(ITEM_LINE));
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.Acrobot.ChestShop.Plugins;
|
package com.Acrobot.ChestShop.Plugins;
|
||||||
|
|
||||||
|
import com.Acrobot.ChestShop.Events.ChestShopReloadEvent;
|
||||||
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
|
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
|
||||||
import com.Acrobot.ChestShop.Permission;
|
import com.Acrobot.ChestShop.Permission;
|
||||||
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
||||||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
|
||||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
@ -18,6 +18,12 @@ import static com.Acrobot.Breeze.Utils.BlockUtil.isSign;
|
|||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
public class ChestShop implements Listener {
|
public class ChestShop implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public static void onReload(ChestShopReloadEvent event) {
|
||||||
|
com.Acrobot.ChestShop.ChestShop.getPlugin().loadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public static void onProtectionCheck(ProtectionCheckEvent event) {
|
public static void onProtectionCheck(ProtectionCheckEvent event) {
|
||||||
if (event.getResult() == Event.Result.DENY || event.isBuiltInProtectionIgnored()) {
|
if (event.getResult() == Event.Result.DENY || event.isBuiltInProtectionIgnored()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user