mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-09 20:21:07 +00:00
Added command "/shop open" to open shops
Shift-click no longer works anywhere to open a shop.
This commit is contained in:
parent
79660920d8
commit
474f734456
26
src/main/java/de/epiceric/shopchest/event/ShopOpenEvent.java
Normal file
26
src/main/java/de/epiceric/shopchest/event/ShopOpenEvent.java
Normal file
@ -0,0 +1,26 @@
|
||||
package de.epiceric.shopchest.event;
|
||||
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
/**
|
||||
* Called when a player opens a shop (clicks on a chest)
|
||||
*/
|
||||
public class ShopOpenEvent extends ShopEvent implements Cancellable {
|
||||
private boolean cancelled;
|
||||
|
||||
public ShopOpenEvent(Player player, Shop shop) {
|
||||
super(player, shop);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package de.epiceric.shopchest.event;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Called when a player wants to open a shop (enters the command)
|
||||
*/
|
||||
public class ShopPreOpenEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Player player;
|
||||
private boolean cancelled;
|
||||
|
||||
public ShopPreOpenEvent(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Player who is involved in this event
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -638,7 +638,7 @@ public class LanguageUtils {
|
||||
itemNames.add(new ItemName(Material.DRAGONS_BREATH, langConfig.getString("item.dragon_breath.name", "Dragon's Breath")));
|
||||
itemNames.add(new ItemName(Material.SPECTRAL_ARROW, langConfig.getString("item.spectral_arrow.name", "Spectral Arrow")));
|
||||
itemNames.add(new ItemName(Material.TIPPED_ARROW, langConfig.getString("item.tipped_arrow.name", "Tipped Arrow")));
|
||||
itemNames.add(new ItemName(Material.SHIELD, langConfig.getString("item.shield.name", "Shield"))); //TODO ADD SHIELD DESCRIPTIONS
|
||||
itemNames.add(new ItemName(Material.SHIELD, langConfig.getString("item.shield.name", "Shield")));
|
||||
itemNames.add(new ItemName(Material.ELYTRA, langConfig.getString("item.elytra.name", "Elytra")));
|
||||
itemNames.add(new ItemName(Material.BOAT_SPRUCE, langConfig.getString("item.boat.spruce.name", "Spruce Boat")));
|
||||
itemNames.add(new ItemName(Material.BOAT_BIRCH, langConfig.getString("item.boat.birch.name", "Birch Boat")));
|
||||
@ -946,8 +946,9 @@ public class LanguageUtils {
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.PRICES_CONTAIN_DECIMALS, langConfig.getString("message.prices-contain-decimals", "&cPrices must not contain decimals.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_ITEM_IN_HAND, langConfig.getString("message.no-item-in-hand", "&cNo item in hand")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_CREATE, langConfig.getString("message.click-chest-to-create-shop", "&aClick a chest to create a shop.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_REMOVE, langConfig.getString("message.click-chest-to-remove-shop", "&aClick a shop-chest to remove the shop.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_REMOVE, langConfig.getString("message.click-chest-to-remove-shop", "&aClick a shop to remove it.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_INFO, langConfig.getString("message.click-chest-for-info", "&aClick a shop to retrieve information.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_OPEN, langConfig.getString("message.click-chest-to-open-shop", "&aClick a shop to open it.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.OPENED_SHOP, langConfig.getString("message.opened-shop", "&aYou opened %VENDOR%'s shop."), Regex.VENDOR));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.CANNOT_BREAK_SHOP, langConfig.getString("message.cannot-break-shop", "&cYou can't break a shop.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.CANNOT_SELL_BROKEN_ITEM, langConfig.getString("message.cannot-sell-broken-item", "&cYou can't sell a broken item.")));
|
||||
@ -991,6 +992,7 @@ public class LanguageUtils {
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_RELOAD, langConfig.getString("message.commandDescription.reload", "Reload shops.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_UPDATE, langConfig.getString("message.commandDescription.update", "Check for Updates.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_LIMITS, langConfig.getString("message.commandDescription.limits", "View shop limits.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_OPEN, langConfig.getString("message.commandDescription.open", "Open a shop.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_CONFIG, langConfig.getString("message.commandDescription.config", "Change configuration values.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHANGED_CONFIG_SET, langConfig.getString("message.config.set", "&6Changed &a%PROPERTY% &6to &a%VALUE%&6."), Regex.PROPERTY, Regex.VALUE));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHANGED_CONFIG_REMOVED, langConfig.getString("message.config.removed", "&6Removed &a%VALUE% &6from &a%PROPERTY%&6."), Regex.PROPERTY, Regex.VALUE));
|
||||
|
@ -83,6 +83,7 @@ public class LocalizedMessage {
|
||||
CLICK_CHEST_CREATE,
|
||||
CLICK_CHEST_REMOVE,
|
||||
CLICK_CHEST_INFO,
|
||||
CLICK_CHEST_OPEN,
|
||||
OPENED_SHOP,
|
||||
CANNOT_BREAK_SHOP,
|
||||
CANNOT_SELL_BROKEN_ITEM,
|
||||
@ -126,6 +127,7 @@ public class LocalizedMessage {
|
||||
COMMAND_DESC_RELOAD,
|
||||
COMMAND_DESC_UPDATE,
|
||||
COMMAND_DESC_LIMITS,
|
||||
COMMAND_DESC_OPEN,
|
||||
COMMAND_DESC_CONFIG,
|
||||
CHANGED_CONFIG_SET,
|
||||
CHANGED_CONFIG_REMOVED,
|
||||
|
@ -10,10 +10,7 @@ import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.config.Config;
|
||||
import de.epiceric.shopchest.config.Regex;
|
||||
import de.epiceric.shopchest.event.ShopBuySellEvent;
|
||||
import de.epiceric.shopchest.event.ShopCreateEvent;
|
||||
import de.epiceric.shopchest.event.ShopInfoEvent;
|
||||
import de.epiceric.shopchest.event.ShopRemoveEvent;
|
||||
import de.epiceric.shopchest.event.*;
|
||||
import de.epiceric.shopchest.language.LanguageUtils;
|
||||
import de.epiceric.shopchest.language.LocalizedMessage;
|
||||
import de.epiceric.shopchest.nms.Hologram;
|
||||
@ -164,7 +161,7 @@ public class ShopInteractListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleInteractEvent(PlayerInteractEvent e, boolean calledFromInteractEvent) {
|
||||
private void handleInteractEvent(PlayerInteractEvent e) {
|
||||
Block b = e.getClickedBlock();
|
||||
Player p = e.getPlayer();
|
||||
boolean inverted = config.invert_mouse_buttons;
|
||||
@ -224,10 +221,7 @@ public class ShopInteractListener implements Listener {
|
||||
if (shopUtils.isShop(b.getLocation())) {
|
||||
Shop shop = shopUtils.getShop(b.getLocation());
|
||||
if (p.getUniqueId().equals(shop.getVendor().getUniqueId()) || p.hasPermission(Permissions.OPEN_OTHER)) {
|
||||
e.setCancelled(false);
|
||||
if (!calledFromInteractEvent) {
|
||||
p.openInventory(shop.getInventoryHolder().getInventory());
|
||||
}
|
||||
open(p, shop, true);
|
||||
} else {
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_OPEN_OTHERS));
|
||||
plugin.debug(p.getName() + " is not permitted to open another player's shop");
|
||||
@ -251,6 +245,10 @@ public class ShopInteractListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && p.getUniqueId().equals(shop.getVendor().getUniqueId()) && shop.getShopType() != ShopType.ADMIN) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((e.getAction() == Action.RIGHT_CLICK_BLOCK && !inverted) || (e.getAction() == Action.LEFT_CLICK_BLOCK && inverted)) {
|
||||
e.setCancelled(true);
|
||||
|
||||
@ -368,7 +366,7 @@ public class ShopInteractListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent e) {
|
||||
if (config.enable_authme_integration && plugin.hasAuthMe() && !AuthMe.getApi().isAuthenticated(e.getPlayer())) return;
|
||||
handleInteractEvent(e, true);
|
||||
handleInteractEvent(e);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -394,7 +392,7 @@ public class ShopInteractListener implements Listener {
|
||||
|
||||
if (b != null) {
|
||||
PlayerInteractEvent interactEvent = new PlayerInteractEvent(p, Action.RIGHT_CLICK_BLOCK, Utils.getPreferredItemInHand(p), b, null);
|
||||
handleInteractEvent(interactEvent, false);
|
||||
handleInteractEvent(interactEvent);
|
||||
}
|
||||
|
||||
}
|
||||
@ -428,7 +426,7 @@ public class ShopInteractListener implements Listener {
|
||||
|
||||
if (b != null) {
|
||||
PlayerInteractEvent interactEvent = new PlayerInteractEvent(p, Action.LEFT_CLICK_BLOCK, Utils.getPreferredItemInHand(p), b, null);
|
||||
handleInteractEvent(interactEvent, false);
|
||||
handleInteractEvent(interactEvent);
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -494,7 +492,7 @@ public class ShopInteractListener implements Listener {
|
||||
* @param shop Shop to be removed
|
||||
*/
|
||||
private void remove(Player executor, Shop shop) {
|
||||
plugin.debug(executor.getName() + " is removing shop (#" + shop.getID() + ")");
|
||||
plugin.debug(executor.getName() + " is removing " + shop.getVendor().getPlayer().getName() + "'s shop (#" + shop.getID() + ")");
|
||||
ShopRemoveEvent event = new ShopRemoveEvent(executor, shop);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
@ -507,6 +505,25 @@ public class ShopInteractListener implements Listener {
|
||||
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_REMOVED));
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a shop
|
||||
* @param executor Player, who executed the command and will receive the message
|
||||
* @param shop Shop to be opened
|
||||
*/
|
||||
private void open(Player executor, Shop shop, boolean message) {
|
||||
plugin.debug(executor.getName() + " is opening " + shop.getVendor().getName() + "'s shop (#" + shop.getID() + ")");
|
||||
ShopOpenEvent event = new ShopOpenEvent(executor, shop);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
plugin.debug("Open event cancelled (#" + shop.getID() + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
executor.openInventory(shop.getInventoryHolder().getInventory());
|
||||
plugin.debug("Opened shop (#" + shop.getID() + ")");
|
||||
if (message) executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.OPENED_SHOP, new LocalizedMessage.ReplacedRegex(Regex.VENDOR, shop.getVendor().getName())));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param executor Player, who executed the command and will retrieve the information
|
||||
|
@ -94,7 +94,7 @@ public class ClickType {
|
||||
}
|
||||
|
||||
public enum EnumClickType {
|
||||
CREATE, REMOVE, INFO
|
||||
CREATE, REMOVE, INFO, OPEN
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ message.no-item-in-hand=&cKein Item in der Hand.
|
||||
message.click-chest-to-create-shop=&aKlicke auf eine Truhe, um einen Shop zu erstellen.
|
||||
message.click-chest-to-remove-shop=&aKlicke auf einen Shop, um ihn zu entfernen.
|
||||
message.click-chest-for-info=&aKlicke auf einen Shop, um Informationen über ihn zu bekommen.
|
||||
message.click-chest-to-open-shop=&Klicke auf einen Shop, um ihn zu öffnen.
|
||||
message.opened-shop=&aDu hast &6%VENDOR%&as Shop geöffnet.
|
||||
message.cannot-break-shop=&cDu kannst einen Shop nicht zerstören.
|
||||
message.cannot-sell-broken-item=&cDu kannst kein kaputtes Artikel verkaufen.
|
||||
@ -82,6 +83,7 @@ message.commandDescription.info=Rufe Informationen über den Shop ab.
|
||||
message.commandDescription.reload=Lade die Shops neu.
|
||||
message.commandDescription.update=Suche nach Aktualisierungen.
|
||||
message.commandDescription.limits=Betrachte die Shop Limits.
|
||||
message.commandDescription.open=Öffne einen Shop.
|
||||
message.commandDescription.config=Verändere Konfigurationswerte.
|
||||
message.config.set=&6Eigenschaft &a%PROPERTY% &6wurde auf &a%VALUE% &6gesetzt.
|
||||
message.config.added=&6Wert &a%VALUE% &6wurde zu &a%PROPERTY% &6hinzugefügt.
|
||||
|
@ -136,11 +136,14 @@ message.no-item-in-hand=&cNo item in hand
|
||||
message.click-chest-to-create-shop=&aClick a chest to create a shop.
|
||||
|
||||
# Set the message when the player must click a shop to remove it.
|
||||
message.click-chest-to-remove-shop=&aClick a shop-chest to remove the shop.
|
||||
message.click-chest-to-remove-shop=&aClick a shop to remove it.
|
||||
|
||||
# Set the message when the player must click a shop to retrieve information.
|
||||
message.click-chest-for-info=&aClick a shop to retrieve information.
|
||||
|
||||
# Set the message when the player must click a shop to open it.
|
||||
message.click-chest-to-open-shop=&aClick a shop to open it.
|
||||
|
||||
# Set the message when the player opened a shop.
|
||||
# Usable regex: %VENDOR%
|
||||
message.opened-shop=&aYou opened %VENDOR%'s shop.
|
||||
@ -283,6 +286,9 @@ message.commandDescription.update=Check for Updates.
|
||||
# Set the command description message for '/shop limits' when you type '/shop'.
|
||||
message.commandDescription.limits=View shop limits.
|
||||
|
||||
# Set the command description message for '/shop open' when you type '/shop'.
|
||||
message.commandDescription.open=Open a shop.
|
||||
|
||||
# Set the command description message for '/shop config' when you type '/shop'.
|
||||
message.commandDescription.config=Change configuration values.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user