Skip to content

Commit 8ebb703

Browse files
committed
Feat: Add destination teleport subcommand
1 parent ae33016 commit 8ebb703

File tree

7 files changed

+78
-3
lines changed

7 files changed

+78
-3
lines changed

core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ private void registerDestinationCommand(CommandRegister commandRegister) {
151151
this.destiCommand = new CommandWithSubCommands(this);
152152
this.destiCommand.registerSubCommand("create", new CreateDestiSubCommand());
153153
this.destiCommand.registerSubCommand("remove", new RemoveDestiSubCommand());
154+
this.destiCommand.registerSubCommand("teleport", new TeleportDestiSubCommand());
154155
this.destiCommand.registerSubCommand("list", new ListDestiSubCommand());
155156
this.destiCommand.registerSubCommand("show", new ShowDestiSubCommand());
156157

core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
7474

7575
@Override
7676
public boolean hasPermission(CommandSenderContainer sender) {
77-
return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender);
77+
return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender);
7878
}
7979

8080
@Override

core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/RemoveDestiSubCommand.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
2828
}
2929
}
3030
else {
31-
sender.sendMessage(Lang.translate("command.portal.remove.noname"));
31+
sender.sendMessage(Lang.translate("command.destination.noname"));
3232
}
3333
}
3434

3535
@Override
3636
public boolean hasPermission(CommandSenderContainer sender) {
37-
return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender);
37+
return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender);
3838
}
3939

4040
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.sekwah.advancedportals.core.commands.subcommands.desti;
2+
3+
import com.google.inject.Inject;
4+
import com.sekwah.advancedportals.core.commands.SubCommand;
5+
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
6+
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
7+
import com.sekwah.advancedportals.core.services.DestinationServices;
8+
import com.sekwah.advancedportals.core.util.Lang;
9+
10+
import java.util.Collections;
11+
import java.util.List;
12+
13+
public class TeleportDestiSubCommand implements SubCommand {
14+
15+
@Inject
16+
DestinationServices destinationServices;
17+
@Override
18+
public void onCommand(CommandSenderContainer sender, String[] args) {
19+
if(args.length > 1) {
20+
if(destinationServices.teleportToDestination(args[1], sender.getPlayerContainer())) {
21+
sender.sendMessage(Lang.translate("messageprefix.positive")
22+
+ Lang.translate("command.destination.teleport.success")
23+
.replaceAll("@destiname", args[1]));
24+
} else {
25+
sender.sendMessage(Lang.translate("messageprefix.negative") +
26+
Lang.translate("command.destination.teleport.error")
27+
.replaceAll("@destiname", args[1]));
28+
}
29+
} else {
30+
sender.sendMessage(Lang.translate("command.destination.noname"));
31+
}
32+
}
33+
34+
@Override
35+
public boolean hasPermission(CommandSenderContainer sender) {
36+
return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender);
37+
}
38+
39+
@Override
40+
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
41+
if(args.length > 2) {
42+
return Collections.emptyList();
43+
}
44+
List<String> destiNames = destinationServices.getDestinationNames();
45+
Collections.sort(destiNames);
46+
return destiNames;
47+
}
48+
49+
@Override
50+
public String getBasicHelpText() {
51+
return Lang.translate("command.destination.teleport.help");
52+
}
53+
54+
@Override
55+
public String getDetailedHelpText() {
56+
return Lang.translate("command.destination.teleport.detailedhelp");
57+
}
58+
}

core/src/main/java/com/sekwah/advancedportals/core/permissions/PortalPermissions.java

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class PortalPermissions {
1010
private static final PermissionBuilder PERMISSIONS = new PermissionBuilder("advancedportals");
1111

1212
public static final PermissionBuilder BUILD = PERMISSIONS.createChild("build");
13+
public static final PermissionBuilder DESTI = PERMISSIONS.createChild("desti");
1314
public static final PermissionBuilder CREATE_PORTAL = PERMISSIONS.createChild("createportal");
1415
public static final PermissionBuilder LANG_UPDATE = PERMISSIONS.createChild("langupdate");
1516
public static final PermissionBuilder RELOAD = PERMISSIONS.createChild("reload");

core/src/main/java/com/sekwah/advancedportals/core/services/DestinationServices.java

+8
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,12 @@ public boolean removeDestination(String name, PlayerContainer playerContainer) {
107107
public Destination getDestination(String name) {
108108
return destinationCache.get(name);
109109
}
110+
111+
public boolean teleportToDestination(String name, PlayerContainer playerContainer) {
112+
if(this.destinationRepository.containsKey(name)) {
113+
playerContainer.teleport(this.destinationRepository.get(name).getLoc());
114+
return true;
115+
}
116+
return false;
117+
}
110118
}

lang/src/main/resources/lang/en_GB.lang

+7
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ command.portal.show.enabled= Portal markers are now enabled.
8686
command.portal.show.disabled= Portal markers are now disabled.
8787
command.portal.show.unsupported= Portal markers are not supported on this version of minecraft. (1.16+ atm only)
8888

89+
command.destination.noname=No destination by that name was found
90+
8991
command.destination.remove.error= There was a problem removing the destination.
9092
command.destination.remove.complete= The destination has been successfully removed.
9193

@@ -95,6 +97,11 @@ command.destination.show.enabled= Destination markers are now enabled.
9597
command.destination.show.disabled= Destination markers are now disabled.
9698
command.destination.show.unsupported= Destination markers are not supported on this version of minecraft. (1.16+ atm only)
9799

100+
command.destination.teleport.help=Teleports to specified destination.
101+
command.destination.teleport.detailedhelp=Teleports to destination given by the name of the destination.
102+
command.destination.teleport.error=There was an error teleporting to your destination (@destiname).
103+
command.destination.teleport.success=You have teleported to destination (@destiname).
104+
98105
command.destination.reload.help=Reloads the destination data from the repository.
99106
command.destination.reload.detailedhelp=This command will reload all destination data from the repository, updating the cache with the latest data.
100107
command.destination.reload= Destinations reloaded.

0 commit comments

Comments
 (0)