private static void block(Player player) { for (int id : instances.keySet()) { EarthBlast blast = instances.get(id); if (blast.player.equals(player)) { continue; } if (!blast.location.getWorld().equals(player.getWorld())) { continue; } if (!blast.progressing) { continue; } if (GeneralMethods.isRegionProtectedFromBuild(player, "EarthBlast", blast.location)) { continue; } Location location = player.getEyeLocation(); Vector vector = location.getDirection(); Location mloc = blast.location; if (mloc.distance(location) <= RANGE && GeneralMethods.getDistanceFromLine(vector, location, blast.location) < deflectrange && mloc.distance(location.clone().add(vector)) < mloc.distance(location.clone().add(vector.clone().multiply(-1)))) { blast.breakBlock(); } } }
private static void redirectTargettedBlasts(Player player, ArrayList<EarthBlast> ignore) { for (int id : instances.keySet()) { EarthBlast blast = instances.get(id); if (!blast.progressing || ignore.contains(blast)) { continue; } if (!blast.location.getWorld().equals(player.getWorld())) { continue; } if (GeneralMethods.isRegionProtectedFromBuild(player, "EarthBlast", blast.location)) { continue; } if (blast.player.equals(player)) { blast.redirect(player, getTargetLocation(player)); } Location location = player.getEyeLocation(); Vector vector = location.getDirection(); Location mloc = blast.location; if (mloc.distance(location) <= RANGE && GeneralMethods.getDistanceFromLine(vector, location, blast.location) < deflectrange && mloc.distance(location.clone().add(vector)) < mloc.distance(location.clone().add(vector.clone().multiply(-1)))) { blast.redirect(player, getTargetLocation(player)); } } }
public void bOOM() { Vector v = p.getVelocity(); v.setY(2.3); p.teleport(p.getLocation().add(0, 0.5, 0)); p.setVelocity(v); p.setFallDistance(0F); TempData.sonicRainBoomMap.put(p.getUniqueId(), System.currentTimeMillis()); p.sendMessage(ChatColor.LIGHT_PURPLE + "SONIC RAINBOOM!"); TempData.fallMap.add(p.getUniqueId()); // Particles final World world = p.getWorld(); for (int i = 0; i < 20 * 4; i++) { Bukkit.getScheduler() .scheduleSyncDelayedTask( Main.PLUGIN, new Runnable() { @Override public void run() { world .spigot() .playEffect(p.getLocation(), Effect.COLOURED_DUST, 1, 1, 1, 1, 1, 1, 48, 30); } }, i); } }
private void calculateRay(int ox, int oy, int oz, Collection<BlockVector> result) { double x = ox / 7.5 - 1; double y = oy / 7.5 - 1; double z = oz / 7.5 - 1; Vector direction = new Vector(x, y, z); direction.normalize(); direction.multiply(0.3f); // 0.3 blocks away with each step Location current = location.clone(); float currentPower = calculateStartPower(); while (currentPower > 0) { GlowBlock block = world.getBlockAt(current); if (block.getType() != Material.AIR) { double blastDurability = getBlastDurability(block) / 5d; blastDurability += 0.3F; blastDurability *= 0.3F; currentPower -= blastDurability; if (currentPower > 0) { result.add(new BlockVector(block.getX(), block.getY(), block.getZ())); } } current.add(direction); currentPower -= 0.225f; } }
protected void triggersign(TriggerType type, Object args) { InputState is = this.getInput(1, (BlockRedstoneEvent) args); if (is == InputState.HIGH && !lastState) { lastState = true; Vector v = new Vector( to.getBlockX() - from.getBlockX(), to.getBlockY() - from.getBlockY(), to.getBlockZ() - from.getBlockZ()); v.normalize(); v.multiply(speed); while (from.getBlock().getType() != Material.AIR) { from = from.toVector().add(v.clone().normalize().multiply(.2)).toLocation(this.getWorld()); } for (int i = 0; i < arrows; i++) { Arrow a = this.getWorld().spawn(from, Arrow.class); a.setVelocity(v.clone().add(getVariance(variance))); this.main.cleaner.register(a, 5000); } this.getWorld().playEffect(from, org.bukkit.Effect.BOW_FIRE, 0); } else if ((is == InputState.LOW || is == InputState.DISCONNECTED) && lastState) { lastState = false; } else { return; } }
private void playOutExplosion(GlowPlayer player, Iterable<BlockVector> blocks) { Collection<ExplosionMessage.Record> records = new ArrayList<>(); Location clientLoc = location.clone(); clientLoc.setX((int) clientLoc.getX()); clientLoc.setY((int) clientLoc.getY()); clientLoc.setZ((int) clientLoc.getZ()); for (BlockVector block : blocks) { byte x = (byte) (block.getBlockX() - clientLoc.getBlockX()); byte y = (byte) (block.getBlockY() - clientLoc.getBlockY()); byte z = (byte) (block.getBlockZ() - clientLoc.getBlockZ()); records.add(new ExplosionMessage.Record(x, y, z)); } Vector velocity = player.getVelocity(); ExplosionMessage message = new ExplosionMessage( (float) location.getX(), (float) location.getY(), (float) location.getZ(), 5, (float) velocity.getX(), (float) velocity.getY(), (float) velocity.getZ(), records); player.getSession().send(message); }
@Override public boolean isInside(BlockRegion block) { Vector point = new Vector(block.getX(), block.getY(), block.getZ()); return Math.pow(point.getX() - origin.getX(), 2.0D) + Math.pow(point.getZ() - origin.getZ(), 2.0D) < (radius * radius); }
@Override public void send(Player player) { final PacketPlayOutSpawnEntity p23 = new PacketPlayOutSpawnEntity(); final Location position = player.getLocation(); p23.a = entityId; // v1_7_R1 p23.b = MathHelper.floor(position.getX() * 32.0D); // v1_7_R1 p23.c = MathHelper.floor(position.getY() * 32.0D); // v1_7_R1 p23.d = MathHelper.floor(position.getZ() * 32.0D); // v1_7_R1 p23.h = MathHelper.d(position.getPitch() * 256.0F / 360.0F); // v1_7_R1 p23.i = MathHelper.d(position.getYaw() * 256.0F / 360.0F); // v1_7_R1 p23.j = vehicleTypeId; // v1_7_R1 p23.k = dataValue; // v1_7_R1 if (dataValue > 0) { final Vector velocity = getVelocity(); double d1 = velocity.getX(); double d2 = velocity.getY(); double d3 = velocity.getZ(); double d4 = 3.9D; if (d1 < -d4) d1 = -d4; if (d2 < -d4) d2 = -d4; if (d3 < -d4) d3 = -d4; if (d1 > d4) d1 = d4; if (d2 > d4) d2 = d4; if (d3 > d4) d3 = d4; p23.e = (int) (d1 * 8000.0D); // v1_7_R1 p23.f = (int) (d2 * 8000.0D); // v1_7_R1 p23.g = (int) (d3 * 8000.0D); // v1_7_R1 } PlayerHelper.sendPacketToPlayer(player, p23); }
@Override public void cast(Entity entity) { // entity.getWorld().playSound(entity.getLocation(), Sound.GHAST_FIREBALL, 1F, 1F); entity.getWorld().playSound(entity.getLocation(), Sound.NOTE_STICKS, 1F, 0.4F); // TODO - find a better way to launch block without needing Player if (entity instanceof Player) { Player player = (Player) entity; Vector velocity = player.getEyeLocation().getDirection(); velocity.normalize().multiply(power); FallingBlock fb = DeprecatedMethods.spawnFallingBlock( entity.getLocation().clone().add(0, 1, 0), DeprecatedMethods.getMaterialByID(blockID), (byte) 0); fb.setDropItem(false); fb.setVelocity(velocity); // make it do damage if (damage) { DynamicClassFunctions.setFallingBlockHurtEntities(fb, hurt, hurt); } } }
public void setBlock(Vector pos, Material type, int data) { Vector vec = translate(pos); if (boundingBox.isVectorInside(vec)) { delegate.setTypeAndRawData( world, vec.getBlockX(), vec.getBlockY(), vec.getBlockZ(), type, data); } }
@Override public boolean doPowerSign( PowerSigns plugin, Block signBlock, String action, Matcher argsm, Boolean isOn) { Sign signState = (Sign) signBlock.getState(); BlockFace signDir = PowerSigns.getSignDirection(signBlock); Vector dir = PowerSigns.strToVector(argsm.group(1), signDir); Block invBlock = signBlock.getRelative(dir.getBlockX(), dir.getBlockY(), dir.getBlockZ()); Inventory inventory; BlockState state = invBlock.getState(); if (state instanceof InventoryHolder) inventory = ((InventoryHolder) state).getInventory(); else return plugin.debugFail("bad inv:" + invBlock.getType().toString() + " " + dir.toString()); Material[] materials = PowerSigns.getMaterials(signState.getLine(1)); int count = 0; for (Material material : materials) count += PowerSigns.inventoryCount(inventory, material); signState.setLine(2, Integer.toString(count)); plugin.updateSignState(signState); return true; }
public boolean spawnMob(Vector pos, EntityType entityType) { Vector vec = translate(pos); return boundingBox.isVectorInside(vec) && world.spawnEntity( new Location(world, vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()), entityType) != null; }
@Override public SpellResult step(CastContext context) { if (entity == null) { return SpellResult.FAIL; } SpellResult result = super.step(context); Location target = actionContext.getTargetLocation(); // TODO: locationOffset and velocityOffset should be made relative if (locationOffset != null) { target = target.clone().add(locationOffset); } if (doVelocity) { Vector velocity = this.velocity.clone().multiply(distanceTravelledThisTick); if (velocityOffset != null) { velocity = velocity.add(velocityOffset); } entity.setVelocity(velocity); } Location currentLocation = entity.getLocation(); if (doTeleport) { if (!orient) { target.setYaw(currentLocation.getYaw()); target.setPitch(currentLocation.getPitch()); } entity.teleport(target); } return result; }
@Override public void run() { if (master.contchunks.isEmpty()) return; World world = master.team.getMatch().getWorld(); Location loc = new Location(world, 0, 0, 0); Set<BlockData> goals = master.searching; for (int i = 0; i < 15; i++) // 15 chunks per run { Vector vec = master.entitychunks.poll(); if (vec == null) { this.cancel(); return; } BlockState[] containers = world .getChunkAt(vec.getBlockX(), vec.getBlockZ()) .getTileEntities(); // actually chunk-coords for (BlockState state : containers) { if (state instanceof InventoryHolder) { Inventory inv = ((InventoryHolder) state).getInventory(); if (state instanceof Chest) inv = ((Chest) state).getBlockInventory(); checkInventory(inv, goals, state.getLocation(loc)); } // TODO: spawners } } }
@Override public boolean onDamageOther(EntityDamageByEntityEvent e, Player p, int level) { if (e.getEntity() instanceof LivingEntity) { LivingEntity le = (LivingEntity) e.getEntity(); try { fireworks.playFirework( le.getWorld(), le.getLocation(), FireworkEffect.builder().with(Type.BURST).withColor(Color.WHITE).build()); } catch (Exception ex) { Logger.getLogger(Burst.class.getName()).log(Level.SEVERE, null, ex); } Vector unitVector = le.getLocation().toVector().subtract(e.getDamager().getLocation().toVector()).normalize(); unitVector.setY(0.55 / level); le.setVelocity(unitVector.multiply(level * 2)); e.setCancelled(true); return true; } return false; }
public void manageAirVectors() { for (int i = 0; i < tasks.size(); i++) { if (((FireComboStream) tasks.get(i)).isCancelled()) { tasks.remove(i); i--; } } if (tasks.size() == 0) { remove(); return; } for (int i = 0; i < tasks.size(); i++) { FireComboStream fstream = (FireComboStream) tasks.get(i); Location loc = fstream.getLocation(); if (GeneralMethods.isRegionProtectedFromBuild(this, loc)) { fstream.remove(); return; } if (!isTransparent(loc.getBlock())) { if (!isTransparent(loc.clone().add(0, 0.2, 0).getBlock())) { fstream.remove(); return; } } if (i % 3 == 0) { for (Entity entity : GeneralMethods.getEntitiesAroundPoint(loc, 2.5)) { if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation())) { remove(); return; } if (!entity.equals(player) && !affectedEntities.contains(entity)) { affectedEntities.add(entity); if (knockback != 0) { Vector force = fstream.getDirection(); entity.setVelocity(force.multiply(knockback)); } if (damage != 0) { if (entity instanceof LivingEntity) { if (fstream.getAbility().equalsIgnoreCase("AirSweep")) { DamageHandler.damageEntity(entity, damage, this); } else { DamageHandler.damageEntity(entity, damage, this); } } } } } if (GeneralMethods.blockAbilities(player, FireCombo.getBlockableAbilities(), loc, 1)) { fstream.remove(); } else AirAbility.removeAirSpouts(loc, player); WaterAbility.removeWaterSpouts(loc, player); EarthAbility.removeSandSpouts(loc, player); } } }
@SuppressWarnings("unchecked") protected String getVectorJSON(Vector vec) { JSONObject data = new JSONObject(); // x, y, z data.put("x", String.valueOf(vec.getX())); data.put("y", String.valueOf(vec.getY())); data.put("z", String.valueOf(vec.getZ())); return data.toJSONString(); }
private void tossItem(ItemStack dropItem) { Location loc = player.getLocation(); loc.setY(loc.getY() + 1); Item item = loc.getWorld().dropItem(loc, dropItem); Vector v = loc.getDirection().multiply(0.2); v.setY(0.2); item.setVelocity(v); }
@Override public void g(double x, double y, double z) { if (this.m_remoteEntity == null) { super.g(x, y, z); return; } Vector vector = ((RemoteBaseEntity) this.m_remoteEntity).onPush(x, y, z); if (vector != null) super.g(vector.getX(), vector.getY(), vector.getZ()); }
/** * Update the cached values for players velocity to be prepared to give them additional movement * freedom in their next move events * * @param v * @param data */ public void updateVelocity(Vector v, MovingData data) { // Compare the velocity vector to the existing movement freedom that we've from previous events double tmp = (Math.abs(v.getX()) + Math.abs(v.getZ())) * 3D; if (tmp > data.horizFreedom) data.horizFreedom = tmp; if (v.getY() > data.maxYVelocity) { data.maxYVelocity = v.getY(); } }
/** * Set the location of the item and put it on the right place on the block * * @param location The location of the item/shop block */ private void setLocation(Location location) { this.location = location.getBlock().getLocation(); // simply clear everything after the comma. Vector vec = this.location.toVector(); vec.add(new Vector(0.5, 0.6, 0.5)); this.location = vec.toLocation(this.location.getWorld()); if (getItem() != null) { getItem().teleport(this.location); } }
@Override public boolean isInside(BlockRegion block) { Vector point = new Vector(block.getX(), block.getY(), block.getZ()); if (point.getY() >= origin.getY() && point.getY() <= origin.getY() + height) { return Math.pow(point.getX() - origin.getX(), 2.0D) + Math.pow(point.getZ() - origin.getZ(), 2.0D) < (radius * radius); } return false; /* if(infinite) { return matchesXZ(block); } BlockRegion check = new BlockRegion(block.getStringX(), values.get(0).getStringY(), block.getStringZ()); double max = check.getDoubleY() + height; for(BlockRegion region : getValues()) { if(region.isInside(check) && block.getDoubleY() <= max) { return true; } } return false; */ }
@Override public void onRun() { Location location = getLocation(); for (int i = 0; i < particles; i++) { Vector vector = RandomUtils.getRandomVector().multiply(radius); if (!sphere) vector.setY(Math.abs(vector.getY())); location.add(vector); particle.display(location, visibleRange); location.subtract(vector); } }
/** * Fill the {@link Cube} with a specific block type. * * @param type Block type. * @see http://www.minecraftwiki.net/wiki/Data_values */ public void fill(int type) { World world = point.getWorld(); Vector end = end(); for (int x = point.getBlockX(); x < end.getBlockX(); x++) { for (int y = point.getBlockY(); y < end.getBlockY(); y++) { for (int z = point.getBlockZ(); z < end.getBlockZ(); z++) { Block block = world.getBlockAt(x, y, z); block.setTypeId(type); } } } }
@Override public void writeData(SpoutOutputStream output) throws IOException { output.writeString(text); output.writeDouble(location.getX()); output.writeDouble(location.getY()); output.writeDouble(location.getZ()); output.writeFloat(scale); output.writeInt(duration); output.writeDouble(movement.getX()); output.writeDouble(movement.getY()); output.writeDouble(movement.getZ()); }
@EventHandler public void onChat(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); String message = event.getMessage(); if (message.equalsIgnoreCase("test")) { event.setCancelled(true); player.sendMessage(message); Vector vector = getPlayerVector(player); // player.setVelocity(vector.multiply(2)); player.launchProjectile(Fireball.class).setVelocity(vector.multiply(5)); } }
@EventHandler(priority = EventPriority.NORMAL) public void EnterCart(final VehicleEnterEvent event) { Entity e = event.getVehicle(); // get the vehicle Vector dir = event .getEntered() .getLocation() .getDirection(); // get who entered it and what direction they were looking if (e instanceof Minecart) { e.setVelocity(dir.multiply(1)); } }
public static void checkSecond() { for (Item i : Bukkit.getWorld("PrisonMap").getEntitiesByClass(Item.class)) { if (tnts.contains(i.getUniqueId())) { ParticleEffect.SMOKE_NORMAL.display( 0.25f, 0.25f, 0.25f, 0.0001f, 5, i.getLocation().clone().add(0, 0.5, 0), 100); if (i.getTicksLived() > 30) { ParticleEffect.EXPLOSION_HUGE.display( 0.5f, 0.5f, 0.5f, 0.1f, 5, i.getLocation().clone().add(0, 1, 0), 100); for (Entity e : i.getNearbyEntities(3.5, 3.5, 3.5)) { if (e instanceof Player) { Location midPoint = i.getLocation(); Vector direction = e.getLocation().toVector().subtract(midPoint.toVector()).normalize(); direction.multiply(1.1).setY(0.7); e.setVelocity(direction); ((Player) e).damage(0.0); } } final List<Location> blocks = new ArrayList<Location>(); int radius = 3; int bX = i.getLocation().getBlockX(); int bY = i.getLocation().getBlockY(); int bZ = i.getLocation().getBlockZ(); for (int x = bX - radius; x <= bX + radius; x++) { for (int y = bY - radius; y <= bY + radius; y++) { for (int z = bZ - radius; z <= bZ + radius; z++) { double distance = ((bX - x) * (bX - x) + ((bZ - z) * (bZ - z)) + ((bY - y) * (bY - y))); if (distance < radius * radius) { Location loc = new Location(i.getWorld(), x, y, z); if (loc.getBlock().getType() != Material.AIR) { blocks.add(loc); } } } } } for (Location loc : blocks) { Random r = new Random(); int i1 = r.nextInt(3) + 1; if (Game.isBreakable(loc.getBlock().getType()) && (i1 == 1 || i1 == 2)) { loc.getBlock().setType(Material.AIR); } } Game.playSound(Sound.EXPLODE, i.getLocation(), 1f, 1f); tnts.remove(i.getUniqueId()); i.teleport(i.getLocation().subtract(0, 500, 0)); } } } }
protected String getVector(Vector vec) { String ret = "{"; ret += "\"x\":\"" + vec.getX() + "\""; ret += ",\"y\":\"" + vec.getY() + "\""; ret += ",\"z\":\"" + vec.getZ() + "\""; ret += "}"; if (!isJSON(ret)) return getVectorJSON(vec); try { getVector(ret); } catch (Exception ex) { return getVectorJSON(vec); } return ret; }
// Finds points on a line extending infinitely through the points startLoc and endLoc intersecting // a circle centered at circleLoc private List<Location> getCollisionPoints( Location startLoc, Location endLoc, Location circleLoc, double radiusSquared) { Vector delta = vectorFromLocations(startLoc, endLoc); Vector circleLocInTermsOfStart = vectorFromLocations(startLoc, circleLoc); boolean flipped = false; if (delta.getX() == 0) { flipped = true; flipXZ(delta); flipXZ(circleLocInTermsOfStart); } circleLocInTermsOfStart.add(new Vector(0.5, 0, 0.5)); double slope = delta.getZ() / delta.getX(); double circleX = circleLocInTermsOfStart.getX(); double circleZ = circleLocInTermsOfStart.getZ(); double circleXSquared = circleX * circleX; double circleZSquared = circleZ * circleZ; List<Double> xs = getSolutions( slope * slope + 1, -(2 * circleZ * slope + 2 * circleX), circleXSquared + circleZSquared - radiusSquared); List<Location> results = new ArrayList<Location>(); for (double x : xs) { Vector offset = new Vector(x, 0, x * slope); if (flipped) flipXZ(offset); results.add(startLoc.clone().add(offset)); } return results; }