mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-22 02:25:49 +01:00
feat: Add destination teleport subcommand (#420)
This commit is contained in:
parent
e13f1d54b3
commit
7c7dc98edd
@ -151,6 +151,7 @@ public class AdvancedPortalsCore {
|
||||
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());
|
||||
|
||||
|
@ -74,7 +74,7 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSenderContainer sender) {
|
||||
return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender);
|
||||
return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,13 +28,13 @@ public class RemoveDestiSubCommand implements SubCommand {
|
||||
}
|
||||
}
|
||||
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
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
@ -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");
|
||||
|
@ -107,4 +107,12 @@ public class DestinationServices {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user