Only permitted players can remove admin shops

+ Changed permission "shopchest.removeOther" to "shopchest.remove.other"
Closes #36
This commit is contained in:
Eric 2017-01-04 14:34:34 +01:00
parent f233c626e1
commit 2951ef8349
8 changed files with 65 additions and 33 deletions

View File

@ -653,6 +653,7 @@ public class LanguageUtils {
itemNames.add(new ItemName(Material.SHULKER_SHELL, langConfig.getString("item.shulkerShell.name", "Shulker Shell"))); itemNames.add(new ItemName(Material.SHULKER_SHELL, langConfig.getString("item.shulkerShell.name", "Shulker Shell")));
if (Utils.getRevision() >= 2 || Utils.getMajorVersion() > 11) { if (Utils.getRevision() >= 2 || Utils.getMajorVersion() > 11) {
// Add Item Name of 1.11.2
itemNames.add(new ItemName(Material.IRON_NUGGET, langConfig.getString("item.ironNugget.name", "Iron Nugget"))); itemNames.add(new ItemName(Material.IRON_NUGGET, langConfig.getString("item.ironNugget.name", "Iron Nugget")));
} }
} }
@ -696,6 +697,7 @@ public class LanguageUtils {
enchantmentNames.add(new EnchantmentName(Enchantment.VANISHING_CURSE, langConfig.getString("enchantment.vanishing_curse", "Curse of Vanishing"))); enchantmentNames.add(new EnchantmentName(Enchantment.VANISHING_CURSE, langConfig.getString("enchantment.vanishing_curse", "Curse of Vanishing")));
if (Utils.getRevision() >= 2 || Utils.getMajorVersion() > 11) { if (Utils.getRevision() >= 2 || Utils.getMajorVersion() > 11) {
// Add Enchantment Name of 1.11.2
enchantmentNames.add(new EnchantmentName(Enchantment.SWEEPING_EDGE, langConfig.getString("enchantment.sweeping", "Sweeping Edge"))); enchantmentNames.add(new EnchantmentName(Enchantment.SWEEPING_EDGE, langConfig.getString("enchantment.sweeping", "Sweeping Edge")));
} }
} }
@ -974,6 +976,7 @@ public class LanguageUtils {
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_WG_BUY, langConfig.getString("message.noPermission.worldguard-buy", "&cYou don't have permission to buy something here."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_WG_BUY, langConfig.getString("message.noPermission.worldguard-buy", "&cYou don't have permission to buy something here.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_WG_SELL, langConfig.getString("message.noPermission.worldguard-sell", "&cYou don't have permission to sell something here."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_WG_SELL, langConfig.getString("message.noPermission.worldguard-sell", "&cYou don't have permission to sell something here.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_REMOVE_OTHERS, langConfig.getString("message.noPermission.remove-others", "&cYou don't have permission to remove this shop."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_REMOVE_OTHERS, langConfig.getString("message.noPermission.remove-others", "&cYou don't have permission to remove this shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_REMOVE_ADMIN, langConfig.getString("message.noPermission.remove-admin", "&cYou don't have permission to remove an admin shop.")));
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_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_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_CONFIG, langConfig.getString("message.noPermission.config", "&cYou don't have permission to change configuration values.")));

View File

@ -111,6 +111,7 @@ public class LocalizedMessage {
NO_PERMISSION_WG_BUY, NO_PERMISSION_WG_BUY,
NO_PERMISSION_WG_SELL, NO_PERMISSION_WG_SELL,
NO_PERMISSION_REMOVE_OTHERS, NO_PERMISSION_REMOVE_OTHERS,
NO_PERMISSION_REMOVE_ADMIN,
NO_PERMISSION_RELOAD, NO_PERMISSION_RELOAD,
NO_PERMISSION_UPDATE, NO_PERMISSION_UPDATE,
NO_PERMISSION_CONFIG, NO_PERMISSION_CONFIG,

View File

@ -44,6 +44,34 @@ public class ChestProtectListener implements Listener {
this.worldGuard = worldGuard; this.worldGuard = worldGuard;
} }
private void remove(final Shop shop, final Block b, Player p) {
shopUtils.removeShop(shop, true);
if (shop.getInventoryHolder() instanceof DoubleChest) {
DoubleChest dc = (DoubleChest) shop.getInventoryHolder();
final Chest l = (Chest) dc.getLeftSide();
final Chest r = (Chest) dc.getRightSide();
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
Shop newShop = null;
if (b.getLocation().equals(l.getLocation()))
newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), r.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());
else if (b.getLocation().equals(r.getLocation()))
newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), l.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());
shopUtils.addShop(newShop, true);
}
}, 1L);
return;
}
plugin.debug(String.format("%s broke %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_REMOVED));
}
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) { public void onBlockBreak(BlockBreakEvent e) {
final Block b = e.getBlock(); final Block b = e.getBlock();
@ -55,33 +83,16 @@ public class ChestProtectListener implements Listener {
if (p.isSneaking()) { if (p.isSneaking()) {
plugin.debug(String.format("%s tries to break %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); 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(Permissions.REMOVE_OTHER)) { if (shop.getShopType() == Shop.ShopType.ADMIN) {
shopUtils.removeShop(shop, true); if (p.hasPermission(Permissions.REMOVE_ADMIN)) {
remove(shop, b, p);
if (shop.getInventoryHolder() instanceof DoubleChest) { return;
DoubleChest dc = (DoubleChest) shop.getInventoryHolder(); }
final Chest l = (Chest) dc.getLeftSide(); } else {
final Chest r = (Chest) dc.getRightSide(); if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.REMOVE_OTHER)) {
remove(shop, b, p);
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
Shop newShop = null;
if (b.getLocation().equals(l.getLocation()))
newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), r.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());
else if (b.getLocation().equals(r.getLocation()))
newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), l.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());
shopUtils.addShop(newShop, true);
}
}, 1L);
return; return;
} }
plugin.debug(String.format("%s broke %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_REMOVED));
return;
} }
} }

