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: Spoiler: PlayerEggThrowEvent Code (Text): package me.mariozgr8.events; 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);} @EventHandler public void OnPlayerThrow(PlayerEggThrowEvent e){ Player p = e.getPlayer(); Location loc = p.getLocation(); loc.setX(loc.getX() + 1); if(!(p.hasPermission("events.spawning.rabbit"))){} if(p.hasPermission("events.spawning.rabbit")){ //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 ?
Old Version https://www.spigotmc.org/resources/perworldplugins-unofficial-update-version.6454/ The new version: https://www.spigotmc.org/resources/perworldplugins.32751/
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.
Code (Text): Rabbit r = (Rabbit) Bukkit.getServer().getWorld(p.getWorld()).spawnEntity(location, EntityType.RABBIT);
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
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 ?
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);