Code cleanup and add jenkins update provider

This commit is contained in:
GeorgH93 2018-04-30 01:51:52 +02:00
parent 12767c0027
commit d663fb1d22
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
5 changed files with 42 additions and 24 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>Minepacks</artifactId>
<version>2.0-SNAPSHOT</version>
<version>2.0-BETA-SNAPSHOT</version>
<scm>
<connection>scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git</connection>
@ -57,7 +57,7 @@
<dependency>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>PluginLib</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
</dependency>
</dependencies>

View File

@ -22,6 +22,7 @@
import at.pcgamingfreaks.ConsoleColor;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.OldFileUpdater;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.WorldBlacklistMode;
import at.pcgamingfreaks.YamlFileManager;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@ -47,11 +48,11 @@ protected void doUpdate()
}
@Override
protected void doUpgrade(at.pcgamingfreaks.Configuration oldConfig)
protected void doUpgrade(YamlFileManager oldConfig)
{
if(oldConfig.getVersion() < 20) // Pre V2.0 config file
{
OldFileUpdater.updateConfig(oldConfig.getConfig(), getConfig());
OldFileUpdater.updateConfig(oldConfig.getYaml(), getConfig());
}
else
{
@ -184,6 +185,12 @@ public boolean getAutoUpdate()
return getConfig().getBoolean("Misc.AutoUpdate", true);
}
public boolean useUpdaterDevBuilds()
{
//TODO add config value for final version
return true;
}
public boolean isBungeeCordModeEnabled()
{
return getConfig().getBoolean("Misc.UseBungeeCord", false);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016-2017 GeorgH93
* Copyright (C) 2016-2018 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -30,6 +30,7 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.Nullable;
import java.sql.*;
@ -42,8 +43,8 @@ public abstract class SQL extends Database
protected String tablePlayers, tableBackpacks, tableCooldowns; // Table Names
protected String fieldPlayerName, fieldPlayerID, fieldPlayerUUID, fieldBpOwner, fieldBpIts, fieldBpVersion, fieldBpLastUpdate, fieldCdPlayer, fieldCdTime; // Table Fields
protected String queryUpdatePlayerAdd, queryGetPlayerID, queryInsertBp, queryUpdateBp, queryGetBP, queryDeleteOldBackpacks, queryGetUnsetOrInvalidUUIDs, queryFixUUIDs, querySyncCooldown; // DB Querys
protected String queryDeleteOldCooldowns, queryGetCooldown; // DB Querys
@Language("SQL") protected String queryUpdatePlayerAdd, queryGetPlayerID, queryInsertBp, queryUpdateBp, queryGetBP, queryDeleteOldBackpacks, queryGetUnsetOrInvalidUUIDs, queryFixUUIDs; // DB Querys
@Language("SQL") protected String queryDeleteOldCooldowns, querySyncCooldown, queryGetCooldown; // DB Querys
protected boolean updatePlayer, syncCooldown;
public SQL(Minepacks mp)
@ -249,7 +250,7 @@ protected void setTableAndFieldNames()
protected abstract void updateQuerysForDialect();
protected String replacePlaceholders(String query)
protected String replacePlaceholders(@Language("SQL") String query)
{
return query.replaceAll("(\\{\\w+})", "`$1`").replaceAll("`(\\{\\w+})`_(\\w+)", "`$1_$2`").replaceAll("fk_`(\\{\\w+})`_`(\\{\\w+})`_`(\\{\\w+})`", "`fk_$1_$2_$3`") // Fix name formatting
.replaceAll("\\{TablePlayers}", tablePlayers).replaceAll("\\{FieldName}", fieldPlayerName).replaceAll("\\{FieldUUID}", fieldPlayerUUID).replaceAll("\\{FieldPlayerID}", fieldPlayerID) // Players

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016-2017 GeorgH93
* Copyright (C) 2016-2018 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -121,9 +121,8 @@ protected void checkDB()
stmt.execute("ALTER TABLE `backpacks` ADD COLUMN `version` INT DEFAULT 0;");
}
catch(SQLException ignored) {}
try
try(ResultSet rs = stmt.executeQuery("SELECT DATE('now');"))
{
ResultSet rs = stmt.executeQuery("SELECT DATE('now');");
rs.next();
stmt.execute("ALTER TABLE `backpacks` ADD COLUMN `lastupdate` DATE DEFAULT '" + rs.getString(1) + "';");
}

View File

@ -35,6 +35,9 @@
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.EventListener;
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.ItemFilter;
import at.pcgamingfreaks.StringUtils;
import at.pcgamingfreaks.Updater.UpdateProviders.BukkitUpdateProvider;
import at.pcgamingfreaks.Updater.UpdateProviders.JenkinsUpdateProvider;
import at.pcgamingfreaks.Updater.UpdateProviders.UpdateProvider;
import org.apache.commons.lang3.Validate;
import org.bukkit.Bukkit;
@ -53,6 +56,8 @@
public class Minepacks extends JavaPlugin implements MinepacksPlugin
{
private static final int BUKKIT_PROJECT_ID = 83445;
private static final String JENKINS_URL = "https://ci.pcgamingfreaks.at", JENKINS_JOB = "Minepacks V2";
private static Minepacks instance = null;
public Config config;
@ -104,12 +109,7 @@ public void onEnable()
load();
if(config.getAutoUpdate()) // Lets check for updates
{
getLogger().info("Checking for updates ...");
Updater updater = new Updater(this, this.getFile(), true, 83445); // Create a new updater with dev.bukkit.org as update provider
updater.update(); // Starts the update
}
if(config.getAutoUpdate()) update();
StringUtils.getPluginEnabledMessage(getDescription().getName());
}
@ -117,17 +117,28 @@ public void onEnable()
public void onDisable()
{
Updater updater = null;
if(config.getAutoUpdate()) // Lets check for updates
{
getLogger().info("Checking for updates ...");
updater = new Updater(this, this.getFile(), true, 83445); // Create a new updater with dev.bukkit.org as update provider
updater.update(); // Starts the update, if there is a new update available it will download while we close the rest
}
if(config.getAutoUpdate()) updater = update();
unload();
if(updater != null) updater.waitForAsyncOperation(); // The update can download while we kill the listeners and close the DB connections
if(updater != null) updater.waitForAsyncOperation();
StringUtils.getPluginDisabledMessage(getDescription().getName());
}
public Updater update()
{
UpdateProvider updateProvider;
if(config.useUpdaterDevBuilds())
{
updateProvider = new JenkinsUpdateProvider(JENKINS_URL, JENKINS_JOB, getLogger());
}
else
{
updateProvider = new BukkitUpdateProvider(BUKKIT_PROJECT_ID, getLogger());
}
Updater updater = new Updater(this, this.getFile(), true, updateProvider);
updater.update();
return updater;
}
private void load()
{
lang.load(config.getLanguage(), config.getLanguageUpdateMode());