Skip to content

Instantly share code, notes, and snippets.

@amhokies
Last active August 29, 2015 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amhokies/11201261 to your computer and use it in GitHub Desktop.
Save amhokies/11201261 to your computer and use it in GitHub Desktop.
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);
}
}
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