Nooby Dev

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

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

    Niknea

    The_Doctor_123
    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

    AzubuSan

    Niknea
    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

    Code:java
    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);
    6.  
    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

    Niknea

    AzubuSan
    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?
    Code:java
    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

    The_Doctor_123

    Niknea
    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

    Developerjohn

    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

    Niknea

    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

    Developerjohn

    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

    The_Doctor_123

    Niknea
    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.

    Developerjohn
    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

    Niknea

    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

    Developing

  11. Offline

    Developerjohn

    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

    The_Doctor_123

    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

    Not2EXceL

    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

    Developerjohn

    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

    Niknea

    AzubuSan
    The_Doctor_123
    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.
    Code:java
    1. package me.niknea.luckyitems;
    2.  
    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 org.bukkit.plugin.java.JavaPlugin;
    10.  
    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);
    17.  
    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. }
    25.  
    26.  
    27. }
     
  16. Offline

    Niknea

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

    The_Doctor_123

    Niknea
    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

    Niknea

    Still doesn't work
    Code:java
    1. package me.niknea.luckyitems;
    2.  
    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 org.bukkit.plugin.java.JavaPlugin;
    12.  
    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);
    20.  
    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. }
    28.  
    29.  
    30. }
    31.  
    32.  
    33.  
    34.  
     
  19. Offline

    The_Doctor_123

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

    Niknea

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

    zombiekiller753

    Niknea

    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);


    EDIT:
    Ahh ninjaed.

    Yeah. That's what you need
     
  22. Offline

    The_Doctor_123

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

    Niknea

    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.
    Code:java
    1. @EventHandler(priority=EventPriority.HIGH)
    2. public void onPlayerUse(PlayerInteractEvent event)
    3. {
    4. Player player = event.getPlayer();
    5.  
    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
    Code:
    INFO]: Can't find player CraftPlayer{name=Niknea}

    Thanks so much once again,
    Niknea
     
  24. Offline

    reider45

    Niknea instead of Bukkit.dispatchCommand use
    Code:
    player.setGameMode(GameMode.CREATIVE);
    Also if you wanted to use
    Code:java
    1. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "gamemode 1 " + (player));


    It should be

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

    The_Doctor_123

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

    Code:java
    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

    1Rogue


    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

    Niknea

    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

    AzubuSan

    Niknea You would need to something like:
    Code:java
    1.  
    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