v1.2.1 Update

Hello, this is just a small update.

Changes:
  - Updater Message has been moved to async to stop any lag from coming
from it.
  - Internal auto updater has been moved to async to protect from
making lag.

Added:
  - New MCUpdate metrics. http://mcupdate.org/plugin?pl=61
This commit is contained in:
BadBones69 2017-04-06 15:14:21 -04:00
parent 3f2b71008c
commit e864040e28
5 changed files with 195 additions and 10 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="/Users/Joe/Plugins/Spigot/Spigot 1.10.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/Joe/Desktop/Stuff/Spigot/Spigot%201.10%20JavaDoc.jar!/"/>

5
Notes
View File

@ -4,7 +4,8 @@ Features:
(Bug) When you collect an item from the expired list with a fully inventory, the item gets lost.
Changes:
- Updated Metrics.
- Updater Message has been moved to async to stop any lag from coming from it.
- Internal auto updater has been moved to async to protect from making lag.
Added:
- The help menu can now be changed in the Messages.yml.
- New MCUpdate metrics. http://mcupdate.org/plugin?pl=61

View File

@ -2,7 +2,7 @@ name: CrazyAuctions
author: BadBones69
main: me.badbones69.crazyauctions.Main
website: https://www.spigotmc.org/resources/authors/kicjow.9719/
version: 1.2
version: 1.2.1
depend: [Vault]
description: >
A plugin to auction off items globally.

View File

@ -15,6 +15,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import me.badbones69.crazyauctions.currency.Vault;
@ -53,6 +54,9 @@ public class Main extends JavaPlugin implements Listener{
} catch (IOException e) {
System.out.println("Error Submitting stats!");
}
try {
new MCUpdate(this, true);
} catch (IOException e) {}
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args){
@ -280,7 +284,7 @@ public class Main extends JavaPlugin implements Listener{
@EventHandler
public void onJoin(PlayerJoinEvent e){
final Player player = e.getPlayer();
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
new BukkitRunnable(){
@Override
public void run() {
if(player.getName().equals("BadBones69")){
@ -291,16 +295,16 @@ public class Main extends JavaPlugin implements Listener{
Methods.hasUpdate(player);
}
}
}, 40);
}.runTaskLaterAsynchronously(this, 40);
}
private void startCheck(){
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
new BukkitRunnable(){
@Override
public void run() {
Methods.updateAuction();
}
}, 20, 5*20);
}.runTaskTimerAsynchronously(this, 20, 5*20);
}
private ArrayList<Material> getDamageableItems(){

View File

@ -0,0 +1,180 @@
package me.badbones69.crazyauctions;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;
public class MCUpdate implements Listener {
private final static String VERSION = "1.0";
private static final String BASE_URL = "http://report.mcupdate.org";
/**
* Server received information.
*/
private static String updateMessage = "";
private static boolean upToDate = true;
private Plugin pl;
/**
* Interval of time to ping (seconds)
*/
private int PING_INTERVAL;
/**
* The scheduled task
*/
private volatile BukkitTask task = null;
public MCUpdate(Plugin plugin, boolean startTask) throws IOException
{
if (plugin != null)
{
this.pl = plugin;
//I should add a custom configuration for MCUpdate itself
Bukkit.getPluginManager().registerEvents(this, plugin);
setPingInterval(900);
if (startTask)
{
start();
}
}
}
private boolean start() {
// Is MCUpdate already running?
if (task == null) {
// Begin hitting the server with glorious data
task = pl.getServer().getScheduler().runTaskTimerAsynchronously(pl, () -> {
report();
if (!upToDate) {
pl.getServer().getConsoleSender().sendMessage(format(updateMessage));
}
}, 0, PING_INTERVAL * 20);
}
return true;
}
private int getOnlinePlayers() {
try {
Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
if (onlinePlayerMethod.getReturnType().equals(Collection.class)) {
return ((Collection<?>) onlinePlayerMethod.invoke(Bukkit.getServer())).size();
} else {
return ((Player[]) onlinePlayerMethod.invoke(Bukkit.getServer())).length;
}
} catch (Exception ex) {
}
return 0;
}
private void report() {
String ver = pl.getDescription().getVersion();
String name = pl.getDescription().getName();
int playersOnline = this.getOnlinePlayers();
boolean onlineMode = pl.getServer().getOnlineMode();
String serverVersion = pl.getServer().getVersion();
String osname = System.getProperty("os.name");
String osarch = System.getProperty("os.arch");
String osversion = System.getProperty("os.version");
String java_version = System.getProperty("java.version");
int coreCount = Runtime.getRuntime().availableProcessors();
String report = "{ \"report\": {";
report += toJson("plugin", name) + ",";
report += toJson("version", ver) + ",";
report += toJson("playersonline", playersOnline + "") + ",";
report += toJson("onlinemode", onlineMode + "") + ",";
report += toJson("serverversion", serverVersion) + ",";
report += toJson("osname", osname) + ",";
report += toJson("osarch", osarch) + ",";
report += toJson("osversion", osversion) + ",";
report += toJson("javaversion", java_version) + ",";
report += toJson("corecount", coreCount + "") + "";
report += "} }";
byte[] data = report.getBytes();
try {
URL url = new URL(BASE_URL);
URLConnection c = url.openConnection();
c.setConnectTimeout(2500);
c.setReadTimeout(3500);
c.addRequestProperty("User-Agent", "MCUPDATE/" + VERSION);
c.addRequestProperty("Content-Type", "application/json");
c.addRequestProperty("Content-Length", Integer.toString(data.length));
c.addRequestProperty("Accept", "application/json");
c.addRequestProperty("Connection", "close");
c.setDoOutput(true);
OutputStream os = c.getOutputStream();
os.write(data);
os.flush();
BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream()));
String endData = br.readLine().trim();
String serverMessage = getString(endData, "message");
String cVersion = getString(endData, "pl_Version");
updateMessage = getString(endData, "update_Message");
if (!serverMessage.equals("ERROR")) {
if (!ver.equals(cVersion)) {
upToDate = false;
}
}
br.close();
} catch (IOException ignored) {
}
}
private String getString(String data, String key) {
String dat = data.replace("{ \"Response\": {\"", "");
dat = dat.replace("\"} }", "");
List<String> list = Arrays.asList(dat.split("\",\""));
for (String stub : list) {
List<String> list2 = Arrays.asList(stub.split("\":\""));
if (key.equals(list2.get(0))) {
return list2.get(1);
}
}
return null;
}
private static String toJson(String key, String value) {
return "\"" + key + "\":\"" + value + "\"";
}
private static String format(String format) {
return ChatColor.translateAlternateColorCodes('&', format);
}
public void setPingInterval(int PING_INTERVAL) {
this.PING_INTERVAL = PING_INTERVAL;
}
}