Fixed permission check issue.

This commit is contained in:
Brianna 2020-04-14 15:27:56 -04:00
parent 4fcf8577c9
commit d1533cd096
3 changed files with 31 additions and 4 deletions

View File

@ -1,10 +1,12 @@
package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.utils.PlayerUtils;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.Punishment;
import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.VaultPermissions;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@ -48,12 +50,12 @@ public class CommandBan extends AbstractCommand {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
if (player == null) {
if (!player.hasPlayedBefore()) {
instance.getLocale().newMessage("That player does not exist.").sendMessage(sender);
return ReturnType.FAILURE;
}
if (sender instanceof Player && player.getPlayer().hasPermission("um.ban.exempt")) {
if (sender instanceof Player && VaultPermissions.hasPermission(Bukkit.getWorlds().get(0).getName(), player, "um.ban.exempt")) {
instance.getLocale().newMessage("You cannot ban this player.").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}

View File

@ -5,6 +5,7 @@ import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.Punishment;
import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.VaultPermissions;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@ -48,12 +49,12 @@ public class CommandMute extends AbstractCommand {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
if (player == null) {
if (!player.hasPlayedBefore()) {
instance.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
if (sender instanceof Player && player.getPlayer().hasPermission("um.mute.exempt")) {
if (sender instanceof Player && VaultPermissions.hasPermission(Bukkit.getWorlds().get(0).getName(), player, "um.mute.exempt")) {
instance.getLocale().newMessage("You cannot mute that player.").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}

View File

@ -0,0 +1,24 @@
package com.songoda.ultimatemoderation.utils;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.RegisteredServiceProvider;
public class VaultPermissions {
// Vault
private static Permission vaultPermission = null;
static {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") != null) {
RegisteredServiceProvider<Permission> permissionRsp = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
if (permissionRsp != null) vaultPermission = permissionRsp.getProvider();
}
}
public static boolean hasPermission(String world, OfflinePlayer offlinePlayer, String perm) {
if (vaultPermission != null) return vaultPermission.playerHas(world, offlinePlayer, perm);
return false;
}
}