So I am trying to create that if you are looking at an entity in the range of 12 blocks, it will heal them by 4 hearts. I think what my code does is heals everyone in the range of 12 blocks... Anyone help? I want it to heal the person you are looking at within 12 blocks. Code: Code: @EventHandler public void click(PlayerInteractEvent e) { Player player = e.getPlayer(); Player target = e.getPlayer(); Location loc = player.getLocation(); if(e.getAction() == Action.RIGHT_CLICK_AIR) { if(e.getItem().getType() == Material.INK_SACK) { for(Entity en : player.getNearbyEntities(12, 12, 12)) { player.sendMessage(ChatColor.GREEN + "You healed" + (en instanceof Player ? ((Player) en).getName() : en.getType().name())); if(en instanceof Player) { ((Player) en).setHealth(8); } } } }
What's the problem you're having? You just pasted some code and hoped for us to know what you're trying to ask lel
Do you read... The code currently I think heals everyone within the distance of 12 blocks. I want it to heal the player your looking at. HElp please!
@xXCapzXx So just check if the players pitch and yaw is looking at an entity and if the entity is a player then heal them 4 hearts???
Learn Java, if you don't know how to do such things you should learn the language. These are simple concepts, the bukkit forums are for helping which I did. It's not for spoon feeding code.
No, I am asking how to do this, I am new to bukkit, so this is the website where I come to read and learn and express myself.
Right here. You make an if statement see if the pitch and yaw is facing an entity from 12 blocks away, then check if the entity is a player with if statement again. Then if he/she is then heal the player. I'm not going to spoon feed you the code. You must learn that yourself. <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
Try getting the players target block, then check for entities within a certain distance around that block.
Please Correct Me If I'm Wrong, But Doesn't this heal the player that makes a Right Click Action with a stick? Then just add the radius Code: public void onClickStick(PlayerInteractionEvent e) Player p = e.getPlayer(); Action a = e.getAction(); if(a == Action.RIGHT_CLICK_AIR && e.getBlock() == Material.STICK){ p.setHealth(20.0D); p.setFoodLevel(20); p.setFireTicks(0); }
I am not that experienced with hashset<byte> Can you type the code for that. I have no clue what to put there.
why are you getting all the names of a 12 blocks ³ you should just pick up a player 12 blocks away, not a cube of 6 of radius
I used a tutorial but I forgot where I got it. First create a new class named Vector3D Code: /* * Attack hidden players * * Copyright 2012 Kristian S. Stangeland (Comphenix) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see <[url]http://www.gnu.org/licenses/>[/url]. */ import org.bukkit.Location; import org.bukkit.util.Vector; public class Vector3D { /** * Represents the null (0, 0, 0) origin. */ public static final Vector3D ORIGIN = new Vector3D(0, 0, 0); // Use protected members, like Bukkit public final double x; public final double y; public final double z; /** * Construct an immutable 3D vector. */ public Vector3D(double x, double y, double z) { this.x = x; this.y = y; this.z = z; } /** * Construct an immutable floating point 3D vector from a location object. * @param location - the location to copy. */ public Vector3D(Location location) { this(location.toVector()); } /** * Construct an immutable floating point 3D vector from a mutable Bukkit vector. * @param vector - the mutable real Bukkit vector to copy. */ public Vector3D(Vector vector) { if (vector == null) throw new IllegalArgumentException("Vector cannot be NULL."); this.x = vector.getX(); this.y = vector.getY(); this.z = vector.getZ(); } /** * Convert this instance to an equivalent real 3D vector. * @return Real 3D vector. */ public Vector toVector() { return new Vector(x, y, z); } /** * Adds the current vector and a given position vector, producing a result vector. * @param other - the other vector. * @return The new result vector. */ public Vector3D add(Vector3D other) { if (other == null) throw new IllegalArgumentException("other cannot be NULL"); return new Vector3D(x + other.x, y + other.y, z + other.z); } /** * Adds the current vector and a given vector together, producing a result vector. * @param //other - the other vector. * @return The new result vector. */ public Vector3D add(double x, double y, double z) { return new Vector3D(this.x + x, this.y + y, this.z + z); } /** * Substracts the current vector and a given vector, producing a result position. * @param other - the other position. * @return The new result position. */ public Vector3D subtract(Vector3D other) { if (other == null) throw new IllegalArgumentException("other cannot be NULL"); return new Vector3D(x - other.x, y - other.y, z - other.z); } /** * Substracts the current vector and a given vector together, producing a result vector. * @param //other - the other vector. * @return The new result vector. */ public Vector3D subtract(double x, double y, double z) { return new Vector3D(this.x - x, this.y - y, this.z - z); } /** * Multiply each dimension in the current vector by the given factor. * @param factor - multiplier. * @return The new result. */ public Vector3D multiply(int factor) { return new Vector3D(x * factor, y * factor, z * factor); } /** * Multiply each dimension in the current vector by the given factor. * @param factor - multiplier. * @return The new result. */ public Vector3D multiply(double factor) { return new Vector3D(x * factor, y * factor, z * factor); } /** * Divide each dimension in the current vector by the given divisor. * @param divisor - the divisor. * @return The new result. */ public Vector3D divide(int divisor) { if (divisor == 0) throw new IllegalArgumentException("Cannot divide by null."); return new Vector3D(x / divisor, y / divisor, z / divisor); } /** * Divide each dimension in the current vector by the given divisor. * @param divisor - the divisor. * @return The new result. */ public Vector3D divide(double divisor) { if (divisor == 0) throw new IllegalArgumentException("Cannot divide by null."); return new Vector3D(x / divisor, y / divisor, z / divisor); } /** * Retrieve the absolute value of this vector. * @return The new result. */ public Vector3D abs() { return new Vector3D(Math.abs(x), Math.abs(y), Math.abs(z)); } @Override public String toString() { return String.format("[x: %s, y: %s, z: %s]", x, y, z); } Here's my ghost possess system. Code: final int POSSESS_REACH = 100; @EventHandler public void GhostItemClickEvents(PlayerInteractEvent event) { Player player = event.getPlayer(); ItemStack item = player.getItemInHand(); Boolean air = event.getAction().equals(Action.RIGHT_CLICK_AIR); Boolean block = event.getAction().equals(Action.RIGHT_CLICK_BLOCK); if ( air ) { if ( item.getType().equals(Material.GLOWSTONE_DUST) ) { Location playerpos = player.getEyeLocation(); Vector3D playerDir = new Vector3D(playerpos.getDirection()); Vector3D playerStart = new Vector3D(playerpos); Vector3D playerend = playerStart.add(playerDir.multiply(POSSESS_REACH)); if ( item.hasItemMeta() ) { if ( item.getItemMeta().getDisplayName().equals(ChatColor.YELLOW + "Possess User") ) { for (Player target : player.getWorld().getPlayers()) { Vector3D targetPos = new Vector3D(target.getLocation()); Vector3D minimum = targetPos.add(-0.5, 0, -0.5); Vector3D maximum = targetPos.add(0.5, 1.67, 0.5); if ( target != player && hasIntersection(playerStart, playerend, minimum, maximum) ) { if ( hit == null || hit.getLocation().distanceSquared(playerpos) > target.getLocation().distanceSquared(playerpos) ) { this.hit = target; } } } event.setCancelled(true); if ( hit !=null ) { player.sendMessage(ChatColor.YELLOW + "You have possessed " + hit.getName()); hit.sendMessage(ChatColor.YELLOW + "You have been possessed by " + player.getName()); event.setCancelled(true); victims.put(player.getUniqueId(), hit.getUniqueId()); player.getInventory().setItem(0, applyLore(new ItemStack(Material.TRIPWIRE_HOOK), ChatColor.AQUA + "Freeze Victim", ChatColor.GRAY + "Freeze your target!")); player.getInventory().setItem(1, applyLore(new ItemStack(Material.TRIPWIRE_HOOK), ChatColor.YELLOW + "Slow Victim", ChatColor.GRAY + "Slowdown your target!")); player.getInventory().setItem(2, applyLore(new ItemStack(Material.TRIPWIRE_HOOK), ChatColor.LIGHT_PURPLE + "Weaken Victim", ChatColor.GRAY + "Weaken your target!")); } } } } } } private boolean hasIntersection(Vector3D p1, Vector3D p2, Vector3D min, Vector3D max) { final double epsilon = 0.0001f; Vector3D d = p2.subtract(p1).multiply(0.5); Vector3D e = max.subtract(min).multiply(0.5); Vector3D c = p1.add(d).subtract(min.add(max).multiply(0.5)); Vector3D ad = d.abs(); if (Math.abs(c.x) > e.x + ad.x) return false; if (Math.abs(c.y) > e.y + ad.y) return false; if (Math.abs(c.z) > e.z + ad.z) return false; if (Math.abs(d.y * c.z - d.z * c.y) > e.y * ad.z + e.z * ad.y + epsilon) return false; if (Math.abs(d.z * c.x - d.x * c.z) > e.z * ad.x + e.x * ad.z + epsilon) return false; if (Math.abs(d.x * c.y - d.y * c.x) > e.x * ad.y + e.y * ad.x + epsilon) return false; return true; }