Create config on player join event

Discussion in 'Plugin Development' started by Mortem420, Sep 27, 2019.

  1. Offline

    Mortem420

    I just started getting into Bukkit coding about a week or so ago and right now I'm just playing with code to get a better understanding of it before I decide to try and code anything serious

    I'd like some help with creating a class related to player join events that will create a "UUID".yml file for playerdata

    Code for player join event class:

    Code:java
    1. import org.bukkit.ChatColor;
    2. import org.bukkit.entity.Player;
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.player.PlayerJoinEvent;
    6.  
    7. import me.Mortem420.PracticePlugin.configManager;
    8. import me.Mortem420.PracticePlugin.myConfig;
    9.  
    10. public class PlayerJoin_Event implements Listener
    11.  
    12. {
    13.  
    14. public configManager manager;
    15.  
    16. public myConfig playerDataTwo;
    17.  
    18. @EventHandler
    19. public void onJoin(PlayerJoinEvent joinEvent)
    20. {
    21. Player thePlayer = joinEvent.getPlayer();
    22. joinEvent.setJoinMessage(ChatColor.GOLD + "Hello " + thePlayer.getName() + ". Welcome to: " + thePlayer.getWorld().getName() + ". It is " + thePlayer.getWorld().getTime());
    23.  
    24. // String playerUUID = thePlayer.getUniqueId().toString();
    25. // if(!playerDataTwo.contains(playerUUID));
    26. // {
    27. // playerDataTwo = manager.getNewConfig("playerData/" + thePlayer.getName() + ".yml", new String[] {thePlayer.getName(), "This is the playerData file", "UUID: " + playerUUID});
    28.  
    29.  
    30. // playerDataTwo.set("Homes." + thePlayer.getName(), thePlayer.getLocation());
    31. // playerDataTwo.saveConfig();
    32. // }
    33. }
    34. }
    35.  


    The lines that are commented out should be atleast close to checking for and making the .yml file, I just don't fully know where or how to properly use it. I know for sure that the event is registered properly because I get the message when I join the server

    Any help would be much appreciated as I've really been enjoying learning Java and hope to be able to code my own plugins
     
    Last edited by a moderator: Sep 27, 2019
  2. Offline

    timtower Moderator Moderator

    @Mortem420 1. Please use a constructor for manager and playerDataTwo.
    2. playerDataTwo can be a local variable by the looks of it.
    3. What is wrong with the commented lines then?
     
  3. Offline

    Mortem420

    manager and playerDataTwo are constructed in other class files that I have for managing config files. the problem I'm having with the commented lines is that when I join my server I get a console error referring to the line with
    if(!playerDataTwo.contains(playerUUID));

    I just have them commented for right now so its still there when i can figure out how to fix it
     
  4. Offline

    timtower Moderator Moderator

    @Mortem420 What error do you get then? The stacktrace tells a lot.
     
  5. Offline

    Mortem420

    Heres the full console error:

    [05:03:10] [Server thread/ERROR]: Could not pass event PlayerJoinEvent to PracticePlugin v0.0.14e
    org.bukkit.event.EventException: null
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.PlayerList.onPlayerJoin(PlayerList.java:346) [spigot.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.PlayerList.a(PlayerList.java:166) [spigot.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.LoginListener.b(LoginListener.java:159) [spigot.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.LoginListener.e(LoginListener.java:57) [spigot.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) [spigot.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [spigot.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:845) [spigot.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot.jar:git-Spigot-dcd1643-e60fc34]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
    Caused by: java.lang.NullPointerException
    at me.Mortem420.PracticePlugin.Events.PlayerJoin_Event.onJoin(PlayerJoin_Event.java:28) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_221]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_221]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_221]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_221]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
    ... 14 more
     
  6. Offline

    timtower Moderator Moderator

  7. Offline

    Mortem420

    line 28 is if(!playerDataTwo.contains(playerUUID));
     
  8. Offline

    timtower Moderator Moderator

    playerDataTwo is null.
     
  9. Offline

    Mortem420

    yeah, I had a feeling. I think its just that line I'm having trouble with. I could have even typed it entirely wrong, i'm not sure. any advice for what i could do to fix it??
     
  10. Offline

    timtower Moderator Moderator

    @Mortem420 You didn't type it wrong, then you would get other issues.
    manager should check if the file exists already.
     
  11. Offline

    Mortem420

    hmm... well that's the idea but I'm unsure of how to get it to work. I have similar code working elsewhere in the plugin but there I have it set to check for and/or create the file after doing a command in-game. maybe its the way i'm going about the file detection??
     
  12. Offline

    timtower Moderator Moderator

    @Mortem420 You are not doing any file detection.
     
  13. Offline

    Mortem420

    oh ok, well I'm still learning so to some degree don't quite know what I'm doing
     
  14. Offline

    timtower Moderator Moderator

    @Mortem420 manager should get a method to check if it has a file for that UUID already
     
  15. Offline

    Mortem420

    well i guess its back to google and youtube videos for now until i understand things a bit better i guess. dont wanna be starting anymore threads for stupid, noobish questions. I feel this is a simple problem and with more knowledge I could probably figure it out at some point

    ah, i see. ill try to get that figured out then

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     

Share This Page