Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ruseps.world.content;
- import com.ruseps.world.entity.impl.player.Player;
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- public class FlowerLog {
- /**
- * These variables are constants because they will not change
- * no matter what the circumstances are.
- */
- private static final String FILE_PATH = "./data/saves/FlowerPlantsLog.txt";
- private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd, HH:mm:ss");
- public static String getFlowerColor(int object) {
- switch (object) {
- case 2980:
- return "Pastel";
- case 2981:
- return "Red";
- case 2982:
- return "Blue";
- case 2983:
- return "Yellow";
- case 2984:
- return "Purple";
- case 2985:
- return "Orange";
- case 2986:
- return "Rainbow";
- case 2987:
- return "White";
- case 2988:
- return "Black";
- default:
- // If the value is not handled in any other case, it defaults to this.
- return "error getting color";
- }
- }
- public static void writeFlowerLog(Player player, String color) {
- Calendar cal = Calendar.getInstance();
- /**
- * A try-with-resources does not need to be closed or terminated, as it does that
- * automatically when the statement terminates (Either successfully or not)
- */
- try (BufferedWriter bw = new BufferedWriter(new FileWriter(FILE_PATH, true))) {
- bw.write("[" + DATE_FORMAT.format(cal.getTime()) + "] " + "[" + player.getPlayerName() + "] " + "planted " + color);
- bw.newLine();
- bw.flush();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment