mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-28 03:09:14 +00:00
Fix alwaysShowTitles showing titles every time you move
This commit is contained in:
@@ -11,10 +11,12 @@ public class RegionsEnterEvent extends Event {
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
private final Player player;
|
||||
private final List<String> regions;
|
||||
private final boolean hasChanged;
|
||||
|
||||
public RegionsEnterEvent(Player player, List<String> regions) {
|
||||
public RegionsEnterEvent(Player player, List<String> regions, boolean hasChanged) {
|
||||
this.player = player;
|
||||
this.regions = regions;
|
||||
this.hasChanged = hasChanged;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
@@ -25,6 +27,10 @@ public class RegionsEnterEvent extends Event {
|
||||
return regions;
|
||||
}
|
||||
|
||||
public boolean hasChanged() {
|
||||
return hasChanged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
|
||||
@@ -34,9 +34,13 @@ public class WorldGuardLegacyIntegration implements IntegrationManager {
|
||||
@Override
|
||||
public void handleMove(PlayerMoveEvent pme) {
|
||||
Player player = pme.getPlayer();
|
||||
int oldX = pme.getFrom().getBlockX();
|
||||
int oldY = pme.getFrom().getBlockY();
|
||||
int oldZ = pme.getFrom().getBlockZ();
|
||||
int x = pme.getTo().getBlockX();
|
||||
int y = pme.getTo().getBlockY();
|
||||
int z = pme.getTo().getBlockZ();
|
||||
Set<ProtectedRegion> oldRegions = this.getProtectedRegions(new Location(player.getWorld(), oldX, oldY, oldZ));
|
||||
Set<ProtectedRegion> regions = this.getProtectedRegions(new Location(player.getWorld(), x, y, z));
|
||||
|
||||
List<String> stringRegions = new ArrayList<>();
|
||||
@@ -53,7 +57,7 @@ public class WorldGuardLegacyIntegration implements IntegrationManager {
|
||||
}
|
||||
stringRegions.add(region.getId());
|
||||
});
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringRegions));
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringRegions, !oldRegions.equals(regions)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,9 +36,13 @@ public class WorldGuardIntegration implements IntegrationManager {
|
||||
@Override
|
||||
public void handleMove(PlayerMoveEvent pme) {
|
||||
Player player = pme.getPlayer();
|
||||
int oldX = pme.getFrom().getBlockX();
|
||||
int oldY = pme.getFrom().getBlockY();
|
||||
int oldZ = pme.getFrom().getBlockZ();
|
||||
int x = pme.getTo().getBlockX();
|
||||
int y = pme.getTo().getBlockY();
|
||||
int z = pme.getTo().getBlockZ();
|
||||
Set<ProtectedRegion> oldRegions = this.getProtectedRegions(new Location(player.getWorld(), oldX, oldY, oldZ));
|
||||
Set<ProtectedRegion> regions = this.getProtectedRegions(new Location(player.getWorld(), x, y, z));
|
||||
|
||||
List<String> stringRegions = new ArrayList<>();
|
||||
@@ -56,7 +60,7 @@ public class WorldGuardIntegration implements IntegrationManager {
|
||||
stringRegions.add(region.getId());
|
||||
});
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringRegions));
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringRegions, !oldRegions.equals(regions)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -70,7 +70,7 @@ public class RegionListener implements Listener {
|
||||
});
|
||||
}
|
||||
|
||||
if (configuredRegion.alwaysShowTitles()) {
|
||||
if (configuredRegion.alwaysShowTitles() && ree.hasChanged()) {
|
||||
this.sendTitles(player, configuredRegion);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user