Let plebs use /sub teleport

There's still explicit permissions for this command, but granting `subservers.command` is no longer necessary.
This commit is contained in:
ME1312 2021-03-13 12:09:54 -05:00
parent a992ec7c52
commit a9b0afb40a
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
2 changed files with 43 additions and 34 deletions

View File

@ -731,38 +731,7 @@ public final class SubCommand extends BukkitCommand {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Subservers> [[Template] <Version>]"));
}
} else if (args[0].equalsIgnoreCase("tp") || args[0].equalsIgnoreCase("teleport")) {
if (args.length > ((sender instanceof Player)?1:2)) {
String select = args[(args.length > 2)?2:1];
plugin.api.getServer(select, server -> {
if (server != null) {
if (permits(server, sender, "subservers.server.%.*", "subservers.server.%.teleport")) {
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
Player target = (args.length > 2)?Bukkit.getPlayer(args[1]):null;
if (target != null || args.length == 2) {
if (target == null || target == sender || permits(server, sender, "subservers.server.%.*", "subservers.server.%.teleport-others")) {
if (target == null) target = (Player) sender;
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Teleport").replace("$str$", target.getName()));
plugin.pmc(target, "Connect", server.getName());
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.server." + server.getName() + ".teleport-others"));
}
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Unknown-Player").replace("$str$", args[1]));
}
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Teleport.Not-Running").replace("$str$", server.getName()));
}
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Select-Permission").replace("$str$", server.getName()));
}
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Unknown-Server").replace("$str$", select));
}
});
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " " + ((sender instanceof Player)?"[Player]":"<Player>") + " <Server>"));
}
executeTeleport(sender, label, args);
} else if ((args[0].equalsIgnoreCase("view") || args[0].equalsIgnoreCase("open")) && sender instanceof Player) {
if (plugin.gui != null) {
if (sender.hasPermission("subservers.interface")) {
@ -824,6 +793,8 @@ public final class SubCommand extends BukkitCommand {
sender.sendMessage(printHelp(sender, label));
}
}
} else if (args.length > 0 && (args[0].equalsIgnoreCase("tp") || args[0].equalsIgnoreCase("teleport"))) {
executeTeleport(sender, label, args);
} else if (sender.hasPermission("subservers.interface") && sender instanceof Player) {
plugin.gui.getRenderer((Player) sender).newUI();
} else {
@ -832,6 +803,40 @@ public final class SubCommand extends BukkitCommand {
}
return true;
}
private void executeTeleport(CommandSender sender, String label, String[] args) {
if (args.length > ((sender instanceof Player)?1:2)) {
String select = args[(args.length > 2)?2:1];
plugin.api.getServer(select, server -> {
if (server != null) {
if (permits(server, sender, "subservers.server.%.*", "subservers.server.%.teleport")) {
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
Player target = (args.length > 2)?Bukkit.getPlayer(args[1]):null;
if (target != null || args.length == 2) {
if (target == null || target == sender || permits(server, sender, "subservers.server.%.*", "subservers.server.%.teleport-others")) {
if (target == null) target = (Player) sender;
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Teleport").replace("$str$", target.getName()));
plugin.pmc(target, "Connect", server.getName());
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.server." + server.getName() + ".teleport-others"));
}
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Unknown-Player").replace("$str$", args[1]));
}
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Teleport.Not-Running").replace("$str$", server.getName()));
}
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Select-Permission").replace("$str$", server.getName()));
}
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Unknown-Server").replace("$str$", select));
}
});
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " " + ((sender instanceof Player)?"[Player]":"<Player>") + " <Server>"));
}
}
private void selectServers(CommandSender sender, String[] rargs, int index, boolean mode, String permissions, Callback<ServerSelection> callback) {
selectServers(sender, rargs, index, mode, Arrays.asList(permissions), callback);
}

View File

@ -135,12 +135,16 @@ public final class SubCommand implements CommandExecutor {
}
private boolean canRun(CommandSource sender) throws CommandException {
return canRun(sender, false);
}
private boolean canRun(CommandSource sender, boolean permitted) throws CommandException {
if (SubAPI.getInstance().getSubDataNetwork()[0] == null) {
throw new CommandException(Text.builder("An exception has occurred while running this command").color(TextColors.RED).build(), new IllegalStateException("SubData is not connected"), false);
} else if (plugin.lang == null) {
throw new CommandException(Text.builder("An exception has occurred while running this command").color(TextColors.RED).build(), new IllegalStateException("There are no lang options available at this time"), false);
} else {
return sender.hasPermission("subservers.command");
return permitted || sender.hasPermission("subservers.command");
}
}
@ -1132,7 +1136,7 @@ public final class SubCommand implements CommandExecutor {
public final class TELEPORT implements CommandExecutor {
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
if (canRun(sender)) {
if (canRun(sender, true)) {
Optional<String> p = args.getOne(Text.of("Player"));
Optional<String> s = args.getOne(Text.of("Server"));
if (!s.isPresent()) {