Plugin wont execute?

Discussion in 'Plugin Development' started by BeastyBoo, Nov 19, 2016.

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

    BeastyBoo

    Hello, I get no errors in consol. It says its active when I do /pl. But when I try to use a grapple hook and teleport to its hook location it wont execute.


    Code:
    package me.spig0t.Patch;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Sound;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.player.PlayerFishEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;
    
    import com.orange451.pvpgunplus.events.PVPGunPlusGunDamageEntityEvent;
    
    public class Patch
      extends JavaPlugin
      implements Listener
    {
       
     
      public void onEnable()
      {
        Bukkit.getPluginManager().registerEvents(this, this);
      }
     
      public void onDisable()
      {
         
      }
     
      @EventHandler
      public void EntityDamage(PVPGunPlusGunDamageEntityEvent e)
      {
        Player p1 = (Player)e.getEntityDamaged();
        p1.setMaximumNoDamageTicks(0);
      }
     
      @EventHandler
      public void EntityDamage2(EntityDamageByEntityEvent e)
      {
        Player p = (Player)e.getDamager();
        Player p2 = (Player)e.getEntity();
        if (e.getCause() != EntityDamageEvent.DamageCause.PROJECTILE)
        {
          p.setMaximumNoDamageTicks(20);
          p2.setMaximumNoDamageTicks(20);
        }
      }
     
     
      @EventHandler(priority=EventPriority.HIGHEST)
      public void Grapple(PlayerFishEvent e)
      {
          System.out.println("Fail 3");
        Player p = (Player)e.getHook().getShooter();
        if (((p instanceof Player)) &&
          (e.getState() == PlayerFishEvent.State.IN_GROUND))
        {
          e.getHook().getLocation().add(new Vector(0, 1, 0));
          Location loc = e.getHook().getLocation();
          System.out.println("Fail 1");
          pullEntityToLocation(p, loc);
          p.playSound(loc, Sound.MAGMACUBE_JUMP, 1.0F, 10.0F);
        }
      }
     
      private void pullEntityToLocation(Entity e, Location loc)
      {
          System.out.println("Fail 4");
        Location entityLoc = e.getLocation();
       
        entityLoc.setY(entityLoc.getY() + 0.5D);
        e.teleport(entityLoc);
       
        double g = -0.087D;
        double d = loc.distance(entityLoc);
       
        double t = d;
        double v_x = (1.0D + 0.07D * t) * (loc.getX() - entityLoc.getX()) / t;
        double v_y = (1.0D + 0.03D * t) * (loc.getY() - entityLoc.getY()) / t - 0.5D * g * t;
        double v_z = (1.0D + 0.07D * t) * (loc.getZ() - entityLoc.getZ()) / t;
        double speedCalc = Math.abs(Math.abs(v_x + v_y + v_z - 5.0E-4D) - v_x + v_y + v_z);
        Vector v = e.getVelocity();
        v.setX(v_x);
        v.setY(v_y);
        v.setZ(v_z);
       
       
        if (speedCalc > 5.0D)
        {
          System.out.println("ERROR: A user is at an abnormal velocity!");
          v.setX(v_x + speedCalc);
          v.setZ(v_z + speedCalc);
        }
        System.out.println("Fail 2");
        e.setVelocity(v);
      }
    }
     
  2. Offline

    jlin13

    None of the code executes, or just some of the code executes? You have debug lines in the code, it would be nice to see some output

    May be relevant to your problem: (probably not)
    Code:
    Player p = (Player)e.getHook().getShooter();
        if (((p instanceof Player)) &&
          (e.getState() == PlayerFishEvent.State.IN_GROUND))
        {
    In your code you cast (Player) to the shooter and then you check if the player is instanceof Player (which is redundant, of course a Player casted object is going to be an instance of Player). You should check if the entity e.getHook().getShooter() instanceof Player, and then put your code inside of there
     
    Last edited: Nov 19, 2016
  3. Offline

    Wispyy

    I don't think PVPGunPlusGunDamageEntityEvent is a valid event... (E: Unless it's a custom made event)

    E2: Ignore above. I noticed the import:
    import com.orange451.pvpgunplus.events.PVPGunPlusGunDamageEntityEvent;
     
  4. Offline

    BeastyBoo

    @jlin13 @Wispyy
    Its only the fishing rod stuff that doesnt execute, I dont know why. The debug messages dont even show up in the consol.

    I changed this part as you said, still no difference. That part of the code dont work, and the debug messages wont send:
    e.getHook().getShooter() instanceof Player

    EDIT:


    Here I've added two debug messages, none of them are showing in the consol?
    Code:
    @EventHandler(priority=EventPriority.HIGHEST)
      public void Grapple(PlayerFishEvent e)
      {
        System.out.println("Test1");
        Player p = (Player)e.getHook().getShooter();
        if (((p instanceof Player)) &&
          (e.getState() == PlayerFishEvent.State.IN_GROUND))
        {
          e.getHook().getLocation().add(new Vector(0, 1, 0));
          Location loc = e.getHook().getLocation();
         
          pullEntityToLocation(p, loc);
          p.playSound(loc, Sound.MAGMACUBE_JUMP, 1.0F, 10.0F);
        }
      }
     
      private void pullEntityToLocation(Entity e, Location loc)
      {
          System.out.println("Test2");
        Location entityLoc = e.getLocation();
       
        entityLoc.setY(entityLoc.getY() + 0.5D);
        e.teleport(entityLoc);
       
        double g = -0.087D;
        double d = loc.distance(entityLoc);
       
        double t = d;
        double v_x = (1.0D + 0.07D * t) * (loc.getX() - entityLoc.getX()) / t;
        double v_y = (1.0D + 0.03D * t) * (loc.getY() - entityLoc.getY()) / t - 0.5D * g * t;
        double v_z = (1.0D + 0.07D * t) * (loc.getZ() - entityLoc.getZ()) / t;
        double speedCalc = Math.abs(Math.abs(v_x + v_y + v_z - 5.0E-4D) - v_x + v_y + v_z);
        Vector v = e.getVelocity();
        v.setX(v_x);
        v.setY(v_y);
        v.setZ(v_z);
       
       
        if (speedCalc > 5.0D)
        {
          System.out.println("ERROR: A user is at an abnormal velocity!");
          v.setX(v_x + speedCalc);
          v.setZ(v_z + speedCalc);
        }
       
        e.setVelocity(v);
      }
     
    Last edited: Nov 19, 2016
  5. Offline

    jlin13

    @BeastyBoo My comment wasn't intended to fix your problem - I was just advising you against more of a general Java mistake, and still you haven't changed it

    Code:
    Player p = (Player) e.getHook().getShooter();
    if (p instanceof Player) {
        // do stuff
    }
    
    
    versus

    Code:
    if (e.getHook().getShooter() instanceof Player) {
        Player p = (Player) e.getHook().getShooter();
        // do stuff
    }
    you shouldn't cast something before you've checked its type
     
  6. Offline

    BeastyBoo

    @jlin13
    rip ok. I still dont know why it wont execute. it dont even show the debug message in the start of each handler
     
  7. Offline

    mythbusterma

    @BeastyBoo

    PlayerFishEvent is only called when the player catches something, you should be listening for the event when a player interacts if you mean to listen for them casting a fishing line.

    Also, you should have lower vase method names, and don't use system out, use Bukkit's logger.
     
Thread Status:
Not open for further replies.

Share This Page