Guest User

FlowerLog.java

a guest
Oct 28th, 2015
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. package com.ruseps.world.content;
  2.  
  3. import com.ruseps.world.entity.impl.player.Player;
  4. import java.io.BufferedWriter;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.text.DateFormat;
  8. import java.text.SimpleDateFormat;
  9. import java.util.Calendar;
  10.  
  11. public class FlowerLog {
  12.     /**
  13.      * These variables are constants because they will not change
  14.      * no matter what the circumstances are.
  15.      */
  16.     private static final String FILE_PATH = "./data/saves/FlowerPlantsLog.txt";
  17.     private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd, HH:mm:ss");
  18.  
  19.     public static String getFlowerColor(int object) {
  20.         switch (object) {
  21.             case 2980:
  22.                 return "Pastel";
  23.             case 2981:
  24.                 return "Red";
  25.             case 2982:
  26.                 return "Blue";
  27.             case 2983:
  28.                 return "Yellow";
  29.             case 2984:
  30.                 return "Purple";
  31.             case 2985:
  32.                 return "Orange";
  33.             case 2986:
  34.                 return "Rainbow";
  35.             case 2987:
  36.                 return "White";
  37.             case 2988:
  38.                 return "Black";
  39.             default:
  40.                 // If the value is not handled in any other case, it defaults to this.
  41.                 return "error getting color";
  42.         }
  43.     }
  44.     public static void writeFlowerLog(Player player, String color) {
  45.         Calendar cal = Calendar.getInstance();
  46.         /**
  47.          * A try-with-resources does not need to be closed or terminated, as it does that
  48.          * automatically when the statement terminates (Either successfully or not)
  49.          */
  50.         try (BufferedWriter bw = new BufferedWriter(new FileWriter(FILE_PATH, true))) {
  51.             bw.write("[" + DATE_FORMAT.format(cal.getTime()) + "] " + "[" + player.getPlayerName() + "]    " + "planted       " + color);
  52.             bw.newLine();
  53.             bw.flush();
  54.         } catch (IOException ioe) {
  55.             ioe.printStackTrace();
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment