How to see if player is in the spawn protection

Discussion in 'Plugin Development' started by ursa_arcadius, Feb 21, 2011.

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

    ursa_arcadius

    I feel bad starting so many threads, maybe I should just make one called Tony's Questions...
    Anyways,

    How do I find out if a player is in the spawn protection area? I want to be able to prevent my plugin from placing a material if they are not supposed to be able to build there.
     
  2. Offline

    Edward Hand

    You can use something like this:

    Code:
    Location loc = player.getWorld().getSpawnLocation();
    if(Math.abs(loc.getX()-player.getLocation().getX)>16 || Math.abs(loc.getZ()-player.getLocation().getZ)>16)
    {
       //player is outside the spawn zone
    }
    
     
  3. Offline

    Plague

    Well spawn protection size can be changed in the config file, so I don't recommend using hard values. But don't know it the value is accessible.
     
  4. Offline

    Edward Hand

    Ah yes. He's right. I'll look into that.
    --- merged: Feb 21, 2011 8:55 PM ---
    The value of spawn protection radius can be found as follows:

    Code:
    int radius = ((CraftServer)theServer).getHandle().c.spawnProtection
    (substituting 'theServer' with a reference to the server obviously)
     
  5. Offline

    ursa_arcadius

    Awesome, thanks guys!

    Edit: I am getting the error "CraftServer cannot be resolved to a type" when trying to cast for the command given by EdwardHand.
     
  6. Offline

    Edward Hand

    Code:
    import org.bukkit.craftbukkit.CraftServer;
    and make sure your java project is set up to reference craftbukkit as well as bukkit
     
  7. Offline

    ursa_arcadius

    Problem at line 48. Eclipse doesn't like the import at the top either. I just downloaded a new copy of Bukkit so I don't think that is the problem. Any ideas?
     
  8. Offline

    Edward Hand

    Have you definitely added craftbukkit-0.0.1-SNAPSHOT.jar to your java build path libraries in eclipse? If so, the import should be fine.
     
  9. Offline

    ursa_arcadius

    Haha wow, I totally missed that. I only have it referencing bukkit.
    I did not know we were allowed to reference craftbukkit. Thanks again works now.
     
  10. Offline

    Plague

    Oh linking craftbukkit for my plugin to change spawn! took me almost an hour to figure out I have to link craftbukkit also!
     
  11. Offline

    Edward Hand

    I always link craftbukkit. I'm not sure I'm supposed to do that, but it makes my plugins work so I don't care.
     
  12. Offline

    Plague

    I link bukkit, craftbukkit only if I need something more "hackish" as craftbukkit is not primarily supposed to be linked, bukkit should encapsulate it for us.

    Of course since you have experience with the base server anyway, it doesn't matter :)
     
  13. Offline

    darknesschaos

    Where do you go to read through the code? Seriously, you are like a dictionary for craftbukkit code.
     
  14. Offline

    Plague

    I actually asked him this question and it seems he just got bored one day and disassembled minecraft_server.jar and learned it by heart :D
     
  15. Offline

    Saturisk

    Definition of Nerd
     
Thread Status:
Not open for further replies.

Share This Page