001package net.tnemc.plugincore.core.utils; 002/* 003 * The New Plugin Core 004 * Copyright (C) 2022 - 2024 Daniel "creatorfromhell" Vidmar 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU Affero 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 Affero General Public License for more details. 015 * 016 * You should have received a copy of the GNU Affero General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019 020import com.vdurmont.semver4j.Semver; 021import net.tnemc.plugincore.PluginCore; 022 023/** 024 * UpdateChecker 025 * 026 * @author creatorfromhell 027 * @since 0.1.2.0 028 */ 029public class UpdateChecker { 030 031 private final Semver ver; 032 033 public UpdateChecker() { 034 ver = IOUtil.readVersion().map(Semver::new).orElseGet(()->new Semver("0.0.0.0")); 035 } 036 037 public boolean isEarlyBuild() { 038 return ver.isLowerThan(PluginCore.engine().version()); 039 } 040 041 public boolean needsUpdate() { 042 return ver.isGreaterThan(PluginCore.engine().version()); 043 } 044 045 public String stable() { 046 if(new Semver(PluginCore.engine().version() + "-" + PluginCore.engine().build(), Semver.SemverType.LOOSE).isStable()) { 047 return "Stable"; 048 } 049 return "Not Stable"; 050 } 051 052 public String getBuild() { 053 return ver.getValue(); 054 } 055}