mirror of
https://github.com/filoghost/ChestCommands.git
synced 2024-11-26 20:16:16 +01:00
Add possibility to negate permission in PERMISSION and VIEW-PERMISSION
This commit is contained in:
parent
107f641238
commit
9d7be71593
@ -6,7 +6,7 @@ import com.gmail.filoghost.chestcommands.config.yaml.SpecialConfig;
|
||||
public class Lang extends SpecialConfig {
|
||||
|
||||
public String no_open_permission = "&cYou don't have permission &e{permission} &cto use this menu.";
|
||||
public String default_no_icon_permission = "&cYou need {money}$ for this.";
|
||||
public String default_no_icon_permission = "&cYou don't have permission for this icon.";
|
||||
public String no_required_item = "&cYou must have &e{amount}x {material} &c(ID: {id}, data value: {datavalue}) for this.";
|
||||
public String no_money = "&cYou need {money}$ for this.";
|
||||
public String no_points = "&cYou need {points} player points for this.";
|
||||
|
@ -58,7 +58,7 @@ public class ExtendedIconMenu extends IconMenu {
|
||||
if (icons[i] instanceof ExtendedIcon) {
|
||||
ExtendedIcon extIcon = (ExtendedIcon) icons[i];
|
||||
|
||||
if (extIcon.getViewPermission() != null && !player.hasPermission(extIcon.getViewPermission())) {
|
||||
if (!extIcon.canViewIcon(player)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,10 @@ public class ExtendedIcon extends Icon {
|
||||
private String permission;
|
||||
private String permissionMessage;
|
||||
private String viewPermission;
|
||||
|
||||
private boolean permissionNegated;
|
||||
private boolean viewPermissionNegated;
|
||||
|
||||
private double moneyPrice;
|
||||
private int playerPointsPrice;
|
||||
private RequiredItem requiredItem;
|
||||
@ -24,11 +28,29 @@ public class ExtendedIcon extends Icon {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
public boolean canClickIcon(Player player) {
|
||||
if (permission == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (permissionNegated) {
|
||||
return !player.hasPermission(permission);
|
||||
} else {
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPermission(String permission) {
|
||||
if (permission.isEmpty()) {
|
||||
permission = null;
|
||||
}
|
||||
|
||||
if (permission != null) {
|
||||
if (permission.startsWith("!")) {
|
||||
permissionNegated = true;
|
||||
permission = permission.substring(1, viewPermission.length()).trim();
|
||||
}
|
||||
}
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
@ -40,11 +62,29 @@ public class ExtendedIcon extends Icon {
|
||||
this.permissionMessage = permissionMessage;
|
||||
}
|
||||
|
||||
public String getViewPermission() {
|
||||
return viewPermission;
|
||||
public boolean canViewIcon(Player player) {
|
||||
if (viewPermission == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (viewPermissionNegated) {
|
||||
return !player.hasPermission(viewPermission);
|
||||
} else {
|
||||
return player.hasPermission(viewPermission);
|
||||
}
|
||||
}
|
||||
|
||||
public void setViewPermission(String viewPermission) {
|
||||
if (viewPermission.isEmpty()) {
|
||||
viewPermission = null;
|
||||
}
|
||||
|
||||
if (viewPermission != null) {
|
||||
if (viewPermission.startsWith("!")) {
|
||||
viewPermissionNegated = true;
|
||||
viewPermission = viewPermission.substring(1, viewPermission.length()).trim();
|
||||
}
|
||||
}
|
||||
this.viewPermission = viewPermission;
|
||||
}
|
||||
|
||||
@ -78,11 +118,11 @@ public class ExtendedIcon extends Icon {
|
||||
|
||||
// Check all the requirements.
|
||||
|
||||
if (permission != null && !permission.isEmpty() && !player.hasPermission(permission)) {
|
||||
if (!canClickIcon(player)) {
|
||||
if (permissionMessage != null) {
|
||||
player.sendMessage(permissionMessage);
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "You don't have permission.");
|
||||
player.sendMessage(ChestCommands.getLang().default_no_icon_permission);
|
||||
}
|
||||
return closeOnClick;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user