Development Assistance Spawn TNT when using fishing rod *help*

Discussion in 'Plugin Help/Development/Requests' started by Rostik002, May 24, 2015.

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

    Rostik002

    Can someone please tell me why this doesn't work, I am new to plugins and java itself.

    Code:
    package me.Rostik002;
    
    import org.bukkit.Location;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    
    
    
    public class FishingListener implements Listener {
       
        public FishingListener(MainClass plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);   
           
            }
           
    
        public void onEvent(PlayerLoginEvent e) {
    
            Player player = e.getPlayer();
            if(player.getNearbyEntities(10, 10, 10).contains(EntityType.FISHING_HOOK)) {
            Location loc = e.getPlayer().getLocation();
            player.getWorld().spawnEntity(loc, EntityType,PRIMED_TNT);
           
           
           
        }
           
       
        }
    }
    
     
  2. Offline

    sciolizer

    @Rostik002

    If you're using a smart IDE like IntelliJ, it will help you spot the errors. I counted at least two. (Let me know if you need further explanation.)

    However, I think there's two additional bugs which it won't catch. You should put @EventHandler on your event handler.

    Code:
    @EventHandler
    public void onEvent(PlayerLoginEvent e) {
    
    Secondly, (I'm less sure about this) you might want to be using PlayerJoinEvent instead of PlayerLoginEvent.
     
  3. Offline

    nverdier

  4. Offline

    Rostik002

    Thank you, ill try doing this and report back, you see, the only good youtube tutorial is from 2013 so the code must have changed a bit I guess, also this was my first time not following a tutorial but ill keep trying :)

    Unfortunately, the 2 fixes you provided me didn't work, this is how my code looks now:

    Code:
    package me.Rostik002;
    
    import org.bukkit.Location;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    
    
    
    
    public class FishingListener implements Listener {
       
        public FishingListener(MainClass plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);   
           
            }
           
        @EventHandler
        public void onEvent(PlayerJoinEvent e) {
    
            Player player = e.getPlayer();
            if(player.getNearbyEntities(10, 10, 10).contains(EntityType.FISHING_HOOK)) {
            Location loc = e.getPlayer().getLocation();
            player.getWorld().spawnEntity(loc, EntityType.PRIMED_TNT);
           
           
           
        }
           
       
        }
    }
       
    The Fishing hook and primed TNT seem to be correct, as it displays "
    org.bukkit.entity.EntityType.FISHING_HOOK" when I hover over it
     
    Last edited by a moderator: May 25, 2015
  5. Offline

    I Al Istannen

Thread Status:
Not open for further replies.

Share This Page