mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2024-12-22 16:48:11 +01:00
v1.2.5 Update
Bug Fixes: - A blank line from Crazy Auctions would appear randomly in Console due to old MCUpdate class. - Damaged leather armor could be sold in the CA even if damaged items are turned off. - Trying to bid on an item that has just expired causes an error in console. Changes: - Bunch of code cleanup. - Switched from the old MCUpdate class to the new MassiveStats class. Added: - New permission to force end auctions. "crazyauctions.force-end"
This commit is contained in:
commit
92d6553ebc
24
.classpath
24
.classpath
@ -1,24 +0,0 @@
|
||||
<?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.8"/>
|
||||
<classpathentry kind="lib" path="/Users/Joe/Plugins/Spigot/Spigot 1.12.1.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="jar:file:/Users/Joe/Plugins/Spigot/Spigot%201.12%20JavaDoc.jar!/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="/Users/Joe/Plugins/Spigot/Spigot 1.11.2.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="jar:file:/Users/Joe/Plugins/Spigot/Spigot%201.11.2%20JavaDoc.jar!/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<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!/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="/Users/Joe/Plugins/Spigot/Spigot 1.9.4.jar"/>
|
||||
<classpathentry kind="lib" path="/Users/Joe/Plugins/Spigot/Spigot 1.8.8.jar"/>
|
||||
<classpathentry kind="lib" path="/Users/Joe/Plugins/Vault.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
9
.gitignore
vendored
9
.gitignore
vendored
@ -1,7 +1,12 @@
|
||||
|
||||
\.idea/
|
||||
|
||||
*.prefs
|
||||
*.iml
|
||||
|
||||
*.class
|
||||
|
||||
bin/
|
||||
target/classes/
|
||||
|
||||
target/
|
||||
|
||||
\.DS_Store
|
||||
|
17
.project
17
.project
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Crazy Auctions</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
27
Notes
27
Notes
@ -1,27 +0,0 @@
|
||||
Feature Requests:
|
||||
- Add it so you can sell more then just 64 of a stack.
|
||||
- Add a history purchase history.
|
||||
- Add a taxation option.
|
||||
- Add an option to broadcast a message when a player adds a new item.
|
||||
- Add a black list to block names and lores.
|
||||
- Add an option to set Bidding as the 1st GUI.
|
||||
- Add the command translation for Spanish and Portugees.
|
||||
- Add MySQL support.
|
||||
- Make the command messages all configurable.
|
||||
- Add a tax system for when a player buys an item.
|
||||
- Add an option to search for items by ID.
|
||||
|
||||
Reports:
|
||||
-
|
||||
|
||||
Bug Fixes:
|
||||
-
|
||||
|
||||
Added:
|
||||
-
|
||||
|
||||
Changes:
|
||||
-
|
||||
|
||||
Removed:
|
||||
-
|
92
pom.xml
Normal file
92
pom.xml
Normal file
@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>me.badbones69</groupId>
|
||||
<artifactId>crazyauctions</artifactId>
|
||||
<version>1.2.5</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean install package</defaultGoal>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<!-- Set to java 8 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Generates only the jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-jar</id>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>me.badbones69:*</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<!--<finalName>${project.artifactId}[v${project.version}]</finalName>-->
|
||||
<!--<outputFile>/Users/badbones/Desktop/Stuff/Server/plugins/Crazy Auctions[v${project.version}].jar</outputFile>-->
|
||||
<outputFile>/Users/badbones/Plugins/Public Plugins/Crazy Auctions/Crazy Auctions[v${project.version}].jar</outputFile>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
487
src/main/java/com/massivestats/MassiveStats.java
Normal file
487
src/main/java/com/massivestats/MassiveStats.java
Normal file
@ -0,0 +1,487 @@
|
||||
package com.massivestats;/*
|
||||
* Copyright 2018 (c) Massive Statistics LLC - All Rights Reserved
|
||||
* This file may only be used in conjunction with the 'com.massivestats.MassiveStats' service.
|
||||
*/
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* com.massivestats.MassiveStats collects plugin and server information for plugin authors.
|
||||
* You can learn more at our website: https://www.massivestats.com/
|
||||
*
|
||||
* @version 3.0
|
||||
* @author Sam Jakob Harker, Brianna Hazel O'Keefe
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class MassiveStats implements Listener {
|
||||
|
||||
/* START: MASSIVESTATS SETTINGS */
|
||||
public static final int CLIENT_VERSION = 0; // v3.0
|
||||
public static final String API_URL = "https://report.massivestats.com/v2/";
|
||||
|
||||
public static final String MASSIVE_UPDATE_PERMISSION = "massivestats.update";
|
||||
/* END: MASSIVESTATS SETTINGS */
|
||||
|
||||
private MassiveStatsUpdateTask task = null;
|
||||
private int pingInterval;
|
||||
|
||||
private MassiveStatsDataResponse lastResponse;
|
||||
private boolean listenerDisabled;
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
private Class jsonElement;
|
||||
private Class jsonParser;
|
||||
private Class jsonObject;
|
||||
private Class jsonPrimitive;
|
||||
|
||||
/**
|
||||
* @param plugin The plugin you wish to collect data for.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public MassiveStats(JavaPlugin plugin) {
|
||||
this(plugin, 900); // default value: 900 seconds (= 15 minutes)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plugin The plugin you wish to collect data for.
|
||||
* @param pingInterval Duration between requests.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public MassiveStats(JavaPlugin plugin, int pingInterval) {
|
||||
try {
|
||||
jsonElement = Class.forName("com.google.gson.JsonElement");
|
||||
jsonParser = Class.forName("com.google.gson.JsonParser");
|
||||
jsonObject = Class.forName("com.google.gson.JsonObject");
|
||||
jsonPrimitive = Class.forName("com.google.gson.JsonPrimitive");
|
||||
}catch(ClassNotFoundException ex) {
|
||||
// Gson not included in classpath (so use NMS version)
|
||||
try {
|
||||
jsonElement = Class.forName("net.minecraft.util.com.google.gson.JsonElement");
|
||||
jsonParser = Class.forName("net.minecraft.util.com.google.gson.JsonParser");
|
||||
jsonObject = Class.forName("net.minecraft.util.com.google.gson.JsonObject");
|
||||
jsonPrimitive = Class.forName("net.minecraft.util.com.google.gson.JsonPrimitive");
|
||||
}catch(ClassNotFoundException ignored) {
|
||||
Bukkit.getLogger().severe("com.massivestats.MassiveStats could not find an instance/version of Gson to use.");
|
||||
this.plugin = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the pingInterval that is set is reasonable.
|
||||
if(pingInterval < 10 || pingInterval > 86400) {
|
||||
pingInterval = 900;
|
||||
}
|
||||
|
||||
// Ensure that a plugin instance has been provided.
|
||||
if(plugin == null) {
|
||||
throw new IllegalArgumentException("You must provide a plugin for com.massivestats.MassiveStats to collect data for!");
|
||||
}
|
||||
|
||||
// Set the ping interval.
|
||||
this.pingInterval = pingInterval;
|
||||
// Set the plugin reference.
|
||||
this.plugin = plugin;
|
||||
// and start sending data to the com.massivestats.MassiveStats server immediately.
|
||||
start();
|
||||
|
||||
// Register join/leave events for the plugin
|
||||
Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether or not the built-in com.massivestats.MassiveStats {@link PlayerJoinEvent} listener is enabled.
|
||||
* @return Whether or not the com.massivestats.MassiveStats listener is enabled.
|
||||
*/
|
||||
public boolean isListenerDisabled() {
|
||||
return listenerDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not the built-in com.massivestats.MassiveStats {@link PlayerJoinEvent} listener is enabled.
|
||||
* @param listenerDisabled Whether or not the com.massivestats.MassiveStats listener is enabled.
|
||||
*/
|
||||
public void setListenerDisabled(boolean listenerDisabled) {
|
||||
this.listenerDisabled = listenerDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the com.massivestats.MassiveStats reporting timer.
|
||||
* If the timer is already running, this method will do nothing.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public void start() {
|
||||
if(this.plugin == null) {
|
||||
Bukkit.getLogger().severe("com.massivestats.MassiveStats could not find an instance/version of Gson to use and thus cannot start.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(task == null) {
|
||||
// If the API endpoint URL is invalid, don't start a new task to prevent the user from being spammed.
|
||||
try {
|
||||
new URL(MassiveStats.API_URL);
|
||||
}catch(MalformedURLException ex) {
|
||||
getPlugin()
|
||||
.getLogger().warning("You have specified an invalid API endpoint for com.massivestats.MassiveStats.");
|
||||
return;
|
||||
}
|
||||
|
||||
task = new MassiveStatsUpdateTask(this);
|
||||
task.runTaskTimerAsynchronously(plugin, 0L, pingInterval * 20L);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the com.massivestats.MassiveStats reporting timer.
|
||||
* Requests will no longer be sent to the server - or until {@link #start()} is invoked.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public void stop() {
|
||||
if(task == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the duration, in seconds, that com.massivestats.MassiveStats should wait before sending another request to the server.
|
||||
* @param pingInterval Duration between requests.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public void setPingInterval(int pingInterval) {
|
||||
this.pingInterval = pingInterval;
|
||||
|
||||
stop();
|
||||
start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the duration, in seconds, that com.massivestats.MassiveStats will wait before sending another request to the server.
|
||||
* @return Duration between requests.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public int getPingInterval() {
|
||||
return pingInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plugin that this com.massivestats.MassiveStats instance is collecting data for.
|
||||
* @return com.massivestats.MassiveStats instance plugin.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public JavaPlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
void setLastResponse(MassiveStatsDataResponse lastResponse) {
|
||||
this.lastResponse = lastResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of the last response from the com.massivestats.MassiveStats server.
|
||||
* @return com.massivestats.MassiveStats server response.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public MassiveStatsDataResponse getLastResponse() {
|
||||
return lastResponse;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
// Ensure the listener should be active
|
||||
if(lastResponse == null || listenerDisabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Of course, only notify the user if the plugin is not up to date.
|
||||
if(lastResponse.isUpToDate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// and only notify operators - or players with the correct permission.
|
||||
if(!event.getPlayer().isOp() && !event.getPlayer().hasPermission(MassiveStats.MASSIVE_UPDATE_PERMISSION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.getPlayer().sendMessage(lastResponse.getUpdateMessage());
|
||||
}
|
||||
|
||||
Class getJsonElement() {
|
||||
return jsonElement;
|
||||
}
|
||||
|
||||
Class getJsonParser() {
|
||||
return jsonParser;
|
||||
}
|
||||
|
||||
Class getJsonObject() {
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
Class getJsonPrimitive() {
|
||||
return jsonPrimitive;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MassiveStatsUpdateTask extends BukkitRunnable {
|
||||
|
||||
private final MassiveStats instance;
|
||||
|
||||
MassiveStatsUpdateTask(MassiveStats requester) {
|
||||
instance = requester;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("all")
|
||||
public void run() {
|
||||
try {
|
||||
// Generate the request payload and serialize it as JSON.
|
||||
String payload = new MassiveStatsDataRequest(instance).serialize();
|
||||
|
||||
// Then create a new HttpsUrlConnection to the API server and open it.
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(MassiveStats.API_URL).openConnection();
|
||||
|
||||
// Ensure that we don't hang the server with our 'dang shenanigans'.
|
||||
connection.setConnectTimeout(2500);
|
||||
connection.setReadTimeout(3500);
|
||||
|
||||
// Set the all-important request headers before we begin POSTing...
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Accept", "application/json");
|
||||
connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
|
||||
connection.setRequestProperty("User-Agent", "Massive/" + MassiveStats.CLIENT_VERSION);
|
||||
|
||||
// Open the output stream, write the payload, and then close the stream.
|
||||
connection.setDoOutput(true);
|
||||
DataOutputStream output = new DataOutputStream(connection.getOutputStream());
|
||||
output.writeBytes(payload);
|
||||
output.flush();
|
||||
output.close();
|
||||
|
||||
// Ensure that the server was happy with our data.
|
||||
int responseCode = connection.getResponseCode();
|
||||
if(responseCode != 200) {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
// Now, read the server's response to our payload...
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
StringBuilder response = new StringBuilder();
|
||||
|
||||
// ...line by line.
|
||||
String line;
|
||||
while((line = input.readLine()) != null) {
|
||||
response.append(line);
|
||||
}
|
||||
input.close();
|
||||
|
||||
// Now, we parse the JSON object.
|
||||
try {
|
||||
if(response.toString().contains("ERR_DATA_MISSING")) {
|
||||
Bukkit.getLogger().severe("com.massivestats.MassiveStats has encountered an error for the following plugin: "
|
||||
+ instance.getPlugin().getName());
|
||||
instance.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
Object parser = instance.getJsonParser().newInstance();
|
||||
|
||||
// JsonElement
|
||||
Object serverResponseRaw =
|
||||
parser.getClass().getMethod("parse", String.class).invoke(parser, response.toString());
|
||||
|
||||
// JsonObject
|
||||
Object serverResponse = serverResponseRaw.getClass().getMethod("getAsJsonObject", null)
|
||||
.invoke(serverResponseRaw, null);
|
||||
|
||||
Method serverResponseGet = instance.getJsonObject().getMethod("get", String.class);
|
||||
|
||||
Method getAsBoolean =
|
||||
instance.getJsonPrimitive().getMethod("getAsBoolean", null);
|
||||
Method getAsString =
|
||||
instance.getJsonPrimitive().getMethod("getAsString", null);
|
||||
|
||||
if(serverResponseGet.invoke(serverResponse, "upToDate") == null) {
|
||||
Bukkit.getLogger().severe("com.massivestats.MassiveStats has encountered an error for the following plugin: "
|
||||
+ instance.getPlugin().getName());
|
||||
instance.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if(serverResponseGet.invoke(serverResponse, "notice") != null) {
|
||||
Bukkit.getLogger().severe(
|
||||
(String) getAsString.invoke(serverResponseGet.invoke(serverResponse, "notice"))
|
||||
);
|
||||
instance.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean upToDate = (boolean) getAsBoolean.invoke(serverResponseGet.invoke(serverResponse, "upToDate"), null);
|
||||
String latestVersion = (String) getAsString.invoke(serverResponseGet.invoke(serverResponse, "latestVersion"), null);
|
||||
String updateMessage = ChatColor.translateAlternateColorCodes(
|
||||
'&', (String) getAsString.invoke(serverResponseGet.invoke(serverResponse, "updateMessage"), null)
|
||||
);
|
||||
|
||||
instance.setLastResponse(new MassiveStatsDataResponse(
|
||||
upToDate, latestVersion, updateMessage
|
||||
));
|
||||
|
||||
}catch(IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
|
||||
instance.getPlugin()
|
||||
.getLogger().warning("com.massivestats.MassiveStats returned an invalid response for this plugin.");
|
||||
}
|
||||
|
||||
// Finally, call an event to mark the update.
|
||||
}catch(MalformedURLException ex) {
|
||||
instance.getPlugin()
|
||||
.getLogger().warning("You have specified an invalid API endpoint for com.massivestats.MassiveStats.");
|
||||
}catch(IOException ex) {
|
||||
instance.getPlugin()
|
||||
.getLogger().warning("com.massivestats.MassiveStats was unable to communicate with its API endpoint.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MassiveStatsDataRequest {
|
||||
|
||||
private Object jsonObject;
|
||||
|
||||
MassiveStatsDataRequest(MassiveStats requester) {
|
||||
try {
|
||||
jsonObject = requester.getJsonObject().newInstance();
|
||||
|
||||
Method add =
|
||||
requester.getJsonObject().newInstance().getClass().getMethod("add", String.class, requester.getJsonElement());
|
||||
Method addPropertyString =
|
||||
requester.getJsonObject().newInstance().getClass().getMethod("addProperty", String.class, String.class);
|
||||
Method addPropertyNumber =
|
||||
requester.getJsonObject().newInstance().getClass().getMethod("addProperty", String.class, Number.class);
|
||||
Method addPropertyBoolean =
|
||||
requester.getJsonObject().newInstance().getClass().getMethod("addProperty", String.class, Boolean.class);
|
||||
|
||||
addPropertyNumber.invoke(jsonObject, "now", System.currentTimeMillis());
|
||||
|
||||
/* PLUGIN DATA */
|
||||
Object pluginObject = jsonObject.getClass().newInstance();
|
||||
addPropertyString.invoke(pluginObject, "name", requester.getPlugin().getDescription().getName());
|
||||
addPropertyString.invoke(pluginObject, "version", requester.getPlugin().getDescription().getVersion());
|
||||
add.invoke(jsonObject, "plugin", pluginObject);
|
||||
|
||||
/* SERVER DATA */
|
||||
Object minecraftServerObject = jsonObject.getClass().newInstance();
|
||||
addPropertyNumber.invoke(minecraftServerObject, "players", Bukkit.getServer().getOnlinePlayers().size());
|
||||
addPropertyBoolean.invoke(minecraftServerObject, "onlineMode", Bukkit.getServer().getOnlineMode());
|
||||
addPropertyString.invoke(minecraftServerObject, "version", Bukkit.getServer().getVersion());
|
||||
|
||||
Object javaServerObject = jsonObject.getClass().newInstance();
|
||||
addPropertyString.invoke(javaServerObject, "version", System.getProperty("java.version"));
|
||||
|
||||
Object osServerObject = jsonObject.getClass().newInstance();
|
||||
addPropertyString.invoke(osServerObject, "name", System.getProperty("os.name"));
|
||||
addPropertyString.invoke(osServerObject, "arch", System.getProperty("os.arch"));
|
||||
addPropertyString.invoke(osServerObject, "version", System.getProperty("os.version"));
|
||||
|
||||
Object hardwareServerObject = jsonObject.getClass().newInstance();
|
||||
addPropertyNumber.invoke(hardwareServerObject, "cores", Runtime.getRuntime().availableProcessors());
|
||||
|
||||
Object serverObject = jsonObject.getClass().newInstance();
|
||||
add.invoke(serverObject, "minecraft", minecraftServerObject);
|
||||
add.invoke(serverObject, "java", javaServerObject);
|
||||
add.invoke(serverObject, "os", osServerObject);
|
||||
add.invoke(serverObject, "hardware", hardwareServerObject);
|
||||
|
||||
add.invoke(jsonObject, "server", serverObject);
|
||||
|
||||
/* MASSIVE DATA */
|
||||
Object massiveObject = jsonObject.getClass().newInstance();
|
||||
addPropertyNumber.invoke(massiveObject, "version", MassiveStats.CLIENT_VERSION);
|
||||
addPropertyNumber.invoke(massiveObject, "pingInterval", requester.getPingInterval());
|
||||
|
||||
//object.add("Massive", massiveObject);
|
||||
add.invoke(jsonObject, "Massive", massiveObject);
|
||||
}catch(IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public String serialize() {
|
||||
//return object.toString();
|
||||
try {
|
||||
Method toString = jsonObject.getClass().getMethod("toString", null);
|
||||
return (String) toString.invoke(jsonObject);
|
||||
}catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused") final class MassiveStatsDataResponse {
|
||||
|
||||
private final boolean isUpToDate;
|
||||
private final String newVersion;
|
||||
private final String updateMessage;
|
||||
|
||||
MassiveStatsDataResponse(boolean isUpToDate, String newVersion, String updateMessage) {
|
||||
this.isUpToDate = isUpToDate;
|
||||
|
||||
if(!isUpToDate) {
|
||||
this.newVersion = newVersion;
|
||||
this.updateMessage = updateMessage;
|
||||
return;
|
||||
}
|
||||
|
||||
this.newVersion = null;
|
||||
this.updateMessage = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether or not this version of the plugin is the latest.
|
||||
* True = This is the latest version of the plugin.
|
||||
* False = There is an update available.
|
||||
* @return Whether or not there is an update available.
|
||||
*/
|
||||
public boolean isUpToDate() {
|
||||
return isUpToDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the latest version. If this is the latest version, it returns null.
|
||||
* @return The name of the latest version.
|
||||
*/
|
||||
public String getLatestVersion() {
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message to display, convincing the user to update to the new version of the plugin.
|
||||
* @return The update message to display.
|
||||
*/
|
||||
public String getUpdateMessage() {
|
||||
return updateMessage;
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
package me.badbones69.crazyauctions;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import com.massivestats.MassiveStats;
|
||||
import me.badbones69.crazyauctions.api.Category;
|
||||
import me.badbones69.crazyauctions.api.CrazyAuctions;
|
||||
import me.badbones69.crazyauctions.api.SettingsManager;
|
||||
import me.badbones69.crazyauctions.api.ShopType;
|
||||
import me.badbones69.crazyauctions.api.events.AuctionListEvent;
|
||||
import me.badbones69.crazyauctions.controlers.GUI;
|
||||
import me.badbones69.crazyauctions.currency.Vault;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
@ -17,26 +21,19 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import me.badbones69.crazyauctions.api.Category;
|
||||
import me.badbones69.crazyauctions.api.CrazyAuctions;
|
||||
import me.badbones69.crazyauctions.api.MCUpdate;
|
||||
import me.badbones69.crazyauctions.api.SettingsManager;
|
||||
import me.badbones69.crazyauctions.api.ShopType;
|
||||
import me.badbones69.crazyauctions.controlers.GUI;
|
||||
import me.badbones69.crazyauctions.currency.Vault;
|
||||
import me.badbones69.crazyauctions.events.AuctionListEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class Main extends JavaPlugin implements Listener {
|
||||
|
||||
public static SettingsManager settings = SettingsManager.getInstance();
|
||||
public static CrazyAuctions auc = CrazyAuctions.getInstance();
|
||||
private int file = 0;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
settings.setup(this);
|
||||
Methods.hasUpdate();
|
||||
// Methods.hasUpdate();
|
||||
Bukkit.getServer().getPluginManager().registerEvents(this, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new GUI(), this);
|
||||
Methods.updateAuction();
|
||||
@ -44,17 +41,15 @@ public class Main extends JavaPlugin implements Listener {
|
||||
if(!Vault.setupEconomy()) {
|
||||
saveDefaultConfig();
|
||||
}
|
||||
if(Bukkit.getPluginManager().getPlugin("Vault") == null) {
|
||||
Bukkit.getConsoleSender().sendMessage(Methods.getPrefix() + Methods.color("&cThis plugin is shutting down. This plugin requires a compatable currency plugin." + " &cPlease add Vault to continue using this."));
|
||||
Bukkit.getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
try {
|
||||
new MCUpdate(this, true);
|
||||
}catch(IOException e) {}
|
||||
MassiveStats massiveStats = new MassiveStats(this);
|
||||
}catch(Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
int file = 0;
|
||||
Bukkit.getScheduler().cancelTask(file);
|
||||
settings.saveData();
|
||||
}
|
||||
@ -246,7 +241,7 @@ public class Main extends JavaPlugin implements Listener {
|
||||
String seller = player.getName();
|
||||
int num = 1;
|
||||
Random r = new Random();
|
||||
for(; settings.getData().contains("Items." + num); num++);
|
||||
for(; settings.getData().contains("Items." + num); num++) ;
|
||||
settings.getData().set("Items." + num + ".Price", price);
|
||||
settings.getData().set("Items." + num + ".Seller", seller);
|
||||
if(args[0].equalsIgnoreCase("Bid")) {
|
||||
@ -303,11 +298,8 @@ public class Main extends JavaPlugin implements Listener {
|
||||
if(player.getName().equals("BadBones69")) {
|
||||
player.sendMessage(Methods.getPrefix() + Methods.color("&7This server is running your Crazy Auctions Plugin. " + "&7It is running version &av" + Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions").getDescription().getVersion() + "&7."));
|
||||
}
|
||||
if(player.isOp()) {
|
||||
Methods.hasUpdate(player);
|
||||
}
|
||||
}
|
||||
}.runTaskLaterAsynchronously(this, 40);
|
||||
}.runTaskLater(this, 40);
|
||||
}
|
||||
|
||||
private void startCheck() {
|
||||
@ -320,7 +312,7 @@ public class Main extends JavaPlugin implements Listener {
|
||||
}
|
||||
|
||||
private ArrayList<Material> getDamageableItems() {
|
||||
ArrayList<Material> ma = new ArrayList<Material>();
|
||||
ArrayList<Material> ma = new ArrayList<>();
|
||||
ma.add(Material.DIAMOND_HELMET);
|
||||
ma.add(Material.DIAMOND_CHESTPLATE);
|
||||
ma.add(Material.DIAMOND_LEGGINGS);
|
||||
@ -337,10 +329,10 @@ public class Main extends JavaPlugin implements Listener {
|
||||
ma.add(Material.IRON_CHESTPLATE);
|
||||
ma.add(Material.IRON_LEGGINGS);
|
||||
ma.add(Material.IRON_BOOTS);
|
||||
ma.add(Material.DIAMOND_HELMET);
|
||||
ma.add(Material.DIAMOND_CHESTPLATE);
|
||||
ma.add(Material.DIAMOND_LEGGINGS);
|
||||
ma.add(Material.DIAMOND_BOOTS);
|
||||
ma.add(Material.LEATHER_HELMET);
|
||||
ma.add(Material.LEATHER_CHESTPLATE);
|
||||
ma.add(Material.LEATHER_LEGGINGS);
|
||||
ma.add(Material.LEATHER_BOOTS);
|
||||
ma.add(Material.BOW);
|
||||
ma.add(Material.WOOD_SWORD);
|
||||
ma.add(Material.STONE_SWORD);
|
@ -1,20 +1,8 @@
|
||||
package me.badbones69.crazyauctions;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import me.badbones69.crazyauctions.api.events.AuctionWinBidEvent;
|
||||
import me.badbones69.crazyauctions.currency.CurrencyManager;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -23,8 +11,11 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import me.badbones69.crazyauctions.currency.CurrencyManager;
|
||||
import me.badbones69.crazyauctions.events.AuctionWinBidEvent;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Methods {
|
||||
|
||||
@ -80,7 +71,7 @@ public class Methods {
|
||||
}
|
||||
|
||||
public static ItemStack makeItem(String type, int amount, String name, List<String> lore) {
|
||||
ArrayList<String> l = new ArrayList<String>();
|
||||
ArrayList<String> l = new ArrayList<>();
|
||||
int ty = 0;
|
||||
if(type.contains(":")) {
|
||||
String[] b = type.split(":");
|
||||
@ -112,7 +103,7 @@ public class Methods {
|
||||
}
|
||||
|
||||
public static ItemStack makeItem(Material material, int amount, int type, String name, List<String> lore) {
|
||||
ArrayList<String> l = new ArrayList<String>();
|
||||
ArrayList<String> l = new ArrayList<>();
|
||||
ItemStack item = new ItemStack(material, amount, (short) type);
|
||||
ItemMeta m = item.getItemMeta();
|
||||
m.setDisplayName(color(name));
|
||||
@ -134,7 +125,7 @@ public class Methods {
|
||||
}
|
||||
|
||||
public static ItemStack addLore(ItemStack item, String i) {
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
ItemMeta m = item.getItemMeta();
|
||||
if(item.getItemMeta().hasLore()) {
|
||||
lore.addAll(item.getItemMeta().getLore());
|
||||
@ -146,7 +137,7 @@ public class Methods {
|
||||
}
|
||||
|
||||
public static ItemStack addLore(ItemStack item, List<String> list) {
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
ItemMeta m = item.getItemMeta();
|
||||
if(item.getItemMeta().hasLore()) lore.addAll(item.getItemMeta().getLore());
|
||||
for(String i : list)
|
||||
@ -236,7 +227,7 @@ public class Methods {
|
||||
}
|
||||
|
||||
public static boolean hasPermission(Player player, String perm) {
|
||||
if(!player.hasPermission("CrazyAuctions." + perm)) {
|
||||
if(!player.hasPermission("crazyauctions." + perm)) {
|
||||
player.sendMessage(color(Main.settings.getMsg().getString("Messages.No-Permission")));
|
||||
return false;
|
||||
}
|
||||
@ -246,7 +237,7 @@ public class Methods {
|
||||
public static boolean hasPermission(CommandSender sender, String perm) {
|
||||
if(sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(!player.hasPermission("CrazyAuctions." + perm)) {
|
||||
if(!player.hasPermission("crazyauctions." + perm)) {
|
||||
player.sendMessage(color(Main.settings.getMsg().getString("Messages.No-Permission")));
|
||||
return false;
|
||||
}else {
|
||||
@ -257,40 +248,8 @@ public class Methods {
|
||||
}
|
||||
}
|
||||
|
||||
public static void hasUpdate() {
|
||||
try {
|
||||
HttpURLConnection c = (HttpURLConnection) new URL("http://www.spigotmc.org/api/general.php").openConnection();
|
||||
c.setDoOutput(true);
|
||||
c.setRequestMethod("POST");
|
||||
c.getOutputStream().write(("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=25219").getBytes("UTF-8"));
|
||||
String oldVersion = plugin.getDescription().getVersion();
|
||||
String newVersion = new BufferedReader(new InputStreamReader(c.getInputStream())).readLine().replaceAll("[a-zA-Z ]", "");
|
||||
if(!newVersion.equals(oldVersion)) {
|
||||
Bukkit.getConsoleSender().sendMessage(getPrefix() + color("&cYour server is running &7v" + oldVersion + "&c and the newest is &7v" + newVersion + "&c."));
|
||||
}
|
||||
}catch(Exception e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void hasUpdate(Player player) {
|
||||
try {
|
||||
HttpURLConnection c = (HttpURLConnection) new URL("http://www.spigotmc.org/api/general.php").openConnection();
|
||||
c.setDoOutput(true);
|
||||
c.setRequestMethod("POST");
|
||||
c.getOutputStream().write(("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=25219").getBytes("UTF-8"));
|
||||
String oldVersion = plugin.getDescription().getVersion();
|
||||
String newVersion = new BufferedReader(new InputStreamReader(c.getInputStream())).readLine().replaceAll("[a-zA-Z ]", "");
|
||||
if(!newVersion.equals(oldVersion)) {
|
||||
player.sendMessage(getPrefix() + color("&cYour server is running &7v" + oldVersion + "&c and the newest is &7v" + newVersion + "&c."));
|
||||
}
|
||||
}catch(Exception e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ItemStack> getPage(List<ItemStack> list, Integer page) {
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
if(page <= 0) page = 1;
|
||||
int max = 45;
|
||||
int index = page * max - max;
|
||||
@ -310,7 +269,7 @@ public class Methods {
|
||||
}
|
||||
|
||||
public static List<Integer> getPageInts(List<Integer> list, Integer page) {
|
||||
List<Integer> items = new ArrayList<Integer>();
|
||||
List<Integer> items = new ArrayList<>();
|
||||
if(page <= 0) page = 1;
|
||||
int max = 45;
|
||||
int index = page * max - max;
|
||||
@ -332,7 +291,7 @@ public class Methods {
|
||||
public static int getMaxPage(List<ItemStack> list) {
|
||||
int maxPage = 1;
|
||||
int amount = list.size();
|
||||
for(; amount > 45; amount -= 45, maxPage++);
|
||||
for(; amount > 45; amount -= 45, maxPage++) ;
|
||||
return maxPage;
|
||||
}
|
||||
|
||||
@ -345,9 +304,9 @@ public class Methods {
|
||||
int H = 0;
|
||||
int M = 0;
|
||||
int S = 0;
|
||||
for(; total > 86400; total -= 86400, D++);
|
||||
for(; total > 3600; total -= 3600, H++);
|
||||
for(; total > 60; total -= 60, M++);
|
||||
for(; total > 86400; total -= 86400, D++) ;
|
||||
for(; total > 3600; total -= 3600, H++) ;
|
||||
for(; total > 60; total -= 60, M++) ;
|
||||
S += total;
|
||||
return D + "d " + H + "h " + M + "m " + S + "s ";
|
||||
}
|
||||
@ -398,7 +357,7 @@ public class Methods {
|
||||
fullExpireTime.setTimeInMillis(data.getLong("Items." + i + ".Full-Time"));
|
||||
if(cal.after(expireTime)) {
|
||||
int num = 1;
|
||||
for(; data.contains("OutOfTime/Cancelled." + num); num++);
|
||||
for(; data.contains("OutOfTime/Cancelled." + num); num++) ;
|
||||
if(data.getBoolean("Items." + i + ".Biddable") && !data.getString("Items." + i + ".TopBidder").equalsIgnoreCase("None") && CurrencyManager.getMoney(Methods.getPlayer(data.getString("Items." + i + ".TopBidder"))) >= data.getInt("Items." + i + ".Price")) {
|
||||
String winner = data.getString("Items." + i + ".TopBidder");
|
||||
String seller = data.getString("Items." + i + ".Seller");
|
@ -1,12 +1,12 @@
|
||||
package me.badbones69.crazyauctions.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
public enum Category{
|
||||
import java.util.ArrayList;
|
||||
|
||||
public enum Category {
|
||||
|
||||
NONE("None", new ArrayList<Material>()),
|
||||
NONE("None", new ArrayList<>()),
|
||||
OTHER("Other", getOthers()),
|
||||
ARMOR("Armor", getArmor()),
|
||||
WEAPONS("Weapons", getWeapons()),
|
||||
@ -51,7 +51,7 @@ public enum Category{
|
||||
}
|
||||
|
||||
private static ArrayList<Material> getArmor() {
|
||||
ArrayList<Material> ma = new ArrayList<Material>();
|
||||
ArrayList<Material> ma = new ArrayList<>();
|
||||
ma.add(Material.DIAMOND_HELMET);
|
||||
ma.add(Material.DIAMOND_CHESTPLATE);
|
||||
ma.add(Material.DIAMOND_LEGGINGS);
|
||||
@ -76,7 +76,7 @@ public enum Category{
|
||||
}
|
||||
|
||||
private static ArrayList<Material> getTools() {
|
||||
ArrayList<Material> ma = new ArrayList<Material>();
|
||||
ArrayList<Material> ma = new ArrayList<>();
|
||||
ma.add(Material.WOOD_PICKAXE);
|
||||
ma.add(Material.STONE_PICKAXE);
|
||||
ma.add(Material.IRON_PICKAXE);
|
||||
@ -97,7 +97,7 @@ public enum Category{
|
||||
}
|
||||
|
||||
private static ArrayList<Material> getWeapons() {
|
||||
ArrayList<Material> ma = new ArrayList<Material>();
|
||||
ArrayList<Material> ma = new ArrayList<>();
|
||||
ma.add(Material.WOOD_SWORD);
|
||||
ma.add(Material.STONE_SWORD);
|
||||
ma.add(Material.IRON_SWORD);
|
||||
@ -111,7 +111,7 @@ public enum Category{
|
||||
}
|
||||
|
||||
private static ArrayList<Material> getFood() {
|
||||
ArrayList<Material> ma = new ArrayList<Material>();
|
||||
ArrayList<Material> ma = new ArrayList<>();
|
||||
for(Material m : Material.values()) {
|
||||
if(m.isEdible()) {
|
||||
if(m != Material.POTION) ma.add(m);
|
||||
@ -121,13 +121,17 @@ public enum Category{
|
||||
}
|
||||
|
||||
private static ArrayList<Material> getPotions() {
|
||||
ArrayList<Material> ma = new ArrayList<Material>();
|
||||
ArrayList<Material> ma = new ArrayList<>();
|
||||
ma.add(Material.POTION);
|
||||
ma.add(Material.SPLASH_POTION);
|
||||
if(Material.matchMaterial("LINGERING_POTION") != null) {
|
||||
ma.add(Material.matchMaterial("LINGERING_POTION"));
|
||||
}
|
||||
return ma;
|
||||
}
|
||||
|
||||
private static ArrayList<Material> getBlocks() {
|
||||
ArrayList<Material> ma = new ArrayList<Material>();
|
||||
ArrayList<Material> ma = new ArrayList<>();
|
||||
for(Material m : Material.values()) {
|
||||
if(m.isBlock()) {
|
||||
ma.add(m);
|
||||
@ -137,7 +141,7 @@ public enum Category{
|
||||
}
|
||||
|
||||
private static ArrayList<Material> getOthers() {
|
||||
ArrayList<Material> ma = new ArrayList<Material>();
|
||||
ArrayList<Material> ma = new ArrayList<>();
|
||||
for(Material m : Material.values()) {
|
||||
if(!(getArmor().contains(m) || getTools().contains(m) || getWeapons().contains(m) || getFood().contains(m) || getPotions().contains(m) || getBlocks().contains(m))) {
|
||||
ma.add(m);
|
@ -1,12 +1,11 @@
|
||||
package me.badbones69.crazyauctions.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import me.badbones69.crazyauctions.Main;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.badbones69.crazyauctions.Main;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CrazyAuctions {
|
||||
|
@ -1,10 +1,5 @@
|
||||
package me.badbones69.crazyauctions.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -12,6 +7,11 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class SettingsManager {
|
||||
|
||||
static SettingsManager instance = new SettingsManager();
|
@ -1,4 +1,4 @@
|
||||
package me.badbones69.crazyauctions.events;
|
||||
package me.badbones69.crazyauctions.api.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
@ -6,9 +6,9 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author BadBones69
|
||||
*
|
||||
*
|
||||
* This event is fired when a player buys something from the selling auction house.
|
||||
*
|
||||
*/
|
||||
@ -20,7 +20,7 @@ public class AuctionBuyEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
* @param price
|
@ -1,16 +1,15 @@
|
||||
package me.badbones69.crazyauctions.events;
|
||||
package me.badbones69.crazyauctions.api.events;
|
||||
|
||||
import me.badbones69.crazyauctions.api.ShopType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.badbones69.crazyauctions.api.ShopType;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author BadBones69
|
||||
*
|
||||
*
|
||||
* This event is fired when a new item is listed onto the auction house.
|
||||
*
|
||||
*/
|
||||
@ -23,7 +22,7 @@ public class AuctionListEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param player
|
||||
* @param shop
|
||||
* @param item
|
@ -1,4 +1,4 @@
|
||||
package me.badbones69.crazyauctions.events;
|
||||
package me.badbones69.crazyauctions.api.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
@ -6,9 +6,9 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author BadBones69
|
||||
*
|
||||
*
|
||||
* This event is fired when a player places a new bid onto an item in the auction house.
|
||||
*
|
||||
*/
|
||||
@ -20,7 +20,7 @@ public class AuctionNewBidEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
* @param bid
|
@ -1,4 +1,4 @@
|
||||
package me.badbones69.crazyauctions.events;
|
||||
package me.badbones69.crazyauctions.api.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
@ -6,9 +6,9 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author BadBones69
|
||||
*
|
||||
*
|
||||
* This event is fired when a bidding item's time has run out and so a player wins the item.
|
||||
*
|
||||
*/
|
||||
@ -20,7 +20,7 @@ public class AuctionWinBidEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
* @param bid
|
@ -1,12 +1,13 @@
|
||||
package me.badbones69.crazyauctions.controlers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import me.badbones69.crazyauctions.Main;
|
||||
import me.badbones69.crazyauctions.Methods;
|
||||
import me.badbones69.crazyauctions.api.Category;
|
||||
import me.badbones69.crazyauctions.api.ShopType;
|
||||
import me.badbones69.crazyauctions.api.events.AuctionBuyEvent;
|
||||
import me.badbones69.crazyauctions.api.events.AuctionNewBidEvent;
|
||||
import me.badbones69.crazyauctions.currency.CurrencyManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -19,22 +20,19 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import me.badbones69.crazyauctions.Main;
|
||||
import me.badbones69.crazyauctions.Methods;
|
||||
import me.badbones69.crazyauctions.api.Category;
|
||||
import me.badbones69.crazyauctions.api.ShopType;
|
||||
import me.badbones69.crazyauctions.currency.CurrencyManager;
|
||||
import me.badbones69.crazyauctions.events.AuctionBuyEvent;
|
||||
import me.badbones69.crazyauctions.events.AuctionNewBidEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class GUI implements Listener {
|
||||
|
||||
private static HashMap<Player, Integer> Bidding = new HashMap<Player, Integer>();
|
||||
private static HashMap<Player, String> BiddingID = new HashMap<Player, String>();
|
||||
private static HashMap<Player, ShopType> Type = new HashMap<Player, ShopType>(); // Shop Type
|
||||
private static HashMap<Player, Category> Cat = new HashMap<Player, Category>(); // Category Type
|
||||
private static HashMap<Player, List<Integer>> List = new HashMap<Player, List<Integer>>();
|
||||
private static HashMap<Player, String> IDs = new HashMap<Player, String>();
|
||||
private static HashMap<Player, Integer> bidding = new HashMap<>();
|
||||
private static HashMap<Player, String> biddingID = new HashMap<>();
|
||||
private static HashMap<Player, ShopType> Type = new HashMap<>(); // Shop Type
|
||||
private static HashMap<Player, Category> Cat = new HashMap<>(); // Category Type
|
||||
private static HashMap<Player, List<Integer>> List = new HashMap<>();
|
||||
private static HashMap<Player, String> IDs = new HashMap<>();
|
||||
|
||||
public static Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions");
|
||||
|
||||
@ -42,9 +40,8 @@ public class GUI implements Listener {
|
||||
Methods.updateAuction();
|
||||
FileConfiguration config = Main.settings.getConfig();
|
||||
FileConfiguration data = Main.settings.getData();
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
List<Integer> ID = new ArrayList<Integer>();
|
||||
List<Integer> Id = new ArrayList<Integer>();
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
List<Integer> ID = new ArrayList<>();
|
||||
if(!data.contains("Items")) {
|
||||
data.set("Items.Clear", null);
|
||||
Main.settings.saveData();
|
||||
@ -56,7 +53,7 @@ public class GUI implements Listener {
|
||||
}
|
||||
if(data.contains("Items")) {
|
||||
for(String i : data.getConfigurationSection("Items").getKeys(false)) {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
List<String> lore = new ArrayList<>();
|
||||
if(cat.getItems().contains(data.getItemStack("Items." + i + ".Item").getType()) || cat == Category.NONE) {
|
||||
if(data.getBoolean("Items." + i + ".Biddable")) {
|
||||
if(sell == ShopType.BID) {
|
||||
@ -81,9 +78,9 @@ public class GUI implements Listener {
|
||||
}
|
||||
}
|
||||
int maxPage = Methods.getMaxPage(items);
|
||||
for(; page > maxPage; page--);
|
||||
for(; page > maxPage; page--) ;
|
||||
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page));
|
||||
List<String> options = new ArrayList<String>();
|
||||
List<String> options = new ArrayList<>();
|
||||
options.add("SellingItems");
|
||||
options.add("Cancelled/ExpiredItems");
|
||||
options.add("PreviousPage");
|
||||
@ -109,7 +106,7 @@ public class GUI implements Listener {
|
||||
}
|
||||
String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item");
|
||||
String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name");
|
||||
List<String> lore = new ArrayList<String>();
|
||||
List<String> lore = new ArrayList<>();
|
||||
int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot");
|
||||
String cName = Methods.color(config.getString("Settings.GUISettings.Category-Settings." + Cat.get(player).getName() + ".Name"));
|
||||
if(config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) {
|
||||
@ -125,9 +122,7 @@ public class GUI implements Listener {
|
||||
int slot = inv.firstEmpty();
|
||||
inv.setItem(slot, item);
|
||||
}
|
||||
for(int id : Methods.getPageInts(ID, page)) {
|
||||
Id.add(id);
|
||||
}
|
||||
List<Integer> Id = new ArrayList<>(Methods.getPageInts(ID, page));
|
||||
List.put(player, Id);
|
||||
player.openInventory(inv);
|
||||
}
|
||||
@ -136,7 +131,7 @@ public class GUI implements Listener {
|
||||
Methods.updateAuction();
|
||||
FileConfiguration config = Main.settings.getConfig();
|
||||
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Categories")));
|
||||
List<String> options = new ArrayList<String>();
|
||||
List<String> options = new ArrayList<>();
|
||||
options.add("OtherSettings.Back");
|
||||
options.add("OtherSettings.WhatIsThis.Categories");
|
||||
options.add("Category-Settings.Armor");
|
||||
@ -170,11 +165,10 @@ public class GUI implements Listener {
|
||||
Methods.updateAuction();
|
||||
FileConfiguration config = Main.settings.getConfig();
|
||||
FileConfiguration data = Main.settings.getData();
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
List<Integer> ID = new ArrayList<Integer>();
|
||||
List<Integer> Id = new ArrayList<Integer>();
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
List<Integer> ID = new ArrayList<>();
|
||||
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Players-Current-Items")));
|
||||
List<String> options = new ArrayList<String>();
|
||||
List<String> options = new ArrayList<>();
|
||||
options.add("Back");
|
||||
options.add("WhatIsThis.CurrentItems");
|
||||
for(String o : options) {
|
||||
@ -195,7 +189,7 @@ public class GUI implements Listener {
|
||||
if(data.contains("Items")) {
|
||||
for(String i : data.getConfigurationSection("Items").getKeys(false)) {
|
||||
if(data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
List<String> lore = new ArrayList<>();
|
||||
for(String l : config.getStringList("Settings.GUISettings.CurrentLore")) {
|
||||
lore.add(l.replaceAll("%Price%", Methods.getPrice(i, false)).replaceAll("%price%", Methods.getPrice(i, false)).replaceAll("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replaceAll("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))));
|
||||
}
|
||||
@ -208,9 +202,7 @@ public class GUI implements Listener {
|
||||
int slot = inv.firstEmpty();
|
||||
inv.setItem(slot, item);
|
||||
}
|
||||
for(int id : Methods.getPageInts(ID, page)) {
|
||||
Id.add(id);
|
||||
}
|
||||
List<Integer> Id = new ArrayList<>(Methods.getPageInts(ID, page));
|
||||
List.put(player, Id);
|
||||
player.openInventory(inv);
|
||||
}
|
||||
@ -219,13 +211,12 @@ public class GUI implements Listener {
|
||||
Methods.updateAuction();
|
||||
FileConfiguration config = Main.settings.getConfig();
|
||||
FileConfiguration data = Main.settings.getData();
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
List<Integer> ID = new ArrayList<Integer>();
|
||||
List<Integer> Id = new ArrayList<Integer>();
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
List<Integer> ID = new ArrayList<>();
|
||||
if(data.contains("OutOfTime/Cancelled")) {
|
||||
for(String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
|
||||
if(data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getName())) {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
List<String> lore = new ArrayList<>();
|
||||
for(String l : config.getStringList("Settings.GUISettings.Cancelled/ExpiredLore")) {
|
||||
lore.add(l.replaceAll("%Price%", Methods.getPrice(i, true)).replaceAll("%price%", Methods.getPrice(i, true)).replaceAll("%Time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time"))).replaceAll("%time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time"))));
|
||||
}
|
||||
@ -235,9 +226,9 @@ public class GUI implements Listener {
|
||||
}
|
||||
}
|
||||
int maxPage = Methods.getMaxPage(items);
|
||||
for(; page > maxPage; page--);
|
||||
for(; page > maxPage; page--) ;
|
||||
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Cancelled/Expired-Items") + " #" + page));
|
||||
List<String> options = new ArrayList<String>();
|
||||
List<String> options = new ArrayList<>();
|
||||
options.add("Back");
|
||||
options.add("PreviousPage");
|
||||
options.add("Return");
|
||||
@ -262,9 +253,7 @@ public class GUI implements Listener {
|
||||
int slot = inv.firstEmpty();
|
||||
inv.setItem(slot, item);
|
||||
}
|
||||
for(int id : Methods.getPageInts(ID, page)) {
|
||||
Id.add(id);
|
||||
}
|
||||
List<Integer> Id = new ArrayList<>(Methods.getPageInts(ID, page));
|
||||
List.put(player, Id);
|
||||
player.openInventory(inv);
|
||||
}
|
||||
@ -280,13 +269,13 @@ public class GUI implements Listener {
|
||||
return;
|
||||
}
|
||||
Inventory inv = Bukkit.createInventory(null, 9, Methods.color(config.getString("Settings.Buying-Item")));
|
||||
List<String> options = new ArrayList<String>();
|
||||
List<String> options = new ArrayList<>();
|
||||
options.add("Confirm");
|
||||
options.add("Cancel");
|
||||
for(String o : options) {
|
||||
String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item");
|
||||
String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name");
|
||||
ItemStack item = new ItemStack(Material.AIR);
|
||||
ItemStack item;
|
||||
if(config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) {
|
||||
item = Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore"));
|
||||
}else {
|
||||
@ -306,7 +295,7 @@ public class GUI implements Listener {
|
||||
}
|
||||
}
|
||||
ItemStack item = data.getItemStack("Items." + ID + ".Item");
|
||||
List<String> lore = new ArrayList<String>();
|
||||
List<String> lore = new ArrayList<>();
|
||||
for(String l : config.getStringList("Settings.GUISettings.SellingLore")) {
|
||||
lore.add(l.replaceAll("%Price%", Methods.getPrice(ID, false)).replaceAll("%price%", Methods.getPrice(ID, false)).replaceAll("%Seller%", data.getString("Items." + ID + ".Seller")).replaceAll("%seller%", data.getString("Items." + ID + ".Seller")));
|
||||
}
|
||||
@ -326,7 +315,7 @@ public class GUI implements Listener {
|
||||
return;
|
||||
}
|
||||
Inventory inv = Bukkit.createInventory(null, 27, Methods.color(config.getString("Settings.Bidding-On-Item")));
|
||||
if(!Bidding.containsKey(player)) Bidding.put(player, 0);
|
||||
if(!bidding.containsKey(player)) bidding.put(player, 0);
|
||||
inv.setItem(9, Methods.makeItem("160:5", 1, "&a+1"));
|
||||
inv.setItem(10, Methods.makeItem("160:5", 1, "&a+10"));
|
||||
inv.setItem(11, Methods.makeItem("160:5", 1, "&a+100"));
|
||||
@ -346,9 +335,8 @@ public class GUI implements Listener {
|
||||
Methods.updateAuction();
|
||||
FileConfiguration config = Main.settings.getConfig();
|
||||
FileConfiguration data = Main.settings.getData();
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
List<Integer> ID = new ArrayList<Integer>();
|
||||
List<Integer> Id = new ArrayList<Integer>();
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
List<Integer> ID = new ArrayList<>();
|
||||
if(!data.contains("Items")) {
|
||||
data.set("Items.Clear", null);
|
||||
Main.settings.saveData();
|
||||
@ -356,7 +344,7 @@ public class GUI implements Listener {
|
||||
if(data.contains("Items")) {
|
||||
for(String i : data.getConfigurationSection("Items").getKeys(false)) {
|
||||
if(data.getString("Items." + i + ".Seller").equalsIgnoreCase(other)) {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
List<String> lore = new ArrayList<>();
|
||||
if(data.getBoolean("Items." + i + ".Biddable")) {
|
||||
String seller = data.getString("Items." + i + ".Seller");
|
||||
String topbidder = data.getString("Items." + i + ".TopBidder");
|
||||
@ -376,9 +364,9 @@ public class GUI implements Listener {
|
||||
}
|
||||
}
|
||||
int maxPage = Methods.getMaxPage(items);
|
||||
for(; page > maxPage; page--);
|
||||
for(; page > maxPage; page--) ;
|
||||
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page));
|
||||
List<String> options = new ArrayList<String>();
|
||||
List<String> options = new ArrayList<>();
|
||||
options.add("WhatIsThis.Viewing");
|
||||
for(String o : options) {
|
||||
if(config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) {
|
||||
@ -399,10 +387,7 @@ public class GUI implements Listener {
|
||||
int slot = inv.firstEmpty();
|
||||
inv.setItem(slot, item);
|
||||
}
|
||||
for(int id : Methods.getPageInts(ID, page)) {
|
||||
Id.add(id);
|
||||
}
|
||||
List.put(player, Id);
|
||||
List.put(player, new ArrayList<>(Methods.getPageInts(ID, page)));
|
||||
player.openInventory(inv);
|
||||
}
|
||||
|
||||
@ -410,10 +395,10 @@ public class GUI implements Listener {
|
||||
FileConfiguration config = Main.settings.getConfig();
|
||||
String id = config.getString("Settings.GUISettings.OtherSettings.Bidding.Item");
|
||||
String name = config.getString("Settings.GUISettings.OtherSettings.Bidding.Name");
|
||||
ItemStack item = new ItemStack(Material.AIR);
|
||||
int bid = Bidding.get(player);
|
||||
ItemStack item;
|
||||
int bid = bidding.get(player);
|
||||
if(config.contains("Settings.GUISettings.OtherSettings.Bidding.Lore")) {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
List<String> lore = new ArrayList<>();
|
||||
for(String l : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")) {
|
||||
lore.add(l.replaceAll("%Bid%", bid + "").replaceAll("%bid%", bid + "").replaceAll("%TopBid%", Methods.getPrice(ID, false)).replaceAll("%topbid%", Methods.getPrice(ID, false)));
|
||||
}
|
||||
@ -430,7 +415,7 @@ public class GUI implements Listener {
|
||||
String seller = data.getString("Items." + ID + ".Seller");
|
||||
String topbidder = data.getString("Items." + ID + ".TopBidder");
|
||||
ItemStack item = data.getItemStack("Items." + ID + ".Item");
|
||||
List<String> lore = new ArrayList<String>();
|
||||
List<String> lore = new ArrayList<>();
|
||||
for(String l : config.getStringList("Settings.GUISettings.Bidding")) {
|
||||
lore.add(l.replaceAll("%TopBid%", Methods.getPrice(ID, false)).replaceAll("%topbid%", Methods.getPrice(ID, false)).replaceAll("%Seller%", seller).replaceAll("%seller%", seller).replaceAll("%TopBidder%", topbidder).replaceAll("%topbidder%", topbidder).replaceAll("%Time%", Methods.convertToTime(data.getLong("Items." + ID + ".Time-Till-Expire"))).replaceAll("%time%", Methods.convertToTime(data.getLong("Items." + ID + ".Time-Till-Expire"))));
|
||||
}
|
||||
@ -444,9 +429,7 @@ public class GUI implements Listener {
|
||||
Player player = (Player) e.getPlayer();
|
||||
if(inv != null) {
|
||||
if(inv.getName().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) {
|
||||
if(Bidding.containsKey(player)) {
|
||||
Bidding.remove(player);
|
||||
}
|
||||
bidding.remove(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -493,8 +476,8 @@ public class GUI implements Listener {
|
||||
if(item.hasItemMeta()) {
|
||||
if(item.getItemMeta().hasDisplayName()) {
|
||||
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bid.Name")))) {
|
||||
String ID = BiddingID.get(player);
|
||||
int bid = Bidding.get(player);
|
||||
String ID = biddingID.get(player);
|
||||
int bid = bidding.get(player);
|
||||
String topBidder = data.getString("Items." + ID + ".TopBidder");
|
||||
if(CurrencyManager.getMoney(player) < bid) {
|
||||
player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Need-More-Money").replaceAll("%Money_Needed%", (bid - CurrencyManager.getMoney(player)) + "").replaceAll("%money_needed%", (bid - CurrencyManager.getMoney(player)) + "")));
|
||||
@ -513,74 +496,34 @@ public class GUI implements Listener {
|
||||
data.set("Items." + ID + ".TopBidder", player.getName());
|
||||
player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Bid-Msg").replaceAll("%Bid%", bid + "").replaceAll("%bid%", bid + "")));
|
||||
Main.settings.saveData();
|
||||
Bidding.put(player, 0);
|
||||
bidding.put(player, 0);
|
||||
player.closeInventory();
|
||||
playClick(player);
|
||||
return;
|
||||
}
|
||||
if(item.getItemMeta().getDisplayName().equals(Methods.color("&a+1"))) {
|
||||
Bidding.put(player, (Bidding.get(player) + 1));
|
||||
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
|
||||
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
|
||||
playClick(player);
|
||||
return;
|
||||
}
|
||||
if(item.getItemMeta().getDisplayName().equals(Methods.color("&a+10"))) {
|
||||
Bidding.put(player, (Bidding.get(player) + 10));
|
||||
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
|
||||
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
|
||||
playClick(player);
|
||||
return;
|
||||
}
|
||||
if(item.getItemMeta().getDisplayName().equals(Methods.color("&a+100"))) {
|
||||
Bidding.put(player, (Bidding.get(player) + 100));
|
||||
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
|
||||
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
|
||||
playClick(player);
|
||||
return;
|
||||
}
|
||||
if(item.getItemMeta().getDisplayName().equals(Methods.color("&a+1000"))) {
|
||||
Bidding.put(player, (Bidding.get(player) + 1000));
|
||||
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
|
||||
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
|
||||
playClick(player);
|
||||
return;
|
||||
}
|
||||
if(item.getItemMeta().getDisplayName().equals(Methods.color("&c-1"))) {
|
||||
int bid = Bidding.get(player) - 1;
|
||||
if(bid < 0) bid = 0;
|
||||
Bidding.put(player, bid);
|
||||
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
|
||||
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
|
||||
playClick(player);
|
||||
return;
|
||||
}
|
||||
if(item.getItemMeta().getDisplayName().equals(Methods.color("&c-10"))) {
|
||||
int bid = Bidding.get(player) - 10;
|
||||
if(bid < 0) bid = 0;
|
||||
Bidding.put(player, bid);
|
||||
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
|
||||
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
|
||||
playClick(player);
|
||||
return;
|
||||
}
|
||||
if(item.getItemMeta().getDisplayName().equals(Methods.color("&c-100"))) {
|
||||
int bid = Bidding.get(player) - 100;
|
||||
if(bid < 0) bid = 0;
|
||||
Bidding.put(player, bid);
|
||||
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
|
||||
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
|
||||
playClick(player);
|
||||
return;
|
||||
}
|
||||
if(item.getItemMeta().getDisplayName().equals(Methods.color("&c-1000"))) {
|
||||
int bid = Bidding.get(player) - 1000;
|
||||
if(bid < 0) bid = 0;
|
||||
Bidding.put(player, bid);
|
||||
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
|
||||
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
|
||||
playClick(player);
|
||||
return;
|
||||
HashMap<String, Integer> priceEdits = new HashMap<>();
|
||||
priceEdits.put("&a+1", 1);
|
||||
priceEdits.put("&a+10", 10);
|
||||
priceEdits.put("&a+100", 100);
|
||||
priceEdits.put("&a+1000", 1000);
|
||||
priceEdits.put("&c-1", -1);
|
||||
priceEdits.put("&c-10", -10);
|
||||
priceEdits.put("&c-100", -100);
|
||||
priceEdits.put("&c-1000", -1000);
|
||||
for(String price : priceEdits.keySet()) {
|
||||
if(item.getItemMeta().getDisplayName().equals(Methods.color(price))) {
|
||||
try {
|
||||
bidding.put(player, (bidding.get(player) + priceEdits.get(price)));
|
||||
inv.setItem(4, getBiddingItem(player, biddingID.get(player)));
|
||||
inv.setItem(13, getBiddingGlass(player, biddingID.get(player)));
|
||||
playClick(player);
|
||||
return;
|
||||
}catch(Exception ex) {
|
||||
player.closeInventory();
|
||||
player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Item-Doesnt-Exist")));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -664,11 +607,10 @@ public class GUI implements Listener {
|
||||
for(String i : data.getConfigurationSection("Items").getKeys(false)) {
|
||||
int ID = data.getInt("Items." + i + ".StoreID");
|
||||
if(id == ID) {
|
||||
T = true;
|
||||
if(player.hasPermission("CrazyAuctions.Admin")) {
|
||||
if(player.hasPermission("crazyAuctions.admin") || player.hasPermission("crazyauctions.force-end")) {
|
||||
if(e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
|
||||
int num = 1;
|
||||
for(; data.contains("OutOfTime/Cancelled." + num); num++);
|
||||
for(; data.contains("OutOfTime/Cancelled." + num); num++) ;
|
||||
String seller = data.getString("Items." + i + ".Seller");
|
||||
if(Methods.isOnline(seller)) {
|
||||
Player S = Methods.getPlayer(seller);
|
||||
@ -690,7 +632,7 @@ public class GUI implements Listener {
|
||||
if(data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) {
|
||||
String it = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Item");
|
||||
String name = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name");
|
||||
ItemStack I = new ItemStack(Material.AIR);
|
||||
ItemStack I;
|
||||
if(config.contains("Settings.GUISettings.OtherSettings.Your-Item.Lore")) {
|
||||
I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Your-Item.Lore"));
|
||||
}else {
|
||||
@ -698,19 +640,14 @@ public class GUI implements Listener {
|
||||
}
|
||||
inv.setItem(slot, I);
|
||||
playClick(player);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
inv.setItem(slot, item);
|
||||
}
|
||||
}, 3 * 20);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> inv.setItem(slot, item), 3 * 20);
|
||||
return;
|
||||
}
|
||||
Long cost = data.getLong("Items." + i + ".Price");
|
||||
if(CurrencyManager.getMoney(player) < cost) {
|
||||
String it = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Item");
|
||||
String name = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name");
|
||||
ItemStack I = new ItemStack(Material.AIR);
|
||||
ItemStack I;
|
||||
if(config.contains("Settings.GUISettings.OtherSettings.Cant-Afford.Lore")) {
|
||||
I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Cant-Afford.Lore"));
|
||||
}else {
|
||||
@ -718,19 +655,14 @@ public class GUI implements Listener {
|
||||
}
|
||||
inv.setItem(slot, I);
|
||||
playClick(player);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
inv.setItem(slot, item);
|
||||
}
|
||||
}, 3 * 20);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> inv.setItem(slot, item), 3 * 20);
|
||||
return;
|
||||
}
|
||||
if(data.getBoolean("Items." + i + ".Biddable")) {
|
||||
if(player.getName().equalsIgnoreCase(data.getString("Items." + i + ".TopBidder"))) {
|
||||
String it = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Item");
|
||||
String name = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name");
|
||||
ItemStack I = new ItemStack(Material.AIR);
|
||||
ItemStack I;
|
||||
if(config.contains("Settings.GUISettings.OtherSettings.Top-Bidder.Lore")) {
|
||||
I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Top-Bidder.Lore"));
|
||||
}else {
|
||||
@ -738,17 +670,12 @@ public class GUI implements Listener {
|
||||
}
|
||||
inv.setItem(slot, I);
|
||||
playClick(player);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
inv.setItem(slot, item);
|
||||
}
|
||||
}, 3 * 20);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> inv.setItem(slot, item), 3 * 20);
|
||||
return;
|
||||
}
|
||||
playClick(player);
|
||||
openBidding(player, i);
|
||||
BiddingID.put(player, i);
|
||||
biddingID.put(player, i);
|
||||
}else {
|
||||
playClick(player);
|
||||
openBuying(player, i);
|
||||
@ -845,10 +772,9 @@ public class GUI implements Listener {
|
||||
for(String i : data.getConfigurationSection("Items").getKeys(false)) {
|
||||
int ID = data.getInt("Items." + i + ".StoreID");
|
||||
if(id == ID) {
|
||||
T = true;
|
||||
player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Cancelled-Item")));
|
||||
int num = 1;
|
||||
for(; data.contains("OutOfTime/Cancelled." + num); num++);
|
||||
for(; data.contains("OutOfTime/Cancelled." + num); num++) ;
|
||||
data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".Full-Time", data.getLong("Items." + i + ".Full-Time"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
|
||||
@ -932,7 +858,6 @@ public class GUI implements Listener {
|
||||
int ID = data.getInt("OutOfTime/Cancelled." + i + ".StoreID");
|
||||
if(id == ID) {
|
||||
if(!Methods.isInvFull(player)) {
|
||||
T = true;
|
||||
player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Got-Item-Back")));
|
||||
ItemStack IT = data.getItemStack("OutOfTime/Cancelled." + i + ".Item");
|
||||
player.getInventory().addItem(IT);
|
||||
@ -952,7 +877,6 @@ public class GUI implements Listener {
|
||||
playClick(player);
|
||||
openShop(player, Type.get(player), Cat.get(player), 1);
|
||||
player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Item-Doesnt-Exist")));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
package me.badbones69.crazyauctions.currency;
|
||||
|
||||
import me.badbones69.crazyauctions.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.badbones69.crazyauctions.Main;
|
||||
|
||||
public enum CurrencyManager { // Currency Manager
|
||||
|
||||
VAULT("Vault", "Money");
|
||||
@ -52,7 +51,7 @@ public enum CurrencyManager { // Currency Manager
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return Returns true if the server has the plugin.
|
||||
*/
|
||||
public Boolean hasPlugin() {
|
||||
@ -65,7 +64,7 @@ public enum CurrencyManager { // Currency Manager
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param player
|
||||
* Player you want the currency from.
|
||||
* @param type
|
||||
@ -77,7 +76,7 @@ public enum CurrencyManager { // Currency Manager
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param player
|
||||
* Player you want the currency from.
|
||||
* @param type
|
||||
@ -90,7 +89,7 @@ public enum CurrencyManager { // Currency Manager
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param player
|
||||
* Player you want the currency from.
|
||||
* @param type
|
||||
@ -103,7 +102,7 @@ public enum CurrencyManager { // Currency Manager
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param player
|
||||
* Player you want the currency from.
|
||||
* @param type
|
||||
@ -116,7 +115,7 @@ public enum CurrencyManager { // Currency Manager
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param player
|
||||
* Player you want the currency from.
|
||||
* @param type
|
@ -1,13 +1,12 @@
|
||||
package me.badbones69.crazyauctions.currency;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
|
||||
public class Vault {
|
||||
|
||||
public static Economy econ = null;
|
@ -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.4
|
||||
version: ${version}
|
||||
depend: [Vault]
|
||||
description: >
|
||||
A plugin to auction off items globally.
|
@ -1,291 +0,0 @@
|
||||
package me.badbones69.crazyauctions.api;
|
||||
|
||||
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.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class MCUpdate implements Listener {
|
||||
|
||||
private final static String VERSION = "1.1";
|
||||
|
||||
private static final String BASE_URL = "http://report.mcupdate.org";
|
||||
|
||||
/**
|
||||
* Server received information.
|
||||
*/
|
||||
private static String updateMessage = "";
|
||||
private static boolean upToDate = true;
|
||||
private boolean checkUpdate = true;
|
||||
|
||||
private Plugin pl;
|
||||
|
||||
/**
|
||||
* Interval of time to ping (seconds)
|
||||
*/
|
||||
private int PING_INTERVAL;
|
||||
|
||||
/**
|
||||
* The scheduled task
|
||||
*/
|
||||
private volatile BukkitTask task = null;
|
||||
|
||||
/**
|
||||
* Start up the MCUpdater.
|
||||
*
|
||||
* @param plugin
|
||||
* The plugin using this.
|
||||
* @throws IOException
|
||||
*/
|
||||
public MCUpdate(Plugin plugin) throws IOException {
|
||||
if(plugin != null) {
|
||||
this.pl = plugin;
|
||||
// I should add a custom configuration for MCUpdate itself
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
setPingInterval(900);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Start up the MCUpdater.
|
||||
*
|
||||
* @param plugin
|
||||
* The plugin using this.
|
||||
* @param activate
|
||||
* Toggle if it starts the MCUpdater when used.
|
||||
* @throws IOException
|
||||
*/
|
||||
public MCUpdate(Plugin plugin, Boolean activate) 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(activate) {
|
||||
startLogging();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call when you wan't to start the updater.
|
||||
*
|
||||
* @return True if everything starts and false if it doesn't start.
|
||||
*/
|
||||
public boolean startLogging() {
|
||||
// Is MCUpdate already running?
|
||||
if(task == null) {
|
||||
// Begin hitting the server with glorious data
|
||||
task = pl.getServer().getScheduler().runTaskTimerAsynchronously(pl, () -> {
|
||||
report();
|
||||
if(!upToDate) {
|
||||
if(checkUpdate) {
|
||||
pl.getServer().getConsoleSender().sendMessage(format(updateMessage));
|
||||
}
|
||||
}
|
||||
}, 0, PING_INTERVAL * 20);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call when you want to stop the updater.
|
||||
*
|
||||
* @return True if it successfully stoped and false if couldn't.
|
||||
*/
|
||||
public boolean stopLogging() {
|
||||
if(task != null) {
|
||||
try {
|
||||
task.cancel();
|
||||
return true;
|
||||
}catch(Exception e) {}
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if MCUpdate is logging information.
|
||||
*
|
||||
* @return True if it is logging info and false if not.
|
||||
*/
|
||||
public Boolean isLogging() {
|
||||
return task != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the updater uses the internal update checker.
|
||||
*
|
||||
* @param checkUpdate
|
||||
* True if you want to use the internal update checker and false
|
||||
* if not.
|
||||
*/
|
||||
public void checkUpdate(Boolean checkUpdate) {
|
||||
this.checkUpdate = checkUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the internal updater is active.
|
||||
*
|
||||
* @return True if the internal updater is activated and false if not.
|
||||
*/
|
||||
public Boolean needsUpdated() {
|
||||
return checkUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rate the information is sent to MCUpdate.org.
|
||||
*
|
||||
* @param PING_INTERVAL
|
||||
* The rate at which the data is sent in seconds.
|
||||
*/
|
||||
public void setPingInterval(int PING_INTERVAL) {
|
||||
this.PING_INTERVAL = PING_INTERVAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rate which the data is sent to MCUpdate.org.
|
||||
*
|
||||
* @return The rate the data is sent in seconds.
|
||||
*/
|
||||
public int getPingInterval() {
|
||||
return PING_INTERVAL;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
if(p.isOp() && !upToDate) {
|
||||
if(checkUpdate) {
|
||||
p.sendMessage(format(updateMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 != null) {
|
||||
if(!serverMessage.equals("ERROR")) {
|
||||
if(cVersion != null) {
|
||||
if(!ver.equals(cVersion)) {
|
||||
upToDate = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
|
||||
}catch(Exception 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 "";
|
||||
}
|
||||
|
||||
private static String toJson(String key, String value) {
|
||||
return "\"" + key + "\":\"" + value + "\"";
|
||||
}
|
||||
|
||||
private static String format(String format) {
|
||||
if(format != null) {
|
||||
return ChatColor.translateAlternateColorCodes('&', format);
|
||||
}else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user