hasPermissionOrThrow

This commit is contained in:
Magnus Ulf 2019-01-04 15:05:31 +01:00
parent a5179b514a
commit cde14c7100
2 changed files with 21 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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
// -------------------------------------------- //