Need help with a custom item plugin i made.

Discussion in 'Plugin Development' started by trusebruse, May 19, 2013.

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

    Rocoty

    Yeah, remove the entire method (that includes the method body, you know), although if you are going to use it now or later, just keep it...the code would still compile
     
  2. Offline

    trusebruse

    What? I didn't get that. I'm trying to make this part to work,
    Code:
     Altar = new ItemStack(Material.DIAMOND, 9, DIAMOND_BLOCK);
    ItemMeta meta = Altar.getItemMeta();
    meta.setDisplayName(ChatColor.RESET + Altar_Block);
    Altar.setItemMeta(meta); 
    So can have my custom block (Altar) to be craftable..

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

    Rocoty

    Well, then you should invoke the method where you want it. You can't expect a car to go without using any pedals
     
  4. Offline

    trusebruse

    How?
     
  5. Offline

    Rocoty

  6. Offline

    trusebruse

    Yes, you are absolutely right but before i do anything i want to complete this plugin and i would love some help.
    What excactly am i supposed i add?
     
  7. Offline

    Rocoty

    somewhere in your code, wherever you want the body of the method to be executed, you type:
    Code:
    createBrick();
     
  8. Offline

    trusebruse

    Well, the warning dissapeared when i entered public instead of private. But it still dosn't seems to work.
    Any idea?
    Code:
    package me.trusebruse.prayer;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.inventory.ShapedRecipe;
     
    public class Prayer extends JavaPlugin {
        private ItemStack Altar;
        private short DIAMOND_BLOCK;
        private String Altar_Block;
       
            public void createBrick() {
                Altar = new ItemStack(Material.CLAY_BRICK, 1, DIAMOND_BLOCK);
                ItemMeta meta = Altar.getItemMeta();
                meta.setDisplayName(ChatColor.RESET + Altar_Block);
                Altar.setItemMeta(meta);
            };
            public void registerCrafting() {
                ItemStack result = new ItemStack(Material.DIAMOND_BLOCK);
                ShapedRecipe recipe = new ShapedRecipe(result);
                recipe.shape("###", "###", "###");
                recipe.setIngredient('#', Altar.getData());
                getServer().addRecipe(recipe);}
                   
               
     
        public ItemStack getAltar() {
            return this.Altar;
        };
     
        //Effects 
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event)
        {
            if(event.getAction() == Action.RIGHT_CLICK_BLOCK)
            {
                event.getPlayer().sendMessage(ChatColor.GOLD+ "You absorbed powers from the gods.");
                Player player = event.getPlayer();
                player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 3000, 0));
                player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 10000, 100));
                player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000, 1));
                player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 1000, 0));
                if (player.hasPermission("altar.use"));}
            {
     
                 
                  event.setCancelled(true);
                  event.getPlayer().sendMessage(ChatColor.AQUA+ "The gods won't transfer powers to you yet.");
                  }
        }
    }
     
     
                 
    
     
  9. Offline

    Rocoty

    You still never use the method anywhere in yuor code. You just define it and leave it hanging.

    The warning was shown because the compiler could be 100% certain the method was never used (because it was private and never used within the same class). When you changed it to public, you effectively told the compiler: "Hey, I can handle this! I know this method isn't used anywhere in this class, but I've ensured it's being used somewhere on the outside." Therefore it removed the warning.

    Your problem persists because you still don't use the method anywhere. Let me give you an example:

    Code:
    private void method() { //Define the method, its name is "method"
        System.out.println("Method has been invoked"); //Give the method a body
    }//Close the body
     
    @Override
    public void onEnable() {
        method(); //Invoke method (you HAVE to do this somewhere in the code. You HAVE to tell the code to execute method if you ever want it to be executed)
    }
     
  10. Offline

    trusebruse

    Alright so where and what in my code should i add this then?
     
  11. Offline

    Rocoty

    It all depends on where and when you want it to happen. But please, read up on basic Java. Search tutorials, do anything. It will make everything so much clearer!
     
  12. Offline

    caseif

    Can everyone just please stop responding? The OP clearly doesn't have a basic understanding of Java or the Bukkit API, and almost every single issue they've had can be resolved with a Google search. Granted, some may require a bit more digging than others, but I guarantee that every solution will be found within the first 2 or 3 pages of the results. Please, trusebruse, just learn some Java before posting to the forums.
     
    CubieX likes this.
  13. Offline

    trusebruse

    Alrighty then. I'll read java until I really understand this stuff, I'm Sorry for bothering you gyus. ;)
    //Truse
     
  14. Offline

    Minnymin3

    Also itemmeta is lost when the block is placed. Thats why you have to figure out some crafty way of checking if the block is your block.
     
  15. Offline

    CubieX

    I already explained that and a possible solution in my second post on page 1.
    But I totally agree with AngryNerd : It makes no sense to give the OP all the code he wants, as long as he has not the slightest clue about Java.
    This forum is not meant to teach somebody the very basics. It's meant to help "Developers" to get around with the Bukkit API.
    Nobody has to be a pro here and the least of the people are.
    But knowing your basic tool set is essential. And reading a Java book or two and getting familiar with the language, is something, that has to be done prior to coming here.
    Learning by doing is good. But "Copy and Paste" without the will to discover what's actually going on is not.
     
    Minnymin3 likes this.
Thread Status:
Not open for further replies.

Share This Page