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;
}
Aggregations