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.apache.logging.log4j.LogManager;
022import org.apache.logging.log4j.Logger;
023import org.checkerframework.checker.nullness.qual.Nullable;
024
025import java.io.IOException;
026import java.nio.file.Files;
027import java.nio.file.Path;
028
029/**
030 * Object representing a plot backup. This does not actually contain the
031 * backup itself, it is just a pointer to an available backup
032 */
033public class Backup {
034
035    private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + Backup.class.getSimpleName());
036
037    private final BackupProfile owner;
038    private final long creationTime;
039    @Nullable
040    private final Path file;
041
042    Backup(final BackupProfile owner, final long creationTime, @Nullable final Path file) {
043        this.owner = owner;
044        this.creationTime = creationTime;
045        this.file = file;
046    }
047
048    /**
049     * Delete the backup
050     */
051    public void delete() {
052        if (file != null) {
053            try {
054                Files.deleteIfExists(file);
055            } catch (final IOException e) {
056                LOGGER.error("Error deleting backup at {}", file, e);
057            }
058        }
059    }
060
061    public BackupProfile getOwner() {
062        return this.owner;
063    }
064
065    public long getCreationTime() {
066        return this.creationTime;
067    }
068
069    public @Nullable Path getFile() {
070        return this.file;
071    }
072
073}