mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +00:00
Add a command list
This commit is contained in:
1 parent
30cf917969
commit
7a47868f86
6 files changed
+87
-15
No files matched your search
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>me.William278</groupId>
|
<groupId>me.William278</groupId>
|
||||||
<artifactId>HuskHomes</artifactId>
|
<artifactId>HuskHomes</artifactId>
|
||||||
<version>2.5.1-dev</version>
|
<version>2.5.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HuskHomes</name>
|
<name>HuskHomes</name>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import de.themoep.minedown.MineDown;
|
|||||||
import me.william278.huskhomes2.HuskHomes;
|
import me.william278.huskhomes2.HuskHomes;
|
||||||
import me.william278.huskhomes2.MessageManager;
|
import me.william278.huskhomes2.MessageManager;
|
||||||
import me.william278.huskhomes2.migrators.EssentialsMigrator;
|
import me.william278.huskhomes2.migrators.EssentialsMigrator;
|
||||||
|
import me.william278.huskhomes2.util.ChatList;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -12,6 +13,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -28,6 +30,32 @@ public class HuskHomesCommand extends CommandBase implements TabCompleter {
|
|||||||
.append("[• Report Issues:](white) [[Link]](#00fb9a show_text=&7Click to open link open_url=https://github.com/WiIIiam278/HuskHomes2/issues)\n")
|
.append("[• Report Issues:](white) [[Link]](#00fb9a show_text=&7Click to open link open_url=https://github.com/WiIIiam278/HuskHomes2/issues)\n")
|
||||||
.append("[• Support Discord:](white) [[Link]](#00fb9a show_text=&7Click to join open_url=https://discord.gg/tVYhJfyDWG)");
|
.append("[• Support Discord:](white) [[Link]](#00fb9a show_text=&7Click to join open_url=https://discord.gg/tVYhJfyDWG)");
|
||||||
|
|
||||||
|
// Show users a list of available commands
|
||||||
|
public static void showHelpMenu(Player player, int pageNumber) {
|
||||||
|
ArrayList<String> commandDisplay = new ArrayList<>();
|
||||||
|
for (String command : plugin.getDescription().getCommands().keySet()) {
|
||||||
|
if (HuskHomes.getSettings().hideCommandsFromHelpMenuWithoutPermission()) {
|
||||||
|
if (!player.hasPermission((String) plugin.getDescription().getCommands().get(command).get("permission"))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (command.equals("huskhomes") && HuskHomes.getSettings().hideHuskHomesCommandFromHelpMenu()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String description = (String) plugin.getDescription().getCommands().get(command).get("description");
|
||||||
|
String commandUsage = (String) plugin.getDescription().getCommands().get(command).get("usage");
|
||||||
|
commandDisplay.add("[/" + command + "](#00fb9a show_text=�fb9a&" + commandUsage + " suggest_command=/" + command + ") [•](white) [" + description + "](gray)");
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageManager.sendMessage(player, "command_list_header");
|
||||||
|
ChatList helpList = new ChatList(commandDisplay, 10, "/huskhomes help", "\n");
|
||||||
|
if (helpList.doesNotContainPage(pageNumber)) {
|
||||||
|
MessageManager.sendMessage(player, "error_invalid_page_number");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.spigot().sendMessage(helpList.getPage(pageNumber));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
@@ -43,6 +71,17 @@ public class HuskHomesCommand extends CommandBase implements TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
|
case "about":
|
||||||
|
case "info":
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player p = (Player) sender;
|
||||||
|
if (!p.hasPermission("huskhomes.about")) {
|
||||||
|
MessageManager.sendMessage(p, "error_no_permission");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender.spigot().sendMessage(new MineDown(PLUGIN_INFORMATION.toString()).toComponent());
|
||||||
|
return true;
|
||||||
case "update":
|
case "update":
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player p = (Player) sender;
|
Player p = (Player) sender;
|
||||||
@@ -97,15 +136,27 @@ public class HuskHomesCommand extends CommandBase implements TabCompleter {
|
|||||||
sender.sendMessage(ChatColor.RED + "Invalid syntax! Usage: /huskhomes migrate essentialsX");
|
sender.sendMessage(ChatColor.RED + "Invalid syntax! Usage: /huskhomes migrate essentialsX");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
case "help":
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player p = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if (!p.hasPermission("huskhomes.about")) {
|
if (args.length == 2) {
|
||||||
MessageManager.sendMessage(p, "error_no_permission");
|
try {
|
||||||
return true;
|
int pageNo = Integer.parseInt(args[1]);
|
||||||
|
showHelpMenu(player, pageNo);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
MessageManager.sendMessage(player, "error_invalid_page_number");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showHelpMenu(player, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.spigot().sendMessage(new MineDown(PLUGIN_INFORMATION.toString()).toComponent());
|
return true;
|
||||||
|
default:
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
showHelpMenu((Player) sender, 1);
|
||||||
|
} else {
|
||||||
|
sender.spigot().sendMessage(new MineDown(PLUGIN_INFORMATION.toString()).toComponent());
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,19 +166,20 @@ public class HuskHomesCommand extends CommandBase implements TabCompleter {
|
|||||||
// Console is fine too
|
// Console is fine too
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final static String[] COMMAND_TAB_ARGS = {"help", "about", "update", "reload"};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||||
|
Player p = (Player) sender;
|
||||||
|
if (command.getPermission() != null) {
|
||||||
|
if (!p.hasPermission(command.getPermission())) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
final List<String> tabCompletions = new ArrayList<>();
|
final List<String> tabCompletions = new ArrayList<>();
|
||||||
List<String> tabOptions = new ArrayList<>();
|
StringUtil.copyPartialMatches(args[0], Arrays.asList(COMMAND_TAB_ARGS), tabCompletions);
|
||||||
tabOptions.add("about");
|
|
||||||
tabOptions.add("reload");
|
|
||||||
tabOptions.add("update");
|
|
||||||
|
|
||||||
StringUtil.copyPartialMatches(args[0], tabOptions, tabCompletions);
|
|
||||||
|
|
||||||
Collections.sort(tabCompletions);
|
Collections.sort(tabCompletions);
|
||||||
|
|
||||||
return tabCompletions;
|
return tabCompletions;
|
||||||
} else {
|
} else {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
|||||||
@@ -77,6 +77,10 @@ public class Settings {
|
|||||||
private int publicHomesPerPage;
|
private int publicHomesPerPage;
|
||||||
private int warpsPerPage;
|
private int warpsPerPage;
|
||||||
|
|
||||||
|
// Help menu options
|
||||||
|
private boolean hideCommandsFromHelpMenuWithoutPermission;
|
||||||
|
private boolean hideHuskHomesCommandFromHelpMenu;
|
||||||
|
|
||||||
// RTP command settings
|
// RTP command settings
|
||||||
private boolean doRtpCommand;
|
private boolean doRtpCommand;
|
||||||
private int rtpRange;
|
private int rtpRange;
|
||||||
@@ -220,6 +224,9 @@ public class Settings {
|
|||||||
this.publicHomesPerPage = config.getInt("general.lists.public_homes_per_page");
|
this.publicHomesPerPage = config.getInt("general.lists.public_homes_per_page");
|
||||||
this.warpsPerPage = config.getInt("general.lists.warps_per_page");
|
this.warpsPerPage = config.getInt("general.lists.warps_per_page");
|
||||||
|
|
||||||
|
this.hideCommandsFromHelpMenuWithoutPermission = config.getBoolean("general.help_menu.hide_commands_without_permission");
|
||||||
|
this.hideHuskHomesCommandFromHelpMenu = config.getBoolean("general.help_menu.hide_huskhomes_command");
|
||||||
|
|
||||||
this.maximumHomes = config.getInt("general.max_sethomes");
|
this.maximumHomes = config.getInt("general.max_sethomes");
|
||||||
this.teleportRequestExpiryTime = config.getInt("general.teleport_request_expiry_time");
|
this.teleportRequestExpiryTime = config.getInt("general.teleport_request_expiry_time");
|
||||||
this.teleportWarmupTime = config.getInt("general.teleport_warmup_time");
|
this.teleportWarmupTime = config.getInt("general.teleport_warmup_time");
|
||||||
@@ -438,4 +445,12 @@ public class Settings {
|
|||||||
public boolean doHideRestrictedWarps() {
|
public boolean doHideRestrictedWarps() {
|
||||||
return hideRestrictedWarps;
|
return hideRestrictedWarps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hideCommandsFromHelpMenuWithoutPermission() {
|
||||||
|
return hideCommandsFromHelpMenuWithoutPermission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hideHuskHomesCommandFromHelpMenu() {
|
||||||
|
return hideHuskHomesCommandFromHelpMenu;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -121,3 +121,4 @@ page_options_min: '\n[Viewing Page %1%/%2%](#00fb9a) [→](gray show_text=&7View
|
|||||||
page_options_min_max: '\n[Viewing Page %1%/%2%](#00fb9a)'
|
page_options_min_max: '\n[Viewing Page %1%/%2%](#00fb9a)'
|
||||||
page_options_max: '\n[←](gray show_text=&7View previous page run_command=%1%) [Viewing Page %2%/%3%](#00fb9a)'
|
page_options_max: '\n[←](gray show_text=&7View previous page run_command=%1%) [Viewing Page %2%/%3%](#00fb9a)'
|
||||||
page_no_items: '[(No items to display on this page)](gray show_text=&7Try a different page number)'
|
page_no_items: '[(No items to display on this page)](gray show_text=&7Try a different page number)'
|
||||||
|
command_list_header: '\n[HuskHomes](#00fb9a bold) [| Command List](#00fb9a)'
|
||||||
@@ -121,3 +121,4 @@ page_options_min: '\n[Pagina %1%/%2%](#00fb9a) [→](gray show_text=&7Pagina suc
|
|||||||
page_options_min_max: '\n[Pagina %1%/%2%](#00fb9a)'
|
page_options_min_max: '\n[Pagina %1%/%2%](#00fb9a)'
|
||||||
page_options_max: '\n[←](gray show_text=&7Pagina precedente run_command=%1%) [Pagina %2%/%3%](#00fb9a)'
|
page_options_max: '\n[←](gray show_text=&7Pagina precedente run_command=%1%) [Pagina %2%/%3%](#00fb9a)'
|
||||||
page_no_items: '[(Nessun oggetto visibile in questa pagina)](gray show_text=&7Prova un numero differente)'
|
page_no_items: '[(Nessun oggetto visibile in questa pagina)](gray show_text=&7Prova un numero differente)'
|
||||||
|
command_list_header: '\n[HuskHomes](#00fb9a bold) [| Command List](#00fb9a)'
|
||||||
@@ -32,6 +32,9 @@ general:
|
|||||||
private_homes_per_page: 10
|
private_homes_per_page: 10
|
||||||
public_homes_per_page: 10
|
public_homes_per_page: 10
|
||||||
warps_per_page: 10
|
warps_per_page: 10
|
||||||
|
help_menu:
|
||||||
|
hide_commands_without_permission: true
|
||||||
|
hide_huskhomes_command: false
|
||||||
bungee_options:
|
bungee_options:
|
||||||
enable_bungee_mode: false
|
enable_bungee_mode: false
|
||||||
server_id: 'server'
|
server_id: 'server'
|
||||||
|
|||||||
Reference in new issue
Block a user