1. Welcome to LilyPad. Download the project, explore the forums, and create your own LilyPad network.


    If you use the software and enjoy it or have a question, or would like to contribute to the future of the software directly or through resources, please sign up and join our little community.

Setting up permissions

Discussion in 'Programming' started by 123isme1, Dec 31, 2013.

  1. 123isme1

    123isme1 New Member

    hey guys,
    I am working on merging a bunch of my plugins together, and I decided to add permissions with it. Currently I am working on making it so you must have permission "MC123CraftExtras.IHArmor" (stands for "iron horse armor" to craft iron horse armor. I have tried multiple videos and other resources, but gotten nowhere. Do I need to add a permissions.java class? I know I also need to add something in the Main.java class, but don't know what.
    Here is my code: Here is the part of the code I am working on:
    Code (java):
    package com.MC123isme1.MC123CraftExtras;

    import org.bukkit.Material;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener {

        public void onEnable(){
         
            final ShapedRecipe ihArmor = new ShapedRecipe(new ItemStack(Material.IRON_BARDING));
            ihArmor.shape("  H", "CCC", "L L");
            ihArmor.setIngredient('H', Material.IRON_HELMET);
            ihArmor.setIngredient('C', Material.IRON_CHESTPLATE);
            ihArmor.setIngredient('L', Material.IRON_LEGGINGS);
            getServer().addRecipe(ihArmor);
        }
    }
    Thank you guys in advance for all the help!

    Lastly, I know that I am the only person that has started discussions in this topic, but is that bad?
    Last edited by a moderator: Dec 31, 2013
  2. boboman13

    boboman13 Member Contributor

    I'm not exactly sure what you're doing here. Are you creating a Permissions plugin, checking whether a player has a permission node, creating a Permission object...?

    If you're checking for a permission:
    Code (text):
    Player player = thisismyplayer;
    if(player.hasPermission("MC123CraftExtras.IHArmor")) {
        // do something
    }
  3. 123isme1

    123isme1 New Member

    It is the latter one, it allows crafting of Iron Horse Armor, but only if you have the permission. When I used your code, the issue I'm having is that it has a red underline (error) on "thisismyplayer" and says it cannot be resolved to a variable.
    Here is what I have:
    Code (text):
            Player player = thisismyplayer;
            if(player.hasPermission("MC123CraftExtras.IHArmor")) {
           
            final ShapedRecipe ihArmor = new ShapedRecipe(new ItemStack(Material.IRON_BARDING));
            ihArmor.shape("  H", "CCC", "L L");
            ihArmor.setIngredient('H', Material.IRON_HELMET);
            ihArmor.setIngredient('C', Material.IRON_CHESTPLATE);
            ihArmor.setIngredient('L', Material.IRON_LEGGINGS);
            getServer().addRecipe(ihArmor);
            }
  4. Matt

    Matt Forum Moderator & Contributor Staff Member Moderator Contributor

    Because you didn't defined the player on the right way.

    Try this instead of Player player = thisismyplayer;

    Code (java):

    Player player = getServer().getPlayer(getName());
     
    • Like Like x 1
  5. 123isme1

    123isme1 New Member

    EDIT: No errors appear in Eclipse, only in the console
    You guys will hate me for this:
    Got this while loading the plugin, it doesn't work at all, but still appears green in /pl.
    Code (text):
    [08:46:35 ERROR]: Error occurred while enabling 123CraftExtras v1 (Is it up to d
    ate?)
    java.lang.NullPointerException
            at com.MC123isme1.MC123CraftExtras.Main.onEnable(Main.java:16) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217) ~[c
    raftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:457) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:381) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin(CraftServer.jav
    a:298) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.enablePlugins(CraftServer.
    java:280) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.reload(CraftServer.java:63
    0) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at org.bukkit.Bukkit.reload(Bukkit.java:279) [craftbukkit.jar:git-Bukkit
    -1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
    23) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:19
    2) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServe
    r.java:542) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchServerCommand(Craf
    tServer.java:529) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.aw(DedicatedServer.java:
    286) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    51) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    41) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :453) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-38-g4b4e2cc-b2953jnks]
    Heres my Main.java:
    Code (java):
    package com.MC123isme1.MC123CraftExtras;

    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener {

        public void onEnable(){

       
            Player player = getServer().getPlayer(getName());
            if(player.hasPermission("MC123CraftExtras.HorseArmor.IHArmor")) {
       
            final ShapedRecipe ihArmor = new ShapedRecipe(new ItemStack(Material.IRON_BARDING));
            ihArmor.shape("  H", "CCC", "L L");
            ihArmor.setIngredient('H', Material.IRON_HELMET);
            ihArmor.setIngredient('C', Material.IRON_CHESTPLATE);
            ihArmor.setIngredient('L', Material.IRON_LEGGINGS);
            getServer().addRecipe(ihArmor);
            }

        }
    }
     
    And my plugin.yml:
    Code (yaml):
    name: 123CraftExtras
    main
    : com.MC123isme1.MC123CraftExtras.Main
    version
    : 1
    author
    : 123isme1
    permissions
    :
        MC123CraftExtras.HorseArmor
    :
          description
    : Allows crafting of horse armor
          children
    :
            MC123CraftExtras.HorseArmor.IHArmor
    :
              description
    : Craft Iron Horse armor
    Last edited by a moderator: Dec 31, 2013
  6. Matt

    Matt Forum Moderator & Contributor Staff Member Moderator Contributor

    Ohh you are doing this in a on enable? You can't do that.
  7. 123isme1

    123isme1 New Member

    Oh...derp
    Also I found a post by dinnerbone that might help for the future

Share This Page