Java Mistake - Ranks

Discussion in 'Plugin Development' started by Jamscott, Jul 26, 2014.

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

    Jamscott

    I have started to code bukkit plugins for about 2 weeks now but I skiped learning Java witch I learned was the biggest mistake I could ever do .I have got so far knowing very little about java but i have got to that point where I need to learn it could someone tell me a good way to learn it but first could you fix my problem and tell me what I need to do.

    I have created a system were it creates teams for ranks but I placed this code in a class called Ranks and i try to access this in my onJoin event how do i do this

    Then could you maybe tell me a good place to learn Java

    Ranks Class
    Code:java
    1. public class Ranks {
    2.  
    3. public void enableRanks() {
    4. ScoreboardManager manager = Bukkit.getScoreboardManager();
    5. Scoreboard main = manager.getMainScoreboard();
    6.  
    7. Team owner = main.getTeam("owner");
    8. if (owner == null) {
    9. owner = main.registerNewTeam("owner");
    10. }
    11. owner.setCanSeeFriendlyInvisibles(true);
    12. owner.setPrefix("§c");
    13. owner.setSuffix("§e");
    14. owner.setAllowFriendlyFire(true);
    15. owner.setCanSeeFriendlyInvisibles(true);
    16. owner.setDisplayName("Owner");
    17.  
    18. Team Default = main.getTeam("Default");
    19. if (Default == null) {
    20. Default = main.registerNewTeam("Default");
    21. }
    22. Default.setCanSeeFriendlyInvisibles(true);
    23. Default.setPrefix("§2");
    24. Default.setAllowFriendlyFire(true);
    25. Default.setCanSeeFriendlyInvisibles(false);
    26. Default.setDisplayName("Default");
    27.  
    28. Team Ultra = main.getTeam("Ultra");
    29. if (Ultra == null) {
    30. Ultra = main.registerNewTeam("Ultra");
    31. }
    32. Ultra.setCanSeeFriendlyInvisibles(true);
    33. Ultra.setPrefix("§b");
    34. Ultra.setAllowFriendlyFire(true);
    35. Ultra.setCanSeeFriendlyInvisibles(false);
    36. Ultra.setDisplayName("Ultra");
    37.  
    38. Team Hero = main.getTeam("Hero");
    39. if (Hero == null) {
    40. Hero = main.registerNewTeam("Hero");
    41. }
    42. Hero.setCanSeeFriendlyInvisibles(true);
    43. Hero.setPrefix("§d");
    44. Hero.setAllowFriendlyFire(true);
    45. Hero.setCanSeeFriendlyInvisibles(false);
    46. Hero.setDisplayName("Hero");
    47. }
    48.  
    49. }
    50.  


    OnJoin
    Code:java
    1. public class PlayerJoin implements Listener {
    2. @EventHandler
    3. public void onJoin(PlayerJoinEvent e) {
    4.  
    5. Player p = e.getPlayer();
    6. if (main.getPlayerTeam(p) == null) {
    7. Default.addPlayer(p);
    8. }
    9. if (plugin.joinMessage == true) {
    10. if (!main.getPlayerTeam(p) == Default) {
    11. e.setJoinMessage(p.getDisplayName() + "Joined.");
    12. }else{
    13. e.setJoinMessage(null);
    14. }
    15. }
    16. }
    17. }
    18.  
     
  2. Offline

    Dubehh

    thenewboston makes good tutorials :)
     
  3. Offline

    Niknea

    Jamscott YouTube videos are personally a terrible place to learn any programming language, as you can easily not get something, as most videos faintly explain certain topics. That's why I highly recommend books, Java for Dummies, Java a Beginners Guide, or both great books, and is the two books I read to build my knowledge of Java.

    Now for your question, you would need to get an instance of your Ranks class, to be able to use the methods contained in the Ranks class in your OnJoin class, once you do that, you can easily access the method with the following code:

    PHP:
    instance.enableRanks();
     
    AoH_Ruthless and Dragonphase like this.
  4. Offline

    Excalibur


    Head First Java taught me everything I need to know for Bukkit. I have skimmed both those books and they are not nearly as good in my opinion. This is the best advice I can give aswell though, please do not learn Java from videos. Every single person has their own set of bad habits and believe me you do not want to pick up on them.
     
    Niknea likes this.
  5. Offline

    k9rosie

    i personally learned java by making bukkit plugins, and tinkering with other people's source code. learn the fundamentals of object oriented programming because that's pretty much what java is. after you start understanding how OOP works you can begin learning the basic java apis.
     
  6. Offline

    Niknea

    k9rosie Personally, I think thats a terrible way to learn Java, using an API to learn a programming language.
     
  7. Offline

    xTigerRebornx

    Niknea likes this.
Thread Status:
Not open for further replies.

Share This Page