Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PlayerJoin implements Listener {
- private GradientNick plugin;
- public PlayerJoin(GradientNick plugin) {
- this.plugin = plugin;
- }
- @EventHandler
- public void onJoin(PlayerJoinEvent e) {
- Player p = e.getPlayer();
- String UUID = p.getUniqueId().toString();
- File playersFile = new File(plugin.getDataFolder(), "players.yml");
- if (!playersFile.exists()) {
- try {
- playersFile.createNewFile();
- } catch (IOException exception) {
- exception.printStackTrace();
- }
- }
- YamlConfiguration playersConfig = YamlConfiguration.loadConfiguration(playersFile);
- if (!(p.hasPlayedBefore())) {
- playersConfig.set(UUID + ".firstnickname", p.getDisplayName());
- playersConfig.set(UUID + ".gnickname", p.getDisplayName());
- try {
- playersConfig.save(playersFile);
- } catch (IOException exception) {
- exception.printStackTrace();
- }
- return;
- } else {
- p.setDisplayName(playersConfig.getString(UUID + ".gnickname"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment