Permission check fix

This commit is contained in:
Jesse Boyd 2017-01-13 07:22:28 +11:00
parent 686a6c499f
commit 35ebc8c830
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
6 changed files with 37 additions and 5 deletions

View File

@ -102,6 +102,11 @@ public class BukkitPlayer extends PlotPlayer {
return this.player.hasPermission(permission);
}
@Override
public boolean isPermissionSet(String permission) {
return this.player.isPermissionSet(permission);
}
@Override
public void sendMessage(String message) {
if (!StringMan.isEqual(this.<String>getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {

View File

@ -60,7 +60,12 @@ public class ConsolePlayer extends PlotPlayer {
public boolean hasPermission(String permission) {
return true;
}
@Override
public boolean isPermissionSet(String permission) {
return true;
}
@Override
public void sendMessage(String message) {
PS.log(message);

View File

@ -60,7 +60,12 @@ public class Permissions {
* @return
*/
public static boolean hasPermission(CommandCaller caller, String permission) {
if (caller.hasPermission(permission) || caller.hasPermission(C.PERMISSION_ADMIN.s())) {
if (caller.hasPermission(permission)) {
return true;
} else if (caller.isPermissionSet(permission)) {
return false;
}
if (caller.hasPermission(C.PERMISSION_ADMIN.s())) {
return true;
}
permission = permission.toLowerCase().replaceAll("^[^a-z|0-9|\\.|_|-]", "");
@ -68,9 +73,12 @@ public class Permissions {
StringBuilder n = new StringBuilder();
for (int i = 0; i <= (nodes.length - 1); i++) {
n.append(nodes[i] + ".");
if (!permission.equals(n + C.PERMISSION_STAR.s())) {
if (caller.hasPermission(n + C.PERMISSION_STAR.s())) {
String combined = n + C.PERMISSION_STAR.s();
if (!permission.equals(combined)) {
if (caller.hasPermission(combined)) {
return true;
} else if (caller.isPermissionSet(combined)) {
return false;
}
}
}

View File

@ -15,6 +15,8 @@ public interface CommandCaller {
* @param permission the name of the permission
*/
boolean hasPermission(String permission);
boolean isPermissionSet(String permission);
RequiredType getSuperCaller();
}

View File

@ -97,6 +97,11 @@ public class NukkitPlayer extends PlotPlayer {
return this.player.hasPermission(permission);
}
@Override
public boolean isPermissionSet(String permission) {
return this.player.isPermissionSet(permission);
}
@Override
public void sendMessage(String message) {
if (!StringMan.isEqual(this.<String>getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {

View File

@ -20,6 +20,7 @@ import org.spongepowered.api.entity.living.player.gamemode.GameModes;
import org.spongepowered.api.service.ban.BanService;
import org.spongepowered.api.text.chat.ChatTypes;
import org.spongepowered.api.text.serializer.TextSerializers;
import org.spongepowered.api.util.Tristate;
import org.spongepowered.api.world.World;
import java.util.Optional;
@ -72,7 +73,13 @@ public class SpongePlayer extends PlotPlayer {
public boolean hasPermission(String permission) {
return this.player.hasPermission(permission);
}
@Override
public boolean isPermissionSet(String permission) {
Tristate state = this.player.getPermissionValue(this.player.getActiveContexts(), permission);
return state != Tristate.UNDEFINED;
}
@Override
public void sendMessage(String message) {
if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {