public void iceFishing(Fish hook, Block block) { // Make a hole block.setType(Material.STATIONARY_WATER); for (int x = -1; x <= 1; x++) { for (int z = -1; z <= 1; z++) { Block relative = block.getRelative(x, 0, z); if (relative.getType() == Material.ICE) { relative.setType(Material.STATIONARY_WATER); } } } // Recast in the new spot EventUtils.callFakeFishEvent(getPlayer(), hook); }
public void masterAngler(Fish hook) { Player player = getPlayer(); Location location = hook.getLocation(); double biteChance = hook.getBiteChance(); hookLocation = location; if (Fishing.masterAnglerBiomes.contains(location.getBlock().getBiome())) { biteChance = biteChance * AdvancedConfig.getInstance().getMasterAnglerBiomeModifier(); } if (player.isInsideVehicle() && player.getVehicle().getType() == EntityType.BOAT) { biteChance = biteChance * AdvancedConfig.getInstance().getMasterAnglerBoatModifier(); } hook.setBiteChance(Math.min(biteChance, 1.0)); }
@Override public boolean isFishing() { if(player.getItemInHand().getType() == Material.FISHING_ROD) { for(Entity entity : player.getNearbyEntities(16, 16, 16)) { if(entity instanceof Fish) { Fish fish = (Fish) entity; if(fish.getShooter() instanceof Player) { Player p = (Player) fish.getShooter(); if(p.equals(player)) { return true; } } } } } return false; }
@EventHandler public void onPlayerFishEvent(PlayerFishEvent event) { Fish hook = event.getHook(); if (event.getState() != PlayerFishEvent.State.FISHING) { boolean isBlock = false; for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { for (int dz = -1; dz <= 1; dz++) { if (!RParticles.isAirlike(hook.getWorld().getBlockAt(hook.getLocation().getBlockX() + dx, hook.getLocation().getBlockY() + dy, hook.getLocation().getBlockZ() + dz))) { isBlock = true; break; } } } } try { event.getPlayer().getEquipment().getItemInMainHand().setDurability((short) 0); } catch (Exception e) { } if (isBlock) { pullEntityToLocation(event.getPlayer(), hook.getLocation()); } else { event.getPlayer().sendMessage(ChatColor.RED + "Your grapple wasn't hooked on anything."); } } }
@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 PlayerFishEvent(final Player player, final Entity entity, final Fish hookEntity, final State state) { super(player); this.entity = entity; this.hookEntity = hookEntity; this.state = state; }
public Class<? extends Fish> getReturnType() { return Fish.class; }
@Nullable protected Fish[] get(Event e) { return new Fish[]{((PlayerFishEvent)e).getHook()}; }
public FakePlayerFishEvent(Player player, Entity entity, Fish hookEntity, State state) { super(player, entity, hookEntity, state); }
public static FakePlayerFishEvent callFakeFishEvent(Player player, Fish hook) { FakePlayerFishEvent event = new FakePlayerFishEvent(player, null, hook, PlayerFishEvent.State.FISHING); mcMMO.p.getServer().getPluginManager().callEvent(event); return event; }
@Override @SuppressWarnings("deprecation") public Fish getHook() { throw new NotImplementedException("TODO"); // TODO }
public PlayerFishEvent(Player player, Entity entity, Fish hookEntity, PlayerFishEvent.State state) { super(player); }
public Fish getHook() { return null; }
/** * Gets the fishing hook. * * @return Fish the entity representing the fishing hook/bobber. */ public Fish getHook() { return hookEntity; }