Simplify teleportation permissions

This commit is contained in:
ME1312 2021-03-14 14:03:48 -04:00
parent b188f0d4af
commit 23a434054f
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
3 changed files with 53 additions and 63 deletions

View File

@ -794,11 +794,7 @@ public final class SubCommand extends BukkitCommand {
} }
} }
} else if (args.length > 0 && (args[0].equalsIgnoreCase("tp") || args[0].equalsIgnoreCase("teleport"))) { } else if (args.length > 0 && (args[0].equalsIgnoreCase("tp") || args[0].equalsIgnoreCase("teleport"))) {
if (sender.hasPermission("subservers.request")) {
executeTeleport(sender, label, args); executeTeleport(sender, label, args);
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.request"));
}
} else if (sender.hasPermission("subservers.interface") && sender instanceof Player) { } else if (sender.hasPermission("subservers.interface") && sender instanceof Player) {
plugin.gui.getRenderer((Player) sender).newUI(); plugin.gui.getRenderer((Player) sender).newUI();
} else { } else {
@ -809,20 +805,20 @@ public final class SubCommand extends BukkitCommand {
} }
private void executeTeleport(CommandSender sender, String label, String[] args) { private void executeTeleport(CommandSender sender, String label, String[] args) {
if (args.length > ((sender instanceof Player)?1:2)) { if (args.length > ((sender instanceof Player)?1:2)) {
if (sender.hasPermission("subservers.teleport")) {
String select = args[(args.length > 2)?2:1]; String select = args[(args.length > 2)?2:1];
plugin.api.getServer(select, server -> { plugin.api.getServer(select, server -> {
if (server != null) { if (server != null) {
if (permits(server, sender, "subservers.server.%.*", "subservers.server.%.teleport")) {
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) { if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
Player target = (args.length > 2)?Bukkit.getPlayer(args[1]):null; Player target = (args.length > 2)?Bukkit.getPlayer(args[1]):null;
if (target != null || args.length == 2) { if (target != null || args.length == 2) {
if (target == null || target == sender || permits(server, sender, "subservers.server.%.*", "subservers.server.%.teleport-others")) { if (target == null || target == sender || sender.hasPermission("subservers.teleport-others")) {
if (target == null) target = (Player) sender; if (target == null) target = (Player) sender;
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Teleport").replace("$str$", target.getName())); sender.sendMessage(plugin.api.getLang("SubServers", "Command.Teleport").replace("$str$", target.getName()));
plugin.pmc(target, "Connect", server.getName()); plugin.pmc(target, "Connect", server.getName());
} else { } else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.server." + server.getName() + ".teleport-others")); sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.teleport-others"));
} }
} else { } else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Unknown-Player").replace("$str$", args[1])); sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Unknown-Player").replace("$str$", args[1]));
@ -830,13 +826,13 @@ public final class SubCommand extends BukkitCommand {
} else { } else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Teleport.Not-Running").replace("$str$", server.getName())); 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 { } else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Unknown-Server").replace("$str$", select)); sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Unknown-Server").replace("$str$", select));
} }
}); });
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.teleport"));
}
} else { } else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " " + ((sender instanceof Player)?"[Player]":"<Player>") + " <Server>")); sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " " + ((sender instanceof Player)?"[Player]":"<Player>") + " <Server>"));
} }

View File

