Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement open other command #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/fun/lewisdev/deluxehub/Permissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public enum Permissions {
COMMAND_DELUXEHUB_RELOAD("command.reload"),
COMMAND_SCOREBOARD_TOGGLE("command.scoreboard"),
COMMAND_OPEN_MENUS("command.openmenu"),
COMMAND_OPEN_MENUS_OTHERS("command.openmenu.others"),
COMMAND_HOLOGRAMS("command.holograms"),

COMMAND_GAMEMODE("command.gamemode"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import fun.lewisdev.deluxehub.module.modules.visual.scoreboard.ScoreboardManager;
import fun.lewisdev.deluxehub.module.modules.world.LobbySpawn;
import fun.lewisdev.deluxehub.utility.TextUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -59,7 +60,7 @@ public void main(final CommandContext args, final CommandSender sender) throws C
sender.sendMessage("");
sender.sendMessage(TextUtil.color(" &d/deluxehub info &8- &7&oDisplays information about the current config"));
sender.sendMessage(TextUtil.color(" &d/deluxehub scoreboard &8- &7&oToggle the scoreboard"));
sender.sendMessage(TextUtil.color(" &d/deluxehub open <menu> &8- &7&oOpen a custom menu"));
sender.sendMessage(TextUtil.color(" &d/deluxehub open <menu> [player] &8- &7&oOpen a custom menu"));
sender.sendMessage(TextUtil.color(" &d/deluxehub hologram &8- &7&oView the hologram help"));
sender.sendMessage("");
sender.sendMessage(TextUtil.color(" &d/vanish &8- &7&oToggle vanish mode"));
Expand Down Expand Up @@ -172,14 +173,30 @@ else if (args.getString(0).equalsIgnoreCase("info")) {
Description: opens a custom menu
*/
else if (args.getString(0).equalsIgnoreCase("open")) {
if (!(sender instanceof Player)) throw new CommandException("Console cannot open menus");
int argsLength = args.argsLength();
Player target = null;
if (argsLength >= 3 && sender.hasPermission(Permissions.COMMAND_OPEN_MENUS_OTHERS.getPermission())) {
String targetName = args.getString(2);
target = Bukkit.getPlayer(targetName);
}

if (target == null) {
if (sender instanceof Player) target = (Player) sender;
else {
if(argsLength < 3) {
sender.sendMessage(TextUtil.color("&cUsage: /deluxehub open <menu> <player>"));
return;
}
throw new CommandException("Player not found");
}
}

if (!sender.hasPermission(Permissions.COMMAND_OPEN_MENUS.getPermission())) {
Messages.NO_PERMISSION.send(sender);
return;
}

if (args.argsLength() == 1) {
if (argsLength < 2) {
sender.sendMessage(TextUtil.color("&cUsage: /deluxehub open <menu>"));
return;
}
Expand All @@ -189,7 +206,7 @@ else if (args.getString(0).equalsIgnoreCase("open")) {
sender.sendMessage(TextUtil.color("&c" + args.getString(1) + " is not a valid menu ID."));
return;
}
inventory.openInventory((Player) sender);
inventory.openInventory(target);
}

/*
Expand Down