Fishing rod and hook.

Discussion in 'Plugin Development' started by Zarkopafilis, Mar 18, 2013.

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

    Zarkopafilis

    If a player is "hit" I can say with a fishing rod , and the "damager" I can also say , "pulls back" the "hook" , grabbed player is pulled to the damager.
    What event listener?
    Projectile hit?
    Player Interact?
    How to get the "hook"?

    Wow I can say many things :3
     
  2. Offline

    ZeusAllMighty11

    Both the interact event and fish event may be called when the player casts their reel.


    Why don't you do some debugging instead of asking 20 questions?
     
  3. Offline

    Zarkopafilis

    ZeusAllMighty11
    Made some process but I am unable to check for some weird reasons
    Will this work out for me?
    Code:
    package com.gmail.zarkopfilis.commands;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Entity;
    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.PlayerFishEvent;
     
    public class fishhook implements Listener {
     
     
     
        @EventHandler
     
        public void onPlayerFishingEvent(PlayerFishEvent event){
            Player p = event.getPlayer();
        Material item = p.getItemInHand().getType();
     
        if(item == Material.FISHING_ROD){
     
     
     
            java.util.List<Entity> nearby = p.getNearbyEntities(50,50,50);
            Entity hook = null;
            for (Entity e : nearby) {
         
                if (e.getType() == EntityType.FISHING_HOOK) {
                    hook = e;
                    for(Player victim : Bukkit.getOnlinePlayers()){
                    if(hook.getPassenger() == victim){
                     
                        victim.teleport(p);
                     
                    }
                }
                }
            }
     
     
       
         
         
    }
        }
    }
     
  4. Offline

    ZeusAllMighty11

    Seems k, but Enumerations (enums) should not be compared with ==, used for objects, and should instead use .equals()
     
  5. Offline

    Zarkopafilis

    ZeusAllMighty11

    This :
    Code:
    package com.gmail.zarkopfilis.mclol;
     
    import java.util.HashMap;
    import java.util.Map;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Entity;
    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.PlayerFishEvent;
     
    public class rodhook implements Listener{
    public rodhook(){}
       
        private Map<String, Long> cooldown3 = new HashMap<String, Long>();
        private final long COOLDOWN3 = 16*1000;
       
        @EventHandler
        public void onPlayerFishingEvent(PlayerFishEvent event){
            Player p = event.getPlayer();
        Material item = p.getItemInHand().getType();
       
       
        if(item == Material.FISHING_ROD){
           
               
           
            java.util.List<Entity> nearby = p.getNearbyEntities(50,50,50);
            Entity hook = null;
            for (Entity e : nearby) {
           
                if (e.getType() == EntityType.FISHING_HOOK) {
                    Long mapped3 = cooldown3.get(p.getName());
                    long cd3 = mapped3 == null ? Long.MIN_VALUE : mapped3.longValue();
           
                    if(System.currentTimeMillis() > cd3){
                    hook = e;
                    cooldown3.put(p.getName(), System.currentTimeMillis() + COOLDOWN3);
                    for(Player victim : Bukkit.getOnlinePlayers()){
                    if(hook.getPassenger() == victim){
                       
                        victim.teleport(p);
                       
                       
                    }
                   
                   
                }
                }else{
                   
                    cd3 -= System.currentTimeMillis();
                    cd3 /= 1000;
                    p.sendMessage(ChatColor.RED +"You are on cool down! Wait %t more seconds".replace("%t", ""+cd3));
                }
            }
           
           
            }
               
             
    }
        }
       
           
           
           
        }
       
    
    Cooldown works but the player is not even hitted by the hook!
     
  6. Offline

    ZeusAllMighty11

    It's hard to read with indenting, debugging is best.

    Also you still totally ignored my post
     
  7. Offline

    lcpvp

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerHitFishingrodscorpion(final PlayerFishEvent event) {
    4. final Player player = event.getPlayer();
    5. if (event.getCaught() instanceof Player) {
    6. final Player caught = (Player) event.getCaught();
    7. if (player.getItemInHand().getType() == Material.FISHING_ROD) {
    8. player.sendMessage(ChatColor.RED + "GET OVER HERE!");
    9. caught.teleport(player.getLocation());
    10. }
    11. }
    12. }
    13. }
     
  8. Offline

    ZeusAllMighty11

    Code:java
    1.  
    2.  
    3.  
    4. No need to check player item in hand, since PlayerFishEvent is only toggled when a player is actually fishing - with a rod... lol
     
  9. Offline

    Zarkopafilis

    Um ok
    I changed the code and added a timer , seems to be fully working on my testserver whithout plugins but in my server it doesnt work , do you know any plugin not letting the hook go into players / entities??
     
  10. Offline

    kaskoepoes112


    eventpriority I guess , Please, don't ask 20 questions a day :p
     
  11. Offline

    Zarkopafilis

    On my testserve I test with 1 plugin at a time. On the main server my buddy(owner) has 1242523452 3more plugins
     
  12. Offline

    kaskoepoes112


    yes , maybe he has a plugin with the same event with a higher priority and it canceles your event..
     
Thread Status:
Not open for further replies.

Share This Page