Guest User

Untitled

a guest
Jun 21st, 2023
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. public class PlayerJoin implements Listener {
  2.  
  3. private GradientNick plugin;
  4.  
  5. public PlayerJoin(GradientNick plugin) {
  6. this.plugin = plugin;
  7. }
  8.  
  9. @EventHandler
  10. public void onJoin(PlayerJoinEvent e) {
  11. Player p = e.getPlayer();
  12. String UUID = p.getUniqueId().toString();
  13. File playersFile = new File(plugin.getDataFolder(), "players.yml");
  14.  
  15. if (!playersFile.exists()) {
  16. try {
  17. playersFile.createNewFile();
  18. } catch (IOException exception) {
  19. exception.printStackTrace();
  20. }
  21. }
  22.  
  23. YamlConfiguration playersConfig = YamlConfiguration.loadConfiguration(playersFile);
  24.  
  25. if (!(p.hasPlayedBefore())) {
  26. playersConfig.set(UUID + ".firstnickname", p.getDisplayName());
  27. playersConfig.set(UUID + ".gnickname", p.getDisplayName());
  28. try {
  29. playersConfig.save(playersFile);
  30. } catch (IOException exception) {
  31. exception.printStackTrace();
  32. }
  33. return;
  34. } else {
  35. p.setDisplayName(playersConfig.getString(UUID + ".gnickname"));
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment