Registering Events

Discussion in 'Plugin Development' started by monkeymanboy, Oct 2, 2013.

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

    monkeymanboy

    I started cleaning up my core plugin for my server and I started using multiple classes I think I registered the events wrong this is my onenable
    Code:java
    1. @Override
    2. public void onEnable(){
    3. getLogger().info("Minecloud Core Enabled");
    4. PluginManager pm = this.getServer().getPluginManager();
    5. pm.registerEvents(new fb(), this);
    6. pm.registerEvents(this, this);
    7. //Recipes To Register
    8. for (ShapedRecipe recipe : recipes) {
    9. this.getServer().addRecipe(recipe);
    10. }
    11.  
    12. for (ShapelessRecipe recipe : shapeless) {
    13. this.getServer().addRecipe(recipe);
    14. }
    15. }

    Here's my fb class
    Code:java
    1. package com.icloud.dcljr.MinecloudCore;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.HumanEntity;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.inventory.CraftItemEvent;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.ShapedRecipe;
    14. import org.bukkit.inventory.ShapelessRecipe;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16.  
    17. import Utils.EasyItems;
    18.  
    19. public class fb implements Listener {
    20.  
    21. public static MinecloudCore plugin;
    22.  
    23. public static ArrayList<ShapelessRecipe> shapeless = new ArrayList<ShapelessRecipe>();
    24. public static ArrayList<ShapedRecipe> recipes = new ArrayList<ShapedRecipe>();
    25. //Recipe Limiter To Just Freebuild
    26. @SuppressWarnings("incomplete-switch")
    27. @EventHandler
    28. public void RemoveRecipes(CraftItemEvent e) {
    29. HumanEntity p = (HumanEntity) e.getViewers().get(0);
    30. ItemMeta im = e.getRecipe().getResult().getItemMeta();
    31. if (p instanceof Player) {
    32. @SuppressWarnings("unused")
    33. Player player = (Player) p;
    34. boolean isWorldHM = p.getWorld().getName().startsWith("world");
    35. boolean isItemHM = (im.hasLore()) ? im.getLore().contains(ChatColor.DARK_AQUA + "Freebuild Item") : false;
    36. if (!isWorldHM && isItemHM) {
    37. e.setCancelled(true);
    38. }
    39. }
    40. }
    41. //Items and their recipes
    42. {
    43. ItemStack EnderBow = EasyItems.EasyFreebuild(Material.BOW, (int) 1,(byte) 0, (String) "Enderbow" ,(String) "The dragons essence");
    44. ShapedRecipe ebow = new ShapedRecipe(new ItemStack(EnderBow));
    45. ebow.shape(" ST", "SET", " ST");
    46. ebow.setIngredient('S', Material.STRING);
    47. ebow.setIngredient('T', Material.STICK);
    48. ebow.setIngredient('E', Material.DRAGON_EGG);
    49. recipes.add(ebow);
    50.  
    51.  
    52. ItemStack LemonG = EasyItems.EasyFreebuild(Material.INK_SACK, (int) 4,(byte) 11, (String) "Lemon Grenade" ,(String) "In Cave Johnsons name");
    53. ShapelessRecipe LemonGrenade = new ShapelessRecipe(new ItemStack(LemonG));
    54. LemonGrenade.addIngredient(Material.APPLE);
    55. LemonGrenade.addIngredient(Material.INK_SACK, 11);
    56. LemonGrenade.addIngredient(Material.TNT);
    57. shapeless.add(LemonGrenade);
    58. }
    59. }
    60.  
     
  2. Offline

    sgavster

    You'd do
    Code:
        private final fb f = new fb(this);
    Code:java
    1. pm.registerEvents(this.f, this);
     
  3. Offline

    monkeymanboy

  4. Offline

    sgavster

    1. onEnable:
      Code:java
      1. pm.registerEvents(this.f, this);

      Under yourplugin implements blah blah
      Code:java
      1. private final fb f = new fb(this);
    Edit: AHH I don't know why this is orange, I didn't click the color button..
     
  5. Offline

    monkeymanboy

    sgavster I get an error under new fb(this)
     
  6. Offline

    sgavster

    monkeymanboy Put this in your fb class:

    Code:
        public static MinecloudCore plugin;
     
        public fb (MinecloudCore instance)
        {
            plugin = instance;
        }
     
  7. Offline

    monkeymanboy

    sgavster no errors now I'll test it
    EDIT: Still get an error

    I think it might be this in my main
    Code:java
    1. public static ArrayList<ShapelessRecipe> shapeless;
    2. public static ArrayList<ShapedRecipe> recipes;

    here's how I did it in class fb
    Code:java
    1. public static ArrayList<ShapelessRecipe> shapeless = new ArrayList<ShapelessRecipe>();
    2. public static ArrayList<ShapedRecipe> recipes = new ArrayList<ShapedRecipe>();


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  8. Offline

    sgavster

    Why dont you make recipes like this
    Code:
    private ShapelessRecipe myRecipe = new ShapelessRecipe(new ItemStack(Material.STICK, 1)).addIngredient(Material.DIRT);
    And register it onEnable
    getServer().addRecipe(myRecipe);
     
  9. Offline

    monkeymanboy

    sgavster Because it is in a different class
     
  10. Offline

    monkeymanboy

Thread Status:
Not open for further replies.

Share This Page