Spawn pig

Discussion in 'Plugin Development' started by InspectorFacepalm, May 29, 2013.

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

    LazyLemons

    InspectorFacepalm Are you sure the event is being called? Between lines, have something like
    Code:
    System.out.println("Debug 1");
    , and see where the messages stop.
     
  2. Doesn't say anything :/
     
  3. Offline

    LucasEmanuel

    Well do you have it on github then?
     
  4. Nope, I'll just show you what Compressions made for me <3
    Code:
    import java.util.ArrayList;
    import java.util.List;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.World;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.scheduler.BukkitScheduler;
    
    public class Main extends JavaPlugin
      implements Listener
    {
      List<String> cooldown = new ArrayList();
    
      public void onEnable()
      {
        getServer().getPluginManager().registerEvents(this, this);
      }
    
      public void onPlayerInteract(PlayerInteractEvent e)
      {
        final Player player = e.getPlayer();
        World world = player.getWorld();
        if ((e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && (player.getItemInHand().getType().equals(Material.BLAZE_ROD)))
          if (this.cooldown.contains(player.getName()))
          {
            player.sendMessage(ChatColor.RED + "You can't spawn a pig at this time!");
          }
          else {
            world.spawnEntity(player.getEyeLocation(), EntityType.PIG);
            this.cooldown.add(player.getName());
            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitRunnable() {
              public void run() {
                Main.this.cooldown.remove(player.getName());
              }
            }
            , 6000L);
          }
      }
    
      public void onPlayerJoin(PlayerJoinEvent e)
      {
        Player player = e.getPlayer();
        player.sendMessage(ChatColor.GRAY + "This server is running PigEvent by Compressions.");
      }
    }
    
    It doesn't spawn a pig tho :./
     
  5. Offline

    LucasEmanuel

    Add @EventHandler above the methods.
     
  6. Tried that, still doesn't work :/
     
  7. Offline

    LazyLemons

    InspectorFacepalm You have @EventHandler above
    Code:
    public void onPlayerInteract(PlayerInteractEvent e)
    ?
    Also, instead, try
    Code:
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
     
  8. I already have everything you said :/
     
  9. Offline

    GodzOfMadness

    InspectorFacepalm In your server.properties file is "spawn-animals" set to true?
     
  10. Yep it is.
     
  11. Offline

    Minecrell

    InspectorFacepalm I really don't know what you are doing wrong... Took the code above; added the @EventHandler and compiled it... It is working great :p

    EDIT: Lol, 72 replies for how to spawn a pig :D
     
  12. :p I'll try to do something else, thank you all for helping <3
     
  13. Offline

    bfgbfggf

    sooo... you have 3000 lines of code?
    create better code. Listeners in other classes. This same with commands. etc.


    EDIT: and try create new project only with that pig code (don't forget register it!)
    and check if that work.

    EDIT: maybe that stupid... but maybe you don't export all code? When you start exproting try click on that box with you project 3x. Click, unClick , Click. or check if there all classes Clicked.
    *Sorry for English... I don't have idea how to write that in English :D
     
  14. Ehh, I'ma just wait, some guy said he would make the plugin, and if it works it will be awesome and I'll jizz
     
Thread Status:
Not open for further replies.

Share This Page