Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package total;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- public class TotalJoins extends JavaPlugin{
- int joinsdata = 0;
- File joins = new File("total/joins.txt");
- public void onEnable(){
- getLogger().info("[Total] is enabled");
- }
- public void onDisable(){
- getLogger().info("[Total] is Disabled!");
- try
- {
- String data = Integer.toString(joinsdata);
- if (!joins.exists()) {
- joins.createNewFile();
- }
- BufferedWriter bw = new BufferedWriter(new FileWriter(joins));
- bw.write(data);
- bw.close();
- }
- catch(IOException ioe)
- {
- //error
- }
- }
- public TotalJoins(final Player playerJoined){
- joinsdata += 1;
- }
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if (cmd.getName().equalsIgnoreCase("joins")){
- try
- {
- BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(joins)));//again, make sure you have a file object
- String l;
- while((l=br.readLine()) != null)
- {
- sender.sendMessage("The server has been joined " + joinsdata + " times!");
- return true;
- }
- br.close();
- }
- catch(IOException ioe)
- {
- //error
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment