Search in sources :

Example 1 with TeleportCause

use of com.plotsquared.core.events.TeleportCause in project PlotSquared by IntellectualSites.

the class Plot method teleportPlayer.

/**
 * Teleport a player to a plot and send them the teleport message.
 *
 * @param player         the player
 * @param cause          the cause of the teleport
 * @param resultConsumer Called with the result of the teleportation
 */
public void teleportPlayer(final PlotPlayer<?> player, TeleportCause cause, Consumer<Boolean> resultConsumer) {
    Plot plot = this.getBasePlot(false);
    Result result = this.eventDispatcher.callTeleport(player, player.getLocation(), plot, cause).getEventResult();
    if (result == Result.DENY) {
        player.sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Teleport"));
        resultConsumer.accept(false);
        return;
    }
    final Consumer<Location> locationConsumer = location -> {
        if (Settings.Teleport.DELAY == 0 || Permissions.hasPermission(player, "plots.teleport.delay.bypass")) {
            player.sendMessage(TranslatableCaption.of("teleport.teleported_to_plot"));
            player.teleport(location, cause);
            resultConsumer.accept(true);
            return;
        }
        player.sendMessage(TranslatableCaption.of("teleport.teleport_in_seconds"), Template.of("amount", String.valueOf(Settings.Teleport.DELAY)));
        final String name = player.getName();
        TaskManager.addToTeleportQueue(name);
        TaskManager.runTaskLater(() -> {
            if (!TaskManager.removeFromTeleportQueue(name)) {
                return;
            }
            try {
                player.sendMessage(TranslatableCaption.of("teleport.teleported_to_plot"));
                player.teleport(location, cause);
            } catch (final Exception ignored) {
            }
        }, TaskTime.seconds(Settings.Teleport.DELAY));
        resultConsumer.accept(true);
    };
    if (this.area.isHomeAllowNonmember() || plot.isAdded(player.getUUID())) {
        this.getHome(locationConsumer);
    } else {
        this.getDefaultHome(false, locationConsumer);
    }
}
Also used : TeleportCause(com.plotsquared.core.events.TeleportCause) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Inject(com.google.inject.Inject) Like(com.plotsquared.core.command.Like) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Permission(com.plotsquared.core.permissions.Permission) StaticCaption(com.plotsquared.core.configuration.caption.StaticCaption) BlockLoc(com.plotsquared.core.location.BlockLoc) Schematic(com.plotsquared.core.plot.schematic.Schematic) Map(java.util.Map) PlotListener(com.plotsquared.core.listener.PlotListener) FlagContainer(com.plotsquared.core.plot.flag.FlagContainer) DescriptionFlag(com.plotsquared.core.plot.flag.implementations.DescriptionFlag) Template(net.kyori.adventure.text.minimessage.Template) EventDispatcher(com.plotsquared.core.util.EventDispatcher) Caption(com.plotsquared.core.configuration.caption.Caption) DBFunc(com.plotsquared.core.database.DBFunc) RegionManager(com.plotsquared.core.util.RegionManager) WorldUtil(com.plotsquared.core.util.WorldUtil) TextComponent(net.kyori.adventure.text.TextComponent) ImmutableSet(com.google.common.collect.ImmutableSet) RunnableVal(com.plotsquared.core.util.task.RunnableVal) TimeZone(java.util.TimeZone) ServerPlotFlag(com.plotsquared.core.plot.flag.implementations.ServerPlotFlag) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MiniMessage(net.kyori.adventure.text.minimessage.MiniMessage) Set(java.util.Set) UUID(java.util.UUID) CAP_MONSTER(com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER) Sets(com.google.common.collect.Sets) Result(com.plotsquared.core.events.Result) Objects(java.util.Objects) List(java.util.List) Logger(org.apache.logging.log4j.Logger) CAP_MOB(com.plotsquared.core.util.entity.EntityCategories.CAP_MOB) TranslatableCaption(com.plotsquared.core.configuration.caption.TranslatableCaption) Entry(java.util.Map.Entry) InternalFlag(com.plotsquared.core.plot.flag.InternalFlag) TaskTime(com.plotsquared.core.util.task.TaskTime) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) CAP_VEHICLE(com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE) NonNull(org.checkerframework.checker.nullness.qual.NonNull) CAP_ENTITY(com.plotsquared.core.util.entity.EntityCategories.CAP_ENTITY) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CaptionUtility(com.plotsquared.core.configuration.caption.CaptionUtility) ClassicPlotWorld(com.plotsquared.core.generator.ClassicPlotWorld) PlotFlag(com.plotsquared.core.plot.flag.PlotFlag) Direction(com.plotsquared.core.location.Direction) PlotQuery(com.plotsquared.core.util.query.PlotQuery) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) SinglePlotArea(com.plotsquared.core.plot.world.SinglePlotArea) SchematicHandler(com.plotsquared.core.util.SchematicHandler) Component(net.kyori.adventure.text.Component) ConsolePlayer(com.plotsquared.core.player.ConsolePlayer) ExpireManager(com.plotsquared.core.plot.expiration.ExpireManager) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Location(com.plotsquared.core.location.Location) GlobalFlagContainer(com.plotsquared.core.plot.flag.GlobalFlagContainer) RegionUtil(com.plotsquared.core.util.RegionUtil) KeepFlag(com.plotsquared.core.plot.flag.implementations.KeepFlag) Permissions(com.plotsquared.core.util.Permissions) MathMan(com.plotsquared.core.util.MathMan) TaskManager(com.plotsquared.core.util.task.TaskManager) Cleaner(java.lang.ref.Cleaner) DecimalFormat(java.text.DecimalFormat) DoubleFlag(com.plotsquared.core.plot.flag.types.DoubleFlag) TimeUtil(com.plotsquared.core.util.TimeUtil) CAP_MISC(com.plotsquared.core.util.entity.EntityCategories.CAP_MISC) Consumer(java.util.function.Consumer) PlotAnalysis(com.plotsquared.core.plot.expiration.PlotAnalysis) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) PlotSquared(com.plotsquared.core.PlotSquared) PlayerManager(com.plotsquared.core.util.PlayerManager) PlotPlayer(com.plotsquared.core.player.PlotPlayer) CAP_ANIMAL(com.plotsquared.core.util.entity.EntityCategories.CAP_ANIMAL) Settings(com.plotsquared.core.configuration.Settings) ArrayDeque(java.util.ArrayDeque) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) Result(com.plotsquared.core.events.Result) Location(com.plotsquared.core.location.Location)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Inject (com.google.inject.Inject)1 PlotSquared (com.plotsquared.core.PlotSquared)1 Like (com.plotsquared.core.command.Like)1 Settings (com.plotsquared.core.configuration.Settings)1 Caption (com.plotsquared.core.configuration.caption.Caption)1 CaptionUtility (com.plotsquared.core.configuration.caption.CaptionUtility)1 StaticCaption (com.plotsquared.core.configuration.caption.StaticCaption)1 TranslatableCaption (com.plotsquared.core.configuration.caption.TranslatableCaption)1 DBFunc (com.plotsquared.core.database.DBFunc)1 Result (com.plotsquared.core.events.Result)1 TeleportCause (com.plotsquared.core.events.TeleportCause)1 ClassicPlotWorld (com.plotsquared.core.generator.ClassicPlotWorld)1 PlotListener (com.plotsquared.core.listener.PlotListener)1 BlockLoc (com.plotsquared.core.location.BlockLoc)1 Direction (com.plotsquared.core.location.Direction)1 Location (com.plotsquared.core.location.Location)1 Permission (com.plotsquared.core.permissions.Permission)1