Solved I'm making a plugin, I need some help.

Discussion in 'Plugin Development' started by thomasb454, Jun 18, 2013.

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

    thomasb454

    historio
    It's fine, don't worry!

    Thanks again.

    Can anyone expand on what historio said?

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

    wizzinangel

    thomasb454 give me about 2 hours and I'll have a look again.

    thomasb454 do you have the Itemstack line added and have you imported ItemStack?

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

    thomasb454

  4. Offline

    historio

    thomasb454 I get that error message with a plugin i'm making too :/
     
  5. Offline

    thomasb454

    historio
    pt1448 said, I think it needs to be 'cast' as I'm still learning I don't know what that is.
     
  6. Offline

    historio

  7. Offline

    thomasb454

    historio
    Lol, before check this thread I seen you posted it. So I clicked that link, then seen you replied to this one with that link xD

    I don't think that made any sense. Ow well :D
     
  8. Offline

    wizzinangel

    @thomasb454you shouldn't need the event.getPlayer() which isn't a function under the event.
    My test code I used is:

    Code:java
    1. import org.bukkit.Material;
    2. import org.bukkit.event.inventory.InventoryCreativeEvent;
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.inventory.ItemStack;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public class DisableCreativeFunctions extends JavaPlugin implements Listener{
    9.  
    10. public void onEnable() {
    11. getServer().getPluginManager().registerEvents(this, this);
    12.  
    13. }
    14.  
    15. public void onDisable() {
    16.  
    17. }
    18.  
    19. @EventHandler
    20. public void onSpawnItem(InventoryCreativeEvent event) {
    21. ItemStack EGApple = new ItemStack(322,1, (byte)1);
    22.  
    23. if (event.getInventory().contains(Material.getMaterial(322))) {
    24. event.setCancelled(true);
    25. } else if (event.getInventory().contains(EGApple)) {
    26. event.setCancelled(true);
    27. }
    28. }
    29. }


    And this works fine
     
  9. Offline

    thomasb454

    wizzinangel
    Don't work.
    Code:java
    1. package com.dcsoft;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.event.inventory.InventoryCreativeEvent;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.inventory.ItemStack;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class GodApple extends JavaPlugin implements Listener {
    11.  
    12. public void onEnable() {
    13. getServer().getPluginManager().registerEvents(this, this);
    14.  
    15. }
    16.  
    17. public void onDisable() {
    18.  
    19. }
    20.  
    21. @EventHandler
    22. public void onSpawnItem(InventoryCreativeEvent event) {
    23. ItemStack EGApple = new ItemStack(322, 1, (byte) 1);
    24.  
    25. if (event.getInventory().contains(Material.getMaterial(322))) {
    26. event.setCancelled(true);
    27. } else if (event.getInventory().contains(EGApple)) {
    28. event.setCancelled(true);
    29. }
    30. }
    31. }


    bump

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

    thomasb454

    I really need this plugin guys, please help me!
     
  11. Offline

    thomasb454

  12. Offline

    xxmobkiller

    If you want i can just make the plugin for you and post the code or i can just post the .jar or just the code you tell me i am on all the time !
     
  13. Offline

    Minnymin3

    Heres some magical code that will help you fix all your plugin problems:
    Code:java
    1. learn.java();
     
    AngryNerd and kinglime like this.
  14. Offline

    savagesun

    You aren't overriding the onEnable/onDisable methods? Place @Override above them? Something like:
    Code:
    @Override
    public void onEnable() {
    //...
    }
     
    @Override
    public void onDisable() {
    //...
    }
    Not sure it's causing you errors, but it should be.
     
  15. Offline

    thomasb454

    Minnymin3
    Hi, please don't comment unless your going to help.
    People like you make me mad.

    savagesun
    Ok, I'll try this out.

    xxmobkiller
    That would be great, thanks!

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

    Minnymin3

    thomasb454
    People like you make me mad because you have not even tried to learn java. This forum is meant for people develop their plugins, not for people trying to get code that someone else gave them work.
     
  17. Offline

    thomasb454

    Minnymin3
    I am learning Java. So if you've got nothing else that is helpful to say please stop responding.

    I'm starting to read through a Java book.

    EDIT:
    I've also made my own plugin.
     
  18. Offline

    xxmobkiller

    OK OK EVERY ONE that is needing help if you want to know how to add the Player player = event.getPlayer();
    That is wrong you don't need that here how to do it the right way Player player = event.getWhoClicked();
    but here the fix to the golden apple here is the code and the .jar
    Code:
    import org.bukkit.Material;
    import org.bukkit.event.inventory.InventoryCreativeEvent;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin implements Listener {
     
      public void onEnable() {
          getServer().getPluginManager().registerEvents(this, this);
     
      }
     
      public void onDisable() {
     
      }
     
      @EventHandler
      public void onSpawnItem(InventoryCreativeEvent event) {
          ItemStack EGApple = new ItemStack(322, 0, (byte) 1);
     
          if (event.getInventory().contains(Material.getMaterial(322))) {
              event.setCurrentItem(EGApple);
              event.setCancelled(true);
          } else if (event.getInventory().contains(EGApple)) {
              event.setCancelled(true);
          }
      }
    }

    here the .jar file for this plugin http://www.herosh.com/download/11169175/NoGoldenApple.jar.html
     
  19. Offline

    thomasb454

    xxmobkiller
    The plugin doesn't work.
    Since I'm new, is there a event.deleteitem (or something like that)?
     
  20. Offline

    xxmobkiller

    I thank i know what i did wrong but first i will need 2 thangs first is do you want me to delete the golden apple when they move it to there invtory or just replace it with the golden apple if none of this what i said dose not get what you need then what is it you want done when they try to get the item
     
  21. Offline

    thomasb454

    xxmobkiller
    Hi. I want it to delete the Golden Apple (God Apple) if PLACED in the inventor.

    I don't want it to delete it if it's given using a command though. If it helps, the Golden Apple that will be given using a command will be renamed.
     
  22. Offline

    xxmobkiller

    ok i will redo the code and fix it !
     
  23. Offline

    thomasb454

    Solved! My mate dcgamingentral gave me this code. Thanks!

    Code:java
    1. @EventHandler
    2. public void itemSpawnEvent(PlayerItemConsumeEvent event) {
    3. Player player = (Player) event.getPlayer();
    4. ItemStack OPApple = new ItemStack(322, 0, (byte) 1);
    5. if(event.getItem().getType() == Material.GOLDEN_APPLE)
    6. if(event.getItem().getData().getData() == 1) {
    7. if(event.getItem().hasItemMeta())
    8. if(event.getItem().getItemMeta().getDisplayName().equals("OP APPLE ©")) return;
    9. player.getInventory().remove(event.getItem());
    10. event.setCancelled(true);
    11. player.sendMessage(colorize("&6Please by&a an OP Apple&6 from our in-game store!&b (/warp shop)"));
    12. }
    13. }
    14. public static String colorize(String msg) {
    15. String coloredMsg = "";
    16. for (int i = 0; i < msg.length(); i++) {
    17. if (msg.charAt(i) == '&')
    18. coloredMsg += '§';
    19. else
    20. coloredMsg += msg.charAt(i);
    21. }
    22. return coloredMsg;
    23. }
    24.  
    25. }
     
Thread Status:
Not open for further replies.

Share This Page