Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions src/main/java/studio/magemonkey/divinity/Perms.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package studio.magemonkey.divinity;

import org.bukkit.permissions.Permissible;
import org.jetbrains.annotations.NotNull;
import studio.magemonkey.divinity.modules.api.socketing.ModuleSocket;

public class Perms {

private static final String PREFIX = "quantumrpg.";
private static final String DIVINITY = "divinity.";
private static final String PREFIX = "quantumrpg.";

public static final String USER = PREFIX + "user";
public static final String ADMIN = PREFIX + "admin";
Expand Down Expand Up @@ -100,20 +98,4 @@ public static String getSocketGuiUser(@NotNull ModuleSocket<?> module) {
public static String getSocketGuiMerchant(@NotNull ModuleSocket<?> module) {
return SOCKET_GUI_MERCHANT.replace("%module%", module.getId());
}

/**
* Checks whether the permissible has the given permission, accepting both
* the legacy {@code quantumrpg.*} namespace and the current {@code divinity.*}
* namespace as equivalent.
*/
public static boolean has(@NotNull Permissible permissible, @NotNull String permission) {
if (permissible.hasPermission(permission)) return true;
if (permission.startsWith(PREFIX)) {
return permissible.hasPermission(DIVINITY + permission.substring(PREFIX.length()));
}
if (permission.startsWith(DIVINITY)) {
return permissible.hasPermission(PREFIX + permission.substring(DIVINITY.length()));
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected boolean onDragDrop(
@NotNull I mItem,
@NotNull InventoryClickEvent e) {

if (!Perms.has(player, Perms.getSocketGuiUser(this))) {
if (!player.hasPermission(Perms.getSocketGuiUser(this))) {
plugin.lang().Error_NoPerm.send(player);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String description() {
@Override
@NotNull
public List<String> getTab(@NotNull Player player, int i, @NotNull String[] args) {
if (Perms.has(player, Perms.getSocketCmdMerchantOthers(this.module))) {
if (player.hasPermission(Perms.getSocketCmdMerchantOthers(this.module))) {
if (i == 1) {
return PlayerUT.getPlayerNames();
}
Expand All @@ -57,7 +57,7 @@ protected void perform(@NotNull CommandSender sender, @NotNull String label, @No
this.printUsage(sender);
return;
}
if (args.length > 1 && !Perms.has(sender, Perms.getSocketCmdMerchantOthers(this.module))) {
if (args.length > 1 && !sender.hasPermission(Perms.getSocketCmdMerchantOthers(this.module))) {
this.errPerm(sender);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void shutdown() {
}

public void openMerchantGUI(@NotNull Player player, boolean force) {
if (!force && !Perms.has(player, Perms.getSocketGuiMerchant(this.moduleSocket))) {
if (!force && !player.hasPermission(Perms.getSocketGuiMerchant(this.moduleSocket))) {
plugin.lang().Error_NoPerm.send(player);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public boolean hasPermission(@NotNull Player player) {
if (!this.isPermissionRequired()) return true;

String node = Perms.CLASS_CLASS + "." + this.getId();
return Perms.has(player, node);
return player.hasPermission(node);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void shutdown() {
// METHODS

public void openDismantleGUI(@NotNull Player player, boolean isForce) {
if (!isForce && !Perms.has(player, Perms.DISMANTLE_GUI)) {
if (!isForce && !player.hasPermission(Perms.DISMANTLE_GUI)) {
plugin.lang().Error_NoPerm.send(player);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public final boolean openExtraction(
boolean force
) {

if (!force && !Perms.has(player, Perms.EXTRACTOR_GUI)) {
if (!force && !player.hasPermission(Perms.EXTRACTOR_GUI)) {
plugin.lang().Error_NoPerm.send(player);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public boolean isRateableItem(@NotNull ItemStack target) {
}

public void openGUIPaid(@NotNull Player player, @Nullable ItemStack target, boolean force) {
if (!force && !Perms.has(player, Perms.MAGIC_DUST_GUI)) {
if (!force && !player.hasPermission(Perms.MAGIC_DUST_GUI)) {
plugin.lang().Error_NoPerm.send(player);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public boolean openAnvilGUI(
@Nullable RepairType type,
boolean isForce) {

if (!isForce && !Perms.has(player, Perms.REPAIR_GUI)) {
if (!isForce && !player.hasPermission(Perms.REPAIR_GUI)) {
plugin.lang().Error_NoPerm.send(player);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void shutdown() {
}

public void openSellGUI(@NotNull Player player, boolean isForce) {
if (!isForce && !Perms.has(player, Perms.SELL_GUI)) {
if (!isForce && !player.hasPermission(Perms.SELL_GUI)) {
plugin.lang().Error_NoPerm.send(player);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void onSoulStart(InventoryClickEvent e) {
}
} else {
if (this.hasOwner(item)) {
if (!this.isOwner(item, p) && !Perms.has(p, Perms.BYPASS_REQ_USER_UNTRADEABLE)) {
if (!this.isOwner(item, p) && !p.hasPermission(Perms.BYPASS_REQ_USER_UNTRADEABLE)) {
e.setCancelled(true);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import studio.magemonkey.divinity.stats.items.ItemStats;
import studio.magemonkey.divinity.stats.items.attributes.stats.DurabilityStat;
import studio.magemonkey.divinity.stats.items.requirements.ItemRequirements;
import studio.magemonkey.divinity.Perms;
import studio.magemonkey.divinity.stats.items.requirements.api.UserRequirement;
import studio.magemonkey.divinity.types.ItemGroup;
import studio.magemonkey.divinity.types.ItemSubType;
Expand Down Expand Up @@ -63,7 +62,7 @@ public static boolean canUse(@NotNull ItemStack item, @NotNull Player player, bo

if (!Hooks.isNPC(player)) {
for (UserRequirement<?> req : ItemRequirements.getUserRequirements()) {
if (!Perms.has(player, req.getBypassPermission()) && !req.canUse(player, item)) {
if (!player.hasPermission(req.getBypassPermission()) && !req.canUse(player, item)) {
if (msg) req.getDenyMessage(player, item)
.replace("%item%", ItemUT.getItemName(item))
.replace("%player%", player.getName())
Expand Down
Loading