Added permission for extending other players' shop chests

This commit is contained in:
Eric 2016-11-18 20:57:26 +01:00
parent ef3bc57381
commit 1d7a534fe4
6 changed files with 33 additions and 17 deletions

View File

@ -966,6 +966,7 @@ public class LanguageUtils {
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_RELOAD, langConfig.getString("message.noPermission.reload", "&cYou don't have permission to reload the shops.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_UPDATE, langConfig.getString("message.noPermission.update", "&cYou don't have permission to check for updates.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_CONFIG, langConfig.getString("message.noPermission.config", "&cYou don't have permission to change configuration values.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_EXTEND_OTHERS, langConfig.getString("message.noPermission.extend-others", "&cYou don't have permission to extend this chest.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE, langConfig.getString("message.commandDescription.create", "Create a shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVE, langConfig.getString("message.commandDescription.remove", "Remove a shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_INFO, langConfig.getString("message.commandDescription.info", "Retrieve shop information.")));

View File

@ -112,6 +112,7 @@ public class LocalizedMessage {
NO_PERMISSION_RELOAD,
NO_PERMISSION_UPDATE,
NO_PERMISSION_CONFIG,
NO_PERMISSION_EXTEND_OTHERS,
COMMAND_DESC_CREATE,
COMMAND_DESC_REMOVE,
COMMAND_DESC_INFO,

View File

@ -43,6 +43,8 @@ public class ChestProtectListener implements Listener {
Player p = e.getPlayer();
if (p.isSneaking()) {
plugin.debug(String.format("%s tries to break %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission("shopchest.removeOther")) {
shopUtils.removeShop(shop, true);
@ -96,7 +98,7 @@ public class ChestProtectListener implements Listener {
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
Player p = e.getPlayer();
Block b = e.getBlockPlaced();
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
@ -109,26 +111,31 @@ public class ChestProtectListener implements Listener {
Chest l = (Chest) dc.getLeftSide();
if (shopUtils.isShop(r.getLocation()) || shopUtils.isShop(l.getLocation())) {
plugin.debug(e.getPlayer().getName() + " tried to extend a shop to a double chest");
Shop shop;
if (b.getRelative(BlockFace.UP).getType() == Material.AIR) {
Shop shop;
if (b.getLocation().equals(r.getLocation())) {
shop = shopUtils.getShop(l.getLocation());
} else if (b.getLocation().equals(l.getLocation())) {
shop = shopUtils.getShop(r.getLocation());
} else {
return;
}
if (b.getLocation().equals(r.getLocation())) {
shop = shopUtils.getShop(l.getLocation());
} else if (b.getLocation().equals(l.getLocation())) {
shop = shopUtils.getShop(r.getLocation());
plugin.debug(String.format("%s tries to extend %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission("shopchest.extendOther")) {
if (b.getRelative(BlockFace.UP).getType() == Material.AIR) {
shopUtils.removeShop(shop, true);
Shop newShop = new Shop(shop.getID(), ShopChest.getInstance(), shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());
shopUtils.addShop(newShop, true);
plugin.debug(String.format("%s extended %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
} else {
return;
e.setCancelled(true);
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_BLOCKED));
}
shopUtils.removeShop(shop, true);
Shop newShop = new Shop(shop.getID(), ShopChest.getInstance(), shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());
shopUtils.addShop(newShop, true);
} else {
e.setCancelled(true);
e.getPlayer().sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_BLOCKED));
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_EXTEND_OTHERS));
}
}

View File

@ -68,6 +68,7 @@ message.noPermission.remove-others=&cDu hast keine Berechtigung diesen Shop zu e
message.noPermission.reload=&cDu hast keine Berechtigung die Shops neu zu laden.
message.noPermission.update=&cDu hast keine Berechtigung nach Aktualisierungen zu suchen.
message.noPermission.config=&cDu hast keine Berechtigung Konfigurationswerte zu verändern.
message.noPermission.extend-others=&cDu hast keine Berechtigung diesen Shop zu erweitern.
message.commandDescription.create=Erstelle einen Shop.
message.commandDescription.remove=Entferne einen Shop.
message.commandDescription.info=Rufe Informationen über den Shop ab.

View File

@ -238,6 +238,9 @@ message.noPermission.update=&cYou don't have permission to check for updates.
# Set the message when a not permitted player tries to change configuration values.
message.noPermission.config=&cYou don't have permission to change configuration values.
# Set the message when a not permitted player tries to extend another player's shop's chest.
message.noPermission.extend-others=&cYou don't have permission to extend this chest.
# Set the command description message for '/shop create' when you type '/shop'.
message.commandDescription.create=Create a shop.

View File

@ -35,7 +35,7 @@ permissions:
shopchest.create: true
default: op
shopchest.removeOther:
description: Allows you to remove other players' shop.
description: Allows you to remove other players' shops.
default: op
shopchest.buy:
description: Allows you to buy something.
@ -44,7 +44,7 @@ permissions:
description: Allows you to sell something.
default: true
shopchest.openOther:
description: Allows you to open other players' shop.
description: Allows you to open other players' shops.
default: op
shopchest.notification.update:
description: Allows you to get update notification on join.
@ -60,3 +60,6 @@ permissions:
shopchest.config:
description: Allows you to change configuration values per command.
default: op
shopchest.extendOther:
description: Allows you to extend other players' shops.
default: op