View File

@ -181,13 +181,21 @@ public class ShopInteractListener implements Listener {
if (shopUtils.isShop(b.getLocation())) { if (shopUtils.isShop(b.getLocation())) {
Shop shop = shopUtils.getShop(b.getLocation()); Shop shop = shopUtils.getShop(b.getLocation());
if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.REMOVE_OTHER)) { if (shop.getShopType() == ShopType.ADMIN) {
remove(p, shop); if (p.hasPermission(Permissions.REMOVE_ADMIN)) {
remove(p, shop);
} else {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_REMOVE_ADMIN));
plugin.debug(p.getName() + " is not permitted to remove an admin shop");
}
} else { } else {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_REMOVE_OTHERS)); if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.REMOVE_OTHER)) {
plugin.debug(p.getName() + " is not permitted to remove another player's shop"); remove(p, shop);
} else {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_REMOVE_OTHERS));
plugin.debug(p.getName() + " is not permitted to remove another player's shop");
}
} }
} else { } else {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_NO_SHOP)); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_NO_SHOP));
plugin.debug("Chest is not a shop"); plugin.debug("Chest is not a shop");

View File

@ -5,7 +5,8 @@ public class Permissions {
public static final String CREATE = "shopchest.create"; public static final String CREATE = "shopchest.create";
public static final String CREATE_ADMIN = "shopchest.create.admin"; public static final String CREATE_ADMIN = "shopchest.create.admin";
public static final String CREATE_PROTECTED = "shopchest.create.protected"; public static final String CREATE_PROTECTED = "shopchest.create.protected";
public static final String REMOVE_OTHER = "shopchest.removeOther"; public static final String REMOVE_OTHER = "shopchest.remove.other";
public static final String REMOVE_ADMIN = "shopchest.remove.admin";
public static final String BUY = "shopchest.buy"; public static final String BUY = "shopchest.buy";
public static final String SELL = "shopchest.sell"; public static final String SELL = "shopchest.sell";
public static final String OPEN_OTHER = "shopchest.openOther"; public static final String OPEN_OTHER = "shopchest.openOther";

View File

@ -67,6 +67,7 @@ message.noPermission.sell=&cDu hast keine Berechtigung etwas zu verkaufen.
message.noPermission.worldguard-buy=&cDu hast keine Berechtigung hier etwas zu kaufen. message.noPermission.worldguard-buy=&cDu hast keine Berechtigung hier etwas zu kaufen.
message.noPermission.worldguard-sell=&cDu hast keine Berechtigung hier etwas zu verkaufen. message.noPermission.worldguard-sell=&cDu hast keine Berechtigung hier etwas zu verkaufen.
message.noPermission.remove-others=&cDu hast keine Berechtigung diesen Shop zu entfernen. message.noPermission.remove-others=&cDu hast keine Berechtigung diesen Shop zu entfernen.
message.noPermission.remove-admin=&cDu hast keine Berechtigung einen Admin Shop zu entfernen.
message.noPermission.reload=&cDu hast keine Berechtigung die Shops neu zu laden. 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.update=&cDu hast keine Berechtigung nach Aktualisierungen zu suchen.
message.noPermission.config=&cDu hast keine Berechtigung Konfigurationswerte zu verändern. message.noPermission.config=&cDu hast keine Berechtigung Konfigurationswerte zu verändern.

View File

@ -235,6 +235,9 @@ message.noPermission.worldguard-sell=&cYou don't have permission to sell somethi
# Set the message when a not permitted player tries to remove another player's shop. # Set the message when a not permitted player tries to remove another player's shop.
message.noPermission.remove-others=&cYou don't have permission to remove this shop. message.noPermission.remove-others=&cYou don't have permission to remove this shop.
# Set the message when a not permitted player tries to remove an admin shop.
message.noPermission.remove-others=&cYou don't have permission to remove an admin shop.
# Set the message when a not permitted player tries to reload the shops. # Set the message when a not permitted player tries to reload the shops.
message.noPermission.reload=&cYou don't have permission to reload the shops. message.noPermission.reload=&cYou don't have permission to reload the shops.

View File

@ -15,7 +15,8 @@ permissions:
shopchest.create: true shopchest.create: true
shopchest.create.admin: true shopchest.create.admin: true
shopchest.create.protected: true shopchest.create.protected: true
shopchest.removeOther: true shopchest.remove.other: true
shopchest.remove.admin: true
shopchest.buy: true shopchest.buy: true
shopchest.openOther: true shopchest.openOther: true
shopchest.notification.update: true shopchest.notification.update: true
@ -39,9 +40,12 @@ permissions:
children: children:
shopchest.create: true shopchest.create: true
default: op default: op
shopchest.removeOther: shopchest.remove.other:
description: Allows you to remove other players' shops. description: Allows you to remove other players' shops.
default: op default: op
shopchest.remove.admin:
description: Allows you to remove admin shops.
default: op
shopchest.buy: shopchest.buy:
description: Allows you to buy something. description: Allows you to buy something.
default: true default: true