Skip to content

Commit 5506c3b

Browse files
committed
fix: kick player from plot if denied on join
Signed-off-by: Florian Reuth <git@florianreuth.de>
1 parent b573ef8 commit 5506c3b

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.plotsquared.core.configuration.Settings;
3030
import com.plotsquared.core.configuration.caption.Caption;
3131
import com.plotsquared.core.configuration.caption.TranslatableCaption;
32+
import com.plotsquared.core.events.TeleportCause;
3233
import com.plotsquared.core.listener.PlayerBlockEventType;
3334
import com.plotsquared.core.listener.PlotListener;
3435
import com.plotsquared.core.location.Location;
@@ -543,7 +544,7 @@ public void onConnect(PlayerJoinEvent event) {
543544
if (area != null) {
544545
Plot plot = area.getPlot(location);
545546
if (plot != null) {
546-
plotListener.plotEntry(pp, plot);
547+
this.enforceJoinEntry(pp, player, plot);
547548
}
548549
}
549550
// Delayed
@@ -575,6 +576,24 @@ public void onConnect(PlayerJoinEvent event) {
575576
}
576577
}
577578

579+
private void enforceJoinEntry(final PlotPlayer<Player> player, final Player bukkitPlayer, final Plot plot) {
580+
if (!this.plotListener.plotEntry(player, plot)) {
581+
Location spawn = PlotSquared.platform().worldUtil().getSpawn(plot.getWorldName());
582+
if (!plot.equals(spawn.getPlot())) {
583+
player.teleport(spawn, TeleportCause.DENIED);
584+
return;
585+
}
586+
587+
Location fallbackSpawn = PlotSquared.platform().worldUtil().getSpawn(this.plotAreaManager.getAllWorlds()[0]);
588+
if (plot.equals(fallbackSpawn.getPlot())) {
589+
player.kick(
590+
"You got kicked from the plot! This server did not set up a loaded spawn, so you got kicked from the server.");
591+
} else {
592+
player.teleport(fallbackSpawn, TeleportCause.DENIED);
593+
}
594+
}
595+
}
596+
578597
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
579598
public void playerRespawn(PlayerRespawnEvent event) {
580599
Player player = event.getPlayer();
@@ -754,8 +773,10 @@ public void playerMove(PlayerMoveEvent event) {
754773
if (now == null) {
755774
try (final MetaDataAccess<Boolean> kickAccess =
756775
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
757-
if (lastPlot != null && !plotListener.plotExit(pp, lastPlot, now, area) && this.tmpTeleport && !kickAccess.get().orElse(
758-
false)) {
776+
if (lastPlot != null && !plotListener.plotExit(pp, lastPlot, now, area) && this.tmpTeleport && !kickAccess
777+
.get()
778+
.orElse(
779+
false)) {
759780
pp.sendMessage(
760781
TranslatableCaption.of("permission.no_permission_event"),
761782
TagResolver.resolver(
@@ -848,8 +869,10 @@ public void playerMove(PlayerMoveEvent event) {
848869
if (plot == null) {
849870
try (final MetaDataAccess<Boolean> kickAccess =
850871
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
851-
if (lastPlot != null && !plotListener.plotExit(pp, lastPlot, null, area) && this.tmpTeleport && !kickAccess.get().orElse(
852-
false)) {
872+
if (lastPlot != null && !plotListener.plotExit(pp, lastPlot, null, area) && this.tmpTeleport && !kickAccess
873+
.get()
874+
.orElse(
875+
false)) {
853876
pp.sendMessage(
854877
TranslatableCaption.of("permission.no_permission_event"),
855878
TagResolver.resolver(

0 commit comments

Comments
 (0)