I try to make a spigot plugin that can detect if nobody is on the server. I need this for a timer, if nobody is on the server, it should stop the timer and save the time of the timer in a text file. Is there any way I can do this with a plugin. Thanks for every help, Aaron.
How to create text files:
try {
File file = new File(Yourplugin.getPlugin(YourPlugin.class).getDataFolder().getPath(), "filename.txt");
file.getParentFile().mkdirs();
file.createNewFile();
} catch (IOException exception){
System.out.println(exception.toString());
}
How to read from text files:
File file = new File(YourPlugin.getPlugin(Yourplugin.class).getDataFolder().getPath(), "filename.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String line = br.readline(); //can be null, if nothing is in file
How to write to Files:
File file = new File(YourPlugin.getPlugin(Yourplugin.class).getDataFolder().getPath(), "filename.txt");
BufferedWriter wr = new BufferedWriter(new FileWriter(file));
br.write("yourtime");
You should make a try catch construction in every example like in the first one.