mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 02:08:27 +01:00
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:
parent
a992ec7c52
commit
a9b0afb40a
@ -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);
|
||||
}
|
||||
|
@ -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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user