mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-27 02:39:07 +00:00
Fixes #24
This commit is contained in:
@@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class RegionsEnterEvent extends Event {
|
||||
@@ -19,6 +20,12 @@ public class RegionsEnterEvent extends Event {
|
||||
this.hasChanged = hasChanged;
|
||||
}
|
||||
|
||||
public RegionsEnterEvent(Player player, String region, boolean hasChanged) {
|
||||
this.player = player;
|
||||
this.regions = Collections.singletonList(region);
|
||||
this.hasChanged = hasChanged;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
@@ -27,6 +34,10 @@ public class RegionsEnterEvent extends Event {
|
||||
return regions;
|
||||
}
|
||||
|
||||
public String getPriority() {
|
||||
return regions.get(0);
|
||||
}
|
||||
|
||||
public boolean hasChanged() {
|
||||
return hasChanged;
|
||||
}
|
||||
|
||||
@@ -14,8 +14,6 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class WorldGuardLegacyIntegration implements IntegrationManager {
|
||||
@@ -43,7 +41,6 @@ public class WorldGuardLegacyIntegration implements IntegrationManager {
|
||||
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<>();
|
||||
regions.forEach(region -> {
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region.getId());
|
||||
if (configuredRegion != null && configuredRegion.getRequirements() != null) {
|
||||
@@ -55,9 +52,9 @@ public class WorldGuardLegacyIntegration implements IntegrationManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
stringRegions.add(region.getId());
|
||||
});
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringRegions, !oldRegions.equals(regions)));
|
||||
ConfiguredRegion prioritisedRegion = getPrioritisedRegion(pme.getTo());
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, prioritisedRegion.getId(), !oldRegions.equals(regions)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,8 +12,6 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ResidenceIntegration implements IntegrationManager {
|
||||
@@ -36,12 +34,9 @@ public class ResidenceIntegration implements IntegrationManager {
|
||||
ClaimedResidence oldResidence = Residence.getInstance().getResidenceManager().getByLoc(pme.getFrom());
|
||||
ClaimedResidence residence = Residence.getInstance().getResidenceManager().getByLoc(pme.getTo());
|
||||
if (oldResidence == null || residence == null) return;
|
||||
|
||||
List<String> stringResidence = new ArrayList<>();
|
||||
if (!checkRequirements(pme, residence.getName())) return;
|
||||
|
||||
stringResidence.add(residence.getName());
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringResidence, !oldResidence.equals(residence)));
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, residence.getName(), !oldResidence.equals(residence)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,6 +33,7 @@ public class WorldGuardIntegration implements IntegrationManager {
|
||||
|
||||
@Override
|
||||
public void handleMove(PlayerMoveEvent pme) {
|
||||
if (pme.getTo() == null) return;
|
||||
Player player = pme.getPlayer();
|
||||
int oldX = pme.getFrom().getBlockX();
|
||||
int oldY = pme.getFrom().getBlockY();
|
||||
@@ -43,11 +44,14 @@ public class WorldGuardIntegration implements IntegrationManager {
|
||||
Set<ProtectedRegion> oldRegions = this.getProtectedRegions(new Location(player.getWorld(), oldX, oldY, oldZ));
|
||||
Set<ProtectedRegion> regions = this.getProtectedRegions(new Location(player.getWorld(), x, y, z));
|
||||
|
||||
String prioritisedRegion = getPrioritisedRegion(pme.getTo()).getId();
|
||||
List<String> stringRegions = new ArrayList<>();
|
||||
regions.forEach(region -> {
|
||||
if (checkRequirements(pme, region.getId())) stringRegions.add(region.getId());
|
||||
if (!prioritisedRegion.equals(region.getId())
|
||||
&& checkRequirements(pme, region.getId())) stringRegions.add(region.getId());
|
||||
});
|
||||
|
||||
stringRegions.add(0, getPrioritisedRegion(pme.getTo()).getId());
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringRegions, !oldRegions.equals(regions)));
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ public class RegionListener implements Listener {
|
||||
for (String region : event.getRegions()) {
|
||||
if (plugin.getManagers().getRegionsCache().getConfiguredRegions().containsKey(region)) {
|
||||
boolean has = false;
|
||||
boolean prioritised = event.getPriority().equals(region);
|
||||
for (Discovery discoveredRegion : account.getDiscoveredRegions().values()) {
|
||||
if (discoveredRegion.getRegion().equals(region)) {
|
||||
has = true;
|
||||
@@ -53,11 +54,11 @@ public class RegionListener implements Listener {
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegions().get(region);
|
||||
this.checkEffects(configuredRegion, player);
|
||||
|
||||
if (configuredRegion.alwaysShowTitles() && event.hasChanged() && has) {
|
||||
if (configuredRegion.alwaysShowTitles() && event.hasChanged() && has && prioritised) {
|
||||
this.sendTitles(player, configuredRegion, false);
|
||||
}
|
||||
|
||||
if (!has && configuredRegion.isDiscoverable()) {
|
||||
if (!has && configuredRegion.isDiscoverable() && prioritised) {
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
String formattedDate = date.format(format);
|
||||
account.addDiscovery(new WorldDiscovery(formattedDate, region));
|
||||
|
||||
Reference in New Issue
Block a user