Skip to content

Commit

Permalink
feat: Add destination teleport subcommand (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
TreemanKing authored and sekwah41 committed Nov 18, 2024
1 parent d23a3e6 commit af5018d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private void registerDestinationCommand(CommandRegister commandRegister) {
this.destiCommand = new CommandWithSubCommands(this);
this.destiCommand.registerSubCommand("create", new CreateDestiSubCommand());
this.destiCommand.registerSubCommand("remove", new RemoveDestiSubCommand());
this.destiCommand.registerSubCommand("teleport", new TeleportDestiSubCommand(), "tp");
this.destiCommand.registerSubCommand("list", new ListDestiSubCommand());
this.destiCommand.registerSubCommand("show", new ShowDestiSubCommand());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {

@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender);
return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
}
}
else {
sender.sendMessage(Lang.translate("command.portal.remove.noname"));
sender.sendMessage(Lang.translate("command.destination.noname"));
}
}

@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender);
return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.sekwah.advancedportals.core.commands.subcommands.desti;

import com.google.inject.Inject;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
import com.sekwah.advancedportals.core.services.DestinationServices;
import com.sekwah.advancedportals.core.util.Lang;

import java.util.Collections;
import java.util.List;

public class TeleportDestiSubCommand implements SubCommand {

@Inject
DestinationServices destinationServices;
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
if(destinationServices.teleportToDestination(args[1], sender.getPlayerContainer())) {
sender.sendMessage(Lang.translate("messageprefix.positive")
+ Lang.translate("command.destination.teleport.success")
.replaceAll("@destiname", args[1]));
} else {
sender.sendMessage(Lang.translate("messageprefix.negative") +
Lang.translate("command.destination.teleport.error")
.replaceAll("@destiname", args[1]));
}
} else {
sender.sendMessage(Lang.translate("command.destination.noname"));
}
}

@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender);
}

@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
if(args.length > 2) {
return Collections.emptyList();
}
List<String> destiNames = destinationServices.getDestinationNames();
Collections.sort(destiNames);
return destiNames;
}

@Override
public String getBasicHelpText() {
return Lang.translate("command.destination.teleport.help");
}

@Override
public String getDetailedHelpText() {
return Lang.translate("command.destination.teleport.detailedhelp");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class PortalPermissions {
private static final PermissionBuilder PERMISSIONS = new PermissionBuilder("advancedportals");

public static final PermissionBuilder BUILD = PERMISSIONS.createChild("build");
public static final PermissionBuilder DESTI = PERMISSIONS.createChild("desti");
public static final PermissionBuilder CREATE_PORTAL = PERMISSIONS.createChild("createportal");
public static final PermissionBuilder LANG_UPDATE = PERMISSIONS.createChild("langupdate");
public static final PermissionBuilder RELOAD = PERMISSIONS.createChild("reload");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,12 @@ public boolean removeDestination(String name, PlayerContainer playerContainer) {
public Destination getDestination(String name) {
return destinationCache.get(name);
}

public boolean teleportToDestination(String name, PlayerContainer playerContainer) {
if(this.destinationRepository.containsKey(name)) {
playerContainer.teleport(this.destinationRepository.get(name).getLoc());
return true;
}
return false;
}
}
7 changes: 7 additions & 0 deletions lang/src/main/resources/lang/en_GB.lang
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ command.portal.show.enabled= Portal markers are now enabled.
command.portal.show.disabled= Portal markers are now disabled.
command.portal.show.unsupported= Portal markers are not supported on this version of minecraft. (1.16+ atm only)

command.destination.noname=No destination by that name was found

command.destination.remove.error= There was a problem removing the destination.
command.destination.remove.complete= The destination has been successfully removed.

Expand All @@ -98,6 +100,11 @@ command.destination.show.enabled= Destination markers are now enabled.
command.destination.show.disabled= Destination markers are now disabled.
command.destination.show.unsupported= Destination markers are not supported on this version of minecraft. (1.16+ atm only)

command.destination.teleport.help=Teleports to specified destination.
command.destination.teleport.detailedhelp=Teleports to destination given by the name of the destination.
command.destination.teleport.error=There was an error teleporting to your destination (@destiname).
command.destination.teleport.success=You have teleported to destination (@destiname).

command.destination.reload.help=Reloads the destination data from the repository.
command.destination.reload.detailedhelp=This command will reload all destination data from the repository, updating the cache with the latest data.
command.destination.reload= Destinations reloaded.
Expand Down

0 comments on commit af5018d

Please sign in to comment.