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

The following are top voted examples for showing how to use org.bukkit.event.world.ChunkUnloadEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: NeverLag   File: RemoveEntityWhenChunkUnload.java   View source code 6 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onChunkUnload(ChunkUnloadEvent e) {
	if (!cm.removeEntityWhenChunkUnload) {
		return;
	}
	for (Entity entity : e.getChunk().getEntities()) {
		if (NeverLagUtils.checkCustomNpc(entity)) {
			continue;
		}
		if (entity instanceof Monster && cm.removeMonsterWhenChunkUnload) {
			entity.remove();
		} else if (entity instanceof Animals && cm.removeAnimalsWhenChunkUnload) {
			entity.remove();
		} else if (entity instanceof Item && cm.removeItemWhenChunkUnload) {
			entity.remove();
		} else if (entity instanceof Arrow && cm.removeArrowWhenChunkUnload) {
			entity.remove();
		} else if (entity instanceof Squid && cm.removeSquidWhenChunkUnload) {
			entity.remove();
		}
	}
}
 
Example 2
Project: QuestManager   File: QuestManager.java   View source code 6 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent e) {
	if (QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getWorlds().contains(
			e.getWorld().getName()))
	for (Entity entity : e.getChunk().getEntities()) {
		for (NPC npc : questNPCs) {
			
			//if (npc.getEntity().getCustomName() != null &&
			if (npc.getName() != null &&
					//npc.getEntity().getCustomName().equals(entity.getCustomName()))
					npc.getName().equals(entity.getCustomName()))
			if (npc.getID().equals(entity.getUniqueId())) {
				return;
			}
		}
		if (entity instanceof LivingEntity) {
			LivingEntity live = (LivingEntity) entity;
			QuestManagerPlugin.questManagerPlugin.getEnemyManager().removeEntity(live);
			entity.remove();
		}
	}
}
 
Example 3
Project: ExilePearl   File: PlayerListener.java   View source code 6 votes vote down vote up
/**
 * Prevent chunk that contain pearls from unloading
 * @param e The event args
 */
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent e) {
	Chunk chunk = e.getChunk();
	for (Entity entity : chunk.getEntities()) {
		if (!(entity instanceof Item)) {
			continue;
		}
		
		Item item = (Item)entity;
		ExilePearl pearl = pearlApi.getPearlFromItemStack(item.getItemStack());
		
		if (pearl != null) {
			e.setCancelled(true);
			pearlApi.log("Prevented chunk (%d, %d) from unloading because it contained an exile pearl for player %s.", chunk.getX(), chunk.getZ(), pearl.getPlayerName());
		}
	}
}
 
Example 4
Project: civcraft   File: BonusGoodieManager.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void OnChunkUnload(ChunkUnloadEvent event) {
	
	BonusGoodie goodie;
	
	for (Entity entity : event.getChunk().getEntities()) {
		if (!(entity instanceof Item)) {
			continue;
		}
		
		goodie = CivGlobal.getBonusGoodie(((Item)entity).getItemStack());
		if (goodie == null) {
			continue;
		}
		
		goodie.replenish(((Item)entity).getItemStack(), (Item)entity, null, null);
	}
}
 
Example 5
Project: StarQuestCode   File: ChunkListener.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onChunkUnload(ChunkUnloadEvent event) {
	Entity[] entitiesInChunk = event.getChunk().getEntities();
	if (entitiesInChunk.length == 0)
		return;

	List<EntityType> passives = Settings.getAllPassives();
	List<EntityType> hostiles = Settings.getAllHostiles();

	for (Entity e : entitiesInChunk) {
		if ((hostiles != null && hostiles.contains(e.getType())
				|| (passives != null && passives.contains(e.getType())))) {
			LivingEntity le = (LivingEntity) e;
			if ((le.getCustomName() == null) && (!le.isCustomNameVisible())) {
				le.remove();
			}
		} else if (e.getType() == EntityType.WITHER_SKULL) {
			e.remove();
		}
	}
}
 
Example 6
Project: StarQuestCode   File: Events.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onChunkUnload(ChunkUnloadEvent event)
{
	if(!event.isCancelled())
	{
		Chunk chunk = event.getChunk();
		
		for(Machine machine : SQTechBase.machines)
		{
			if(machine.getMachineType() instanceof Harvester)
			{
				if(machine.getGUIBlock().getLocation().getChunk() == chunk)
				{
					main.setInactive(machine);
					machine.data.put("blocked", false);
				}
			}
		}
	}
}
 
