Solved Custom Ender Eye Target

Discussion in 'Spigot Plugin Development' started by AlpDemirAlver, Mar 23, 2021.

Thread Status:
Not open for further replies.
  1. Hey, I am new to making plugins and trying to make one. I am trying to make an ender eye target a player instead of an stronghold. I tried using EnderSignal.setTargetLocation() but it did not work. I would be very happy if someone could help me, thanks.
     
  2. Did it throw an error? Did it fly towards the stronghold anyway? What happened?
     
  3. Sorry, my fault. It said:

    Cannot make a static reference to the non-static method setTargetLocation(Location) from the type EnderSignal
     
  4. Post your code and we’ll be able to fix it
     
  5. you can only set the target location for an instance of EnderSignal. I would listen for a ProjectileLaunchEvent and check if it´s an EnderSignal and then set the targetlocation
     
  6. Main or command?

    This is the one which includes the command.


    package me.demiralver.manhunt;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class Speedrunner implements CommandExecutor {



    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if(!sender.hasPermission("manhunt.speedrunner"))
    sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You don't have enough permissions to run this command!");
    else {
    if (args.length > 0) {
    Player target = Bukkit.getPlayer(args[0]);
    if(target != null) {
    Manhunt.config.set("speedrunner", args[0]);
    Manhunt main = Manhunt.getPlugin(Manhunt.class);
    main.saveConfig();
    sender.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Successfully made player speedrunner!");
    }
    else {
    sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Enter a real username!");
    }
    }

    return true;
    }
    return false;

    }
    }
     
  7. T
    Thank you for your reply and help. :)
     
  8. I am doing a projectile launch listener, and the part down belown gives an cannot resolved to be a type error.

    if (proj instanceof eye_of_ender);
     
  9. I’m assuming we want main. Wherever you’re trying to set the target for the eye of ender
     
  10. I’m on my phone and not home, so I could be wrong, but it should be if (proj instanceof EnderSignal)
     
  11. Done it like this, I am getting an error at the last row. The error is The method setTargetLocation(String) is undefined for the type Events.
    The class is events.

    Code:


    public abstract class Events implements Listener {

    @EventHandler
    public void onProjectileLaunch(ProjectileLaunchEvent e) {
    Projectile proj = e.getEntity();
    Manhunt main = Manhunt.getPlugin(Manhunt.class);
    String speedrunner = main.getConfig().getString("speedrunner");
    if (proj.equals(EntityType.ENDER_SIGNAL));
    setTargetLocation(speedrunner);
    }


    }
     
  12. So there are a few problems with your code. First of all you are comparing the projectile to an EntityType. Instead you should check if the entity is an insteanceof Endersignal. Also you are calling the setTargetLocation on the instance of your class instead of the Endersignal. Instead you need to cast the projectile to Endersignal and call the method on that object. And last but not least you are currently passing a string to the method setTargetLocation which probably takes a Location
     
  13. Hey, thanks for your reply but I couldn't understand anything. If it is not a problem, can you do the changes at the code please?
     
  14. I'm sorry but I'm strictly against spoonfeeding
     
  15. Okay, thank you for your help.
     
  16. Hello, I think I did the things you said. I am stuck at the target location part. Is this wrong or am I doing it in a wrong order?

    Code (Text):

    package me.demiralver.manhunt;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.entity.EnderSignal;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Projectile;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.ProjectileLaunchEvent;

    public abstract class Events implements Listener {
     
        @EventHandler
        public void onProjectileLaunch(ProjectileLaunchEvent e) {
            Manhunt main = Manhunt.getPlugin(Manhunt.class);
            String speedrunner = main.getConfig().getString("speedrunner");
            Player target = Bukkit.getPlayer(speedrunner);
            Location speedrunnerloc = target.getLocation();
            Projectile proj = e.getEntity();
            if (proj instanceof EnderSignal);
            proj.EnderSignal.setTargetLocation(speedrunnerloc);
        }
         

        }
     
     
  17. Instead of proj.EnderSignal you need ((EnderSignal)proj)
     
  18. Thanks
     
  19. Hey, unfortuanetly the ender eyes keeps going to the stronghold, can you see if there's any fails in the code? There is no errors.



    Code (Text):

    package me.demiralver.manhunt;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.EnderSignal;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Projectile;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.ProjectileLaunchEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;

    public abstract class Events implements Listener {
     
     
        @EventHandler
        public void onProjectileLaunch(ProjectileLaunchEvent e) {
            Manhunt main = Manhunt.getPlugin(Manhunt.class);
            String speedrunner = main.getConfig().getString("speedrunner");
            Player target = Bukkit.getPlayer(speedrunner);
            Location speedrunnerloc = target.getLocation();
            Projectile proj = e.getEntity();
            if (proj instanceof EnderSignal);
            ((EnderSignal)proj).setTargetLocation(speedrunnerloc);
            }
         
        public void PlayerRespawnEvent(Player respawnPlayer) {
            Inventory inv = respawnPlayer.getInventory();
            inv.addItem(new ItemStack(Material.COMPASS, 1));
        }
     
     

        }
     
    Edit: I added the compass thing to test if it gives it, it does not.
     
  20. maybe you forgot to register the listener

    Edit:
    I just realised you will need to remove the ; in
    Code (Text):
    if (proj instanceof EnderSignal);
    because otherwise it counts as an if statement with empty body meaning your code below it will always execute even if the projectile launched is an arrow
     
Thread Status:
Not open for further replies.