Java Code Examples for org.spongepowered.api.util.blockray.BlockRay#next()
The following examples show how to use
org.spongepowered.api.util.blockray.BlockRay#next() .
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: PlayerEventHandler.java From GriefPrevention with MIT License | 5 votes |
private GPClaim findNearbyClaim(Player player) { int maxDistance = GriefPreventionPlugin.instance.maxInspectionDistance; BlockRay<World> blockRay = BlockRay.from(player).distanceLimit(maxDistance).build(); GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); GPClaim claim = null; int count = 0; while (blockRay.hasNext()) { BlockRayHit<World> blockRayHit = blockRay.next(); Location<World> location = blockRayHit.getLocation(); claim = this.dataStore.getClaimAt(location); if (claim != null && !claim.isWilderness() && (playerData.visualBlocks == null || (claim.id != playerData.visualClaimId))) { playerData.lastValidInspectLocation = location; return claim; } BlockType blockType = location.getBlockType(); if (blockType != BlockTypes.AIR && blockType != BlockTypes.TALLGRASS) { break; } count++; } if (count == maxDistance) { GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.claimTooFar.toText()); } else if (claim != null && claim.isWilderness()){ GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.blockNotClaimed.toText()); } return claim; }
Example 2
Source File: BlockUtils.java From GriefPrevention with MIT License | 5 votes |
public static Optional<Location<World>> getTargetBlock(Player player, GPPlayerData playerData, int maxDistance, boolean ignoreAir) throws IllegalStateException { BlockRay<World> blockRay = BlockRay.from(player).distanceLimit(maxDistance).build(); GPClaim claim = null; if (playerData.visualClaimId != null) { claim = (GPClaim) GriefPreventionPlugin.instance.dataStore.getClaim(player.getWorld().getProperties(), playerData.visualClaimId); } while (blockRay.hasNext()) { BlockRayHit<World> blockRayHit = blockRay.next(); if (claim != null) { for (Vector3i corner : claim.getVisualizer().getVisualCorners()) { if (corner.equals(blockRayHit.getBlockPosition())) { return Optional.of(blockRayHit.getLocation()); } } } if (ignoreAir) { if (blockRayHit.getLocation().getBlockType() != BlockTypes.TALLGRASS) { return Optional.of(blockRayHit.getLocation()); } } else { if (blockRayHit.getLocation().getBlockType() != BlockTypes.AIR && blockRayHit.getLocation().getBlockType() != BlockTypes.TALLGRASS) { return Optional.of(blockRayHit.getLocation()); } } } return Optional.empty(); }
Example 3
Source File: BlockInfoExecutor.java From EssentialCmds with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { if (src instanceof Player) { Player player = (Player) src; BlockRay<World> playerBlockRay = BlockRay.from(player).blockLimit(5).build(); BlockRayHit<World> finalHitRay = null; while (playerBlockRay.hasNext()) { BlockRayHit<World> currentHitRay = playerBlockRay.next(); if (!player.getWorld().getBlockType(currentHitRay.getBlockPosition()).equals(BlockTypes.AIR)) { finalHitRay = currentHitRay; break; } } if (finalHitRay != null) { player.sendMessage(Text.of(TextColors.GOLD, "The name of the block you're looking at is: ", TextColors.GRAY, finalHitRay.getLocation().getBlock().getType().getTranslation().get())); player.sendMessage(Text.of(TextColors.GOLD, "The ID of the block you're looking at is: ", TextColors.GRAY, finalHitRay.getLocation().getBlock().getName())); Optional<Object> metaDataQuery = finalHitRay.getLocation().getBlock().toContainer().get(DataQuery.of("UnsafeMeta")); player.sendMessage(Text.of(TextColors.GOLD, "The meta of the block you're looking at is: ", TextColors.GRAY, metaDataQuery.isPresent() ? metaDataQuery.get().toString() : 0)); } else { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You're not looking at any block within range.")); } } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use this command.")); } return CommandResult.success(); }
Example 4
Source File: MobSpawnExecutor.java From EssentialCmds with MIT License | 5 votes |
public Location<World> getSpawnLocFromPlayerLoc(Player player) { BlockRay<World> playerBlockRay = BlockRay.from(player).blockLimit(350).build(); BlockRayHit<World> finalHitRay = null; while (playerBlockRay.hasNext()) { BlockRayHit<World> currentHitRay = playerBlockRay.next(); if (!player.getWorld().getBlockType(currentHitRay.getBlockPosition()).equals(BlockTypes.AIR)) { finalHitRay = currentHitRay; break; } } Location<World> spawnLocation = null; if (finalHitRay == null) { spawnLocation = player.getLocation(); } else { spawnLocation = finalHitRay.getLocation(); } return spawnLocation; }
Example 5
Source File: PlayerEventHandler.java From GriefDefender with MIT License | 4 votes |
private GDClaim findNearbyClaim(Player player, GDPlayerData playerData, int maxDistance, boolean hidingVisuals) { if (maxDistance <= 20) { maxDistance = 100; } BlockRay<World> blockRay = BlockRay.from(player).distanceLimit(maxDistance).build(); GDClaim playerClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation()); GDClaim firstClaim = null; GDClaim claim = null; playerData.lastNonAirInspectLocation = null; playerData.lastValidInspectLocation = null; while (blockRay.hasNext()) { BlockRayHit<World> blockRayHit = blockRay.next(); Location<World> location = blockRayHit.getLocation(); claim = this.dataStore.getClaimAt(location); if (firstClaim == null && !claim.isWilderness()) { if (hidingVisuals) { if (claim.hasActiveVisual(player)) { firstClaim = claim; } } else { firstClaim = claim; } } if (playerData.lastNonAirInspectLocation == null && !location.getBlockType().equals(BlockTypes.AIR)) { playerData.lastNonAirInspectLocation = location; } if (claim != null && !claim.isWilderness() && !playerClaim.getUniqueId().equals(claim.getUniqueId())) { playerData.lastValidInspectLocation = location; } if (!location.getBlockType().equals(BlockTypes.AIR) && !NMSUtil.getInstance().isBlockTransparent(location.getBlock())) { break; } } if (claim == null || claim.isWilderness()) { if (firstClaim == null) { return GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(player.getWorld().getUniqueId()).getWildernessClaim(); } return firstClaim; } return claim; }
Example 6
Source File: EntityInfoExecutor.java From EssentialCmds with MIT License | 4 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { if (src instanceof Player) { Player player = (Player) src; BlockRay<World> playerBlockRay = BlockRay.from(player).blockLimit(5).build(); BlockRayHit<World> finalHitRay = null; while (playerBlockRay.hasNext()) { BlockRayHit<World> currentHitRay = playerBlockRay.next(); if (!player.getWorld().getBlockType(currentHitRay.getBlockPosition()).equals(BlockTypes.AIR)) { finalHitRay = currentHitRay; break; } } if (finalHitRay != null) { Entity entityFound = null; for (Entity entity : player.getWorld().getEntities()) { if (entity.getLocation().getBlockPosition().equals(finalHitRay.getBlockPosition().add(new Vector3i(0, 1, 0)))) { entityFound = entity; break; } } if (entityFound != null) { player.sendMessage(Text.of(TextColors.GOLD, "The name of the entity you're looking at is: ", TextColors.GRAY, entityFound.getTranslation().get())); player.sendMessage(Text.of(TextColors.GOLD, "The ID of the entity you're looking at is: ", TextColors.GRAY, entityFound.getType().getId())); } else { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "No entity found!")); } } else { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You're not looking at any block within range.")); } } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use this command.")); } return CommandResult.success(); }
Example 7
Source File: ThruExecutor.java From EssentialCmds with MIT License | 4 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { if (src instanceof Player) { Player player = (Player) src; BlockRay<World> playerBlockRay = BlockRay.from(player).blockLimit(25).build(); BlockRayHit<World> finalHitRay = null; Location<World> location = null; while (playerBlockRay.hasNext()) { BlockRayHit<World> currentHitRay = playerBlockRay.next(); if (finalHitRay != null && player.getWorld().getBlockType(currentHitRay.getBlockPosition()).equals(BlockTypes.AIR)) { location = currentHitRay.getLocation(); break; } else if (player.getWorld().getBlockType(currentHitRay.getBlockPosition()).equals(BlockTypes.AIR)) { continue; } else { finalHitRay = currentHitRay; } } if (finalHitRay != null && location != null) { if (player.setLocationSafely(location)) { player.sendMessage(Text.of(TextColors.LIGHT_PURPLE, "Whoosh!")); } else { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "No free spot ahead of you found.")); } } else if (finalHitRay == null) { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You are not facing a wall.")); } else { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "No free spot ahead of you found.")); } } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /thru!")); } return CommandResult.success(); }
Example 8
Source File: JumpExecutor.java From EssentialCmds with MIT License | 4 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { if (src instanceof Player) { Player player = (Player) src; BlockRay<World> playerBlockRay = BlockRay.from(player).blockLimit(350).build(); BlockRayHit<World> finalHitRay = null; while (playerBlockRay.hasNext()) { BlockRayHit<World> currentHitRay = playerBlockRay.next(); if (!player.getWorld().getBlockType(currentHitRay.getBlockPosition()).equals(BlockTypes.AIR)) { finalHitRay = currentHitRay; break; } } if (finalHitRay == null) { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Could not find the block you're looking at within range!")); } else { boolean safely = false; // If not passable, then it is a solid block if (!finalHitRay.getLocation().getProperty(PassableProperty.class).get().getValue()) { safely = player.setLocationSafely(finalHitRay.getLocation().add(0, 1, 0)); } else { // If the block below this is tall grass or a tall flower, then teleport down to that if (finalHitRay.getLocation().getRelative(Direction.DOWN).getProperty(PassableProperty.class).get().getValue()) { safely = player.setLocationSafely(finalHitRay.getLocation().sub(0, 1, 0)); } else { // If not then we found our location safely = player.setLocationSafely(finalHitRay.getLocation()); } } if (safely) { player.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Jumped to the block you were looking at.")); } else { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Couldn't safely put you where you are looking.")); } } } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /jump!")); } return CommandResult.success(); }