Example 7
Project: StarQuestCode   File: Events.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onChunkUnload(ChunkUnloadEvent event)
{
	if(!event.isCancelled())
	{
		Chunk chunk = event.getChunk();
		
		for(Machine machine : SQTechBase.machines)
		{
			if(machine.getMachineType().name == "Drill")
			{
				if(machine.getGUIBlock().getLocation().getChunk() == chunk)
				{
					machine.data.put("isActive", false);
					machine.data.put("blocked", false);
				}
			}
		}
	}
}
 
Example 8
Project: horsekeep   File: HorseKeep.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onChunkUnloaded(ChunkUnloadEvent event) {
    Chunk c = event.getChunk();
    
    Entity[] entities = c.getEntities();
    
    for(Entity e: entities){
    	if (this.manager.isHorse(e))
    	{
    		if (this.manager.isOwned(e.getUniqueId()))
    		{
    			// We save horse location
    			Location loc = e.getLocation();
    			this.data.getHorsesData().set("horses."+e.getUniqueId()+".lastpos",loc.getWorld().getName()+":"+loc.getX()+":"+loc.getY()+":"+loc.getZ()+":"+loc.getYaw()+":"+loc.getPitch());
    			
    			this.data.save();
    		}
    	}
    }
}
 
Example 9
Project: PlotSquared   File: ChunkListener.java   View source code 6 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
    if (ignoreUnload) {
        return;
    }
    if (Settings.Chunk_Processor.AUTO_TRIM) {
        Chunk chunk = event.getChunk();
        String world = chunk.getWorld().getName();
        if (PS.get().hasPlotArea(world)) {
            if (unloadChunk(world, chunk, true)) {
                return;
            }
        }
    }
    if (processChunk(event.getChunk(), true)) {
        event.setCancelled(true);
    }
}
 
Example 10
Project: EndHQ-Libraries   File: ChunkEntityLoader.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent event)
{
	final Chunk c = event.getChunk();
	for(Entity entity : c.getEntities())
	{
		if(!(entity instanceof LivingEntity))
			continue;

		RemoteEntity rentity = RemoteEntities.getRemoteEntityFromEntity((LivingEntity)entity);
		if(rentity != null && rentity.isSpawned())
		{
			m_toSpawn.add(new EntityLoadData(rentity, entity.getLocation()));
			rentity.despawn(DespawnReason.CHUNK_UNLOAD);
		}
	}
}
 
Example 11
Project: ReadySetJump   File: BlockConfig.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
private void onChunkUnload(ChunkUnloadEvent cue) {
  Chunk chunk = cue.getChunk();
  ConfigurationSection config = configs.get(cue.getChunk());
  if(config != null && config.isConfigurationSection("blocks")) {
    ConfigurationSection blocks = config.getConfigurationSection("blocks");
    for(Map.Entry<String, Object> entry : blocks.getValues(false).entrySet()) {
      ConfigurationSection section = (ConfigurationSection) entry.getValue();
      String[] locationParts = entry.getKey().split(" ");
      int[] locationValues = new int[3];
      for(int i = 0; i < 3; i++) {
        locationValues[i] = Integer.parseInt(locationParts[i]);
      }
      BlockConfigUnloadEvent event = new BlockConfigUnloadEvent(plugin, section, cue.getChunk().getBlock(locationValues[0], locationValues[2], locationValues[2]));
      Bukkit.getPluginManager().callEvent(event);
    }
  }
  saveConfig(cue.getChunk());
  configs.remove(chunk);
  blockConfigs.remove(chunk);
}
 
Example 12
Project: NPlugins   File: ChunkListener.java   View source code 6 votes vote down vote up
/**
 * Remove the unloaded EnderDragons from the loaded set
 *
 * @param event a Chunk Unload Event
 */
@EventHandler(priority = EventPriority.NORMAL)
public void onEndChunkUnload(final ChunkUnloadEvent event) {
    if (event.getWorld().getEnvironment() == Environment.THE_END) {
        final String worldName = event.getWorld().getName();
        final EndWorldHandler handler = this.plugin.getHandler(StringUtil.toLowerCamelCase(worldName));
        if (handler != null) {
            EndChunk chunk = handler.getChunks().getChunk(event.getChunk());
            if (chunk == null) {
                chunk = handler.getChunks().addChunk(event.getChunk());
            }
            for (final Entity e : event.getChunk().getEntities()) {
                if (e.getType() == EntityType.ENDER_DRAGON) {
                    final EnderDragon ed = (EnderDragon)e;
                    handler.getLoadedDragons().remove(ed.getUniqueId());
                    chunk.incrementSavedDragons();
                }
            }
        }
    }
}
 
