Java Code Examples for org.bukkit.Location#getWorld()

The following examples show how to use org.bukkit.Location#getWorld() . 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: GameCreator.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
private String addSpawner(String type, Location loc, String customName, boolean hologramEnabled, double startLevel, org.screamingsandals.bedwars.api.Team team, int maxSpawnedResources) {
    if (game.getPos1() == null || game.getPos2() == null) {
        return i18n("admin_command_set_pos1_pos2_first");
    }
    if (game.getWorld() != loc.getWorld()) {
        return i18n("admin_command_must_be_in_same_world");
    }
    if (!isInArea(loc, game.getPos1(), game.getPos2())) {
        return i18n("admin_command_spawn_must_be_in_area");
    }
    loc.setYaw(0);
    loc.setPitch(0);
    ItemSpawnerType spawnerType = Main.getSpawnerType(type);
    if (spawnerType != null) {
        game.getSpawners().add(new ItemSpawner(loc, spawnerType, customName, hologramEnabled, startLevel, team, maxSpawnedResources));
        return i18n("admin_command_spawner_added").replace("%resource%", spawnerType.getItemName())
                .replace("%x%", Integer.toString(loc.getBlockX())).replace("%y%", Integer.toString(loc.getBlockY()))
                .replace("%z%", Integer.toString(loc.getBlockZ()));
    } else {
        return i18n("admin_command_invalid_spawner_type");
    }
}
 
