mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-13 22:21:06 +00:00
parent
f54c2ff7ff
commit
f233c626e1
@ -117,6 +117,15 @@ public class Config {
|
|||||||
/** Whether the item amount should be calculated to fit the available money or inventory space **/
|
/** Whether the item amount should be calculated to fit the available money or inventory space **/
|
||||||
public boolean auto_calculate_item_amount;
|
public boolean auto_calculate_item_amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Whether the mouse buttons are inverted</p>
|
||||||
|
*
|
||||||
|
* <b>Default:</b><br>
|
||||||
|
* Right-Click: Buy<br>
|
||||||
|
* Left-Click: Sell
|
||||||
|
**/
|
||||||
|
public boolean invert_mouse_buttons;
|
||||||
|
|
||||||
/** Amount the hologram should be lifted **/
|
/** Amount the hologram should be lifted **/
|
||||||
public double two_line_hologram_lift;
|
public double two_line_hologram_lift;
|
||||||
|
|
||||||
@ -313,6 +322,7 @@ public class Config {
|
|||||||
append_potion_level_to_item_name = plugin.getConfig().getBoolean("append-potion-level-to-item-name");
|
append_potion_level_to_item_name = plugin.getConfig().getBoolean("append-potion-level-to-item-name");
|
||||||
show_shop_items = plugin.getConfig().getBoolean("show-shop-items");
|
show_shop_items = plugin.getConfig().getBoolean("show-shop-items");
|
||||||
remove_shop_on_error = plugin.getConfig().getBoolean("remove-shop-on-error");
|
remove_shop_on_error = plugin.getConfig().getBoolean("remove-shop-on-error");
|
||||||
|
invert_mouse_buttons = plugin.getConfig().getBoolean("invert-mouse-buttons");
|
||||||
two_line_hologram_lift = plugin.getConfig().getDouble("two-line-hologram-lift");
|
two_line_hologram_lift = plugin.getConfig().getDouble("two-line-hologram-lift");
|
||||||
maximal_distance = plugin.getConfig().getDouble("maximal-distance");
|
maximal_distance = plugin.getConfig().getDouble("maximal-distance");
|
||||||
maximal_item_distance = plugin.getConfig().getDouble("maximal-item-distance");
|
maximal_item_distance = plugin.getConfig().getDouble("maximal-item-distance");
|
||||||
|
@ -153,14 +153,12 @@ public class ShopInteractListener implements Listener {
|
|||||||
private void handleInteractEvent(PlayerInteractEvent e, boolean calledFromInteractEvent) {
|
private void handleInteractEvent(PlayerInteractEvent e, boolean calledFromInteractEvent) {
|
||||||
Block b = e.getClickedBlock();
|
Block b = e.getClickedBlock();
|
||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
|
boolean inverted = config.invert_mouse_buttons;
|
||||||
|
|
||||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) {
|
if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||||
|
|
||||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
||||||
|
if (ClickType.getPlayerClickType(p) != null) {
|
||||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
|
|
||||||
if (ClickType.getPlayerClickType(p) != null) {
|
|
||||||
|
|
||||||
switch (ClickType.getPlayerClickType(p).getClickType()) {
|
switch (ClickType.getPlayerClickType(p).getClickType()) {
|
||||||
case INFO:
|
case INFO:
|
||||||
@ -199,13 +197,19 @@ public class ShopInteractListener implements Listener {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (shopUtils.isShop(b.getLocation())) {
|
||||||
|
Shop shop = shopUtils.getShop(b.getLocation());
|
||||||
|
|
||||||
} else {
|
if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||||
|
|
||||||
if (shopUtils.isShop(b.getLocation())) {
|
|
||||||
Shop shop = shopUtils.getShop(b.getLocation());
|
|
||||||
|
|
||||||
if (p.isSneaking()) {
|
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) {
|
if (Utils.getPreferredItemInHand(p) == null) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
if (!shop.getVendor().getUniqueId().equals(p.getUniqueId())) {
|
if (!shop.getVendor().getUniqueId().equals(p.getUniqueId())) {
|
||||||
@ -228,127 +232,116 @@ public class ShopInteractListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
e.setCancelled(true);
|
|
||||||
if (shop.getShopType() == ShopType.ADMIN || !shop.getVendor().getUniqueId().equals(p.getUniqueId())) {
|
|
||||||
plugin.debug(p.getName() + " wants to buy");
|
|
||||||
if (shop.getBuyPrice() > 0) {
|
|
||||||
if (p.hasPermission(Permissions.BUY)) {
|
|
||||||
boolean worldGuardAllowed = true;
|
|
||||||
|
|
||||||
if (shop.getShopType() == ShopType.ADMIN) {
|
return;
|
||||||
if (plugin.hasWorldGuard() && config.enable_worldguard_integration) {
|
}
|
||||||
RegionContainer container = worldGuard.getRegionContainer();
|
}
|
||||||
RegionQuery query = container.createQuery();
|
|
||||||
worldGuardAllowed = query.testState(b.getLocation(), p, ShopFlag.USE_ADMIN_SHOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (worldGuardAllowed || p.hasPermission(Permissions.WORLDGUARD_BYPASS)) {
|
if ((e.getAction() == Action.RIGHT_CLICK_BLOCK && !inverted) || (e.getAction() == Action.LEFT_CLICK_BLOCK && inverted)) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
|
||||||
|
if (shop.getShopType() == ShopType.ADMIN || !shop.getVendor().getUniqueId().equals(p.getUniqueId())) {
|
||||||
|
plugin.debug(p.getName() + " wants to buy");
|
||||||
|
|
||||||
|
if (shop.getBuyPrice() > 0) {
|
||||||
|
if (p.hasPermission(Permissions.BUY)) {
|
||||||
|
boolean worldGuardAllowed = true;
|
||||||
|
|
||||||
|
if (shop.getShopType() == ShopType.ADMIN) {
|
||||||
|
if (plugin.hasWorldGuard() && config.enable_worldguard_integration) {
|
||||||
|
RegionContainer container = worldGuard.getRegionContainer();
|
||||||
|
RegionQuery query = container.createQuery();
|
||||||
|
worldGuardAllowed = query.testState(b.getLocation(), p, ShopFlag.USE_ADMIN_SHOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (worldGuardAllowed || p.hasPermission(Permissions.WORLDGUARD_BYPASS)) {
|
||||||
|
buy(p, shop);
|
||||||
|
} else {
|
||||||
|
plugin.debug(p.getName() + " doesn't have worldguard permission");
|
||||||
|
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_WG_BUY));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (plugin.hasWorldGuard() && config.enable_worldguard_integration) {
|
||||||
|
RegionContainer container = worldGuard.getRegionContainer();
|
||||||
|
RegionQuery query = container.createQuery();
|
||||||
|
worldGuardAllowed = query.testState(b.getLocation(), p, ShopFlag.USE_SHOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (worldGuardAllowed || p.hasPermission(Permissions.WORLDGUARD_BYPASS)) {
|
||||||
|
Chest c = (Chest) b.getState();
|
||||||
|
if (Utils.getAmount(c.getInventory(), shop.getProduct()) >= shop.getProduct().getAmount()) {
|
||||||
buy(p, shop);
|
buy(p, shop);
|
||||||
} else {
|
} else {
|
||||||
plugin.debug(p.getName() + " doesn't have worldguard permission");
|
if (config.auto_calculate_item_amount && Utils.getAmount(c.getInventory(), shop.getProduct()) > 0) {
|
||||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_WG_BUY));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (plugin.hasWorldGuard() && config.enable_worldguard_integration) {
|
|
||||||
RegionContainer container = worldGuard.getRegionContainer();
|
|
||||||
RegionQuery query = container.createQuery();
|
|
||||||
worldGuardAllowed = query.testState(b.getLocation(), p, ShopFlag.USE_SHOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (worldGuardAllowed || p.hasPermission(Permissions.WORLDGUARD_BYPASS)) {
|
|
||||||
Chest c = (Chest) b.getState();
|
|
||||||
if (Utils.getAmount(c.getInventory(), shop.getProduct()) >= shop.getProduct().getAmount()) {
|
|
||||||
buy(p, shop);
|
buy(p, shop);
|
||||||
} else {
|
} else {
|
||||||
if (config.auto_calculate_item_amount && Utils.getAmount(c.getInventory(), shop.getProduct()) > 0) {
|
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.OUT_OF_STOCK));
|
||||||
buy(p, shop);
|
plugin.debug("Shop is out of stock");
|
||||||
} else {
|
|
||||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.OUT_OF_STOCK));
|
|
||||||
plugin.debug("Shop is out of stock");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
plugin.debug(p.getName() + " doesn't have worldguard permission");
|
||||||
|
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_WG_BUY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_BUY));
|
||||||
|
plugin.debug(p.getName() + " is not permitted to buy");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUYING_DISABLED));
|
||||||
|
plugin.debug("Buying is disabled");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if ((e.getAction() == Action.LEFT_CLICK_BLOCK && !inverted) || (e.getAction() == Action.RIGHT_CLICK_BLOCK && inverted)) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
|
||||||
|
if ((shop.getShopType() == ShopType.ADMIN) || (!shop.getVendor().getUniqueId().equals(p.getUniqueId()))) {
|
||||||
|
plugin.debug(p.getName() + " wants to sell");
|
||||||
|
|
||||||
|
if (shop.getSellPrice() > 0) {
|
||||||
|
if (p.hasPermission(Permissions.SELL)) {
|
||||||
|
boolean worldGuardAllowed = true;
|
||||||
|
|
||||||
|
if (plugin.hasWorldGuard() && config.enable_worldguard_integration) {
|
||||||
|
RegionContainer container = worldGuard.getRegionContainer();
|
||||||
|
RegionQuery query = container.createQuery();
|
||||||
|
|
||||||
|
StateFlag flag = (shop.getShopType() == ShopType.ADMIN ? ShopFlag.USE_ADMIN_SHOP : ShopFlag.USE_SHOP);
|
||||||
|
worldGuardAllowed = query.testState(b.getLocation(), p, flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (worldGuardAllowed || p.hasPermission(Permissions.WORLDGUARD_BYPASS)) {
|
||||||
|
if (Utils.getAmount(p.getInventory(), shop.getProduct()) >= shop.getProduct().getAmount()) {
|
||||||
|
sell(p, shop);
|
||||||
|
} else {
|
||||||
|
if (config.auto_calculate_item_amount && Utils.getAmount(p.getInventory(), shop.getProduct()) > 0) {
|
||||||
|
sell(p, shop);
|
||||||
} else {
|
} else {
|
||||||
plugin.debug(p.getName() + " doesn't have worldguard permission");
|
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NOT_ENOUGH_ITEMS));
|
||||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_WG_BUY));
|
plugin.debug(p.getName() + " doesn't have enough items");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_BUY));
|
plugin.debug(p.getName() + " doesn't have worldguard permission");
|
||||||
plugin.debug(p.getName() + " is not permitted to buy");
|
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_WG_SELL));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUYING_DISABLED));
|
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_SELL));
|
||||||
plugin.debug("Buying is disabled");
|
plugin.debug(p.getName() + " is not permitted to sell");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
e.setCancelled(false);
|
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SELLING_DISABLED));
|
||||||
if (!calledFromInteractEvent) {
|
plugin.debug("Selling is disabled");
|
||||||
p.openInventory(shop.getInventoryHolder().getInventory());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
|
|
||||||
|
|
||||||
if (shopUtils.isShop(b.getLocation())) {
|
|
||||||
if (p.isSneaking())
|
|
||||||
return;
|
|
||||||
|
|
||||||
e.setCancelled(true);
|
|
||||||
Shop shop = shopUtils.getShop(b.getLocation());
|
|
||||||
|
|
||||||
if ((shop.getShopType() == ShopType.ADMIN) || (!shop.getVendor().getUniqueId().equals(p.getUniqueId()))) {
|
|
||||||
plugin.debug(p.getName() + " wants to sell");
|
|
||||||
if (shop.getSellPrice() > 0) {
|
|
||||||
if (p.hasPermission(Permissions.SELL)) {
|
|
||||||
boolean worldGuardAllowed = true;
|
|
||||||
|
|
||||||
if (plugin.hasWorldGuard() && config.enable_worldguard_integration) {
|
|
||||||
RegionContainer container = worldGuard.getRegionContainer();
|
|
||||||
RegionQuery query = container.createQuery();
|
|
||||||
|
|
||||||
StateFlag flag = (shop.getShopType() == ShopType.ADMIN ? ShopFlag.USE_ADMIN_SHOP : ShopFlag.USE_SHOP);
|
|
||||||
worldGuardAllowed = query.testState(b.getLocation(), p, flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (worldGuardAllowed || p.hasPermission(Permissions.WORLDGUARD_BYPASS)) {
|
|
||||||
if (Utils.getAmount(p.getInventory(), shop.getProduct()) >= shop.getProduct().getAmount()) {
|
|
||||||
sell(p, shop);
|
|
||||||
} else {
|
|
||||||
if (config.auto_calculate_item_amount && Utils.getAmount(p.getInventory(), shop.getProduct()) > 0) {
|
|
||||||
sell(p, shop);
|
|
||||||
} else {
|
|
||||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NOT_ENOUGH_ITEMS));
|
|
||||||
plugin.debug(p.getName() + " doesn't have enough items");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plugin.debug(p.getName() + " doesn't have worldguard permission");
|
|
||||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_WG_SELL));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_SELL));
|
|
||||||
plugin.debug(p.getName() + " is not permitted to sell");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SELLING_DISABLED));
|
e.setCancelled(false);
|
||||||
plugin.debug("Selling is disabled");
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
e.setCancelled(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
ClickType.removePlayerClickType(p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,10 +82,16 @@ append-potion-level-to-item-name: false
|
|||||||
# This might be useful if you're removing shop chests with WorldEdit, resetting plots, or similar
|
# This might be useful if you're removing shop chests with WorldEdit, resetting plots, or similar
|
||||||
remove-shop-on-error: false
|
remove-shop-on-error: false
|
||||||
|
|
||||||
|
# Set whether the mouse buttons should be inverted.
|
||||||
|
# Default:
|
||||||
|
# Right-Click -> Buy
|
||||||
|
# Left-Click -> Sell
|
||||||
|
invert-mouse-buttons: false
|
||||||
|
|
||||||
# Set the maximal distance (in blocks) to the shop where the player can see the hologram.
|
# Set the maximal distance (in blocks) to the shop where the player can see the hologram.
|
||||||
maximal-distance: 2
|
maximal-distance: 2
|
||||||
|
|
||||||
# Set the maximal distance (in blocks) to the shop where the player can see the floatig shop item.
|
# Set the maximal distance (in blocks) to the shop where the player can see the floating shop item.
|
||||||
maximal-item-distance: 40
|
maximal-item-distance: 40
|
||||||
|
|
||||||
# Set the time in seconds between automatic shop reloads.
|
# Set the time in seconds between automatic shop reloads.
|
||||||
|
Loading…
Reference in New Issue
Block a user