Example 13
Project: xEssentials-deprecated-bukkit   File: ChunkProtectionEvent.java   View source code 6 votes vote down vote up
@EventHandler
public void onChunkProtect(ChunkUnloadEvent e) {
	for(Entity entity : e.getChunk().getEntities()) {
		if(entity instanceof WitherSkull) {
			WitherSkull wither = (WitherSkull) entity;
			if(pl.getConfiguration().getDebugConfig().isEnabled()) {
				xEssentials.log("removed wither skull at: {" + wither.getWorld().getName() + ", " + wither.getLocation().getBlockX() + ", " + wither.getLocation().getBlockY() + ", " + wither.getLocation().getBlockZ() + "} to prevent lag", LogType.INFO);
			}
			wither.remove();
		} else if(entity instanceof Fireball) {
			Fireball fb = (Fireball) entity;
			if(pl.getConfiguration().getDebugConfig().isEnabled()) {
				xEssentials.log("removed fireball at: {" + fb.getWorld().getName() + ", " + fb.getLocation().getBlockX() + ", " + fb.getLocation().getBlockY() + ", " + fb.getLocation().getBlockZ() + "} to prevent lag", LogType.INFO);
			}
			fb.remove();
		}
	}
}
 
Example 14
Project: SparkTrail   File: EntityListener.java   View source code 6 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
    ArrayList<Entity> toRemove = new ArrayList<Entity>();
    for (Entity e : event.getChunk().getEntities()) {
        EffectHolder holder = EffectManager.getInstance().getEffect(e.getUniqueId());
        if (holder != null) {
            EffectManager.getInstance().clear(holder);
            continue;
        }

        if (e instanceof Item && ItemSpray.UUID_LIST.contains(e.getUniqueId())) {
            toRemove.add(e);
        }
    }
    if (!toRemove.isEmpty()) {
        Iterator<Entity> i = toRemove.iterator();
        while (i.hasNext()) {
            i.next().remove();
        }
    }
}
 
Example 15
Project: EntityAPI   File: SimpleChunkManager.java   View source code 6 votes vote down vote up
@EventHandler
public void onUnload(ChunkUnloadEvent event) {
    Chunk unloadedChunk = event.getChunk();
    for (Entity entity : unloadedChunk.getEntities()) {
        if (entity instanceof LivingEntity) {
            Object handle = BukkitUnwrapper.getInstance().unwrap(entity);
            if (handle instanceof ControllableEntityHandle) {
                ControllableEntity controllableEntity = ((ControllableEntityHandle) handle).getControllableEntity();
                if (controllableEntity != null && controllableEntity.isSpawned()) {
                    this.SPAWN_QUEUE.add(new EntityChunkData(controllableEntity, entity.getLocation()));
                    controllableEntity.despawn(DespawnReason.CHUNK_UNLOAD);
                }
            }
        }
    }
}
 
Example 16
Project: CropControl   File: CropControlEventHandler.java   View source code 5 votes vote down vote up
/**
 * Marks a loaded chunk as pending unload. It'll be unloaded later en-masse.
 * 
 * @param e The chunk to unload.
 */
@EventHandler(ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent e) {
	Chunk chunk = e.getChunk();
	
	CropControl.getDAO().unloadChunk(chunk);
}
 
Example 17
Project: AntiCheat   File: OrebfuscatorChunkListener.java   View source code 5 votes vote down vote up
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent event) {
    Chunk chunk = event.getChunk();
    ChunkReloader.addUnloadedChunk(event.getWorld(), chunk.getX(), chunk.getZ());

    //Orebfuscator.log("Chunk x = " + chunk.getX() + ", z = " + chunk.getZ() + " is unloaded");/*debug*/
}
 
