Implemented optional specification of teleport causes

This should have backwards-compatibility for any users of the API but would require an update from anything reimplementing (for whatever reason) the interfaces amended by this commit.
This commit is contained in:
zombachu
2020-01-02 18:29:12 -10:00
parent 0f39df0e0b
commit 3aa554c52b
18 changed files with 81 additions and 28 deletions

View File

@ -1,11 +1,14 @@
package com.github.intellectualsites.plotsquared.bukkit.object;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitEventUtil;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.TeleportCause;
import com.github.intellectualsites.plotsquared.plot.util.EconHandler;
import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.PlotWeather;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
@ -193,13 +196,13 @@ public class BukkitPlayer extends PlotPlayer {
}
}
@Override public void teleport(@NotNull final Location location) {
@Override public void teleport(@NotNull final Location location, @NotNull final TeleportCause cause) {
if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) {
return;
}
final org.bukkit.Location bukkitLocation = new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5,
location.getY(), location.getZ() + 0.5, location.getYaw(), location.getPitch());
PaperLib.teleportAsync(player, bukkitLocation, PlayerTeleportEvent.TeleportCause.COMMAND);
PaperLib.teleportAsync(player, bukkitLocation, ((BukkitEventUtil) EventUtil.manager).getTeleportCause(cause));
}
@Override public String getName() {

View File

@ -25,11 +25,13 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.Rating;
import com.github.intellectualsites.plotsquared.plot.object.TeleportCause;
import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -130,4 +132,14 @@ public final class BukkitEventUtil extends EventUtil {
}
return event.getRating();
}
public PlayerTeleportEvent.TeleportCause getTeleportCause(@NotNull final TeleportCause cause) {
switch (cause) {
case COMMAND:
return PlayerTeleportEvent.TeleportCause.COMMAND;
case PLUGIN:
return PlayerTeleportEvent.TeleportCause.PLUGIN;
default: return PlayerTeleportEvent.TeleportCause.UNKNOWN;
}
}
}