@ -6,70 +6,63 @@ softdepend: [TitleManager, PlaceholderAPI]
website: "https://github.com/ME1312/SubServers-2" website: "https://github.com/ME1312/SubServers-2"
#commands: #commands:
# subservers: # subservers:
# description: 'The SubServers Command' # description: "The SubServers Command"
# usage: '/subservers is currently unavailable' # usage: "/subservers is currently unavailable"
# subserver: # subserver:
# description: 'The SubServers Command' # description: "The SubServers Command"
# usage: '/subserver is currently unavailable' # usage: "/subserver is currently unavailable"
# sub: # sub:
# description: 'The SubServers Command' # description: "The SubServers Command"
# usage: '/sub is currently unavailable' # usage: "/sub is currently unavailable"
permissions: permissions:
subservers.*: subservers.*:
description: 'Grants Access to to Everything in SubServers.Client' description: "Access everything in SubServers.Client"
default: op default: op
children: children:
subservers.interface: subservers.interface:
description: 'Grants Access to the SubServers Interface' description: "Access to the SubServers Interface"
default: op default: op
subservers.command: subservers.command:
description: 'Grants Access to the SubServers Command' description: "Access to the SubServers Command"
default: op
children:
subservers.teleport:
description: "Access to SubServers' Teleport Command"
default: op
subservers.teleport-others:
description: "Access to Teleport other players using the Teleport Command"
default: op default: op
subservers.host.*: subservers.host.*:
description: 'Grants Access to all Host Actions on all Hosts' description: "Access to all Host Actions on all Hosts"
default: op default: op
children: children:
subservers.host.*.*: subservers.host.*.*:
description: 'Grants Access to all Host Actions on all Hosts' description: "Access to all Host Actions on all Hosts"
default: op default: op
children: children:
subservers.host.*.create: subservers.host.*.create:
description: 'Grants Access to Create a SubServer on all Hosts' description: "Access to Create a Subserver on all Hosts"
default: op default: op
subservers.subserver.*: subservers.subserver.*:
description: 'Grants Access to all SubServer Actions on all SubServers' description: "Access to all Subserver Actions on all Subservers"
default: op default: op
children: children:
subservers.subserver.*.*: subservers.subserver.*.*:
description: 'Grants Access to all SubServer Actions on all SubServers' description: "Access to all Subserver Actions on all Subservers"
default: op default: op
children: children:
subservers.subserver.*.start: subservers.subserver.*.start:
description: 'Grants Access to Start all SubServers' description: "Access to Start all Subservers"
default: op default: op
subservers.subserver.*.stop: subservers.subserver.*.stop:
description: 'Grants Access to Stop all SubServers' description: "Access to Stop all Subservers"
default: op default: op
subservers.subserver.*.terminate: subservers.subserver.*.terminate:
description: 'Grants Access to Terminate all SubServers' description: "Access to Terminate all Subservers"
default: op default: op
subservers.subserver.*.command: subservers.subserver.*.command:
description: 'Grants Access to Send Commands to all SubServers' description: "Access to Send Commands to all Subservers"
default: op default: op
subservers.subserver.*.update: subservers.subserver.*.update:
description: 'Grants Access to Update all SubServers' description: "Access to Update all Subservers"
default: op
subservers.server.*:
description: 'Grants Access to Server Actions on all Servers'
default: op
children:
subservers.server.*.*:
description: 'Grants Access to Server Actions on all Servers'
default: op
children:
subservers.server.*.teleport:
description: 'Grants Access to Teleport to any Server'
default: op
subservers.server.*.teleport-others:
description: 'Grants Access to Teleport Others to any Server'
default: op default: op

View File

@ -1136,7 +1136,7 @@ public final class SubCommand implements CommandExecutor {
public final class TELEPORT implements CommandExecutor { public final class TELEPORT implements CommandExecutor {
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
if (canRun(sender, true) && (sender.hasPermission("subservers.command") || sender.hasPermission("subservers.request"))) { if (canRun(sender, true)) {
Optional<String> p = args.getOne(Text.of("Player")); Optional<String> p = args.getOne(Text.of("Player"));
Optional<String> s = args.getOne(Text.of("Server")); Optional<String> s = args.getOne(Text.of("Server"));
if (!s.isPresent()) { if (!s.isPresent()) {
@ -1146,20 +1146,20 @@ public final class SubCommand implements CommandExecutor {
} }
if (s.isPresent() && (p.isPresent() || sender instanceof Player)) { if (s.isPresent() && (p.isPresent() || sender instanceof Player)) {
if (sender.hasPermission("subservers.command") || sender.hasPermission("subservers.teleport")) {
String name = (p.isPresent())?p.get():null; String name = (p.isPresent())?p.get():null;
String select = s.get(); String select = s.get();
plugin.api.getServer(select, server -> { plugin.api.getServer(select, server -> {
if (server != null) { if (server != null) {
if (permits(server, sender, "subservers.server.%.*", "subservers.server.%.teleport")) {
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) { if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
Value<Boolean> msg = new Container<>(false); Value<Boolean> msg = new Container<>(false);
Callback<Player> action = target -> { Callback<Player> action = target -> {
if (target == sender || permits(server, sender, "subservers.server.%.*", "subservers.server.%.teleport-others")) { if (target == sender || sender.hasPermission("subservers.teleport-others")) {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Teleport").replace("$str$", target.getName()))); sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Teleport").replace("$str$", target.getName())));
plugin.pmc(target, "Connect", server.getName()); plugin.pmc(target, "Connect", server.getName());
} else if (!msg.value()) { } else if (!msg.value()) {
msg.value(true); msg.value(true);
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.server." + server.getName() + ".teleport-others"))); sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.teleport-others")));
} }
}; };
@ -1183,14 +1183,15 @@ public final class SubCommand implements CommandExecutor {
} else { } else {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Teleport.Not-Running").replace("$str$", server.getName()))); sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Teleport.Not-Running").replace("$str$", server.getName())));
} }
} else {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Select-Permission").replace("$str$", server.getName())));
}
} else { } else {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Generic.Unknown-Server").replace("$str$", select))); sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Generic.Unknown-Server").replace("$str$", select)));
} }
}); });
return CommandResult.builder().successCount(1).build(); return CommandResult.builder().successCount(1).build();
} else {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.teleport")));
return CommandResult.builder().successCount(0).build();
}
} else { } else {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub teleport " + ((sender instanceof Player)?"[Player]":"<Player>") + " <Server>"))); sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub teleport " + ((sender instanceof Player)?"[Player]":"<Player>") + " <Server>")));
return CommandResult.builder().successCount(0).build(); return CommandResult.builder().successCount(0).build();