Last active
August 29, 2015 14:00
-
-
Save amhokies/11201261 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyPlugin extends JavaPlugin { | |
@Override | |
public void onEnable() { | |
// Here we are instanciating our PlayerListener class and passing an instance | |
// of this class to its constructor. This will give us access to all public | |
// members of this class from within PlayerListener. | |
getServer().getPluginManager().registerEvents(new PlayerListener(this), this); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PlayerListener implements Listener { | |
/** | |
* The instance of the Main class | |
*/ | |
private Plugin plugin; | |
/** | |
* Might as well create a static File object to represent | |
* our PlayerData directory. | |
*/ | |
private static File playerDataDir; | |
/** | |
* This is our constructor. It is automatically called | |
* when an instance of our class is created. We are going | |
* to store the Plugin instance passed in to our plugin | |
* field so that the Main class's methods can be used | |
* from this class | |
*/ | |
public PlayerListener(Plugin plugin) { | |
this.plugin = plugin; | |
if (playerDataDir == null) | |
playerDataDir = new File(plugin.getDataFolder(), "PlayerData"); | |
} | |
@EventHandler | |
public void onPlayerJoin(PlayerJoin event) { | |
File f = new File(playerDataDir, event.getPlayer().getName() + ".yml"); | |
// The rest | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment