[Help] Lag at login

Discussion in 'Plugin Development' started by DSvend, Oct 20, 2013.

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

    DSvend

    Hello ladies and gentlemen!
    I am fairly new at coding, but I decided to tackle a simple name-plugin as a donator perk on my server, but recently I noticed a lot of lag was occuring at login. I'm not completely sure, but considering I use an onPlayerJoin, and I'm certainly capable of making mistakes, I will assume it is my plugin causing it. This is the code in question:

    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent e){
    3. if(e.getPlayer().getName() != null){
    4. Player player = e.getPlayer();
    5. if(this.getConfig().get(player.getName() + "prefix") != null && this.getConfig().get(player.getName() + "colour") != null && this.getConfig().get(player.getName() + "suffix") != null){
    6. player.setDisplayName("&r" + this.getConfig().getString(player.getName() + "prefix") + this.getConfig().getString(player.getName() + "colour") + player.getName() + "&r" + this.getConfig().getString(player.getName() + "suffix"));
    7. }
    8. //prefix null
    9. else if(this.getConfig().get(player.getName() + "prefix") == null && this.getConfig().get(player.getName() + "colour") != null && this.getConfig().get(player.getName() + "suffix") != null){
    10. player.setDisplayName(this.getConfig().getString(player.getName() + "colour") + player.getName() + "&r" + this.getConfig().getString(player.getName() + "suffix"));
    11. }
    12. //colour is null
    13. else if(this.getConfig().get(player.getName() + "prefix") != null && this.getConfig().get(player.getName() + "colour") == null && this.getConfig().get(player.getName() + "suffix") != null){
    14. player.setDisplayName("&r" + this.getConfig().getString(player.getName() + "prefix") + player.getName() + "&r" + this.getConfig().getString(player.getName() + "suffix"));
    15. }
    16. //suffix is null
    17. else if(this.getConfig().get(player.getName() + "prefix") != null && this.getConfig().get(player.getName() + "colour") != null && this.getConfig().get(player.getName() + "suffix") == null){
    18. player.setDisplayName("&r" + this.getConfig().getString(player.getName() + "prefix") + this.getConfig().getString(player.getName() + "colour") + player.getName());
    19. }
    20. //prefix and colour is null
    21. else if(this.getConfig().get(player.getName() + "prefix") == null && this.getConfig().get(player.getName() + "colour") == null && this.getConfig().get(player.getName() + "suffix") != null){
    22. player.setDisplayName(player.getName() + "&r" + this.getConfig().getString(player.getName() + "suffix"));
    23. }
    24. //prefix and suffix is null
    25. else if(this.getConfig().get(player.getName() + "prefix") == null && this.getConfig().get(player.getName() + "colour") != null && this.getConfig().get(player.getName() + "suffix") == null){
    26. player.setDisplayName(this.getConfig().getString(player.getName() + "colour") + player.getName());
    27. }
    28. //colour and suffix is null
    29. else if(this.getConfig().get(player.getName() + "prefix") != null && this.getConfig().get(player.getName() + "colour") == null && this.getConfig().get(player.getName() + "suffix") == null){
    30. player.setDisplayName("&r" + this.getConfig().getString(player.getName() + "prefix") + player.getName());
    31. }
    32.  
    33. }
    34. }

    Basically, what the plugin does is it gives the people who have the permission the ability to change the colour of their name, and add a few letters before and after. I use this blurb of jambled coding mess to set their display name at login, and what it does is checks to see if the player has a prefix, suffix, or colour, and what to do accordingly.
     
  2. Offline

    rippin

    Try assigning a variable to the string you get from the config so you only have to access the config once.
    String prefix = this.getConfig.getString(player.getName() + "prefix"); Also do it for the suffix and colour.

    Then just replace everywhere that this.getConfig.getString(player.getName() + "prefix") is with prefix. And do it for the other ones to.
     
    DSvend likes this.
Thread Status:
Not open for further replies.

Share This Page