2018-02-04 15:29:07 +00:00
|
|
|
/*
|
2020-02-01 13:03:15 +00:00
|
|
|
* Copyright (C) 2011-2020 lishid. All rights reserved.
|
2018-02-04 15:29:07 +00:00
|
|
|
*
|
|
|
|
* 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"),
|
2018-05-26 10:58:56 +00:00
|
|
|
SILENT_DEFAULT("silent.default"),
|
2017-11-07 23:16:38 +00:00
|
|
|
ANYCHEST("anychest"),
|
2018-05-26 10:58:56 +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"),
|
2020-05-28 23:44:34 +00:00
|
|
|
OPENSELF("openself"),
|
|
|
|
OPENONLINE("openonline"),
|
2020-09-15 17:35:04 +00:00
|
|
|
OPENOFFLINE("openoffline"),
|
|
|
|
SPECTATE("spectate");
|
2017-11-07 23:16:38 +00:00
|
|
|
|
2018-05-26 10:58:56 +00:00
|
|
|
private final String permission;
|
2017-11-07 23:16:38 +00:00
|
|
|
|
2018-05-26 10:58:56 +00:00
|
|
|
Permissions(String permission) {
|
|
|
|
this.permission = "OpenInv." + permission;
|
2016-11-25 21:42:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPermission(Permissible permissible) {
|
2017-11-07 23:16:38 +00:00
|
|
|
|
2018-05-26 10:58:56 +00:00
|
|
|
boolean hasPermission = permissible.hasPermission(permission);
|
|
|
|
if (hasPermission || permissible.isPermissionSet(permission)) {
|
|
|
|
return hasPermission;
|
2016-11-25 21:42:06 +00:00
|
|
|
}
|
2017-11-07 23:16:38 +00:00
|
|
|
|
2018-05-26 10:58:56 +00:00
|
|
|
StringBuilder permissionDestroyer = new StringBuilder(permission);
|
|
|
|
for (int lastPeriod = permissionDestroyer.lastIndexOf("."); lastPeriod > 0;
|
|
|
|
lastPeriod = permissionDestroyer.lastIndexOf(".")) {
|
|
|
|
permissionDestroyer.delete(lastPeriod + 1, permissionDestroyer.length()).append('*');
|
|
|
|
|
|
|
|
hasPermission = permissible.hasPermission(permissionDestroyer.toString());
|
|
|
|
if (hasPermission || permissible.isPermissionSet(permissionDestroyer.toString())) {
|
|
|
|
return hasPermission;
|
|
|
|
}
|
|
|
|
|
|
|
|
permissionDestroyer.delete(lastPeriod, permissionDestroyer.length());
|
|
|
|
|
2017-11-07 23:16:38 +00:00
|
|
|
}
|
|
|
|
|
2018-05-26 10:58:56 +00:00
|
|
|
return permissible.hasPermission("*");
|
|
|
|
|
2016-11-25 21:42:06 +00:00
|
|
|
}
|
2016-11-25 13:01:44 +00:00
|
|
|
|
|
|
|
}
|