Example 18
Project: EscapeLag   File: UnloadClear.java   View source code 5 votes vote down vote up
@EventHandler
public void ChunkloadClear(ChunkUnloadEvent event) {
	if (ConfigOptimize.UnloadClearenable != true) {
		return;
	}
	Chunk chunk = event.getChunk();
	boolean noclearitemchunk = false;
	int dcs = DeathChunk.size();
	for (int i = 0; i < dcs; i++) {
		Chunk deathchunk = DeathChunk.get(i);
		if (Utils.isSameChunk(chunk, deathchunk)) {
			DeathChunk.remove(chunk);
			noclearitemchunk = true;
			break;
		}
	}
	Entity[] entities = chunk.getEntities();
	for (int i = 0; i < entities.length; i++) {
		Entity ent = entities[i];
		if (ent.getType() == EntityType.DROPPED_ITEM && noclearitemchunk == false && ConfigOptimize.UnloadClearDROPPED_ITEMenable) {
			ent.remove();
		}
		if(ConfigOptimize.UnloadCleartype.contains(ent.getType().name())||ConfigOptimize.UnloadCleartype.contains("*")) {
			ent.remove();
		}
	}
}
 
Example 19
Project: AddGun   File: Guns.java   View source code 5 votes vote down vote up
/**
 * This eliminates pending bullets on chunk unload
 * 
 * @param event
 */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void chunkUnloadClearBullets(ChunkUnloadEvent event) {
	if (event.getChunk() == null) return;
	Entity[] entities = event.getChunk().getEntities();
	for (Entity e : entities) {
		if (inFlightBullets.containsKey(e.getUniqueId())) {
			inFlightBullets.remove(e.getUniqueId());
			travelPaths.remove(e.getUniqueId());
			e.remove();
		}
	}
}
 
Example 20
Project: SurvivalAPI   File: ChunkListener.java   View source code 5 votes vote down vote up
/**
 * Save unloaded chunk
 *
 * @param event Event
 */
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event)
{
    for (Entity entity : event.getChunk().getEntities())
        if (!(entity instanceof Item || entity instanceof HumanEntity || entity instanceof Minecart))
            entity.remove();

    //event.setCancelled(true);
}
 
Example 21
Project: NeverLag   File: HotChunkHolder.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onUnloadChunk(ChunkUnloadEvent e) {
	if (!cm.hotChunkEnabled || NeverLag.getTpsWatcher().getAverageTPS() < cm.hotChunkTpsThreshold) {
		return;
	}
	ChunkInfo chunkInfo = new ChunkInfo(e.getChunk());
	if (hotChunkRecord.contains(chunkInfo)) {
		e.setCancelled(true);
		this.addHotChunkUnloadCount(chunkInfo);
	}
}
 
Example 22
Project: NeverLag   File: HotChunkHolder.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onUnloadChunkMonitor(ChunkUnloadEvent e) {
	if (!cm.hotChunkEnabled || NeverLag.getTpsWatcher().getAverageTPS() < cm.hotChunkTpsThreshold) {
		return;
	}
	ChunkInfo chunkInfo = new ChunkInfo(e.getChunk());
	chunkUnLoadTime.put(chunkInfo, System.currentTimeMillis());
}
 
Example 23
Project: WorldGuardExtraFlagsPlugin   File: WorldListener.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChunkUnloadEvent(ChunkUnloadEvent event)
{
	for (ProtectedRegion region : WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionManager(event.getWorld()).getApplicableRegions(new ProtectedCuboidRegion("UnloadChunkFlagTester", new BlockVector(event.getChunk().getX() * 16, 0, event.getChunk().getZ() * 16), new BlockVector(event.getChunk().getX() * 16 + 15, 256, event.getChunk().getZ() * 16 + 15))))
	{
		if (region.getFlag(FlagUtils.CHUNK_UNLOAD) == State.DENY)
		{
			event.setCancelled(true);
			break;
		}
	}
}
 
Example 24
Project: cubit   File: WorldListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onChunkUnloadEvent(final ChunkUnloadEvent event) {
    mrg.debug("ChunkUnloadEvent " + event.getChunk().getX() + " " + event.getChunk().getZ());

    if (chunkTasks.containsKey(event.getChunk())) {
        chunkTasks.remove(event.getChunk()).cancel();
    }

    if (CubitBukkitPlugin.inst().getYamlManager().getLimit().check_chunk_unload) {
        mrg.checkChunk(event.getChunk(), null);
    }
}
 
Example 25
Project: CanaryBukkit   File: CanaryWorldListener.java   View source code 5 votes vote down vote up
@HookHandler(priority = Priority.CRITICAL, ignoreCanceled = true)
public void onChunkUnload(final ChunkUnloadHook hook) {
    ChunkUnloadEvent event =
            new ChunkUnloadEvent(new CanaryChunk(hook.getChunk(), new CanaryWorld(hook.getWorld())));
    event.setCancelled(hook.isCanceled());
    server.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        hook.setCanceled();
    }
}
 
