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); return this.player.hasPermission(permission);
} }
@Override
public boolean isPermissionSet(String permission) {
return this.player.isPermissionSet(permission);
}
@Override @Override
public void sendMessage(String message) { public void sendMessage(String message) {
if (!StringMan.isEqual(this.<String>getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) { if (!StringMan.isEqual(this.<String>getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {

View File

@ -61,6 +61,11 @@ public class ConsolePlayer extends PlotPlayer {
return true; return true;
} }
@Override
public boolean isPermissionSet(String permission) {
return true;
}
@Override @Override
public void sendMessage(String message) { public void sendMessage(String message) {
PS.log(message); PS.log(message);

View File

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

View File

@ -16,5 +16,7 @@ public interface CommandCaller {
*/ */
boolean hasPermission(String permission); boolean hasPermission(String permission);
boolean isPermissionSet(String permission);
RequiredType getSuperCaller(); RequiredType getSuperCaller();
} }

View File

@ -97,6 +97,11 @@ public class NukkitPlayer extends PlotPlayer {
return this.player.hasPermission(permission); return this.player.hasPermission(permission);
} }
@Override
public boolean isPermissionSet(String permission) {
return this.player.isPermissionSet(permission);
}
@Override @Override
public void sendMessage(String message) { public void sendMessage(String message) {
if (!StringMan.isEqual(this.<String>getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) { 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.service.ban.BanService;
import org.spongepowered.api.text.chat.ChatTypes; import org.spongepowered.api.text.chat.ChatTypes;
import org.spongepowered.api.text.serializer.TextSerializers; import org.spongepowered.api.text.serializer.TextSerializers;
import org.spongepowered.api.util.Tristate;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import java.util.Optional; import java.util.Optional;
@ -73,6 +74,12 @@ public class SpongePlayer extends PlotPlayer {
return this.player.hasPermission(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 @Override
public void sendMessage(String message) { public void sendMessage(String message) {
if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) { if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {