hasPermissionOrThrow
This commit is contained in:
parent
a5179b514a
commit
cde14c7100
@ -82,4 +82,9 @@ public enum MassiveCorePerm implements Identified
|
||||
return PermissionUtil.hasPermission(permissible, this);
|
||||
}
|
||||
|
||||
public void hasOrThrow(Permissible permissible) throws MassiveException
|
||||
{
|
||||
PermissionUtil.hasPermissionOrThrow(permissible, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.massivecraft.massivecore.util;
|
||||
import com.massivecraft.massivecore.Identified;
|
||||
import com.massivecraft.massivecore.Lang;
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.event.EventMassiveCorePermissionDeniedFormat;
|
||||
import com.massivecraft.massivecore.mixin.MixinMessage;
|
||||
import com.massivecraft.massivecore.nms.NmsPermissions;
|
||||
@ -402,6 +403,21 @@ public class PermissionUtil
|
||||
return hasPermission(permissible, permission, false);
|
||||
}
|
||||
|
||||
public static void hasPermissionOrThrow(Permissible permissible, Object permission) throws MassiveException
|
||||
{
|
||||
// Fail Fast
|
||||
if (permissible == null) throw new NullPointerException("permissible");
|
||||
if (permission == null) throw new NullPointerException("permission");
|
||||
|
||||
String permissionId = asPermissionId(permission);
|
||||
if (permissionId == null) throw new NullPointerException("permissionId");
|
||||
|
||||
if (!permissible.hasPermission(permissionId))
|
||||
{
|
||||
throw new MassiveException().addMessage(getPermissionDeniedMessage(permission));
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PERMISSIBLE > BASE
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user