Nooby Dev

Discussion in 'Plugin Development' started by Niknea, Dec 9, 2013.

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


    Alright the plugin finally loads *yay* however it doesn't work. The aim for this plugin is to check if they have 7 stone on log in, if they do they get a message saying you do, if they don't they get a message that says you don't. However its not appearing, mind showing / explain whats wrong?
  2. Offline


    Mind showing us your current code?

    Edit: Never mind, I misread something haha..

    Well anyway, here's the code that should work in case you can't figure it out yourself:
    Show Spoiler

    1. @EventHandler(priority = EventPriority.HIGH)
    2. public void loginInventoryCheck(PlayerJoinEvent event) {
    3. Player player = event.getPlayer();
    4. Inventory inv = player.getInventory();
    5. ItemStack itemstack = new ItemStack(Material.STONE, 7);
    7. if(inv.contains(itemstack)) {
    8. player.sendMessage(ChatColor.RED + "Woohoo stone!");
    9. } else if(!inv.contains(itemstack)) {
    10. player.sendMessage(ChatColor.GOLD + "Aww no stone, here have some!");
    11. inv.addItem(itemstack);
    12. }
    13. }

    Niknea likes this.
  3. Offline


    Alright I'm just going to confirm each line so I know what it fully is and I'm not just copying you.

    Line #1: I'm not to sure mind explaining it?
    Line #2: I think I know however I'm not fully sure mind explaining?
    Line #3: Sets player to event.getplayer()
    Line #4: Sets inventory to player.getinventory()
    Line #5: Creates an ItemStack of 7 stone
    Line #7: If the player has the itemstack (in this case 7 stone) it will execute the code in line 8
    Line #8: Sends a red colored message saying "Woohoo stone!"
    Line #9: If the player didn't have the 7 stone line 9,10, and 11 would execute. Also for line 9 couldn't you have done this?
    1. else { player.sendMessage(ChatColor.GOLD + "Aww no stone, here have some!");
    2. inv.addItem(itemstack)
    3. }

    Line #10: Will send a gold colored message saying "Aww not stone, here have some!"
    Line #11: Gives the player the itemstack ( 7 stone in this case )

    Thanks again, Niknea

    EDIT: The code you sent me doesn't work, it loads in the config however nothing happens.
  4. Offline


    I have to say, you're the only person I've seen that wants to exactly what the code means. We really appreciate that rather than the usual copy/paste/thank you/bye situations.

    However, I still say you should learn Java first as it would make life easier and make the learning process faster in the long-run.
  5. Offline


    The_Doctor_123 I want to know to, not just him. Actually, I think lots of us want to so we get a clear understanding of what it is, that way, we can use it in the future. :D
    Niknea likes this.
  6. Offline


    I know the basics of Java, such as boolean, return, if, else, variables, else if ladders, and a bit more. However I'm not that familiar with the Bukkit API and I'm trying to learn that, if you think I should learn more what would you recommend me to learn, as I think I've learned a good amount for only coding plugins. However I will be glad to learn more, just recommend what I should learn and I will for sure.
  7. Offline


    Hmmm, it's kind of hard to find things out there that actually teach the Bukkit API. Exactly what I'm doing right now is Private Messaging (PM) someone to actually help me understand and learn some of the API (saves you from getting yelled at (not saying that's bad, but still :p)).
  8. Offline


    I guess I'm just looking at the face of the situation and jumping to conclusions. And usually I'm right. It's pretty vital to be able to read stack traces and to identify the problem. With that given information, I just suppose you don't know Java.

    I've never seen anybody include the words "don't give me code, I want to learn" in their topics, nor ask for line-by-line verifications.
  9. Offline


    Ya my apologies I am sounding a bit nooby, and should talk with more reasoning to prove I'm not nooby, however I insure you I know Java ;)
  10. Offline


  11. Offline


    The_Doctor_123 I'm sure he does know Java :p. The other post: I thought you meant giving the learning developer all the answers instead of them figuring it out on their own with the example provided. Heh, my mistake.

    Developing Appljuze programming is a great one too but I've already explained it to Niknea so nvm that:)

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


    I don't like that person's tutorials. He has tutorials and states that he "teaches Java and Bukkit at the same time." Sadly, that results in failed developers.
  13. Offline


    The_Doctor_123 you simply can't teach both at the same time. Teaching an api without proper knowledge fails
    The_Doctor_123 likes this.
  14. Offline


    The_Doctor_123 I'm not going to listen to his tutorials until I'm done read Head First Java, but I'm just going to aim for the things I'll have trouble with or didn't just cover. I know he doesn't teach both at the same time, it's pretty obvious.:p
    The_Doctor_123 likes this.
  15. Offline


    Alright just really really quick, I revised my code however it still dosen't work, can you please very quickly check it and try to find the problem and tell me? Thanks you so much.
    1. package me.niknea.luckyitems;
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.player.PlayerJoinEvent;
    7. import org.bukkit.inventory.Inventory;
    8. import org.bukkit.inventory.ItemStack;
    9. import;
    11. public class Luckyitems extends JavaPlugin
    12. {
    13. public void loginInventoryCheck(PlayerJoinEvent event) {
    14. Player player = event.getPlayer();
    15. Inventory inv = player.getInventory();
    16. ItemStack itemstack = new ItemStack (Material.STONE, 7);
    18. if(inv.contains(itemstack)){
    19. player.sendMessage(ChatColor.GOLD + "Wohoo, Stone!");
    20. }
    21. else {
    22. player.sendMessage(ChatColor.RED + "Aww, no stone!");
    23. }
    24. }
    27. }
  16. Offline


    Bump, anyone know the reason my code isn't working?
  17. Offline


    Yes, multiple problems:
    1. Your class doesn't implement Listener.
    2. You don't register events to that class.
    3. You don't have the EventHandler annotation above the loginInventoryCheck() method.
  18. Offline


    Still doesn't work
    1. package me.niknea.luckyitems;
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerJoinEvent;
    9. import org.bukkit.inventory.Inventory;
    10. import org.bukkit.inventory.ItemStack;
    11. import;
    13. public class Luckyitems extends JavaPlugin implements Listener
    14. {
    15. @EventHandler
    16. public void loginInventoryCheck(PlayerJoinEvent event) {
    17. Player player = event.getPlayer();
    18. Inventory inv = player.getInventory();
    19. ItemStack itemstack = new ItemStack (Material.STONE, 7);
    21. if(inv.contains(itemstack)){
    22. player.sendMessage(ChatColor.GOLD + "Wohoo, Stone!");
    23. }
    24. else {
    25. player.sendMessage(ChatColor.RED + "Aww, no stone!");
    26. }
    27. }
    30. }
  19. Offline


    You didn't take care of #2.
  20. Offline


    Usally people put it on the method onEnable and onDisable. So would I have to make both of those two?
  21. Offline

    Deleted user


    Read up on the Bukkit plugin tutorial.

    You need an onEnable class, where you would register the listener.

    Show Spoiler

    getServer().getPluginManager().registerEvents(this, this);

    Ahh ninjaed.

    Yeah. That's what you need
  22. Offline


    Err.. I don't see any reason to register events when the plugin is disabling..
  23. Offline


    Fixed it thank you so much! Also I am coding a plugin and I cant figure out how to do this , I've searched the wiki, and it makes me quite mad as it seems like a very simple thing to fix. Anyways I want it went you right click a stick it will update your gamemode and do a few other stuff. All of it worked except for the gamemode. Here is the code.
    1. @EventHandler(priority=EventPriority.HIGH)
    2. public void onPlayerUse(PlayerInteractEvent event)
    3. {
    4. Player player = event.getPlayer();
    6. if(event.getAction().equals(Action.RIGHT_CLICK_AIR))
    7. {
    8. if(player.getItemInHand().getType() == Material.STICK)
    9. {
    10. player.sendMessage(ChatColor.GOLD + "Your gamemode has been updated!");
    11. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "gamemode 1 " + (player));

    Console message when I right click the item
    INFO]: Can't find player CraftPlayer{name=Niknea}

    Thanks so much once again,
  24. Offline


    Niknea instead of Bukkit.dispatchCommand use
    Also if you wanted to use
    1. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "gamemode 1 " + (player));

    It should be

    1. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "gamemode 1 " + player.getName());
    3. // I believe
    Niknea likes this.
  25. Offline


    A Player is not a String...
  26. Concatenation of an object and a string results in

    1. Object object=new Object;
    2. String str="test";
    3. String result=str+object;
    4. //is the same as
    5. String result2=str+object.toString();

    Concatenating objects with strings works in some places :) (but obviously not this one)
  27. Offline


    You're most likely to receive the default .toString() implementation from Object, which is ClassName@hashcodeOfObject, unless the object itself overrides that method.
  28. yes, so it does work in some conditions, but not this one.
  29. Offline


    Also, the player only gets gamemode when they right click air, how can I make it they would get gamemode if they right click anywhere? Also do you mind sending me the link or code on how to make a custom lore and name? Thank you so much!
  30. Offline


    Niknea You would need to something like:
    2. if(event.getPlayer().getItemInHand().getType() == Material.STICK) {
    3. if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4. // Code
    5. }
    6. }

    EDIT: Y U NO Syntax=java?
Thread Status:
Not open for further replies.

Share This Page