org.bukkit.Chunk#getX ( )源码实例Demo

下面列出了org.bukkit.Chunk#getX ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Holograms   文件: HologramListener.java
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
    Chunk chunk = event.getChunk();
    for (Entity entity : chunk.getEntities()) {
        HologramEntity hologramEntity = plugin.getEntityController().getHologramEntity(entity);
        if (hologramEntity != null) {
            hologramEntity.remove();
        }
    }
    Collection<Hologram> holograms = plugin.getHologramManager().getActiveHolograms().values();
    for (Hologram holo : holograms) {
        Location loc = holo.getLocation();
        int chunkX = (int) Math.floor(loc.getBlockX() / 16.0D);
        int chunkZ = (int) Math.floor(loc.getBlockZ() / 16.0D);
        if (chunkX == chunk.getX() && chunkZ == chunk.getZ()) {
            holo.despawn();
        }
    }
}
 
源代码2 项目: Holograms   文件: HologramListener.java
@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);
        }
    }
}
 
源代码3 项目: RedProtect   文件: RegionManager.java
public Set<Region> getRegionsForChunk(Chunk chunk) {
    Set<Region> regions = new HashSet<>();
    for (Region region : RedProtect.get().rm.getRegionsByWorld(chunk.getWorld().getName())) {
        int minChunkX = (int) Math.floor(region.getMinMbrX() / 16f);
        int maxChunkX = (int) Math.floor(region.getMaxMbrX() / 16f);
        int minChunkZ = (int) Math.floor(region.getMinMbrZ() / 16f);
        int maxChunkZ = (int) Math.floor(region.getMaxMbrZ() / 16f);
        if (chunk.getX() >= minChunkX && chunk.getX() <= maxChunkX && chunk.getZ() >= minChunkZ && chunk.getZ() <= maxChunkZ) {
            regions.add(region);
        }
    }
    return regions;
}
 
源代码4 项目: GiantTrees   文件: TreePopulator.java
@Override
public void
    populate(final World world, final Random random, final Chunk chunk) {
  final Location refPoint = new Location(world, (chunk.getX() * 16)
                                                + random.nextInt(16), 64,
                                         (chunk.getZ() * 16)
                                             + random.nextInt(16));
  refPoint.setY(this.getHighestSoil(world.getHighestBlockAt(refPoint)));

  final Biome biome = this.simplifyBiome(world.getBiome(refPoint.getBlockX(),
                                                        refPoint.getBlockZ()));
  if (this.isAcceptableBiome(biome) && this.treeCanGrow(random)) {
    final String treeType = biome.name();

    final File treeFile = new File(this.plugin.getDataFolder(), "biome."
                                                                + treeType
                                                                + ".xml");
    final File rootFile = new File(this.plugin.getDataFolder(), "biome."
                                                                + treeType
                                                                + ".root.xml");

    if (treeFile.exists()) {
      final TreeRenderer renderer = new TreeRenderer(this.plugin);
      renderer.renderTree(refPoint, treeFile, rootFile, random.nextInt(),
                          false);
    }
  }
}
 
源代码5 项目: GlobalWarming   文件: Fire.java
/**
 * Set a random set of loaded blocks on fire
 */
private void setFire(World world, int blocks) {
    if (world != null) {
        int count = world.getLoadedChunks().length;
        for (int i = 0; i < blocks; i++) {
            int chunkIndex = GlobalWarming.getInstance().getRandom().nextInt(count);
            Chunk chunk = world.getLoadedChunks()[chunkIndex];
            int x = (chunk.getX() * BLOCKS_PER_CHUNK) + GlobalWarming.getInstance().getRandom().nextInt(BLOCKS_PER_CHUNK);
            int z = (chunk.getZ() * BLOCKS_PER_CHUNK) + GlobalWarming.getInstance().getRandom().nextInt(BLOCKS_PER_CHUNK);
            Block topBlock = world.getHighestBlockAt(x, z);
            topBlock.getRelative(BlockFace.UP).setType(Material.FIRE);
        }
    }
}
 
源代码6 项目: FastAsyncWorldedit   文件: AsyncChunk.java
@Override
public boolean equals(Object obj) {
    if (obj == null || !(obj instanceof Chunk)) {
        return false;
    }
    Chunk other = (Chunk) obj;
    return other.getX() == x && other.getZ() == z && world.equals(other.getWorld());
}
 
