[WRITTEN BOOK] Help!

Discussion in 'Plugin Development' started by iBenjaHD, Mar 30, 2014.

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

    iBenjaHD

    I am making my own huge plugin, I really want to know how to add a book, a written book where I chose what it should say on each pages,
    I want to know when someone for example types /book they get the book that already are made.
    Please help me!
     
  2. Offline

    2MBKindiegames

    This should get you started
    Code:java
    1. ItemStack itemstack = new ItemStack(Material.WRITTEN_BOOK, 1);
    2. BookMeta bm = (BookMeta) itemstack.getItemMeta();
    3.  
    4. bm.setAuthor("PlayerName");
    5. bm.setDisplayName("Name");
    6. bm.setPage(0, "Page 1 text");
    7. bm.setPage(1, "Page 2 text");
    8. bm.setTitle("Title");
    9. itemstack.setItemMeta(bm);
     
  3. Offline

    iBenjaHD

    How can I do so they can do a command to get the book?

    Code:
                    if (cmd.getName().equalsIgnoreCase("Regler")) {
                    ItemStack itemstack = new ItemStack(Material.WRITTEN_BOOK, 1);
                    BookMeta bm = (BookMeta) itemstack.getItemMeta();
           
                    bm.setAuthor("iBenjaHD");
                    bm.setDisplayName("Server regler");
                    bm.setPage(0, "Hei folkens dette er en test");
                    bm.setPage(1, "Test nummer 2");
                    bm.setTitle("Server regler");
                    itemstack.setItemMeta(bm);
                    }
    I did that but it didn't work
     
  4. Offline

    2MBKindiegames

    Use this:
     
  5. Offline

    iBenjaHD

    Where? Please send me the code I sent you with what you said
     
  6. Offline

    2MBKindiegames

    Here you go:
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("Regler")) {
    2. if (sender instanceof Player) {
    3. Player player = (Player)sender;
    4. ItemStack itemstack = new ItemStack(Material.WRITTEN_BOOK, 1);
    5. BookMeta bm = (BookMeta) itemstack.getItemMeta();
    6.  
    7. bm.setAuthor("iBenjaHD");
    8. bm.setDisplayName("Server regler");
    9. bm.setPage(0, "Hei folkens dette er en test");
    10. bm.setPage(1, "Test nummer 2");
    11. bm.setTitle("Server regler");
    12. itemstack.setItemMeta(bm);
    13. player.getInventory().addItem(itemstack);
    14. }
    15. }
     
  7. Offline

    iBenjaHD

    I
    It still doesn't work when I type /regler .....

    My code:

    Code:java
    1. }
    2. if (cmd.getName().equalsIgnoreCase("Regler")) {
    3. if (sender instanceof Player) {
    4. ItemStack itemstack = new ItemStack(Material.WRITTEN_BOOK, 1);
    5. BookMeta bm = (BookMeta) itemstack.getItemMeta();
    6.  
    7. bm.setAuthor("iBenjaHD");
    8. bm.setDisplayName("Server regler");
    9. bm.setPage(0, "Hei folkens dette er en test");
    10. bm.setPage(1, "Test nummer 2");
    11. bm.setTitle("Server regler");
    12. itemstack.setItemMeta(bm);
    13. player.getInventory().addItem(itemstack);
    14. }
     
  8. Offline

    2MBKindiegames

    Sorry, i forgot, add
    between line 13 & 14
     
  9. Offline

    iBenjaHD

    It still won't work.

    My code:
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("Regler")) {
    2. if (sender instanceof Player) {
    3. ItemStack itemstack = new ItemStack(Material.WRITTEN_BOOK, 1);
    4. BookMeta bm = (BookMeta) itemstack.getItemMeta();
    5.  
    6. bm.setAuthor("iBenjaHD");
    7. bm.setDisplayName("Server regler");
    8. bm.setPage(0, "Hei folkens dette er en test");
    9. bm.setPage(1, "Test nummer 2");
    10. bm.setTitle("Server regler");
    11. itemstack.setItemMeta(bm);
    12. player.getInventory().addItem(itemstack);
    13. player.updateInventory();
    14. }
     
  10. Offline

    2MBKindiegames

    Can you confirm the commands are listed correctly into your plugin.yml and the listener is set right?
     
  11. Offline

    iBenjaHD

    Listener?
     
  12. Offline

    2MBKindiegames

     
  13. Offline

    iBenjaHD

    SStill does not work...
     
  14. Offline

    Minnymin3

    2MBKindiegames
    No. Commands are not events!
    iBenjaHD
    First off, it seems you have close to no idea what you are doing. Start by learning java and then read the plugin tutorial on the Bukkit wiki.
     
  15. Offline

    iBenjaHD

    I know java, but I didn't know how to add this itemstack thingy, I make plugins and I success.... They work well. But then I came to this and it didn't work..... That's why I asked about help...
     
  16. Offline

    Minnymin3

    My apologies. It appeared as though you didn't know where your onCommand statement was. The code given should work fine. What exactly happens when you execute the command?
     
  17. Offline

    iBenjaHD

    t
    Nothing happends -.-
     
  18. Offline

    TheHolySheep_NL

    iBenjaHD
    Did to add the "regler" command in your config file?

    - Sheep
     
  19. Offline

    iBenjaHD

    Yes I have that..

    Regler:
    usage: /<command>
    aliases: [rules]
    description: Sjekk reglene
     
  20. Offline

    SuperOmegaCow

    iBenjaHD
    this.getCommand("your command").setExecutor(new YourCommandClass()):
     
Thread Status:
Not open for further replies.

Share This Page