Skip to content

Commit 4012e9b

Browse files
author
Sekwah
committed
Fixed permissions surrounding /portal warp
1 parent 6c9eeb0 commit 4012e9b

File tree

3 files changed

+111
-98
lines changed

3 files changed

+111
-98
lines changed

src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java

+42-41
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,45 @@ public boolean onCommand(CommandSender sender, Command cmd, String command, Stri
6262
Player player = (Player) sender;
6363
PlayerInventory inventory = player.getInventory();
6464

65+
if(args.length > 0) {
66+
if(args[0].equalsIgnoreCase("warp") && player.hasPermission("advancedportals.warp")) {
67+
if (args.length == 2 && (player.hasPermission("advancedportals.warp.*")
68+
|| player.hasPermission("advancedportals.warp." + args[1]))) {
69+
AdvancedPortal portal = Portal.getPortal(args[1]);
70+
71+
if(portal == null) {
72+
sender.sendMessage(PluginMessages.customPrefixFail
73+
+ " Could not find a portal with that name");
74+
}
75+
else {
76+
if (portal.inPortal.contains(player.getUniqueId()))
77+
return true;
78+
WarpEvent warpEvent = new WarpEvent(player, portal);
79+
plugin.getServer().getPluginManager().callEvent(warpEvent);
80+
81+
if (!warpEvent.isCancelled()) {
82+
Portal.activate(player, portal, false);
83+
return true;
84+
}
85+
}
86+
} else if (args.length == 1 && player.hasPermission("advancedportals.warp")) {
87+
sendMenu(player, "Help Menu: Warp",
88+
"\u00A76/" + command + " warp <name> \u00A7a- teleport to warp name");
89+
}
90+
else {
91+
sender.sendMessage(PluginMessages.customPrefixFail
92+
+ " You do not have permission to perform that command");
93+
}
94+
return true;
95+
}
96+
97+
}
98+
6599
if (sender.hasPermission("advancedportals.portal")) {
66100
if (args.length > 0) {
67101
switch (args[0].toLowerCase()) {
68-
case "warp":
69-
if (args.length == 2 && (player.hasPermission("advancedportals.warp.*") || player.hasPermission("advancedportals.warp." + args[1]))) {
70-
AdvancedPortal portal = Portal.getPortal(args[1]);
71-
72-
if(portal == null) {
73-
sender.sendMessage(PluginMessages.customPrefixFail
74-
+ " Could not find a portal with that name");
75-
}
76-
else {
77-
if (portal.inPortal.contains(player.getUniqueId()))
78-
return true;
79-
WarpEvent warpEvent = new WarpEvent(player, portal);
80-
plugin.getServer().getPluginManager().callEvent(warpEvent);
81-
82-
if (!warpEvent.isCancelled()) {
83-
Portal.activate(player, portal);
84-
}
85-
}
86-
} else if (args.length == 1 && player.hasPermission("advancedportals.portal.warp")) {
87-
sendMenu(player, "Help Menu: Warp",
88-
"\u00A76/" + command + " warp <name> \u00A7a- teleport to warp name");
89-
}
90-
else {
91-
sender.sendMessage(PluginMessages.customPrefixFail
92-
+ " You do not have permission");
93-
}
94-
break;
95102
case "disablebeacon":
96-
boolean DISABLE_BEACON = config.getConfig().getBoolean("DisableGatewayBeam", true);
97-
if (player.hasPermission("advancedportals.build") && DISABLE_BEACON) {
103+
if (player.hasPermission("advancedportals.build")) {
98104
if(args.length == 1) {
99105
sender.sendMessage(PluginMessages.customPrefixFail
100106
+ " You need to specify a portal to replace the blocks.");
@@ -113,16 +119,6 @@ public boolean onCommand(CommandSender sender, Command cmd, String command, Stri
113119
}
114120
}
115121
}
116-
else {
117-
if(DISABLE_BEACON) {
118-
119-
}
120-
else {
121-
122-
}
123-
sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission " +
124-
"to do that." + " Needed: \u00A7eadvancedportals.build");
125-
}
126122
break;
127123
case "wand":
128124
case "selector":
@@ -847,11 +843,14 @@ private void portalEditMenu(CommandSender sender, ConfigAccessor portalConfig, S
847843
@Override
848844
public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) {
849845
LinkedList<String> autoComplete = new LinkedList<String>();
846+
if(args.length == 1 && (sender.hasPermission("advancedportals.warp"))) {
847+
autoComplete.add("warp");
848+
}
850849
if (sender.hasPermission("advancedportals.createportal")) {
851850
if (args.length == 1 || (args.length == 2 && args[0].toLowerCase().equals("help"))) {
852851
autoComplete.addAll(Arrays.asList("create", "list", "portalblock", "select", "unselect", "command",
853852
"selector", "show", "gatewayblock", "endportalblock", "variables", "wand", "disablebeacon", "remove", "rename",
854-
"help", "bukkitpage", "helppage", "warp"));
853+
"help", "bukkitpage", "helppage"));
855854
} else if (args[0].toLowerCase().equals("create")) {
856855

857856
boolean hasName = false;
@@ -936,7 +935,9 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String comm
936935
if (args.length == 2 && (args[0].equalsIgnoreCase("warp"))) {
937936
for (AdvancedPortal portal : Portal.portals) {
938937
String perm = portal.getArg("permission");
939-
if (perm == null || sender.hasPermission(perm)) {
938+
if ((perm == null || sender.hasPermission(perm))
939+
&& (sender.hasPermission("advancedportals.warp.*")
940+
|| sender.hasPermission("advancedportals.warp." + portal.getName()))) {
940941
autoComplete.add(portal.getName());
941942
}
942943
}

src/main/java/com/sekwah/advancedportals/bukkit/portals/Portal.java

+15-6
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public static boolean activate(Player player, String portalName) {
405405
return false;
406406
}
407407

408-
public static boolean activate(Player player, AdvancedPortal portal) {
408+
public static boolean activate(Player player, AdvancedPortal portal, boolean doKnockback) {
409409

410410
if (blockSpectatorMode && player.getGameMode() == GameMode.SPECTATOR) {
411411
player.sendMessage(
@@ -419,7 +419,8 @@ public static boolean activate(Player player, AdvancedPortal portal) {
419419
player.sendMessage(
420420
PluginMessages.customPrefixFail + "\u00A7c You do not have permission to use this portal!");
421421
failSound(player, portal);
422-
throwPlayerBack(player);
422+
if(doKnockback)
423+
throwPlayerBack(player);
423424
return false;
424425
}
425426

@@ -430,7 +431,8 @@ public static boolean activate(Player player, AdvancedPortal portal) {
430431
int time = (joinCooldownDelay - diff);
431432
player.sendMessage(ChatColor.RED + "There is " + ChatColor.YELLOW + time + ChatColor.RED + (time == 1 ? " second" : " seconds") + " join cooldown protection left.");
432433
failSound(player, portal);
433-
throwPlayerBack(player);
434+
if(doKnockback)
435+
throwPlayerBack(player);
434436
return false;
435437
}
436438
joinCooldown.remove(player.getName());
@@ -451,7 +453,8 @@ public static boolean activate(Player player, AdvancedPortal portal) {
451453
player.sendMessage(ChatColor.RED + "Please wait " + ChatColor.YELLOW + time + ChatColor.RED
452454
+ (time == 1 ? " second" : " seconds") + " until attempting to enter this portal again.");
453455
failSound(player, portal);
454-
throwPlayerBack(player);
456+
if(doKnockback)
457+
throwPlayerBack(player);
455458
return false;
456459
}
457460
}
@@ -509,7 +512,8 @@ public static boolean activate(Player player, AdvancedPortal portal) {
509512
if (configDesti.getConfig().getString(portal.getDestiation() + ".world") != null) {
510513
warped = Destination.warp(player, portal.getDestiation(), hasMessage);
511514
if (!warped) {
512-
throwPlayerBack(player);
515+
if(doKnockback)
516+
throwPlayerBack(player);
513517
}
514518
}
515519
} else {
@@ -518,7 +522,8 @@ public static boolean activate(Player player, AdvancedPortal portal) {
518522
+ "\u00A7c The portal you are trying to use doesn't have a destination!");
519523
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.getName() + "' has just had a warp "
520524
+ "attempt and either the data is corrupt or portal doesn't exist!");
521-
throwPlayerBack(player);
525+
if(doKnockback)
526+
throwPlayerBack(player);
522527
failSound(player, portal);
523528
}
524529
}
@@ -692,4 +697,8 @@ public static void throwPlayerBack(Player player) {
692697
public static int getPortalProtectionRadius() {
693698
return portalProtectionRadius;
694699
}
700+
701+
public static boolean activate(Player player, AdvancedPortal portal) {
702+
return activate(player, portal, true);
703+
}
695704
}

src/main/resources/plugin.yml

+54-51
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,58 @@ author: sekwah41
55
description: An advanced portals plugin for bukkit.
66
api-version: 1.13
77
commands:
8-
advancedportals:
9-
description: The main command for the advanced portals
10-
aliases: [portals, aportals, portal, ap]
11-
usage: /<command>
12-
destination:
13-
description: Can be used to access portal destinations.
14-
aliases: [desti]
15-
usage: /<command>
8+
advancedportals:
9+
description: The main command for the advanced portals
10+
aliases: [portals, aportals, portal, ap]
11+
usage: /<command>
12+
destination:
13+
description: Can be used to access portal destinations.
14+
aliases: [desti]
15+
usage: /<command>
1616
permissions:
17-
advancedportals.*:
18-
description: Gives access to all commands
19-
default: op
20-
children:
21-
advancedportals.createportal: true
22-
advancedportals.portal: true
23-
advancedportals.build: true
24-
advancedportals.desti: true
25-
advancedportals.createportal:
26-
description: Allows you to create portals
27-
default: op
28-
advancedportals.createportal.commandlevel.*:
29-
description: Gives access to all level raisers
30-
default: false
31-
children:
32-
advancedportals.createportal.commandlevel.op: true
33-
advancedportals.createportal.commandlevel.bungee: true
34-
advancedportals.createportal.commandlevel.perms: true
35-
advancedportals.createportal.commandlevel.console: true
36-
advancedportals.createportal.commandlevel.op:
37-
description: Allows you to run portal commands as op
38-
default: false
39-
advancedportals.createportal.commandlevel.perms:
40-
description: Allows you to run portal commands with * permission
41-
default: false
42-
advancedportals.createportal.commandlevel.bungee:
43-
description: Allows you to run portal commands through bungee
44-
default: false
45-
advancedportals.createportal.commandlevel.console:
46-
description: Executes command in the console
47-
default: false
48-
advancedportals.portal:
49-
description: Allows use of portal commands
50-
default: op
51-
advancedportals.build:
52-
description: Allows you to build in the portal regions
53-
default: op
54-
advancedportals.desti:
55-
description: Gives access to all desti commands
56-
default: op
57-
advancedportals.warp.*:
58-
description: Access to all warps
59-
default: op
17+
advancedportals.*:
18+
description: Gives access to all commands
19+
default: op
20+
children:
21+
advancedportals.createportal: true
22+
advancedportals.portal: true
23+
advancedportals.build: true
24+
advancedportals.desti: true
25+
advancedportals.createportal:
26+
description: Allows you to create portals
27+
default: op
28+
advancedportals.createportal.commandlevel.*:
29+
description: Gives access to all level raisers
30+
default: false
31+
children:
32+
advancedportals.createportal.commandlevel.op: true
33+
advancedportals.createportal.commandlevel.bungee: true
34+
advancedportals.createportal.commandlevel.perms: true
35+
advancedportals.createportal.commandlevel.console: true
36+
advancedportals.createportal.commandlevel.op:
37+
description: Allows you to run portal commands as op
38+
default: false
39+
advancedportals.createportal.commandlevel.perms:
40+
description: Allows you to run portal commands with * permission
41+
default: false
42+
advancedportals.createportal.commandlevel.bungee:
43+
description: Allows you to run portal commands through bungee
44+
default: false
45+
advancedportals.createportal.commandlevel.console:
46+
description: Executes command in the console
47+
default: false
48+
advancedportals.portal:
49+
description: Allows use of portal commands
50+
default: op
51+
advancedportals.build:
52+
description: Allows you to build in the portal regions
53+
default: op
54+
advancedportals.desti:
55+
description: Gives access to all desti commands
56+
default: op
57+
advancedportals.warp:
58+
description: Access to the warp command
59+
default: op
60+
advancedportals.warp.*:
61+
description: Access to all warps
62+
default: op

0 commit comments

Comments
 (0)