源代码7 项目: Civs   文件: UnloadedInventoryHandler.java
public void syncAllInventoriesInChunk(Chunk chunk) {
    String chunkString = "c:" + chunk.getX() + ":" + chunk.getZ();
    if (!unloadedChestInventories.containsKey(chunkString)) {
        return;
    }
    for (String locationString : unloadedChestInventories.get(chunkString).keySet()) {
        syncInventory(locationString);
    }
}
 
源代码8 项目: civcraft   文件: TradeGoodPopulator.java
@Override
public void populate(World world, Random random, Chunk source) {
   	
   	ChunkCoord cCoord = new ChunkCoord(source);
   	TradeGoodPick pick = CivGlobal.preGenerator.goodPicks.get(cCoord);
   	if (pick != null) {
		int centerX = (source.getX() << 4) + 8;
		int centerZ = (source.getZ() << 4) + 8;
		int centerY = world.getHighestBlockYAt(centerX, centerZ);
		BlockCoord coord = new BlockCoord(world.getName(), centerX, centerY, centerZ);

		if (checkForDuplicateTradeGood(world.getName(), centerX, centerY, centerZ)) {
			return;
		}
		
		// Determine if we should be a water good.
		ConfigTradeGood good;
		if (ItemManager.getBlockTypeIdAt(world, centerX, centerY-1, centerZ) == CivData.WATER || 
			ItemManager.getBlockTypeIdAt(world, centerX, centerY-1, centerZ) == CivData.WATER_RUNNING) {
			good = pick.waterPick;
		}  else {
			good = pick.landPick;
		}
		
		// Randomly choose a land or water good.
		if (good == null) {
			System.out.println("Could not find suitable good type during populate! aborting.");
			return;
		}
		
		// Create a copy and save it in the global hash table.
		buildTradeGoodie(good, coord, world, false);
   	}
	
   }
 
源代码9 项目: GriefDefender   文件: GDClaimManager.java
private long getChunkKey(Chunk chunk) {
    return (long) chunk.getX() & 0xffffffffL | ((long) chunk.getZ() & 0xffffffffL) << 32;
}
 
源代码10 项目: civcraft   文件: TradeGoodPostGenTask.java
@Override
public void run() {
	World world = Bukkit.getWorld("world");
	BlockCoord bcoord2 = new BlockCoord();

	for(int i = 0; i < amount; i++) {
		TradeGoodPick pick = picksQueue.poll();
		if (pick == null) {
			return;
		}
		
		ChunkCoord coord = pick.chunkCoord;
		Chunk chunk = world.getChunkAt(coord.getX(), coord.getZ());
		
		int centerX = (chunk.getX() << 4) + 8;
		int centerZ = (chunk.getZ() << 4) + 8;
		int centerY = world.getHighestBlockYAt(centerX, centerZ);
		
		
		
		bcoord2.setWorldname("world");
		bcoord2.setX(centerX);
		bcoord2.setY(centerY - 1);
		bcoord2.setZ(centerZ);
		
		/* try to detect already existing trade goods. */
		while(true) {
			Block top = world.getBlockAt(bcoord2.getX(), bcoord2.getY(), bcoord2.getZ());
			
			if (!top.getChunk().isLoaded()) {
				top.getChunk().load();
			}
			
			if (ItemManager.getId(top) == CivData.BEDROCK) {
				ItemManager.setTypeId(top, CivData.AIR);
    			ItemManager.setData(top, 0, true);
    			bcoord2.setY(bcoord2.getY() - 1);
    			
    			top = top.getRelative(BlockFace.NORTH);
    			if (ItemManager.getId(top) == CivData.WALL_SIGN) {
    				ItemManager.setTypeId(top, CivData.AIR);
	    			ItemManager.setData(top, 0, true);	    			
	    		}
    			
    			top = top.getRelative(BlockFace.SOUTH);
    			if (ItemManager.getId(top) == CivData.WALL_SIGN) {
    				ItemManager.setTypeId(top, CivData.AIR);
	    			ItemManager.setData(top, 0, true);	    			
	    		}
    			
    			top = top.getRelative(BlockFace.EAST);
    			if (ItemManager.getId(top) == CivData.WALL_SIGN) {
    				ItemManager.setTypeId(top, CivData.AIR);
	    			ItemManager.setData(top, 0, true);	    			
	    		}
    			
    			top = top.getRelative(BlockFace.WEST);
    			if (ItemManager.getId(top) == CivData.WALL_SIGN) {
    				ItemManager.setTypeId(top, CivData.AIR);
	    			ItemManager.setData(top, 0, true);
	    		}
			} else {
				break;
			}
			
		}
		
		centerY = world.getHighestBlockYAt(centerX, centerZ);
		
		// Determine if we should be a water good.
		ConfigTradeGood good;
		if (ItemManager.getBlockTypeIdAt(world, centerX, centerY-1, centerZ) == CivData.WATER || 
			ItemManager.getBlockTypeIdAt(world, centerX, centerY-1, centerZ) == CivData.WATER_RUNNING) {
			good = pick.waterPick;
		}  else {
			good = pick.landPick;
		}
		
		// Randomly choose a land or water good.
		if (good == null) {
			System.out.println("Could not find suitable good type during populate! aborting.");
			continue;
		}
		
		// Create a copy and save it in the global hash table.
		BlockCoord bcoord = new BlockCoord(world.getName(), centerX, centerY, centerZ);
		TradeGoodPopulator.buildTradeGoodie(good, bcoord, world, true);
		
	}
}
 
