org.bukkit.event.world.WorldUnloadEvent Java Examples

The following examples show how to use org.bukkit.event.world.WorldUnloadEvent. 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 check out the related API usage on the sidebar.
Example #1
Source File: WorldListener.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@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
Source File: ReferenceCleanup.java    From Carbon with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 File: WorldEventHandler.java    From GriefDefender with 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 File: CraftServer.java    From Thermos with 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 File: WorldListener.java    From RedProtect with 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 File: WorldListener.java    From Slimefun4 with 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
Source File: WorldProblemListener.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void unloadWorld(WorldUnloadEvent event) {
  this.repairedChunks.removeAll(event.getWorld());
  block36Locations.remove(event.getWorld());
}
 
Example #8
Source File: CraftServer.java    From Kettle with 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
Source File: LivingEntityMapAdapter.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldUnload(WorldUnloadEvent event) {
    for(Entity entity : event.getWorld().getEntities()) {
        map.remove(entity);
    }
}
 
Example #10
Source File: LeakListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onWorldChange(WorldUnloadEvent event) {
    leakDetector.expectRelease(event.getWorld(), DEADLINE, true);
}
 
Example #11
Source File: PlayerFreezer.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onUnload(WorldUnloadEvent event) {
    armorStands.remove(event.getWorld());
}
 
Example #12
Source File: ChunkUnloadMetadataPurge.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onWorldUnload(WorldUnloadEvent event) {
    EntityTracker.chunkWiper(event);
}
 
Example #13
Source File: EntityTracker.java    From EliteMobs with 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 File: ThreadSafetyListener.java    From LagMonitor with MIT License 4 votes vote down vote up
@EventHandler
public void onWorldUnload(WorldUnloadEvent worldUnloadEvent) {
    checkSafety(worldUnloadEvent);
}
 
Example #15
Source File: ThreadSafetyListener.java    From LagMonitor with MIT License 4 votes vote down vote up
@EventHandler
public void onWorldUnload(WorldUnloadEvent worldUnloadEvent) {
    checkSafety(worldUnloadEvent);
}
 
Example #16
Source File: WorldListener.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
void onWorldUnload(WorldUnloadEvent event) {
	plugin.unloadShopkeepersInWorld(event.getWorld());
}