Plugin issues

Discussion in 'Spigot Plugin Development' started by Mariozgr8, Apr 13, 2017.

  1. HI, so I have a question: Can I make a plugin work in a specific world only ? if its possible how can I make it ?
    Also, i'm trying to code a plugin that will spawn a rabbit pet when a plyer throw a normal egg.
    So far I've done this:
    Code (Text):

    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.*;

    public class EggThrowPlayer implements Listener {

        public EggThrowPlayer(EventsHandler plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);}
        public void OnPlayerThrow(PlayerEggThrowEvent e){
            Player p = e.getPlayer();
            Location loc = p.getLocation();
            loc.setX(loc.getX() + 1);
                //i want to make it here so that a rabbit spawn at the location loc when the player throw the egg.
    But I don't know how to spawn a rabbit at the location loc. Can anyone help me please ? :)
  2. You can get the world that the player is in, you can get its name and check if the player is in the world you want.

    You can get the world and use spawnEntity to spawn the rabbit.
    • Like Like x 1
  3. Code (Text):
    Rabbit r = (Rabbit) Bukkit.getServer().getWorld(p.getWorld()).spawnEntity(location, EntityType.RABBIT);
  4. Thanks for your help guys :) but I can't figure out how to write it :( I want to spawn a rabbit at the location loc what should o write ?

    EDIT: I didn't see the messaged thanks :)
  5. Fluddershy gave you the answer
  6. When I typed this I got : The method getWorld(String) in the type Server is not applicable for the arguments (World). How can I fix this ?
  7. Code (Text):
    String playerWorld = (String) p.getWorld().toString();
    or a 1 liner
    Code (Text):
    Rabbit r = (Rabbit) Bukkit.getServer().getWorld(p.getWorld().toString()).spawnEntity(location, EntityType.RABBIT);
    • Agree Agree x 1
  8. If you want to get the worlds name you would use getName instead.
  9. p is the player. Have you defined the player yet?
    Something like Player p = event.getPlayer()
  10. Thanks guys for your help :)
  11. Why did I have to see this
    • Funny Funny x 1