001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.core.backup;
020
021import org.checkerframework.checker.nullness.qual.Nullable;
022
023import java.io.IOException;
024import java.nio.file.Files;
025import java.nio.file.Path;
026
027/**
028 * Object representing a plot backup. This does not actually contain the
029 * backup itself, it is just a pointer to an available backup
030 */
031public class Backup {
032
033    private final BackupProfile owner;
034    private final long creationTime;
035    @Nullable
036    private final Path file;
037
038    Backup(final BackupProfile owner, final long creationTime, final Path file) {
039        this.owner = owner;
040        this.creationTime = creationTime;
041        this.file = file;
042    }
043
044    /**
045     * Delete the backup
046     */
047    public void delete() {
048        if (file != null) {
049            try {
050                Files.deleteIfExists(file);
051            } catch (final IOException e) {
052                e.printStackTrace();
053            }
054        }
055    }
056
057    public BackupProfile getOwner() {
058        return this.owner;
059    }
060
061    public long getCreationTime() {
062        return this.creationTime;
063    }
064
065    public @Nullable Path getFile() {
066        return this.file;
067    }
068
069}