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

The following examples show how to use org.bukkit.Location#clone() . 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: AdjacentBlocks.java    From Hawk with GNU General Public License v3.0 6 votes vote down vote up
public static boolean blockAdjacentIsLiquid(Location loc) {
    Location check = loc.clone();
    Set<Block> sample = new HashSet<>();
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 0.3)));
    sample.add(ServerUtils.getBlockAsync(check.add(0.3, 0, 0)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, -0.3)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, -0.3)));
    sample.add(ServerUtils.getBlockAsync(check.add(-0.3, 0, 0)));
    sample.add(ServerUtils.getBlockAsync(check.add(-0.3, 0, 0)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 0.3)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 0.3)));
    for (Block b : sample) {
        if (b != null && b.isLiquid())
            return true;
    }
    return false;
}
 
Example 2
Source File: GameObjectiveProximityHandler.java    From CardinalPGM with MIT License 6 votes vote down vote up
private void setProximity(Location loc, Player player) {
    if (info.locations == null) return;
    if (info.horizontal) {
        loc = loc.clone();
        loc.setY(0);
    }
    double newProximity = proximity;
    for (Vector proxLoc : info.locations) {
        double prox = proxLoc.distance(loc.position());
        if (prox < newProximity) {
            newProximity = prox;
        }
    }
    if (newProximity < proximity) {
        Double old = proximity;
        proximity = newProximity;
        Bukkit.getServer().getPluginManager().callEvent(new ObjectiveProximityEvent(objective, player, old, proximity));
    }
}
 
Example 3
Source File: FlagFreeze.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
	Iterator<WeakReference<SpleefPlayer>> iterator = frozenPlayers.iterator();
	while (iterator.hasNext()) {
		WeakReference<SpleefPlayer> ref = iterator.next();
		SpleefPlayer player = ref.get();
		
		if (player == null) {
			iterator.remove();
		}
		
		Location now = player.getBukkitPlayer().getLocation();
		Location freezeLoc = freezeLocations.get(player);
		
		if (now.getX() != freezeLoc.getX() || now.getY() != freezeLoc.getY() || now.getZ() != freezeLoc.getZ()) {
			Location tpLocation = freezeLoc.clone();
			tpLocation.setYaw(now.getYaw());
			tpLocation.setPitch(now.getPitch());
			
			player.teleport(tpLocation);
		}
	}
}
 
Example 4
Source File: AdjacentBlocks.java    From Hawk with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public static boolean blockNearbyIsSolid(Location loc, boolean hawkDefinition) {
    Location check = loc.clone();
    Set<Block> sample = new HashSet<>();
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 1)));
    sample.add(ServerUtils.getBlockAsync(check.add(1, 0, 0)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, -1)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, -1)));
    sample.add(ServerUtils.getBlockAsync(check.add(-1, 0, 0)));
    sample.add(ServerUtils.getBlockAsync(check.add(-1, 0, 0)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 1)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 1)));
    for (Block b : sample) {
        if (b == null)
            continue;
        if (hawkDefinition) {
            if (WrappedBlock.getWrappedBlock(b, Hawk.getServerVersion()).isSolid())
                return true;
        } else if (b.getType().isSolid())
            return true;
    }
    return false;
}
 
Example 5
Source File: AdjacentBlocks.java    From Hawk with GNU General Public License v3.0 6 votes vote down vote up
public static boolean matContainsStringIsAdjacent(Location loc, String name) {
    Location check = loc.clone();
    Set<Block> sample = new HashSet<>();
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 0.3)));
    sample.add(ServerUtils.getBlockAsync(check.add(0.3, 0, 0)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, -0.3)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, -0.3)));
    sample.add(ServerUtils.getBlockAsync(check.add(-0.3, 0, 0)));
    sample.add(ServerUtils.getBlockAsync(check.add(-0.3, 0, 0)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 0.3)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 0.3)));
    for (Block b : sample) {
        if (b != null && b.getType().name().contains(name))
            return true;
    }
    return false;
}
 
Example 6
Source File: AdjacentBlocks.java    From Hawk with GNU General Public License v3.0 6 votes vote down vote up
public static boolean matIsAdjacent(Location loc, Material... materials) {
    Location check = loc.clone();
    Set<Block> sample = new HashSet<>();
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 0.3)));
    sample.add(ServerUtils.getBlockAsync(check.add(0.3, 0, 0)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, -0.3)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, -0.3)));
    sample.add(ServerUtils.getBlockAsync(check.add(-0.3, 0, 0)));
    sample.add(ServerUtils.getBlockAsync(check.add(-0.3, 0, 0)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 0.3)));
    sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 0.3)));
    for (Block b : sample) {
        if (b == null)
            continue;
        for (Material mat : materials) {
            if (b.getType() == mat)
                return true;
        }
    }
    return false;
}
 
