Java Code Examples for org.bukkit.event.world.WorldUnloadEvent

The following examples show how to use org.bukkit.event.world.WorldUnloadEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldUnload(WorldUnloadEvent e) {
    // FIXME: 24/11/2019 It's not necessary but ok.
    // This is a workaround, because I don't get parsed chunk events when a
    // world unloads, I think...
    // So manually tell all of these shops they're unloaded.
    for (final Chunk chunk : e.getWorld().getLoadedChunks()) {
        final Map<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
        if (inChunk == null) {
            continue;
        }
        for (final Shop shop : inChunk.values()) {
            if (shop.isLoaded()) { //Don't unload already unloaded shops.
                shop.onUnload();
            }
        }
    }
}
 
Example 2
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldUnload(WorldUnloadEvent event) {
	final World world = event.getWorld();
	if (plugin.getConfig().getBoolean("optimizations.cleanupreferences.world", false)) {
		executor.schedule(new Runnable() {
			@Override
			public void run() {
				List<World> loadedworlds = Bukkit.getWorlds();
				for (World loadedworld : loadedworlds) {
					if (loadedworld == world) {
						return;
					}
				}
				nullFields(world);
			}
		}, 1, TimeUnit.SECONDS);
	}
}
 
Example 3
Source Project: GriefDefender   Source File: WorldEventHandler.java    License: MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onWorldUnload(WorldUnloadEvent event) {
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getWorld().getUID())) {
        return;
    }

    GriefDefenderPlugin.getInstance().dataStore.removeClaimWorldManager(event.getWorld().getUID());
}
 
Example 4
Source Project: Thermos   Source File: CraftServer.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean unloadWorld(World world, boolean save) {
    if (world == null) {
        return false;
    }

    net.minecraft.world.WorldServer handle = ((CraftWorld) world).getHandle();

    if (!(console.worlds.contains(handle))) {
        return false;
    }

    if (handle.playerEntities.size() > 0) {
        return false;
    }

    WorldUnloadEvent e = new WorldUnloadEvent(handle.getWorld());
    pluginManager.callEvent(e);

    if (e.isCancelled()) {
        return false;
    }

    if (save) {
        try {
            handle.saveAllChunks(true, null);
            handle.flush();
            WorldSaveEvent event = new WorldSaveEvent(handle.getWorld());
            getPluginManager().callEvent(event);
        } catch (net.minecraft.world.MinecraftException ex) {
            getLogger().log(Level.SEVERE, null, ex);
            FMLLog.log(org.apache.logging.log4j.Level.ERROR, ex, "Failed to save world " + handle.getWorld().getName() + " while unloading it.");
        }
    }
    MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(handle)); // Cauldron - fire unload event before removing world
    worlds.remove(world.getName().toLowerCase());
    DimensionManager.setWorld(handle.provider.dimensionId, null); // Cauldron - remove world from DimensionManager
    return true;
}
 
Example 5
Source Project: RedProtect   Source File: WorldListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onWorldUnload(WorldUnloadEvent e) {
    World w = e.getWorld();
    try {
        RedProtect.get().rm.unload(w.getName());

        RedProtect.get().reloadConfigs();
        RedProtect.get().logger.warning("World unloaded: " + w.getName());
    } catch (Exception ex) {
        RedProtect.get().logger.severe("RedProtect problem on unload world:");
        ex.printStackTrace();
    }
}
 
Example 6
Source Project: Slimefun4   Source File: WorldListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onWorldUnload(WorldUnloadEvent e) {
    BlockStorage storage = BlockStorage.getStorage(e.getWorld());

    if (storage != null) {
        storage.save(true);
    }
    else {
        Slimefun.getLogger().log(Level.SEVERE, "Could not save Slimefun Blocks for World \"{0}\"", e.getWorld().getName());
    }
}
 
Example 7
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void unloadWorld(WorldUnloadEvent event) {
  this.repairedChunks.removeAll(event.getWorld());
  block36Locations.remove(event.getWorld());
}
 
Example 8
Source Project: Kettle   Source File: CraftServer.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean unloadWorld(World world, boolean save) {
    if (world == null) {
        return false;
    }

    WorldServer handle = ((CraftWorld) world).getHandle();

    if (!(console.worldServerList.contains(handle))) {
        return false;
    }

    if (handle.dimension == 0) {
        return false;
    }

    if (handle.playerEntities.size() > 0) {
        return false;
    }

    WorldUnloadEvent e = new WorldUnloadEvent(handle.getWorld());
    pluginManager.callEvent(e);

    if (e.isCancelled()) {
        return false;
    }

    if (save) {
        try {
            handle.saveAllChunks(true, null);
            handle.flush();
        } catch (MinecraftException ex) {
            getLogger().log(Level.SEVERE, null, ex);
        }
    }
    MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Unload(handle)); // fire unload event before removing world
    worlds.remove(world.getName().toLowerCase(java.util.Locale.ENGLISH));
    DimensionManager.setWorld(handle.provider.getDimension(), null, FMLCommonHandler.instance().getMinecraftServerInstance()); // remove world from DimensionManager

    return true;
}
 
Example 9
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldUnload(WorldUnloadEvent event) {
    for(Entity entity : event.getWorld().getEntities()) {
        map.remove(entity);
    }
}
 
Example 10
@EventHandler(priority = EventPriority.LOWEST)
public void onWorldChange(WorldUnloadEvent event) {
    leakDetector.expectRelease(event.getWorld(), DEADLINE, true);
}
 
Example 11
@EventHandler(priority = EventPriority.MONITOR)
public void onUnload(WorldUnloadEvent event) {
    armorStands.remove(event.getWorld());
}
 
Example 12
@EventHandler
public void onWorldUnload(WorldUnloadEvent event) {
    EntityTracker.chunkWiper(event);
}
 
Example 13
Source Project: EliteMobs   Source File: EntityTracker.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static void chunkWiper(WorldUnloadEvent event) {
    for (Chunk chunk : event.getWorld().getLoadedChunks())
        for (Entity entity : chunk.getEntities())
            wipeEntity(entity);
}
 
Example 14
Source Project: LagMonitor   Source File: ThreadSafetyListener.java    License: MIT License 4 votes vote down vote up
@EventHandler
public void onWorldUnload(WorldUnloadEvent worldUnloadEvent) {
    checkSafety(worldUnloadEvent);
}
 
Example 15
Source Project: LagMonitor   Source File: ThreadSafetyListener.java    License: MIT License 4 votes vote down vote up
@EventHandler
public void onWorldUnload(WorldUnloadEvent worldUnloadEvent) {
    checkSafety(worldUnloadEvent);
}
 
Example 16
Source Project: Shopkeepers   Source File: WorldListener.java    License: GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
void onWorldUnload(WorldUnloadEvent event) {
	plugin.unloadShopkeepersInWorld(event.getWorld());
}