Example 2
Source File: NMS_v1_8_R3.java    From Crazy-Crates with MIT License 6 votes vote down vote up
@Override
public List<Location> getLocations(File f, Location loc) {
    loc = loc.subtract(2, 1, 2);
    List<Location> locations = new ArrayList<>();
    try {
        FileInputStream fis = new FileInputStream(f);
        NBTTagCompound nbt = NBTCompressedStreamTools.a(fis);
        short width = nbt.getShort("Width");
        short height = nbt.getShort("Height");
        short length = nbt.getShort("Length");
        fis.close();
        //paste
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                for (int z = 0; z < length; ++z) {
                    final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ());
                    locations.add(l);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return locations;
}
 
Example 3
Source File: WorldGuard7FAWEHook.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
@Override
public Collection<? extends Region> getRegionsAt_i(@Nullable final Location l) {
    final ArrayList<Region> r = new ArrayList<>();
    
    if (l == null) // Working around possible cause of issue #280
        return Collections.emptyList();
    if (l.getWorld() == null)
        return Collections.emptyList();
    RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
    if (query == null)
        return r;
    ApplicableRegionSet applicable = query.getApplicableRegions(BukkitAdapter.adapt(l));
    if (applicable == null)
        return r;
    final Iterator<ProtectedRegion> i = applicable.iterator();
    while (i.hasNext())
        r.add(new WorldGuardRegion(l.getWorld(), i.next()));
    return r;
}
 
Example 4
Source File: ChallengeLogic.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
private boolean islandContains(Player player, List<ItemStack> itemStacks, int radius) {
    final Location l = player.getLocation();
    final int px = l.getBlockX();
    final int py = l.getBlockY();
    final int pz = l.getBlockZ();
    World world = l.getWorld();
    BlockCollection blockCollection = new BlockCollection();
    for (int x = px - radius; x <= px + radius; x++) {
        for (int y = py - radius; y <= py + radius; y++) {
            for (int z = pz - radius; z <= pz + radius; z++) {
                Block block = world.getBlockAt(x, y, z);
                blockCollection.add(block);
            }
        }
    }
    String diff = blockCollection.diff(itemStacks);
    if (diff != null) {
        player.sendMessage(diff);
        return false;
    }
    return true;
}
 
Example 5
Source File: WorldManager.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates the world spawn at the given {@link Location}. Places the spawn schematic if
 * configured and when it exists on disk. Places a gold block with two air above it otherwise.
 * @param spawnLocation Location to create the spawn at.
 */
private void createSpawn(@NotNull Location spawnLocation) {
    Validate.notNull(spawnLocation, "SpawnLocation cannot be null");
    Validate.notNull(spawnLocation.getWorld(), "SpawnLocation#world cannot be null");

    File schematic = new File(plugin.getDataFolder() + File.separator + "schematics" +
            File.separator + "spawn.schem");
    World world = spawnLocation.getWorld();

    if (plugin.getConfig().getInt("options.general.spawnSize", 0) > 32 && schematic.exists()) {
        AsyncWorldEditHandler.loadIslandSchematic(schematic, spawnLocation, null);
    } else {
        Block spawnBlock = world.getBlockAt(spawnLocation).getRelative(BlockFace.DOWN);
        spawnBlock.setType(Material.GOLD_BLOCK);
        Block air = spawnBlock.getRelative(BlockFace.UP);
        air.setType(Material.AIR);
        air.getRelative(BlockFace.UP).setType(Material.AIR);
    }
}
 
Example 6
Source File: NMSUtilsHologramInteraction.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void updatePlayerHologram(Player player, Location holoLocation) {
       List<Hologram> holograms;
       if (!this.holograms.containsKey(player)) {
           this.holograms.put(player, new ArrayList<>());
       }

       holograms = this.holograms.get(player);
       Hologram holo = this.getHologramByLocation(holograms, holoLocation);
       if (holo == null && player.getWorld() == holoLocation.getWorld()) {
           holograms.add(this.createPlayerStatisticHologram(player, holoLocation));
       } else if (holo != null) {
           if (holo.getLocation().getWorld() == player.getWorld()) {
               this.updatePlayerStatisticHologram(player, holo);
           } else {
               holograms.remove(holo);
               holo.destroy();
           }
       }
}
 
Example 7
Source File: GameCreator.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String setPos1(Location loc) {
    if (game.getWorld() == null) {
        game.setWorld(loc.getWorld());
    }
    if (game.getWorld() != loc.getWorld()) {
        return i18n("admin_command_must_be_in_same_world");
    }
    if (game.getPos2() != null) {
        if (Math.abs(game.getPos2().getBlockY() - loc.getBlockY()) <= 5) {
            return i18n("admin_command_pos1_pos2_difference_must_be_higher");
        }
    }
    game.setPos1(loc);
    return i18n("admin_command_pos1_setted").replace("%arena%", game.getName())
            .replace("%x%", Integer.toString(loc.getBlockX())).replace("%y%", Integer.toString(loc.getBlockY()))
            .replace("%z%", Integer.toString(loc.getBlockZ()));
}
 
Example 8
Source File: Wall.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
private void getVerticalWallSegment(Player player, Location loc, Map<String, SimpleBlock> simpleBlocks) throws CivException {
	Location tmp = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ());
	for (int i = 0; i < Wall.HEIGHT; i++) {
		SimpleBlock sb;
		if (i == 0) {
			sb = new SimpleBlock(CivData.STONE_BRICK, 0x1);
		} else {
			sb = new SimpleBlock(CivData.STONE_BRICK, 0);
		}
		sb.worldname = tmp.getWorld().getName();
		sb.x = tmp.getBlockX();
		sb.y = tmp.getBlockY();
		sb.z = tmp.getBlockZ();
		
		validateBlockLocation(player, tmp);
		simpleBlocks.put(sb.worldname+","+sb.x+","+sb.y+","+sb.z, sb);
		
		tmp.add(0, 1.0, 0);
	} 
}
 
Example 9
Source File: FaweAdapter_1_10.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean setBlock(Location location, BaseBlock block, boolean notifyAndLight)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(block);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();

    boolean changed = location.getBlock().setTypeIdAndData(block.getId(), (byte)block.getData(), notifyAndLight);

    CompoundTag nativeTag = block.getNbtData();
    if (nativeTag != null)
    {
        TileEntity tileEntity = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z));
        if (tileEntity != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            tag.set("x", new NBTTagInt(x));
            tag.set("y", new NBTTagInt(y));
            tag.set("z", new NBTTagInt(z));
            readTagIntoTileEntity(tag, tileEntity);
        }
    }
    return changed;
}
 
Example 10
Source File: Arena.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
public boolean containsBlock(Location v) {
    if (v.getWorld() != min.getWorld()) return false;
    final double x = v.getX();
    final double y = v.getY();
    final double z = v.getZ();
    return x >= min.getBlockX() && x < max.getBlockX() + 1 && y >= min.getBlockY() && y < max.getBlockY() + 1 && z >= min.getBlockZ() && z < max.getBlockZ() + 1;  
}
 
