@SuppressWarnings("unchecked") public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) { net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle(); net.minecraft.entity.Entity launch = null; if (Snowball.class.isAssignableFrom(projectile)) { launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle()); } else if (Egg.class.isAssignableFrom(projectile)) { launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle()); } else if (EnderPearl.class.isAssignableFrom(projectile)) { launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle()); } else if (Arrow.class.isAssignableFrom(projectile)) { launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1); } else if (ThrownPotion.class.isAssignableFrom(projectile)) { launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1))); } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) { launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle()); } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) { launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle()); } else if (Fireball.class.isAssignableFrom(projectile)) { Location location = getEyeLocation(); Vector direction = location.getDirection().multiply(10); if (SmallFireball.class.isAssignableFrom(projectile)) { launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ()); } else if (WitherSkull.class.isAssignableFrom(projectile)) { launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ()); } else { launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ()); } ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this; launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); } Validate.notNull(launch, "Projectile not supported"); if (velocity != null) { ((T) launch.getBukkitEntity()).setVelocity(velocity); } world.spawnEntityInWorld(launch); return (T) launch.getBukkitEntity(); }
public static ExpBottleEvent callExpBottleEvent(net.minecraft.entity.Entity entity, int exp) { ThrownExpBottle bottle = (ThrownExpBottle) entity.getBukkitEntity(); ExpBottleEvent event = new ExpBottleEvent(bottle, exp); Bukkit.getPluginManager().callEvent(event); return event; }
public ExpBottleEvent(final ThrownExpBottle bottle, final int exp) { super(bottle); this.exp = exp; }
@Override public ThrownExpBottle getEntity() { return (ThrownExpBottle) entity; }
public static ExpBottleEvent callExpBottleEvent(Entity entity, int exp) { ThrownExpBottle bottle = (ThrownExpBottle) entity.getBukkitEntity(); ExpBottleEvent event = new ExpBottleEvent(bottle, exp); Bukkit.getPluginManager().callEvent(event); return event; }
@SuppressWarnings("deprecation") @EventHandler public void onClick(PlayerInteractEvent e) { if(e.getPlayer().getItemInHand().getType() != null){ if(e.getPlayer().getItemInHand().getType() == Material.EXP_BOTTLE){ e.setCancelled(true); e.getPlayer().updateInventory(); if(DexCore.getCurrencySystem().hasEnoughGC(e.getPlayer().getUniqueId().toString(), 30)){ DexCore.getCurrencySystem().removeGC(e.getPlayer().getUniqueId().toString(), 30); }else{ e.getPlayer().sendMessage(ChatColor.BLUE + "Gadget > " + ChatColor.GRAY + "You don't have enough points!"); return; } if(!cooldowntask.containsKey(e.getPlayer().getName())){ final Player p = e.getPlayer(); p.launchProjectile(ThrownExpBottle.class, p.getLocation().getDirection().multiply(1)); timeleft.put(p.getName(), 10.0); cooldowntask.put(p.getName(), new BukkitRunnable() { @Override public void run() { if(timeleft.get(p.getName()) == 0.0){ cooldowntask.remove(p.getName()); timeleft.remove(p.getName()); cancel(); }else{ timeleft.put(p.getName(), timeleft.get(p.getName()) - 0.5); } } }); cooldowntask.get(p.getName()).runTaskTimer(Hub.instance, 10, 10); }else{ e.getPlayer().sendMessage(ChatColor.BLUE + "Gadget > " + ChatColor.GRAY + " You must wait for " + ChatColor.RED + timeleft.get(e.getPlayer().getName()) + ChatColor.GRAY + " seconds."); } } } }
public PoreExpBottleEvent(EntityEvent handle) { super(null, -1); this.handle = checkNotNull(handle, "handle"); checkState(handle.getEntity() instanceof org.spongepowered.api.entity.projectile.ThrownExpBottle, "Bad entity type"); }
@Override public ThrownExpBottle getEntity() { return (ThrownExpBottle) PoreThrownExpBottle.of(this.getHandle().getEntity()); }
public ExpBottleEvent(ThrownExpBottle bottle, int exp) { super(bottle); }
public ThrownExpBottle getEntity() { return null; }