源代码11 项目: PGM   文件: ChunkVector.java
public static ChunkVector of(Chunk chunk) {
  return new ChunkVector(chunk.getX(), chunk.getZ());
}
 
源代码12 项目: factions-top   文件: ChunkPos.java
public static ChunkPos of(Chunk chunk) {
    return new ChunkPos(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
}
 
源代码13 项目: QuickShop-Reremake   文件: SubCommand_Find.java
@Override
public void onCommand(
        @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
    if (!(sender instanceof Player)) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("Only player can run this command", sender));
        return;
    }

    if (cmdArg.length < 1) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.no-type-given", sender));
        return;
    }

    final StringBuilder sb = new StringBuilder(cmdArg[0]);

    for (int i = 1; i < cmdArg.length; i++) {
        sb.append(" ").append(cmdArg[i]);
    }

    final String lookFor = sb.toString().toLowerCase();
    final Player p = (Player) sender;
    final Location loc = p.getEyeLocation().clone();
    final double minDistance = plugin.getConfig().getInt("shop.find-distance");
    double minDistanceSquared = minDistance * minDistance;
    final int chunkRadius = (int) minDistance / 16 + 1;
    Shop closest = null;
    CompletableFuture<Chunk> future = new CompletableFuture<>();
    plugin.getBukkitAPIWrapper().getChunkAt(loc.getWorld(), loc, future);
    final Chunk c;
    try {
        c = future.get();
    } catch (Exception asyncErr) {
        MsgUtil.sendMessage(sender, "Cannot execute the command, see console for details.");
        plugin.getSentryErrorReporter().sendError(asyncErr, "Unknown errors");
        plugin.getSentryErrorReporter().ignoreThrow();
        asyncErr.printStackTrace();
        return;
    }
    for (int x = -chunkRadius + c.getX(); x < chunkRadius + c.getX(); x++) {
        for (int z = -chunkRadius + c.getZ(); z < chunkRadius + c.getZ(); z++) {
            final Chunk d = c.getWorld().getChunkAt(x, z);
            final Map<Location, Shop> inChunk = plugin.getShopManager().getShops(d);

            if (inChunk == null) {
                continue;
            }

            for (Shop shop : inChunk.values()) {
                if (!Util.getItemStackName(shop.getItem()).toLowerCase().contains(lookFor)) {
                    continue;
                }

                if (shop.getLocation().distanceSquared(loc) >= minDistanceSquared) {
                    continue;
                }

                closest = shop;
                minDistanceSquared = shop.getLocation().distanceSquared(loc);
            }
        }
    }

    if (closest == null) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("no-nearby-shop", sender, cmdArg[0]));
        return;
    }

    final Location lookat = closest.getLocation().clone().add(0.5, 0.5, 0.5);
    // Hack fix to make /qs find not used by /back
    plugin
            .getBukkitAPIWrapper()
            .teleportEntity(
                    p,
                    Util.lookAt(loc, lookat).add(0, -1.62, 0),
                    PlayerTeleportEvent.TeleportCause.UNKNOWN);
    MsgUtil.sendMessage(p,
            MsgUtil.getMessage(
                    "nearby-shop-this-way", sender, Integer.toString((int) Math.floor(Math.sqrt(minDistanceSquared)))));
}
 
