Add way to invert mouse buttons

Closes #35
This commit is contained in:
Eric 2017-01-03 15:35:35 +01:00
parent f54c2ff7ff
commit f233c626e1
3 changed files with 119 additions and 110 deletions

View File

@ -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");

View File

@ -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 (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (ClickType.getPlayerClickType(p) != null) { if (ClickType.getPlayerClickType(p) != null) {
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
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 { } else {
if (shopUtils.isShop(b.getLocation())) { if (shopUtils.isShop(b.getLocation())) {
Shop shop = shopUtils.getShop(b.getLocation()); Shop shop = shopUtils.getShop(b.getLocation());
if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
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,10 +232,17 @@ public class ShopInteractListener implements Listener {
} }
} }
} }
} else {
return;
}
}
if ((e.getAction() == Action.RIGHT_CLICK_BLOCK && !inverted) || (e.getAction() == Action.LEFT_CLICK_BLOCK && inverted)) {
e.setCancelled(true); e.setCancelled(true);
if (shop.getShopType() == ShopType.ADMIN || !shop.getVendor().getUniqueId().equals(p.getUniqueId())) { if (shop.getShopType() == ShopType.ADMIN || !shop.getVendor().getUniqueId().equals(p.getUniqueId())) {
plugin.debug(p.getName() + " wants to buy"); plugin.debug(p.getName() + " wants to buy");
if (shop.getBuyPrice() > 0) { if (shop.getBuyPrice() > 0) {
if (p.hasPermission(Permissions.BUY)) { if (p.hasPermission(Permissions.BUY)) {
boolean worldGuardAllowed = true; boolean worldGuardAllowed = true;
@ -281,28 +292,14 @@ public class ShopInteractListener implements Listener {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUYING_DISABLED)); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUYING_DISABLED));
plugin.debug("Buying is disabled"); plugin.debug("Buying is disabled");
} }
} else {
e.setCancelled(false);
if (!calledFromInteractEvent) {
p.openInventory(shop.getInventoryHolder().getInventory());
}
}
}
}
} }
} else if ((e.getAction() == Action.LEFT_CLICK_BLOCK && !inverted) || (e.getAction() == Action.RIGHT_CLICK_BLOCK && inverted)) {
} else if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
if (shopUtils.isShop(b.getLocation())) {
if (p.isSneaking())
return;
e.setCancelled(true); e.setCancelled(true);
Shop shop = shopUtils.getShop(b.getLocation());
if ((shop.getShopType() == ShopType.ADMIN) || (!shop.getVendor().getUniqueId().equals(p.getUniqueId()))) { if ((shop.getShopType() == ShopType.ADMIN) || (!shop.getVendor().getUniqueId().equals(p.getUniqueId()))) {
plugin.debug(p.getName() + " wants to sell"); plugin.debug(p.getName() + " wants to sell");
if (shop.getSellPrice() > 0) { if (shop.getSellPrice() > 0) {
if (p.hasPermission(Permissions.SELL)) { if (p.hasPermission(Permissions.SELL)) {
boolean worldGuardAllowed = true; boolean worldGuardAllowed = true;
@ -342,13 +339,9 @@ public class ShopInteractListener implements Listener {
e.setCancelled(false); e.setCancelled(false);
} }
} }
} }
} }
}
} else {
ClickType.removePlayerClickType(p);
} }
} }

View File

@ -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.