Advertisement
Guest User

Java Wands

a guest
Jan 5th, 2014
320
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.03 KB | None
  1. package me.Captain_Dory.Wands;
  2.  
  3. import java.util.HashMap;
  4.  
  5. import org.bukkit.Effect;
  6. import org.bukkit.Location;
  7. import org.bukkit.Material;
  8. import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
  9. import org.bukkit.craftbukkit.v1_6_R3.entity.CraftSnowball;
  10. import org.bukkit.entity.Entity;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.entity.Snowball;
  13. import org.bukkit.event.EventHandler;
  14. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  15. import org.bukkit.event.player.PlayerInteractEvent;
  16. import org.bukkit.plugin.java.JavaPlugin;
  17. import org.bukkit.util.BlockIterator;
  18.  
  19. public class Main extends JavaPlugin{
  20.    public void onEnable() {
  21.        getLogger().info("wow much enable :^]");
  22.    }
  23.    
  24.    public void onDisable() {
  25.        getLogger().info("wow many disable doge sad :c");
  26.    }
  27.    
  28.    @EventHandler
  29.    public void eva (PlayerInteractEvent e) {
  30.        Location location = player.getEyeLocation();
  31.        BlockIterator blocksToAdd = new BlockIterator(location, 0D, 15);
  32.        Location blockToAdd;
  33.        while(blocksToAdd.hasNext()) {
  34.                if (blockToAdd.getBlock().getType() != Material.AIR ||!shotprojectiledata.containsKey(projectile)) {
  35.                        break;
  36.                }
  37.                blockToAdd = blocksToAdd.next().getLocation();
  38.                player.getWorld().playEffect(blockToAdd, Effect.STEP_SOUND, Material.FIRE);
  39.        }
  40.        Snowball projectile = player.launchProjectile(Snowball.class);
  41.        EntityData data = new EntityData(projectile.getLocation(), 15, 5D);
  42.        shotprojectiledata.put(projectile, data);
  43.        for (Player p : Bukkit.getOnlinePlayers()) {
  44.            ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new  PacketPlayOutEntityDestroy(((CraftSnowball) projectile).getHandle().getId()));
  45.        public class EntityData {
  46.        private Location firedfrom;
  47.        private Integer range;
  48.        private Double damage;
  49.         public EntityData(Location loc, Integer range, Double damage) {
  50.            this.firedfrom = loc;
  51.            this.range = range;
  52.            this.damage = damage;
  53.        }
  54.        public Location getFiredFrom() {
  55.            return firedfrom;
  56.        }
  57.        public Integer getRange() {
  58.            return range;
  59.        }
  60.        public Double getDamage() {
  61.            return damage;
  62.        }
  63.    }
  64.  
  65.    //put where ever you want again
  66.    public final static HashMap<Entity, EntityData> shotprojectiledata = new HashMap<Entity, EntityData>();
  67.  
  68.  
  69.    @EventHandler
  70.    public void onHit(EntityDamageByEntityEvent event) {
  71.        if (event.getDamager() instanceof Snowball) {
  72.            if (shotprojectiledata.containsKey(event.getDamager())) {
  73.                EntityData eventdata = shotprojectiledata.get(event.getDamager());
  74.                if (event.getEntity().getLocation().distance(eventdata.getFiredFrom())<=eventdata.getRange()) {
  75.                    event.setDamage(eventdata.getDamage());
  76.                    shotprojectiledata.remove(event.getDamager());
  77.                }
  78.            }
  79.        }
  80.    }
  81.    }
  82.    
  83.    }
Advertisement
RAW Paste Data Copied
Advertisement