Skip to content

Commit

Permalink
Merge pull request #80 from Ben12345rocks/2.8.7
Browse files Browse the repository at this point in the history
2.8.7
  • Loading branch information
BenCodez committed Aug 27, 2017
2 parents 26335a2 + 45f09ed commit 833acd1
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 53 deletions.
2 changes: 1 addition & 1 deletion AdvancedCore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.Ben12345rocks</groupId>
<artifactId>AdvancedCore</artifactId>
<version>2.8.6</version>
<version>2.8.7</version>
<packaging>jar</packaging>
<name>AdvancedCore</name>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public static AdvancedCoreHook getInstance() {
private ArrayList<JavascriptPlaceholderRequest> javascriptEngineRequests = new ArrayList<JavascriptPlaceholderRequest>();
private String version = "";
private String buildTime = "";
private int maxMysqlSize = -1;

public int getMaxMysqlSize() {
return maxMysqlSize;
}

public void setMaxMysqlSize(int maxMysqlSize) {
this.maxMysqlSize = maxMysqlSize;
}

private HashMap<String, Object> javascriptEngine = new HashMap<String, Object>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public PlayerJoinEvent(Plugin plugin) {
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerLogin(PlayerLoginEvent event) {
AdvancedCoreHook.getInstance()
.debug("Login: " + event.getPlayer().getName() + " (" + event.getPlayer().getUniqueId() + ")");
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {

@Override
Expand All @@ -65,6 +67,8 @@ public void run() {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerQuit(PlayerQuitEvent event) {
AdvancedCoreHook.getInstance()
.debug("Logout: " + event.getPlayer().getName() + " (" + event.getPlayer().getUniqueId() + ")");
final String uuid = event.getPlayer().getPlayer().getUniqueId().toString();
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,13 @@ public boolean hasPermission(String perm) {
}
return player.hasPermission(perm);
}

public void closeInv() {
Player player = getPlayer();
if (player != null) {
player.closeInventory();
}
}

/**
* Checks if is online.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ public ArrayList<String> getLore() {
public String getName() {
return is.getItemMeta().getDisplayName();
}

public boolean hasCustomDisplayName() {
return is.getItemMeta().hasDisplayName();
}

public boolean hasCustomLore() {
return is.getItemMeta().hasLore();
}

/**
* @return the skull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.Ben12345rocks.AdvancedCore.Util.Updater;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;

import javax.net.ssl.HttpsURLConnection;

import org.bukkit.plugin.java.JavaPlugin;

import com.Ben12345rocks.AdvancedCore.AdvancedCoreHook;

// TODO: Auto-generated Javadoc
/**
* The Class Updater.
Expand Down Expand Up @@ -40,26 +40,22 @@ public enum UpdateResult {
UPDATE_AVAILABLE
}

/** The api key. */
private final String API_KEY = "98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4";
// private final String API_KEY =
// "98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4";

/** The connection. */
private HttpURLConnection connection;
// private HttpURLConnection connection;

/** The host. */
private final String HOST = "http://www.spigotmc.org";
// private final String HOST = "http://www.spigotmc.org";

/** The old version. */
private String oldVersion;

/** The plugin. */
private JavaPlugin plugin;

/** The query. */
private final String QUERY = "/api/general.php";
// private final String QUERY = "/api/general.php";

/** The request method. */
private final String REQUEST_METHOD = "POST";
// private final String REQUEST_METHOD = "POST";

/** The resource id. */
private String RESOURCE_ID = "";
Expand All @@ -70,8 +66,7 @@ public enum UpdateResult {
/** The version. */
private String version;

/** The write string. */
private String WRITE_STRING;
// private String WRITE_STRING;

/**
* Instantiates a new updater.
Expand All @@ -93,14 +88,7 @@ public Updater(JavaPlugin plugin, Integer resourceId, boolean disabled) {
return;
}

try {
connection = (HttpURLConnection) new URL(HOST + QUERY).openConnection();
} catch (IOException e) {
result = UpdateResult.FAIL_SPIGOT;
return;
}

WRITE_STRING = "key=" + API_KEY + "&resource=" + RESOURCE_ID;
// WRITE_STRING = "key=" + API_KEY + "&resource=" + RESOURCE_ID;
run();
}

Expand All @@ -122,41 +110,39 @@ public String getVersion() {
return version;
}

/**
* Run.
*/
private void run() {
connection.setDoOutput(true);
try {
connection.setRequestMethod(REQUEST_METHOD);
connection.getOutputStream().write(WRITE_STRING.getBytes("UTF-8"));
} catch (ProtocolException e1) {
result = UpdateResult.FAIL_SPIGOT;
} catch (UnsupportedEncodingException e) {
result = UpdateResult.FAIL_SPIGOT;
} catch (IOException e) {
result = UpdateResult.FAIL_SPIGOT;
}
String version;
try {
version = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
if (version == null) {
result = UpdateResult.FAIL_SPIGOT;
return;
}
} catch (Exception e) {
result = UpdateResult.BAD_RESOURCEID;
return;
}
if (version.length() <= 7) {
this.version = version;
version.replace("[^A-Za-z]", "").replace("|", "");
HttpsURLConnection connection = (HttpsURLConnection) new URL(
"https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
int timed_out = 1250; // check if API is avaible, set your time as you want
connection.setConnectTimeout(timed_out);
connection.setReadTimeout(timed_out);
this.version = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
connection.disconnect();
versionCheck();
return;
} catch (Exception e) {
result = UpdateResult.FAIL_SPIGOT;
AdvancedCoreHook.getInstance().debug(e);
}
result = UpdateResult.BAD_RESOURCEID;
result = UpdateResult.FAIL_SPIGOT;
}

/*
* private void run() { connection.setDoOutput(true); try {
* connection.setRequestMethod(REQUEST_METHOD);
* connection.getOutputStream().write(WRITE_STRING.getBytes("UTF-8")); } catch
* (ProtocolException e1) { result = UpdateResult.FAIL_SPIGOT; } catch
* (UnsupportedEncodingException e) { result = UpdateResult.FAIL_SPIGOT; } catch
* (IOException e) { result = UpdateResult.FAIL_SPIGOT; } String version; try {
* version = new BufferedReader(new
* InputStreamReader(connection.getInputStream())).readLine(); if (version ==
* null) { result = UpdateResult.FAIL_SPIGOT; return; } } catch (Exception e) {
* result = UpdateResult.BAD_RESOURCEID; return; } if (version.length() <= 7) {
* this.version = version; version.replace("[^A-Za-z]", "").replace("|", "");
* versionCheck(); return; } result = UpdateResult.BAD_RESOURCEID; }
*/

/**
* Should update.
*
Expand Down
10 changes: 10 additions & 0 deletions AdvancedCore/src/com/Ben12345rocks/AdvancedCore/mysql/MySQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public ArrayList<Column> load(String key) {

public MySQL(String tableName, String hostName, int port, String database, String user, String pass,
int maxThreads) {
if (AdvancedCoreHook.getInstance().getMaxMysqlSize() >= 0) {
table = CompatibleCacheBuilder.newBuilder().concurrencyLevel(4).expireAfterAccess(20, TimeUnit.MINUTES)
.maximumSize(AdvancedCoreHook.getInstance().getMaxMysqlSize())
.build(new CacheLoader<String, ArrayList<Column>>() {
@Override
public ArrayList<Column> load(String key) {
return getExactQuery(new Column("uuid", key, DataType.STRING));
}
});
}
name = tableName;
mysql = new com.Ben12345rocks.AdvancedCore.mysql.api.MySQL(maxThreads);
if (!mysql.connect(hostName, "" + port, user, pass, database)) {
Expand Down

0 comments on commit 833acd1

Please sign in to comment.