Ender eye type

Discussion in 'Spigot Help' started by DenDennisCool, Jul 6, 2021.

  1. Is eye of ender not an entity? When I run this code, it prints ARROW and ENDER_PEARL and EGG in the chat when I use those items, but when I throw the eye of ender it doesn't show anything.

    Code (Java):

    @EventHandler
           public void throwPearl(ProjectileLaunchEvent e) {

            Bukkit.broadcastMessage(e.getEntityType().toString());


        }
     
    Code (Java):

    Something that did kind of work, but wasn't what I wanted: Using PlayerInteractEvent , it also displays the messsage Ender eye was thrown on left click which isn't what i want; I only want it when the eye is thrown.

        @EventHandler
           public void throwPearl(PlayerInteractEvent e) {

     
            if(e.getItem().toString().contains("ENDER_EYE")) {
                Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "locate stronghold");
                Bukkit.broadcastMessage("Ender eye was thrown");
             
            }
             
     
    #1 DenDennisCool, Jul 6, 2021
    Last edited: Jul 6, 2021
  2. 1) The entity you're looking for is EnderSignal.
    2) It's not shown in ProjectileLaunchEvent because it's technically not a projectile - think about it: it doesn't fly in a direction like arrows or pearls, it does its own custom thing.

    What are you trying to do with it? There might be a different way.
     
  3. What i'm trying to do is to give the player the exact coordinates of the stronghold, upon throwing an ender eye.
    Code (Java):

    Something that did kind of work, but wasn't what I wanted: Using PlayerInteractEvent , it also displays the messsage Ender eye was thrown on left click which isn't what i want; I only want it when the eye is thrown.

        @EventHandler
           public void throwPearl(PlayerInteractEvent e) {

     
            if(e.getItem().toString().contains("ENDER_EYE")) {
                Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "locate stronghold");
                Bukkit.broadcastMessage("Ender eye was thrown");
             
            }
             
    This code detects if it's an ender eye which is what i want, but it sends the message Ender eye was thrown on every interaction, even when breaking a block with ender eye.
    Is there a better Event i should be using for only throwing?


    And what im tryign to do is, when the player throws ender eye, server displays a message with the exact coordinates of stronghold
     
  4. In that case, I suggest you try this:
    1) Listen to EntitySpawnEvent.
    2) Check if the entity is an EnderSignal.
    3) If yes: cast the entity to EnderSignal and use #getTargetLocation on it to get the location it's going towards. (and send it however you want)

    This hasn't been tested, but I think it might work.
     
    • Useful Useful x 1
  5. It works! But the location is the location where the EnderSignal despawns. The stronghold coordinates using /locate in the console currently outputs this:
    [23:06:38] [Server thread/INFO]: The nearest stronghold is at [-1544, ~, -120] (1534 blocks away)
    Is there a way to put this in the chat from the console? I am getting very complicated results when I google this...

    This is the code currently:
    Code (Java):

        @EventHandler
           public void throwPearl(EntitySpawnEvent e) {

            if(e.getEntityType() == EntityType.ENDER_SIGNAL) {
                Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "locate stronghold");
                Bukkit.broadcastMessage("Ender eye was thrown");
                Bukkit.broadcastMessage(((EnderSignal)e.getEntity()).getTargetLocation().toString());
               
            }
             

        }
     
     
  6. Just to point it out: You are not telling the player the coordinates of the nearest stronghold from their location, but from the nearest stronghold from x:0,y:0,z:0 as you are running the "locate" command as the console and not as the player.
     
  7. See my reply above
     
  8. I can let the player use /locate, but the player needs to be OP to do that right?
     
  9. What am I doing wrong here?

    Location loc = e.getLocation(); // this is fine
    Location nearStronghold = locateNearestStructure(loc, StructureType.STRONGHOLD, 50, true);

    error: The method locateNearestStructure(Location, StructureType, int, boolean) is undefined for the type Events
     
  10. "locateNearestStructure" is a function inside the World class - you can't just call it out of nowhere.
    You need invoke it through the world in the location.
     
  11. Bukkit.broadcastMessage((e.getLocation().getWorld().locateNearestStructure(loc, StructureType.STRONGHOLD, 50, false).toString()));

    This works, and it prints the following:
    Location{world=CraftWorld{name=world},x=-1544.0,y=32.0,z=-120.0,pitch=0.0,yaw=0.0}

    How can I get the X, Y , Z coordinates to print? I tried this:
    double y = e.getLocation().getWorld().locateNearestStructure(loc, StructureType.STRONGHOLD, 50, false).getY();
    Bukkit.broadcastMessage(y.toString());

    Bukkit message can only use a string, and
    y.toString() appears to not even be a thing, do you know how to output the Y coordinate?
     
  12. Code (Java):
    Location stronghold = e.getLocation().getWorld().locateNearestStructure(loc, StructureType.STRONGHOLD, 50, false);
    String strongholdString = "Stronghold located at: (" + stronghold.getX() + "," + stronghold.getZ() + ")";
    This is just an example, change the String "strongholdString" however you want (no, the variable names don't matter) and do with it whatever you want.
    This is basic stuff - I suggest you start using Spigot's JavaDocs more often, it'll save you time.
     
    • Friendly Friendly x 1