Skip to content

Commit

Permalink
Permissions and assorted fixes
Browse files Browse the repository at this point in the history
- Removed duplicate message(NO_EDIT > NO_SHOP_PERMISSION)
- `Switch` command now requires `EDIT` permission and the create permission for the shop it is switching to
- `Edit` command now requires `EDIT` permission as well as proper role on shop or `ADMIN` permission
- `What` command now requires `EDIT` permission; Not sure if I want this to be this way, if we remove this the wiki needs to be updated to reflect it.
  • Loading branch information
KillerOfPie committed Nov 4, 2021
1 parent ff582a3 commit 8314a9f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
24 changes: 21 additions & 3 deletions src/main/java/org/shanerx/tradeshop/commands/CommandRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ public void open() {
if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) ||
shop.getManagersUUID().contains(pSender.getUniqueId()) ||
Permissions.hasPermission(pSender, Permissions.ADMIN))) {
sendMessage(Message.NO_EDIT.getPrefixed());
sendMessage(Message.NO_SHOP_PERMISSION.getPrefixed());
return;
}

Expand Down Expand Up @@ -603,7 +603,7 @@ public void close() {
if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) ||
shop.getManagersUUID().contains(pSender.getUniqueId()) ||
Permissions.hasPermission(pSender, Permissions.ADMIN))) {
sendMessage(Message.NO_EDIT.getPrefixed());
sendMessage(Message.NO_SHOP_PERMISSION.getPrefixed());
return;
}

Expand All @@ -626,8 +626,26 @@ public void switchShop() {
if (shop == null)
return;

if (!Permissions.hasPermission(pSender, Permissions.EDIT)) {
sendMessage(Message.NO_COMMAND_PERMISSION.getPrefixed());
return;
}

switch (shop.getShopType()) {
case TRADE:
if (!Permissions.hasPermission(pSender, Permissions.CREATEBI)) {
sendMessage(Message.NO_COMMAND_PERMISSION.getPrefixed());
return;
}
case BITRADE:
if (!Permissions.hasPermission(pSender, Permissions.CREATE)) {
sendMessage(Message.NO_COMMAND_PERMISSION.getPrefixed());
return;
}
}

if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) || shop.getManagersUUID().contains(pSender.getUniqueId()))) {
sendMessage(Message.NO_EDIT.getPrefixed());
sendMessage(Message.NO_SHOP_PERMISSION.getPrefixed());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,15 @@ public void edit() {
if (shop == null)
return;

if (!Permissions.hasPermission(pSender, Permissions.EDIT)) {
sendMessage(Message.NO_COMMAND_PERMISSION.getPrefixed());
return;
}

if (!(shop.getOwner().getUUID().equals(pSender.getUniqueId()) ||
shop.getManagersUUID().contains(pSender.getUniqueId()) ||
Permissions.hasPermission(pSender, Permissions.ADMIN))) {
sendMessage(Message.NO_EDIT.getPrefixed());
sendMessage(Message.NO_SHOP_PERMISSION.getPrefixed());
return;
}

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/shanerx/tradeshop/commands/WhatCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.Damageable;
import org.shanerx.tradeshop.TradeShop;
import org.shanerx.tradeshop.enumys.Setting;
import org.shanerx.tradeshop.enumys.ShopItemStackSettingKeys;
import org.shanerx.tradeshop.enumys.ShopType;
import org.shanerx.tradeshop.enumys.*;
import org.shanerx.tradeshop.objects.Shop;
import org.shanerx.tradeshop.objects.ShopItemStack;

Expand All @@ -55,6 +53,11 @@ public void what() {
if (shop == null)
return;

if (!Permissions.hasPermission(pSender, Permissions.INFO)) {
sendMessage(Message.NO_COMMAND_PERMISSION.getPrefixed());
return;
}

InventoryGui gui = new InventoryGui(plugin, colorize(shop.getShopType() == ShopType.ITRADE ?
Setting.ITRADESHOP_OWNER.getString() :
Bukkit.getOfflinePlayer(shop.getOwner().getUUID()).getName() + "'s Shop"),
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/shanerx/tradeshop/enumys/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public enum Message {
MULTI_UPDATE(MessageSectionKeys.NONE, "&aTrade multiplier has been updated to %amount%."),
NO_CHEST(MessageSectionKeys.NONE, "&cYou need to put a chest under the sign!", "Text to display when a player attempts to place a sign without placing the chest first:"),
NO_COMMAND_PERMISSION(MessageSectionKeys.NONE, "&aYou do not have permission to execute this command", "Text to display when a player attempts to run administrator commands:"),
NO_EDIT(MessageSectionKeys.NONE, "&cYou do not have permission to edit this shop."),
NO_SHOP_PERMISSION(MessageSectionKeys.NONE, "&cYou do not have permission to edit that shop."),
NO_SIGHTED_SHOP(MessageSectionKeys.NONE, "&cNo shop in range!", "Text to display when a player is too far from a shop"),
NO_TS_CREATE_PERMISSION(MessageSectionKeys.NONE, "&cYou don't have permission to create TradeShops!", "Text to display when a player attempts to setup a shoptype they are not allowed to create:"),
Expand Down

0 comments on commit 8314a9f

Please sign in to comment.