OnPlayerFish Problem

Discussion in 'Plugin Development' started by bcohen9685, Aug 22, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    bcohen9685

  2. Offline

    Dragonphase

    bcohen9685

    Please post the entirety of your Events.java class.
     
  3. Offline

    krazytraynz

    I can't give you a 100% correct answer without all of your code, but I imagine that the error is being thrown when a Player doesn't catch anything. Put in a check to make sure event.getCaught() isn't null.
     
  4. Offline

    bcohen9685

    Events.java class


    package me.bradencohen.TheGymKitPvP;

    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerFishEvent;

    public class Events implements Listener {
    public main plugin;
    public Events(main instance){

    plugin = instance;}


    @EventHandler
    public void onPlayerFish(PlayerFishEvent event)
    {
    Player p = event.getPlayer();
    Entity e = event.getCaught();
    if (!p.hasPermission("fisherman.use")) {
    return;
    }
    Location loc = e.getLocation();
    p.teleport(loc);
    p.sendMessage(ChatColor.RED + "You Have Been Caught By" + ChatColor.BLUE + p.getName());

    }










    @EventHandler
    public void onDeath(PlayerDeathEvent e){
    Player p = e.getEntity();
    plugin.kitused.remove(p.getName());
    plugin.Fisherman.remove(p.getName());
    plugin.Standard.remove(p.getName());
    plugin.Archer.remove(p.getName());

    }
    }

    krazytraynz

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    Dragonphase

    bcohen9685

    I meant using pastebin... so we can see the line numbers and formatting and help you resolve your issue more quickly.
     
  6. Offline

    Jaaakee224

    bcohen9685 Dragonphase krazytraynz
    Because I'm Nice. But, please copy the entire class please. Imports and everything.
    Code:java
    1. package me.bradencohen.TheGymKitPvP;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Location;
    5. import org.bukkit.entity.Entity;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.entity.PlayerDeathEvent;
    10. import org.bukkit.event.player.PlayerFishEvent;
    11.  
    12. public class Events implements Listener {
    13.  
    14. public main plugin;
    15.  
    16. public Events(main instance) {
    17.  
    18. plugin = instance;
    19. }
    20.  
    21.  
    22. @EventHandler
    23. public void onPlayerFish(PlayerFishEvent event) {
    24. Player p = event.getPlayer();
    25. Entity e = event.getCaught();
    26. if (!p.hasPermission("fisherman.use")) {
    27. return;
    28. }
    29. Location loc = e.getLocation();
    30. p.teleport(loc);
    31. p.sendMessage(ChatColor.RED + "You Have Been Caught By" + ChatColor.BLUE + p.getName());
    32.  
    33. }
    34.  
    35. @EventHandler
    36. public void onDeath(PlayerDeathEvent e){
    37. Player p = e.getEntity();
    38. plugin.kitused.remove(p.getName());
    39. plugin.Fisherman.remove(p.getName());
    40. plugin.Standard.remove(p.getName());
    41. plugin.Archer.remove(p.getName());
    42.  
    43. }
    44. }
     
  7. Offline

    bcohen9685

  8. Offline

    Jaaakee224

    bcohen9685You actually have the right event, but you are casting something which is is null.
     
  9. Offline

    krazytraynz

    Like I said earlier, just check to make sure event.getCaught() isn't null.
    Code:java
    1. @EventHandler
    2. public void onPlayerFish(PlayerFishEvent event) {
    3. Player p = event.getPlayer();
    4. if(event.getCaught() != null){
    5. Entity e = event.getCaught();
    6. if (!p.hasPermission("fisherman.use")) {
    7. return;
    8. }
    9. Location loc = e.getLocation();
    10. p.teleport(loc);
    11. p.sendMessage(ChatColor.RED + "You Have Been Caught By" + ChatColor.BLUE + p.getName());
    12. }
    13. }
     
  10. Offline

    stormneo7

    bcohen9685
    I believe that you want to teleport the entity that was caught to the player, not the player to the entity.
     
  11. Offline

    bcohen9685

  12. Offline

    bcohen9685

Thread Status:
Not open for further replies.

Share This Page