1
0
mirror of https://github.com/BentoBoxWorld/Warps.git synced 2024-11-10 21:09:50 +01:00

Don't validate unloaded signs in startup

This commit is contained in:
Gabriele C 2020-08-03 18:49:23 +02:00
parent 27afafadce
commit 6eb3261faa
4 changed files with 36 additions and 10 deletions

View File

@ -66,7 +66,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.10.0</build.version>
<build.version>1.10.1</build.version>
</properties>
<!-- Profiles will allow to automatically change build version. -->

View File

@ -186,7 +186,11 @@ public class WarpSignsManager {
// Load into map
if (warpsData != null) {
warpsData.getWarpSigns().forEach((k,v) -> {
if (k != null && k.getWorld() != null && k.getBlock().getType().name().contains("SIGN")) {
if (k != null && k.getWorld() != null) {
if (k.getBlock().getChunk().isLoaded() && !k.getBlock().getType().name().contains("SIGN")) {
return;
}
// Add to map
getWarpMap(k.getWorld()).put(v, k);
}

View File

@ -1,5 +1,6 @@
package world.bentobox.warps.listeners;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
@ -16,6 +17,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.events.team.TeamEvent.TeamKickEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent.TeamLeaveEvent;
@ -44,6 +46,26 @@ public class WarpSignsListener implements Listener {
this.plugin = addon.getPlugin();
}
@EventHandler(priority = EventPriority.NORMAL)
public void onChunkLoad(ChunkLoadEvent event) {
boolean changed = false;
Iterator<Map.Entry<UUID, Location>> iterator =
addon.getWarpSignsManager().getWarpMap(event.getWorld()).entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<UUID, Location> entry = iterator.next();
if (entry.getValue().getChunk().equals(event.getChunk())
&& !entry.getValue().getBlock().getType().name().contains("SIGN")) {
iterator.remove();
// Remove sign from warp panel cache
addon.getWarpPanelManager().removeWarp(event.getWorld(), entry.getKey());
changed = true;
}
}
if (changed) {
addon.getWarpSignsManager().saveWarpList();
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerLeave(TeamLeaveEvent e) {
// Remove any warp signs from this game mode

View File

@ -20,13 +20,7 @@ import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@ -90,6 +84,8 @@ public class WarpSignsManagerTest {
@Mock
private Location location;
@Mock
private Chunk chunk;
@Mock
private Block block;
@Mock
private PluginManager pim;
@ -166,9 +162,13 @@ public class WarpSignsManagerTest {
when(location.getBlockZ()).thenReturn(25);
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
// Chunk
when(chunk.isLoaded()).thenReturn(true);
// Block
when(block.getType()).thenReturn(Material.ACACIA_SIGN);
when(block.getLocation()).thenReturn(location);
when(block.getChunk()).thenReturn(chunk);
Sign sign = mock(Sign.class);
String[] lines = {"[Welcome]", "line2", "line3", "line4"};
when(sign.getLines()).thenReturn(lines);