private Region parseHalves(Element el, double dir) throws InvalidXMLException { final List<HalfspaceRegion> halves = new ArrayList<>(); XMLUtils.parseNumber(el, "x", Double.class).infinity(true).optional().ifPresent(x -> halves.add(new HalfspaceRegion(new Vector(x, 0, 0), new Vector(dir, 0, 0))) ); XMLUtils.parseNumber(el, "y", Double.class).infinity(true).optional().ifPresent(y -> halves.add(new HalfspaceRegion(new Vector(0, y, 0), new Vector(0, dir, 0))) ); XMLUtils.parseNumber(el, "z", Double.class).infinity(true).optional().ifPresent(z -> halves.add(new HalfspaceRegion(new Vector(0, 0, z), new Vector(0, 0, dir))) ); if(halves.isEmpty()) { throw new InvalidXMLException("Expected at least one of x, y, or z attributes", el); } return new Intersection(halves); }
@Override public void onTick() { if (target.isDead()) { return; } double speed = this.entity.getVelocity().length() * 0.9D + 0.14D; Vector velocity = null; Vector direction = this.entity.getVelocity().clone().normalize(); Vector targetDirection = this.target.getLocation().clone().add(new Vector(0, 0.5D, 0)) .subtract(this.entity.getLocation()).toVector(); Vector targetDirectionNorm = targetDirection.clone().normalize(); double angle = direction.angle(targetDirectionNorm); if (angle < 0.12D) { velocity = direction.clone().multiply(speed); } else { velocity = direction.clone().multiply((angle - 0.12D) / angle) .add(targetDirectionNorm.clone().multiply(0.12D / angle)).normalize().multiply(speed); } this.entity.setVelocity(velocity.add(new Vector(0.0D, 0.03D, 0.0D))); }
public static BoundingBoxWrapper getBB(Entity forWhat) { try { Object aaBb = getBB.invoke(getHandle.invoke(craftEntity.cast(forWhat))); double[] c = new double[]{ (double) coordinates[0].get(aaBb), (double) coordinates[1].get(aaBb), (double) coordinates[2].get(aaBb), (double) coordinates[3].get(aaBb), (double) coordinates[4].get(aaBb), (double) coordinates[5].get(aaBb) }; BoundingBoxWrapper box = new BoundingBoxWrapper(new Vector(c[0], c[1], c[2]), new Vector(c[3], c[4], c[5])); box.unshift(forWhat.getLocation()); return box; } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); return null; } }
public void ejectMass() { if(!action) return; if(mass >= 32) { mass -= 16; final StaticCell cell = new StaticCell(12, getX(), getY()); cell.setInvinsible(true); int size = (int) (Math.floor(Math.cbrt(this.mass))); if (size < 3) size = 3; Vector vector = player.getPlayer().getLocation().getDirection().setY(0).normalize().multiply((double)size / 1.5D); cell.setVelocity(vector); AgarMC plugin = AgarMC.get(); plugin.getGame().addStaticCell(cell); plugin.getServer().getScheduler().runTaskLater(plugin, () -> cell.setInvinsible(false), 10L); recalculateSize(); } }
public KillAuraTask(final Player player) { super(player, true); this.touched = new HashMap<>(); this.angles = new HashMap<>(); this.positionsTemplate = new ArrayList<>(); this.nextTest = System.currentTimeMillis(); this.numberDisplayed = 1; this.activeCheck = true; this.isTouched = false; this.positionsTemplate.add(new Vector(3, 2.5, 1.5)); this.positionsTemplate.add(new Vector(2.5, 1, -2)); this.positionsTemplate.add(new Vector(0, 0.5, 4)); this.positionsTemplate.add(new Vector(0, 4, -2.5)); this.positionsTemplate.add(new Vector(0, 4, 2.5)); this.positionsTemplate.add(new Vector(3, 0.5, -3)); this.positionsTemplate.add(new Vector(-4, 0.5, 2)); this.positionsTemplate.add(new Vector(0, 4.5, 0)); this.positionsTemplate.add(new Vector(3, 0.2, 3)); this.positionsTemplate.add(new Vector(-2, 4.5, 0)); this.resetAngles(); }
@Override public void onRun() { Location location = getLocation(); location.add(0, 0.5, 0); for (int i = 0; i < particles; i++) { float alpha = ((MathUtils.PI / compilation) / particles) * i; double phi = Math.pow(Math.abs(MathUtils.sin(2 * compilation * alpha)) + factorInnerSpike * Math.abs(MathUtils.sin(compilation * alpha)), 1 / compressYFactorTotal); Vector vector = new Vector(); vector.setY(phi * (MathUtils.sin(alpha) + MathUtils.cos(alpha)) * yFactor); vector.setZ(phi * (MathUtils.cos(alpha) - MathUtils.sin(alpha)) * zFactor); VectorUtils.rotateVector(vector, 0, -location.getYaw() * MathUtils.degreesToRadians + (Math.PI / 2f), 0); display(particle, location.add(vector), this.clr); location.subtract(vector); } }
EventRuleImpl(EventRuleScope scope, Region region, Filter filter, Kit kit, boolean lendKit, Vector velocity, @Nullable BaseComponent message, boolean earlyWarning) { this.scope = scope; this.region = region; this.filter = filter; this.kit = kit; this.lendKit = lendKit; this.velocity = velocity; this.message = message; this.earlyWarning = earlyWarning; }
private ArrayList<Vector> getVectorsNormal(LivingEntity e) { ArrayList<Vector> vectors = new ArrayList<Vector>(); Vector v = e.getEyeLocation().getDirection().normalize(); v.setY(0); vectors.add(v); double z = v.getZ(); double x = v.getX(); double radians = Math.atan(z / x); if (x < 0) radians += Math.PI; for (int k = 1; k < 4; k++) { Vector v2 = new Vector(); v2.setY(v.getY()); v2.setX(Math.cos(radians + k * Math.PI / 2)); v2.setZ(Math.sin(radians + k * Math.PI / 2)); vectors.add(v2.normalize()); } return vectors; }
public void pullEntityToLocation(Entity e, Location loc) { Location entityLoc = e.getLocation(); entityLoc.setY(entityLoc.getY() + 0.5D); e.teleport(entityLoc); double g = -0.08D; if (loc.getWorld() != entityLoc.getWorld()) return; double d = loc.distance(entityLoc); double t = d; double v_x = (1.0D + 0.07000000000000001D * t) * (loc.getX() - entityLoc.getX()) / t; double v_y = (1.0D + 0.03D * t) * (loc.getY() - entityLoc.getY()) / t - 0.5D * g * t; double v_z = (1.0D + 0.07000000000000001D * t) * (loc.getZ() - entityLoc.getZ()) / t; Vector v = e.getVelocity(); v.setX(v_x); v.setY(v_y); v.setZ(v_z); e.setVelocity(v); e.setFallDistance(0f); }
public void launchFireworkDisplay(final World w, final Location loc) { Firework fw = (Firework) w.spawn(loc.clone().add(new Vector(getRandomNum(5, -5), 1, getRandomNum(5, -5))), Firework.class); FireworkMeta meta = fw.getFireworkMeta(); FireworkEffect effect = SkyWarsReloaded.getNMS().getFireworkEffect(getRandomColor(),getRandomColor(), getRandomColor(), getRandomColor(), getRandomColor(), getRandomType()); meta.addEffect(effect); meta.setPower(getRandomNum(4, 1)); fw.setFireworkMeta(meta); fireworksCount++; if (fireworksCount < ((SkyWarsReloaded.getCfg().getTimeAfterGame() - 5)*4)) { SkyWarsReloaded.get().getServer().getScheduler().scheduleSyncDelayedTask(SkyWarsReloaded.get(), new Runnable() { public void run() { launchFireworkDisplay(w, loc); } }, 5); } }
/** * Teleport a {@link FakeArmorstand} to a specific {@link Location} in certain intervals, which is visible for all Players * * @param p the {@link Player} to teleport the {@link FakeArmorstand} for * @param to the {@link Location} where the {@link FakeArmorstand} should be teleported to * @param teleportCount the amount of teleportation that should be made * @param wait the amount of time to wait 'till the next teleport starts * @param armorstand the {@link FakeArmorstand} which should be teleported */ public static void splitTeleportArmorstand(final Player p, final Location to, final int teleportCount, final long wait, final FakeArmorstand armorstand) { final Location currentLocation = armorstand.getCurrentlocation(); Vector between = to.toVector().subtract(currentLocation.toVector()); final double toMoveInX = between.getX() / teleportCount; final double toMoveInY = between.getY() / teleportCount; final double toMoveInZ = between.getZ() / teleportCount; SPLIT_MAP.put(p.getName(), new BukkitRunnable() { public void run() { if (!LocationUtil.isSameLocation(currentLocation, to)) { teleportArmorstand(p, currentLocation.add(new Vector(toMoveInX, toMoveInY, toMoveInZ)), armorstand); } else this.cancel(); } }.runTaskTimer(AlphaLibary.getInstance(), 0, wait)); }
public void run() { Vector headMove = null; if (this.start == 0l) { // start headMove = start(); } else if (!isDone()) { // continue; headMove = step(); } else { // done throw new RuntimeException("Done this animation"); } if (player != null) { Location bloc = player.getEyeLocation().clone(); Location loc = player.getEyeLocation().clone().setDirection(bloc.getDirection().clone().add(headMove)); ((CraftPlayer)player).getHandle().playerConnection.sendPacket(new PacketPlayOutPosition(0.0, 0.0, 0.0, loc.getYaw() - bloc.getYaw(), loc.getPitch() - bloc.getPitch(), flags, 99)); } }
/** * Teleport a {@link FakeBigItem} to a specific {@link Location} in certain intervals, which is visible for all Players * * @param p the {@link Player} to teleport the {@link FakeBigItem} for * @param to the {@link Location} where the {@link FakeBigItem} should be teleported to * @param teleportCount the amount of teleportation that should be made * @param wait the amount of time to wait 'till the next teleport starts * @param item the {@link FakeBigItem} which should be teleported */ public static void splitTeleportBigItem(final Player p, final Location to, final int teleportCount, final long wait, final FakeBigItem item) { final Location currentLocation = item.getCurrentlocation(); Vector between = to.toVector().subtract(currentLocation.toVector()); final double toMoveInX = between.getX() / teleportCount; final double toMoveInY = between.getY() / teleportCount; final double toMoveInZ = between.getZ() / teleportCount; SPLIT_MAP.put(p.getName(), new BukkitRunnable() { public void run() { if (!LocationUtil.isSameLocation(currentLocation, to)) { teleportBigItem(p, currentLocation.add(new Vector(toMoveInX, toMoveInY, toMoveInZ)), item); } else this.cancel(); } }.runTaskTimer(AlphaLibary.getInstance(), 0, wait)); }
@Override public void onRun() { // Prevents an excess of particles if (last != null && last.getX() == getEntity().getLocation().getX() && last.getZ() == getEntity().getLocation().getZ()) return; last = getEntity().getLocation(); Block block = this.getEntity().getLocation().add(0, -0.4, 0).getBlock(); Material type = block.getType(); // If the step should be displayed or not if (type.isBlock() && type.isSolid() && !type.isTransparent()) { Location loc = getEntity().getLocation(); loc.setY(block.getY()); loc = loc.add(0, 1 + Math.random() / 100, 0); Vector dir = VectorUtils.rotateAroundAxisY(getEntity().getLocation().getDirection().setY(0).normalize(), p ? 90 : -90).multiply(0.25); display(ParticleEffect.FOOTSTEP, loc.add(dir.getX(), 0, dir.getZ()), 7, 0); p = !p; } }
/**Dungeon activation function called when a player gives the /start command. Calls the genEntry() function at that players position. * @param p The player that gave the /start command. */ private void startDungeon(Player p) { // calc starting location in front of player on level ground: // also check if ground is solid. if not then paste over the gras etc. int initDist = 10; // distance to player Vector start = new Vector(p.getLocation().getBlockX(),p.getLocation().getBlockY(),p.getLocation().getBlockZ()); Direc playerDirec = Helper.getPlayerDirec(p); int deltaX = (int)Math.round(-Helper.sind(playerDirec.degree())*initDist); int deltaZ = (int)Math.round(+Helper.cosd(playerDirec.degree())*initDist); start.add(new Vector(deltaX,0,deltaZ)); int solidOffset = 0; if (world.getHighestBlockAt(start.getBlockX(), start.getBlockZ()).getType().isSolid()) { solidOffset = 1; } start.setY(world.getHighestBlockYAt(start.getBlockX(), start.getBlockZ())+solidOffset); genEntry(start, playerDirec); }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPunch(BlockPunchEvent event) { final MatchPlayer player = getMatch().getPlayer(event.getPlayer()); if(player == null) return; RayBlockIntersection hit = event.getIntersection(); BlockDrops drops = getRuleSet().getDrops(event, hit.getBlock().getState(), player.getParticipantState()); if(drops == null) return; MaterialData oldMaterial = hit.getBlock().getState().getData(); replaceBlock(drops, hit.getBlock(), player); // Play a fake punching effect if the block is punchable. Use raw particles instead of // playBlockBreakEffect so the position is precise rather than in the block center. Object packet = NMSHacks.blockCrackParticlesPacket(oldMaterial, false, hit.getPosition(), new Vector(), 0, 5); for(MatchPlayer viewer : getMatch().getPlayers()) { if(viewer.getBukkit().getEyeLocation().toVector().distanceSquared(hit.getPosition()) < 16 * 16) { NMSHacks.sendPacket(viewer.getBukkit(), packet); } } NMSHacks.playBlockPlaceSound(hit.getBlock().getWorld(), hit.getPosition(), oldMaterial.getItemType(), 1); dropObjects(drops, player, hit.getPosition().toLocation(hit.getBlock().getWorld()), 1d, false); }
@Override public void run() { if (!this.arena.isEnabled()) return; this.timer--; if (this.timer <= 0) { for (final Entity entity : this.arena.getBallSpawnLocation().getWorld().getEntities()) { if (!(entity instanceof Player) && !(entity instanceof Rabbit) && !(entity instanceof ArmorStand) && !this.isCustomDrop(entity)) { if (this.arena.isLocationInArea(entity.getLocation())) { final Vector vector = Config.getInstance().getEntityProtectionVelocity(); entity.getLocation().setDirection(vector); entity.setVelocity(vector); } } } this.updateSigns(); this.fixCachedRangePlayers(); if (this.arena.getTeamMeta().isSpectatorMessagesEnabled()) { for (final Player player : this.getPlayersInRange()) { if (!this.playData.contains(player)) this.playData.add(player); } this.arena.getTeamMeta().getScoreboard().play(null, this.redGoals, this.blueGoals, this.getPlayersInRange()); } else { this.arena.getTeamMeta().getScoreboard().play(null, this.redGoals, this.blueGoals, this.getPlayers()); } this.timer = 20; } super.run(); }
protected Region(String name, Location pos1, Location pos2, int levelMin, int levelMax) { if (pos1 != null && pos2 != null) { if (pos1.getWorld() != null && pos2.getWorld() != null) { if (!pos1.getWorld().getUID().equals(pos2.getWorld().getUID())) { throw new IllegalStateException("The 2 locations of the region must be in the same world!"); } } else { throw new NullPointerException("One/both of the worlds is/are null!"); } this.worldName = pos1.getWorld().getName(); double x1 = Math.min(pos1.getX(), pos2.getX()); double y1 = Math.min(pos1.getY(), pos2.getY()); double z1 = Math.min(pos1.getZ(), pos2.getZ()); double x2 = Math.max(pos1.getX(), pos2.getX()); double y2 = Math.max(pos1.getY(), pos2.getY()); double z2 = Math.max(pos1.getZ(), pos2.getZ()); this.min = new Vector(x1, y1, z1); this.max = new Vector(x2, y2, z2); } if (levelMax < 0 || levelMin < 0) { throw new IllegalArgumentException("Max/min level cannot be less than 0!"); } if (levelMax < levelMin) { throw new IllegalArgumentException("Max level cannot be less than min level!"); } this.levelMin = levelMin; this.levelMax = levelMax; this.name = name; this.npcs = new HashMap<>(); this.rewards = new ArrayList<>(); this.id = IDs++; }
private MonumentWool findMonumentWool(Vector point) { for(MonumentWool wool : this.wools) { if(wool.getDefinition().getPlacementRegion().contains(point)) { return wool; } } return null; }
public boolean intersects(Vector min, Vector max, double blocksAway, double accuracy) { List<Vector> positions = traverse(blocksAway, accuracy); for (Vector position : positions) { if (intersects(position, min, max)) return true; } return false; }
private List<ArmorStandData> createExtractionASD() { List<ArmorStandData> asds = new ArrayList<>(); ItemStack block = ITEM_EXTRACTION_BLOCK; asds.add(new ArmorStandData(new RelLoc(0.05f, -0.35f, 0.5f - 0.44f), new Vector(1, 0, 0), false, null, ITEM_BLAZE, new Vector(0f, 0f, 0f), new Vector(-10f, 0f, 45f))); asds.add(new ArmorStandData(new RelLoc(0.05f, -1.0307f, 0.5f - 0.86f), new Vector(1, 0, 0), false, null, ITEM_BLAZE, new Vector(0f, 0f, 0f), new Vector(-10f, 0f, 135f))); asds.add(new ArmorStandData(new RelLoc(0.05f, -1.0307f - 0.45f, 0.5f - 0.37f), new Vector(1, 0, 0), false, null, ITEM_BLAZE, new Vector(0f, 0f, 0f), new Vector(-10f, 0f, 135f))); asds.add(new ArmorStandData(new RelLoc(0.05f, -0.35f - 0.45f, 0.5f - 0.93f), new Vector(1, 0, 0), false, null, ITEM_BLAZE, new Vector(0f, 0f, 0f), new Vector(-10f, 0f, 45f))); asds.add(new ArmorStandData(new RelLoc(0.55f - 0.3f, -0.43f, 0.5f), new Vector(1, 0, 0), true, block, null, new Vector(0f, 0f, 0f), new Vector(0f, 0f, 0f))); asds.add(new ArmorStandData(new RelLoc(0.55f + 0.2f, -0.43f, 0.5f), new Vector(1, 0, 0), true, block, null, new Vector(0f, 0f, 0f), new Vector(0f, 0f, 0f))); return asds; }
public Vector midPoint(){ return new Vector( (minX + maxX) / 2.0, (minY + maxY) / 2.0, (minZ + maxZ) / 2.0 ); }
public static void heartBeam(PlayerInteractEvent event) { final Player player = event.getPlayer(); List<String> combo = Datafiles.getCombos(event.getPlayer().getName()); new BukkitRunnable() { double t = 0; Location loc = player.getLocation(); Vector direction = loc.getDirection().normalize(); public void run() { t = t + 0.5; double x = direction.getX() * t; double y = direction.getY() * t + 1.5; double z = direction.getZ() * t; loc.add(x, y, z); ParticleEffect.HEART.display(0, 0, 0, 4, 5, loc, 30); for(Entity e: loc.getChunk().getEntities()){ if(e.getLocation().distance(loc) < 1.0){ if(!e.equals(player)){ if(e instanceof Player){ Player p = (Player) e; p.setHealth(p.getHealth()-10); } } } } loc.subtract(x, y, z); if(t == 0.5){ ActionBarAPI.sendActionBar(player, "§c§lHEAL SPELL §7§lACTIVATED"); } if (t > 30) { this.cancel(); Location loc1 = new Location(player.getWorld(), x, y, z); Bukkit.getWorld(player.getWorld().getName()).createExplosion(loc1, 4.0F); } } }.runTaskTimer(Main.getInstance(), 0, 1); }
public static void takeOff(Player observer, Location loc) { for(int i = 0; i < GizmoConfig.SMOKE_COUNT; i++) { double angle = 2 * Math.PI * i / GizmoConfig.SMOKE_COUNT; Location base = loc.clone().add(new Vector(GizmoConfig.SMOKE_RADIUS * Math.cos(angle), 0, GizmoConfig.SMOKE_RADIUS * Math.sin(angle))); for(int j = 0; j <= 8; j++) { observer.playEffect(base, Effect.SMOKE, j); } } }
@Override public void execute(KingdomFactionsPlayer player) { noFallDamage.add(player.getName()); double forwardPowerModifier = 1.5D; double upwardPowerModifier = forwardPowerModifier * 2.0D; double fwv = 2.0D; double uwv = 0.7D; Vector dir = player.getLocation().getDirection(); dir.setY(0).normalize().multiply(fwv * forwardPowerModifier).setY(uwv * upwardPowerModifier); player.getPlayer().setVelocity(dir); final World w = player.getPlayer().getWorld(); w.playSound(player.getLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F); new BukkitRunnable() { int autoStopCount = 0; @SuppressWarnings("deprecation") public void run() { if ((this.autoStopCount <= 30) && (Leap.noFallDamage.contains(player.getName())) && (Bukkit.getPlayer(player.getName()) != null) && (!Bukkit.getPlayer(player.getName()).isOnGround())) { Player p = Bukkit.getPlayer((player.getName())); w.playEffect(p.getLocation(), Effect.ENDER_SIGNAL, 1); this.autoStopCount += 1; } else { if ((Leap.noFallDamage.contains(player.getName()))) { Leap.noFallDamage.remove(player.getName()); } cancel(); } } }.runTaskTimer(KingdomFactionsPlugin.getInstance(), 5L, 3L); }
/** * Calculates the navigation path and returns true if found. * * @return success */ @Override public boolean a() { if (this.player == null) { return this.path != null; } if (!this.entity.getWorld().getWorldData().getName().equals(this.player.getWorld().getName())) { this.entity.getBukkitEntity().teleport(this.player.getLocation()); } else if (this.entity.getBukkitEntity().getLocation().distance(this.player.getLocation()) > ConfigPet.getInstance().getBlocksAwayFromPlayer()) { this.counter2 = PetBlockHelper.afraidWaterEffect(this.petBlock, this.counter2); final Location targetLocation = this.player.getLocation(); this.entity.getNavigation().m(); this.entity.getNavigation(); this.path = this.entity.getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1); this.entity.getNavigation(); if (this.entity.getBukkitEntity().getLocation().distance(this.player.getLocation()) > ConfigPet.getInstance().getFollow_maxRangeTeleport()) this.entity.getBukkitEntity().teleport(this.player.getLocation()); if (Math.abs(this.entity.getBukkitEntity().getLocation().getY() - targetLocation.getY()) >= 2) { this.counter++; } else { this.counter = 0; } if (this.counter > 5) { this.entity.getBukkitEntity().setVelocity(new Vector(0.1, (float) ConfigPet.getInstance().getModifier_petclimbing() * 0.1, 0.1)); this.counter = 0; } if (this.path != null) { this.c(); } } return this.path != null; }
@Override public ArmorStandData createConnASD(ModelledPipeConnModelData data) { ItemStack hoe = data.isIron_ExtractionPipe_ActiveSide() ? ITEM_HOE_CONN_EXTRACTION_CLOSED : ITEM_HOE_CONN_EXTRACTION_OPENED; ArmorStandData asd; if (data.getConnDirection() == WrappedDirection.UP) { asd = new ArmorStandData(new RelLoc(0.75f, 0.5f - 1.4369f, 0.5f), new Vector(1, 0, 0), false, hoe, null, new Vector(-90f, 0f, 0f), new Vector(0f, 0f, 0f)); } else if (data.getConnDirection() == WrappedDirection.DOWN) { asd = new ArmorStandData(new RelLoc(0.25f, 0.5f - 1.1885f - 0.25f, 0.5f), new Vector(1, 0, 0), false, hoe, null, new Vector(90f, 0f, 0f), new Vector(0f, 0f, 0f)); } else { asd = new ArmorStandData(new RelLoc(0.5f, 0.5f - 1.1875f, 0.5f), new Vector(data.getConnDirection().getX(), 0, data.getConnDirection().getZ()), false, hoe, null, new Vector(180f, 180f, 0f), new Vector(0f, 0f, 0f)); } return asd; }
@Override public void onRun() { if (font == null) { cancel(); return; } Location location = getLocation(); location.add(0, 1.2, 0); if(!lockedYaw) { yaw = -location.getYaw(); dir = location.getDirection(); dir = dir.normalize().setY(0); lockedYaw = true; } location.add(dir); try { if (image == null) { image = StringParser.stringToBufferedImage(font, text); } for (int y = 0; y < image.getHeight(); y += stepY) { for (int x = 0; x < image.getWidth(); x += stepX) { int clr = image.getRGB(image.getWidth() - 1 - x, y); if (clr != Color.black.getRGB()) continue; Vector v = new Vector((float) image.getWidth() / 2 - x, (float) image.getHeight() / 2 - y, 0).multiply(size); VectorUtils.rotateAroundAxisY(v, yaw * MathUtils.degreesToRadians); display(particle, location.add(v)); location.subtract(v); } } } catch (Exception ex) { cancel(true); } }
/** * Gets called when a player interacts with a ball * * @param event event */ @EventHandler public void ballInteractEvent(BallInteractEvent event) { final Game game; if ((game = this.controller.getGameFromBall(event.getBall())) != null) { final GameEntity entity = (GameEntity) game; if (entity.ballPreviousCacheLocation != null && entity.ballPreviousCacheLocation.distance(event.getBall().getLocation().toVector()) < 2) { entity.ballCornerBumper++; } else { entity.ballCornerBumper = 0; } if (entity.ballCornerBumper >= 3) { final Vector direction = entity.arena.getBallSpawnLocation().toVector().subtract(event.getBall().getLocation().toVector()); int x = 1; int z = 1; if (direction.getX() < 0) x = -1; if (direction.getZ() < 0) z = -1; event.getBall().teleport(new Location(event.getBall().getLocation().getWorld(), event.getBall().getLocation().getX() + x, event.getBall().getLocation().getY(), event.getBall().getLocation().getZ() + z)); entity.ballCornerBumper = 0; } entity.ballPreviousCacheLocation = event.getBall().getLocation().toVector(); if (entity.blueTeam.contains(event.getPlayer())) { entity.lastHitTeam = Team.BLUE; } else { entity.lastHitTeam = Team.RED; } entity.lastHit = event.getPlayer(); } }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void lavaProtection(final BlockTransformEvent event) { if(event.getWorld() != this.match.getWorld()) return; Vector blockVector = BlockUtils.center(event.getNewState()).toVector(); for(Core core : this.cores) { if(core.getLavaRegion().contains(blockVector)) { event.setCancelled(true); } } }
public static @Nonnull Vector calculateLookVector(@Nonnull Location location) { double pitch = Math.toRadians(location.getPitch()); double yaw = Math.toRadians(location.getYaw()); Vector normal = new Vector( -(Math.cos(pitch) * Math.sin(yaw)), -Math.sin(pitch), Math.cos(pitch) * Math.cos(yaw) ); return normal; }
@Override public float getAngle(Vector from) { double dx = this.target.getX() - from.getX(); double dz = this.target.getZ() - from.getZ(); double distance = Math.sqrt(dx * dx + dz * dz); double dy = this.target.getY() - (from.getY() + 1.62); // add eye height so player actually looks at point return (float) Math.toDegrees(Math.atan2(-dy, distance)); }
@GameEvent public void onStep(@Nonnull PlayerInteractEvent event) { if (event.getAction() == Action.PHYSICAL) { if (event.getClickedBlock().getType() != Material.WOOD_PLATE && event.getClickedBlock().getType() != Material.STONE_PLATE) { return; } if (event.isCancelled()) { return; } double strength = 1.5; double up = 1; if (event.getClickedBlock().getRelative(BlockFace.DOWN, 2).getState() instanceof Sign) { Sign sign = (Sign) event.getClickedBlock().getRelative(BlockFace.DOWN, 2).getState(); if (sign.getLine(0).contains("[Boom]")) { try { strength = Double.parseDouble(sign.getLine(1)); up = Double.parseDouble(sign.getLine(2)); } catch (final Exception ex) { log.warning("Invalid boom sign at " + sign.getLocation()); } } } event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENTITY_ENDERDRAGON_SHOOT, 10.0F, 1.0F); event.getPlayer().playEffect(event.getPlayer().getLocation(), Effect.SMOKE, 10); Vector v = event.getPlayer().getLocation().getDirection().multiply(strength / 2).setY(up / 2); event.getPlayer().setVelocity(v); event.setCancelled(true); } }
@Override public void check() { super.check(); for(int y = 0; y <= 4; y++) { for(int x = 0; x <= 1; x++) { for(int z = 0; z <= 1; z++) { Vector vector = armorStand.getVelocity().setY(0).normalize(); for(int i = 0; i <= 3; i++) { Absorption.get().getGame().paintBlock(armorStand.getLocation().add(1 - x / 2 - vector.clone().multiply(i).getX(), -y, 1 - z / 2 - vector.clone().multiply(i).getZ()).getBlock(), COLOR); } } } } }
public RayParticleForm(Effect effect, EffectData<?> effectData, Location location, Vector direction, double dense, double lenght) { super(location, direction, dense, lenght, null); if (effectData != null) Validate.isTrue(effect.getData() != null && effect.getData().isAssignableFrom(effectData.getDataValue().getClass()), "Wrong kind of effectData for this effect!"); else { Validate.isTrue(effect.getData() == null, "Wrong kind of effectData for this effect!"); effectData = new EffectData<>(null); } EffectData<?> finalEffectData = effectData; setAction((p, loc) -> p.playEffect(loc, effect, finalEffectData.getDataValue())); }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void dispenserNukes(BlockTransformEvent event) { BlockState oldState = event.getOldState(); if(oldState instanceof Dispenser && this.properties.dispenserNukeLimit > 0 && this.properties.dispenserNukeMultiplier > 0 && event.getCause() instanceof EntityExplodeEvent) { EntityExplodeEvent explodeEvent = (EntityExplodeEvent) event.getCause(); Dispenser dispenser = (Dispenser) oldState; int tntLimit = Math.round(this.properties.dispenserNukeLimit / this.properties.dispenserNukeMultiplier); int tntCount = 0; for(ItemStack stack : dispenser.getInventory().contents()) { if(stack != null && stack.getType() == Material.TNT) { int transfer = Math.min(stack.getAmount(), tntLimit - tntCount); if(transfer > 0) { stack.setAmount(stack.getAmount() - transfer); tntCount += transfer; } } } tntCount = (int) Math.ceil(tntCount * this.properties.dispenserNukeMultiplier); for(int i = 0; i < tntCount; i++) { TNTPrimed tnt = this.getMatch().getWorld().spawn(BlockUtils.base(dispenser), TNTPrimed.class); tnt.setFuseTicks(10 + this.getMatch().getRandom().nextInt(10)); // between 0.5 and 1.0 seconds, same as vanilla TNT chaining Random random = this.getMatch().getRandom(); Vector velocity = new Vector(random.nextGaussian(), random.nextGaussian(), random.nextGaussian()); // uniform random direction velocity.normalize().multiply(0.5 + 0.5 * random.nextDouble()); tnt.setVelocity(velocity); callPrimeEvent(tnt, explodeEvent.getEntity(), false); } } }
@Override public boolean cast(final Player p, final PlayerDataRPG pd, final int level) { final Location start = p.getLocation().add(0, p.getEyeHeight() * 0.1, 0); Location permStart = p.getLocation().add(0, p.getEyeHeight() * 0.1, 0).clone(); Location loc = start; Vector direction = p.getLocation().getDirection().normalize(); direction.setY(0); int length = 5; Location prev = null; for (int k = 0; k < length; k++) { Location temp = loc.clone(); loc = loc.add(direction); if (loc.getBlock().getType().isSolid()) break; prev = temp.clone(); } if (prev != null) { RParticles.show(ParticleEffect.EXPLOSION_NORMAL, permStart, 10); RParticles.show(ParticleEffect.EXPLOSION_NORMAL, prev, 10); p.teleport(prev); } else { p.sendMessage(ChatColor.RED + "You can't flash through walls!"); return false; } Spell.notify(p, "You instantly teleport a short distance."); return true; }
/** * Calculates the navigation path and returns true if found. * * @return success */ @Override public boolean a() { if (this.player == null) { return this.path != null; } if (!this.entity.getWorld().getWorldData().getName().equals(this.player.getWorld().getName())) { this.entity.getBukkitEntity().teleport(this.player.getLocation()); } else if (this.entity.getBukkitEntity().getLocation().distance(this.player.getLocation()) > ConfigPet.getInstance().getBlocksAwayFromPlayer()) { this.counter2 = PetBlockHelper.afraidWaterEffect(this.petBlock, this.counter2); final Location targetLocation = this.player.getLocation(); this.entity.getNavigation().o(); this.entity.getNavigation(); this.path = this.entity.getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1); this.entity.getNavigation(); if (this.entity.getBukkitEntity().getLocation().distance(this.player.getLocation()) > ConfigPet.getInstance().getFollow_maxRangeTeleport()) this.entity.getBukkitEntity().teleport(this.player.getLocation()); if (Math.abs(this.entity.getBukkitEntity().getLocation().getY() - targetLocation.getY()) >= 2) { this.counter++; } else { this.counter = 0; } if (this.counter > 5) { this.entity.getBukkitEntity().setVelocity(new Vector(0.1, ConfigPet.getInstance().getModifier_petclimbing() * 0.1, 0.1)); this.counter = 0; } if (this.path != null) { this.c(); } } return this.path != null; }
/** * Calculates the navigation path and returns true if found. * * @return success */ @Override public boolean a() { if (this.player == null) { return this.path != null; } if (!this.entity.getWorld().getWorldData().getName().equals(this.player.getWorld().getName())) { this.entity.getBukkitEntity().teleport(this.player.getLocation()); } else if (this.entity.getBukkitEntity().getLocation().distance(this.player.getLocation()) > ConfigPet.getInstance().getBlocksAwayFromPlayer()) { this.counter2 = PetBlockHelper.afraidWaterEffect(this.petBlock, this.counter2); final Location targetLocation = this.player.getLocation(); this.entity.getNavigation().n(); this.entity.getNavigation(); this.path = this.entity.getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1); this.entity.getNavigation(); if (this.entity.getBukkitEntity().getLocation().distance(this.player.getLocation()) > ConfigPet.getInstance().getFollow_maxRangeTeleport()) this.entity.getBukkitEntity().teleport(this.player.getLocation()); if (Math.abs(this.entity.getBukkitEntity().getLocation().getY() - targetLocation.getY()) >= 2) { this.counter++; } else { this.counter = 0; } if (this.counter > 5) { this.entity.getBukkitEntity().setVelocity(new Vector(0.1, (float) ConfigPet.getInstance().getModifier_petclimbing() * 0.1, 0.1)); this.counter = 0; } if (this.path != null) { this.c(); } } return this.path != null; }
@EventHandler public void onGameTick(GameTickEvent event) { if(event.getTicksInSecond() < potionDropPerSecond) { ItemStack itemStack = new ItemStack(Material.POTION, 1, (byte) 8197); Item entity = this.potionDropLocation.getWorld().dropItem(potionDropLocation, itemStack); entity.setCustomName(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Potion"); entity.setCustomNameVisible(true); entity.setVelocity(new Vector(0, 0.47, 0).add(Utils.getRandomCircleVector() .multiply(potionVelocityMultiplier*Math.random()))); } }