Defining a location

Discussion in 'Plugin Development' started by eagledude4, Feb 4, 2011.

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

    eagledude4

  2. Offline

    Plague

    Code:
    Double X = -903.4378328594687;
    Double Y = -903.4378328594687;
    Double Z = -214.5814831264097;
    Double Pitch = 8.100071907043457;
    Double Yaw = -358.3551940917969;
    Location noobSpawn = new Location(player.getWorld(), X, Y, Z, Pitch, Yaw);
     
  3. Offline

    eagledude4

    "The constructor Location (World, Double, Double, Double, Double, Double) is undefined"

    I found that if I removed pitch and yaw from the args, the error goes away. How do I include pitch and yaw in my location?
     
  4. Offline

    Plague

    yeah, they are only Float I think. Try using some IDE, Eclipse would help you instantly with errors like this.
    Also when you don't know the exact function call but have a clue, use the documentation here.
     
  5. Offline

    eagledude4

    They're not floats, they're doubles.

    I am using eclipse, and have been for some time, but can't come to any conclusions on how to include pitch and yaw. The javadoc can't help me with the arguments of the function.
     
  6. Offline

    Plague

    I told you use Float instead of Double!
    But Eclipse should show you the interface of the function when you point it with the mouse.
     
  7. Offline

    eagledude4

    When I use floats for pitch and yaw, I get a mismatch error: cannot convert from double to float
     
  8. Offline

    Plague

    Cut on the precision with yaw and pitch numbers (give less numbers after the decimal point).

    Edit: if stilla problem post the current code, I'm going to bed, so either someone will check that, or tomorrow.
     
  9. Offline

    eagledude4

    even with only 2 numbers after the decimal point im getting the same error.
     
  10. Offline

    Plague

    Okay, what I did is to open my Eclipse and type the code.
    It immediately UNDERLINED the problem. If you said that in the beginning that it underlined the numbers themselves we wouldn't be here for so long ;)
    Add 'f' after the numbers for floats.
     
  11. Offline

    eagledude4

    Thanks, that fixed it. While we're here, I don't want to make another thread for this small issue.

    In my player listener, I have
    Code:
    public class GroupSpawnsPlayerListener extends PlayerListener {
    private final GroupSpawns plugin;
    and

    Code:
    public GroupSpawnsPlayerListener(GroupSpawns instance) {
            plugin = instance;
        }
    I get a warning saying plugin is never read locally. Should plugin be private?
     
  12. Offline

    robhol

    No, keep it around, it might come in handy. :p
     
  13. Offline

    eagledude4

    I'm not sure what the point of having private declarations is anyway.
     
  14. Offline

    Timberjaw

    @eagledude4 You may want to read this: http://download.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

    Basically, you should be using private for your members unless you have a good reason not to. Using public willy-willy can lead to less maintainable code, as you become accustomed to having access to the internal members of a class from outside the class. You get tied down to how the class works internally (by relying on specific locations for data) instead of coming up with a standard method for accessing that data.
     
  15. Offline

    eagledude4

    But if I have plugin as private, then how come it warns me that its never read locally when it's within the class?
     
  16. Offline

    Timberjaw

    Because you're declaring a member but never using it. It's just giving you some friendly advice: "hey, it looks like you're declaring a member you don't need. Want me to delete it?"

    As soon as you use the plugin member for something, that warning will go away.
     
  17. Offline

    eagledude4

    I thought that plugin for "plugin = instance;" was the member. When I remove the member, plugin for "plugin = instance" can't be resolved
     
  18. Offline

    Timberjaw

    Yes, plugin is the member: private final GroupSpawns plugin;
    If you remove the member, you also need to remove plugin = instance; and should update your constructor signature to remove GroupSpawns instance as well (there's no point in passing the instance to your listener if you're not going to save/use it).
     
  19. Offline

    Plague

    I usually comment the variable out, since it's very useful when you want to access some other variables in a more complicated plugin. You could just remove it, but I personally would not know how exactly it was defined, so just comment it out, until needed.
     
  20. Offline

    eagledude4

    K, I wasn't sure if I needed the instance or not. It sounded like it was important to have
     
Thread Status:
Not open for further replies.

Share This Page