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 035 ver = IOUtil.readVersion().map(Semver::new).orElseGet(()->new Semver("0.0.0.0")); 036 } 037 038 public boolean isEarlyBuild() { 039 040 return ver.isLowerThan(PluginCore.engine().version()); 041 } 042 043 public boolean needsUpdate() { 044 045 return ver.isGreaterThan(PluginCore.engine().version()); 046 } 047 048 public String stable() { 049 050 if(new Semver(PluginCore.engine().version() + "-" + PluginCore.engine().build(), Semver.SemverType.LOOSE).isStable()) { 051 return "Stable"; 052 } 053 return "Not Stable"; 054 } 055 056 public String getBuild() { 057 058 return ver.getValue(); 059 } 060}