Example 26
Project: BedwarsRel   File: ChunkListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onUnload(ChunkUnloadEvent unload) {
  Game game = BedwarsRel.getInstance().getGameManager()
      .getGameByChunkLocation(unload.getChunk().getX(),
          unload.getChunk().getZ());
  if (game == null) {
    return;
  }

  if (game.getState() != GameState.RUNNING) {
    return;
  }

  unload.setCancelled(true);
}
 
Example 27
Project: FastAsyncWorldedit   File: BukkitQueue_0.java   View source code 5 votes vote down vote up
@EventHandler
public static void onChunkUnload(ChunkUnloadEvent event) {
    Chunk chunk = event.getChunk();
    long pair = MathMan.pairInt(chunk.getX(), chunk.getZ());
    Long lastLoad = keepLoaded.get(pair);
    if (lastLoad != null) {
        if (Fawe.get().getTimer().getTickStart() - lastLoad < 10000) {
            event.setCancelled(true);
        } else {
            keepLoaded.remove(pair);
        }
    }
}
 
Example 28
Project: Portals   File: ChunkUnload.java   View source code 5 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
	
	/* Do not let chunks containing entities about to be teleported unload */
	for (Entity entity : event.getChunk().getEntities()) {
		if (Portals.justTeleportedEntities.contains(entity.getUniqueId())) {
			event.setCancelled(true);
		}	
	}
	
}
 
Example 29
Project: civcraft   File: BlockListener.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onChunkUnloadEvent(ChunkUnloadEvent event) {
	Boolean persist = CivGlobal.isPersistChunk(event.getChunk());		
	if (persist != null && persist == true) {
		event.setCancelled(true);
	}
}
 
Example 30
Project: Almura-Server   File: ChunkProviderServer.java   View source code 5 votes vote down vote up
public boolean unloadChunks() {
    if (!this.world.savingDisabled) {
        // CraftBukkit start
        Server server = this.world.getServer();
        for (int i = 0; i < 100 && !this.unloadQueue.isEmpty(); i++) {
            long chunkcoordinates = this.unloadQueue.popFirst();
            Chunk chunk = this.chunks.get(chunkcoordinates);
            if (chunk == null) continue;
            // Almura - Remove the chunk from cache if it is unloaded
            Chunk result = world.lastChunkAccessed;
            if (result != null && result.x == chunk.x && result.z == chunk.z) {
                world.lastChunkAccessed = null;
            }
            // Almura end

            ChunkUnloadEvent event = new ChunkUnloadEvent(chunk.bukkitChunk);
            server.getPluginManager().callEvent(event);
            if (!event.isCancelled()) {
                chunk.removeEntities();
                this.saveChunk(chunk);
                this.saveChunkNOP(chunk);
                // this.unloadQueue.remove(integer);
                this.chunks.remove(chunkcoordinates); // CraftBukkit
            }
        }
        // CraftBukkit end

        if (this.e != null) {
            this.e.a();
        }
    }

    return this.chunkProvider.unloadChunks();
}
 
Example 31
Project: McMMOPlus   File: WorldListener.java   View source code 5 votes vote down vote up
/**
 * Monitor ChunkUnload events.
 *
 * @param event The event to watch
 */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent event) {
    Chunk chunk = event.getChunk();

    mcMMO.getPlaceStore().chunkUnloaded(chunk.getX(), chunk.getZ(), event.getWorld());
}
 
Example 32
Project: SwornCritters   File: WorldListener.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onChunkUnload(ChunkUnloadEvent event)
{
	for (Entity entity : event.getChunk().getEntities())
	{
		if (entity.getUniqueId().equals(plugin.getLegendaryEntityId()))
		{
			entity.remove();
			plugin.removeLegendary();
		}
	}
}
 
Example 33
Project: NucleusFramework   File: InternalEntityTracker.java   View source code 5 votes vote down vote up
/**
 * Handle chunk unload
 */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
private void onChunkUnload(ChunkUnloadEvent event) {

    Entity[] entities = event.getChunk().getEntities();

    for (Entity entity : entities) {

        TrackedEntity tracked = _entities.get(entity.getUniqueId());
        if (tracked == null || isDisposed(tracked))
            continue;

        tracked.notifyChunkUnload(new ChunkCoords(event.getChunk()));
    }
}
 
