Search in sources :

Example 1 with PlotWeather

use of com.plotsquared.core.plot.PlotWeather in project PlotSquared by IntellectualSites.

the class PlotListener method plotExit.

public boolean plotExit(final PlotPlayer<?> player, Plot plot) {
    try (final MetaDataAccess<Plot> lastPlot = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
        final Plot previous = lastPlot.remove();
        this.eventDispatcher.callLeave(player, plot);
        if (plot.hasOwner()) {
            PlotArea pw = plot.getArea();
            if (pw == null) {
                return true;
            }
            try (final MetaDataAccess<Boolean> kickAccess = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
                if (plot.getFlag(DenyExitFlag.class) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_EXIT_DENIED) && !kickAccess.get().orElse(false)) {
                    if (previous != null) {
                        lastPlot.set(previous);
                    }
                    return false;
                }
            }
            if (!plot.getFlag(GamemodeFlag.class).equals(GamemodeFlag.DEFAULT) || !plot.getFlag(GuestGamemodeFlag.class).equals(GamemodeFlag.DEFAULT)) {
                if (player.getGameMode() != pw.getGameMode()) {
                    if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) {
                        player.setGameMode(pw.getGameMode());
                    } else {
                        player.sendMessage(TranslatableCaption.of("gamemode.gamemode_was_bypassed"), Template.of("gamemode", pw.getGameMode().getName().toLowerCase()), Template.of("plot", plot.toString()));
                    }
                }
            }
            String farewell = plot.getFlag(FarewellFlag.class);
            if (!farewell.isEmpty()) {
                if (!Settings.Chat.NOTIFICATION_AS_ACTIONBAR) {
                    plot.format(StaticCaption.of(farewell), player, false).thenAcceptAsync(player::sendMessage);
                } else {
                    plot.format(StaticCaption.of(farewell), player, false).thenAcceptAsync(player::sendActionBar);
                }
            }
            if (plot.getFlag(NotifyLeaveFlag.class)) {
                if (!Permissions.hasPermission(player, "plots.flag.notify-leave.bypass")) {
                    for (UUID uuid : plot.getOwners()) {
                        final PlotPlayer<?> owner = PlotSquared.platform().playerManager().getPlayerIfExists(uuid);
                        if ((owner != null) && !owner.getUUID().equals(player.getUUID()) && owner.canSee(player)) {
                            Caption caption = TranslatableCaption.of("notification.notify_leave");
                            notifyPlotOwner(player, plot, owner, caption);
                        }
                    }
                }
            }
            final FlyFlag.FlyStatus flyStatus = plot.getFlag(FlyFlag.class);
            if (flyStatus != FlyFlag.FlyStatus.DEFAULT) {
                try (final MetaDataAccess<Boolean> metaDataAccess = player.accessPersistentMetaData(PlayerMetaDataKeys.PERSISTENT_FLIGHT)) {
                    final Optional<Boolean> value = metaDataAccess.get();
                    if (value.isPresent()) {
                        player.setFlight(value.get());
                        metaDataAccess.remove();
                    } else {
                        GameMode gameMode = player.getGameMode();
                        if (gameMode == GameModes.SURVIVAL || gameMode == GameModes.ADVENTURE) {
                            player.setFlight(false);
                        } else if (!player.getFlight()) {
                            player.setFlight(true);
                        }
                    }
                }
            }
            if (plot.getFlag(TimeFlag.class) != TimeFlag.TIME_DISABLED.getValue().longValue()) {
                player.setTime(Long.MAX_VALUE);
            }
            final PlotWeather plotWeather = plot.getFlag(WeatherFlag.class);
            if (plotWeather != PlotWeather.OFF) {
                player.setWeather(PlotWeather.WORLD);
            }
            try (final MetaDataAccess<Location> musicAccess = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_MUSIC)) {
                musicAccess.get().ifPresent(lastLoc -> {
                    musicAccess.remove();
                    player.playMusic(lastLoc, ItemTypes.AIR);
                });
            }
            feedRunnable.remove(player.getUUID());
            healRunnable.remove(player.getUUID());
        }
    }
    return true;
}
Also used : PlotArea(com.plotsquared.core.plot.PlotArea) Plot(com.plotsquared.core.plot.Plot) GuestGamemodeFlag(com.plotsquared.core.plot.flag.implementations.GuestGamemodeFlag) StaticCaption(com.plotsquared.core.configuration.caption.StaticCaption) Caption(com.plotsquared.core.configuration.caption.Caption) TranslatableCaption(com.plotsquared.core.configuration.caption.TranslatableCaption) GameMode(com.sk89q.worldedit.world.gamemode.GameMode) FlyFlag(com.plotsquared.core.plot.flag.implementations.FlyFlag) TimeFlag(com.plotsquared.core.plot.flag.implementations.TimeFlag) GamemodeFlag(com.plotsquared.core.plot.flag.implementations.GamemodeFlag) GuestGamemodeFlag(com.plotsquared.core.plot.flag.implementations.GuestGamemodeFlag) UUID(java.util.UUID) PlotWeather(com.plotsquared.core.plot.PlotWeather) Location(com.plotsquared.core.location.Location)

Aggregations

Caption (com.plotsquared.core.configuration.caption.Caption)1 StaticCaption (com.plotsquared.core.configuration.caption.StaticCaption)1 TranslatableCaption (com.plotsquared.core.configuration.caption.TranslatableCaption)1 Location (com.plotsquared.core.location.Location)1 Plot (com.plotsquared.core.plot.Plot)1 PlotArea (com.plotsquared.core.plot.PlotArea)1 PlotWeather (com.plotsquared.core.plot.PlotWeather)1 FlyFlag (com.plotsquared.core.plot.flag.implementations.FlyFlag)1 GamemodeFlag (com.plotsquared.core.plot.flag.implementations.GamemodeFlag)1 GuestGamemodeFlag (com.plotsquared.core.plot.flag.implementations.GuestGamemodeFlag)1 TimeFlag (com.plotsquared.core.plot.flag.implementations.TimeFlag)1 GameMode (com.sk89q.worldedit.world.gamemode.GameMode)1 UUID (java.util.UUID)1