mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-29 14:15:41 +01:00
Added ability to hide command rank commands by Ops.
This commit is contained in:
parent
9acb79fc60
commit
43db8d346c
@ -5,6 +5,7 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
@ -18,6 +19,7 @@ import world.bentobox.bentobox.managers.RanksManager;
|
|||||||
*/
|
*/
|
||||||
public class CommandCycleClick implements ClickHandler {
|
public class CommandCycleClick implements ClickHandler {
|
||||||
|
|
||||||
|
protected static final String COMMAND_RANK_PREFIX = "COMMAND_RANK:";
|
||||||
private final BentoBox plugin = BentoBox.getInstance();
|
private final BentoBox plugin = BentoBox.getInstance();
|
||||||
private final String command;
|
private final String command;
|
||||||
private final CommandRankClickListener commandRankClickListener;
|
private final CommandRankClickListener commandRankClickListener;
|
||||||
@ -53,6 +55,8 @@ public class CommandCycleClick implements ClickHandler {
|
|||||||
island.setRankCommand(command, RanksManager.getInstance().getRankDownValue(currentRank));
|
island.setRankCommand(command, RanksManager.getInstance().getRankDownValue(currentRank));
|
||||||
}
|
}
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||||
|
} else if (click.equals(ClickType.SHIFT_LEFT) && user.isOp()) {
|
||||||
|
leftShiftClick(user);
|
||||||
}
|
}
|
||||||
// Apply change to panel
|
// Apply change to panel
|
||||||
panel.getInventory().setItem(slot, commandRankClickListener.getPanelItem(command, user, world).getItem());
|
panel.getInventory().setItem(slot, commandRankClickListener.getPanelItem(command, user, world).getItem());
|
||||||
@ -65,4 +69,22 @@ public class CommandCycleClick implements ClickHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds or removes the command rank from visibility by non-Ops
|
||||||
|
* @param user - the Op requesting the change
|
||||||
|
*/
|
||||||
|
private void leftShiftClick(User user) {
|
||||||
|
String configSetting = COMMAND_RANK_PREFIX + command;
|
||||||
|
if (!plugin.getIWM().getHiddenFlags(user.getWorld()).contains(configSetting)) {
|
||||||
|
plugin.getIWM().getHiddenFlags(user.getWorld()).add(configSetting);
|
||||||
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1F);
|
||||||
|
} else {
|
||||||
|
plugin.getIWM().getHiddenFlags(user.getWorld()).remove(configSetting);
|
||||||
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1F, 1F);
|
||||||
|
}
|
||||||
|
// Save changes
|
||||||
|
plugin.getIWM().getAddon(user.getWorld()).ifPresent(GameModeAddon::saveWorldSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public class CommandRankClickListener implements ClickHandler {
|
|||||||
if (panel.getName().equals(panelName)) {
|
if (panel.getName().equals(panelName)) {
|
||||||
// This is a click on the panel
|
// This is a click on the panel
|
||||||
// Slot relates to the command
|
// Slot relates to the command
|
||||||
String c = getCommands(panel.getWorld().orElse(user.getWorld())).get(slot);
|
String c = getCommands(panel.getWorld().orElse(user.getWorld()), user).get(slot);
|
||||||
// Apply change to panel
|
// Apply change to panel
|
||||||
panel.getInventory().setItem(slot, getPanelItem(c, user, panel.getWorld().orElse(user.getWorld())).getItem());
|
panel.getInventory().setItem(slot, getPanelItem(c, user, panel.getWorld().orElse(user.getWorld())).getItem());
|
||||||
} else {
|
} else {
|
||||||
@ -94,7 +94,7 @@ public class CommandRankClickListener implements ClickHandler {
|
|||||||
PanelBuilder pb = new PanelBuilder();
|
PanelBuilder pb = new PanelBuilder();
|
||||||
pb.user(user).name(panelName).world(world);
|
pb.user(user).name(panelName).world(world);
|
||||||
// Make panel items
|
// Make panel items
|
||||||
getCommands(world).forEach(c -> pb.item(getPanelItem(c, user, world)));
|
getCommands(world, user).forEach(c -> pb.item(getPanelItem(c, user, world)));
|
||||||
pb.build();
|
pb.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -123,14 +123,18 @@ public class CommandRankClickListener implements ClickHandler {
|
|||||||
pib.description(user.getTranslation("protection.panel.flag-item.minimal-rank") + user.getTranslation(reference));
|
pib.description(user.getTranslation("protection.panel.flag-item.minimal-rank") + user.getTranslation(reference));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
pib.invisible(plugin.getIWM().getHiddenFlags(world).contains(CommandCycleClick.COMMAND_RANK_PREFIX + c));
|
||||||
return pib.build();
|
return pib.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getCommands(World world) {
|
private List<String> getCommands(World world, User user) {
|
||||||
List<String> result = new ArrayList<>();
|
List<String> hiddenItems = plugin.getIWM().getHiddenFlags(world);
|
||||||
plugin.getCommandsManager().getCommands().values().stream()
|
List<String> result = plugin.getCommandsManager().getCommands().values().stream()
|
||||||
.filter(c -> c.getWorld() != null && c.getWorld().equals(world))
|
.filter(c -> c.getWorld() != null && c.getWorld().equals(world)) // Only allow commands in this world
|
||||||
.forEach(c -> result.addAll(getCmdRecursively("/", c)));
|
.filter(c -> c.testPermission(user.getSender())) // Only allow them to see commands they have permission to see
|
||||||
|
.flatMap(c -> getCmdRecursively("/", c).stream())
|
||||||
|
.filter(label -> user.isOp() || !hiddenItems.contains(CommandCycleClick.COMMAND_RANK_PREFIX + label))
|
||||||
|
.toList();
|
||||||
if (result.size() > 49) {
|
if (result.size() > 49) {
|
||||||
plugin.logError("Number of rank setting commands is too big for GUI");
|
plugin.logError("Number of rank setting commands is too big for GUI");
|
||||||
result.subList(49, result.size()).clear();
|
result.subList(49, result.size()).clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user