源代码14 项目: GlobalWarming   文件: GChunk.java
public GChunk(Chunk chunk) {
    this.world = chunk.getWorld().getName();
    this.x = chunk.getX();
    this.z = chunk.getZ();
}
 
源代码15 项目: ProjectAres   文件: Regions.java
public static Region forChunk(Chunk chunk) {
    Vector min = new Vector(chunk.getX() * 16, 0, chunk.getZ() * 16);
    return new CuboidRegion(min, new Vector(min.getX() + 16, 256, min.getZ() + 16));
}
 
源代码16 项目: ProjectAres   文件: ChunkVector.java
public static ChunkVector of(Chunk chunk) {
    return new ChunkVector(chunk.getX(), chunk.getZ());
}
 
源代码17 项目: BedwarsRel   文件: Region.java
public boolean chunkIsInRegion(Chunk chunk) {
  return (chunk.getX() >= this.minCorner.getX() && chunk.getX() <= this.maxCorner.getX()
      && chunk.getZ() >= this.minCorner.getZ() && chunk.getZ() <= this.maxCorner.getZ());
}
 
源代码18 项目: ClaimChunk   文件: PlayerMovementHandler.java
@SuppressWarnings("unused")
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
    if (e != null && !e.isCancelled() && e.getTo() != null) {
        // Get the previous and current chunks
        Chunk prev = e.getFrom().getChunk();
        Chunk to = e.getTo().getChunk();

        // Make sure the player moved into a new chunk
        if (prev.getX() != to.getX() || prev.getZ() != to.getZ()) {
            // If the claim is currently autoclaiming, try to claim this chunk
            if (AutoClaimHandler.inList(e.getPlayer())) {
                claimChunk.getCommandHandler().mainHandler.claimChunk(e.getPlayer(), to);
                return;
            }

            ChunkHandler ch = claimChunk.getChunkHandler();

            // Check if the previous chunk was already claimed
            boolean lastClaimed = ch.isClaimed(prev.getWorld(), prev.getX(), prev.getZ());

            // Check if the new chunk is already claimed
            if (ch.isClaimed(to.getWorld(), to.getX(), to.getZ())) {
                // If the new chunk and the previous chunk were claimed, check if the owners differ
                if (lastClaimed) {
                    UUID prevOwner = ch.getOwner(prev.getWorld(), prev.getX(), prev.getZ());
                    UUID newOwner = ch.getOwner(to.getWorld(), to.getX(), to.getZ());

                    // Only display the new chunk's owner if they differ from the previous chunk's owner
                    if ((prevOwner == null && newOwner == null) || (prevOwner != null && !prevOwner.equals(newOwner))) {
                        showTitle(e.getPlayer(), to);
                    }
                } else {
                    // Show the player the chunk's owner
                    showTitle(e.getPlayer(), to);
                }
            } else {
                // The player entered an unclaimed chunk from a claimed chunk
                if (lastClaimed) {
                    UUID lastOwner = ch.getOwner(prev.getWorld(), prev.getX(), prev.getZ());
                    String name = claimChunk.getPlayerHandler().getChunkName(lastOwner);
                    String msg = (e.getPlayer().getUniqueId().equals(lastOwner) ? claimChunk.getMessages().chunkLeaveSelf : claimChunk.getMessages().chunkLeave)
                            .replace("%%PLAYER%%",
                                    ((name == null) ? claimChunk.getMessages().chunkLeaveUnknown : name));
                    Utils.toPlayer(e.getPlayer(), msg);
                }
            }
        }
    }
}
 
源代码19 项目: AreaShop   文件: SignsFeature.java
/**
 * Convert a chunk to a string to use as map key.
 * Use a Location argument to prevent chunk loading!
 * @param chunk The location to get the key for
 * @return A string to use in a map for a chunk
 */
public static String chunkToString(Chunk chunk) {
	return chunk.getWorld().getName() + ";" + chunk.getX() + ";" + chunk.getZ();
}
 
源代码20 项目: ClaimChunk   文件: ChunkPos.java
/**
 * Create an instance of a chunk position from Spigot's chunk position
 * representation.
 *
 * @param chunk The Spigot chunk representation.
 */
public ChunkPos(Chunk chunk) {
    this(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
}