Example 7
Source File: FlagObjective.java    From CardinalPGM with MIT License 6 votes vote down vote up
public boolean inRange(Location newLoc, Location oldLoc) {
    Location flag = getCurrentFlagLocation().clone();
    double dx = Math.abs(newLoc.getX() - flag.getX());
    double dy = Math.abs(newLoc.getY() - (flag.getY() - 0.5));
    double dz = Math.abs(newLoc.getZ() - flag.getZ());
    if (dx < 1D && dz < 1D && dy < 2.5D) {
        Vector flagY0 = flag.toVector().clone();
        flagY0.setY(0);
        Vector newY0 = newLoc.toVector().clone();
        newY0.setY(0);
        double dist1 = flagY0.distance(newY0);
        if (dist1 < 1D) {
            if (oldLoc == null) return true;
            Location oldY0 = oldLoc.clone();
            oldY0.setY(0);
            double dist2 = flagY0.distance(oldY0.position());
            return dist1 < dist2;
        }
    }
    return false;
}
 
Example 8
Source File: SentinelTargetingHelper.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Finds a spot this NPC should run to, to avoid threats. Returns null if there's nowhere to run.
 */
public Location findBestRunSpot() {
    if (sentinel.avoidReturnPoint != null
            && sentinel.avoidReturnPoint.getWorld().equals(getLivingEntity().getWorld())) {
        return sentinel.avoidReturnPoint.clone();
    }
    Location pos = sentinel.getGuardZone();
    if (!pos.getWorld().equals(getLivingEntity().getWorld())) {
        // Emergency corrective measures...
        getNPC().getNavigator().cancelNavigation();
        getLivingEntity().teleport(sentinel.getGuardZone());
        return null;
    }
    LivingEntity closestThreat = null;
    double threatRangeSquared = 1000 * 1000;
    for (LivingEntity entity : avoidanceList) {
        double dist = entity.getLocation().distanceSquared(pos);
        if (dist < threatRangeSquared) {
            closestThreat = entity;
            threatRangeSquared = dist;
        }
    }
    if (closestThreat == null) {
        return null;
    }
    if (threatRangeSquared >= sentinel.avoidRange * sentinel.avoidRange) {
        if (SentinelPlugin.debugMe) {
            sentinel.debug("Threats are getting close... holding my post.");
        }
        return pos.clone();
    }
    return runDirection(pos);
}
 
Example 9
Source File: BlockUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Return the "base" {@link Location} of the block at the given location,
 * which is the bottom center point on the block (i.e. the location of any
 * block-shaped entity that is aligned with the block).
 */
public static Location base(Location location) {
    Location center = location.clone();
    center.setX(center.getBlockX() + 0.5);
    center.setY(center.getBlockY());
    center.setZ(center.getBlockZ() + 0.5);
    return center;
}
 
Example 10
Source File: Fireworks.java    From CardinalPGM with MIT License 5 votes vote down vote up
private static Location firstEmptyBlock(Location loc) {
    loc = loc.clone();
    while (true) {
        if (loc.getBlock() == null || loc.getY() == 256 || !loc.getBlock().getType().isOccluding()) return loc;
        loc.add(0, 1, 0);
    }
}
 
Example 11
Source File: Trackers.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public static double distanceFromRanged(RangedInfo rangedInfo, @Nullable Location deathLocation) {
  if (rangedInfo.getOrigin() == null || deathLocation == null) return Double.NaN;

  // When players fall in the void, use y=0 as their death location
  if (deathLocation.getY() < 0) {
    deathLocation = deathLocation.clone();
    deathLocation.setY(0);
  }
  return deathLocation.distance(rangedInfo.getOrigin());
}
 
Example 12
Source File: Wonder.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void build(Player player, Location centerLoc, Template tpl) throws Exception {

	// We take the player's current position and make it the 'center' by moving the center location
	// to the 'corner' of the structure.
	Location savedLocation = centerLoc.clone();

	centerLoc = this.repositionCenter(centerLoc, tpl.dir(), (double)tpl.size_x, (double)tpl.size_z);
	Block centerBlock = centerLoc.getBlock();
	// Before we place the blocks, give our build function a chance to work on it
	
	this.setTotalBlockCount(tpl.size_x*tpl.size_y*tpl.size_z);
	// Save the template x,y,z for later. This lets us know our own dimensions.
	// this is saved in the db so it remains valid even if the template changes.
	this.setTemplateName(tpl.getFilepath());
	this.setTemplateX(tpl.size_x);
	this.setTemplateY(tpl.size_y);
	this.setTemplateZ(tpl.size_z);
	this.setTemplateAABB(new BlockCoord(centerLoc), tpl);
	
	checkBlockPermissionsAndRestrictions(player, centerBlock, tpl.size_x, tpl.size_y, tpl.size_z, savedLocation);
	this.runOnBuild(centerLoc, tpl);

	// Setup undo information
	getTown().lastBuildableBuilt = this;
	tpl.saveUndoTemplate(this.getCorner().toString(), this.getTown().getName(), centerLoc);
	tpl.buildScaffolding(centerLoc);
	
	// Player's center was converted to this building's corner, save it as such.
	this.startBuildTask(tpl, centerLoc);
	
	this.save();
	CivGlobal.addWonder(this);
	CivMessage.global(this.getCiv().getName()+" has started construction of "+this.getDisplayName()+" in the town of "+this.getTown().getName());
}
 
