mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Add DestinationFactory#getPlayerAwareDestination to parse cannon dest.
This commit is contained in:
parent
fee822a2fe
commit
81f6014e94
@ -102,8 +102,7 @@ public class TeleportCommand extends MultiverseCommand {
|
||||
@NotNull Player teleportee,
|
||||
@NotNull String destinationName) {
|
||||
|
||||
destinationName = parseCannonDestination(teleportee, destinationName);
|
||||
MVDestination destination = this.plugin.getDestFactory().getDestination(destinationName);
|
||||
MVDestination destination = this.plugin.getDestFactory().getPlayerAwareDestination(destinationName, teleportee);
|
||||
|
||||
MVTeleportEvent teleportEvent = new MVTeleportEvent(destination, teleportee, teleporter, true);
|
||||
this.plugin.getServer().getPluginManager().callEvent(teleportEvent);
|
||||
@ -165,28 +164,6 @@ public class TeleportCommand extends MultiverseCommand {
|
||||
// else: Player was teleported successfully (or the tp event was fired I should say)
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String parseCannonDestination(@NotNull Player teleportee,
|
||||
@NotNull String destinationName) {
|
||||
|
||||
if (!destinationName.matches("(?i)cannon-[\\d]+(\\.[\\d]+)?")) {
|
||||
return destinationName;
|
||||
}
|
||||
|
||||
String[] cannonSpeed = destinationName.split("-");
|
||||
try {
|
||||
double speed = Double.parseDouble(cannonSpeed[1]);
|
||||
destinationName = "ca:" + teleportee.getWorld().getName() + ":" + teleportee.getLocation().getX()
|
||||
+ "," + teleportee.getLocation().getY() + "," + teleportee.getLocation().getZ() + ":"
|
||||
+ teleportee.getLocation().getPitch() + ":" + teleportee.getLocation().getYaw() + ":" + speed;
|
||||
}
|
||||
catch (Exception e) {
|
||||
destinationName = "i:invalid";
|
||||
}
|
||||
|
||||
return destinationName;
|
||||
}
|
||||
|
||||
private boolean checkSendPermissions(@NotNull CommandSender teleporter,
|
||||
@NotNull Player teleportee,
|
||||
@NotNull MVDestination destination) {
|
||||
|
@ -11,8 +11,10 @@ import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.utils.PermissionTools;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@ -34,6 +36,31 @@ public class DestinationFactory {
|
||||
this.permTools = new PermissionTools(plugin);
|
||||
}
|
||||
|
||||
public MVDestination getPlayerAwareDestination(String destination, Player player) {
|
||||
return getDestination(parseCannonDest(player, destination));
|
||||
}
|
||||
|
||||
private String parseCannonDest(@NotNull Player teleportee,
|
||||
@NotNull String destinationName) {
|
||||
|
||||
if (!destinationName.matches("(?i)cannon-[\\d]+(\\.[\\d]+)?")) {
|
||||
return destinationName;
|
||||
}
|
||||
|
||||
String[] cannonSpeed = destinationName.split("-");
|
||||
try {
|
||||
double speed = Double.parseDouble(cannonSpeed[1]);
|
||||
destinationName = "ca:" + teleportee.getWorld().getName() + ":" + teleportee.getLocation().getX()
|
||||
+ "," + teleportee.getLocation().getY() + "," + teleportee.getLocation().getZ() + ":"
|
||||
+ teleportee.getLocation().getPitch() + ":" + teleportee.getLocation().getYaw() + ":" + speed;
|
||||
}
|
||||
catch (Exception e) {
|
||||
destinationName = "i:invalid";
|
||||
}
|
||||
|
||||
return destinationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new destination from a string.
|
||||
* Returns a new InvalidDestination if the string could not be parsed.
|
||||
|
Loading…
Reference in New Issue
Block a user