Fixed sync db Logger.java
Added temp test code in player tracker...ignore. fixed bug in dynamic server sorter.
This commit is contained in:
parent
d2caf23ed7
commit
c265c7ce5c
@ -3,16 +3,19 @@ package mineplex.core.logger;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class Logger
|
public class Logger
|
||||||
{
|
{
|
||||||
public static Logger Instance;
|
public static Logger Instance;
|
||||||
|
|
||||||
|
private static JavaPlugin _plugin;
|
||||||
private LoggerRepository _repository;
|
private LoggerRepository _repository;
|
||||||
|
|
||||||
public static void initialize(JavaPlugin plugin)
|
public static void initialize(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
|
_plugin = plugin;
|
||||||
Instance = new Logger(plugin);
|
Instance = new Logger(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,14 +50,20 @@ public class Logger
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(String message)
|
public void log(final String message)
|
||||||
{
|
{
|
||||||
_repository.saveLog(message);
|
Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_repository.saveLog(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(Throwable exception)
|
public void log(Throwable exception)
|
||||||
{
|
{
|
||||||
List<String> messages = new ArrayList<String>();
|
final List<String> messages = new ArrayList<String>();
|
||||||
|
|
||||||
messages.add("[Exception Start]" + exception.getMessage());
|
messages.add("[Exception Start]" + exception.getMessage());
|
||||||
|
|
||||||
@ -65,6 +74,12 @@ public class Logger
|
|||||||
|
|
||||||
messages.add("[Exception End]");
|
messages.add("[Exception End]");
|
||||||
|
|
||||||
_repository.saveLog(messages.toArray(new String[0]));
|
Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_repository.saveLog(messages.toArray(new String[0]));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,20 @@
|
|||||||
package mineplex.core.playerTracker;
|
package mineplex.core.playerTracker;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import javax.crypto.Mac;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Hex;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.libs.com.google.gson.Gson;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -8,18 +22,88 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import mineplex.core.MiniPlugin;
|
import mineplex.core.MiniPlugin;
|
||||||
import mineplex.core.account.event.ClientUnloadEvent;
|
import mineplex.core.account.event.ClientUnloadEvent;
|
||||||
|
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||||
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||||
|
|
||||||
public class PlayerTracker extends MiniPlugin
|
public class PlayerTracker extends MiniPlugin
|
||||||
{
|
{
|
||||||
private PlayerTrackerRepository _repository = null;
|
private PlayerTrackerRepository _repository = null;
|
||||||
|
|
||||||
public PlayerTracker(JavaPlugin plugin, String serverName, boolean us)
|
public PlayerTracker(JavaPlugin plugin, String serverName, boolean us)
|
||||||
{
|
{
|
||||||
super("Player Tracker", plugin);
|
super("Player Tracker", plugin);
|
||||||
|
|
||||||
_repository = new PlayerTrackerRepository();
|
_repository = new PlayerTrackerRepository();
|
||||||
_repository.initialize(serverName, us);
|
_repository.initialize(serverName, us);
|
||||||
|
|
||||||
|
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||||
|
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||||
|
|
||||||
|
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
|
||||||
|
connectionManager.setMaxTotal(200);
|
||||||
|
connectionManager.setDefaultMaxPerRoute(20);
|
||||||
|
|
||||||
|
HttpClient httpClient = new DefaultHttpClient(connectionManager);
|
||||||
|
InputStream in = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
HttpGet request = new HttpGet("http://api.dnsmadeeasy.com/V2.0/dns/managed/962728/records/");
|
||||||
|
|
||||||
|
String timeStamp = getServerTime();
|
||||||
|
SecretKeySpec keySpec = new SecretKeySpec("8c9af8cc-d306-4df3-8de8-944deafa8239".getBytes(), "HmacSHA1");
|
||||||
|
Mac mac = Mac.getInstance("HmacSHA1");
|
||||||
|
mac.init(keySpec);
|
||||||
|
byte[] hashBytes = mac.doFinal((timeStamp + "").getBytes());
|
||||||
|
Hex.encodeHexString(hashBytes);
|
||||||
|
|
||||||
|
request.addHeader("x-dnsme-apiKey", "610e21ee-4250-4b55-b637-a1fcc3847850");
|
||||||
|
request.addHeader("x-dnsme-requestDate", timeStamp + "");
|
||||||
|
request.addHeader("x-dnsme-hmac", Hex.encodeHexString(hashBytes));
|
||||||
|
request.addHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
|
HttpResponse response = httpClient.execute(request);
|
||||||
|
|
||||||
|
if (response != null)
|
||||||
|
{
|
||||||
|
in = response.getEntity().getContent();
|
||||||
|
System.out.println(convertStreamToString(in));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.out.println("JsonWebCall.Execute() Error:\n" + ex.getMessage());
|
||||||
|
|
||||||
|
for (StackTraceElement trace : ex.getStackTrace())
|
||||||
|
{
|
||||||
|
System.out.println(trace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
httpClient.getConnectionManager().shutdown();
|
||||||
|
|
||||||
|
if (in != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void trackPlayer(final PlayerJoinEvent event)
|
public void trackPlayer(final PlayerJoinEvent event)
|
||||||
{
|
{
|
||||||
@ -31,7 +115,7 @@ public class PlayerTracker extends MiniPlugin
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void untrackPlayer(final ClientUnloadEvent event)
|
public void untrackPlayer(final ClientUnloadEvent event)
|
||||||
{
|
{
|
||||||
@ -43,4 +127,43 @@ public class PlayerTracker extends MiniPlugin
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getServerTime()
|
||||||
|
{
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
|
||||||
|
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
return dateFormat.format(calendar.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String convertStreamToString(InputStream is)
|
||||||
|
{
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
String line = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while ((line = reader.readLine()) != null)
|
||||||
|
{
|
||||||
|
sb.append(line + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ public class Hub extends JavaPlugin implements IRelation
|
|||||||
PreferencesManager preferenceManager = new PreferencesManager(this, clientManager, donationManager);
|
PreferencesManager preferenceManager = new PreferencesManager(this, clientManager, donationManager);
|
||||||
preferenceManager.GiveItem = true;
|
preferenceManager.GiveItem = true;
|
||||||
new MessageManager(this, clientManager, preferenceManager);
|
new MessageManager(this, clientManager, preferenceManager);
|
||||||
Creature creature = new Creature(this);
|
Creature creature = new Creature(this);
|
||||||
NpcManager npcManager = new NpcManager(this, creature);
|
NpcManager npcManager = new NpcManager(this, creature);
|
||||||
PetManager petManager = new PetManager(this, clientManager, donationManager, creature, webServerAddress);
|
PetManager petManager = new PetManager(this, clientManager, donationManager, creature, webServerAddress);
|
||||||
new AntiStack(this);
|
new AntiStack(this);
|
||||||
|
@ -22,9 +22,9 @@ public class DynamicServerSorter implements Comparator<DynamicServerData>
|
|||||||
if (first.AvailableCPU > second.AvailableCPU)
|
if (first.AvailableCPU > second.AvailableCPU)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (second.AvailableCPU < first.AvailableCPU)
|
if (second.AvailableCPU > first.AvailableCPU)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in New Issue
Block a user