Example 13
Source File: Transporter.java    From AnnihilationPro with MIT License 5 votes vote down vote up
private Location getMiddle(Location loc)
{
	Location k = loc.clone();
	k.setX(k.getBlockX()+0.5);
	//k.setY(k.getBlockY()+0.5);
	k.setZ(k.getBlockZ()+0.5);
	return k;
}
 
Example 14
Source File: FireworkMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Location getOpenSpaceAbove(Location location) {
  Preconditions.checkNotNull(location, "location");

  Location result = location.clone();
  while (true) {
    Block block = result.getBlock();
    if (block == null || block.getType() == Material.AIR) break;

    result.setY(result.getY() + 1);
  }

  return result;
}
 
Example 15
Source File: Utils.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
public static Location getDirectionLocation(Location location, int blockOffset) {
  Location loc = location.clone();
  return loc.add(loc.getDirection().setY(0).normalize().multiply(blockOffset));
}
 
Example 16
Source File: InteractiveBuildCommand.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public InteractiveBuildCommand(Town town, Buildable buildable, Location center, Template tpl) {
	this.town = town;
	this.buildable = buildable;
	this.center = center.clone();
	this.tpl = tpl;
}
 
Example 17
Source File: BlockUtil.java    From GriefDefender with MIT License 4 votes vote down vote up
public Location getBlockRelative(Location location, Direction direction) {
    final Vector3i offset = direction.asBlockOffset();
    // We must clone here as Bukkit's location is mutable
    location = location.clone();
    return location.add(offset.getX(), offset.getY(), offset.getZ());
}
 
Example 18
Source File: TeleportLogic.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
private PendingTeleport(Location location, BukkitTask task) {
    this.location = location != null ? location.clone() : null;
    this.task = task;
}
 
Example 19
Source File: PortalTransform.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Location apply(Location v) {
    v = v.clone();
    v.setPosition(to.getRandom(PGM.getMatchManager().needMatch(v.getWorld()).getRandom()));
    return v;
}
 
Example 20
Source File: EquationEffect.java    From EffectLib with MIT License 4 votes vote down vote up
@Override
public void onRun() {
    if (xTransform == null) {
        xTransform = EquationStore.getInstance().getTransform(xEquation, variable);
        yTransform = EquationStore.getInstance().getTransform(yEquation, variable);
        zTransform = EquationStore.getInstance().getTransform(zEquation, variable);
        
        if (x2Equation != null && y2Equation != null && z2Equation != null && particles2 > 0) {
            x2Transform = EquationStore.getInstance().getTransform(x2Equation, variable, variable2);
            y2Transform = EquationStore.getInstance().getTransform(y2Equation, variable, variable2);
            z2Transform = EquationStore.getInstance().getTransform(z2Equation, variable, variable2);
        }
    }
    Location location = getLocation();

    boolean hasInnerEquation = (x2Transform != null && y2Transform != null && z2Transform != null);
    for (int i = 0; i < particles; i++) {
        Double xValue = xTransform.get(step);
        Double yValue = yTransform.get(step);
        Double zValue = zTransform.get(step);
        
        Vector result = new Vector(xValue, yValue, zValue);
        if (orient && orientPitch) {
            result = VectorUtils.rotateVector(result, location);
        } else if (orient) {
            result = VectorUtils.rotateVector(result, location.getYaw(), 0);
        }

        Location targetLocation = location.clone();
        targetLocation.add(result);
        if (!hasInnerEquation) {
            display(particle, targetLocation);
        } else {
            for (int j = 0; j < particles2; j++) {
                Double x2Value = x2Transform.get(step, miniStep);
                Double y2Value = y2Transform.get(step, miniStep);
                Double z2Value = z2Transform.get(step, miniStep);
                
                Vector result2 = new Vector(x2Value, y2Value, z2Value);
                if (orient && orientPitch) {
                    result2 = VectorUtils.rotateVector(result2, location);
                } else if (orient) {
                    result2 = VectorUtils.rotateVector(result2, location.getYaw(), 0);
                }
                
                Location target2Location = targetLocation.clone().add(result2);
                display(particle, target2Location);
                
                miniStep++;
            }
            
            if (cycleMiniStep) {
                miniStep = 0;
            }
        }
        if (maxSteps != 0 && step > maxSteps) {
            step = 0;
            break;
        } else {
            step++;
        }
    }
}