mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 10:22:29 +00:00
Updated events
Methods getPlayer() and getShop() don't need to be overridden, as they are now declared in the ShopEvent superclass.
This commit is contained in:
parent
bc13dd7a9d
commit
79660920d8
@ -1,10 +1,7 @@
|
||||
package de.epiceric.shopchest;
|
||||
|
||||
import de.epiceric.shopchest.config.Regex;
|
||||
import de.epiceric.shopchest.event.ShopPreCreateEvent;
|
||||
import de.epiceric.shopchest.event.ShopPreInfoEvent;
|
||||
import de.epiceric.shopchest.event.ShopPreRemoveEvent;
|
||||
import de.epiceric.shopchest.event.ShopReloadEvent;
|
||||
import de.epiceric.shopchest.event.*;
|
||||
import de.epiceric.shopchest.language.LanguageUtils;
|
||||
import de.epiceric.shopchest.language.LocalizedMessage;
|
||||
import de.epiceric.shopchest.nms.JsonBuilder;
|
||||
@ -62,6 +59,7 @@ class ShopCommand extends BukkitCommand {
|
||||
case "REMOVE":
|
||||
case "INFO":
|
||||
case "LIMITS":
|
||||
case "OPEN":
|
||||
sender.sendMessage(ChatColor.RED + "Only players can use this command.");
|
||||
return true;
|
||||
}
|
||||
@ -104,6 +102,9 @@ class ShopCommand extends BukkitCommand {
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.OCCUPIED_SHOP_SLOTS,
|
||||
new LocalizedMessage.ReplacedRegex(Regex.LIMIT, (limit < 0 ? "∞" : String.valueOf(limit))),
|
||||
new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(shopUtils.getShopAmount(p)))));
|
||||
} else if (args[0].equalsIgnoreCase("open")) {
|
||||
needsHelp = false;
|
||||
open(p);
|
||||
}
|
||||
}
|
||||
|
||||
@ -474,6 +475,25 @@ class ShopCommand extends BukkitCommand {
|
||||
ClickType.setPlayerClickType(p, new ClickType(EnumClickType.INFO));
|
||||
}
|
||||
|
||||
/**
|
||||
* A given player opens a shop
|
||||
* @param p The command executor
|
||||
*/
|
||||
private void open(Player p) {
|
||||
plugin.debug(p.getName() + " wants to open a shop");
|
||||
|
||||
ShopPreOpenEvent event = new ShopPreOpenEvent(p);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
plugin.debug("Shop pre open event cancelled");
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.debug(p.getName() + " can now click a chest");
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CLICK_CHEST_OPEN));
|
||||
ClickType.setPlayerClickType(p, new ClickType(EnumClickType.OPEN));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the basic help message
|
||||
* @param sender {@link CommandSender} who will receive the message
|
||||
@ -491,6 +511,7 @@ class ShopCommand extends BukkitCommand {
|
||||
sender.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " remove - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVE));
|
||||
sender.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " info - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_INFO));
|
||||
sender.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " limits - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_LIMITS));
|
||||
sender.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " open - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_OPEN));
|
||||
}
|
||||
|
||||
if (sender.hasPermission(Permissions.RELOAD)) {
|
||||
|
@ -8,26 +8,18 @@ import org.bukkit.event.Cancellable;
|
||||
* Called when a player buys or sells something from or to a shop
|
||||
*/
|
||||
public class ShopBuySellEvent extends ShopEvent implements Cancellable {
|
||||
private Player player;
|
||||
private Shop shop;
|
||||
private Type type;
|
||||
private int newAmount;
|
||||
private double newPrice;
|
||||
private boolean cancelled;
|
||||
|
||||
public ShopBuySellEvent(Player player, Shop shop, Type type, int newAmount, double newPrice) {
|
||||
this.player = player;
|
||||
this.shop = shop;
|
||||
super(player, shop);
|
||||
this.type = type;
|
||||
this.newAmount = newAmount;
|
||||
this.newPrice = newPrice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shop getShop() {
|
||||
return shop;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether the player buys or sells something
|
||||
*/
|
||||
@ -49,11 +41,6 @@ public class ShopBuySellEvent extends ShopEvent implements Cancellable {
|
||||
return newPrice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
|
@ -8,27 +8,13 @@ import org.bukkit.event.Cancellable;
|
||||
* Called when a player creates a shop (clicks on a chest)
|
||||
*/
|
||||
public class ShopCreateEvent extends ShopEvent implements Cancellable {
|
||||
private Player player;
|
||||
private Shop shop;
|
||||
private double creationPrice;
|
||||
private boolean cancelled;
|
||||
|
||||
public ShopCreateEvent(Player player, Shop shop, double creationPrice) {
|
||||
this.player = player;
|
||||
this.shop = shop;
|
||||
super(player, shop);
|
||||
this.creationPrice = creationPrice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shop getShop() {
|
||||
return shop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The price the player has to pay in order to create the shop (only if the event is not cancelled)
|
||||
*/
|
||||
|
@ -8,16 +8,27 @@ import org.bukkit.event.HandlerList;
|
||||
public abstract class ShopEvent extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Shop shop;
|
||||
private Player player;
|
||||
|
||||
public ShopEvent(Player player, Shop shop) {
|
||||
this.player = player;
|
||||
this.shop = shop;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Shop which is involved in this event
|
||||
*/
|
||||
public abstract Shop getShop();
|
||||
public Shop getShop() {
|
||||
return shop;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Player who is involved in this event
|
||||
*/
|
||||
public abstract Player getPlayer();
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
|
@ -8,23 +8,10 @@ import org.bukkit.event.Cancellable;
|
||||
* Called when a player retrieves information about a shop (clicks on a chest)
|
||||
*/
|
||||
public class ShopInfoEvent extends ShopEvent implements Cancellable {
|
||||
private Player player;
|
||||
private Shop shop;
|
||||
private boolean cancelled;
|
||||
|
||||
public ShopInfoEvent(Player player, Shop shop) {
|
||||
this.player = player;
|
||||
this.shop = shop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shop getShop() {
|
||||
return shop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
super(player, shop);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,23 +8,10 @@ import org.bukkit.event.Cancellable;
|
||||
* Called when a player wants to create a shop (enters the command)
|
||||
*/
|
||||
public class ShopPreCreateEvent extends ShopEvent implements Cancellable {
|
||||
private Player player;
|
||||
private Shop shop;
|
||||
private boolean cancelled;
|
||||
|
||||
public ShopPreCreateEvent(Player player, Shop shop) {
|
||||
this.player = player;
|
||||
this.shop = shop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shop getShop() {
|
||||
return shop;
|
||||
super(player, shop);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,23 +8,10 @@ import org.bukkit.event.Cancellable;
|
||||
* Called when a player removes a shop (clicks on a chest)
|
||||
*/
|
||||
public class ShopRemoveEvent extends ShopEvent implements Cancellable {
|
||||
private Player player;
|
||||
private Shop shop;
|
||||
private boolean cancelled;
|
||||
|
||||
public ShopRemoveEvent(Player player, Shop shop) {
|
||||
this.player = player;
|
||||
this.shop = shop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shop getShop() {
|
||||
return shop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
super(player, shop);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,6 +3,10 @@ package de.epiceric.shopchest.event;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Called when the shop updater runs <br/>
|
||||
* It's not recommended to listen to this event!
|
||||
*/
|
||||
public class ShopUpdateEvent extends Event {
|
||||
|
||||
public enum UpdateQuality {
|
||||
|
@ -218,27 +218,12 @@ public class ShopInteractListener implements Listener {
|
||||
ClickType.removePlayerClickType(p);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
case OPEN:
|
||||
e.setCancelled(true);
|
||||
|
||||
if (shopUtils.isShop(b.getLocation())) {
|
||||
Shop shop = shopUtils.getShop(b.getLocation());
|
||||
|
||||
if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
if (p.isSneaking()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (p.isSneaking() || (shop.getShopType() != ShopType.ADMIN && shop.getVendor().getUniqueId().equals(p.getUniqueId()))) {
|
||||
if (Utils.getPreferredItemInHand(p) == null) {
|
||||
e.setCancelled(true);
|
||||
if (!shop.getVendor().getUniqueId().equals(p.getUniqueId())) {
|
||||
if (p.hasPermission(Permissions.OPEN_OTHER)) {
|
||||
String vendorName = (shop.getVendor().getName() == null ? shop.getVendor().getUniqueId().toString() : shop.getVendor().getName());
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.OPENED_SHOP, new LocalizedMessage.ReplacedRegex(Regex.VENDOR, vendorName)));
|
||||
plugin.debug(p.getName() + " is opening " + vendorName + "'s shop (#" + shop.getID() + ")");
|
||||
if (p.getUniqueId().equals(shop.getVendor().getUniqueId()) || p.hasPermission(Permissions.OPEN_OTHER)) {
|
||||
e.setCancelled(false);
|
||||
if (!calledFromInteractEvent) {
|
||||
p.openInventory(shop.getInventoryHolder().getInventory());
|
||||
@ -248,13 +233,20 @@ public class ShopInteractListener implements Listener {
|
||||
plugin.debug(p.getName() + " is not permitted to open another player's shop");
|
||||
}
|
||||
} else {
|
||||
e.setCancelled(false);
|
||||
if (!calledFromInteractEvent) {
|
||||
p.openInventory(shop.getInventoryHolder().getInventory());
|
||||
}
|
||||
}
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_NO_SHOP));
|
||||
plugin.debug("Chest is not a shop");
|
||||
}
|
||||
|
||||
ClickType.removePlayerClickType(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (shopUtils.isShop(b.getLocation())) {
|
||||
Shop shop = shopUtils.getShop(b.getLocation());
|
||||
|
||||
if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
if (p.isSneaking()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user