2018-02-04 15:29:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011-2018 lishid. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-12-01 02:26:56 +00:00
|
|
|
package com.lishid.openinv.util;
|
2016-11-25 13:01:44 +00:00
|
|
|
|
2016-11-25 21:42:06 +00:00
|
|
|
import org.bukkit.permissions.Permissible;
|
2016-11-25 13:01:44 +00:00
|
|
|
|
2016-11-25 21:42:06 +00:00
|
|
|
public enum Permissions {
|
|
|
|
|
2017-11-07 23:16:38 +00:00
|
|
|
OPENINV("openinv"),
|
|
|
|
OVERRIDE("override"),
|
|
|
|
EXEMPT("exempt"),
|
|
|
|
CROSSWORLD("crossworld"),
|
|
|
|
SILENT("silent"),
|
2017-11-08 22:37:22 +00:00
|
|
|
SILENT_DEFAULT("silent", "default"),
|
2017-11-07 23:16:38 +00:00
|
|
|
ANYCHEST("anychest"),
|
2017-11-08 22:37:22 +00:00
|
|
|
ANY_DEFAULT("any", "default"),
|
2017-11-07 23:16:38 +00:00
|
|
|
ENDERCHEST("openender"),
|
|
|
|
ENDERCHEST_ALL("openenderall"),
|
|
|
|
SEARCH("search"),
|
|
|
|
EDITINV("editinv"),
|
|
|
|
EDITENDER("editender"),
|
|
|
|
OPENSELF("openself");
|
|
|
|
|
|
|
|
private final String[] permission;
|
|
|
|
|
2017-11-08 22:37:22 +00:00
|
|
|
Permissions(String... permissions) {
|
|
|
|
this.permission = new String[permissions.length + 1];
|
2017-11-07 23:16:38 +00:00
|
|
|
this.permission[0] = "OpenInv";
|
2017-11-08 22:37:22 +00:00
|
|
|
System.arraycopy(permissions, 0, this.permission, 1, permissions.length);
|
2016-11-25 21:42:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPermission(Permissible permissible) {
|
2017-11-07 23:16:38 +00:00
|
|
|
StringBuilder permissionBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
// Support wildcard nodes.
|
|
|
|
for (int i = 0; i < permission.length; i++) {
|
|
|
|
if (permissible.hasPermission(permissionBuilder.toString() + "*")) {
|
2016-11-25 21:42:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-11-07 23:16:38 +00:00
|
|
|
permissionBuilder.append(permission[i]).append('.');
|
2016-11-25 21:42:06 +00:00
|
|
|
}
|
2017-11-07 23:16:38 +00:00
|
|
|
|
|
|
|
// Delete trailing period.
|
|
|
|
if (permissionBuilder.length() > 0) {
|
|
|
|
permissionBuilder.deleteCharAt(permissionBuilder.length() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return permissible.hasPermission(permissionBuilder.toString());
|
2016-11-25 21:42:06 +00:00
|
|
|
}
|
2016-11-25 13:01:44 +00:00
|
|
|
|
|
|
|
}
|