Example 11
Source File: GameCreator.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String setSpecSpawn(Location loc) {
    if (game.getPos1() == null || game.getPos2() == null) {
        return i18n("admin_command_set_pos1_pos2_first");
    }
    if (game.getWorld() != loc.getWorld()) {
        return i18n("admin_command_must_be_in_same_world");
    }
    if (!isInArea(loc, game.getPos1(), game.getPos2())) {
        return i18n("admin_command_spawn_must_be_in_area");
    }
    game.setSpecSpawn(loc);
    return i18n("admin_command_spec_spawn_setted").replace("%x%", Double.toString(loc.getX()))
            .replace("%y%", Double.toString(loc.getY())).replace("%z%", Double.toString(loc.getZ()))
            .replace("%yaw%", Float.toString(loc.getYaw())).replace("%pitch%", Float.toString(loc.getPitch()));
}
 
Example 12
Source File: FaweAdapter_1_11.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean setBlock(Location location, BaseBlock block, boolean notifyAndLight)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(block);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();

    boolean changed = location.getBlock().setTypeIdAndData(block.getId(), (byte)block.getData(), notifyAndLight);

    CompoundTag nativeTag = block.getNbtData();
    if (nativeTag != null)
    {
        TileEntity tileEntity = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z));
        if (tileEntity != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            tag.set("x", new NBTTagInt(x));
            tag.set("y", new NBTTagInt(y));
            tag.set("z", new NBTTagInt(z));
            readTagIntoTileEntity(tag, tileEntity);
        }
    }
    return changed;
}
 
Example 13
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onProjectileHitEvent(ProjectileHitEvent event) {
	if (event.getEntity() instanceof Arrow) {
		ArrowFiredCache afc = CivCache.arrowsFired.get(event.getEntity().getUniqueId());
		if (afc != null) {
			afc.setHit(true);
		}
	}

	if (event.getEntity() instanceof Fireball) {
		CannonFiredCache cfc = CivCache.cannonBallsFired.get(event.getEntity().getUniqueId());
		if (cfc != null) {

			cfc.setHit(true);

			FireworkEffect fe = FireworkEffect.builder().withColor(Color.RED).withColor(Color.BLACK).flicker(true).with(Type.BURST).build();

			Random rand = new Random();
			int spread = 30;
			for (int i = 0; i < 15; i++) {
				int x = rand.nextInt(spread) - spread/2;
				int y = rand.nextInt(spread) - spread/2;
				int z = rand.nextInt(spread) - spread/2;


				Location loc = event.getEntity().getLocation();
				Location location = new Location(loc.getWorld(), loc.getX(),loc.getY(), loc.getZ());
				location.add(x, y, z);

				TaskMaster.syncTask(new FireWorkTask(fe, loc.getWorld(), loc, 5), rand.nextInt(30));
			}

		}
	}
}
 
Example 14
Source File: RegionManager.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
private Region findRegion(int index1, int index2, Location location, int index) {
    if (location.getWorld() == null) {
        return null;
    }
    UUID worldUuid = location.getWorld().getUID();
    for (int i=index1; i<=index2; i++) {
        if (i==index) {
            continue;
        }
        if (withinRegion(regions.get(worldUuid).get(i), location)) {
            return regions.get(worldUuid).get(i);
        }
    }
    return null;
}
 
Example 15
Source File: TownManager.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public Town getTownAt(Location location) {
    ItemManager itemManager = ItemManager.getInstance();
    for (Town town : sortedTowns) {
        TownType townType = (TownType) itemManager.getItemType(town.getType());
        int radius = townType.getBuildRadius();
        int radiusY = townType.getBuildRadiusY();
        Location townLocation = town.getLocation();

        if (townLocation.getWorld() == null) {
            continue;
        }
        if (!townLocation.getWorld().equals(location.getWorld())) {
            continue;
        }

        if (townLocation.getX() - radius >= location.getX()) {
            break;
        }

        if (townLocation.getX() + radius >= location.getX() &&
                townLocation.getZ() + radius >= location.getZ() &&
                townLocation.getZ() - radius <= location.getZ() &&
                townLocation.getY() - radiusY <= location.getY() &&
                townLocation.getY() + radiusY >= location.getY()) {
            return town;
        }

    }
    return null;
}
 
Example 16
Source File: Reactor.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
protected BlockMenu getAccessPort(Location l) {
    Location portL = new Location(l.getWorld(), l.getX(), l.getY() + 3, l.getZ());

    if (BlockStorage.check(portL, SlimefunItems.REACTOR_ACCESS_PORT.getItemId())) {
        return BlockStorage.getInventory(portL);
    }
    else {
        return null;
    }
}
 
