Per Rank Custom Join Messages

Discussion in 'Spigot Plugin Development' started by superzyr, Mar 31, 2015.

  1. Any custom join message plugins that allow for rank specific join messages / permisssions?

    The only difference I need with each rank's join message is the color of their name as they join

    Eg.

    Donator (this rank is &9 Blue)
    Message I need when they join
    - &9Player &fhas joined!
    Permission: joinmessage.announce.Donator

    VIP (this rank is &e Yellow)
    Message I need when they join
    - &ePlayer &fhas joined!
    Permission: joinmessage.announce.vip

    etc.

    Anyone know of any plugin that does this?
     
  2. PlayerJoinEvent
    event.setJoinMessage("string");
     
  3. *Facepalm. She's asking for a plugin that does this, not code.

    Yes I do know she is posting in the wrong section though, @superzyr this section is for coding issues not plugin finding problems.
     
  4. Ah okay


    @superzyr
    I will go ahead and code this for you as I don't really have anything else to do.
     
    • Funny Funny x 1
  5. Code (Text):
    package me.Da_Pepsi_Monster.CustomJoin;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener {

       String Permission_1 = "CustomJoin.Priority1";
       String Permission_2 = "CustomJoin.Priority2";
       String Permission_3 = "CustomJoin.Priority3";
       String Permission_4 = "CustomJoin.Priority4";
       String Permission_5 = "CustomJoin.Priority5";
       String Permission_6 = "CustomJoin.Priority6";
       String Permission_7 = "CustomJoin.Priority7";
       String Permission_8 = "CustomJoin.Priority8";
       String Permission_9 = "CustomJoin.Priority9";
       String Permission_10 = "CustomJoin.Priority10";
       String Permission_11 = "CustomJoin.Priority11";
       String Permission_12 = "CustomJoin.Priority12";
       String Permission_13 = "CustomJoin.Priority13";
       String Permission_14 = "CustomJoin.Priority14";
       String Permission_15 = "CustomJoin.Priority15";
       String Permission_16 = "CustomJoin.Priority16";
       String Permission_17 = "CustomJoin.Priority17";
       String Permission_18 = "CustomJoin.Priority18";
       String Permission_19 = "CustomJoin.Priority19";
       String Permission_20 = "CustomJoin.Priority20";
       String Permission_1_Msg;
       String Permission_2_Msg;
       String Permission_3_Msg;
       String Permission_4_Msg;
       String Permission_5_Msg;
       String Permission_6_Msg;
       String Permission_7_Msg;
       String Permission_8_Msg;
       String Permission_9_Msg;
       String Permission_10_Msg;
       String Permission_11_Msg;
       String Permission_12_Msg;
       String Permission_13_Msg;
       String Permission_14_Msg;
       String Permission_15_Msg;
       String Permission_16_Msg;
       String Permission_17_Msg;
       String Permission_18_Msg;
       String Permission_19_Msg;
       String Permission_20_Msg;

       public void onEnable() {
          Bukkit.getPluginManager().registerEvents(this, this);
          this.saveDefaultConfig();
          this.Permission_1_Msg = this.getConfig().getString("Permission_1_Message");
          this.Permission_2_Msg = this.getConfig().getString("Permission_2_Message");
          this.Permission_3_Msg = this.getConfig().getString("Permission_3_Message");
          this.Permission_4_Msg = this.getConfig().getString("Permission_4_Message");
          this.Permission_5_Msg = this.getConfig().getString("Permission_5_Message");
          this.Permission_6_Msg = this.getConfig().getString("Permission_6_Message");
          this.Permission_7_Msg = this.getConfig().getString("Permission_7_Message");
          this.Permission_8_Msg = this.getConfig().getString("Permission_8_Message");
          this.Permission_9_Msg = this.getConfig().getString("Permission_9_Message");
          this.Permission_10_Msg = this.getConfig().getString("Permission_10_Message");
          this.Permission_11_Msg = this.getConfig().getString("Permission_11_Message");
          this.Permission_12_Msg = this.getConfig().getString("Permission_12_Message");
          this.Permission_13_Msg = this.getConfig().getString("Permission_13_Message");
          this.Permission_14_Msg = this.getConfig().getString("Permission_14_Message");
          this.Permission_15_Msg = this.getConfig().getString("Permission_15_Message");
          this.Permission_16_Msg = this.getConfig().getString("Permission_16_Message");
          this.Permission_17_Msg = this.getConfig().getString("Permission_17_Message");
          this.Permission_18_Msg = this.getConfig().getString("Permission_18_Message");
          this.Permission_19_Msg = this.getConfig().getString("Permission_19_Message");
          this.Permission_20_Msg = this.getConfig().getString("Permission_20_Message");
       }

       @EventHandler
       public void onPlayerJoin(PlayerJoinEvent event) {
          Player player = event.getPlayer();
          if(player.hasPermission(this.Permission_1)) {
             event.setJoinMessage(this.Permission_1_Msg);
          } else if(player.hasPermission(this.Permission_2)) {
             event.setJoinMessage(this.Permission_2_Msg);
          } else if(player.hasPermission(this.Permission_3)) {
             event.setJoinMessage(this.Permission_3_Msg);
          } else if(player.hasPermission(this.Permission_4)) {
             event.setJoinMessage(this.Permission_4_Msg);
          } else if(player.hasPermission(this.Permission_5)) {
             event.setJoinMessage(this.Permission_5_Msg);
          } else if(player.hasPermission(this.Permission_6)) {
             event.setJoinMessage(this.Permission_6_Msg);
          } else if(player.hasPermission(this.Permission_7)) {
             event.setJoinMessage(this.Permission_7_Msg);
          } else if(player.hasPermission(this.Permission_8)) {
             event.setJoinMessage(this.Permission_8_Msg);
          } else if(player.hasPermission(this.Permission_9)) {
             event.setJoinMessage(this.Permission_9_Msg);
          } else if(player.hasPermission(this.Permission_10)) {
             event.setJoinMessage(this.Permission_10_Msg);
          } else if(player.hasPermission(this.Permission_11)) {
             event.setJoinMessage(this.Permission_11_Msg);
          } else if(player.hasPermission(this.Permission_12)) {
             event.setJoinMessage(this.Permission_12_Msg);
          } else if(player.hasPermission(this.Permission_13)) {
             event.setJoinMessage(this.Permission_13_Msg);
          } else if(player.hasPermission(this.Permission_14)) {
             event.setJoinMessage(this.Permission_14_Msg);
          } else if(player.hasPermission(this.Permission_15)) {
             event.setJoinMessage(this.Permission_15_Msg);
          } else if(player.hasPermission(this.Permission_16)) {
             event.setJoinMessage(this.Permission_16_Msg);
          } else if(player.hasPermission(this.Permission_17)) {
             event.setJoinMessage(this.Permission_17_Msg);
          } else if(player.hasPermission(this.Permission_18)) {
             event.setJoinMessage(this.Permission_18_Msg);
          } else if(player.hasPermission(this.Permission_19)) {
             event.setJoinMessage(this.Permission_19_Msg);
          } else if(player.hasPermission(this.Permission_20)) {
             event.setJoinMessage(this.Permission_20_Msg);
          } else {
             event.setJoinMessage((String)null);
          }

       }
    }
     

    Wow... Hashmap? o_O

    Things wrong:
    • Bad variable naming. (Against convention)
    • Bad package naming. (Against convention)
    • Messy code. (Against convention)
    • Poorly made. (Fact).
    Improvements:
    • Have a hash map storing the <Integer, String>. For the number, Message, then load them from the config. After you can get the config for my.permission.[INTEGER]
      • Gets rid of the variables.
      • Gets rid of that long messy if block.
      • Generally a better way to go.. Allows more messages/permissions.
    • Follow convention. It's there for a reason!
     
    • Agree Agree x 2
  6. This was made in 5 minutes. I really didn't want to spend more time on it, so I made it like this :p

    So if you want to make it follow good coding practice, then go ahead :)
     
    • Optimistic Optimistic x 1
  7. @ZyphiorMC Having an "I made it in 5 minutes so I don't give a shit about coding practice/you go do it better if you want" attitude about coding and/or giving content for other people is really unnecessary, either take your time to provide good content or don't provide at all.

    Your code could easily be shortened to a few lines, and "bad coding practice/no time" can't really be blamed as using a simple for loop is very basic Java knowledge.

    Code (Java):
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();

        for (int i = 1 ; i <= 20 ; i++) {
            if (player.hasPermission("CustomJoin.Priority" + i)) {
                player.sendMessage(getConfig().getString("Permission_" + i + "_Message"));
                break;
            }
        }
    }
     
    • Like Like x 1
  8. #9 _Cory_, Mar 31, 2015
    Last edited: Mar 31, 2015
    • Winner Winner x 1
  9. Sorry, only felt like spending 5. [​IMG]


    Happy?
    https://www.dropbox.com/s/1yk3yrmv9yt4ncx/CustomJoin v1.0.jar?dl=1
     
    • Like Like x 1
    • Optimistic Optimistic x 1
  10. LOL. Yep. Still against convention.

    What's this pointless thing for?
    Code (Text):
    for(int i = 1; i < 51; ++i) {
             this.getConfig().contains("Permission_" + i + "_Message");
          }

    http://www.spigotmc.org/resources/joinchanger.5453/
     
    • Like Like x 1
  11. Omnivion

    Patron

    This was actually pretty fun to make, but seeing as @_Cory_ did exactly what I did (minus class formatting, I don't like to have my listeners/configurationUtils in the same class as my main), not going to bother releasing it.

    @ZyphiorMC, advice to you; spend a little more time learning Java before creating plugins for live servers to use. If nothing else but to protect your rep.
     
    • Agree Agree x 1
  12. I already know Java, I was just too lazy to do it the other way. :)

    If you don't like my plugin, nothing is stopping you from not using it. :)
     
    #14 ZyphiorMC, Mar 31, 2015
    Last edited: Mar 31, 2015
    • Agree Agree x 1
    • Optimistic Optimistic x 1
  13. Can You Please Add A Playername Placeholder For This Plugin Please? I'd be very happy if you can help <3
    ~~sorry that I dont know anything about java coding~~
    THANK YOU <3 I love you guys
     
    • Funny Funny x 1
  14. TheJavaHacker

    Supporter

    https://www.spigotmc.org/resources/joinchanger.5453/ Already has player name placeholders in it.