org.bukkit.Location#clone ( )源码实例Demo

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

源代码1 项目: CardinalPGM   文件: FlagObjective.java
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;
}
 
源代码2 项目: Hawk   文件: AdjacentBlocks.java
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;
}
 
源代码3 项目: Hawk   文件: AdjacentBlocks.java
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;
}
 
源代码4 项目: Hawk   文件: AdjacentBlocks.java
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;
}
 
源代码5 项目: Hawk   文件: AdjacentBlocks.java
@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;
}
 
源代码6 项目: HeavySpleef   文件: FlagFreeze.java
@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);
		}
	}
}
 
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));
    }
}
 
源代码8 项目: PGM   文件: FireworkMatchModule.java
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;
}
 
源代码9 项目: PGM   文件: Trackers.java
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());
}
 
源代码10 项目: Sentinel   文件: SentinelTargetingHelper.java
/**
 * 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);
}
 
源代码11 项目: ProjectAres   文件: BlockUtils.java
/**
 * 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;
}
 
源代码12 项目: CardinalPGM   文件: Fireworks.java
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);
    }
}
 
源代码13 项目: civcraft   文件: Wonder.java
@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());
}
 
源代码14 项目: AnnihilationPro   文件: Transporter.java
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;
}
 
源代码15 项目: GriefDefender   文件: BlockUtil.java
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());
}
 
源代码16 项目: civcraft   文件: InteractiveBuildCommand.java
public InteractiveBuildCommand(Town town, Buildable buildable, Location center, Template tpl) {
	this.town = town;
	this.buildable = buildable;
	this.center = center.clone();
	this.tpl = tpl;
}
 
源代码17 项目: BedwarsRel   文件: Utils.java
public static Location getDirectionLocation(Location location, int blockOffset) {
  Location loc = location.clone();
  return loc.add(loc.getDirection().setY(0).normalize().multiply(blockOffset));
}
 
源代码18 项目: uSkyBlock   文件: TeleportLogic.java
private PendingTeleport(Location location, BukkitTask task) {
    this.location = location != null ? location.clone() : null;
    this.task = task;
}
 
源代码19 项目: ProjectAres   文件: PortalTransform.java
@Override
public Location apply(Location v) {
    v = v.clone();
    v.setPosition(to.getRandom(PGM.getMatchManager().needMatch(v.getWorld()).getRandom()));
    return v;
}
 
源代码20 项目: EffectLib   文件: EquationEffect.java
@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++;
        }
    }
}