Half working plugin

Discussion in 'Plugin Development' started by BrushPainter, Oct 9, 2014.

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

    BrushPainter

    Hey guys, my plugin is barely functioning. The only thing working right now is when I type /dice I get a ItemStack (Block of Quartz) but when I right click while holding it, nothing at all happens. It should be sending a message to the player as well as broadcasting a random number.

    Main.java:
    http://pastebin.com/kjH7FZ5G

    plugin.yml: (No tabs were used in it)
    http://pastebin.com/VJKL0wve
     
  2. Offline

    CaptainUniverse

    umm BrushPainter do you know how to use java? Because you are putting regular integers outside of a method. They are not public so I dought it will work.
     
  3. Offline

    Unica

    CaptainUniverse
    Ironically. Do you know java. Because an field / variable doesn't have to be public for it to work, actually, private will work also.

    Private makes it only accessible through the same class, even with an constructor.
    Public makes every variable accessible through constructors and such.
    Code:java
    1. int random; //private
    is usable through the entire class.

    Concerning BrushPainter 's problem.
    Code:java
    1. ItemStack stack = new ItemStack(); //you create a new itemstack
    2. ItemMeta meta = stack.getItemMeta() //You initiate the variable meta
    3. meta.setDisplayName(""); //You SET the new displayname
    4. stack.doSomething(); //Then you use the Itemstack variable


    Your problem is simple,
    reset the itemmeta to the itemstack, and then your 'dice' has a displayname
    -->
    Code:java
    1. ItemStack stack = new ItemStack(stuff);
    2. ItemMeta meta = stack.getItemMeta();
    3. meta.setSomething();
    4. stack.setItemMeta(meta);
     
    Totom3, BrushPainter and es359 like this.
  4. Offline

    fireblast709

    BrushPainter
    • You should set the display name (uncommented the lines and add a setItemMeta(ItemMeta) call). Even more (though optional), you should do this in your constructor.
    • Generate your random number in onCommand.
    • Use cmd.getName() instead of commandLabel for alias support.
    • Check if sender instanceof Player before casting to Player.
    • Check if the ItemStack even has ItemMeta, and check if the ItemMeta even has a display name. Failing to do so could cause NullPointerExceptions.
    • No need for enable/disable messages, Bukkit already does this for you.

    CaptainUniverse Unica http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
     
    Code0 likes this.
  5. Offline

    Code0

    I'm not 100% sure, but instead of putting ....getType().equals() you should remove the getType. Just because you actually defined the ItemStack already.

    As I said, mostly a guess :).
     
  6. Offline

    BrushPainter

    fireblast709 Unica Code0 Ok so it's still doing the same thing, I cut out a lot of the plugin to try and make it as basic as possible but it still doesn't work. What I'm trying to achieve is if the player is holding a Block of Quartz and they right click with it in their hand, then it broadcasts a message saying "You rolled a ...". Please help guys. Here's my new code: http://pastebin.com/A5DY9cr0
     
  7. Offline

    rbrick

    learn java bro
     
  8. Offline

    mythbusterma

    Unica

    Read the links that FireBlast posted. The default access modifier isn't private, it's default modifier (a.k.a. package private), which is certainly not the same thing as private. Second, your definitions of public and private are just wrong. A public member of a class is accessible from any other object, whereas a private member of a class is not accessible from any other object, but can be accessed from within the same class, even with a different instance (this is how a lot of copy-constructors work).
     
Thread Status:
Not open for further replies.

Share This Page