Added SongodaUpdater.

This commit is contained in:
Brianna 2019-04-28 16:55:50 -04:00
parent e532b0019b
commit a352703319
7 changed files with 163 additions and 10 deletions

10
pom.xml
View File

@ -69,24 +69,26 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.14-pre5</version>
<version>1.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>songodaupdater</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-bukkit</artifactId>
<version>0.5.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>

View File

@ -8,9 +8,12 @@ import com.songoda.epicvouchers.libraries.inventory.IconInv;
import com.songoda.epicvouchers.listeners.PlayerCommandListener;
import com.songoda.epicvouchers.listeners.PlayerInteractListener;
import com.songoda.epicvouchers.utils.*;
import com.songoda.epicvouchers.utils.updateModules.LocaleModule;
import com.songoda.epicvouchers.voucher.CoolDownManager;
import com.songoda.epicvouchers.voucher.Voucher;
import com.songoda.epicvouchers.voucher.VoucherExecutor;
import com.songoda.update.Plugin;
import com.songoda.update.SongodaUpdate;
import lombok.Getter;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
@ -25,6 +28,8 @@ import java.util.LinkedHashMap;
@Getter
public class EpicVouchers extends JavaPlugin {
private static EpicVouchers INSTANCE;
private final ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
private CommandManager commandManager;
private Connections connections;
@ -35,8 +40,13 @@ public class EpicVouchers extends JavaPlugin {
private ConfigWrapper vouchersFile = new ConfigWrapper(this, "", "vouchers.yml");
private LinkedHashMap<String, Voucher> vouchers;
public static EpicVouchers getInstance() {
return INSTANCE;
}
@Override
public void onEnable() {
INSTANCE = this;
Bukkit.getConsoleSender().sendMessage(Methods.format("&a============================="));
Bukkit.getConsoleSender().sendMessage(Methods.format("&7EpicVouchers " + this.getDescription().getVersion() + " by &5Songoda <3&7!"));
Bukkit.getConsoleSender().sendMessage(Methods.format("&7Action: &aEnabling&7..."));
@ -46,6 +56,11 @@ public class EpicVouchers extends JavaPlugin {
Locale.saveDefaultLocale("en_US");
this.locale = Locale.getLocale(getConfig().getString("Locale", "en_US"));
//Running Songoda Updater
Plugin plugin = new Plugin(this, 25);
plugin.addModule(new LocaleModule());
SongodaUpdate.load(plugin);
FastInv.init(this);
IconInv.init(this);
BountifulAPI.init(this);

View File

@ -150,11 +150,11 @@ public class Locale {
/**
* Save a default locale file from the project source directory, to the locale folder
*
* @param path the path to the file to save
* @param in file to save
* @param fileName the name of the file to save
* @return true if the operation was successful, false otherwise
*/
public static boolean saveDefaultLocale(String path, String fileName) {
public static boolean saveDefaultLocale(InputStream in, String fileName) {
if (!localeFolder.exists()) localeFolder.mkdirs();
if (!fileName.endsWith(FILE_EXTENSION))
@ -166,7 +166,7 @@ public class Locale {
}
try (OutputStream outputStream = new FileOutputStream(destinationFile)) {
copy(plugin.getResource(fileName), outputStream);
copy(in == null ? plugin.getResource(fileName) : in, outputStream);
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
String[] localeValues = fileName.split("_");
@ -189,7 +189,7 @@ public class Locale {
* @return true if the operation was successful, false otherwise
*/
public static boolean saveDefaultLocale(String fileName) {
return saveDefaultLocale("", fileName);
return saveDefaultLocale(null, fileName);
}
/**
@ -314,7 +314,7 @@ public class Locale {
public String getMessage(String node, Object... args) {
String message = getMessage(node);
for (Object arg : args) {
message = message.replaceFirst("%.*?%", arg.toString());
message = message.replaceFirst("\\%.*?\\%", arg.toString());
}
return message;
}

View File

@ -3,7 +3,7 @@ package com.songoda.epicvouchers.libraries.inventory.icons;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.AbstractAnvilGUI;
import com.songoda.epicvouchers.libraries.ItemBuilder;
import javafx.util.Pair;
import com.songoda.epicvouchers.utils.Pair;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;

View File

@ -0,0 +1,103 @@
package com.songoda.epicvouchers.utils;
import java.io.Serializable;
import javafx.beans.NamedArg;
/**
* <p>A convenience class to represent name-value pairs.</p>
* @since JavaFX 2.0
*/
public class Pair<K,V> implements Serializable{
/**
* Key of this <code>Pair</code>.
*/
private K key;
/**
* Gets the key for this pair.
* @return key for this pair
*/
public K getKey() { return key; }
/**
* Value of this this <code>Pair</code>.
*/
private V value;
/**
* Gets the value for this pair.
* @return value for this pair
*/
public V getValue() { return value; }
/**
* Creates a new pair
* @param key The key for this pair
* @param value The value to use for this pair
*/
public Pair(@NamedArg("key") K key, @NamedArg("value") V value) {
this.key = key;
this.value = value;
}
/**
* <p><code>String</code> representation of this
* <code>Pair</code>.</p>
*
* <p>The default name/value delimiter '=' is always used.</p>
*
* @return <code>String</code> representation of this <code>Pair</code>
*/
@Override
public String toString() {
return key + "=" + value;
}
/**
* <p>Generate a hash code for this <code>Pair</code>.</p>
*
* <p>The hash code is calculated using both the name and
* the value of the <code>Pair</code>.</p>
*
* @return hash code for this <code>Pair</code>
*/
@Override
public int hashCode() {
// name's hashCode is multiplied by an arbitrary prime number (13)
// in order to make sure there is a difference in the hashCode between
// these two parameters:
// name: a value: aa
// name: aa value: a
return key.hashCode() * 13 + (value == null ? 0 : value.hashCode());
}
/**
* <p>Test this <code>Pair</code> for equality with another
* <code>Object</code>.</p>
*
* <p>If the <code>Object</code> to be tested is not a
* <code>Pair</code> or is <code>null</code>, then this method
* returns <code>false</code>.</p>
*
* <p>Two <code>Pair</code>s are considered equal if and only if
* both the names and values are equal.</p>
*
* @param o the <code>Object</code> to test for
* equality with this <code>Pair</code>
* @return <code>true</code> if the given <code>Object</code> is
* equal to this <code>Pair</code> else <code>false</code>
*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof Pair) {
Pair pair = (Pair) o;
if (key != null ? !key.equals(pair.key) : pair.key != null) return false;
if (value != null ? !value.equals(pair.value) : pair.value != null) return false;
return true;
}
return false;
}
}

View File

@ -33,6 +33,7 @@ public class SettingsManager implements Listener {
DATABASE_USERNAME("Database.Username", "PUT_USERNAME_HERE"),
DATABASE_PASSWORD("Database.Password", "PUT_PASSWORD_HERE"),
LANGUGE_MODE("System.Language Mode", "en_US"),
DEBUGGER_ENABLED("System.Debugger Enabled", false);
private final String setting;

View File

@ -0,0 +1,32 @@
package com.songoda.epicvouchers.utils.updateModules;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.update.Module;
import com.songoda.update.Plugin;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
public class LocaleModule implements Module {
@Override
public void run(Plugin plugin) {
JSONObject json = plugin.getJson();
try {
JSONArray files = (JSONArray) json.get("neededFiles");
for (Object o : files) {
JSONObject file = (JSONObject) o;
if (file.get("type").equals("locale")) {
InputStream in = new URL((String) file.get("link")).openStream();
EpicVouchers.getInstance().getLocale().saveDefaultLocale(in, (String) file.get("name"));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}