Creating a player object

Discussion in 'Plugin Development' started by Colecf, Feb 12, 2011.

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

    Colecf

    This is probably a really noob question, but:

    I want to make a plugin were when a player uses the command /letout playername it'll teleport playername outside of the bedrock spawn box we have to a set location. I understand how to set up onPlayerCommand(), but I don't understand how to make a new player object (playername) so I can use player.move(coordinates)

    I only see data types in the javadocs for PlayerXXXEvent, not a plain Player.

    Thanks for your help!

    EDIT: I actually found the player object, but I don't get how to initialize it for a certain username.
     
  2. Offline

    Mixcoatl

    Player is an interface. The implementation is provided by CraftBukkit and should probably not be directly instantiated, as it will depend upon MC server internals -- at least an entity reference. If the player doesn't exist within the server instance (methods: matchPlayer, getOnlinePlayers, etc.) I would not recommend trying to instantiate one.
    If the player in question is offline, it might be better to setup some meta-information the onPlayerJoin event will read and process the next time the player logs in. If you use this mechanism, remember to remove the meta-information once its been processed.
     
  3. Offline

    Colecf

    So there's no way to directly check if someone is online / teleport them just given a username?

    And if not, could I use server.getOnlinePlayers and search for the player in that array, then teleport him/her?
    --- merged: Feb 12, 2011 5:32 PM ---
    I am trying to use getOnlinePlayers, but I don't know how to get a server object, much like the player object. :(
     
  4. You can do server.getPlayer("playername") and then check the return.
    If it is not null then the player is online.

    EDIT: from the main class you can do Player player = this.getServer().getPlayer("playername");
     
  5. Offline

    Colecf

    Thank you Yurij! I think I have the player part sorted out, but I can't seem to create a location to teleport to. This gives me errors:
    Code:
    Location teleplace = (totele.getWorld(), 86, 93, -275);
    totele is the person that I'm trying to teleport, and the coordinants came from /coords in the essentials plugin. (I know this is a hardcoded location with no preferences file, but I'm starting off simple)
     
  6. Offline

    eisental

    should be:
    Code:
    Location teleplace = totele.getWorld().getBlockAt(86,93,-275).getLocation();
    
    Your line is not java. Maybe a basic java tutorial could help you getting started.
     
  7. Offline

    Colecf

    Ah, thanks. I was reading the javadocs and I saw this line:
    Code:
    public Location(World world,
       double x,
       double y,
       double z)
    
    and so that's how I tried to define it.

    I'm having trouble now though. I think all the code is done, but I get this error when I start my server:
    Code:
    SEVERE: Could not load plugins/LetOut.jar in plugins: null
    org.bukkit.plugin.InvalidPluginException
    	at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:78)
    	at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:117)
    	at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:82)
    	at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:42)
    	at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:156)
    	at net.minecraft.server.MinecraftServer.c(MinecraftServer.java:143)
    	at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:104)
    	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:186)
    	at net.minecraft.server.ThreadServerApplication.run(SourceFile:512)
    Caused by: java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    	at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:76)
    	... 8 more
    Caused by: java.lang.Error: Unresolved compilation problem:
    	The import com.bukkit cannot be resolved
    
    	at colecf.LetOut.LetOut.<init>(LetOut.java:12)
    	... 13 more
    
    Does anyone know what I'm doing wrong?
     
  8. You could have done Location teleplace = new Location(totele.getWorld(), 86, 93, -275);

    If I would guess, the problem is in the onEnable method, but I am not sure.
    Can we have a look at the source?
     
  9. Offline

    Colecf

    The last sentence of my post was a link to the source :p
     
  10. No you only included the compiled files
     
  11. Offline

    Colecf

  12. I got 3 errors after adding project to eclipse.

    How I solved them:
    1. Remove line "import com.bukkit.colecf.Basic.BasicPlayerListener;" from LetOut.java
    2. change "public Server server;" to "public static Server server;" in LetOut.java
    3. "tolete.teleportTo(teleplace);" in LetOutPlayerListener.java is misspelled. Should be "totele.teleportTo(teleplace);"

    After fixing that it didnt throm any errors on server startup
     
  13. Offline

    Colecf

    1. Oops. Too much copy/pasting from an example program
    2. I never really understood the prefixes to a variable declaration. Guess I better look that up.
    3. Oops again.

    Thanks for your help Yurij! It's working now. :)
     
  14. Im glad I could help
     
Thread Status:
Not open for further replies.

Share This Page