Adds the info command as described in #5
This commit is contained in:
@@ -8,6 +8,8 @@ Stargate-Command is an addon for Stargate which adds additional useful commands
|
||||
|
||||
* The ability to edit the config file through commands, and automated reloading of changed values
|
||||
* The ability to dial any Stargate accessible to the Player
|
||||
* The ability to visualize Stargates in a network
|
||||
* The ability to see information about the Stargate you are looking at
|
||||
|
||||
## Dependencies
|
||||
|
||||
@@ -20,7 +22,8 @@ Stargate-Command is an addon for Stargate which adds additional useful commands
|
||||
```
|
||||
stargate.command.config - Gives access to the `/sgc config` command
|
||||
stargate.command.dial - Gives access to the `/sgc dial` command
|
||||
stargate.command.visualizer- Gives access to the `/sgc visualizer` command
|
||||
stargate.command.visualizer - Gives access to the `/sgc visualizer` command
|
||||
stargate.command.info - Gives access to the `/sgc info` command
|
||||
```
|
||||
|
||||
# Changes
|
||||
@@ -29,6 +32,8 @@ stargate.command.visualizer- Gives access to the `/sgc visualizer` command
|
||||
|
||||
- Full takeover removing old functionality, and, for now, replacing it with config editing
|
||||
- Adds /sgc dial for dialing any wanted Stargate
|
||||
- Adds /sgc visualizer for visualizing the portals in a network
|
||||
- Adds /sgc info for seeing information about the Stargate the player is looking at
|
||||
[Version 0.0.4]
|
||||
- Fix for Bukkit's direction fix
|
||||
[Version 0.0.3]
|
||||
|
||||
@@ -41,6 +41,8 @@ public class CommandStarGateCommand implements CommandExecutor {
|
||||
return new CommandDial(stargateAPI).onCommand(commandSender, command, s, subArgs);
|
||||
} else if (args[0].equalsIgnoreCase("visualizer")) {
|
||||
return new CommandVisualizer(stargateAPI.getRegistry()).onCommand(commandSender, command, s, subArgs);
|
||||
} else if (args[0].equalsIgnoreCase("info")) {
|
||||
return new TabCommandInfo(stargateAPI.getRegistry()).onCommand(commandSender, command, s, subArgs);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -54,6 +54,8 @@ public class StargateCommandTabCompleter implements TabCompleter {
|
||||
return new DialTabCompleter(stargateAPI).onTabComplete(commandSender, command, s, subArgs);
|
||||
} else if (args[0].equalsIgnoreCase("visualizer")) {
|
||||
return new VisualizerTabCompleter(stargateAPI.getRegistry()).onTabComplete(commandSender, command, s, subArgs);
|
||||
} else if (args[0].equalsIgnoreCase("info")) {
|
||||
return new TabCommandInfo(stargateAPI.getRegistry()).onTabComplete(commandSender, command, s, subArgs);
|
||||
}
|
||||
}
|
||||
return new ArrayList<>();
|
||||
@@ -76,6 +78,9 @@ public class StargateCommandTabCompleter implements TabCompleter {
|
||||
if (commandSender instanceof Player player && player.hasPermission("stargate.command.visualizer")) {
|
||||
commands.add("visualizer");
|
||||
}
|
||||
if (commandSender instanceof Player player && player.hasPermission("stargate.command.info")) {
|
||||
commands.add("info");
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package net.knarcraft.stargatecommand.command;
|
||||
|
||||
import net.TheDgtl.Stargate.network.RegistryAPI;
|
||||
import net.TheDgtl.Stargate.network.portal.Portal;
|
||||
import net.TheDgtl.Stargate.network.portal.PortalFlag;
|
||||
import net.knarcraft.stargatecommand.util.PortalFinderHelper;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This tab-command represents the command for getting information about a seen portal
|
||||
*/
|
||||
public class TabCommandInfo implements TabExecutor {
|
||||
|
||||
private final RegistryAPI registryAPI;
|
||||
|
||||
/**
|
||||
* Instantiates a new info command
|
||||
*
|
||||
* @param registryAPI <p>A reference to the Registry API</p>
|
||||
*/
|
||||
public TabCommandInfo(RegistryAPI registryAPI) {
|
||||
this.registryAPI = registryAPI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] args) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMessage("This command can only be used by a player");
|
||||
return true;
|
||||
}
|
||||
Portal portal = PortalFinderHelper.findPortalByRaytrace(registryAPI, player, 15);
|
||||
if (portal == null) {
|
||||
commandSender.sendMessage("You need to look directly at a portal to get information about it");
|
||||
return true;
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("Information about the Stargate you are currently looking at:").append("\n");
|
||||
stringBuilder.append("|- ").append("Name: ").append(portal.getName()).append("\n");
|
||||
String destination = portal.getDestinationName();
|
||||
if (destination != null && !destination.equalsIgnoreCase("null")) {
|
||||
stringBuilder.append("|- ").append("Destination: ").append(portal.getDestinationName()).append("\n");
|
||||
}
|
||||
stringBuilder.append("|- ").append("Network: ").append(portal.getNetwork().getName()).append("\n");
|
||||
Player owner = Bukkit.getPlayer(portal.getOwnerUUID());
|
||||
if (owner != null) {
|
||||
stringBuilder.append("|- ").append("Owner: ").append(owner.getName()).append("\n");
|
||||
} else {
|
||||
stringBuilder.append("|- ").append("Owner: ").append(portal.getOwnerUUID()).append("\n");
|
||||
}
|
||||
Set<PortalFlag> portalFlags = PortalFlag.parseFlags(portal.getAllFlagsString());
|
||||
stringBuilder.append("|- ").append("Flags: ").append(StringUtils.join(portalFlags, ", ")).append("\n");
|
||||
player.sendMessage(stringBuilder.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] strings) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
public final class TabCompleterHelper {
|
||||
|
||||
private TabCompleterHelper() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,7 @@ commands:
|
||||
/<command> config <config option> <new value>
|
||||
/<command> dial <network name> <portal name>
|
||||
/<command> visualizer <network name>
|
||||
/<command> info
|
||||
permissions:
|
||||
stargate.command.config:
|
||||
description: Allows the use of /sgc config
|
||||
@@ -24,4 +25,7 @@ permissions:
|
||||
default: op
|
||||
stargate.command.visualizer:
|
||||
description: Allows the use of /sgc visualizer
|
||||
default: op
|
||||
stargate.command.info:
|
||||
description: Allows the use of /sgc info
|
||||
default: op
|
||||
Reference in New Issue
Block a user