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:
parent
27afafadce
commit
6eb3261faa
2
pom.xml
2
pom.xml
@ -66,7 +66,7 @@
|
|||||||
<!-- Do not change unless you want different name for local builds. -->
|
<!-- Do not change unless you want different name for local builds. -->
|
||||||
<build.number>-LOCAL</build.number>
|
<build.number>-LOCAL</build.number>
|
||||||
<!-- This allows to change between versions. -->
|
<!-- This allows to change between versions. -->
|
||||||
<build.version>1.10.0</build.version>
|
<build.version>1.10.1</build.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<!-- Profiles will allow to automatically change build version. -->
|
<!-- Profiles will allow to automatically change build version. -->
|
||||||
|
@ -186,7 +186,11 @@ public class WarpSignsManager {
|
|||||||
// Load into map
|
// Load into map
|
||||||
if (warpsData != null) {
|
if (warpsData != null) {
|
||||||
warpsData.getWarpSigns().forEach((k,v) -> {
|
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
|
// Add to map
|
||||||
getWarpMap(k.getWorld()).put(v, k);
|
getWarpMap(k.getWorld()).put(v, k);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package world.bentobox.warps.listeners;
|
package world.bentobox.warps.listeners;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
|
|
||||||
|
import org.bukkit.event.world.ChunkLoadEvent;
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent.TeamKickEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent.TeamKickEvent;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent.TeamLeaveEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent.TeamLeaveEvent;
|
||||||
@ -44,6 +46,26 @@ public class WarpSignsListener implements Listener {
|
|||||||
this.plugin = addon.getPlugin();
|
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)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onPlayerLeave(TeamLeaveEvent e) {
|
public void onPlayerLeave(TeamLeaveEvent e) {
|
||||||
// Remove any warp signs from this game mode
|
// Remove any warp signs from this game mode
|
||||||
|
@ -20,13 +20,7 @@ import java.util.Map;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.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.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -90,6 +84,8 @@ public class WarpSignsManagerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private Location location;
|
private Location location;
|
||||||
@Mock
|
@Mock
|
||||||
|
private Chunk chunk;
|
||||||
|
@Mock
|
||||||
private Block block;
|
private Block block;
|
||||||
@Mock
|
@Mock
|
||||||
private PluginManager pim;
|
private PluginManager pim;
|
||||||
@ -166,9 +162,13 @@ public class WarpSignsManagerTest {
|
|||||||
when(location.getBlockZ()).thenReturn(25);
|
when(location.getBlockZ()).thenReturn(25);
|
||||||
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
|
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
|
||||||
|
|
||||||
|
// Chunk
|
||||||
|
when(chunk.isLoaded()).thenReturn(true);
|
||||||
|
|
||||||
// Block
|
// Block
|
||||||
when(block.getType()).thenReturn(Material.ACACIA_SIGN);
|
when(block.getType()).thenReturn(Material.ACACIA_SIGN);
|
||||||
when(block.getLocation()).thenReturn(location);
|
when(block.getLocation()).thenReturn(location);
|
||||||
|
when(block.getChunk()).thenReturn(chunk);
|
||||||
Sign sign = mock(Sign.class);
|
Sign sign = mock(Sign.class);
|
||||||
String[] lines = {"[Welcome]", "line2", "line3", "line4"};
|
String[] lines = {"[Welcome]", "line2", "line3", "line4"};
|
||||||
when(sign.getLines()).thenReturn(lines);
|
when(sign.getLines()).thenReturn(lines);
|
||||||
|
Loading…
Reference in New Issue
Block a user