Added command rank settings and extra ranks.
This commit is contained in:
parent
203998d000
commit
d44889e7b0
|
@ -8,3 +8,4 @@
|
||||||
/.idea
|
/.idea
|
||||||
/database/
|
/database/
|
||||||
/.gitignore
|
/.gitignore
|
||||||
|
/dependency-reduced-pom.xml
|
||||||
|
|
|
@ -74,10 +74,6 @@ public class BentoBox extends JavaPlugin {
|
||||||
// get a commodore instance
|
// get a commodore instance
|
||||||
commodore = CommodoreProvider.getCommodore(this);
|
commodore = CommodoreProvider.getCommodore(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Not loaded
|
// Not loaded
|
||||||
isLoaded = false;
|
isLoaded = false;
|
||||||
// Store the current millis time so we can tell how many ms it took for BSB to fully load.
|
// Store the current millis time so we can tell how many ms it took for BSB to fully load.
|
||||||
|
|
|
@ -10,6 +10,7 @@ import world.bentobox.bentobox.api.configuration.ConfigEntry;
|
||||||
import world.bentobox.bentobox.api.configuration.StoreAt;
|
import world.bentobox.bentobox.api.configuration.StoreAt;
|
||||||
import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType;
|
import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType;
|
||||||
import world.bentobox.bentobox.database.objects.DataObject;
|
import world.bentobox.bentobox.database.objects.DataObject;
|
||||||
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All the plugin settings are here
|
* All the plugin settings are here
|
||||||
|
@ -109,6 +110,10 @@ public class Settings implements DataObject {
|
||||||
@ConfigComment("Time in seconds that players have to confirm sensitive commands, e.g. island reset")
|
@ConfigComment("Time in seconds that players have to confirm sensitive commands, e.g. island reset")
|
||||||
@ConfigEntry(path = "general.confirmation-time")
|
@ConfigEntry(path = "general.confirmation-time")
|
||||||
private int confirmationTime = 20;
|
private int confirmationTime = 20;
|
||||||
|
|
||||||
|
@ConfigComment("Rank required to use a command. e.g., use the invite command. Default is owner rank is required.")
|
||||||
|
@ConfigEntry(path = "general.rank-command")
|
||||||
|
private Map<String, Integer> rankCommand = new HashMap<>();
|
||||||
|
|
||||||
@ConfigEntry(path = "panel.close-on-click-outside")
|
@ConfigEntry(path = "panel.close-on-click-outside")
|
||||||
private boolean closePanelOnClickOutside = true;
|
private boolean closePanelOnClickOutside = true;
|
||||||
|
@ -586,4 +591,28 @@ public class Settings implements DataObject {
|
||||||
this.banWait = banWait;
|
this.banWait = banWait;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getRankCommand(String command) {
|
||||||
|
return rankCommand.getOrDefault(command, RanksManager.OWNER_RANK);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRankCommand(String command, int rank) {
|
||||||
|
rankCommand.put(command, rank);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the rankCommand
|
||||||
|
*/
|
||||||
|
public Map<String, Integer> getRankCommand() {
|
||||||
|
return rankCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param rankCommand the rankCommand to set
|
||||||
|
*/
|
||||||
|
public void setRankCommand(Map<String, Integer> rankCommand) {
|
||||||
|
this.rankCommand = rankCommand;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -17,16 +17,10 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.command.PluginIdentifiableCommand;
|
import org.bukkit.command.PluginIdentifiableCommand;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
||||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
|
||||||
|
|
||||||
import me.lucko.commodore.Commodore;
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
|
@ -51,6 +45,17 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||||
* True if the command is for the player only (not for the console)
|
* True if the command is for the player only (not for the console)
|
||||||
*/
|
*/
|
||||||
private boolean onlyPlayer = false;
|
private boolean onlyPlayer = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if the command is only for the console to use
|
||||||
|
*/
|
||||||
|
private boolean onlyConsole = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if command is a configurable rank
|
||||||
|
*/
|
||||||
|
private boolean configurableRankCommand = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The parameters string for this command. It is the commands followed by a locale reference.
|
* The parameters string for this command. It is the commands followed by a locale reference.
|
||||||
*/
|
*/
|
||||||
|
@ -201,8 +206,8 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||||
this.permissionPrefix = parent.getPermissionPrefix();
|
this.permissionPrefix = parent.getPermissionPrefix();
|
||||||
// Inherit world
|
// Inherit world
|
||||||
this.world = parent.getWorld();
|
this.world = parent.getWorld();
|
||||||
|
|
||||||
// Default references to description and parameters
|
// Default references to description and parameters
|
||||||
|
|
||||||
StringBuilder reference = new StringBuilder();
|
StringBuilder reference = new StringBuilder();
|
||||||
reference.append(label);
|
reference.append(label);
|
||||||
CompositeCommand p = this;
|
CompositeCommand p = this;
|
||||||
|
@ -420,6 +425,16 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||||
return "/" + usage;
|
return "/" + usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFullUsage() {
|
||||||
|
String result = usage;
|
||||||
|
CompositeCommand c = this.parent;
|
||||||
|
while (c != null) {
|
||||||
|
result = c.getUsage() + " " + result;
|
||||||
|
c = c.getParent();
|
||||||
|
}
|
||||||
|
return "/" + result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this command has a specific sub command.
|
* Check if this command has a specific sub command.
|
||||||
* @param subCommand - sub command
|
* @param subCommand - sub command
|
||||||
|
@ -822,4 +837,33 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||||
user.sendMessage("general.errors.you-must-wait", TextVariables.NUMBER, String.valueOf(timeToGo));
|
user.sendMessage("general.errors.you-must-wait", TextVariables.NUMBER, String.valueOf(timeToGo));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the onlyConsole
|
||||||
|
*/
|
||||||
|
public boolean isOnlyConsole() {
|
||||||
|
return onlyConsole;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This command is only for console use
|
||||||
|
*/
|
||||||
|
public void setOnlyConsole() {
|
||||||
|
this.onlyConsole = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the configurableRankCommand
|
||||||
|
*/
|
||||||
|
public boolean isConfigurableRankCommand() {
|
||||||
|
return configurableRankCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This command can be configured for use by different ranks
|
||||||
|
*/
|
||||||
|
public void setConfigurableRankCommand() {
|
||||||
|
this.configurableRankCommand = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ public class IslandBanCommand extends CompositeCommand {
|
||||||
setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
setParametersHelp("commands.island.ban.parameters");
|
setParametersHelp("commands.island.ban.parameters");
|
||||||
setDescription("commands.island.ban.description");
|
setDescription("commands.island.ban.description");
|
||||||
|
setConfigurableRankCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,8 +43,9 @@ public class IslandBanCommand extends CompositeCommand {
|
||||||
user.sendMessage("general.errors.no-island");
|
user.sendMessage("general.errors.no-island");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!getIslands().isOwner(getWorld(), playerUUID)) {
|
// Check rank to use command
|
||||||
user.sendMessage("general.errors.not-leader");
|
if (getIslands().getIsland(getWorld(), user).getRank(user) < getPlugin().getSettings().getRankCommand(getUsage())) {
|
||||||
|
user.sendMessage("general.errors.no-permission");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Get target player
|
// Get target player
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class IslandUnbanCommand extends CompositeCommand {
|
||||||
setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
setParametersHelp("commands.island.unban.parameters");
|
setParametersHelp("commands.island.unban.parameters");
|
||||||
setDescription("commands.island.unban.description");
|
setDescription("commands.island.unban.description");
|
||||||
|
setConfigurableRankCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,8 +39,9 @@ public class IslandUnbanCommand extends CompositeCommand {
|
||||||
user.sendMessage("general.errors.no-island");
|
user.sendMessage("general.errors.no-island");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!getIslands().isOwner(getWorld(), playerUUID)) {
|
// Check rank to use command
|
||||||
user.sendMessage("general.errors.not-leader");
|
if (getIslands().getIsland(getWorld(), user).getRank(user) < getPlugin().getSettings().getRankCommand(getUsage())) {
|
||||||
|
user.sendMessage("general.errors.no-permission");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Get target player
|
// Get target player
|
||||||
|
|
|
@ -32,19 +32,20 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||||
setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
setDescription("commands.island.team.invite.description");
|
setDescription("commands.island.team.invite.description");
|
||||||
inviteList = HashBiMap.create();
|
inviteList = HashBiMap.create();
|
||||||
|
setConfigurableRankCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, List<String> args) {
|
public boolean execute(User user, String label, List<String> args) {
|
||||||
UUID playerUUID = user.getUniqueId();
|
UUID playerUUID = user.getUniqueId();
|
||||||
// Player issuing the command must have an island
|
// Player issuing the command must have an island
|
||||||
if (!getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
if (!getIslands().inTeam(getWorld(), user.getUniqueId()) && !getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||||
user.sendMessage("general.errors.no-island");
|
user.sendMessage("general.errors.no-island");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UUID teamLeaderUUID = getTeamLeader(getWorld(), user);
|
// Check rank to use command
|
||||||
if (!(teamLeaderUUID.equals(playerUUID))) {
|
if (getIslands().getIsland(getWorld(), user).getRank(user) < getPlugin().getSettings().getRankCommand(getUsage())) {
|
||||||
user.sendMessage("general.errors.not-leader");
|
user.sendMessage("general.errors.no-permission");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.isEmpty() || args.size() > 1) {
|
if (args.isEmpty() || args.size() > 1) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ public class IslandTeamKickCommand extends CompositeCommand {
|
||||||
setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
setParametersHelp("commands.island.team.kick.parameters");
|
setParametersHelp("commands.island.team.kick.parameters");
|
||||||
setDescription("commands.island.team.kick.description");
|
setDescription("commands.island.team.kick.description");
|
||||||
|
setConfigurableRankCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
|
|
||||||
public class IslandTeamPromoteCommand extends CompositeCommand {
|
public class IslandTeamPromoteCommand extends CompositeCommand {
|
||||||
|
|
||||||
|
@ -31,10 +32,12 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
|
||||||
user.sendMessage("general.errors.no-team");
|
user.sendMessage("general.errors.no-team");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!getTeamLeader(getWorld(), user).equals(user.getUniqueId())) {
|
// Check rank to use command
|
||||||
user.sendMessage("general.errors.not-leader");
|
if (getIslands().getIsland(getWorld(), user).getRank(user) < getPlugin().getSettings().getRankCommand(getUsage())) {
|
||||||
return true;
|
user.sendMessage("general.errors.no-permission");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If args are not right, show help
|
// If args are not right, show help
|
||||||
if (args.size() != 1) {
|
if (args.size() != 1) {
|
||||||
showHelp(this, user);
|
showHelp(this, user);
|
||||||
|
@ -58,7 +61,8 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
|
||||||
int currentRank = getIslands().getIsland(getWorld(), user.getUniqueId()).getRank(target);
|
int currentRank = getIslands().getIsland(getWorld(), user.getUniqueId()).getRank(target);
|
||||||
if (this.getLabel().equals("promote")) {
|
if (this.getLabel().equals("promote")) {
|
||||||
int nextRank = getPlugin().getRanksManager().getRankUpValue(currentRank);
|
int nextRank = getPlugin().getRanksManager().getRankUpValue(currentRank);
|
||||||
if (nextRank > currentRank) {
|
// Stop short of owner
|
||||||
|
if (nextRank != RanksManager.OWNER_RANK && nextRank > currentRank) {
|
||||||
getIslands().getIsland(getWorld(), user.getUniqueId()).setRank(target, nextRank);
|
getIslands().getIsland(getWorld(), user.getUniqueId()).setRank(target, nextRank);
|
||||||
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(nextRank));
|
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(nextRank));
|
||||||
user.sendMessage("commands.island.team.promote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName);
|
user.sendMessage("commands.island.team.promote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName);
|
||||||
|
@ -70,7 +74,8 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
|
||||||
} else {
|
} else {
|
||||||
// Demote
|
// Demote
|
||||||
int prevRank = getPlugin().getRanksManager().getRankDownValue(currentRank);
|
int prevRank = getPlugin().getRanksManager().getRankDownValue(currentRank);
|
||||||
if (prevRank < currentRank) {
|
// Lowest is Member
|
||||||
|
if (prevRank >= RanksManager.MEMBER_RANK && prevRank < currentRank) {
|
||||||
getIslands().getIsland(getWorld(), user.getUniqueId()).setRank(target, prevRank);
|
getIslands().getIsland(getWorld(), user.getUniqueId()).setRank(target, prevRank);
|
||||||
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(prevRank));
|
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(prevRank));
|
||||||
user.sendMessage("commands.island.team.demote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName);
|
user.sendMessage("commands.island.team.demote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName);
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package world.bentobox.bentobox.listeners.flags;
|
||||||
|
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
|
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||||
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tastybento
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class CommandCycleClick implements ClickHandler {
|
||||||
|
|
||||||
|
private BentoBox plugin = BentoBox.getInstance();
|
||||||
|
private String command;
|
||||||
|
private CommandRankClickListener commandRankClickListener;
|
||||||
|
|
||||||
|
public CommandCycleClick(CommandRankClickListener commandRankClickListener, String c) {
|
||||||
|
this.commandRankClickListener = commandRankClickListener;
|
||||||
|
this.command = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see world.bentobox.bentobox.api.panels.PanelItem.ClickHandler#onClick(world.bentobox.bentobox.api.panels.Panel, world.bentobox.bentobox.api.user.User, org.bukkit.event.inventory.ClickType, int)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean onClick(Panel panel, User user, ClickType click, int slot) {
|
||||||
|
// Left clicking increases the rank required
|
||||||
|
// Right clicking decreases the rank required
|
||||||
|
// Get the user's island
|
||||||
|
Island island = plugin.getIslands().getIsland(user.getWorld(), user.getUniqueId());
|
||||||
|
if (island != null && island.getOwner().equals(user.getUniqueId())) {
|
||||||
|
RanksManager rm = plugin.getRanksManager();
|
||||||
|
int currentRank = plugin.getSettings().getRankCommand(command);
|
||||||
|
if (click.equals(ClickType.LEFT)) {
|
||||||
|
if (currentRank == RanksManager.OWNER_RANK) {
|
||||||
|
plugin.getSettings().setRankCommand(command, RanksManager.MEMBER_RANK);
|
||||||
|
} else {
|
||||||
|
plugin.getSettings().setRankCommand(command, rm.getRankUpValue(currentRank));
|
||||||
|
}
|
||||||
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||||
|
} else if (click.equals(ClickType.RIGHT)) {
|
||||||
|
if (currentRank == RanksManager.MEMBER_RANK) {
|
||||||
|
plugin.getSettings().setRankCommand(command, RanksManager.OWNER_RANK);
|
||||||
|
} else {
|
||||||
|
plugin.getSettings().setRankCommand(command, rm.getRankDownValue(currentRank));
|
||||||
|
}
|
||||||
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||||
|
}
|
||||||
|
// Apply change to panel
|
||||||
|
panel.getInventory().setItem(slot, commandRankClickListener.getPanelItem(command, user).getItem());
|
||||||
|
} else {
|
||||||
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,135 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package world.bentobox.bentobox.listeners.flags;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
|
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||||
|
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||||
|
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||||
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tastybento
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class CommandRankClickListener implements ClickHandler {
|
||||||
|
|
||||||
|
private BentoBox plugin = BentoBox.getInstance();
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see world.bentobox.bentobox.api.panels.PanelItem.ClickHandler#onClick(world.bentobox.bentobox.api.panels.Panel, world.bentobox.bentobox.api.user.User, org.bukkit.event.inventory.ClickType, int)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
|
||||||
|
// Get the world
|
||||||
|
if (!user.inWorld()) {
|
||||||
|
user.sendMessage("general.errors.wrong-world");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
IslandWorldManager iwm = plugin.getIWM();
|
||||||
|
String reqPerm = iwm.getPermissionPrefix(Util.getWorld(user.getWorld())) + ".admin.settings.COMMAND_RANKS";
|
||||||
|
if (!user.hasPermission(reqPerm)) {
|
||||||
|
user.sendMessage("general.errors.no-permission");
|
||||||
|
user.sendMessage("general.errors.you-need", "[permission]", reqPerm);
|
||||||
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String panelName = user.getTranslation("protection.flags.COMMAND_RANKS.name");
|
||||||
|
if (panel.getName().equals(panelName)) {
|
||||||
|
// This is a click on the panel
|
||||||
|
// Slot relates to the command
|
||||||
|
String c = getCommands(user.getWorld()).get(slot);
|
||||||
|
// Apply change to panel
|
||||||
|
panel.getInventory().setItem(slot, getPanelItem(c, user).getItem());
|
||||||
|
} else {
|
||||||
|
// Open the Sub Settings panel
|
||||||
|
openPanel(user, panelName);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openPanel(User user, String panelName) {
|
||||||
|
// Close the current panel
|
||||||
|
user.closeInventory();
|
||||||
|
// Open a new panel
|
||||||
|
PanelBuilder pb = new PanelBuilder();
|
||||||
|
pb.user(user).name(panelName);
|
||||||
|
// Make panel items
|
||||||
|
getCommands(user.getWorld()).forEach(c -> pb.item(getPanelItem(c, user)));
|
||||||
|
pb.build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the rank command panel item
|
||||||
|
* @param c - rank string
|
||||||
|
* @param user - user
|
||||||
|
* @return panel item for this command
|
||||||
|
*/
|
||||||
|
public PanelItem getPanelItem(String c, User user) {
|
||||||
|
PanelItemBuilder pib = new PanelItemBuilder();
|
||||||
|
pib.name(c);
|
||||||
|
pib.clickHandler(new CommandCycleClick(this, c));
|
||||||
|
pib.icon(Material.MAP);
|
||||||
|
// TODO: use specific layout
|
||||||
|
String d = user.getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, "");
|
||||||
|
pib.description(d);
|
||||||
|
plugin.getRanksManager().getRanks().forEach((reference, score) -> {
|
||||||
|
if (score >= RanksManager.MEMBER_RANK && score < plugin.getSettings().getRankCommand(c)) {
|
||||||
|
pib.description(user.getTranslation("protection.panel.flag-item.blocked_rank") + user.getTranslation(reference));
|
||||||
|
} else if (score <= RanksManager.OWNER_RANK && score > plugin.getSettings().getRankCommand(c)) {
|
||||||
|
pib.description(user.getTranslation("protection.panel.flag-item.allowed_rank") + user.getTranslation(reference));
|
||||||
|
} else if (score == plugin.getSettings().getRankCommand(c)) {
|
||||||
|
pib.description(user.getTranslation("protection.panel.flag-item.minimal_rank") + user.getTranslation(reference));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return pib.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getCommands(World world) {
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
plugin.getCommandsManager().getCommands().values().stream()
|
||||||
|
.filter(c -> c.getWorld() != null && c.getWorld().equals(world))
|
||||||
|
.forEach(c -> result.addAll(getCmdRecursively("/", c)));
|
||||||
|
if (result.size() > 49) {
|
||||||
|
Bukkit.getLogger().severe("Number of rank setting commands is too big for GUI");
|
||||||
|
result.subList(49, result.size()).clear();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively traverses the command tree looking for any configurable rank command and returns a string list of commands
|
||||||
|
* @param labels - preceding command's label list
|
||||||
|
* @param cc - composite command
|
||||||
|
* @return string list of commands
|
||||||
|
*/
|
||||||
|
private List<String> getCmdRecursively(String labels, CompositeCommand cc) {
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
String newLabel = labels + cc.getName();
|
||||||
|
if (cc.isConfigurableRankCommand()) {
|
||||||
|
result.add(newLabel);
|
||||||
|
}
|
||||||
|
cc.getSubCommands().values().forEach(s -> result.addAll(getCmdRecursively(newLabel + " ", s)));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ import world.bentobox.bentobox.listeners.flags.BreedingListener;
|
||||||
import world.bentobox.bentobox.listeners.flags.BucketListener;
|
import world.bentobox.bentobox.listeners.flags.BucketListener;
|
||||||
import world.bentobox.bentobox.listeners.flags.ChestDamageListener;
|
import world.bentobox.bentobox.listeners.flags.ChestDamageListener;
|
||||||
import world.bentobox.bentobox.listeners.flags.CleanSuperFlatListener;
|
import world.bentobox.bentobox.listeners.flags.CleanSuperFlatListener;
|
||||||
|
import world.bentobox.bentobox.listeners.flags.CommandRankClickListener;
|
||||||
import world.bentobox.bentobox.listeners.flags.CreeperListener;
|
import world.bentobox.bentobox.listeners.flags.CreeperListener;
|
||||||
import world.bentobox.bentobox.listeners.flags.EggListener;
|
import world.bentobox.bentobox.listeners.flags.EggListener;
|
||||||
import world.bentobox.bentobox.listeners.flags.EnderChestListener;
|
import world.bentobox.bentobox.listeners.flags.EnderChestListener;
|
||||||
|
@ -222,6 +223,9 @@ public class Flags {
|
||||||
*/
|
*/
|
||||||
public static final Flag CREEPER_GRIEFING = new FlagBuilder().id("CREEPER_GRIEFING").icon(Material.CREEPER_HEAD).type(Type.WORLD_SETTING)
|
public static final Flag CREEPER_GRIEFING = new FlagBuilder().id("CREEPER_GRIEFING").icon(Material.CREEPER_HEAD).type(Type.WORLD_SETTING)
|
||||||
.allowedByDefault(false).build();
|
.allowedByDefault(false).build();
|
||||||
|
|
||||||
|
public static final Flag COMMAND_RANKS = new FlagBuilder().id("COMMAND_RANKS").icon(Material.PLAYER_HEAD).type(Type.WORLD_SETTING)
|
||||||
|
.onClick(new CommandRankClickListener()).subPanel(true).build();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return List of all the flags in this class
|
* @return List of all the flags in this class
|
||||||
|
|
|
@ -44,4 +44,11 @@ public class CommandsManager {
|
||||||
return commands.keySet();
|
return commands.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the commands
|
||||||
|
*/
|
||||||
|
public HashMap<String, CompositeCommand> getCommands() {
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,19 @@ public class RanksManager {
|
||||||
public static final String ADMIN_RANK_REF = "ranks.admin";
|
public static final String ADMIN_RANK_REF = "ranks.admin";
|
||||||
public static final String MOD_RANK_REF = "ranks.mod";
|
public static final String MOD_RANK_REF = "ranks.mod";
|
||||||
public static final String OWNER_RANK_REF = "ranks.owner";
|
public static final String OWNER_RANK_REF = "ranks.owner";
|
||||||
|
public static final String SUB_OWNER_RANK_REF = "ranks.sub-owner";
|
||||||
public static final String MEMBER_RANK_REF = "ranks.member";
|
public static final String MEMBER_RANK_REF = "ranks.member";
|
||||||
|
public static final String TRUSTED_RANK_REF = "ranks.trusted";
|
||||||
|
public static final String COOP_RANK_REF = "ranks.coop";
|
||||||
public static final String VISITOR_RANK_REF = "ranks.visitor";
|
public static final String VISITOR_RANK_REF = "ranks.visitor";
|
||||||
public static final String BANNED_RANK_REF = "ranks.banned";
|
public static final String BANNED_RANK_REF = "ranks.banned";
|
||||||
public static final int ADMIN_RANK = 10000;
|
public static final int ADMIN_RANK = 10000;
|
||||||
public static final int MOD_RANK = 5000;
|
public static final int MOD_RANK = 5000;
|
||||||
public static final int OWNER_RANK = 1000;
|
public static final int OWNER_RANK = 1000;
|
||||||
public static final int MEMBER_RANK = 900;
|
public static final int SUB_OWNER_RANK = 900;
|
||||||
|
public static final int MEMBER_RANK = 500;
|
||||||
|
public static final int TRUSTED_RANK = 400;
|
||||||
|
public static final int COOP_RANK = 200;
|
||||||
public static final int VISITOR_RANK = 0;
|
public static final int VISITOR_RANK = 0;
|
||||||
public static final int BANNED_RANK = -1;
|
public static final int BANNED_RANK = -1;
|
||||||
|
|
||||||
|
@ -38,7 +44,10 @@ public class RanksManager {
|
||||||
ranksPut(ADMIN_RANK_REF, ADMIN_RANK);
|
ranksPut(ADMIN_RANK_REF, ADMIN_RANK);
|
||||||
ranksPut(MOD_RANK_REF, MOD_RANK);
|
ranksPut(MOD_RANK_REF, MOD_RANK);
|
||||||
ranksPut(OWNER_RANK_REF, OWNER_RANK);
|
ranksPut(OWNER_RANK_REF, OWNER_RANK);
|
||||||
|
ranksPut(SUB_OWNER_RANK_REF, SUB_OWNER_RANK);
|
||||||
ranksPut(MEMBER_RANK_REF, MEMBER_RANK);
|
ranksPut(MEMBER_RANK_REF, MEMBER_RANK);
|
||||||
|
ranksPut(TRUSTED_RANK_REF, TRUSTED_RANK);
|
||||||
|
ranksPut(COOP_RANK_REF, COOP_RANK);
|
||||||
ranksPut(VISITOR_RANK_REF, VISITOR_RANK);
|
ranksPut(VISITOR_RANK_REF, VISITOR_RANK);
|
||||||
ranksPut(BANNED_RANK_REF, BANNED_RANK);
|
ranksPut(BANNED_RANK_REF, BANNED_RANK);
|
||||||
loadCustomRanks();
|
loadCustomRanks();
|
||||||
|
|
|
@ -26,7 +26,9 @@ public class SettingsPanel {
|
||||||
/**
|
/**
|
||||||
* Dynamically creates the panel.
|
* Dynamically creates the panel.
|
||||||
* @param plugin - plugin
|
* @param plugin - plugin
|
||||||
* @param user the User to show the panel to
|
* @param user - user to show panel to
|
||||||
|
* @param flagType - initial view
|
||||||
|
* @param world - world
|
||||||
*/
|
*/
|
||||||
public static void openPanel(BentoBox plugin, User user, Flag.Type flagType, World world) {
|
public static void openPanel(BentoBox plugin, User user, Flag.Type flagType, World world) {
|
||||||
String friendlyWorldName = plugin.getIWM().getFriendlyName(world);
|
String friendlyWorldName = plugin.getIWM().getFriendlyName(world);
|
||||||
|
|
|
@ -307,7 +307,9 @@ commands:
|
||||||
|
|
||||||
ranks:
|
ranks:
|
||||||
owner: "Owner"
|
owner: "Owner"
|
||||||
|
sub-owner: "Sub-Owner"
|
||||||
member: "Member"
|
member: "Member"
|
||||||
|
trusted: "Trusted"
|
||||||
coop: "Coop"
|
coop: "Coop"
|
||||||
visitor: "Visitor"
|
visitor: "Visitor"
|
||||||
banned: "Banned"
|
banned: "Banned"
|
||||||
|
@ -385,6 +387,9 @@ protection:
|
||||||
&a(override Buckets)
|
&a(override Buckets)
|
||||||
name: "Collect water"
|
name: "Collect water"
|
||||||
hint: "No water collection"
|
hint: "No water collection"
|
||||||
|
COMMAND_RANKS:
|
||||||
|
name: "Command Ranks"
|
||||||
|
description: "&aConfigure command ranks"
|
||||||
CRAFTING:
|
CRAFTING:
|
||||||
description: "Toggle use"
|
description: "Toggle use"
|
||||||
name: "Workbenches"
|
name: "Workbenches"
|
||||||
|
|
Loading…
Reference in New Issue