/** * Determines the initial location of the fishing hook. * * @param player the player who is fishing * @return the initial location of the hook */ private Location calculateSpawnLocation(Player player) { Location loc = player.getEyeLocation(); Vector direction = loc.getDirection(); double dx = direction.getX() * player.getWidth() / 2; double dz = direction.getZ() * player.getWidth() / 2; loc.add(dx, 0, dz); return loc; } }
@Override public DynmapLocation getLocation() { if(player == null) { return null; } Location loc = player.getEyeLocation(); // Use eye location, since we show head return toLoc(loc); } @Override
public TorrentWave(final Player player, final double radius) { this(player, player.getEyeLocation(), radius); }
public static String handlePlayerPlaceHolder(Player player, String cmd) { cmd = cmd.replaceAll("\\{player}", player.getName()); cmd = cmd.replaceAll("\\{player\\.x}", Float.toString(-player.getLocation().getBlockX())); cmd = cmd.replaceAll("\\{player\\.y}", Float.toString(-player.getLocation().getBlockY())); cmd = cmd.replaceAll("\\{player\\.z}", Float.toString(-player.getLocation().getBlockZ())); cmd = cmd.replaceAll("\\{player\\.yaw}", Float.toString(90 + player.getEyeLocation().getYaw())); cmd = cmd.replaceAll("\\{player\\.pitch}", Float.toString(-player.getEyeLocation().getPitch())); cmd = cmd.replaceAll("\\{yaw}", Float.toString(player.getLocation().getYaw() + 90)); cmd = cmd.replaceAll("\\{pitch}", Float.toString(-player.getLocation().getPitch())); return cmd; }
private static boolean hasHeadRoom(Player player) { boolean hasHeadRoom = true; Block headBlock = player.getEyeLocation().getBlock(); for (int i = 0; i < 3; i++) { if (!headBlock.getRelative(BlockFace.UP, i).isEmpty()) { hasHeadRoom = false; break; } } return hasHeadRoom; } }
public ArrayList<BlockFace> getBlockFacesTowardsPlayer(final Location center) { final ArrayList<BlockFace> faces = new ArrayList<>(); final Vector toPlayer = GeneralMethods.getDirection(center, this.player.getEyeLocation()); final double[] vars = { toPlayer.getX(), toPlayer.getY(), toPlayer.getZ() }; for (int i = 0; i < 3; i++) { if (vars[i] != 0) { faces.add(GeneralMethods.getBlockFaceFromValue(i, vars[i])); } else { continue; } } return faces; }
@EventHandler public void onPlayerDeath(PlayerDeathEvent event) { Hologram hologram = HologramsAPI.createHologram(this, event.getEntity().getEyeLocation()); hologram.appendTextLine(ChatColor.RED + "Player " + ChatColor.GOLD + event.getEntity().getName() + ChatColor.RED + " died here!"); hologram.appendTextLine(ChatColor.GRAY + "Time of death: " + new SimpleDateFormat("H:m").format(new Date())); } }
@Override public void run() { if (player.getInventory().getItemInMainHand().equals(stack)) { burstTask.put(uuid, this.getTaskId()); if (count-- > 0) { fire(player, stack, player.getEyeLocation().getDirection()); return; } } burstTask.invalidate(uuid); this.cancel(); } }).runTaskTimer(RPGItems.plugin, burstInterval, burstInterval);
public static void play(Player player, int octave, Tone tone) { Sound s = null; try { s = Sound.valueOf("NOTE_PIANO"); } catch (Exception e) { s = Sound.valueOf("BLOCK_NOTE_HARP"); } player.playSound(player.getEyeLocation(), s, 1, NotePitch.getPitch(octave, tone)); }
private void getFloor() { this.floorblock = null; for (int i = 0; i <= this.maxHeightFromGround; i++) { final Block block = this.player.getEyeLocation().getBlock().getRelative(BlockFace.DOWN, i); if (GeneralMethods.isSolid(block) || block.isLiquid()) { this.floorblock = block; return; } } }
private void playTick(Player p, int tick) { song.getLayerHashMap().values().forEach((l) -> { Note note = l.getNote(tick); if (note != null) { p.playSound(p.getEyeLocation(), NoteBlockInstrument.getInstrument(note.getInstrument()), l.getVolume() * 100, NotePitch.getPitch(note.getKey() - 33)); } }); }
@Override public PowerResult<Double> hit(Player player, ItemStack stack, LivingEntity entity, double damage, EntityDamageByEntityEvent event) { if (ThreadLocalRandom.current().nextDouble(100) < chance) { damage *= factor; } if (getAngleBetweenVectors(((LivingEntity) event.getEntity()).getEyeLocation().getDirection(), player.getEyeLocation().getDirection()) < 90 && ThreadLocalRandom.current().nextDouble(100) < backstabChance) { damage *= backstabFactor; } return PowerResult.ok(damage); }
private void attack() { if (!this.formed || this.bPlayer.isOnCooldown("OctopusAttack")) { return; } this.bPlayer.addCooldown("OctopusAttack", this.usageCooldown); final double tentacleAngle = (new Vector(1, 0, 0)).angle(this.player.getEyeLocation().getDirection()) + this.angleIncrement / 2; for (double tangle = tentacleAngle; tangle < tentacleAngle + 360; tangle += this.angleIncrement) { final double phi = Math.toRadians(tangle); this.affect(this.player.getLocation().clone().add(new Vector(this.radius * Math.cos(phi), 1, this.radius * Math.sin(phi)))); } }
@EventHandler public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); DPortal dPortal = DPortal.getByLocation(plugin, player.getEyeLocation()); if (dPortal == null) { return; } Block blockFrom = event.getFrom().getBlock(); Block blockTo = event.getTo().getBlock(); if (blockFrom.equals(blockTo)) { return; } dPortal.teleport(player); }
@Override public void runCommand(CommandSender sender, Command baseCommand, String baseCommandLabel, String subCommandLabel, String[] subCommandArgs) { Player p = (Player) sender; Location eye = p.getEyeLocation(); SkyBlockLocation pos1 = new SkyBlockLocation(eye); SetupData state = states.getSetupState(((Player) sender).getUniqueId()); if (state.getOriginPos2() != null && !state.getOriginPos2().world.equalsIgnoreCase(pos1.world)) { sender.sendMessage(SkyTrans.get(TransKey.SWS_SETPOS1_POS2_OTHER_WORLD)); state.setOriginPos2(null); } sender.sendMessage(SkyTrans.get(TransKey.SWS_SETPOS1_CONFIRMATION)); state.setOriginPos1(pos1); } }
@Override public PowerResult<Void> rightClick(Player player, ItemStack stack, PlayerInteractEvent event) { if (!checkCooldown(this, player, cooldown, true, true)) return PowerResult.cd(); if (!getItem().consumeDurability(stack, costAoe)) return PowerResult.cost(); List<LivingEntity> entities = getLivingEntitiesInCone(getNearestLivingEntities(this, player.getEyeLocation(), player, range, 0), player.getLocation().toVector(), facing, player.getLocation().getDirection()); entities.forEach(entity -> { if (!getItem().consumeDurability(stack, costPerEntity)) return; stucked.put(entity.getUniqueId(), System.currentTimeMillis()); entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, duration, 10), true); entity.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, duration, 128), true); } ); return PowerResult.ok(); }
private void cook() { final ItemStack cooked = this.getCooked(this.player.getInventory().getItemInMainHand()); final HashMap<Integer, ItemStack> cantFit = this.player.getInventory().addItem(cooked); for (final int id : cantFit.keySet()) { this.player.getWorld().dropItem(this.player.getEyeLocation(), cantFit.get(id)); } final int amount = this.player.getInventory().getItemInMainHand().getAmount(); if (amount == 1) { this.player.getInventory().clear(this.player.getInventory().getHeldItemSlot()); } else { this.player.getInventory().getItemInMainHand().setAmount(amount - 1); } }
public WaterArmsFreeze(final Player player) { super(player); this.usageCooldownEnabled = getConfig().getBoolean("Abilities.Water.WaterArms.Arms.Cooldowns.UsageCooldown.Enabled"); this.iceRange = getConfig().getInt("Abilities.Water.WaterArms.Freeze.Range"); this.iceDamage = getConfig().getInt("Abilities.Water.WaterArms.Freeze.Damage"); this.usageCooldown = getConfig().getLong("Abilities.Water.WaterArms.Arms.Cooldowns.UsageCooldown.Freeze"); this.direction = player.getEyeLocation().getDirection(); this.createInstance(); }
public void drawCircle(final double theta, final double increment) { final double rotateSpeed = 45; this.revertBlocks(); this.direction = GeneralMethods.rotateXZ(this.direction, rotateSpeed); for (double i = 0; i < theta; i += increment) { final Vector dir = GeneralMethods.rotateXZ(this.direction, i - theta / 2).normalize().multiply(this.radius); dir.setY(0); final Block block = this.player.getEyeLocation().add(dir).getBlock(); this.location = block.getLocation(); if (block.getType() == Material.AIR && !GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { this.createBlock(block, Material.STATIONARY_WATER, (byte) 8); } } }
public void click() { if (!this.player.isSneaking()) { return; } this.player.getLocation().getWorld().playSound(this.player.getLocation(), Sound.BLOCK_STONE_BREAK, 2, 1); this.player.getLocation().getWorld().playSound(this.player.getLocation(), Sound.BLOCK_STONE_BREAK, 2, 1); this.player.getLocation().getWorld().playSound(this.player.getLocation(), Sound.BLOCK_STONE_BREAK, 2, 1); ParticleEffect.BLOCK_CRACK.display(new ParticleEffect.BlockData(this.headData.getItemType(), this.headData.getData()), 0.1F, 0.1F, 0.1F, 1, 32, this.player.getEyeLocation(), 128); ParticleEffect.BLOCK_CRACK.display(new ParticleEffect.BlockData(this.legsData.getItemType(), this.legsData.getData()), 0.1F, 0.1F, 0.1F, 1, 32, this.player.getLocation(), 128); this.bPlayer.addCooldown(this); this.remove(); }