mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-01-03 18:47:43 +01:00
Mega Update
default config now with comments serializer now uses reflections bug fixes and performance improvements
This commit is contained in:
parent
fea451a01c
commit
1c8810ec0b
@ -1,564 +0,0 @@
|
||||
/*
|
||||
* Updater for Bukkit.
|
||||
*
|
||||
* This class provides the means to safely and easily update a plugin, or check to see if it is updated using dev.bukkit.org
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.Updater;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
/**
|
||||
* Check dev.bukkit.org to find updates for a given plugin, and download the updates if needed.
|
||||
* <p/>
|
||||
* <b>VERY, VERY IMPORTANT</b>: Because there are no standards for adding auto-update toggles in your plugin's config, this system provides NO CHECK WITH YOUR CONFIG to make sure the user has allowed auto-updating.
|
||||
* <br>
|
||||
* It is a <b>BUKKIT POLICY</b> that you include a boolean value in your config that prevents the auto-updater from running <b>AT ALL</b>.
|
||||
* <br>
|
||||
* If you fail to include this option in your config, your plugin will be <b>REJECTED</b> when you attempt to submit it to dev.bukkit.org.
|
||||
* <p/>
|
||||
* An example of a good configuration option would be something similar to 'auto-update: true' - if this value is set to false you may NOT run the auto-updater.
|
||||
* <br>
|
||||
* If you are unsure about these rules, please read the plugin submission guidelines: http://goo.gl/8iU5l
|
||||
*
|
||||
* @author Gravity
|
||||
* @version 2.1
|
||||
*/
|
||||
|
||||
public class Bukkit_Updater {
|
||||
|
||||
private Plugin plugin;
|
||||
private UpdateType type;
|
||||
private String versionName;
|
||||
private String versionLink;
|
||||
private String versionType;
|
||||
private String versionGameVersion;
|
||||
|
||||
private boolean announce; // Whether to announce file downloads
|
||||
|
||||
private URL url; // Connecting to RSS
|
||||
private File file; // The plugin's file
|
||||
private Thread thread; // Updater thread
|
||||
|
||||
private int id = -1; // Project's Curse ID
|
||||
private String apiKey = null; // BukkitDev ServerMods API key
|
||||
private static final String TITLE_VALUE = "name"; // Gets remote file's title
|
||||
private static final String LINK_VALUE = "downloadUrl"; // Gets remote file's download link
|
||||
private static final String TYPE_VALUE = "releaseType"; // Gets remote file's release type
|
||||
private static final String VERSION_VALUE = "gameVersion"; // Gets remote file's build version
|
||||
private static final String QUERY = "/servermods/files?projectIds="; // Path to GET
|
||||
private static final String HOST = "https://api.curseforge.com"; // Slugs will be appended to this to get to the project's RSS feed
|
||||
|
||||
private static final String USER_AGENT = "Updater (by Gravity)";
|
||||
private static final String delimiter = "^V|[\\s_-]V"; // Used for locating version numbers in file names
|
||||
private static final String[] NO_UPDATE_TAG = { "-DEV", "-PRE", "-SNAPSHOT" }; // If the version number contains one of these, don't update.
|
||||
private static final int BYTE_SIZE = 1024; // Used for downloading files
|
||||
private final YamlConfiguration config = new YamlConfiguration(); // Config file
|
||||
private String updateFolder;// The folder that downloads will be placed in
|
||||
private UpdateResult result = UpdateResult.SUCCESS; // Used for determining the outcome of the update process
|
||||
|
||||
/**
|
||||
* Initialize the updater.
|
||||
*
|
||||
* @param plugin The plugin that is checking for an update.
|
||||
* @param id The dev.bukkit.org id of the project.
|
||||
* @param file The file that the plugin is running from, get this by doing this.getFile() from within your main class.
|
||||
* @param type Specify the type of update this will be. See {@link UpdateType}
|
||||
* @param announce True if the program should announce the progress of new updates in console.
|
||||
*/
|
||||
public Bukkit_Updater(Plugin plugin, int id, File file, UpdateType type, boolean announce) {
|
||||
this.plugin = plugin;
|
||||
this.type = type;
|
||||
this.announce = announce;
|
||||
this.file = file;
|
||||
this.id = id;
|
||||
this.updateFolder = plugin.getServer().getUpdateFolder();
|
||||
|
||||
final File pluginFile = plugin.getDataFolder().getParentFile();
|
||||
final File updaterFile = new File(pluginFile, "Updater");
|
||||
final File updaterConfigFile = new File(updaterFile, "config.yml");
|
||||
|
||||
this.config.options().header("This configuration file affects all plugins using the Updater system (version 2+ - http://forums.bukkit.org/threads/96681/ )" + '\n'
|
||||
+ "If you wish to use your API key, read http://wiki.bukkit.org/ServerMods_API and place it below." + '\n'
|
||||
+ "Some updating systems will not adhere to the disabled value, but these may be turned off in their plugin's configuration.");
|
||||
this.config.addDefault("api-key", "PUT_API_KEY_HERE");
|
||||
this.config.addDefault("disable", false);
|
||||
|
||||
if (!updaterFile.exists()) {
|
||||
updaterFile.mkdir();
|
||||
}
|
||||
|
||||
boolean createFile = !updaterConfigFile.exists();
|
||||
try {
|
||||
if (createFile) {
|
||||
updaterConfigFile.createNewFile();
|
||||
this.config.options().copyDefaults(true);
|
||||
this.config.save(updaterConfigFile);
|
||||
} else {
|
||||
this.config.load(updaterConfigFile);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
if (createFile) {
|
||||
plugin.getLogger().severe("The updater could not create configuration at " + updaterFile.getAbsolutePath());
|
||||
} else {
|
||||
plugin.getLogger().severe("The updater could not load configuration at " + updaterFile.getAbsolutePath());
|
||||
}
|
||||
plugin.getLogger().log(Level.SEVERE, null, e);
|
||||
}
|
||||
|
||||
if (this.config.getBoolean("disable")) {
|
||||
this.result = UpdateResult.DISABLED;
|
||||
return;
|
||||
}
|
||||
|
||||
String key = this.config.getString("api-key");
|
||||
if (key.equalsIgnoreCase("PUT_API_KEY_HERE") || key.equals("")) {
|
||||
key = null;
|
||||
}
|
||||
|
||||
this.apiKey = key;
|
||||
|
||||
try {
|
||||
this.url = new URL(Bukkit_Updater.HOST + Bukkit_Updater.QUERY + id);
|
||||
} catch (final MalformedURLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "The project ID provided for updating, " + id + " is invalid.", e);
|
||||
this.result = UpdateResult.FAIL_BADID;
|
||||
}
|
||||
|
||||
this.thread = new Thread(new UpdateRunnable());
|
||||
this.thread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the result of the update process.
|
||||
*
|
||||
* @return result of the update process.
|
||||
* @see UpdateResult
|
||||
*/
|
||||
public UpdateResult getResult() {
|
||||
this.waitForThread();
|
||||
return this.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest version's release type.
|
||||
*
|
||||
* @return latest version's release type.
|
||||
* @see ReleaseType
|
||||
*/
|
||||
public ReleaseType getLatestType() {
|
||||
this.waitForThread();
|
||||
if (this.versionType != null) {
|
||||
for (ReleaseType type : ReleaseType.values()) {
|
||||
if (this.versionType.equals(type.name().toLowerCase())) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest version's game version (such as "CB 1.2.5-R1.0").
|
||||
*
|
||||
* @return latest version's game version.
|
||||
*/
|
||||
public String getLatestGameVersion() {
|
||||
this.waitForThread();
|
||||
return this.versionGameVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest version's name (such as "Project v1.0").
|
||||
*
|
||||
* @return latest version's name.
|
||||
*/
|
||||
public String getLatestName() {
|
||||
this.waitForThread();
|
||||
return this.versionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest version's direct file link.
|
||||
*
|
||||
* @return latest version's file link.
|
||||
*/
|
||||
public String getLatestFileLink() {
|
||||
this.waitForThread();
|
||||
return this.versionLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* As the result of Updater output depends on the thread's completion, it is necessary to wait for the thread to finish
|
||||
* before allowing anyone to check the result.
|
||||
*/
|
||||
private void waitForThread() {
|
||||
if ((this.thread != null) && this.thread.isAlive()) {
|
||||
try {
|
||||
this.thread.join();
|
||||
} catch (final InterruptedException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, null, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an update from dev.bukkit.org into the server's update folder.
|
||||
*
|
||||
* @param folder the updates folder location.
|
||||
* @param file the name of the file to save it as.
|
||||
* @param link the url of the file.
|
||||
*/
|
||||
private void saveFile(File folder, String file, String link) {
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
BufferedInputStream in = null;
|
||||
FileOutputStream fout = null;
|
||||
try {
|
||||
// Download the file
|
||||
final URL url = new URL(link);
|
||||
final int fileLength = url.openConnection().getContentLength();
|
||||
in = new BufferedInputStream(url.openStream());
|
||||
fout = new FileOutputStream(folder.getAbsolutePath() + File.separator + file);
|
||||
|
||||
final byte[] data = new byte[Bukkit_Updater.BYTE_SIZE];
|
||||
int count;
|
||||
if (this.announce) {
|
||||
this.plugin.getLogger().info("About to download a new update: " + this.versionName);
|
||||
}
|
||||
long downloaded = 0;
|
||||
while ((count = in.read(data, 0, Bukkit_Updater.BYTE_SIZE)) != -1) {
|
||||
downloaded += count;
|
||||
fout.write(data, 0, count);
|
||||
final int percent = (int) ((downloaded * 100) / fileLength);
|
||||
if (this.announce && ((percent % 10) == 0)) {
|
||||
this.plugin.getLogger().info("Downloading update: " + percent + "% of " + fileLength + " bytes.");
|
||||
}
|
||||
}
|
||||
//Just a quick check to make sure we didn't leave any files from last time...
|
||||
for (final File xFile : new File(this.plugin.getDataFolder().getParent(), this.updateFolder).listFiles()) {
|
||||
if (xFile.getName().endsWith(".zip")) {
|
||||
xFile.delete();
|
||||
}
|
||||
}
|
||||
// Check to see if it's a zip file, if it is, unzip it.
|
||||
final File dFile = new File(folder.getAbsolutePath() + File.separator + file);
|
||||
if (dFile.getName().endsWith(".zip")) {
|
||||
// Unzip
|
||||
this.unzip(dFile.getCanonicalPath());
|
||||
}
|
||||
if (this.announce) {
|
||||
this.plugin.getLogger().info("Finished updating.");
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
this.plugin.getLogger().warning("The auto-updater tried to download a new update, but was unsuccessful.");
|
||||
this.result = UpdateResult.FAIL_DOWNLOAD;
|
||||
} finally {
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (fout != null) {
|
||||
fout.close();
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of Zip-File-Extractor, modified by Gravity for use with Updater.
|
||||
*
|
||||
* @param file the location of the file to extract.
|
||||
*/
|
||||
private void unzip(String file) {
|
||||
try {
|
||||
final File fSourceZip = new File(file);
|
||||
final String zipPath = file.substring(0, file.length() - 4);
|
||||
ZipFile zipFile = new ZipFile(fSourceZip);
|
||||
Enumeration<? extends ZipEntry> e = zipFile.entries();
|
||||
while (e.hasMoreElements()) {
|
||||
ZipEntry entry = e.nextElement();
|
||||
File destinationFilePath = new File(zipPath, entry.getName());
|
||||
destinationFilePath.getParentFile().mkdirs();
|
||||
if (entry.isDirectory()) {
|
||||
continue;
|
||||
} else {
|
||||
final BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
|
||||
int b;
|
||||
final byte buffer[] = new byte[Bukkit_Updater.BYTE_SIZE];
|
||||
final FileOutputStream fos = new FileOutputStream(destinationFilePath);
|
||||
final BufferedOutputStream bos = new BufferedOutputStream(fos, Bukkit_Updater.BYTE_SIZE);
|
||||
while ((b = bis.read(buffer, 0, Bukkit_Updater.BYTE_SIZE)) != -1) {
|
||||
bos.write(buffer, 0, b);
|
||||
}
|
||||
bos.flush();
|
||||
bos.close();
|
||||
bis.close();
|
||||
final String name = destinationFilePath.getName();
|
||||
if (name.endsWith(".jar") && this.pluginFile(name)) {
|
||||
destinationFilePath.renameTo(new File(this.plugin.getDataFolder().getParent(), this.updateFolder + File.separator + name));
|
||||
}
|
||||
}
|
||||
entry = null;
|
||||
destinationFilePath = null;
|
||||
}
|
||||
e = null;
|
||||
zipFile.close();
|
||||
zipFile = null;
|
||||
|
||||
// Move any plugin data folders that were included to the right place, Bukkit won't do this for us.
|
||||
for (final File dFile : new File(zipPath).listFiles()) {
|
||||
if (dFile.isDirectory()) {
|
||||
if (this.pluginFile(dFile.getName())) {
|
||||
final File oFile = new File(this.plugin.getDataFolder().getParent(), dFile.getName()); // Get current dir
|
||||
final File[] contents = oFile.listFiles(); // List of existing files in the current dir
|
||||
for (final File cFile : dFile.listFiles()) // Loop through all the files in the new dir
|
||||
{
|
||||
boolean found = false;
|
||||
for (final File xFile : contents) // Loop through contents to see if it exists
|
||||
{
|
||||
if (xFile.getName().equals(cFile.getName())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
// Move the new file into the current dir
|
||||
cFile.renameTo(new File(oFile.getCanonicalFile() + File.separator + cFile.getName()));
|
||||
} else {
|
||||
// This file already exists, so we don't need it anymore.
|
||||
cFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dFile.delete();
|
||||
}
|
||||
new File(zipPath).delete();
|
||||
fSourceZip.delete();
|
||||
} catch (final IOException e) {
|
||||
this.plugin.getLogger().log(Level.SEVERE, "The auto-updater tried to unzip a new update file, but was unsuccessful.", e);
|
||||
this.result = UpdateResult.FAIL_DOWNLOAD;
|
||||
}
|
||||
new File(file).delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the name of a jar is one of the plugins currently installed, used for extracting the correct files out of a zip.
|
||||
*
|
||||
* @param name a name to check for inside the plugins folder.
|
||||
* @return true if a file inside the plugins folder is named this.
|
||||
*/
|
||||
private boolean pluginFile(String name) {
|
||||
for (final File file : new File("plugins").listFiles()) {
|
||||
if (file.getName().equals(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//Changed Version Checker by GeorgH93
|
||||
/**
|
||||
* Check to see if the program should continue by evaluating whether the plugin is already updated, or shouldn't be updated.
|
||||
*
|
||||
* @param title the plugin's title.
|
||||
* @return true if the version was located and is not the same as the remote's newest.
|
||||
*/
|
||||
private boolean versionCheck(String title)
|
||||
{
|
||||
if (this.type != UpdateType.NO_VERSION_CHECK)
|
||||
{
|
||||
final String localVersion = this.plugin.getDescription().getVersion();
|
||||
if (title.split(delimiter).length == 2)
|
||||
{
|
||||
final String remoteVersion = title.split(delimiter)[1].split("\\s+")[0]; // Get the newest file's version number
|
||||
|
||||
if (this.hasTag(localVersion) || !this.shouldUpdate(localVersion, remoteVersion))
|
||||
{
|
||||
// We already have the latest version, or this build is tagged for no-update
|
||||
this.result = UpdateResult.NO_UPDATE;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The file's name did not contain the string 'vVersion'
|
||||
final String authorInfo = this.plugin.getDescription().getAuthors().size() == 0 ? "" : " (" + this.plugin.getDescription().getAuthors().get(0) + ")";
|
||||
this.plugin.getLogger().warning("The author of this plugin" + authorInfo + " has misconfigured their Auto Update system");
|
||||
this.plugin.getLogger().warning("File versions should follow the format 'PluginName vVERSION'");
|
||||
this.plugin.getLogger().warning("Please notify the author of this error.");
|
||||
this.result = UpdateResult.FAIL_NOVERSION;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>If you wish to run mathematical versioning checks, edit this method.</b>
|
||||
* <p>
|
||||
* With default behavior, Updater will NOT verify that a remote version available on BukkitDev
|
||||
* which is not this version is indeed an "update".
|
||||
* If a version is present on BukkitDev that is not the version that is currently running,
|
||||
* Updater will assume that it is a newer version.
|
||||
* This is because there is no standard versioning scheme, and creating a calculation that can
|
||||
* determine whether a new update is actually an update is sometimes extremely complicated.
|
||||
* </p>
|
||||
* <p>
|
||||
* Updater will call this method from {@link #versionCheck(String)} before deciding whether
|
||||
* the remote version is actually an update.
|
||||
* If you have a specific versioning scheme with which a mathematical determination can
|
||||
* be reliably made to decide whether one version is higher than another, you may
|
||||
* revise this method, using the local and remote version parameters, to execute the
|
||||
* appropriate check.
|
||||
* </p>
|
||||
* <p>
|
||||
* Returning a value of <b>false</b> will tell the update process that this is NOT a new version.
|
||||
* Without revision, this method will always consider a remote version at all different from
|
||||
* that of the local version a new update.
|
||||
* </p>
|
||||
* @param localVersion the current version
|
||||
* @param remoteVersion the remote version
|
||||
* @return true if Updater should consider the remote version an update, false if not.
|
||||
*/
|
||||
public boolean shouldUpdate(String localVersion, String remoteVersion)
|
||||
{
|
||||
String[] lv = localVersion.split(Pattern.quote( "." )), rv = remoteVersion.split(Pattern.quote( "." ));
|
||||
try
|
||||
{
|
||||
int i = 0, c = 0;
|
||||
if(lv.length >= rv.length)
|
||||
{
|
||||
c = rv.length;
|
||||
}
|
||||
else if(rv.length > lv.length)
|
||||
{
|
||||
c = lv.length;
|
||||
}
|
||||
for(i = 0; i < c; i++)
|
||||
{
|
||||
if(Integer.parseInt(rv[i]) > Integer.parseInt(lv[i]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(rv.length > lv.length)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return !localVersion.equalsIgnoreCase(remoteVersion);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate whether the version number is marked showing that it should not be updated by this program.
|
||||
*
|
||||
* @param version a version number to check for tags in.
|
||||
* @return true if updating should be disabled.
|
||||
*/
|
||||
private boolean hasTag(String version) {
|
||||
for (final String string : Bukkit_Updater.NO_UPDATE_TAG) {
|
||||
if (version.contains(string)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a connection to the BukkitDev API and request the newest file's details.
|
||||
*
|
||||
* @return true if successful.
|
||||
*/
|
||||
private boolean read() {
|
||||
try {
|
||||
final URLConnection conn = this.url.openConnection();
|
||||
conn.setConnectTimeout(5000);
|
||||
|
||||
if (this.apiKey != null) {
|
||||
conn.addRequestProperty("X-API-Key", this.apiKey);
|
||||
}
|
||||
conn.addRequestProperty("User-Agent", Bukkit_Updater.USER_AGENT);
|
||||
|
||||
conn.setDoOutput(true);
|
||||
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
final String response = reader.readLine();
|
||||
|
||||
final JSONArray array = (JSONArray) JSONValue.parse(response);
|
||||
|
||||
if (array.size() == 0) {
|
||||
this.plugin.getLogger().warning("The updater could not find any files for the project id " + this.id);
|
||||
this.result = UpdateResult.FAIL_BADID;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.versionName = (String) ((JSONObject) array.get(array.size() - 1)).get(Bukkit_Updater.TITLE_VALUE);
|
||||
this.versionLink = (String) ((JSONObject) array.get(array.size() - 1)).get(Bukkit_Updater.LINK_VALUE);
|
||||
this.versionType = (String) ((JSONObject) array.get(array.size() - 1)).get(Bukkit_Updater.TYPE_VALUE);
|
||||
this.versionGameVersion = (String) ((JSONObject) array.get(array.size() - 1)).get(Bukkit_Updater.VERSION_VALUE);
|
||||
|
||||
return true;
|
||||
} catch (final IOException e) {
|
||||
if (e.getMessage().contains("HTTP response code: 403")) {
|
||||
this.plugin.getLogger().severe("dev.bukkit.org rejected the API key provided in plugins/Updater/config.yml");
|
||||
this.plugin.getLogger().severe("Please double-check your configuration to ensure it is correct.");
|
||||
this.result = UpdateResult.FAIL_APIKEY;
|
||||
} else {
|
||||
this.plugin.getLogger().severe("The updater could not contact dev.bukkit.org for updating.");
|
||||
this.plugin.getLogger().severe("If you have not recently modified your configuration and this is the first time you are seeing this message, the site may be experiencing temporary downtime.");
|
||||
this.result = UpdateResult.FAIL_DBO;
|
||||
}
|
||||
this.plugin.getLogger().log(Level.SEVERE, null, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class UpdateRunnable implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (Bukkit_Updater.this.url != null) {
|
||||
// Obtain the results of the project's file feed
|
||||
if (Bukkit_Updater.this.read()) {
|
||||
if (Bukkit_Updater.this.versionCheck(Bukkit_Updater.this.versionName)) {
|
||||
if ((Bukkit_Updater.this.versionLink != null) && (Bukkit_Updater.this.type != UpdateType.NO_DOWNLOAD)) {
|
||||
String name = Bukkit_Updater.this.file.getName();
|
||||
// If it's a zip file, it shouldn't be downloaded as the plugin's name
|
||||
if (Bukkit_Updater.this.versionLink.endsWith(".zip")) {
|
||||
final String[] split = Bukkit_Updater.this.versionLink.split("/");
|
||||
name = split[split.length - 1];
|
||||
}
|
||||
Bukkit_Updater.this.saveFile(new File(Bukkit_Updater.this.plugin.getDataFolder().getParent(), Bukkit_Updater.this.updateFolder), name, Bukkit_Updater.this.versionLink);
|
||||
} else {
|
||||
Bukkit_Updater.this.result = UpdateResult.UPDATE_AVAILABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package net.gravitydevelopment.Updater;
|
||||
|
||||
/**
|
||||
* Represents the various release types of a file on BukkitDev.
|
||||
*/
|
||||
public enum ReleaseType
|
||||
{
|
||||
/**
|
||||
* An "alpha" file.
|
||||
*/
|
||||
ALPHA,
|
||||
/**
|
||||
* A "beta" file.
|
||||
*/
|
||||
BETA,
|
||||
/**
|
||||
* A "release" file.
|
||||
*/
|
||||
RELEASE
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package net.gravitydevelopment.Updater;
|
||||
|
||||
/**
|
||||
* Gives the developer the result of the update process. Can be obtained by called {@link #getResult()}
|
||||
*/
|
||||
public enum UpdateResult
|
||||
{
|
||||
/**
|
||||
* The updater found an update, and has readied it to be loaded the next time the server restarts/reloads.
|
||||
*/
|
||||
SUCCESS,
|
||||
/**
|
||||
* The updater did not find an update, and nothing was downloaded.
|
||||
*/
|
||||
NO_UPDATE,
|
||||
/**
|
||||
* The server administrator has disabled the updating system.
|
||||
*/
|
||||
DISABLED,
|
||||
/**
|
||||
* The updater found an update, but was unable to download it.
|
||||
*/
|
||||
FAIL_DOWNLOAD,
|
||||
/**
|
||||
* For some reason, the updater was unable to contact dev.bukkit.org to download the file.
|
||||
*/
|
||||
FAIL_DBO,
|
||||
/**
|
||||
* When running the version check, the file on DBO did not contain a recognizable version.
|
||||
*/
|
||||
FAIL_NOVERSION,
|
||||
/**
|
||||
* The id provided by the plugin running the updater was invalid and doesn't exist on DBO.
|
||||
*/
|
||||
FAIL_BADID,
|
||||
/**
|
||||
* The server administrator has improperly configured their API key in the configuration.
|
||||
*/
|
||||
FAIL_APIKEY,
|
||||
/**
|
||||
* The updater found an update, but because of the UpdateType being set to NO_DOWNLOAD, it wasn't downloaded.
|
||||
*/
|
||||
UPDATE_AVAILABLE
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package net.gravitydevelopment.Updater;
|
||||
|
||||
/**
|
||||
* Allows the developer to specify the type of update that will be run.
|
||||
*/
|
||||
public enum UpdateType
|
||||
{
|
||||
/**
|
||||
* Run a version check, and then if the file is out of date, download the newest version.
|
||||
*/
|
||||
DEFAULT,
|
||||
/**
|
||||
* Don't run a version check, just find the latest update and download it.
|
||||
*/
|
||||
NO_VERSION_CHECK,
|
||||
/**
|
||||
* Get information about the version and the download size, but don't actually download anything.
|
||||
*/
|
||||
NO_DOWNLOAD
|
||||
}
|
32
pom.xml
32
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>at.pcgamingfreaks</groupId>
|
||||
<artifactId>MinePacks</artifactId>
|
||||
<version>1.13</version>
|
||||
<version>1.14-SNAPSHOT</version>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git</connection>
|
||||
@ -40,6 +40,10 @@
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>pcgf-repo</id>
|
||||
<url>http://repo.pcgamingfreaks.at/repository/everything/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -56,6 +60,11 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/jar_libs/bukkit.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>at.pcgamingfreaks</groupId>
|
||||
<artifactId>Bukkit_Bungee_PluginLib</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -80,20 +89,23 @@
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-wsdl-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>${basedir}/libs</source>
|
||||
</sources>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>at.pcgamingfreaks:Bukkit_Bungee_PluginLib</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
76
resources/config.yml
Normal file
76
resources/config.yml
Normal file
@ -0,0 +1,76 @@
|
||||
# Minepacks Config File
|
||||
|
||||
# Language settings
|
||||
# Language to use, will load the file: /plugins/Minepacks/lang/<your language setting>.yml
|
||||
Language: en
|
||||
# How outdated language files should be treated. Overwrite/Update
|
||||
# Overwrite = old language file will be replaced with new, use this only if you use the language files suplyed from the plugin
|
||||
# Update = the old language file will be updated with the new english messages, all your changes to the file will survive the update
|
||||
LanguageUpdateMode: Overwrite
|
||||
|
||||
# Title to be showen for the opened inventory. Musst contain an %s (which will be replaced with the players name)
|
||||
BackpackTitle: "&b%s Backpack"
|
||||
# Defines how long a player have to wait till he can reopen his backpack.
|
||||
# Time is in seconds. Values < 1 disable the cooldown.
|
||||
command_cooldown: -1
|
||||
# Defines if the content of the backpack get droped on the death of a player.
|
||||
# If enabled, it can be disabled for individual players with the "backpack.KeepOnDeath" permission.
|
||||
drop_on_death: true
|
||||
|
||||
# Controlls for the auto pickup on full inventory function
|
||||
full_inventory:
|
||||
# If items should be collected to the backpack if the players inventory is full
|
||||
collect_items: false
|
||||
# Interval in seconds how often items around the player should be collected, increase it if it lags the server
|
||||
check_interval: 1
|
||||
# Radius in which items get collected, in meter/blocks, allow decimals
|
||||
collect_radius: 1.5
|
||||
|
||||
|
||||
# Database settings
|
||||
Database:
|
||||
# Database type. MySQL, SQLite or Files
|
||||
Type: SQLite
|
||||
# Turn off if you want to use player ids created from an other plugin. When using shared tables please check the tables sellection
|
||||
UpdatePlayer: true
|
||||
# Auto database cleanup settings
|
||||
AutoCleanup:
|
||||
# Defines the max amount of days backpacks will be stored. -1 to disable auto cleanup
|
||||
MaxInactiveDays: -1
|
||||
# If you would like to use UUIDs, it is recomendet not to change this setting unless you know what you are doing!
|
||||
# true: Only to use if your server is running in online mode and your minecraft version is 1.7.5 or newer
|
||||
# false: In offline mode or for minecraft version below 1.7.5
|
||||
# Should be configured automaticaly based on your minecraft version and online mode settings
|
||||
UseUUIDs: true
|
||||
# Defines the storage format for UUIDs for compatibility with other plugins (shared tables)
|
||||
# true: format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||
# false: format: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
UseUUIDSeparators: false
|
||||
# Settings only for MySQL
|
||||
MySQL:
|
||||
Host: localhost:3306
|
||||
Database: minecraft
|
||||
User: minecraft
|
||||
Password: minecraft
|
||||
# Tables settings for shared tables
|
||||
Tables:
|
||||
# Table names
|
||||
User: backpack_players
|
||||
Backpack: backpacks
|
||||
# Field settings for the tables
|
||||
Fields:
|
||||
User:
|
||||
Player_ID: player_id
|
||||
Name: name
|
||||
UUID: uuid
|
||||
Backpack:
|
||||
Owner_ID: owner
|
||||
ItemStacks: itemstacks
|
||||
Version: version
|
||||
LastUpdate: lastupdate
|
||||
|
||||
# Enables/Disables the auto-update function of the plugin.
|
||||
auto-update: true
|
||||
|
||||
# Config File Version. Don't touch it!
|
||||
Version: 9
|
@ -31,11 +31,11 @@
|
||||
public class Backpack
|
||||
{
|
||||
private OfflinePlayer owner;
|
||||
private HashMap<Player, Boolean> opend = new HashMap<Player, Boolean>();
|
||||
private HashMap<Player, Boolean> opend = new HashMap<>();
|
||||
private Inventory bp;
|
||||
private int size, id;
|
||||
private String title;
|
||||
private boolean inwork;
|
||||
private boolean inWork;
|
||||
|
||||
public Backpack(OfflinePlayer Owner)
|
||||
{
|
||||
@ -44,7 +44,7 @@ public Backpack(OfflinePlayer Owner)
|
||||
id = -1;
|
||||
title = String.format(MinePacks.BackpackTitle, Owner.getName());
|
||||
bp = Bukkit.createInventory(null, size, title);
|
||||
inwork = false;
|
||||
inWork = false;
|
||||
}
|
||||
|
||||
public Backpack(OfflinePlayer Owner, int Size)
|
||||
@ -54,7 +54,7 @@ public Backpack(OfflinePlayer Owner, int Size)
|
||||
bp = Bukkit.createInventory(null, Size, title);
|
||||
size = Size;
|
||||
id = -1;
|
||||
inwork = false;
|
||||
inWork = false;
|
||||
}
|
||||
|
||||
public Backpack(OfflinePlayer Owner, ItemStack[] backpack, int ID)
|
||||
@ -65,7 +65,7 @@ public Backpack(OfflinePlayer Owner, ItemStack[] backpack, int ID)
|
||||
bp = Bukkit.createInventory(null, size, title);
|
||||
bp.setContents(backpack);
|
||||
id = ID;
|
||||
inwork = false;
|
||||
inWork = false;
|
||||
}
|
||||
|
||||
public int getID()
|
||||
@ -117,7 +117,7 @@ public boolean canEdit(Player p)
|
||||
|
||||
public boolean inUse()
|
||||
{
|
||||
return inwork;
|
||||
return inWork;
|
||||
}
|
||||
|
||||
public int getSize()
|
||||
@ -127,7 +127,7 @@ public int getSize()
|
||||
|
||||
public List<ItemStack> setSize(int newSize)
|
||||
{
|
||||
inwork = true;
|
||||
inWork = true;
|
||||
for(Entry<Player, Boolean> e : opend.entrySet())
|
||||
{
|
||||
e.getKey().closeInventory();
|
||||
@ -168,7 +168,7 @@ public List<ItemStack> setSize(int newSize)
|
||||
{
|
||||
e.getKey().openInventory(bp);
|
||||
}
|
||||
inwork = false;
|
||||
inWork = false;
|
||||
return RemovedItems;
|
||||
}
|
||||
|
||||
|
@ -17,191 +17,61 @@
|
||||
|
||||
package at.pcgamingfreaks.georgh.MinePacks.Database;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import at.pcgamingfreaks.Bukkit.Configuration;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import at.pcgamingfreaks.georgh.MinePacks.MinePacks;
|
||||
|
||||
public class Config
|
||||
public class Config extends Configuration
|
||||
{
|
||||
private MinePacks MP;
|
||||
private FileConfiguration config;
|
||||
private static final int CONFIG_VERSION = 8;
|
||||
private static final int CONFIG_VERSION = 9;
|
||||
|
||||
public Config(MinePacks mp)
|
||||
public Config(JavaPlugin plugin)
|
||||
{
|
||||
MP = mp;
|
||||
LoadConfig();
|
||||
super(plugin, CONFIG_VERSION, 9);
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
|
||||
@Override
|
||||
protected boolean newConfigCreated()
|
||||
{
|
||||
LoadConfig();
|
||||
}
|
||||
|
||||
private void LoadConfig()
|
||||
{
|
||||
File file = new File(MP.getDataFolder(), "config.yml");
|
||||
if(!file.exists())
|
||||
{
|
||||
NewConfig(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
config = YamlConfiguration.loadConfiguration(file);
|
||||
UpdateConfig(file);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean UUIDComp()
|
||||
{
|
||||
try
|
||||
{
|
||||
String[] GameVersion = Bukkit.getBukkitVersion().split("-");
|
||||
GameVersion = GameVersion[0].split("\\.");
|
||||
if(Integer.parseInt(GameVersion[1]) > 7 || (Integer.parseInt(GameVersion[1]) == 7 && Integer.parseInt(GameVersion[2]) > 5))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void NewConfig(File file)
|
||||
{
|
||||
config = new YamlConfiguration();
|
||||
config.set("BackpackTitle", ChatColor.AQUA + "%s Backpack");
|
||||
config.set("command_cooldown", -1);
|
||||
config.set("drop_on_death", true);
|
||||
config.set("full_inventory.collect_items", false);
|
||||
config.set("full_inventory.check_interval", 1); // in seconds
|
||||
config.set("full_inventory.collect_radius", 1); // in blocks
|
||||
config.set("Language", "en");
|
||||
config.set("LanguageUpdateMode","Overwrite");
|
||||
config.set("Database.Type","SQLite");
|
||||
config.set("Database.UpdatePlayer", true);
|
||||
config.set("Database.AutoCleanup.MaxInactiveDays", -1);
|
||||
config.set("Database.UseUUIDs", Bukkit.getServer().getOnlineMode() && UUIDComp());
|
||||
config.set("Database.UseUUIDSeparators", false);
|
||||
config.set("Database.MySQL.Host", "localhost:3306");
|
||||
config.set("Database.MySQL.Database", "minecraft");
|
||||
config.set("Database.MySQL.User", "minecraft");
|
||||
config.set("Database.MySQL.Password", "minecraft");
|
||||
config.set("Database.Tables.User", "backpack_players");
|
||||
config.set("Database.Tables.Backpack", "backpacks");
|
||||
config.set("Database.Tables.Fields.User.Player_ID", "player_id");
|
||||
config.set("Database.Tables.Fields.User.Name", "name");
|
||||
config.set("Database.Tables.Fields.User.UUID", "uuid");
|
||||
config.set("Database.Tables.Fields.Backpack.Owner_ID", "owner");
|
||||
config.set("Database.Tables.Fields.Backpack.ItemStacks", "itemstacks");
|
||||
config.set("Database.Tables.Fields.Backpack.Version", "version");
|
||||
config.set("Database.Tables.Fields.Backpack.LastUpdate", "lastupdate");
|
||||
config.set("auto-update", true);
|
||||
config.set("Version",CONFIG_VERSION);
|
||||
|
||||
try
|
||||
{
|
||||
config.save(file);
|
||||
MP.log.info("Config File has been generated.");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean UpdateConfig(File file)
|
||||
{
|
||||
switch(config.getInt("Version"))
|
||||
{
|
||||
case 1:
|
||||
config.set("Database.Tables.Fields.User.Player_ID", "player_id");
|
||||
config.set("Database.Tables.Fields.User.Name", "name");
|
||||
config.set("Database.Tables.Fields.User.UUID", "uuid");
|
||||
config.set("Database.Tables.Fields.Backpack.Owner_ID", "owner");
|
||||
config.set("Database.Tables.Fields.Backpack.ItemStacks", "itemstacks");
|
||||
config.set("Database.Tables.Fields.Backpack.Version", "version");
|
||||
case 2:
|
||||
config.set("Database.UseUUIDSeparators", false);
|
||||
case 3:
|
||||
config.set("auto-update", true);
|
||||
case 4:
|
||||
config.set("command_cooldown", -1);
|
||||
case 5:
|
||||
config.set("Database.AutoCleanup.MaxInactiveDays", -1);
|
||||
config.set("Database.Tables.Fields.Backpack.LastUpdate", "lastupdate");
|
||||
case 6:
|
||||
config.set("show_close_message", true);
|
||||
case 7:
|
||||
config.set("full_inventory.collect_items", false);
|
||||
config.set("full_inventory.check_interval", 1); // in seconds
|
||||
config.set("full_inventory.collect_radius", 1.5); // in blocks
|
||||
break;
|
||||
case CONFIG_VERSION: return false;
|
||||
default: MP.log.info("Config File Version newer than expected!"); return false;
|
||||
}
|
||||
config.set("Version", CONFIG_VERSION);
|
||||
try
|
||||
{
|
||||
config.save(file);
|
||||
MP.log.info("Config File has been updated.");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
config.set("Database.UseUUIDs", Bukkit.getServer().getOnlineMode() && isBukkitVersionUUIDCompatible());
|
||||
return true;
|
||||
}
|
||||
|
||||
public String GetLanguage()
|
||||
@Override
|
||||
protected void doUpdate(int version)
|
||||
{
|
||||
return config.getString("Language");
|
||||
// Nothing to update yet
|
||||
}
|
||||
|
||||
public String GetLanguageUpdateMode()
|
||||
{
|
||||
return config.getString("LanguageUpdateMode");
|
||||
}
|
||||
|
||||
public int GetAutoCleanupMaxInactiveDays()
|
||||
|
||||
// Getter
|
||||
public int getAutoCleanupMaxInactiveDays()
|
||||
{
|
||||
return config.getInt("Database.AutoCleanup.MaxInactiveDays", -1);
|
||||
}
|
||||
|
||||
public String GetDatabaseType()
|
||||
public String getDatabaseType()
|
||||
{
|
||||
return config.getString("Database.Type");
|
||||
}
|
||||
|
||||
public String GetMySQLHost()
|
||||
public String getMySQLHost()
|
||||
{
|
||||
return config.getString("Database.MySQL.Host");
|
||||
}
|
||||
|
||||
public String GetMySQLDatabase()
|
||||
public String getMySQLDatabase()
|
||||
{
|
||||
return config.getString("Database.MySQL.Database");
|
||||
}
|
||||
|
||||
public String GetMySQLUser()
|
||||
public String getMySQLUser()
|
||||
{
|
||||
return config.getString("Database.MySQL.User");
|
||||
}
|
||||
|
||||
public String GetMySQLPassword()
|
||||
public String getMySQLPassword()
|
||||
{
|
||||
return config.getString("Database.MySQL.Password");
|
||||
}
|
||||
@ -242,7 +112,7 @@ public boolean getUseUUIDSeparators()
|
||||
|
||||
public String getBPTitle()
|
||||
{
|
||||
return config.getString("BackpackTitle", "%s Backpack");
|
||||
return ChatColor.translateAlternateColorCodes('&', config.getString("BackpackTitle", "%s Backpack"));
|
||||
}
|
||||
|
||||
public boolean getDropOnDeath()
|
||||
|
@ -33,7 +33,7 @@ public class Database
|
||||
protected boolean UseUUIDs, UseUUIDSeparators;
|
||||
protected long maxAge;
|
||||
|
||||
private HashSet<Backpack> backpacks = new HashSet<Backpack>();
|
||||
private HashSet<Backpack> backpacks = new HashSet<>();
|
||||
protected ItemStackSerializer itsSerializer = new ItemStackSerializer();
|
||||
|
||||
public Database(MinePacks mp)
|
||||
@ -41,12 +41,12 @@ public Database(MinePacks mp)
|
||||
plugin = mp;
|
||||
UseUUIDSeparators = plugin.config.getUseUUIDSeparators();
|
||||
UseUUIDs = plugin.config.UseUUIDs();
|
||||
maxAge = plugin.config.GetAutoCleanupMaxInactiveDays();
|
||||
maxAge = plugin.config.getAutoCleanupMaxInactiveDays();
|
||||
}
|
||||
|
||||
public void Close() { }
|
||||
public void close() { }
|
||||
|
||||
protected String GetPlayerNameOrUUID(OfflinePlayer player)
|
||||
protected String getPlayerNameOrUUID(OfflinePlayer player)
|
||||
{
|
||||
if(UseUUIDs)
|
||||
{
|
||||
@ -67,9 +67,10 @@ protected String GetPlayerNameOrUUID(OfflinePlayer player)
|
||||
|
||||
public static Database getDatabase(MinePacks Plugin)
|
||||
{
|
||||
switch(Plugin.config.GetDatabaseType().toLowerCase())
|
||||
switch(Plugin.config.getDatabaseType().toLowerCase())
|
||||
{
|
||||
case "mysql": return new MySQL(Plugin);
|
||||
case "flat":
|
||||
case "file":
|
||||
case "files": return new Files(Plugin);
|
||||
case "sqlite":
|
||||
@ -101,12 +102,12 @@ public Backpack getBackpack(String title)
|
||||
return null;
|
||||
}
|
||||
|
||||
public Backpack getBackpack(OfflinePlayer player, boolean loadedonly)
|
||||
public Backpack getBackpack(OfflinePlayer player, boolean loadedOnly)
|
||||
{
|
||||
Backpack lbp = findBackpack(player);
|
||||
if(lbp == null && !loadedonly)
|
||||
if(lbp == null && !loadedOnly)
|
||||
{
|
||||
lbp = LoadBackpack(player);
|
||||
lbp = loadBackpack(player);
|
||||
if(lbp == null)
|
||||
{
|
||||
lbp = new Backpack(player);
|
||||
@ -123,9 +124,9 @@ public void UnloadBackpack(Backpack backpack)
|
||||
|
||||
// DB Functions
|
||||
|
||||
public void UpdatePlayer(Player player) {}
|
||||
public void updatePlayer(Player player) {}
|
||||
|
||||
public void SaveBackpack(Backpack backpack) {}
|
||||
public void saveBackpack(Backpack backpack) {}
|
||||
|
||||
public Backpack LoadBackpack(OfflinePlayer player) { return null; }
|
||||
public Backpack loadBackpack(OfflinePlayer player) { return null; }
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import at.pcgamingfreaks.UUIDConverter;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import at.pcgamingfreaks.georgh.MinePacks.Backpack;
|
||||
@ -42,6 +43,7 @@ public Files(MinePacks mp)
|
||||
saveFolder = new File(plugin.getDataFolder(), "backpacks");
|
||||
if(!saveFolder.exists())
|
||||
{
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
saveFolder.mkdirs();
|
||||
}
|
||||
else
|
||||
@ -50,6 +52,7 @@ public Files(MinePacks mp)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private void CheckFiles()
|
||||
{
|
||||
File[] allFiles = saveFolder.listFiles(new BackpackFileFilter());
|
||||
@ -59,7 +62,7 @@ private void CheckFiles()
|
||||
if(maxAge > 0 && (new Date()).getTime() - file.lastModified() > maxAge) // Check if the file is older then x days
|
||||
{
|
||||
file.delete(); // Delete old files
|
||||
continue; // We don't have to check if the file name is correct cause we have the delted the file
|
||||
continue; // We don't have to check if the file name is correct cause we have the deleted the file
|
||||
}
|
||||
len = file.getName().length() - ext.length();
|
||||
if(UseUUIDs) // Use UUID-based saving
|
||||
@ -90,7 +93,7 @@ private void CheckFiles()
|
||||
{
|
||||
if(len > 16) // We only have to rename it if it's name is more than 16 chars (minecraft max player name length)
|
||||
{
|
||||
file.renameTo(new File(saveFolder, UUIDConverter.getNameFromUUID(file.getName().substring(0, len)) + ext));
|
||||
file.renameTo(new File(saveFolder, UUIDConverter.getNameFromUUID(file.getName().substring(0, len)) + ext))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -98,18 +101,18 @@ private void CheckFiles()
|
||||
|
||||
private String getFileName(OfflinePlayer player)
|
||||
{
|
||||
return GetPlayerNameOrUUID(player) + ext;
|
||||
return getPlayerNameOrUUID(player) + ext;
|
||||
}
|
||||
|
||||
// DB Functions
|
||||
public void SaveBackpack(Backpack backpack)
|
||||
public void saveBackpack(Backpack backpack)
|
||||
{
|
||||
File save = new File(saveFolder, getFileName(backpack.getOwner()));
|
||||
try
|
||||
{
|
||||
FileOutputStream fos = new FileOutputStream(save);
|
||||
fos.write(itsSerializer.getUsedVersion());
|
||||
fos.write(itsSerializer.Serialize(backpack.getBackpack()));
|
||||
fos.write(itsSerializer.serialize(backpack.getBackpack()));
|
||||
fos.flush();
|
||||
fos.close();
|
||||
}
|
||||
@ -119,7 +122,7 @@ public void SaveBackpack(Backpack backpack)
|
||||
}
|
||||
}
|
||||
|
||||
public Backpack LoadBackpack(OfflinePlayer player)
|
||||
public Backpack loadBackpack(OfflinePlayer player)
|
||||
{
|
||||
File save = new File(saveFolder, getFileName(player));
|
||||
try
|
||||
@ -129,9 +132,10 @@ public Backpack LoadBackpack(OfflinePlayer player)
|
||||
FileInputStream fis = new FileInputStream(save);
|
||||
int v = fis.read();
|
||||
byte[] out = new byte[(int)(save.length()-1)];
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
fis.read(out);
|
||||
fis.close();
|
||||
return new Backpack(player, itsSerializer.Deserialize(out, v), -1);
|
||||
return new Backpack(player, itsSerializer.deserialize(out, v), -1);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
@ -174,11 +178,7 @@ public boolean accept(File file)
|
||||
@Override
|
||||
public boolean accept(File dir, String name)
|
||||
{
|
||||
if ((name.endsWith(extension) && (name.charAt(name.length() - extension.length() - 1)) == '.'))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return (name.endsWith(extension) && (name.charAt(name.length() - extension.length() - 1)) == '.');
|
||||
}
|
||||
}
|
||||
}
|
@ -17,106 +17,24 @@
|
||||
|
||||
package at.pcgamingfreaks.georgh.MinePacks.Database;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
|
||||
import at.pcgamingfreaks.georgh.MinePacks.MinePacks;
|
||||
|
||||
public class Language
|
||||
public class Language extends at.pcgamingfreaks.Bukkit.Language
|
||||
{
|
||||
private MinePacks MP;
|
||||
private FileConfiguration lang;
|
||||
private static final int LANG_VERSION = 3;
|
||||
|
||||
public Language(MinePacks mp)
|
||||
public Language(JavaPlugin plugin)
|
||||
{
|
||||
MP = mp;
|
||||
LoadFile();
|
||||
super(plugin, LANG_VERSION);
|
||||
}
|
||||
|
||||
public String Get(String Option)
|
||||
protected void doUpdate(int version)
|
||||
{
|
||||
return lang.getString("Language." + Option, "§cMessage not found!");
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
LoadFile();
|
||||
}
|
||||
|
||||
private void LoadFile()
|
||||
{
|
||||
File file = new File(MP.getDataFolder() + File.separator + "Lang", MP.config.GetLanguage()+".yml");
|
||||
if(!file.exists())
|
||||
switch(version)
|
||||
{
|
||||
ExtractLangFile(file);
|
||||
}
|
||||
lang = YamlConfiguration.loadConfiguration(file);
|
||||
UpdateLangFile(file);
|
||||
}
|
||||
|
||||
private void ExtractLangFile(File Target)
|
||||
{
|
||||
try
|
||||
{
|
||||
MP.saveResource("Lang" + File.separator + MP.config.GetLanguage() + ".yml", true);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
File file_en = new File(MP.getDataFolder() + File.separator + "Lang", "en.yml");
|
||||
if(!file_en.exists())
|
||||
{
|
||||
MP.saveResource("Lang" + File.separator + "en.yml", true);
|
||||
}
|
||||
Files.copy(file_en, Target);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
case 1: lang.set("Language.Ingame.Cooldown", "Please wait till you reopen your backpack.");
|
||||
case 2: lang.set("Language.Ingame.InvalidBackpack", lang.getString("Language.Ingame.IvalidBackpack", "Invalid backpack."));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean UpdateLangFile(File file)
|
||||
{
|
||||
if(lang.getInt("Version") != LANG_VERSION)
|
||||
{
|
||||
if(MP.config.GetLanguageUpdateMode().equalsIgnoreCase("overwrite"))
|
||||
{
|
||||
ExtractLangFile(file);
|
||||
LoadFile();
|
||||
MP.log.info(Get("Console.LangUpdated"));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(lang.getInt("Version"))
|
||||
{
|
||||
case 1: lang.set("Language.Ingame.Cooldown", "Please wait till you reopen your backpack.");
|
||||
case 2: lang.set("Language.Ingame.InvalidBackpack", lang.getString("Language.Ingame.IvalidBackpack", "Invalid backpack."));
|
||||
break;
|
||||
default: MP.log.warning("Language File Version newer than expected!"); return false;
|
||||
}
|
||||
lang.set("Version", LANG_VERSION);
|
||||
try
|
||||
{
|
||||
lang.save(file);
|
||||
MP.log.info(Get("Console.LangUpdated"));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import at.pcgamingfreaks.UUIDConverter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import at.pcgamingfreaks.georgh.MinePacks.MinePacks;
|
||||
@ -71,7 +72,7 @@ protected void CheckUUIDs()
|
||||
{
|
||||
if(res.isFirst())
|
||||
{
|
||||
plugin.log.info(plugin.lang.Get("Console.UpdateUUIDs"));
|
||||
plugin.log.info(plugin.lang.get("Console.UpdateUUIDs"));
|
||||
}
|
||||
converter.add("UPDATE `" + Table_Players + "` SET `" + Field_UUID + "`='" + UUIDConverter.getUUIDFromName(res.getString(2), true, UseUUIDSeparators) + "' WHERE `" + Field_PlayerID + "`='" + res.getInt(1) + "'");
|
||||
}
|
||||
@ -81,7 +82,7 @@ protected void CheckUUIDs()
|
||||
{
|
||||
stmt.execute(string);
|
||||
}
|
||||
plugin.log.info(String.format(plugin.lang.Get("Console.UpdatedUUIDs"), converter.size()));
|
||||
plugin.log.info(String.format(plugin.lang.get("Console.UpdatedUUIDs"), converter.size()));
|
||||
}
|
||||
res.close();
|
||||
res = null;
|
||||
@ -92,7 +93,7 @@ protected void CheckUUIDs()
|
||||
{
|
||||
if(res.isFirst())
|
||||
{
|
||||
plugin.log.info(plugin.lang.Get("Console.UpdateUUIDs"));
|
||||
plugin.log.info(plugin.lang.get("Console.UpdateUUIDs"));
|
||||
}
|
||||
converter.add("UPDATE `" + Table_Players + "` SET `" + Field_UUID + "`='" + res.getString(2).replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5") + "' WHERE `" + Field_PlayerID + "`='" + res.getInt(1) + "'");
|
||||
}
|
||||
@ -102,7 +103,7 @@ protected void CheckUUIDs()
|
||||
{
|
||||
stmt.execute(string);
|
||||
}
|
||||
plugin.log.info(String.format(plugin.lang.Get("Console.UpdatedUUIDs"), converter.size()));
|
||||
plugin.log.info(String.format(plugin.lang.get("Console.UpdatedUUIDs"), converter.size()));
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -112,7 +113,7 @@ protected void CheckUUIDs()
|
||||
{
|
||||
if(res.isFirst())
|
||||
{
|
||||
plugin.log.info(plugin.lang.Get("Console.UpdateUUIDs"));
|
||||
plugin.log.info(plugin.lang.get("Console.UpdateUUIDs"));
|
||||
}
|
||||
converter.add("UPDATE `" + Table_Players + "` SET `" + Field_UUID + "`='" + res.getString(2).replaceAll("-", "") + "' WHERE `" + Field_PlayerID + "`='" + res.getInt(1) + "'");
|
||||
}
|
||||
@ -122,7 +123,7 @@ protected void CheckUUIDs()
|
||||
{
|
||||
stmt.execute(string);
|
||||
}
|
||||
plugin.log.info(String.format(plugin.lang.Get("Console.UpdatedUUIDs"), converter.size()));
|
||||
plugin.log.info(String.format(plugin.lang.get("Console.UpdatedUUIDs"), converter.size()));
|
||||
}
|
||||
}
|
||||
res.close();
|
||||
@ -139,7 +140,7 @@ protected Connection GetConnection()
|
||||
{
|
||||
if(conn == null || conn.isClosed())
|
||||
{
|
||||
conn = DriverManager.getConnection("jdbc:mysql://" + plugin.config.GetMySQLHost() + "/" + plugin.config.GetMySQLDatabase() + "?autoReconnect=true&timeBetweenEvictionRunsMillis=300000&testWhileIdle=true", plugin.config.GetMySQLUser(), plugin.config.GetMySQLPassword());
|
||||
conn = DriverManager.getConnection("jdbc:mysql://" + plugin.config.getMySQLHost() + "/" + plugin.config.getMySQLDatabase() + "?autoReconnect=true&timeBetweenEvictionRunsMillis=300000&testWhileIdle=true", plugin.config.getMySQLUser(), plugin.config.getMySQLPassword());
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
@ -206,7 +207,7 @@ protected void AddDateFieldToQuery()
|
||||
}
|
||||
|
||||
// Plugin Functions
|
||||
public void UpdatePlayer(final Player player)
|
||||
public void updatePlayer(final Player player)
|
||||
{
|
||||
if(!UpdatePlayer)
|
||||
{
|
||||
@ -220,9 +221,9 @@ public void run()
|
||||
try
|
||||
{
|
||||
PreparedStatement ps;
|
||||
Connection con = DriverManager.getConnection("jdbc:mysql://" + plugin.config.GetMySQLHost() + "/" + plugin.config.GetMySQLDatabase(), plugin.config.GetMySQLUser(), plugin.config.GetMySQLPassword());;
|
||||
Connection con = DriverManager.getConnection("jdbc:mysql://" + plugin.config.getMySQLHost() + "/" + plugin.config.getMySQLDatabase(), plugin.config.getMySQLUser(), plugin.config.getMySQLPassword());;
|
||||
ps = con.prepareStatement(Query_UpdatePlayerGet);
|
||||
ps.setString(1, GetPlayerNameOrUUID(player));
|
||||
ps.setString(1, getPlayerNameOrUUID(player));
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if(rs.next())
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ public SQL(MinePacks mp)
|
||||
UpdatePlayer = plugin.config.getUpdatePlayer();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
public void close()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -107,12 +107,12 @@ protected void CheckUUIDs() { }
|
||||
protected void CheckDB() { }
|
||||
|
||||
// Plugin Functions
|
||||
public void UpdatePlayer(final Player player)
|
||||
public void updatePlayer(final Player player)
|
||||
{
|
||||
try
|
||||
{
|
||||
PreparedStatement ps = GetConnection().prepareStatement(Query_UpdatePlayerGet);
|
||||
ps.setString(1, GetPlayerNameOrUUID(player));
|
||||
ps.setString(1, getPlayerNameOrUUID(player));
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if(rs.next())
|
||||
{
|
||||
@ -147,7 +147,7 @@ public void UpdatePlayer(final Player player)
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveBackpack(Backpack backpack)
|
||||
public void saveBackpack(Backpack backpack)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -156,7 +156,7 @@ public void SaveBackpack(Backpack backpack)
|
||||
if(backpack.getID() <= 0)
|
||||
{
|
||||
ps = GetConnection().prepareStatement(Query_GetPlayerID);
|
||||
ps.setString(1, GetPlayerNameOrUUID(backpack.getOwner()));
|
||||
ps.setString(1, getPlayerNameOrUUID(backpack.getOwner()));
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if(rs.next())
|
||||
{
|
||||
@ -171,7 +171,7 @@ public void SaveBackpack(Backpack backpack)
|
||||
ps.close();
|
||||
ps = GetConnection().prepareStatement(Query_InsertBP);
|
||||
ps.setInt(1, backpack.getID());
|
||||
ps.setBytes(2, itsSerializer.Serialize(backpack.getBackpack()));
|
||||
ps.setBytes(2, itsSerializer.serialize(backpack.getBackpack()));
|
||||
ps.setInt(3, itsSerializer.getUsedVersion());
|
||||
ps.execute();
|
||||
ps.close();
|
||||
@ -180,7 +180,7 @@ public void SaveBackpack(Backpack backpack)
|
||||
else
|
||||
{
|
||||
ps = GetConnection().prepareStatement(Query_UpdateBP);
|
||||
ps.setBytes(1, itsSerializer.Serialize(backpack.getBackpack()));
|
||||
ps.setBytes(1, itsSerializer.serialize(backpack.getBackpack()));
|
||||
ps.setInt(2, itsSerializer.getUsedVersion());
|
||||
ps.setInt(3, backpack.getID());
|
||||
}
|
||||
@ -193,20 +193,20 @@ public void SaveBackpack(Backpack backpack)
|
||||
}
|
||||
}
|
||||
|
||||
public Backpack LoadBackpack(OfflinePlayer player)
|
||||
public Backpack loadBackpack(OfflinePlayer player)
|
||||
{
|
||||
try
|
||||
{
|
||||
PreparedStatement ps = null; // Statement Variable
|
||||
ps = GetConnection().prepareStatement(Query_GetBP);
|
||||
ps.setString(1, GetPlayerNameOrUUID(player));
|
||||
ps.setString(1, getPlayerNameOrUUID(player));
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if(!rs.next())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int bpid = rs.getInt(1);
|
||||
ItemStack[] its = itsSerializer.Deserialize(rs.getBytes(2), rs.getInt(3));
|
||||
ItemStack[] its = itsSerializer.deserialize(rs.getBytes(2), rs.getInt(3));
|
||||
rs.close();
|
||||
ps.close();
|
||||
return new Backpack(player, its, bpid);
|
||||
|
@ -26,6 +26,7 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import at.pcgamingfreaks.UUIDConverter;
|
||||
import at.pcgamingfreaks.georgh.MinePacks.MinePacks;
|
||||
|
||||
public class SQLite extends SQL
|
||||
@ -47,7 +48,7 @@ public SQLite(MinePacks mp)
|
||||
UseUUIDSeparators = false;
|
||||
UpdatePlayer = true;
|
||||
|
||||
BuildQuerys(); // Build Querys
|
||||
BuildQuerys(); // Build Query's
|
||||
CheckDB(); // Check Database
|
||||
if(UseUUIDs && UpdatePlayer)
|
||||
{
|
||||
@ -140,7 +141,7 @@ protected void CheckUUIDs()
|
||||
{
|
||||
if(res.isFirst())
|
||||
{
|
||||
plugin.log.info(plugin.lang.Get("Console.UpdateUUIDs"));
|
||||
plugin.log.info(plugin.lang.get("Console.UpdateUUIDs"));
|
||||
}
|
||||
converter.add("UPDATE `" + Table_Players + "` SET `uuid`='" + UUIDConverter.getUUIDFromName(res.getString(1), plugin.getServer().getOnlineMode()) + "' WHERE `name`='" + res.getString(1).replace("\\", "\\\\").replace("'", "\\'") + "'");
|
||||
}
|
||||
@ -150,7 +151,7 @@ protected void CheckUUIDs()
|
||||
{
|
||||
stmt.execute(string);
|
||||
}
|
||||
plugin.log.info(String.format(plugin.lang.Get("Console.UpdatedUUIDs"),converter.size()));
|
||||
plugin.log.info(String.format(plugin.lang.get("Console.UpdatedUUIDs"),converter.size()));
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
|
@ -20,7 +20,7 @@ public ItemStackSerializer()
|
||||
{
|
||||
if(version[1].equals("8"))
|
||||
{
|
||||
if(version[2].equals("R1"))
|
||||
/*if(version[2].equals("R1"))
|
||||
{
|
||||
serializer = new MC_1_8_R1();
|
||||
}
|
||||
@ -31,11 +31,12 @@ else if(version[2].equals("R2"))
|
||||
else if(version[2].equals("R3"))
|
||||
{
|
||||
serializer = new MC_1_8_R3();
|
||||
}
|
||||
}*/
|
||||
serializer = new MC_1_8();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e){}
|
||||
catch(Exception e) {}
|
||||
if(serializer == null)
|
||||
{
|
||||
usedVersion = 0;
|
||||
@ -43,17 +44,17 @@ else if(version[2].equals("R3"))
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] Serialize(Inventory inv)
|
||||
public byte[] serialize(Inventory inv)
|
||||
{
|
||||
return serializer.toByteArray(inv);
|
||||
}
|
||||
|
||||
public ItemStack[] Deserialize(byte[] data)
|
||||
public ItemStack[] deserialize(byte[] data)
|
||||
{
|
||||
return serializer.toItemStack(data);
|
||||
}
|
||||
|
||||
public ItemStack[] Deserialize(byte[] data, int version)
|
||||
public ItemStack[] deserialize(byte[] data, int version)
|
||||
{
|
||||
if(version == 0)
|
||||
{
|
||||
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2014-2015 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package at.pcgamingfreaks.georgh.MinePacks.Database.Serializer;
|
||||
|
||||
import at.pcgamingfreaks.Bukkit.Refactor;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.Object;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class MC_1_8 extends Base
|
||||
{
|
||||
Class NBTTagCompound = Refactor.getNMSClass("NBTTagCompound"), NBTCompressedStreamTools = Refactor.getNMSClass("NBTCompressedStreamTools");
|
||||
Class CraftItemStack = Refactor.getOBCClass("inventory.CraftItemStack"), NMSItemStack = Refactor.getNMSClass("ItemStack");
|
||||
|
||||
Method setInt = Refactor.getMethod(NBTTagCompound, "setInt", String.class, int.class), a = Refactor.getMethod(NBTCompressedStreamTools, "a", NBTTagCompound, OutputStream.class);
|
||||
Method set = Refactor.getMethod(NBTTagCompound, "set", String.class, Refactor.getNMSClass("NBTBase")), save = Refactor.getMethod(NMSItemStack, "save", NBTTagCompound);
|
||||
Method asNMSCopy = Refactor.getMethod(CraftItemStack, "asNMSCopy", ItemStack.class), getInt = Refactor.getMethod(NBTTagCompound, "getInt", String.class);
|
||||
Method hasKeyOfType = Refactor.getMethod(NBTTagCompound, "hasKeyOfType", String.class, int.class), getCompound = Refactor.getMethod(NBTTagCompound, "getCompound", String.class);
|
||||
Method createStack = Refactor.getMethod(NMSItemStack, "createStack", NBTTagCompound), asBukkitCopy = Refactor.getMethod(CraftItemStack, "asBukkitCopy", NMSItemStack);
|
||||
Method ain = Refactor.getMethod(NBTCompressedStreamTools, "a", InputStream.class);
|
||||
|
||||
public byte[] toByteArray(Inventory inv)
|
||||
{
|
||||
byte[] ba = null;
|
||||
try
|
||||
{
|
||||
Object localNBTTagCompound = NBTTagCompound.newInstance();
|
||||
setInt.invoke(localNBTTagCompound, "size", inv.getSize());
|
||||
for (int i = 0; i < inv.getSize(); i++)
|
||||
{
|
||||
if (inv.getItem(i) != null)
|
||||
{
|
||||
set.invoke(localNBTTagCompound, String.valueOf(i), save.invoke(asNMSCopy.invoke(null, inv.getItem(i)), NBTTagCompound.newInstance()));
|
||||
}
|
||||
}
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
DataOutputStream w = new DataOutputStream(baos);
|
||||
a.invoke(null, localNBTTagCompound, w);
|
||||
w.flush();
|
||||
ba = baos.toByteArray();
|
||||
w.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ba;
|
||||
}
|
||||
|
||||
public ItemStack[] toItemStack(byte[] data)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
Object localNBTTagCompound = ain.invoke(null, new ByteArrayInputStream(data));
|
||||
int i = (int)getInt.invoke(localNBTTagCompound, "size");
|
||||
ItemStack[] its = new ItemStack[i];
|
||||
for (int k = 0; k < i; k++)
|
||||
{
|
||||
if ((boolean)hasKeyOfType.invoke(localNBTTagCompound, String.valueOf(k), 10))
|
||||
{
|
||||
its[k] = (ItemStack)asBukkitCopy.invoke(null, createStack.invoke(null, getCompound.invoke(localNBTTagCompound, String.valueOf(k))));
|
||||
}
|
||||
}
|
||||
return its;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014-2015 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package at.pcgamingfreaks.georgh.MinePacks.Database;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
public class UUIDConverter
|
||||
{
|
||||
public static String getNameFromUUID(String uuid)
|
||||
{
|
||||
String name = null;
|
||||
try
|
||||
{
|
||||
URL url = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid.replaceAll("-", ""));
|
||||
Scanner jsonScanner = new Scanner(url.openConnection().getInputStream(), "UTF-8");
|
||||
String json = jsonScanner.next();
|
||||
name = (((JSONObject)new JSONParser().parse(json)).get("name")).toString();
|
||||
jsonScanner.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("UUID not found at Mojang (probably offline mode UUID, try Bukkit offline player ...");
|
||||
if(!uuid.contains("-"))
|
||||
{
|
||||
uuid = uuid.replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5");
|
||||
}
|
||||
OfflinePlayer oP = Bukkit.getServer().getOfflinePlayer(UUID.fromString(uuid));
|
||||
if(oP != null)
|
||||
{
|
||||
name = oP.getName();
|
||||
}
|
||||
//e.printStackTrace();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public static String getUUIDFromName(String name, boolean onlinemode)
|
||||
{
|
||||
return getUUIDFromName(name, onlinemode, false);
|
||||
}
|
||||
|
||||
public static String getUUIDFromName(String name, boolean onlinemode, boolean withSeperators)
|
||||
{
|
||||
String uuid = null;
|
||||
if(onlinemode)
|
||||
{
|
||||
try
|
||||
{
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(new URL("https://api.mojang.com/users/profiles/minecraft/" + name).openStream()));
|
||||
uuid = (((JSONObject)new JSONParser().parse(in)).get("id")).toString().replaceAll("\"", "");
|
||||
in.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Unable to get UUID for: " + name + "! Giving offline UUID!");
|
||||
//e.printStackTrace();
|
||||
uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)).toString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)).toString();
|
||||
}
|
||||
if(uuid != null)
|
||||
{
|
||||
if(withSeperators)
|
||||
{
|
||||
if(!uuid.contains("-"))
|
||||
{
|
||||
return uuid = uuid.replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uuid = uuid.replaceAll("-", "");
|
||||
}
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
}
|
@ -17,7 +17,6 @@
|
||||
|
||||
package at.pcgamingfreaks.georgh.MinePacks;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -34,16 +33,16 @@ public class EventListener implements Listener
|
||||
private MinePacks plugin;
|
||||
private boolean drop_on_death, showCloseMessageOwn, showCloseMessageOther;
|
||||
|
||||
private String Message_OwnBPClose, Message_PlayerBPClose;
|
||||
private String message_OwnBPClose, message_PlayerBPClose;
|
||||
|
||||
public EventListener(MinePacks mp)
|
||||
{
|
||||
plugin = mp;
|
||||
drop_on_death = plugin.config.getDropOnDeath();
|
||||
Message_OwnBPClose = ChatColor.translateAlternateColorCodes('&', plugin.lang.Get("Ingame.OwnBackPackClose"));
|
||||
Message_PlayerBPClose = ChatColor.translateAlternateColorCodes('&', plugin.lang.Get("Ingame.PlayerBackPackClose"));
|
||||
showCloseMessageOther = Message_PlayerBPClose != null && plugin.config.getShowCloseMessage();
|
||||
showCloseMessageOwn = Message_OwnBPClose != null && plugin.config.getShowCloseMessage();
|
||||
message_OwnBPClose = plugin.lang.getTranslated("Ingame.OwnBackPackClose");
|
||||
message_PlayerBPClose = plugin.lang.getTranslated("Ingame.PlayerBackPackClose");
|
||||
showCloseMessageOther = message_PlayerBPClose != null && plugin.config.getShowCloseMessage();
|
||||
showCloseMessageOwn = message_OwnBPClose != null && plugin.config.getShowCloseMessage();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -53,16 +52,16 @@ public void onDeath(PlayerDeathEvent event)
|
||||
if (drop_on_death && !player.hasPermission("backpack.KeepOnDeath"))
|
||||
{
|
||||
Backpack backpack = plugin.DB.getBackpack(player, false);
|
||||
Inventory bpinv = backpack.getBackpack();
|
||||
for (ItemStack i : bpinv.getContents())
|
||||
Inventory backpackInventory = backpack.getBackpack();
|
||||
for (ItemStack i : backpackInventory.getContents())
|
||||
{
|
||||
if (i != null)
|
||||
{
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), i);
|
||||
bpinv.remove(i);
|
||||
backpackInventory.remove(i);
|
||||
}
|
||||
}
|
||||
plugin.DB.SaveBackpack(backpack);
|
||||
plugin.DB.saveBackpack(backpack);
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,21 +76,21 @@ public void onClose(InventoryCloseEvent event)
|
||||
Player closer = (Player)event.getPlayer();
|
||||
if(backpack.canEdit(closer))
|
||||
{
|
||||
plugin.DB.SaveBackpack(backpack);
|
||||
plugin.DB.saveBackpack(backpack);
|
||||
}
|
||||
backpack.Close(closer);
|
||||
if(event.getPlayer().getName().equals(backpack.getOwner().getName()))
|
||||
{
|
||||
if(showCloseMessageOwn)
|
||||
{
|
||||
closer.sendMessage(Message_OwnBPClose);
|
||||
closer.sendMessage(message_OwnBPClose);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(showCloseMessageOther)
|
||||
{
|
||||
closer.sendMessage(String.format(Message_PlayerBPClose, backpack.getOwner().getName()));
|
||||
closer.sendMessage(String.format(message_PlayerBPClose, backpack.getOwner().getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -114,7 +113,7 @@ public void onClick(InventoryClickEvent event)
|
||||
@EventHandler
|
||||
public void PlayerLoginEvent(PlayerJoinEvent event)
|
||||
{
|
||||
plugin.DB.UpdatePlayer(event.getPlayer());
|
||||
plugin.DB.updatePlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -35,10 +35,10 @@ public class MinePacks extends JavaPlugin
|
||||
{
|
||||
public final Logger log = getLogger();
|
||||
public final Config config = new Config(this);
|
||||
public Language lang;
|
||||
public final Language lang = new Language(this);
|
||||
public Database DB;
|
||||
|
||||
public HashMap<Player, Long> cooldowns = new HashMap<Player, Long>();
|
||||
public HashMap<Player, Long> cooldowns = new HashMap<>();
|
||||
|
||||
public static String BackpackTitle;
|
||||
public String Message_InvalidBackpack;
|
||||
@ -46,7 +46,7 @@ public class MinePacks extends JavaPlugin
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
lang = new Language(this);
|
||||
lang.load(config.getLanguage(), config.getLanguageUpdateMode());
|
||||
DB = Database.getDatabase(this);
|
||||
getCommand("backpack").setExecutor(new OnCommand(this));
|
||||
getServer().getPluginManager().registerEvents(new EventListener(this), this);
|
||||
@ -56,22 +56,22 @@ public void onEnable()
|
||||
(new ItemsCollector(this)).runTaskTimerAsynchronously(this, config.getFullInvCheckInterval(), config.getFullInvCheckInterval());
|
||||
}
|
||||
|
||||
BackpackTitle = config.getBPTitle();
|
||||
Message_InvalidBackpack = ChatColor.translateAlternateColorCodes('&', ChatColor.RED + lang.Get("Ingame.InvalidBackpack"));
|
||||
BackpackTitle = (config.getBPTitle().contains("%s") ? config.getBPTitle() : ChatColor.AQUA + "%s Backpack");
|
||||
Message_InvalidBackpack = lang.getTranslated("Ingame.InvalidBackpack");
|
||||
getServer().getServicesManager().register(MinePacks.class, this, this, ServicePriority.Normal);
|
||||
log.info(lang.Get("Console.Enabled"));
|
||||
log.info(lang.get("Console.Enabled"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
DB.Close();
|
||||
DB.close();
|
||||
if(config.getAutoUpdate())
|
||||
{
|
||||
new Bukkit_Updater(this, 83445, this.getFile(), UpdateType.DEFAULT, true);
|
||||
}
|
||||
log.info(lang.Get("Console.Disabled"));
|
||||
log.info(lang.get("Console.Disabled"));
|
||||
}
|
||||
|
||||
public void OpenBackpack(Player opener, OfflinePlayer owner, boolean editable)
|
||||
@ -91,41 +91,13 @@ public void OpenBackpack(Player opener, Backpack backpack, boolean editable)
|
||||
|
||||
public int getBackpackPermSize(Player player)
|
||||
{
|
||||
if(player.hasPermission("backpack.size.9"))
|
||||
for(int i = 9; i > 1; i--)
|
||||
{
|
||||
return 81;
|
||||
}
|
||||
else if(player.hasPermission("backpack.size.8"))
|
||||
{
|
||||
return 72;
|
||||
}
|
||||
else if(player.hasPermission("backpack.size.7"))
|
||||
{
|
||||
return 63;
|
||||
}
|
||||
else if(player.hasPermission("backpack.size.6"))
|
||||
{
|
||||
return 54;
|
||||
}
|
||||
else if(player.hasPermission("backpack.size.5"))
|
||||
{
|
||||
return 45;
|
||||
}
|
||||
else if(player.hasPermission("backpack.size.4"))
|
||||
{
|
||||
return 36;
|
||||
}
|
||||
else if(player.hasPermission("backpack.size.3"))
|
||||
{
|
||||
return 27;
|
||||
}
|
||||
else if(player.hasPermission("backpack.size.2"))
|
||||
{
|
||||
return 18;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 9;
|
||||
if(player.hasPermission("backpack.size." + i))
|
||||
{
|
||||
return i * 9;
|
||||
}
|
||||
}
|
||||
return 9;
|
||||
}
|
||||
}
|
@ -33,18 +33,17 @@ public class OnCommand implements CommandExecutor
|
||||
{
|
||||
private MinePacks plugin;
|
||||
|
||||
public String Message_NotFromConsole, Message_NoPermission, Message_IvalidBackpack, Message_BackpackCleaned, Message_Cooldown;
|
||||
public String Message_NotFromConsole, Message_NoPermission, Message_BackpackCleaned, Message_Cooldown;
|
||||
|
||||
public int cooldown;
|
||||
|
||||
public OnCommand(MinePacks mp)
|
||||
{
|
||||
plugin = mp;
|
||||
Message_NotFromConsole = ChatColor.translateAlternateColorCodes('&', plugin.lang.Get("Console.NotFromConsole"));
|
||||
Message_NoPermission = ChatColor.translateAlternateColorCodes('&', ChatColor.RED + plugin.lang.Get("Ingame.NoPermission"));
|
||||
Message_IvalidBackpack = ChatColor.translateAlternateColorCodes('&', ChatColor.RED + plugin.lang.Get("Ingame.IvalidBackpack"));
|
||||
Message_BackpackCleaned = ChatColor.translateAlternateColorCodes('&', ChatColor.DARK_GREEN + plugin.lang.Get("Ingame.BackpackCleaned"));
|
||||
Message_Cooldown = ChatColor.translateAlternateColorCodes('&', ChatColor.DARK_GREEN + plugin.lang.Get("Ingame.Cooldown"));
|
||||
Message_NotFromConsole = plugin.lang.getTranslated("Console.NotFromConsole");
|
||||
Message_NoPermission = ChatColor.RED + plugin.lang.getTranslated("Ingame.NoPermission");
|
||||
Message_BackpackCleaned = ChatColor.DARK_GREEN + plugin.lang.getTranslated("Ingame.BackpackCleaned");
|
||||
Message_Cooldown = ChatColor.DARK_GREEN + plugin.lang.getTranslated("Ingame.Cooldown");
|
||||
cooldown = plugin.config.getCommandCooldown();
|
||||
}
|
||||
|
||||
@ -52,7 +51,7 @@ public OnCommand(MinePacks mp)
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String arg, String[] args)
|
||||
{
|
||||
Player player = null;
|
||||
Player player;
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
player = (Player) sender;
|
||||
@ -71,18 +70,18 @@ public boolean onCommand(CommandSender sender, Command cmd, String arg, String[]
|
||||
{
|
||||
if(plugin.cooldowns.containsKey(player))
|
||||
{
|
||||
if(((new Date()).getTime() - plugin.cooldowns.get(player).longValue()) < cooldown)
|
||||
if(((new Date()).getTime() - plugin.cooldowns.get(player)) < cooldown)
|
||||
{
|
||||
sender.sendMessage(Message_Cooldown);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
plugin.cooldowns.put(player, new Long((new Date()).getTime()));
|
||||
plugin.cooldowns.put(player, (new Date()).getTime());
|
||||
}
|
||||
Backpack bp = plugin.DB.getBackpack(player, false);
|
||||
if(bp == null)
|
||||
{
|
||||
player.sendMessage(Message_IvalidBackpack);
|
||||
player.sendMessage(plugin.Message_InvalidBackpack);
|
||||
return true;
|
||||
}
|
||||
int size = plugin.getBackpackPermSize(player);
|
||||
@ -106,7 +105,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String arg, String[]
|
||||
}
|
||||
else
|
||||
{
|
||||
// Subcommands
|
||||
// Sub-commands
|
||||
switch(args[0].toLowerCase())
|
||||
{
|
||||
case "help": // Shows the help for the plugin
|
||||
@ -115,18 +114,18 @@ public boolean onCommand(CommandSender sender, Command cmd, String arg, String[]
|
||||
if(player.hasPermission("backpack"))
|
||||
{
|
||||
player.sendMessage(ChatColor.GOLD + "Minepacks Help:");
|
||||
player.sendMessage(ChatColor.AQUA + "/backpack" + ChatColor.WHITE + " - " + plugin.lang.Get("Description.Backpack"));
|
||||
player.sendMessage(ChatColor.AQUA + "/backpack" + ChatColor.WHITE + " - " + plugin.lang.getTranslated("Description.Backpack"));
|
||||
if(player.hasPermission("backpack.clean"))
|
||||
{
|
||||
player.sendMessage(ChatColor.AQUA + "/backpack clean" + ChatColor.WHITE + " - " + plugin.lang.Get("Description.Clean"));
|
||||
player.sendMessage(ChatColor.AQUA + "/backpack clean" + ChatColor.WHITE + " - " + plugin.lang.getTranslated("Description.Clean"));
|
||||
}
|
||||
if(player.hasPermission("backpack.clean.other"))
|
||||
{
|
||||
player.sendMessage(ChatColor.AQUA + "/backpack clean <playername>" + ChatColor.WHITE + " - " + plugin.lang.Get("Description.CleanOther"));
|
||||
player.sendMessage(ChatColor.AQUA + "/backpack clean <playername>" + ChatColor.WHITE + " - " + plugin.lang.getTranslated("Description.CleanOther"));
|
||||
}
|
||||
if(player.hasPermission("backpack.other"))
|
||||
{
|
||||
player.sendMessage(ChatColor.AQUA + "/backpack <playername>" + ChatColor.WHITE + " - " + plugin.lang.Get("Description.View"));
|
||||
player.sendMessage(ChatColor.AQUA + "/backpack <playername>" + ChatColor.WHITE + " - " + plugin.lang.getTranslated("Description.View"));
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -146,7 +145,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String arg, String[]
|
||||
}
|
||||
Backpack BP = plugin.DB.getBackpack(OP, false);
|
||||
BP.getBackpack().clear();
|
||||
plugin.DB.SaveBackpack(BP);
|
||||
plugin.DB.saveBackpack(BP);
|
||||
player.sendMessage(Message_BackpackCleaned);
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user