Example 17
Source File: TNTSheep.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public TNTSheep(Location location, Player target) {
  super(((CraftWorld) location.getWorld()).getHandle());

  this.world = location.getWorld();

  this.locX = location.getX();
  this.locY = location.getY();
  this.locZ = location.getZ();

  try {
    Field b = this.goalSelector.getClass().getDeclaredField("b");
    b.setAccessible(true);

    Set<?> goals = (Set<?>) b.get(this.goalSelector);
    goals.clear(); // Clears the goals

    this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D);
    this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
        .setValue(
            BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D));
  } catch (Exception e) {
    BedwarsRel.getInstance().getBugsnag().notify(e);
    e.printStackTrace();
  }

  this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, 1D, false)); // Add bedwars player
  // goal
  try {
    this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
        TargetReason.TARGET_ATTACKED_ENTITY, false);
  } catch (Exception ex) {
    // newer spigot builds
    if (ex instanceof NoSuchMethodException) {
      BedwarsRel.getInstance().getBugsnag().notify(ex);
      this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()));
    }
  }

  ((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
 
Example 18
Source File: ShopUtils.java    From ShopChest with MIT License 5 votes vote down vote up
/**
 * Get the shop at a given location
 *
 * @param location Location of the shop
 * @return Shop at the given location or <b>null</b> if no shop is found there
 */
public Shop getShop(Location location) {
    Location newLocation = new Location(location.getWorld(), location.getBlockX(),
            location.getBlockY(), location.getBlockZ());

    return shopLocation.get(newLocation);
}
 
Example 19
Source File: BlockFromToListener.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
    try {
        final Block block = event.getBlock();
        final Location location = block.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        final Island island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        final Material material = block.getType();
        final Block toBlock = event.getToBlock();
        final Location toLocation = toBlock.getLocation();

        if (material.equals(Material.WATER) || material.equals(Material.LAVA)) {
            final Island toIsland = islandManager.getIslandViaLocation(toLocation);
            if (island != toIsland)
                event.setCancelled(true);
        }

        if (!IridiumSkyblock.getUpgrades().oresUpgrade.enabled) return;

        if (event.getFace() == BlockFace.DOWN) return;

        if (!isSurroundedByWater(toLocation))
            return;

        final int oreLevel = island.getOreLevel();
        final World world = location.getWorld();
        if (world == null) return;

        final String worldName = world.getName();
        final Config config = IridiumSkyblock.getConfiguration();
        List<String> islandOreUpgrades;
        if (worldName.equals(config.worldName)) islandOreUpgrades = IridiumSkyblock.oreUpgradeCache.get(oreLevel);
        else if (worldName.equals(config.netherWorldName)) islandOreUpgrades = IridiumSkyblock.netherOreUpgradeCache.get(oreLevel);
        else return;

        Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> {
            final Material toMaterial = toBlock.getType();
            if (!(toMaterial.equals(Material.COBBLESTONE) || toMaterial.equals(Material.STONE)))
                return;

            final Random random = new Random();
            final String oreUpgrade = islandOreUpgrades.get(random.nextInt(islandOreUpgrades.size()));

            final XMaterial oreUpgradeXmaterial = XMaterial.valueOf(oreUpgrade);
            final Material oreUpgradeMaterial = oreUpgradeXmaterial.parseMaterial(true);
            if (oreUpgradeMaterial == null) return;

            toBlock.setType(oreUpgradeMaterial);

            final BlockState blockState = toBlock.getState();
            blockState.update(true);

            if (Utils.isBlockValuable(toBlock)) {
                final XMaterial xmaterial = XMaterial.matchXMaterial(material);
                island.valuableBlocks.compute(xmaterial.name(), (name, original) -> {
                    if (original == null) return 1;
                    return original + 1;
                });
                if (island.updating)
                    island.tempValues.add(location);
                island.calculateIslandValue();
            }
        });
    } catch (Exception ex) {
        IridiumSkyblock.getInstance().sendErrorMessage(ex);
    }
}
 
Example 20
Source File: BlockIterator.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs the BlockIterator.
 *
 * @param loc     The location for the start of the ray trace
 * @param yOffset The trace begins vertically offset from the start vector
 *                by this value
 */

public BlockIterator(Location loc, double yOffset) {
    this(loc.getWorld(), loc.toVector(), loc.getDirection(), yOffset, 0);
}