Solved Join message plugin wont work.

Discussion in 'Plugin Development' started by Pyr0Seeker, Jan 21, 2015.

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

    Pyr0Seeker

    HI,
    I am fairly new to java, and bukkit plugin development, but i'm trying to be able to write as many of the plugins for my server as possible. Right now i'm working on a plugin that announces when a player joins the server, player join message, that has a different color for the player's name based on what permission that player has/pex group. I finally got everything to compile and run, [TAB] in the .yml is evil, but when i log on to my test server, the join message dosen't change. Any guidance would be appreciated!

    Class file:
    Code:
    package com.Pyr0Seeker.JoinNotifier;
    
    import java.util.logging.Logger;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class JoinNotifier extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
      
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "has been disabled!");
        }
      
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " has been enabled!");
        }
      
         @EventHandler
       public void onPlayerJoin(PlayerJoinEvent event) {
         Player player = event.getPlayer();
       
         if(player.hasPermission("JoinNotifier.owner")){
            event.setJoinMessage(ChatColor.DARK_PURPLE + "" + player + ChatColor.YELLOW + " has joined the server");
          
         }else  if(player.hasPermission("JoinNotifier.tech")){
                event.setJoinMessage(ChatColor.DARK_BLUE + "" + player + ChatColor.YELLOW + " has joined the server");
              
         }else if(player.hasPermission("JoinNotifier.mod")){
                event.setJoinMessage(ChatColor.DARK_GREEN + "" + player + ChatColor.YELLOW + " has joined the server");
              
         }else if(player.hasPermission("JoinNotifier.builder")){
                event.setJoinMessage(ChatColor.GOLD + "" + player + ChatColor.YELLOW + " has joined the server");
                  
         }else{
             event.setJoinMessage(ChatColor.YELLOW + "" + player + " has joined the server");
         }
         }
       
    
    }
    
    and the plugin.yml:
    Code:
    name: JoinNotifier
    main: com.Pyr0Seeker.JoinNotifier.JoinNotifier
    description: Notifies the world when a player joins!
    version: 1.4
    author: Pyr0Seeker
    
    permission:
      JoinNotifier.owner:
        description: Identifies players in the owner group to set their join color.
        default: false
      JoinNotifier.tech:
        description: Identifies players in the Techspert group to set their join color.
        default: false
      JoinNotifier.mod:
        description: Identifies players in the mod group to set their join color.
        default: false
      JoinNotifier.builder:
        description: Identifies players in the builder group to set their join color.
        default: false

    edit: to be clear. the console loads up the plugin just fine, and it will show up in the /plugins command. but the changes the plugins is supposed to make don't take effect
     
  2. Offline

    CraftCreeper6

    GrandmaJam likes this.
  3. Offline

    Pyr0Seeker

  4. Offline

    CraftCreeper6

    @Pyr0Seeker
    You can easily do that by doing:
    Bukkit.getServer().getPluginManager().registerEvents(mainClass, classToRegister);

    Also, I forgot to mention, your Main class must extend JavaPlugin and implement Listener if you want an event in your Main class.
     
  5. Offline

    Pyr0Seeker

  6. Offline

    CraftCreeper6

    @Pyr0Seeker
    You can, or you can just use your Main class. It's neater to use another class.
     
    GrandmaJam likes this.
  7. Offline

    GrandmaJam

    Code:
    @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " has been enabled!");
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
     
  8. Offline

    Pyr0Seeker

    Thank you both @GrandmaJam , @CraftCreeper6

    now its working , but its being funny.
    in every case, ie. with each permission, i get the same weird join message

    2015-01-21_21.11.38.png


    Any ideas?

    my code is the same as before with the exception that my onEnable() reflects @GrandmaJam 's example
     
  9. Offline

    1Rogue

    You're printing the player object, not their name.
     
  10. Offline

    Pyr0Seeker

    so then would it be (ChatColor.DARK_PURPLE + "" + player.getDisplayName() etc.) ?

    Thank you @1Rogue , i think i'm down to the last kink. i changed every instance where a setJoinMessage() calls player to player.getDisplayName(). Now my issue is that no matter what perm i use, my display name always comes back purple. Each perm should have a different display name color.

    Also: i'm sorry if i seem like i'm trying to get you all to write my plugin for me, but i honestly want to learn this stuff and i feel like im just plain stuck!

    Update: i changed all player.getDisplayName() 's to player.getName(). not entirely sure what the difference is but i figured i'd mention it. i still have the same static color problem

    I feel like my Permission are messed up, but i don't know how

    I did a little looking on the difference, and if getDisplayName is changeable and getName is not then does that mean that getDisplayName is supposed to handle when people change their names, or will getName do that and getDisplayName is for if a plugin changes the players display name? Trying really hard to understand
     
    Last edited: Jan 21, 2015
  11. Offline

    Pyr0Seeker

  12. Offline

    Skionz

    @Pyr0Seeker Your probably an operator. If you have the owner permission it has a higher priority I guess you would say then the others due to your if-else statements.
     
  13. Offline

    Pyr0Seeker

    @Skionz I've been testing the permissions individually. When i test a permission, i remove the previous one. I considered conflicting permissions, and im using pex for perms since the actual owner of my server prefers pex, and i make sure that when i test a permission it's the only permission my character has.
     
  14. Offline

    sirrus86

    You've got it. Using getName() will give you the player's actual name, not a custom name given by a plugin or other means.
     
  15. Offline

    Pyr0Seeker

    @sirrus86 thank you for the clarification. So does that mean bukkit/spigot api has support for name changing?

    @sirrus86
    also it seems like it would be better in this case to use getDisplayName to already have support for any nickname plugins that our server may or may not run in the future. Kind of a preemptive measure so to speak

    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>
     
    Last edited by a moderator: Jan 23, 2015
  16. Offline

    Pyr0Seeker

  17. Offline

    the133448

    To change a players name, you can do PlayerObject.setPlayerListName(String name)

    Is your problem fixed? or is their still a problem.
    Just looking through your code, after each if statment just return out, so that if you gave the owner * with pex, it wouldt fall through all your logic.

    And just finally...

    DONT LEARN OF THEBCBROZ...

    Judging by your previous replies it sounds you have no idea what your doing except for rewriting what he did in the video.
     
  18. Offline

    CantBeCharged

  19. Offline

    WinX64

    That depends on what you mean by name changing.

    getName returns the player name, the plain name, without colors or anything, it cannot be changed via bukkit api. This used to the player's unique identifier prior to the mojang name change implementation.

    getDisplayName returns the name used in certain commands and server chat. You can change this one the way you want with setDisplayName. You can add colors, symbols and even change the name itself. It will have no effect over getName.

    getPlayerListName will return the name of the player on the player list when you press TAB. You can also change this one with setPlayerListName, but with some restrictions. The name cannot have over than 16 characters and must be unique, meaning that there can't be 2 equals names there.
     
  20. Offline

    KrypticIce

    Or you can do Bukkit.getServer().getPluginManager().registerEvents(this, this); if you only want one file.
     
  21. Offline

    SuperOriginal

    You should also take a look at this
     
  22. Offline

    Pyr0Seeker

    @the133448
    well i have watched some of those videos, but most of the code for this plugin i wrote myself. Of course by wrote myself, i mean i found instructions here and there online to help with certain tasks, but over all it's been my brain child.

    I just got what @Skionz was saying, i deop'd my test character and my perms began to work. i think i've got it all together now. so basically as long as a person dosn't have OP then my plugin should work fine. So does this mean the OP automatically gives that player all permissions? In which case is there any way for my plug-in to work as intended for an OP?


    @WinX64
    so what you're saying is, bukkit can get a player's actual name, and now uuid's, but it can also mask those names with another name and get those masks yes?


    @SuperOriginal
    Thank you, that actually helped alot, i guess i need to spend some time getting more familiar with java then as well as work out a few kinks in my code to make it more elegant.

    Thank everyone for all the amazing help, i've already learned alot and i appreciate the support!
     
  23. Offline

    SuperOriginal

    @Pyr0Seeker Yes, OP automatically gives players all permissions. You can check if a player is op by using the isOP() method and have your plugin respond accordingly.
     
  24. Offline

    the133448

    @Pyr0Seeker Well you dont need to use PluginDescriptionFile, or the way you got Logger...
    Its all jus practises that thebcbroz teaches you....
     
  25. Offline

    Pyr0Seeker

    @the133448
    yeah, i did copy that over, mostly because i'm trying to understand really what the onEnable/ onDisable are for. i saw a mention of how superfluous that whole bit was in the thread that @SuperOriginal linked. i've removed that from my code. i also redid my package name to match the java naming conventions... which is to say i made it all lowercase. I'm also gonna go ahead and mark this solved!

    @SuperOriginal Is there a way to give two different OP's two different permissions?
     
    Last edited: Jan 25, 2015
  26. Offline

    SuperOriginal

    @Pyr0Seeker No, the point of an OP is to have ALL permissions.

    You would have to deop them and make ranks for them in your permissions.
     
  27. Offline

    Pyr0Seeker

    @SuperOriginal ok, thats what I was gonna do, I was just curious if there was another way. Thanks again for all the help and the candid criticism. It's much appreciated!
     
Thread Status:
Not open for further replies.

Share This Page