Skip to content

Commit

Permalink
misc: Handle teleport and town spawn event for Towny integration
Browse files Browse the repository at this point in the history
misc: Add warning for Folia
misc: Bump config version
  • Loading branch information
MATRIX-feather committed Oct 19, 2024
1 parent 7d27e1d commit dfd29b0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void reload()
});

//更新配置
int targetVersion = 37;
int targetVersion = 38;

var configVersion = getOrDefault(Integer.class, ConfigOption.VERSION);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.event.PlayerChangePlotEvent;
import com.palmergames.bukkit.towny.event.TownSpawnEvent;
import com.palmergames.bukkit.towny.event.player.PlayerEntersIntoTownBorderEvent;
import com.palmergames.bukkit.towny.event.player.PlayerExitsFromTownBorderEvent;
import com.palmergames.bukkit.towny.object.Town;
Expand All @@ -11,6 +13,7 @@
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectLists;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -131,6 +134,12 @@ public void onEnterPlot(PlayerEntersIntoTownBorderEvent e)
updatePlayer(player, e.getEnteredTown());
}

@EventHandler
public void onTownSpawn(TownSpawnEvent e)
{
this.updatePlayer(e.getPlayer(), e.getToTown());
}

@EventHandler
public void onLeavePlot(PlayerExitsFromTownBorderEvent e)
{
Expand Down Expand Up @@ -175,23 +184,30 @@ public void onPlayerExit(PlayerQuitEvent e)
this.unblockPlayer(e.getPlayer());
}

@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent e)
{
if (e.getFrom().getWorld().equals(e.getTo().getWorld()))
this.updatePlayer(e.getPlayer(), null);
}

public void updatePlayer(Player player, @Nullable Town town)
{
this.updatePlayer(player, town, false);
}

public void updatePlayer(Player player, @Nullable Town town, boolean noLookup)
public void updatePlayer(Player player, @Nullable Town currentTown, boolean noLookup)
{
if (!worldUsingTowny(player.getWorld()))
{
unblockPlayer(player);
return;
}

if (town == null && !noLookup)
town = townyAPI.getTown(player.getLocation());
if (currentTown == null && !noLookup)
currentTown = townyAPI.getTown(player.getLocation());

if (allowFlightAt(player, town))
if (allowFlightAt(player, currentTown))
unblockPlayer(player);
else
blockPlayer(player);
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ root:
#
# Note that this doesn't affect worlds that are not managed by Towny
# To disable flying in these worlds, head to `flying > nofly_worlds`!
#
# WARNING!
# 1. There may be some bypasses on Folia servers, due to their teleport event having a strange trigger condition
allow_flight_in_wilderness: false

# Should we enable the "Disguise Revealing" feature?
Expand Down Expand Up @@ -353,4 +356,4 @@ root:
- SelectedItem

# Do not touch unless you know what you're doing!
version: 37
version: 38

0 comments on commit dfd29b0

Please sign in to comment.