Example 34
Project: GoldRushPlugin   File: TrainStation.java   View source code 5 votes vote down vote up
@Override
public void remove() {

    //Unregister handlers for events.
    ChunkUnloadEvent.getHandlerList().unregister(this);
    PlayerMoveEvent.getHandlerList().unregister(this);
    MemberBlockChangeEvent.getHandlerList().unregister(this);
    PlayerInteractEvent.getHandlerList().unregister(this);
    //BlockFinder Class stuff.
    BlockPlaceEvent.getHandlerList().unregister(this);
    BlockBreakEvent.getHandlerList().unregister(this);
    BlockDamageEvent.getHandlerList().unregister(this);

    //Remove from the DB.
    removeFromDB();

    //Remove ALL NPC's in the area.
    for(NPC npc : this.workers) CitizensAPI.getNPCRegistry().deregister(npc);

    //Clear sign logic and change signs to air.
    this.signs = null;
    for(Block b : this.trainArea) {
        if(b.getState() instanceof Sign) {
            b.setType(Material.AIR);
        }
    }

    //Clear trains.
    this.departingTrains = null;
    this.trains = null;

    //Clear visitors
    this.visitors = null;

    //Clear name
    this.stationName = null;

    //Remove from the list
    trainStations.remove(this);
}
 
Example 35
Project: xEssentials-deprecated-bukkit   File: CleanupUnloadedChunkEvent.java   View source code 5 votes vote down vote up
@EventHandler
public void onCleanup(ChunkUnloadEvent e) {
	for(Entity entity : e.getChunk().getEntities()) {
		if(entity instanceof Item) {
			Item item = (Item) entity;
			item.remove();
		} else if(entity instanceof Monster) {
			Monster monster = (Monster) entity;
			monster.remove();
		} else if(entity instanceof ExperienceOrb) {
			ExperienceOrb orb = (ExperienceOrb) entity;
			orb.remove();
		}
	}
}
 
Example 36
Project: Sedimentology   File: Sedimentology.java   View source code 5 votes vote down vote up
@EventHandler
public void onChunkUnloadEvent(ChunkUnloadEvent event) {
	World w = event.getWorld();
	for (SedWorld ww: sedWorldList) {
		if (ww.world.equals(w)) {
			Chunk c = event.getChunk();
			ww.unload(c.getX(),  c.getZ());
		}
	}
}
 
Example 37
Project: Craft-city   File: ChunkProviderServer.java   View source code 5 votes vote down vote up
public boolean unloadChunks() {
    if (!this.world.savingDisabled) {
        // CraftBukkit start
        Server server = this.world.getServer();
        for (int i = 0; i < 100 && !this.unloadQueue.isEmpty(); i++) {
            long chunkcoordinates = this.unloadQueue.popFirst();
            Chunk chunk = this.chunks.get(chunkcoordinates);
            if (chunk == null) continue;

            ChunkUnloadEvent event = new ChunkUnloadEvent(chunk.bukkitChunk);
            server.getPluginManager().callEvent(event);
            if (!event.isCancelled()) {
                chunk.removeEntities();
                this.saveChunk(chunk);
                this.saveChunkNOP(chunk);
                // this.unloadQueue.remove(integer);
                this.chunks.remove(chunkcoordinates); // CraftBukkit
            }
        }
        // CraftBukkit end

        if (this.e != null) {
            this.e.a();
        }
    }

    return this.chunkProvider.unloadChunks();
}
 
Example 38
Project: FramePicture   File: ChunkListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
	if (event.isCancelled()) return;
	Chunk chunk = event.getChunk();
	List<Frame> frames = this.manager.getFramesInChunk(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
	
	for (Frame frame : frames) {
		frame.setEntity(null);
	}
}
 
Example 39
Project: ItemCase-Depreciated   File: WorldListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
    for (Itemcase itemcase : ItemCase.getInstance().getItemcaseManager()
            .getItemcases()) {
        if (event.getChunk().equals(itemcase.getBlock().getChunk())
                && itemcase.isChunkLoaded() == true) {
            itemcase.setChunkLoaded(false);
        }
    }
}
 
Example 40
Project: ZentrelaRPG   File: EnvironmentManager.java   View source code 4 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
    despawnEntities(event.getChunk().getEntities());
}