Skip to content

Commit

Permalink
Fix potential fishing trait errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Sep 26, 2016
1 parent ca69115 commit b4a8eb9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 16 deletions.
@@ -1,11 +1,15 @@
package net.aufdemrand.denizen.nms.interfaces;

import org.bukkit.Location;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

public interface FishingHelper {

enum CatchType {NONE, DEFAULT, JUNK, TREASURE, FISH}

ItemStack getResult(FishHook fishHook, CatchType catchType);

FishHook spawnHook(Location location, Player player);
}
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;

Expand Down Expand Up @@ -177,7 +178,7 @@ private void cast() {
v = v + (CoreUtilities.getRandom().nextDouble() - .8) / 2;
victor = victor.multiply(v / 20.0);

fishHook = from.getWorld().spawn(from, FishHook.class);
fishHook = NMSHandler.getInstance().getFishingHelper().spawnHook(from, (Player) npc.getEntity());
fishHook.setShooter((ProjectileSource) npc.getEntity());
fishHook.setVelocity(victor);

Expand Down Expand Up @@ -212,17 +213,17 @@ private void reel() {
catch (Exception e) {
}
Location location = fishHook.getLocation();
fish = location.getWorld().spawn(location, Item.class);
fish.setItemStack(NMSHandler.getInstance().getFishingHelper().getResult(fishHook, catchType));

Location npcLocation = npc.getEntity().getLocation();
double d5 = npcLocation.getX() - location.getX();
double d6 = npcLocation.getY() - location.getY();
double d7 = npcLocation.getZ() - location.getZ();
double d8 = Math.sqrt(d5 * d5 + d6 * d6 + d7 * d7);
double d9 = 0.1D;

fish.setVelocity(new Vector(d5 * d9, d6 * d9 + Math.sqrt(d8) * 0.08D, d7 * d9));
ItemStack result = NMSHandler.getInstance().getFishingHelper().getResult(fishHook, catchType);
if (result != null) {
fish = location.getWorld().dropItem(location, result);
Location npcLocation = npc.getEntity().getLocation();
double d5 = npcLocation.getX() - location.getX();
double d6 = npcLocation.getY() - location.getY();
double d7 = npcLocation.getZ() - location.getZ();
double d8 = Math.sqrt(d5 * d5 + d6 * d6 + d7 * d7);
double d9 = 0.1D;
fish.setVelocity(new Vector(d5 * d9, d6 * d9 + Math.sqrt(d8) * 0.08D, d7 * d9));
}
DenizenAPI.getDenizenNPC(npc).action("catch fish", null);
}

Expand Down
Expand Up @@ -2,10 +2,13 @@

import net.aufdemrand.denizen.nms.interfaces.FishingHelper;
import net.minecraft.server.v1_10_R1.*;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftFish;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;

import java.util.List;

Expand Down Expand Up @@ -54,6 +57,14 @@ else if (catchType == CatchType.FISH) {
}
}

@Override
public FishHook spawnHook(Location location, Player player) {
WorldServer nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
EntityFishingHook hook = new EntityFishingHook(nmsWorld, ((CraftPlayer) player).getHandle());
nmsWorld.addEntity(hook);
return (FishHook) hook.getBukkitEntity();
}

private ItemStack catchRandomJunk(EntityFishingHook fishHook) {
fishHook.owner.a(StatisticList.A, 1);
WorldServer worldServer = (WorldServer) fishHook.getWorld();
Expand Down
Expand Up @@ -2,10 +2,13 @@

import net.aufdemrand.denizen.nms.interfaces.FishingHelper;
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftFish;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;

import java.util.Arrays;
import java.util.List;
Expand All @@ -18,7 +21,7 @@ public class FishingHelper_v1_8_R3 implements FishingHelper {
new PossibleFishingResult(new ItemStack(Items.BONE), 10),
new PossibleFishingResult(new ItemStack(Items.POTION), 10),
new PossibleFishingResult(new ItemStack(Items.STRING), 5),
(new PossibleFishingResult(new ItemStack(Items.FISHING_ROD), 2)).a(0.9F),
new PossibleFishingResult(new ItemStack(Items.FISHING_ROD), 2).a(0.9F),
new PossibleFishingResult(new ItemStack(Items.BOWL), 10),
new PossibleFishingResult(new ItemStack(Items.STICK), 5),
new PossibleFishingResult(new ItemStack(Items.DYE, 10, 0), 1),
Expand All @@ -28,9 +31,9 @@ public class FishingHelper_v1_8_R3 implements FishingHelper {
new PossibleFishingResult(new ItemStack(Blocks.WATERLILY), 1),
new PossibleFishingResult(new ItemStack(Items.NAME_TAG), 1),
new PossibleFishingResult(new ItemStack(Items.SADDLE), 1),
(new PossibleFishingResult(new ItemStack(Items.BOW), 1)).a(0.25F).a(),
(new PossibleFishingResult(new ItemStack(Items.FISHING_ROD), 1)).a(0.25F).a(),
(new PossibleFishingResult(new ItemStack(Items.BOOK), 1)).a());
new PossibleFishingResult(new ItemStack(Items.BOW), 1).a(0.25F).a(),
new PossibleFishingResult(new ItemStack(Items.FISHING_ROD), 1).a(0.25F).a(),
new PossibleFishingResult(new ItemStack(Items.BOOK), 1).a());
private static final List fishResults = Arrays.asList(
new PossibleFishingResult(new ItemStack(Items.FISH, 1, ItemFish.EnumFish.COD.a()), 60),
new PossibleFishingResult(new ItemStack(Items.FISH, 1, ItemFish.EnumFish.SALMON.a()), 25),
Expand Down Expand Up @@ -80,6 +83,14 @@ else if (catchType == CatchType.FISH) {
}
}

@Override
public FishHook spawnHook(Location location, Player player) {
WorldServer nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
EntityFishingHook hook = new EntityFishingHook(nmsWorld, ((CraftPlayer) player).getHandle());
nmsWorld.addEntity(hook);
return (FishHook) hook.getBukkitEntity();
}

private ItemStack catchRandomJunk(EntityFishingHook fishHook) {
fishHook.owner.a(StatisticList.A, 1);
return ((PossibleFishingResult) WeightedRandom.a(fishHook.world.random, junkResults)).a(fishHook.world.random);
Expand Down
Expand Up @@ -2,10 +2,13 @@

import net.aufdemrand.denizen.nms.interfaces.FishingHelper;
import net.minecraft.server.v1_9_R2.*;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftFish;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;

import java.util.List;

Expand Down Expand Up @@ -54,6 +57,14 @@ else if (catchType == CatchType.FISH) {
}
}

@Override
public FishHook spawnHook(Location location, Player player) {
WorldServer nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
EntityFishingHook hook = new EntityFishingHook(nmsWorld, ((CraftPlayer) player).getHandle());
nmsWorld.addEntity(hook);
return (FishHook) hook.getBukkitEntity();
}

private ItemStack catchRandomJunk(EntityFishingHook fishHook) {
fishHook.owner.a(StatisticList.A, 1);
WorldServer worldServer = (WorldServer) fishHook.getWorld();
Expand Down

0 comments on commit b4a8eb9

Please sign in to comment.