下面列出了怎么用org.bukkit.event.world.ChunkLoadEvent的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler(priority = EventPriority.LOWEST)
public void onChunkLoad(ChunkLoadEvent event) {
if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getWorld().getUID())) {
return;
}
final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getWorld().getUID());
final GDChunk gdChunk = claimWorldManager.getChunk(event.getChunk());
if (gdChunk != null) {
try {
gdChunk.loadChunkTrackingData();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void repairChunk(ChunkLoadEvent event) {
if (this.repairedChunks.put(event.getWorld(), event.getChunk())) {
// Replace formerly invisible half-iron-door blocks with barriers
for (Block ironDoor : event.getChunk().getBlocks(Material.IRON_DOOR_BLOCK)) {
BlockFace half = (ironDoor.getData() & 8) == 0 ? BlockFace.DOWN : BlockFace.UP;
if (ironDoor.getRelative(half.getOppositeFace()).getType() != Material.IRON_DOOR_BLOCK) {
ironDoor.setType(Material.BARRIER, false);
}
}
// Remove all block 36 and remember the ones at y=0 so VoidFilter can check them
for (Block block36 : event.getChunk().getBlocks(Material.PISTON_MOVING_PIECE)) {
if (block36.getY() == 0) {
block36Locations
.get(event.getWorld())
.add(block36.getX(), block36.getY(), block36.getZ());
}
block36.setType(Material.AIR, false);
}
}
}
@EventHandler
public void findSuperMob(ChunkLoadEvent event) {
for (Entity entity : event.getChunk().getEntities()) {
if (SuperMobProperties.isValidSuperMobType(entity))
if (((LivingEntity) entity).getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() ==
SuperMobProperties.getDataInstance(entity).getSuperMobMaxHealth())
if (!EntityTracker.isSuperMob(entity))
EntityTracker.registerSuperMob((LivingEntity) entity);
else if (entity instanceof Villager) {
}
}
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
Chunk chunk = event.getChunk();
if (chunk == null || !chunk.isLoaded()) {
return;
}
Collection<Hologram> holograms = plugin.getHologramManager().getActiveHolograms().values();
for (Hologram holo : holograms) {
int chunkX = (int) Math.floor(holo.getLocation().getBlockX() / 16.0D);
int chunkZ = (int) Math.floor(holo.getLocation().getBlockZ() / 16.0D);
if (chunkX == chunk.getX() && chunkZ == chunk.getZ()) {
plugin.getServer().getScheduler().runTaskLater(plugin, holo::spawn, 10L);
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onChunkLoad(ChunkLoadEvent event) {
for (Entity e : event.getChunk().getEntities()) {
if (e instanceof Monster) {
e.remove();
return;
}
if (e instanceof IronGolem) {
e.remove();
return;
}
}
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
final Chunk chunk = event.getChunk();
Bukkit.getScheduler().runTask(GameHandler.getGameHandler().getPlugin(), new Runnable() {
@Override
public void run() {
for (Block block36 : chunk.getBlocks(Material.getMaterial(36))) {
block36.setType(Material.AIR);
block36.setMetadata("block36", new FixedMetadataValue(GameHandler.getGameHandler().getPlugin(), true));
}
for (Block door : chunk.getBlocks(Material.IRON_DOOR_BLOCK)) {
if (door.getRelative(BlockFace.DOWN).getType() != Material.IRON_DOOR_BLOCK
&& door.getRelative(BlockFace.UP).getType() != Material.IRON_DOOR_BLOCK)
door.setType(Material.BARRIER);
}
}
});
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChunkLoad(ChunkLoadEvent e) {
if (e.isNewChunk()) {
return;
}
final Map<Location, Shop> inChunk = plugin.getShopManager().getShops(e.getChunk());
if (inChunk == null) {
return;
}
Bukkit.getScheduler().runTaskLater(plugin, () -> {
for (Shop shop : inChunk.values()) {
shop.onLoad();
}
}, 1);
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent e) {
if(sm.getCustomConfig().getStringList("no-stack-worlds")
.contains(e.getWorld().getName())){
return;
}
for(Entity currentEntity : e.getChunk().getEntities()){
if(!(currentEntity instanceof Mob)){
continue;
}
// Check if has been cached.
if(sm.getCache().containsKey(currentEntity.getUniqueId())){
int cacheSize = sm.getCache().get(currentEntity.getUniqueId());
sm.getCache().remove(currentEntity.getUniqueId());
StackTools.setSize(currentEntity, cacheSize);
continue;
}
if(currentEntity.getCustomName() != null){
continue;
}
if(sm.getTraitManager().checkTraits(currentEntity)){
continue;
}
if(sm.getHookManager().cantStack(currentEntity)){
continue;
}
if(sm.getLogic().doChecks(currentEntity)){
continue;
}
StackTools.setSize(currentEntity, GlobalValues.NOT_ENOUGH_NEAR);
}
}
@EventHandler
public void chunkLoad(@Nonnull ChunkLoadEvent event) {
Arrays.stream(event.getChunk().getTileEntities())
.filter(blockState -> blockState instanceof Sign)
.map(blockState -> (Sign) blockState)
.forEach(sign -> lastSeenSigns.put(sign.getLocation(), sign));
}
@EventHandler
public void chunkLoad(@Nonnull ChunkLoadEvent event) {
Arrays.stream(event.getChunk().getTileEntities())
.filter(blockState -> blockState instanceof Skull)
.map((blockState) -> (Skull) blockState)
.forEach(skull -> lastSeenSkulls.put(skull.getLocation(), skull));
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
Chunk chunk = event.getChunk();
for (Region r : new HashMap<>(orphanCarts).keySet()) {
StorageMinecart sm = orphanCarts.get(r);
if (Util.isWithinChunk(chunk, sm.getLocation())) {
carts.put(r, sm);
orphanCarts.remove(r);
}
}
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
if (ConfigManager.getInstance().isDebugLog()) {
DebugLogger.chunkLoads++;
}
// System.out.println("chunk loaded: " + event.getChunk().getX() + ", " + event.getChunk().getZ());
UnloadedInventoryHandler.getInstance().syncAllInventoriesInChunk(event.getChunk());
}
/**
* Prevent FireWorks from loading chunks
* @param event
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onChunkLoad(ChunkLoadEvent event) {
if (!Settings.IMP.TICK_LIMITER.FIREWORKS_LOAD_CHUNKS) {
Chunk chunk = event.getChunk();
Entity[] entities = chunk.getEntities();
World world = chunk.getWorld();
Exception e = new Exception();
int start = 14;
int end = 22;
int depth = Math.min(end, getDepth(e));
for (int frame = start; frame < depth; frame++) {
StackTraceElement elem = getElement(e, frame);
if (elem == null) return;
String className = elem.getClassName();
int len = className.length();
if (className != null) {
if (len > 15 && className.charAt(len - 15) == 'E' && className.endsWith("EntityFireworks")) {
for (Entity ent : world.getEntities()) {
if (ent.getType() == EntityType.FIREWORK) {
Vector velocity = ent.getVelocity();
double vertical = Math.abs(velocity.getY());
if (Math.abs(velocity.getX()) > vertical || Math.abs(velocity.getZ()) > vertical) {
Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled rogue FireWork at " + ent.getLocation());
ent.remove();
}
}
}
}
}
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onChunkLoad(ChunkLoadEvent event) {
for(Entity entity : event.getChunk().getEntities()) {
if(entity instanceof LivingEntity) {
EntityIdList.addEntity((LivingEntity)entity);
}
}
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent e) {
if (!plugin.getShopDatabase().isInitialized()) {
return;
}
// Wait 10 ticks after first event is triggered, so that multiple
// chunk loads can be handled at the same time without having to
// send a database request for each chunk.
if (newLoadedChunks.isEmpty()) {
new BukkitRunnable(){
@Override
public void run() {
int chunkCount = newLoadedChunks.size();
plugin.getShopUtils().loadShops(newLoadedChunks.toArray(new Chunk[chunkCount]), new Callback<Integer>(plugin) {
@Override
public void onResult(Integer result) {
if (result == 0) {
return;
}
plugin.debug("Loaded " + result + " shops in " + chunkCount + " chunks");
}
@Override
public void onError(Throwable throwable) {
// Database connection probably failed => disable plugin to prevent more errors
plugin.getLogger().severe("Failed to load shops in newly loaded chunks");
plugin.debug("Failed to load shops in newly loaded chunks");
if (throwable != null) plugin.debug(throwable);
}
});
newLoadedChunks.clear();
}
}.runTaskLater(plugin, 10L);
}
newLoadedChunks.add(e.getChunk());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onChunkLoad(ChunkLoadEvent event) {
List<RegionSign> chunkSigns = signsByChunk.get(chunkToString(event.getChunk()));
if(chunkSigns == null) {
return;
}
Do.forAll(chunkSigns, RegionSign::update);
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onChunkLoad(ChunkLoadEvent event) {
if (!Settings.saveEntities || !IslandGuard.inWorld(event.getWorld())) {
return;
}
Arrays.asList(event.getChunk().getEntities()).forEach(entity -> {
String loc = entities.getString(event.getWorld().getName() + "." + event.getChunk().getX() + "." + event.getChunk().getZ() + "."
+ entity.getUniqueId().toString(), "");
if (!loc.isEmpty()) {
entity.setMetadata("spawnLoc", new FixedMetadataValue(plugin, loc ));
}
});
// Delete the chunk data
entities.set(event.getWorld().getName() + "." + event.getChunk().getX() + "." + event.getChunk().getZ() , null);
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onChunkLoad(final ChunkLoadEvent event) {
if (worldLoaded) {
return;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: " + event.getEventName() + " : " + event.getWorld().getName());
if (event.getWorld().getName().equals(Settings.worldName) || event.getWorld().getName().equals(Settings.worldName + "_nether")) {
return;
}
// Load the world
worldLoaded = true;
ASkyBlock.getIslandWorld();
}
@EventHandler(priority = EventPriority.LOWEST)
public void onChunkLoad(ChunkLoadEvent e) {
if (ASkyBlock.getIslandWorld() == null || e.getWorld() != ASkyBlock.getIslandWorld()) {
if (DEBUG)
Bukkit.getLogger().info("DEBUG: not right world");
return;
}
if (e.getChunk().getBlock(0, 0, 0).getType().equals(Material.BEDROCK)) {
e.getWorld().regenerateChunk(e.getChunk().getX(), e.getChunk().getZ());
Bukkit.getLogger().warning("Regenerating superflat chunk at " + (e.getChunk().getX() * 16) + "," + (e.getChunk().getZ() * 16));
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChunkLoad(ChunkLoadEvent event) {
for (Hologram h : HoloAPI.getManager().getAllHolograms().keySet()) {
if (h.getDefaultLocation().getChunk().equals(event.getChunk())) {
for (Entity e : h.getDefaultLocation().getWorld().getEntities()) {
if (e instanceof Player) {
if (h.getVisibility().isVisibleTo((Player) e, h.getSaveId())) {
h.show((Player) e, true);
}
}
}
}
}
}
@EventHandler (priority = EventPriority.MONITOR)
public void onChunkLoad(ChunkLoadEvent event) {
Chunk chunk = event.getChunk();
// Other plugins could call this event wrongly, check if the chunk is actually loaded.
if (chunk.isLoaded()) {
// In case another plugin loads the chunk asynchronously always make sure to load the holograms on the main thread.
if (Bukkit.isPrimaryThread()) {
processChunkLoad(chunk);
} else {
Bukkit.getScheduler().runTask(HolographicDisplays.getInstance(), () -> processChunkLoad(chunk));
}
}
}
@EventHandler
void onChunkLoad(ChunkLoadEvent event) {
final Chunk chunk = event.getChunk();
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
public void run() {
if (chunk.isLoaded()) {
plugin.loadShopkeepersInChunk(chunk);
}
}
}, 2);
}
@EventHandler
private void onLoad(ChunkLoadEvent event) {
Chunk loadedChunk = event.getChunk();
for (EntityChunkData entityChunkData : SPAWN_QUEUE) {
if (loadedChunk == entityChunkData.getRespawnLocation().getChunk()) {
if (entityChunkData.getControllableEntity().spawn(entityChunkData.getRespawnLocation()) == SpawnResult.FAILED) {
throw new ControllableEntitySpawnException();
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChunkLoad(ChunkLoadEvent event) {
if(world.equals(event.getWorld())) {
checkChunk(event.getChunk());
}
}
@EventHandler
private void onChunkLoad(ChunkLoadEvent event) {
load(event.getChunk());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChunkLoad(ChunkLoadEvent e) {
handleChunkLoadSync(e.getChunk(), false);
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
for (NPCEntity npcEntity : EntityTracker.getNPCEntities())
if (npcEntity.getSpawnLocation().getChunk().equals(event.getChunk()))
npcEntity.respawnNPC();
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent chunkLoadEvent) {
checkSafety(chunkLoadEvent);
}
@EventHandler
public static void onChunkLoad(ChunkLoadEvent event) {
Chunk chunk = event.getChunk();
long pair = MathMan.pairInt(chunk.getX(), chunk.getZ());
keepLoaded.putIfAbsent(pair, Fawe.get().getTimer().getTickStart());
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent chunkLoadEvent) {
checkSafety(chunkLoadEvent);
}