Solved PlayerName.yml Getting

Discussion in 'Plugin Development' started by BurnerDiamond, Jan 28, 2015.

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

    Experminator

    @TGRHavoc Or use Player#getDisplayName() or Player#getUniqueId()
     
  2. Offline

    TGRHavoc

    Considering OP said:
    One would assume he's asking for the player's name and not their display name or UUID.

    What do you mean "main file"? Do you mean your "config.yml" file?
     
  3. Offline

    BurnerDiamond

    @TGRHavoc

    I'm sorry I meant.

    This Event is in a seperate event class.

    Do I have to do anything in the main class.

    Except registering the event?
     
  4. Offline

    TGRHavoc

    Briefly looking at your original code, no, you should only need to register the event.
     
  5. Offline

    Experminator

    @TGRHavoc You are not fully right at my previous post, he want a Player Name, but a DisplayName is also a player name :)
     
  6. Offline

    TGRHavoc

    Not exactly, display name is a "friendly" version of the player name which may include colours. I also believe that this display name can be changed whereas "name" cannot.


    @BurnerDiamond
    Is your problem solved?
     
  7. Offline

    Experminator

    @TGRHavoc But it's a NAME. Why others called DisplayNAME?
    And actually a playername can also change. But it is a enough difficulty.

    - You must use Mojang documentation.
     
  8. Offline

    BurnerDiamond

    @TGRHavoc

    Testing.

    What if I wanted to set an. Integer I the config from a seperate class?
     
  9. Offline

    Experminator

    @BurnerDiamond Call the config file in that class and do <configfile>.set(<path to object>, <integer value>)
     
  10. Offline

    BurnerDiamond

    Wanted to make sure it was the same. Thanks.
     
  11. Offline

    Experminator

    @CodePlaysMinecraft @BurnerDiamond He is actually right. You must learn Java.
    You can read/watch some tutorials/introductions/information about Java at:
    Oracle.
    Youtube (I prefer channel: PogoStick29Dev).
     
  12. Offline

    TGRHavoc

    True, player names can now change so @BurnerDiamond should be using the players' UUID (Player#getUniqueId() ) however, previously they couldn't and only the display name could.

    @BurnerDiamond
    Get the file again and do "config.set( "INTEGER", 20)"
     
  13. Offline

    BurnerDiamond

    Nope gives me an error?

    [22:34:00 ERROR]: Could not pass event PlayerLoginEvent to KitPVP v1.0

    org.bukkit.event.EventException

    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    at net.minecraft.server.v1_7_R4.PlayerList.attemptLogin(PlayerList.java:386) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    at net.minecraft.server.v1_7_R4.LoginListener.c(LoginListener.java:68) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    at net.minecraft.server.v1_7_R4.LoginListener.a(LoginListener.java:42) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:160) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:258) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    Caused by: java.lang.NullPointerException

    at me.bd.events.ConfigLoginEvent.onLogin(ConfigLoginEvent.java:24) ~[?:?]

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.6.0_65]

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[?:1.6.0_65]

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]

    at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]

    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]

    ... 13 more

    [22:34:01 INFO]: BurnerDiamond[/25.165.244.169:58592] logged in with entity id 372 at ([world] -70.9997847341832, 70.0, 364.39885246655405)
     
  14. Offline

    Experminator

    @TGRHavoc Actually it's always be able to change a player name using code. You must interact with Mojang for it.

    @BurnerDiamond NullPointerException at line 24. What is the code of line 24?

    EDIT by Timtower: merged posts
     
  15. Offline

    BurnerDiamond

    Code:
    package me.bd.events;
    
    import java.io.File;
    import java.io.IOException;
    
    import me.bd.kitpvp.Main;
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    
    public class ConfigLoginEvent implements Listener {
       
        FileConfiguration config;
        File cFile;
        @EventHandler
        public void onLogin(PlayerLoginEvent e){
            if(cFile == null){
                cFile = new File(Main.getPlugin().getDataFolder(), e.getPlayer().getUniqueId() + ".yml");
            }
          config.set("UUID", e.getPlayer().getUniqueId());
          config.set("Player", e.getPlayer().getName());
           try {
            config.save(cFile);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
       }
    }
    
    My bad I forgot to make it code @Experminator
     
  16. Offline

    Experminator

    Copy the line: 24...

    And actually set PlayerName to "Player" would not work. Then change every time a player logins, the "Player".

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  17. Offline

    BurnerDiamond

    @Experminator

    What is the problem?

    This is line 24.

    config.set("UUID", e.getPlayer().getUniqueId());
     
  18. Offline

    TGRHavoc

    Don't listen to him :p

    "config" is null. Do "config = YamlConfiguration.loadConfiguration(cFile)"
     
  19. Offline

    BurnerDiamond

    Code:
    [USER=90939044]@TGRHavoc[/USER]
    
    I get this problem now
    
    [22:52:51 ERROR]: Error occurred while enabling KitPVP v1.0 (Is it up to date?)
    
    java.lang.IllegalArgumentException: File cannot be null
    
    at org.apache.commons.lang.Validate.notNull(Validate.java:203) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:175) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at me.bd.events.ConfigLoginEvent.<init>(ConfigLoginEvent.java:17) ~[?:?]
    
    at me.bd.kitpvp.Main.onEnable(Main.java:24) ~[?:?]
    
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:455) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:389) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at org.bukkit.craftbukkit.v1_7_R4.CraftServer.reload(CraftServer.java:839) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at org.bukkit.Bukkit.reload(Bukkit.java:303) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:740) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchServerCommand(CraftServer.java:726) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at net.minecraft.server.v1_7_R4.DedicatedServer.aB(DedicatedServer.java:294) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:259) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    @TGRHavoc

    This is the Main:

    Code:
    package me.bd.kitpvp;
    
    import me.bd.events.ConfigLoginEvent;
    import me.bd.events.LoginEvent;
    import me.bd.events.RespawnEvent;
    import me.bd.kits.Menu;
    import me.bd.tank.Smash;
    import me.bd.tank.Tank;
    
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
        public static Main plugin;
       
        public void onEnable() {
           
            getServer().getPluginManager().registerEvents(new Menu(), this);
            getServer().getPluginManager().registerEvents(new Tank(), this);
            getServer().getPluginManager().registerEvents(new LoginEvent(), this);
            getServer().getPluginManager().registerEvents(new RespawnEvent(), this);
            getServer().getPluginManager().registerEvents(new Smash(), this);
            getServer().getPluginManager().registerEvents(new ConfigLoginEvent(), this);
           
        }
       
        public void onDisable() {
           
        }
       
        public static Plugin getPlugin() {
            return Bukkit.getPluginManager().getPlugin("KitPVP");
       
        }
    
    }
    
    This is the Other:

    Code:
    package me.bd.events;
    
    import java.io.File;
    import java.io.IOException;
    
    import me.bd.kitpvp.Main;
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    
    public class ConfigLoginEvent implements Listener {
       
        File cFile;
        FileConfiguration config = YamlConfiguration.loadConfiguration(cFile);
        @EventHandler
        public void onLogin(PlayerLoginEvent e){
            if(cFile == null){
                cFile = new File(Main.getPlugin().getDataFolder(), e.getPlayer().getUniqueId() + ".yml");
            }
           
            config.set("UUID", e.getPlayer().getUniqueId());
            config.set("Player", e.getPlayer().getName());
           try {
            config.save(cFile);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
       }
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  20. Offline

    TGRHavoc

    Please use the code/syntax tags for errors as well.
    Also, make sure that the config declaration is below the if statement and above the "config.set"s
     
  21. Offline

    BurnerDiamond

    IT WORKS. I HAVE NO FUCKING IDEA WHY BUT IT WORKS. NOW I'M GOING TO GO BACK TO THE JAVADOCS!
     
  22. Offline

    Experminator

    @BurnerDiamond Good! Please can you report this thread to close this thread?
     
Thread Status:
Not open for further replies.

Share This Page