Convert project to Maven
This commit is contained in:
parent
01b51d62e0
commit
86673bb240
|
@ -0,0 +1,17 @@
|
||||||
|
# Maven
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Eclipse
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings/
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
*.iml
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Netbeans
|
||||||
|
nbproject/
|
||||||
|
|
||||||
|
# OS X
|
||||||
|
.DS_Store
|
|
@ -1,515 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2011-2013 Tyler Blair. All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are
|
|
||||||
* permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
||||||
* conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
||||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
|
||||||
* provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
|
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* The views and conclusions contained in the software and documentation are those of the
|
|
||||||
* authors and contributors and should not be interpreted as representing official policies,
|
|
||||||
* either expressed or implied, of anybody else.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.gmail.filoghost.chestcommands;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.Proxy;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.util.VersionUtils;
|
|
||||||
|
|
||||||
public class MetricsLite {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The current revision number
|
|
||||||
*/
|
|
||||||
private final static int REVISION = 7;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The base url of the metrics domain
|
|
||||||
*/
|
|
||||||
private static final String BASE_URL = "http://report.mcstats.org";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The url used to report a server's status
|
|
||||||
*/
|
|
||||||
private static final String REPORT_URL = "/plugin/%s";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interval of time to ping (in minutes)
|
|
||||||
*/
|
|
||||||
private final static int PING_INTERVAL = 15;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The plugin this metrics submits for
|
|
||||||
*/
|
|
||||||
private final Plugin plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The plugin configuration file
|
|
||||||
*/
|
|
||||||
private final YamlConfiguration configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The plugin configuration file
|
|
||||||
*/
|
|
||||||
private final File configurationFile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unique server id
|
|
||||||
*/
|
|
||||||
private final String guid;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Debug mode
|
|
||||||
*/
|
|
||||||
private final boolean debug;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lock for synchronization
|
|
||||||
*/
|
|
||||||
private final Object optOutLock = new Object();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Id of the scheduled task
|
|
||||||
*/
|
|
||||||
private volatile BukkitTask task = null;
|
|
||||||
|
|
||||||
public MetricsLite(Plugin plugin) throws IOException {
|
|
||||||
if (plugin == null) {
|
|
||||||
throw new IllegalArgumentException("Plugin cannot be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.plugin = plugin;
|
|
||||||
|
|
||||||
// load the config
|
|
||||||
configurationFile = getConfigFile();
|
|
||||||
configuration = YamlConfiguration.loadConfiguration(configurationFile);
|
|
||||||
|
|
||||||
// add some defaults
|
|
||||||
configuration.addDefault("opt-out", false);
|
|
||||||
configuration.addDefault("guid", UUID.randomUUID().toString());
|
|
||||||
configuration.addDefault("debug", false);
|
|
||||||
|
|
||||||
// Do we need to create the file?
|
|
||||||
if (configuration.get("guid", null) == null) {
|
|
||||||
configuration.options().header("http://mcstats.org").copyDefaults(true);
|
|
||||||
configuration.save(configurationFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the guid then
|
|
||||||
guid = configuration.getString("guid");
|
|
||||||
debug = configuration.getBoolean("debug", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send
|
|
||||||
* the initial data to the metrics backend, and then after that it will post in increments of
|
|
||||||
* PING_INTERVAL * 1200 ticks.
|
|
||||||
*
|
|
||||||
* @return True if statistics measuring is running, otherwise false.
|
|
||||||
*/
|
|
||||||
public boolean start() {
|
|
||||||
synchronized (optOutLock) {
|
|
||||||
// Did we opt out?
|
|
||||||
if (isOptOut()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is metrics already running?
|
|
||||||
if (task != null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Begin hitting the server with glorious data
|
|
||||||
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
|
||||||
|
|
||||||
private boolean firstPost = true;
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
// This has to be synchronized or it can collide with the disable method.
|
|
||||||
synchronized (optOutLock) {
|
|
||||||
// Disable Task, if it is running and the server owner decided to opt-out
|
|
||||||
if (isOptOut() && task != null) {
|
|
||||||
task.cancel();
|
|
||||||
task = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We use the inverse of firstPost because if it is the first time we are posting,
|
|
||||||
// it is not a interval ping, so it evaluates to FALSE
|
|
||||||
// Each time thereafter it will evaluate to TRUE, i.e PING!
|
|
||||||
postPlugin(!firstPost);
|
|
||||||
|
|
||||||
// After the first post we set firstPost to false
|
|
||||||
// Each post thereafter will be a ping
|
|
||||||
firstPost = false;
|
|
||||||
} catch (IOException e) {
|
|
||||||
if (debug) {
|
|
||||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 0, PING_INTERVAL * 1200);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Has the server owner denied plugin metrics?
|
|
||||||
*
|
|
||||||
* @return true if metrics should be opted out of it
|
|
||||||
*/
|
|
||||||
public boolean isOptOut() {
|
|
||||||
synchronized (optOutLock) {
|
|
||||||
try {
|
|
||||||
// Reload the metrics file
|
|
||||||
configuration.load(getConfigFile());
|
|
||||||
} catch (IOException ex) {
|
|
||||||
if (debug) {
|
|
||||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (InvalidConfigurationException ex) {
|
|
||||||
if (debug) {
|
|
||||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return configuration.getBoolean("opt-out", false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
|
|
||||||
*
|
|
||||||
* @throws java.io.IOException
|
|
||||||
*/
|
|
||||||
public void enable() throws IOException {
|
|
||||||
// This has to be synchronized or it can collide with the check in the task.
|
|
||||||
synchronized (optOutLock) {
|
|
||||||
// Check if the server owner has already set opt-out, if not, set it.
|
|
||||||
if (isOptOut()) {
|
|
||||||
configuration.set("opt-out", false);
|
|
||||||
configuration.save(configurationFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable Task, if it is not running
|
|
||||||
if (task == null) {
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
|
|
||||||
*
|
|
||||||
* @throws java.io.IOException
|
|
||||||
*/
|
|
||||||
public void disable() throws IOException {
|
|
||||||
// This has to be synchronized or it can collide with the check in the task.
|
|
||||||
synchronized (optOutLock) {
|
|
||||||
// Check if the server owner has already set opt-out, if not, set it.
|
|
||||||
if (!isOptOut()) {
|
|
||||||
configuration.set("opt-out", true);
|
|
||||||
configuration.save(configurationFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable Task, if it is running
|
|
||||||
if (task != null) {
|
|
||||||
task.cancel();
|
|
||||||
task = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
|
|
||||||
*
|
|
||||||
* @return the File object for the config file
|
|
||||||
*/
|
|
||||||
public File getConfigFile() {
|
|
||||||
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
|
|
||||||
// is to abuse the plugin object we already have
|
|
||||||
// plugin.getDataFolder() => base/plugins/PluginA/
|
|
||||||
// pluginsFolder => base/plugins/
|
|
||||||
// The base is not necessarily relative to the startup directory.
|
|
||||||
File pluginsFolder = plugin.getDataFolder().getParentFile();
|
|
||||||
|
|
||||||
// return => base/plugins/PluginMetrics/config.yml
|
|
||||||
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic method that posts a plugin to the metrics website
|
|
||||||
*/
|
|
||||||
private void postPlugin(boolean isPing) throws IOException {
|
|
||||||
// Server software specific section
|
|
||||||
PluginDescriptionFile description = plugin.getDescription();
|
|
||||||
String pluginName = description.getName();
|
|
||||||
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
|
||||||
String pluginVersion = description.getVersion();
|
|
||||||
String serverVersion = Bukkit.getVersion();
|
|
||||||
int playersOnline = VersionUtils.getOnlinePlayers().size();
|
|
||||||
|
|
||||||
// END server software specific section -- all code below does not use any code outside of this class / Java
|
|
||||||
|
|
||||||
// Construct the post data
|
|
||||||
StringBuilder json = new StringBuilder(1024);
|
|
||||||
json.append('{');
|
|
||||||
|
|
||||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
|
||||||
appendJSONPair(json, "guid", guid);
|
|
||||||
appendJSONPair(json, "plugin_version", pluginVersion);
|
|
||||||
appendJSONPair(json, "server_version", serverVersion);
|
|
||||||
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
|
|
||||||
|
|
||||||
// New data as of R6
|
|
||||||
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();
|
|
||||||
|
|
||||||
// normalize os arch .. amd64 -> x86_64
|
|
||||||
if (osarch.equals("amd64")) {
|
|
||||||
osarch = "x86_64";
|
|
||||||
}
|
|
||||||
|
|
||||||
appendJSONPair(json, "osname", osname);
|
|
||||||
appendJSONPair(json, "osarch", osarch);
|
|
||||||
appendJSONPair(json, "osversion", osversion);
|
|
||||||
appendJSONPair(json, "cores", Integer.toString(coreCount));
|
|
||||||
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
|
|
||||||
appendJSONPair(json, "java_version", java_version);
|
|
||||||
|
|
||||||
// If we're pinging, append it
|
|
||||||
if (isPing) {
|
|
||||||
appendJSONPair(json, "ping", "1");
|
|
||||||
}
|
|
||||||
|
|
||||||
// close json
|
|
||||||
json.append('}');
|
|
||||||
|
|
||||||
// Create the url
|
|
||||||
URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
|
|
||||||
|
|
||||||
// Connect to the website
|
|
||||||
URLConnection connection;
|
|
||||||
|
|
||||||
// Mineshafter creates a socks proxy, so we can safely bypass it
|
|
||||||
// It does not reroute POST requests so we need to go around it
|
|
||||||
if (isMineshafterPresent()) {
|
|
||||||
connection = url.openConnection(Proxy.NO_PROXY);
|
|
||||||
} else {
|
|
||||||
connection = url.openConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
byte[] uncompressed = json.toString().getBytes();
|
|
||||||
byte[] compressed = gzip(json.toString());
|
|
||||||
|
|
||||||
// Headers
|
|
||||||
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
|
|
||||||
connection.addRequestProperty("Content-Type", "application/json");
|
|
||||||
connection.addRequestProperty("Content-Encoding", "gzip");
|
|
||||||
connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
|
|
||||||
connection.addRequestProperty("Accept", "application/json");
|
|
||||||
connection.addRequestProperty("Connection", "close");
|
|
||||||
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
|
|
||||||
if (debug) {
|
|
||||||
System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the data
|
|
||||||
OutputStream os = connection.getOutputStream();
|
|
||||||
os.write(compressed);
|
|
||||||
os.flush();
|
|
||||||
|
|
||||||
// Now read the response
|
|
||||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
||||||
String response = reader.readLine();
|
|
||||||
|
|
||||||
// close resources
|
|
||||||
os.close();
|
|
||||||
reader.close();
|
|
||||||
|
|
||||||
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
|
|
||||||
if (response == null) {
|
|
||||||
response = "null";
|
|
||||||
} else if (response.startsWith("7")) {
|
|
||||||
response = response.substring(response.startsWith("7,") ? 2 : 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IOException(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* GZip compress a string of bytes
|
|
||||||
*
|
|
||||||
* @param input
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static byte[] gzip(String input) {
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
GZIPOutputStream gzos = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
gzos = new GZIPOutputStream(baos);
|
|
||||||
gzos.write(input.getBytes("UTF-8"));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (gzos != null) try {
|
|
||||||
gzos.close();
|
|
||||||
} catch (IOException ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return baos.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
|
|
||||||
*
|
|
||||||
* @return true if mineshafter is installed on the server
|
|
||||||
*/
|
|
||||||
private boolean isMineshafterPresent() {
|
|
||||||
try {
|
|
||||||
Class.forName("mineshafter.MineServer");
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Appends a json encoded key/value pair to the given string builder.
|
|
||||||
*
|
|
||||||
* @param json
|
|
||||||
* @param key
|
|
||||||
* @param value
|
|
||||||
* @throws UnsupportedEncodingException
|
|
||||||
*/
|
|
||||||
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
|
|
||||||
boolean isValueNumeric = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (value.equals("0") || !value.endsWith("0")) {
|
|
||||||
Double.parseDouble(value);
|
|
||||||
isValueNumeric = true;
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
isValueNumeric = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json.charAt(json.length() - 1) != '{') {
|
|
||||||
json.append(',');
|
|
||||||
}
|
|
||||||
|
|
||||||
json.append(escapeJSON(key));
|
|
||||||
json.append(':');
|
|
||||||
|
|
||||||
if (isValueNumeric) {
|
|
||||||
json.append(value);
|
|
||||||
} else {
|
|
||||||
json.append(escapeJSON(value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Escape a string to create a valid JSON string
|
|
||||||
*
|
|
||||||
* @param text
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static String escapeJSON(String text) {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
|
|
||||||
builder.append('"');
|
|
||||||
for (int index = 0; index < text.length(); index++) {
|
|
||||||
char chr = text.charAt(index);
|
|
||||||
|
|
||||||
switch (chr) {
|
|
||||||
case '"':
|
|
||||||
case '\\':
|
|
||||||
builder.append('\\');
|
|
||||||
builder.append(chr);
|
|
||||||
break;
|
|
||||||
case '\b':
|
|
||||||
builder.append("\\b");
|
|
||||||
break;
|
|
||||||
case '\t':
|
|
||||||
builder.append("\\t");
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
builder.append("\\n");
|
|
||||||
break;
|
|
||||||
case '\r':
|
|
||||||
builder.append("\\r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (chr < ' ') {
|
|
||||||
String t = "000" + Integer.toHexString(chr);
|
|
||||||
builder.append("\\u" + t.substring(t.length() - 4));
|
|
||||||
} else {
|
|
||||||
builder.append(chr);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
builder.append('"');
|
|
||||||
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encode text as UTF-8
|
|
||||||
*
|
|
||||||
* @param text the text to encode
|
|
||||||
* @return the encoded text, as UTF-8
|
|
||||||
*/
|
|
||||||
private static String urlEncode(final String text) throws UnsupportedEncodingException {
|
|
||||||
return URLEncoder.encode(text, "UTF-8");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
Chest Commands
|
ChestCommands
|
||||||
===================
|
===================
|
||||||
|
|
||||||
Bukkit Page: http://dev.bukkit.org/bukkit-plugins/chest-commands
|
Bukkit Page: http://dev.bukkit.org/bukkit-plugins/chest-commands
|
Binary file not shown.
|
@ -0,0 +1,121 @@
|
||||||
|
<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/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.gmail.filoghost</groupId>
|
||||||
|
<artifactId>chestcommands</artifactId>
|
||||||
|
<version>3.1.4</version>
|
||||||
|
|
||||||
|
<name>ChestCommands</name>
|
||||||
|
<url>http://dev.bukkit.org/bukkit-plugins/chest-commands</url>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<url>https://github.com/filoghost/ChestCommands</url>
|
||||||
|
<connection>scm:git:git://github.com:filoghost/ChestCommands.git</connection>
|
||||||
|
<developerConnection>scm:git:git@github.com:filoghost/ChestCommands.git</developerConnection>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
||||||
|
<!-- Disable tests -->
|
||||||
|
<skipTests>true</skipTests>
|
||||||
|
<maven.test.skip>true</maven.test.skip>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>vault-repo</id>
|
||||||
|
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>confuser-repo</id>
|
||||||
|
<url>https://ci.frostcast.net/plugin/repository/everything/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>bstats-repo</id>
|
||||||
|
<url>http://repo.bstats.org/content/repositories/releases/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>bukkit</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>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.confuser</groupId>
|
||||||
|
<artifactId>BarAPI</artifactId>
|
||||||
|
<version>3.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.black_ixx</groupId>
|
||||||
|
<artifactId>PlayerPoints</artifactId>
|
||||||
|
<version>2.1.4</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${project.basedir}/lib/PlayerPoints.jar</systemPath>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bstats</groupId>
|
||||||
|
<artifactId>bstats-bukkit-lite</artifactId>
|
||||||
|
<version>1.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<defaultGoal>clean install</defaultGoal>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bstats</pattern>
|
||||||
|
<shadedPattern>com.gmail.filoghost.holographicdisplays.metrics</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Maven
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Eclipse
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings/
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
*.iml
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Netbeans
|
||||||
|
nbproject/
|
||||||
|
|
||||||
|
# OS X
|
||||||
|
.DS_Store
|
|
@ -1,326 +1,323 @@
|
||||||
package com.gmail.filoghost.chestcommands;
|
package com.gmail.filoghost.chestcommands;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bstats.bukkit.MetricsLite;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import com.gmail.filoghost.chestcommands.SimpleUpdater.ResponseHandler;
|
|
||||||
import com.gmail.filoghost.chestcommands.bridge.BarAPIBridge;
|
import com.gmail.filoghost.chestcommands.SimpleUpdater.ResponseHandler;
|
||||||
import com.gmail.filoghost.chestcommands.bridge.EconomyBridge;
|
import com.gmail.filoghost.chestcommands.bridge.BarAPIBridge;
|
||||||
import com.gmail.filoghost.chestcommands.bridge.PlayerPointsBridge;
|
import com.gmail.filoghost.chestcommands.bridge.EconomyBridge;
|
||||||
import com.gmail.filoghost.chestcommands.command.CommandFramework;
|
import com.gmail.filoghost.chestcommands.bridge.PlayerPointsBridge;
|
||||||
import com.gmail.filoghost.chestcommands.command.CommandHandler;
|
import com.gmail.filoghost.chestcommands.command.CommandFramework;
|
||||||
import com.gmail.filoghost.chestcommands.config.AsciiPlaceholders;
|
import com.gmail.filoghost.chestcommands.command.CommandHandler;
|
||||||
import com.gmail.filoghost.chestcommands.config.Lang;
|
import com.gmail.filoghost.chestcommands.config.AsciiPlaceholders;
|
||||||
import com.gmail.filoghost.chestcommands.config.Settings;
|
import com.gmail.filoghost.chestcommands.config.Lang;
|
||||||
import com.gmail.filoghost.chestcommands.config.yaml.PluginConfig;
|
import com.gmail.filoghost.chestcommands.config.Settings;
|
||||||
import com.gmail.filoghost.chestcommands.internal.BoundItem;
|
import com.gmail.filoghost.chestcommands.config.yaml.PluginConfig;
|
||||||
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
import com.gmail.filoghost.chestcommands.internal.BoundItem;
|
||||||
import com.gmail.filoghost.chestcommands.internal.MenuData;
|
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
||||||
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
|
import com.gmail.filoghost.chestcommands.internal.MenuData;
|
||||||
import com.gmail.filoghost.chestcommands.listener.CommandListener;
|
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
|
||||||
import com.gmail.filoghost.chestcommands.listener.InventoryListener;
|
import com.gmail.filoghost.chestcommands.listener.CommandListener;
|
||||||
import com.gmail.filoghost.chestcommands.listener.JoinListener;
|
import com.gmail.filoghost.chestcommands.listener.InventoryListener;
|
||||||
import com.gmail.filoghost.chestcommands.listener.SignListener;
|
import com.gmail.filoghost.chestcommands.listener.JoinListener;
|
||||||
import com.gmail.filoghost.chestcommands.nms.AttributeRemover;
|
import com.gmail.filoghost.chestcommands.listener.SignListener;
|
||||||
import com.gmail.filoghost.chestcommands.serializer.CommandSerializer;
|
import com.gmail.filoghost.chestcommands.nms.AttributeRemover;
|
||||||
import com.gmail.filoghost.chestcommands.serializer.MenuSerializer;
|
import com.gmail.filoghost.chestcommands.serializer.CommandSerializer;
|
||||||
import com.gmail.filoghost.chestcommands.task.ErrorLoggerTask;
|
import com.gmail.filoghost.chestcommands.serializer.MenuSerializer;
|
||||||
import com.gmail.filoghost.chestcommands.task.RefreshMenusTask;
|
import com.gmail.filoghost.chestcommands.task.ErrorLoggerTask;
|
||||||
import com.gmail.filoghost.chestcommands.util.CaseInsensitiveMap;
|
import com.gmail.filoghost.chestcommands.task.RefreshMenusTask;
|
||||||
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
import com.gmail.filoghost.chestcommands.util.CaseInsensitiveMap;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
||||||
import com.gmail.filoghost.chestcommands.util.VersionUtils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
import com.gmail.filoghost.chestcommands.util.VersionUtils;
|
||||||
public class ChestCommands extends JavaPlugin {
|
|
||||||
|
public class ChestCommands extends JavaPlugin {
|
||||||
public static final String CHAT_PREFIX = ChatColor.DARK_GREEN + "[" + ChatColor.GREEN + "ChestCommands" + ChatColor.DARK_GREEN + "] " + ChatColor.GREEN;
|
|
||||||
|
public static final String CHAT_PREFIX = ChatColor.DARK_GREEN + "[" + ChatColor.GREEN + "ChestCommands" + ChatColor.DARK_GREEN + "] " + ChatColor.GREEN;
|
||||||
private static ChestCommands instance;
|
|
||||||
private static Settings settings;
|
private static ChestCommands instance;
|
||||||
private static Lang lang;
|
private static Settings settings;
|
||||||
|
private static Lang lang;
|
||||||
private static Map<String, ExtendedIconMenu> fileNameToMenuMap;
|
|
||||||
private static Map<String, ExtendedIconMenu> commandsToMenuMap;
|
private static Map<String, ExtendedIconMenu> fileNameToMenuMap;
|
||||||
|
private static Map<String, ExtendedIconMenu> commandsToMenuMap;
|
||||||
private static Set<BoundItem> boundItems;
|
|
||||||
|
private static Set<BoundItem> boundItems;
|
||||||
private static int lastReloadErrors;
|
|
||||||
private static String newVersion;
|
private static int lastReloadErrors;
|
||||||
|
private static String newVersion;
|
||||||
private static AttributeRemover attributeRemover;
|
|
||||||
|
private static AttributeRemover attributeRemover;
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
@Override
|
||||||
if (instance != null) {
|
public void onEnable() {
|
||||||
getLogger().warning("Please do not use /reload or plugin reloaders. Do \"/cc reload\" instead.");
|
if (instance != null) {
|
||||||
return;
|
getLogger().warning("Please do not use /reload or plugin reloaders. Do \"/cc reload\" instead.");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
instance = this;
|
|
||||||
fileNameToMenuMap = CaseInsensitiveMap.create();
|
instance = this;
|
||||||
commandsToMenuMap = CaseInsensitiveMap.create();
|
fileNameToMenuMap = CaseInsensitiveMap.create();
|
||||||
boundItems = Utils.newHashSet();
|
commandsToMenuMap = CaseInsensitiveMap.create();
|
||||||
|
boundItems = Utils.newHashSet();
|
||||||
settings = new Settings(new PluginConfig(this, "config.yml"));
|
|
||||||
lang = new Lang(new PluginConfig(this, "lang.yml"));
|
settings = new Settings(new PluginConfig(this, "config.yml"));
|
||||||
|
lang = new Lang(new PluginConfig(this, "lang.yml"));
|
||||||
if (!EconomyBridge.setupEconomy()) {
|
|
||||||
getLogger().warning("Vault with a compatible economy plugin was not found! Icons with a PRICE or commands that give money will not work.");
|
if (!EconomyBridge.setupEconomy()) {
|
||||||
}
|
getLogger().warning("Vault with a compatible economy plugin was not found! Icons with a PRICE or commands that give money will not work.");
|
||||||
|
}
|
||||||
if (BarAPIBridge.setupPlugin()) {
|
|
||||||
getLogger().info("Hooked BarAPI");
|
if (BarAPIBridge.setupPlugin()) {
|
||||||
}
|
getLogger().info("Hooked BarAPI");
|
||||||
|
}
|
||||||
if (PlayerPointsBridge.setupPlugin()) {
|
|
||||||
getLogger().info("Hooked PlayerPoints");
|
if (PlayerPointsBridge.setupPlugin()) {
|
||||||
}
|
getLogger().info("Hooked PlayerPoints");
|
||||||
|
}
|
||||||
AttributeRemover.setup();
|
|
||||||
|
AttributeRemover.setup();
|
||||||
if (settings.update_notifications) {
|
|
||||||
new SimpleUpdater(this, 56919).checkForUpdates(new ResponseHandler() {
|
if (settings.update_notifications) {
|
||||||
|
new SimpleUpdater(this, 56919).checkForUpdates(new ResponseHandler() {
|
||||||
@Override
|
|
||||||
public void onUpdateFound(String newVersion) {
|
@Override
|
||||||
ChestCommands.newVersion = newVersion;
|
public void onUpdateFound(String newVersion) {
|
||||||
|
ChestCommands.newVersion = newVersion;
|
||||||
if (settings.use_console_colors) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + "Found a new version: " + newVersion + ChatColor.WHITE + " (yours: v" + getDescription().getVersion() + ")");
|
if (settings.use_console_colors) {
|
||||||
Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "Download it on Bukkit Dev:");
|
Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + "Found a new version: " + newVersion + ChatColor.WHITE + " (yours: v" + getDescription().getVersion() + ")");
|
||||||
Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "dev.bukkit.org/bukkit-plugins/chest-commands");
|
Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "Download it on Bukkit Dev:");
|
||||||
} else {
|
Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "dev.bukkit.org/bukkit-plugins/chest-commands");
|
||||||
getLogger().info("Found a new version available: " + newVersion);
|
} else {
|
||||||
getLogger().info("Download it on Bukkit Dev:");
|
getLogger().info("Found a new version available: " + newVersion);
|
||||||
getLogger().info("dev.bukkit.org/bukkit-plugins/chest-commands");
|
getLogger().info("Download it on Bukkit Dev:");
|
||||||
}
|
getLogger().info("dev.bukkit.org/bukkit-plugins/chest-commands");
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
try {
|
|
||||||
new MetricsLite(this).start();
|
MetricsLite metrics = new MetricsLite(this);
|
||||||
} catch (IOException e) {
|
|
||||||
// Metrics failed.
|
Bukkit.getPluginManager().registerEvents(new CommandListener(), this);
|
||||||
}
|
Bukkit.getPluginManager().registerEvents(new InventoryListener(), this);
|
||||||
|
Bukkit.getPluginManager().registerEvents(new JoinListener(), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new CommandListener(), this);
|
Bukkit.getPluginManager().registerEvents(new SignListener(), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new InventoryListener(), this);
|
|
||||||
Bukkit.getPluginManager().registerEvents(new JoinListener(), this);
|
CommandFramework.register(this, new CommandHandler("chestcommands"));
|
||||||
Bukkit.getPluginManager().registerEvents(new SignListener(), this);
|
|
||||||
|
ErrorLogger errorLogger = new ErrorLogger();
|
||||||
CommandFramework.register(this, new CommandHandler("chestcommands"));
|
load(errorLogger);
|
||||||
|
|
||||||
ErrorLogger errorLogger = new ErrorLogger();
|
lastReloadErrors = errorLogger.getSize();
|
||||||
load(errorLogger);
|
if (errorLogger.hasErrors()) {
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new ErrorLoggerTask(errorLogger), 10L);
|
||||||
lastReloadErrors = errorLogger.getSize();
|
}
|
||||||
if (errorLogger.hasErrors()) {
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new ErrorLoggerTask(errorLogger), 10L);
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new RefreshMenusTask(), 2L, 2L);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new RefreshMenusTask(), 2L, 2L);
|
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
closeAllMenus();
|
||||||
@Override
|
}
|
||||||
public void onDisable() {
|
|
||||||
closeAllMenus();
|
|
||||||
}
|
|
||||||
|
public void load(ErrorLogger errorLogger) {
|
||||||
|
fileNameToMenuMap.clear();
|
||||||
|
commandsToMenuMap.clear();
|
||||||
public void load(ErrorLogger errorLogger) {
|
boundItems.clear();
|
||||||
fileNameToMenuMap.clear();
|
|
||||||
commandsToMenuMap.clear();
|
CommandSerializer.checkClassConstructors(errorLogger);
|
||||||
boundItems.clear();
|
|
||||||
|
try {
|
||||||
CommandSerializer.checkClassConstructors(errorLogger);
|
settings.load();
|
||||||
|
} catch (IOException e) {
|
||||||
try {
|
e.printStackTrace();
|
||||||
settings.load();
|
getLogger().warning("I/O error while using the configuration. Default values will be used.");
|
||||||
} catch (IOException e) {
|
} catch (InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
getLogger().warning("I/O error while using the configuration. Default values will be used.");
|
getLogger().warning("The config.yml was not a valid YAML, please look at the error above. Default values will be used.");
|
||||||
} catch (InvalidConfigurationException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
getLogger().warning("The config.yml was not a valid YAML, please look at the error above. Default values will be used.");
|
getLogger().warning("Unhandled error while reading the values for the configuration! Please inform the developer.");
|
||||||
} catch (Exception e) {
|
}
|
||||||
e.printStackTrace();
|
|
||||||
getLogger().warning("Unhandled error while reading the values for the configuration! Please inform the developer.");
|
try {
|
||||||
}
|
lang.load();
|
||||||
|
} catch (IOException e) {
|
||||||
try {
|
e.printStackTrace();
|
||||||
lang.load();
|
getLogger().warning("I/O error while using the language file. Default values will be used.");
|
||||||
} catch (IOException e) {
|
} catch (InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
getLogger().warning("I/O error while using the language file. Default values will be used.");
|
getLogger().warning("The lang.yml was not a valid YAML, please look at the error above. Default values will be used.");
|
||||||
} catch (InvalidConfigurationException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
getLogger().warning("The lang.yml was not a valid YAML, please look at the error above. Default values will be used.");
|
getLogger().warning("Unhandled error while reading the values for the configuration! Please inform the developer.");
|
||||||
} catch (Exception e) {
|
}
|
||||||
e.printStackTrace();
|
|
||||||
getLogger().warning("Unhandled error while reading the values for the configuration! Please inform the developer.");
|
try {
|
||||||
}
|
AsciiPlaceholders.load(errorLogger);
|
||||||
|
} catch (IOException e) {
|
||||||
try {
|
e.printStackTrace();
|
||||||
AsciiPlaceholders.load(errorLogger);
|
getLogger().warning("I/O error while reading the placeholders. They will not work.");
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
getLogger().warning("I/O error while reading the placeholders. They will not work.");
|
getLogger().warning("Unhandled error while reading the placeholders! Please inform the developer.");
|
||||||
} catch (Exception e) {
|
}
|
||||||
e.printStackTrace();
|
|
||||||
getLogger().warning("Unhandled error while reading the placeholders! Please inform the developer.");
|
// Load the menus.
|
||||||
}
|
File menusFolder = new File(getDataFolder(), "menu");
|
||||||
|
|
||||||
// Load the menus.
|
if (!menusFolder.isDirectory()) {
|
||||||
File menusFolder = new File(getDataFolder(), "menu");
|
// Create the directory with the default menu.
|
||||||
|
menusFolder.mkdirs();
|
||||||
if (!menusFolder.isDirectory()) {
|
Utils.saveResourceSafe(this, "menu" + File.separator + "example.yml");
|
||||||
// Create the directory with the default menu.
|
}
|
||||||
menusFolder.mkdirs();
|
|
||||||
Utils.saveResourceSafe(this, "menu" + File.separator + "example.yml");
|
List<PluginConfig> menusList = loadMenus(menusFolder);
|
||||||
}
|
for (PluginConfig menuConfig : menusList) {
|
||||||
|
try {
|
||||||
List<PluginConfig> menusList = loadMenus(menusFolder);
|
menuConfig.load();
|
||||||
for (PluginConfig menuConfig : menusList) {
|
} catch (IOException e) {
|
||||||
try {
|
e.printStackTrace();
|
||||||
menuConfig.load();
|
errorLogger.addError("I/O error while loading the menu \"" + menuConfig.getFileName() + "\". Is the file in use?");
|
||||||
} catch (IOException e) {
|
continue;
|
||||||
e.printStackTrace();
|
} catch (InvalidConfigurationException e) {
|
||||||
errorLogger.addError("I/O error while loading the menu \"" + menuConfig.getFileName() + "\". Is the file in use?");
|
e.printStackTrace();
|
||||||
continue;
|
errorLogger.addError("Invalid YAML configuration for the menu \"" + menuConfig.getFileName() + "\". Please look at the error above, or use an online YAML parser (google is your friend).");
|
||||||
} catch (InvalidConfigurationException e) {
|
continue;
|
||||||
e.printStackTrace();
|
}
|
||||||
errorLogger.addError("Invalid YAML configuration for the menu \"" + menuConfig.getFileName() + "\". Please look at the error above, or use an online YAML parser (google is your friend).");
|
|
||||||
continue;
|
MenuData data = MenuSerializer.loadMenuData(menuConfig, errorLogger);
|
||||||
}
|
ExtendedIconMenu iconMenu = MenuSerializer.loadMenu(menuConfig, data.getTitle(), data.getRows(), errorLogger);
|
||||||
|
|
||||||
MenuData data = MenuSerializer.loadMenuData(menuConfig, errorLogger);
|
if (fileNameToMenuMap.containsKey(menuConfig.getFileName())) {
|
||||||
ExtendedIconMenu iconMenu = MenuSerializer.loadMenu(menuConfig, data.getTitle(), data.getRows(), errorLogger);
|
errorLogger.addError("Two menus have the same file name \"" + menuConfig.getFileName() + "\" with different cases. There will be problems opening one of these two menus.");
|
||||||
|
}
|
||||||
if (fileNameToMenuMap.containsKey(menuConfig.getFileName())) {
|
fileNameToMenuMap.put(menuConfig.getFileName(), iconMenu);
|
||||||
errorLogger.addError("Two menus have the same file name \"" + menuConfig.getFileName() + "\" with different cases. There will be problems opening one of these two menus.");
|
|
||||||
}
|
if (data.hasCommands()) {
|
||||||
fileNameToMenuMap.put(menuConfig.getFileName(), iconMenu);
|
for (String command : data.getCommands()) {
|
||||||
|
if (!command.isEmpty()) {
|
||||||
if (data.hasCommands()) {
|
if (commandsToMenuMap.containsKey(command)) {
|
||||||
for (String command : data.getCommands()) {
|
errorLogger.addError("The menus \"" + commandsToMenuMap.get(command).getFileName() + "\" and \"" + menuConfig.getFileName() + "\" have the same command \"" + command + "\". Only one will be opened.");
|
||||||
if (!command.isEmpty()) {
|
}
|
||||||
if (commandsToMenuMap.containsKey(command)) {
|
commandsToMenuMap.put(command, iconMenu);
|
||||||
errorLogger.addError("The menus \"" + commandsToMenuMap.get(command).getFileName() + "\" and \"" + menuConfig.getFileName() + "\" have the same command \"" + command + "\". Only one will be opened.");
|
}
|
||||||
}
|
}
|
||||||
commandsToMenuMap.put(command, iconMenu);
|
}
|
||||||
}
|
|
||||||
}
|
iconMenu.setRefreshTicks(data.getRefreshTenths());
|
||||||
}
|
|
||||||
|
if (data.getOpenActions() != null) {
|
||||||
iconMenu.setRefreshTicks(data.getRefreshTenths());
|
iconMenu.setOpenActions(data.getOpenActions());
|
||||||
|
}
|
||||||
if (data.getOpenActions() != null) {
|
|
||||||
iconMenu.setOpenActions(data.getOpenActions());
|
if (data.hasBoundMaterial() && data.getClickType() != null) {
|
||||||
}
|
BoundItem boundItem = new BoundItem(iconMenu, data.getBoundMaterial(), data.getClickType());
|
||||||
|
if (data.hasBoundDataValue()) {
|
||||||
if (data.hasBoundMaterial() && data.getClickType() != null) {
|
boundItem.setRestrictiveData(data.getBoundDataValue());
|
||||||
BoundItem boundItem = new BoundItem(iconMenu, data.getBoundMaterial(), data.getClickType());
|
}
|
||||||
if (data.hasBoundDataValue()) {
|
boundItems.add(boundItem);
|
||||||
boundItem.setRestrictiveData(data.getBoundDataValue());
|
}
|
||||||
}
|
}
|
||||||
boundItems.add(boundItem);
|
|
||||||
}
|
// Register the BungeeCord plugin channel.
|
||||||
}
|
if (!Bukkit.getMessenger().isOutgoingChannelRegistered(this, "BungeeCord")) {
|
||||||
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||||
// Register the BungeeCord plugin channel.
|
}
|
||||||
if (!Bukkit.getMessenger().isOutgoingChannelRegistered(this, "BungeeCord")) {
|
}
|
||||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Loads all the configuration files recursively into a list.
|
||||||
|
*/
|
||||||
/**
|
private List<PluginConfig> loadMenus(File file) {
|
||||||
* Loads all the configuration files recursively into a list.
|
List<PluginConfig> list = Utils.newArrayList();
|
||||||
*/
|
if (file.isDirectory()) {
|
||||||
private List<PluginConfig> loadMenus(File file) {
|
for (File subFile : file.listFiles()) {
|
||||||
List<PluginConfig> list = Utils.newArrayList();
|
list.addAll(loadMenus(subFile));
|
||||||
if (file.isDirectory()) {
|
}
|
||||||
for (File subFile : file.listFiles()) {
|
} else if (file.isFile()) {
|
||||||
list.addAll(loadMenus(subFile));
|
if (file.getName().endsWith(".yml")) {
|
||||||
}
|
list.add(new PluginConfig(this, file));
|
||||||
} else if (file.isFile()) {
|
}
|
||||||
if (file.getName().endsWith(".yml")) {
|
}
|
||||||
list.add(new PluginConfig(this, file));
|
return list;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
public static void closeAllMenus() {
|
||||||
|
for (Player player : VersionUtils.getOnlinePlayers()) {
|
||||||
|
if (player.getOpenInventory() != null) {
|
||||||
public static void closeAllMenus() {
|
if (player.getOpenInventory().getTopInventory().getHolder() instanceof MenuInventoryHolder || player.getOpenInventory().getBottomInventory().getHolder() instanceof MenuInventoryHolder) {
|
||||||
for (Player player : VersionUtils.getOnlinePlayers()) {
|
player.closeInventory();
|
||||||
if (player.getOpenInventory() != null) {
|
}
|
||||||
if (player.getOpenInventory().getTopInventory().getHolder() instanceof MenuInventoryHolder || player.getOpenInventory().getBottomInventory().getHolder() instanceof MenuInventoryHolder) {
|
}
|
||||||
player.closeInventory();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
public static ChestCommands getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
public static ChestCommands getInstance() {
|
|
||||||
return instance;
|
public static Settings getSettings() {
|
||||||
}
|
return settings;
|
||||||
|
}
|
||||||
public static Settings getSettings() {
|
|
||||||
return settings;
|
public static Lang getLang() {
|
||||||
}
|
return lang;
|
||||||
|
}
|
||||||
public static Lang getLang() {
|
|
||||||
return lang;
|
public static boolean hasNewVersion() {
|
||||||
}
|
return newVersion != null;
|
||||||
|
}
|
||||||
public static boolean hasNewVersion() {
|
|
||||||
return newVersion != null;
|
public static String getNewVersion() {
|
||||||
}
|
return newVersion;
|
||||||
|
}
|
||||||
public static String getNewVersion() {
|
|
||||||
return newVersion;
|
public static Map<String, ExtendedIconMenu> getFileNameToMenuMap() {
|
||||||
}
|
return fileNameToMenuMap;
|
||||||
|
}
|
||||||
public static Map<String, ExtendedIconMenu> getFileNameToMenuMap() {
|
|
||||||
return fileNameToMenuMap;
|
public static Map<String, ExtendedIconMenu> getCommandToMenuMap() {
|
||||||
}
|
return commandsToMenuMap;
|
||||||
|
}
|
||||||
public static Map<String, ExtendedIconMenu> getCommandToMenuMap() {
|
|
||||||
return commandsToMenuMap;
|
public static Set<BoundItem> getBoundItems() {
|
||||||
}
|
return boundItems;
|
||||||
|
}
|
||||||
public static Set<BoundItem> getBoundItems() {
|
|
||||||
return boundItems;
|
public static int getLastReloadErrors() {
|
||||||
}
|
return lastReloadErrors;
|
||||||
|
}
|
||||||
public static int getLastReloadErrors() {
|
|
||||||
return lastReloadErrors;
|
public static void setLastReloadErrors(int lastReloadErrors) {
|
||||||
}
|
ChestCommands.lastReloadErrors = lastReloadErrors;
|
||||||
|
}
|
||||||
public static void setLastReloadErrors(int lastReloadErrors) {
|
|
||||||
ChestCommands.lastReloadErrors = lastReloadErrors;
|
public static AttributeRemover getAttributeRemover() {
|
||||||
}
|
return attributeRemover;
|
||||||
|
}
|
||||||
public static AttributeRemover getAttributeRemover() {
|
|
||||||
return attributeRemover;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,14 +1,14 @@
|
||||||
package com.gmail.filoghost.chestcommands;
|
package com.gmail.filoghost.chestcommands;
|
||||||
|
|
||||||
public class Permissions {
|
public class Permissions {
|
||||||
|
|
||||||
public static final String
|
public static final String
|
||||||
|
|
||||||
UPDATE_NOTIFICATIONS = "chestcommands.update",
|
UPDATE_NOTIFICATIONS = "chestcommands.update",
|
||||||
SEE_ERRORS = "chestcommands.errors",
|
SEE_ERRORS = "chestcommands.errors",
|
||||||
SIGN_CREATE = "chestcommands.sign",
|
SIGN_CREATE = "chestcommands.sign",
|
||||||
|
|
||||||
COMMAND_BASE = "chestcommands.command.",
|
COMMAND_BASE = "chestcommands.command.",
|
||||||
OPEN_MENU_BASE = "chestcommands.open.";
|
OPEN_MENU_BASE = "chestcommands.open.";
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,166 +1,166 @@
|
||||||
package com.gmail.filoghost.chestcommands;
|
package com.gmail.filoghost.chestcommands;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.JSONValue;
|
import org.json.simple.JSONValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A very simple and lightweight updater.
|
* A very simple and lightweight updater.
|
||||||
*/
|
*/
|
||||||
public final class SimpleUpdater {
|
public final class SimpleUpdater {
|
||||||
|
|
||||||
public interface ResponseHandler {
|
public interface ResponseHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the updater finds a new version.
|
* Called when the updater finds a new version.
|
||||||
* @param newVersion - the new version
|
* @param newVersion - the new version
|
||||||
*/
|
*/
|
||||||
public void onUpdateFound(final String newVersion);
|
public void onUpdateFound(final String newVersion);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Plugin plugin;
|
private Plugin plugin;
|
||||||
private int projectId;
|
private int projectId;
|
||||||
|
|
||||||
public SimpleUpdater(Plugin plugin, int projectId) {
|
public SimpleUpdater(Plugin plugin, int projectId) {
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
throw new NullPointerException("Plugin cannot be null");
|
throw new NullPointerException("Plugin cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.projectId = projectId;
|
this.projectId = projectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates a new async thread to check for updates.
|
* This method creates a new async thread to check for updates.
|
||||||
*/
|
*/
|
||||||
public void checkForUpdates(final ResponseHandler responseHandler) {
|
public void checkForUpdates(final ResponseHandler responseHandler) {
|
||||||
Thread updaterThread = new Thread(new Runnable() {
|
Thread updaterThread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONArray filesArray = (JSONArray) readJson("https://api.curseforge.com/servermods/files?projectIds=" + projectId);
|
JSONArray filesArray = (JSONArray) readJson("https://api.curseforge.com/servermods/files?projectIds=" + projectId);
|
||||||
|
|
||||||
if (filesArray.size() == 0) {
|
if (filesArray.size() == 0) {
|
||||||
// The array cannot be empty, there must be at least one file. The project ID is not valid.
|
// The array cannot be empty, there must be at least one file. The project ID is not valid.
|
||||||
plugin.getLogger().warning("The project ID (" + projectId + ") provided for updating is invalid or curse had a problem.");
|
plugin.getLogger().warning("The project ID (" + projectId + ") provided for updating is invalid or curse had a problem.");
|
||||||
plugin.getLogger().warning("If the error persists, please inform the author.");
|
plugin.getLogger().warning("If the error persists, please inform the author.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String updateName = (String) ((JSONObject) filesArray.get(filesArray.size() - 1)).get("name");
|
String updateName = (String) ((JSONObject) filesArray.get(filesArray.size() - 1)).get("name");
|
||||||
final String newVersion = extractVersion(updateName);
|
final String newVersion = extractVersion(updateName);
|
||||||
|
|
||||||
if (newVersion == null) {
|
if (newVersion == null) {
|
||||||
throw new NumberFormatException();
|
throw new NumberFormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNewerVersion(newVersion)) {
|
if (isNewerVersion(newVersion)) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
responseHandler.onUpdateFound(newVersion);
|
responseHandler.onUpdateFound(newVersion);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
plugin.getLogger().warning("Could not contact BukkitDev to check for updates.");
|
plugin.getLogger().warning("Could not contact BukkitDev to check for updates.");
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
plugin.getLogger().warning("The author of this plugin has misconfigured the Updater system.");
|
plugin.getLogger().warning("The author of this plugin has misconfigured the Updater system.");
|
||||||
plugin.getLogger().warning("File versions should follow the format 'PluginName vVERSION'");
|
plugin.getLogger().warning("File versions should follow the format 'PluginName vVERSION'");
|
||||||
plugin.getLogger().warning("Please notify the author of this error.");
|
plugin.getLogger().warning("Please notify the author of this error.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
plugin.getLogger().warning("Unable to check for updates: unhandled exception.");
|
plugin.getLogger().warning("Unable to check for updates: unhandled exception.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
updaterThread.start();
|
updaterThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object readJson(String url) throws MalformedURLException, IOException {
|
private Object readJson(String url) throws MalformedURLException, IOException {
|
||||||
|
|
||||||
URLConnection conn = new URL(url).openConnection();
|
URLConnection conn = new URL(url).openConnection();
|
||||||
conn.setConnectTimeout(5000);
|
conn.setConnectTimeout(5000);
|
||||||
conn.setReadTimeout(8000);
|
conn.setReadTimeout(8000);
|
||||||
conn.addRequestProperty("User-Agent", "Updater (by filoghost)");
|
conn.addRequestProperty("User-Agent", "Updater (by filoghost)");
|
||||||
conn.setDoOutput(true);
|
conn.setDoOutput(true);
|
||||||
|
|
||||||
return JSONValue.parse(new BufferedReader(new InputStreamReader(conn.getInputStream())));
|
return JSONValue.parse(new BufferedReader(new InputStreamReader(conn.getInputStream())));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare the version found with the plugin's version, from an array of integer separated by full stops.
|
* Compare the version found with the plugin's version, from an array of integer separated by full stops.
|
||||||
* Examples:
|
* Examples:
|
||||||
* v1.2 > v1.12
|
* v1.2 > v1.12
|
||||||
* v2.1 = v2.01
|
* v2.1 = v2.01
|
||||||
*/
|
*/
|
||||||
private boolean isNewerVersion(String remoteVersion) {
|
private boolean isNewerVersion(String remoteVersion) {
|
||||||
String pluginVersion = plugin.getDescription().getVersion();
|
String pluginVersion = plugin.getDescription().getVersion();
|
||||||
|
|
||||||
if (pluginVersion == null) {
|
if (pluginVersion == null) {
|
||||||
// Do not throw exceptions, just consider it as v0.
|
// Do not throw exceptions, just consider it as v0.
|
||||||
pluginVersion = "0";
|
pluginVersion = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!remoteVersion.matches("v?[0-9\\.]+")) {
|
if (!remoteVersion.matches("v?[0-9\\.]+")) {
|
||||||
// Should always be checked before by this class.
|
// Should always be checked before by this class.
|
||||||
throw new IllegalArgumentException("fetched version's format is incorrect");
|
throw new IllegalArgumentException("fetched version's format is incorrect");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove all the "v" from the versions, replace multiple full stops with a single full stop, and split them.
|
// Remove all the "v" from the versions, replace multiple full stops with a single full stop, and split them.
|
||||||
String[] pluginVersionSplit = pluginVersion.replace("v", "").replaceAll("[\\.]{2,}", ".").split("\\.");
|
String[] pluginVersionSplit = pluginVersion.replace("v", "").replaceAll("[\\.]{2,}", ".").split("\\.");
|
||||||
String[] remoteVersionSplit = remoteVersion.replace("v", "").replaceAll("[\\.]{2,}", ".").split("\\.");
|
String[] remoteVersionSplit = remoteVersion.replace("v", "").replaceAll("[\\.]{2,}", ".").split("\\.");
|
||||||
|
|
||||||
int longest = Math.max(pluginVersionSplit.length, remoteVersionSplit.length);
|
int longest = Math.max(pluginVersionSplit.length, remoteVersionSplit.length);
|
||||||
|
|
||||||
int[] pluginVersionArray = new int[longest];
|
int[] pluginVersionArray = new int[longest];
|
||||||
int[] remoteVersionArray = new int[longest];
|
int[] remoteVersionArray = new int[longest];
|
||||||
|
|
||||||
for (int i = 0; i < pluginVersionSplit.length; i++) {
|
for (int i = 0; i < pluginVersionSplit.length; i++) {
|
||||||
pluginVersionArray[i] = Integer.parseInt(pluginVersionSplit[i]);
|
pluginVersionArray[i] = Integer.parseInt(pluginVersionSplit[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < remoteVersionSplit.length; i++) {
|
for (int i = 0; i < remoteVersionSplit.length; i++) {
|
||||||
remoteVersionArray[i] = Integer.parseInt(remoteVersionSplit[i]);
|
remoteVersionArray[i] = Integer.parseInt(remoteVersionSplit[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < longest; i++) {
|
for (int i = 0; i < longest; i++) {
|
||||||
int diff = remoteVersionArray[i] - pluginVersionArray[i];
|
int diff = remoteVersionArray[i] - pluginVersionArray[i];
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
return true;
|
return true;
|
||||||
} else if (diff < 0) {
|
} else if (diff < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue the loop.
|
// Continue the loop.
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String extractVersion(String input) {
|
private String extractVersion(String input) {
|
||||||
Matcher matcher = Pattern.compile("v[0-9\\.]+").matcher(input);
|
Matcher matcher = Pattern.compile("v[0-9\\.]+").matcher(input);
|
||||||
|
|
||||||
String result = null;
|
String result = null;
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
result = matcher.group();
|
result = matcher.group();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,36 +1,36 @@
|
||||||
package com.gmail.filoghost.chestcommands.api;
|
package com.gmail.filoghost.chestcommands.api;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
|
|
||||||
public class ChestCommandsAPI {
|
public class ChestCommandsAPI {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a menu with a given file name was loaded by the plugin.
|
* Checks if a menu with a given file name was loaded by the plugin.
|
||||||
*
|
*
|
||||||
* @return true - if the menu was found.
|
* @return true - if the menu was found.
|
||||||
*/
|
*/
|
||||||
public static boolean isPluginMenu(String yamlFile) {
|
public static boolean isPluginMenu(String yamlFile) {
|
||||||
return ChestCommands.getFileNameToMenuMap().containsKey(yamlFile);
|
return ChestCommands.getFileNameToMenuMap().containsKey(yamlFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a menu loaded by ChestCommands to a player.
|
* Opens a menu loaded by ChestCommands to a player.
|
||||||
* NOTE: this method ignores permissions.
|
* NOTE: this method ignores permissions.
|
||||||
*
|
*
|
||||||
* @param player - the player that will see the GUI.
|
* @param player - the player that will see the GUI.
|
||||||
* @param yamlFile - the file name of the menu to open. The .yml extension CANNOT be omitted.
|
* @param yamlFile - the file name of the menu to open. The .yml extension CANNOT be omitted.
|
||||||
* @return true - if the menu was found and opened, false if not.
|
* @return true - if the menu was found and opened, false if not.
|
||||||
*/
|
*/
|
||||||
public static boolean openPluginMenu(Player player, String yamlFile) {
|
public static boolean openPluginMenu(Player player, String yamlFile) {
|
||||||
IconMenu menu = ChestCommands.getFileNameToMenuMap().get(yamlFile);
|
IconMenu menu = ChestCommands.getFileNameToMenuMap().get(yamlFile);
|
||||||
|
|
||||||
if (menu != null) {
|
if (menu != null) {
|
||||||
menu.open(player);
|
menu.open(player);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,14 +1,14 @@
|
||||||
package com.gmail.filoghost.chestcommands.api;
|
package com.gmail.filoghost.chestcommands.api;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public interface ClickHandler {
|
public interface ClickHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param player - the player that clicked on the icon.
|
* @param player - the player that clicked on the icon.
|
||||||
* @return true if the menu should be closed, false otherwise.
|
* @return true if the menu should be closed, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean onClick(Player player);
|
public boolean onClick(Player player);
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,312 +1,312 @@
|
||||||
package com.gmail.filoghost.chestcommands.api;
|
package com.gmail.filoghost.chestcommands.api;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.internal.Variable;
|
import com.gmail.filoghost.chestcommands.internal.Variable;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class Icon {
|
public class Icon {
|
||||||
|
|
||||||
private Material material;
|
private Material material;
|
||||||
private int amount;
|
private int amount;
|
||||||
private short dataValue;
|
private short dataValue;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private List<String> lore;
|
private List<String> lore;
|
||||||
private Map<Enchantment, Integer> enchantments;
|
private Map<Enchantment, Integer> enchantments;
|
||||||
private Color color;
|
private Color color;
|
||||||
private String skullOwner;
|
private String skullOwner;
|
||||||
|
|
||||||
protected boolean closeOnClick;
|
protected boolean closeOnClick;
|
||||||
private ClickHandler clickHandler;
|
private ClickHandler clickHandler;
|
||||||
|
|
||||||
private Set<Variable> nameVariables;
|
private Set<Variable> nameVariables;
|
||||||
private Map<Integer, Set<Variable>> loreVariables;
|
private Map<Integer, Set<Variable>> loreVariables;
|
||||||
private ItemStack cachedItem; // When there are no variables, we don't recreate the item.
|
private ItemStack cachedItem; // When there are no variables, we don't recreate the item.
|
||||||
|
|
||||||
public Icon() {
|
public Icon() {
|
||||||
enchantments = new HashMap<Enchantment, Integer>();
|
enchantments = new HashMap<Enchantment, Integer>();
|
||||||
closeOnClick = true;
|
closeOnClick = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasVariables() {
|
public boolean hasVariables() {
|
||||||
return nameVariables != null || loreVariables != null;
|
return nameVariables != null || loreVariables != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaterial(Material material) {
|
public void setMaterial(Material material) {
|
||||||
if (material == Material.AIR) material = null;
|
if (material == Material.AIR) material = null;
|
||||||
this.material = material;
|
this.material = material;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getMaterial() {
|
public Material getMaterial() {
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAmount(int amount) {
|
public void setAmount(int amount) {
|
||||||
if (amount < 1) amount = 1;
|
if (amount < 1) amount = 1;
|
||||||
else if (amount > 127) amount = 127;
|
else if (amount > 127) amount = 127;
|
||||||
|
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAmount() {
|
public int getAmount() {
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDataValue(short dataValue) {
|
public void setDataValue(short dataValue) {
|
||||||
if (dataValue < 0) dataValue = 0;
|
if (dataValue < 0) dataValue = 0;
|
||||||
|
|
||||||
this.dataValue = dataValue;
|
this.dataValue = dataValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getDataValue() {
|
public short getDataValue() {
|
||||||
return dataValue;
|
return dataValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.nameVariables = null; // Reset the variables
|
this.nameVariables = null; // Reset the variables
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
for (Variable variable : Variable.values()) {
|
for (Variable variable : Variable.values()) {
|
||||||
if (name.contains(variable.getText())) {
|
if (name.contains(variable.getText())) {
|
||||||
|
|
||||||
if (nameVariables == null) {
|
if (nameVariables == null) {
|
||||||
nameVariables = new HashSet<Variable>();
|
nameVariables = new HashSet<Variable>();
|
||||||
}
|
}
|
||||||
|
|
||||||
nameVariables.add(variable);
|
nameVariables.add(variable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasName() {
|
public boolean hasName() {
|
||||||
return name != null;
|
return name != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLore(String... lore) {
|
public void setLore(String... lore) {
|
||||||
if (lore != null) {
|
if (lore != null) {
|
||||||
setLore(Arrays.asList(lore));
|
setLore(Arrays.asList(lore));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLore(List<String> lore) {
|
public void setLore(List<String> lore) {
|
||||||
this.lore = lore;
|
this.lore = lore;
|
||||||
this.loreVariables = null; // Reset the variables
|
this.loreVariables = null; // Reset the variables
|
||||||
|
|
||||||
if (lore != null) {
|
if (lore != null) {
|
||||||
for (int i = 0; i < lore.size(); i++) {
|
for (int i = 0; i < lore.size(); i++) {
|
||||||
for (Variable variable : Variable.values()) {
|
for (Variable variable : Variable.values()) {
|
||||||
if (lore.get(i).contains(variable.getText())) {
|
if (lore.get(i).contains(variable.getText())) {
|
||||||
|
|
||||||
if (loreVariables == null) {
|
if (loreVariables == null) {
|
||||||
loreVariables = new HashMap<Integer, Set<Variable>>();
|
loreVariables = new HashMap<Integer, Set<Variable>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<Variable> lineVariables = loreVariables.get(i);
|
Set<Variable> lineVariables = loreVariables.get(i);
|
||||||
|
|
||||||
if (lineVariables == null) {
|
if (lineVariables == null) {
|
||||||
lineVariables = new HashSet<Variable>();
|
lineVariables = new HashSet<Variable>();
|
||||||
loreVariables.put(i, lineVariables);
|
loreVariables.put(i, lineVariables);
|
||||||
}
|
}
|
||||||
|
|
||||||
lineVariables.add(variable);
|
lineVariables.add(variable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasLore() {
|
public boolean hasLore() {
|
||||||
return lore != null && lore.size() > 0;
|
return lore != null && lore.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getLore() {
|
public List<String> getLore() {
|
||||||
return lore;
|
return lore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnchantments(Map<Enchantment, Integer> enchantments) {
|
public void setEnchantments(Map<Enchantment, Integer> enchantments) {
|
||||||
if (enchantments == null) {
|
if (enchantments == null) {
|
||||||
this.enchantments.clear();
|
this.enchantments.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.enchantments = enchantments;
|
this.enchantments = enchantments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Enchantment, Integer> getEnchantments() {
|
public Map<Enchantment, Integer> getEnchantments() {
|
||||||
return new HashMap<Enchantment, Integer>(enchantments);
|
return new HashMap<Enchantment, Integer>(enchantments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEnchantment(Enchantment ench) {
|
public void addEnchantment(Enchantment ench) {
|
||||||
addEnchantment(ench, 1);
|
addEnchantment(ench, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEnchantment(Enchantment ench, Integer level) {
|
public void addEnchantment(Enchantment ench, Integer level) {
|
||||||
enchantments.put(ench, level);
|
enchantments.put(ench, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeEnchantment(Enchantment ench) {
|
public void removeEnchantment(Enchantment ench) {
|
||||||
enchantments.remove(ench);
|
enchantments.remove(ench);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearEnchantments() {
|
public void clearEnchantments() {
|
||||||
enchantments.clear();
|
enchantments.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color getColor() {
|
public Color getColor() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(Color color) {
|
public void setColor(Color color) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSkullOwner() {
|
public String getSkullOwner() {
|
||||||
return skullOwner;
|
return skullOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSkullOwner(String skullOwner) {
|
public void setSkullOwner(String skullOwner) {
|
||||||
this.skullOwner = skullOwner;
|
this.skullOwner = skullOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCloseOnClick(boolean closeOnClick) {
|
public void setCloseOnClick(boolean closeOnClick) {
|
||||||
this.closeOnClick = closeOnClick;
|
this.closeOnClick = closeOnClick;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClickHandler(ClickHandler clickHandler) {
|
public void setClickHandler(ClickHandler clickHandler) {
|
||||||
this.clickHandler = clickHandler;
|
this.clickHandler = clickHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClickHandler getClickHandler() {
|
public ClickHandler getClickHandler() {
|
||||||
return clickHandler;
|
return clickHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String calculateName(Player pov) {
|
protected String calculateName(Player pov) {
|
||||||
if (hasName()) {
|
if (hasName()) {
|
||||||
|
|
||||||
String name = this.name;
|
String name = this.name;
|
||||||
|
|
||||||
if (pov != null && nameVariables != null) {
|
if (pov != null && nameVariables != null) {
|
||||||
for (Variable nameVariable : nameVariables) {
|
for (Variable nameVariable : nameVariables) {
|
||||||
name = name.replace(nameVariable.getText(), nameVariable.getReplacement(pov));
|
name = name.replace(nameVariable.getText(), nameVariable.getReplacement(pov));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
// Add a color to display the name empty.
|
// Add a color to display the name empty.
|
||||||
return ChatColor.WHITE.toString();
|
return ChatColor.WHITE.toString();
|
||||||
} else {
|
} else {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<String> calculateLore(Player pov) {
|
protected List<String> calculateLore(Player pov) {
|
||||||
|
|
||||||
List<String> output = null;
|
List<String> output = null;
|
||||||
|
|
||||||
if (hasLore()) {
|
if (hasLore()) {
|
||||||
|
|
||||||
output = Utils.newArrayList();
|
output = Utils.newArrayList();
|
||||||
|
|
||||||
if (pov != null && loreVariables != null) {
|
if (pov != null && loreVariables != null) {
|
||||||
for (int i = 0; i < lore.size(); i++) {
|
for (int i = 0; i < lore.size(); i++) {
|
||||||
|
|
||||||
String line = lore.get(i);
|
String line = lore.get(i);
|
||||||
|
|
||||||
Set<Variable> lineVariables = loreVariables.get(i);
|
Set<Variable> lineVariables = loreVariables.get(i);
|
||||||
if (lineVariables != null) {
|
if (lineVariables != null) {
|
||||||
for (Variable lineVariable : lineVariables) {
|
for (Variable lineVariable : lineVariables) {
|
||||||
line = line.replace(lineVariable.getText(), lineVariable.getReplacement(pov));
|
line = line.replace(lineVariable.getText(), lineVariable.getReplacement(pov));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output.add(line);
|
output.add(line);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise just copy the lines.
|
// Otherwise just copy the lines.
|
||||||
output.addAll(lore);
|
output.addAll(lore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
|
|
||||||
if (output == null) {
|
if (output == null) {
|
||||||
output = Utils.newArrayList();
|
output = Utils.newArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add an error message.
|
// Add an error message.
|
||||||
output.add(ChatColor.RED + "(Invalid material)");
|
output.add(ChatColor.RED + "(Invalid material)");
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack createItemstack(Player pov) {
|
public ItemStack createItemstack(Player pov) {
|
||||||
|
|
||||||
if (!this.hasVariables() && cachedItem != null) {
|
if (!this.hasVariables() && cachedItem != null) {
|
||||||
// Performance.
|
// Performance.
|
||||||
return cachedItem;
|
return cachedItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the material is not set, display BEDROCK.
|
// If the material is not set, display BEDROCK.
|
||||||
ItemStack itemStack = (material != null) ? new ItemStack(material, amount, dataValue) : new ItemStack(Material.BEDROCK, amount);
|
ItemStack itemStack = (material != null) ? new ItemStack(material, amount, dataValue) : new ItemStack(Material.BEDROCK, amount);
|
||||||
|
|
||||||
// Apply name, lore and color.
|
// Apply name, lore and color.
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
|
||||||
itemMeta.setDisplayName(calculateName(pov));
|
itemMeta.setDisplayName(calculateName(pov));
|
||||||
itemMeta.setLore(calculateLore(pov));
|
itemMeta.setLore(calculateLore(pov));
|
||||||
|
|
||||||
if (color != null && itemMeta instanceof LeatherArmorMeta) {
|
if (color != null && itemMeta instanceof LeatherArmorMeta) {
|
||||||
((LeatherArmorMeta) itemMeta).setColor(color);
|
((LeatherArmorMeta) itemMeta).setColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skullOwner != null && itemMeta instanceof SkullMeta) {
|
if (skullOwner != null && itemMeta instanceof SkullMeta) {
|
||||||
((SkullMeta) itemMeta).setOwner(skullOwner);
|
((SkullMeta) itemMeta).setOwner(skullOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
itemStack.setItemMeta(itemMeta);
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
|
||||||
// Apply enchants.
|
// Apply enchants.
|
||||||
if (enchantments.size() > 0) {
|
if (enchantments.size() > 0) {
|
||||||
for (Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
|
for (Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
|
||||||
itemStack.addUnsafeEnchantment(entry.getKey(), entry.getValue());
|
itemStack.addUnsafeEnchantment(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.hasVariables()) {
|
if (!this.hasVariables()) {
|
||||||
// If there are no variables, cache the item.
|
// If there are no variables, cache the item.
|
||||||
cachedItem = itemStack;
|
cachedItem = itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onClick(Player whoClicked) {
|
public boolean onClick(Player whoClicked) {
|
||||||
if (clickHandler != null) {
|
if (clickHandler != null) {
|
||||||
return clickHandler.onClick(whoClicked);
|
return clickHandler.onClick(whoClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
return closeOnClick;
|
return closeOnClick;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,93 +1,93 @@
|
||||||
package com.gmail.filoghost.chestcommands.api;
|
package com.gmail.filoghost.chestcommands.api;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
|
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
|
||||||
import com.gmail.filoghost.chestcommands.nms.AttributeRemover;
|
import com.gmail.filoghost.chestcommands.nms.AttributeRemover;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
import com.gmail.filoghost.chestcommands.util.Validate;
|
import com.gmail.filoghost.chestcommands.util.Validate;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MEMO: Raw slot numbers
|
* MEMO: Raw slot numbers
|
||||||
*
|
*
|
||||||
* | 0| 1| 2| 3| 4| 5| 6| 7| 8|
|
* | 0| 1| 2| 3| 4| 5| 6| 7| 8|
|
||||||
* | 9|10|11|12|13|14|15|16|17|
|
* | 9|10|11|12|13|14|15|16|17|
|
||||||
* ...
|
* ...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class IconMenu {
|
public class IconMenu {
|
||||||
|
|
||||||
protected final String title;
|
protected final String title;
|
||||||
protected final Icon[] icons;
|
protected final Icon[] icons;
|
||||||
|
|
||||||
|
|
||||||
public IconMenu(String title, int rows) {
|
public IconMenu(String title, int rows) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
icons = new Icon[rows * 9];
|
icons = new Icon[rows * 9];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIcon(int x, int y, Icon icon) {
|
public void setIcon(int x, int y, Icon icon) {
|
||||||
int slot = Utils.makePositive(y - 1) * 9 + Utils.makePositive(x - 1);
|
int slot = Utils.makePositive(y - 1) * 9 + Utils.makePositive(x - 1);
|
||||||
if (slot >= 0 && slot < icons.length) {
|
if (slot >= 0 && slot < icons.length) {
|
||||||
icons[slot] = icon;
|
icons[slot] = icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIconRaw(int slot, Icon icon) {
|
public void setIconRaw(int slot, Icon icon) {
|
||||||
if (slot >= 0 && slot < icons.length) {
|
if (slot >= 0 && slot < icons.length) {
|
||||||
icons[slot] = icon;
|
icons[slot] = icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Icon getIcon(int x, int y) {
|
public Icon getIcon(int x, int y) {
|
||||||
int slot = Utils.makePositive(y - 1) * 9 + Utils.makePositive(x - 1);
|
int slot = Utils.makePositive(y - 1) * 9 + Utils.makePositive(x - 1);
|
||||||
if (slot >= 0 && slot < icons.length) {
|
if (slot >= 0 && slot < icons.length) {
|
||||||
return icons[slot];
|
return icons[slot];
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Icon getIconRaw(int slot) {
|
public Icon getIconRaw(int slot) {
|
||||||
if (slot >= 0 && slot < icons.length) {
|
if (slot >= 0 && slot < icons.length) {
|
||||||
return icons[slot];
|
return icons[slot];
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRows() {
|
public int getRows() {
|
||||||
return icons.length / 9;
|
return icons.length / 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return icons.length;
|
return icons.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void open(Player player) {
|
public void open(Player player) {
|
||||||
Validate.notNull(player, "Player cannot be null");
|
Validate.notNull(player, "Player cannot be null");
|
||||||
|
|
||||||
Inventory inventory = Bukkit.createInventory(new MenuInventoryHolder(this), icons.length, title);
|
Inventory inventory = Bukkit.createInventory(new MenuInventoryHolder(this), icons.length, title);
|
||||||
|
|
||||||
for (int i = 0; i < icons.length; i++) {
|
for (int i = 0; i < icons.length; i++) {
|
||||||
if (icons[i] != null) {
|
if (icons[i] != null) {
|
||||||
inventory.setItem(i, AttributeRemover.hideAttributes(icons[i].createItemstack(player)));
|
inventory.setItem(i, AttributeRemover.hideAttributes(icons[i].createItemstack(player)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
player.openInventory(inventory);
|
player.openInventory(inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "IconMenu [title=" + title + ", icons=" + Arrays.toString(icons) + "]";
|
return "IconMenu [title=" + title + ", icons=" + Arrays.toString(icons) + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,34 +1,34 @@
|
||||||
package com.gmail.filoghost.chestcommands.bridge;
|
package com.gmail.filoghost.chestcommands.bridge;
|
||||||
|
|
||||||
import me.confuser.barapi.BarAPI;
|
import me.confuser.barapi.BarAPI;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class BarAPIBridge {
|
public class BarAPIBridge {
|
||||||
|
|
||||||
private static BarAPI barAPI;
|
private static BarAPI barAPI;
|
||||||
|
|
||||||
public static boolean setupPlugin() {
|
public static boolean setupPlugin() {
|
||||||
Plugin barPlugin = Bukkit.getPluginManager().getPlugin("BarAPI");
|
Plugin barPlugin = Bukkit.getPluginManager().getPlugin("BarAPI");
|
||||||
|
|
||||||
if (barPlugin == null) {
|
if (barPlugin == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
barAPI = (BarAPI) barPlugin;
|
barAPI = (BarAPI) barPlugin;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasValidPlugin() {
|
public static boolean hasValidPlugin() {
|
||||||
return barAPI != null;
|
return barAPI != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setMessage(Player player, String message, int seconds) {
|
public static void setMessage(Player player, String message, int seconds) {
|
||||||
if (!hasValidPlugin()) throw new IllegalStateException("BarAPI plugin was not found!");
|
if (!hasValidPlugin()) throw new IllegalStateException("BarAPI plugin was not found!");
|
||||||
|
|
||||||
BarAPI.setMessage(player, message, seconds);
|
BarAPI.setMessage(player, message, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,89 +1,89 @@
|
||||||
package com.gmail.filoghost.chestcommands.bridge;
|
package com.gmail.filoghost.chestcommands.bridge;
|
||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import net.milkbowl.vault.economy.EconomyResponse;
|
import net.milkbowl.vault.economy.EconomyResponse;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class EconomyBridge {
|
public class EconomyBridge {
|
||||||
|
|
||||||
private static Economy economy;
|
private static Economy economy;
|
||||||
|
|
||||||
public static boolean setupEconomy() {
|
public static boolean setupEconomy() {
|
||||||
if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
|
if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
|
RegisteredServiceProvider<Economy> rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
|
||||||
if (rsp == null) {
|
if (rsp == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
economy = rsp.getProvider();
|
economy = rsp.getProvider();
|
||||||
return economy != null;
|
return economy != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasValidEconomy() {
|
public static boolean hasValidEconomy() {
|
||||||
return economy != null;
|
return economy != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Economy getEconomy() {
|
public static Economy getEconomy() {
|
||||||
if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!");
|
if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!");
|
||||||
return economy;
|
return economy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getMoney(Player player) {
|
public static double getMoney(Player player) {
|
||||||
if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!");
|
if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!");
|
||||||
return economy.getBalance(player.getName(), player.getWorld().getName());
|
return economy.getBalance(player.getName(), player.getWorld().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasMoney(Player player, double minimum) {
|
public static boolean hasMoney(Player player, double minimum) {
|
||||||
if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!");
|
if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!");
|
||||||
if (minimum < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + minimum);
|
if (minimum < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + minimum);
|
||||||
|
|
||||||
double balance = economy.getBalance(player.getName(), player.getWorld().getName());
|
double balance = economy.getBalance(player.getName(), player.getWorld().getName());
|
||||||
|
|
||||||
if (balance < minimum) {
|
if (balance < minimum) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the operation was successful.
|
* @return true if the operation was successful.
|
||||||
*/
|
*/
|
||||||
public static boolean takeMoney(Player player, double amount) {
|
public static boolean takeMoney(Player player, double amount) {
|
||||||
if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!");
|
if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!");
|
||||||
if (amount < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + amount);
|
if (amount < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + amount);
|
||||||
|
|
||||||
EconomyResponse response = economy.withdrawPlayer(player.getName(), player.getWorld().getName(), amount);
|
EconomyResponse response = economy.withdrawPlayer(player.getName(), player.getWorld().getName(), amount);
|
||||||
boolean result = response.transactionSuccess();
|
boolean result = response.transactionSuccess();
|
||||||
|
|
||||||
Utils.refreshMenu(player);
|
Utils.refreshMenu(player);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean giveMoney(Player player, double amount) {
|
public static boolean giveMoney(Player player, double amount) {
|
||||||
if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!");
|
if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!");
|
||||||
if (amount < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + amount);
|
if (amount < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + amount);
|
||||||
|
|
||||||
EconomyResponse response = economy.depositPlayer(player.getName(), player.getWorld().getName(), amount);
|
EconomyResponse response = economy.depositPlayer(player.getName(), player.getWorld().getName(), amount);
|
||||||
boolean result = response.transactionSuccess();
|
boolean result = response.transactionSuccess();
|
||||||
|
|
||||||
Utils.refreshMenu(player);
|
Utils.refreshMenu(player);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatMoney(double amount) {
|
public static String formatMoney(double amount) {
|
||||||
if (hasValidEconomy()) {
|
if (hasValidEconomy()) {
|
||||||
return economy.format(amount);
|
return economy.format(amount);
|
||||||
} else {
|
} else {
|
||||||
return Double.toString(amount);
|
return Double.toString(amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,68 +1,68 @@
|
||||||
package com.gmail.filoghost.chestcommands.bridge;
|
package com.gmail.filoghost.chestcommands.bridge;
|
||||||
|
|
||||||
import org.black_ixx.playerpoints.PlayerPoints;
|
import org.black_ixx.playerpoints.PlayerPoints;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
// PlayerPoints minimum version: 2.0
|
// PlayerPoints minimum version: 2.0
|
||||||
public class PlayerPointsBridge {
|
public class PlayerPointsBridge {
|
||||||
|
|
||||||
private static PlayerPoints playerPoints;
|
private static PlayerPoints playerPoints;
|
||||||
|
|
||||||
public static boolean setupPlugin() {
|
public static boolean setupPlugin() {
|
||||||
Plugin pointsPlugin = Bukkit.getPluginManager().getPlugin("PlayerPoints");
|
Plugin pointsPlugin = Bukkit.getPluginManager().getPlugin("PlayerPoints");
|
||||||
|
|
||||||
if (pointsPlugin == null) {
|
if (pointsPlugin == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
playerPoints = (PlayerPoints) pointsPlugin;
|
playerPoints = (PlayerPoints) pointsPlugin;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasValidPlugin() {
|
public static boolean hasValidPlugin() {
|
||||||
return playerPoints != null;
|
return playerPoints != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPoints(Player player) {
|
public static int getPoints(Player player) {
|
||||||
if (!hasValidPlugin()) throw new IllegalStateException("PlayerPoints plugin was not found!");
|
if (!hasValidPlugin()) throw new IllegalStateException("PlayerPoints plugin was not found!");
|
||||||
return playerPoints.getAPI().look(player.getUniqueId());
|
return playerPoints.getAPI().look(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasPoints(Player player, int minimum) {
|
public static boolean hasPoints(Player player, int minimum) {
|
||||||
if (!hasValidPlugin()) throw new IllegalStateException("PlayerPoints plugin was not found!");
|
if (!hasValidPlugin()) throw new IllegalStateException("PlayerPoints plugin was not found!");
|
||||||
if (minimum < 0) throw new IllegalArgumentException("Invalid amount of points: " + minimum);
|
if (minimum < 0) throw new IllegalArgumentException("Invalid amount of points: " + minimum);
|
||||||
|
|
||||||
return playerPoints.getAPI().look(player.getUniqueId()) >= minimum;
|
return playerPoints.getAPI().look(player.getUniqueId()) >= minimum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the operation was successful.
|
* @return true if the operation was successful.
|
||||||
*/
|
*/
|
||||||
public static boolean takePoints(Player player, int points) {
|
public static boolean takePoints(Player player, int points) {
|
||||||
if (!hasValidPlugin()) throw new IllegalStateException("PlayerPoints plugin was not found!");
|
if (!hasValidPlugin()) throw new IllegalStateException("PlayerPoints plugin was not found!");
|
||||||
if (points < 0) throw new IllegalArgumentException("Invalid amount of points: " + points);
|
if (points < 0) throw new IllegalArgumentException("Invalid amount of points: " + points);
|
||||||
|
|
||||||
boolean result = playerPoints.getAPI().take(player.getUniqueId(), points);
|
boolean result = playerPoints.getAPI().take(player.getUniqueId(), points);
|
||||||
|
|
||||||
Utils.refreshMenu(player);
|
Utils.refreshMenu(player);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean givePoints(Player player, int points) {
|
public static boolean givePoints(Player player, int points) {
|
||||||
if (!hasValidPlugin()) throw new IllegalStateException("PlayerPoints plugin was not found!");
|
if (!hasValidPlugin()) throw new IllegalStateException("PlayerPoints plugin was not found!");
|
||||||
if (points < 0) throw new IllegalArgumentException("Invalid amount of points: " + points);
|
if (points < 0) throw new IllegalArgumentException("Invalid amount of points: " + points);
|
||||||
|
|
||||||
boolean result = playerPoints.getAPI().give(player.getUniqueId(), points);
|
boolean result = playerPoints.getAPI().give(player.getUniqueId(), points);
|
||||||
|
|
||||||
Utils.refreshMenu(player);
|
Utils.refreshMenu(player);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,39 +1,39 @@
|
||||||
package com.gmail.filoghost.chestcommands.bridge.bungee;
|
package com.gmail.filoghost.chestcommands.bridge.bungee;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
|
|
||||||
public class BungeeCordUtils {
|
public class BungeeCordUtils {
|
||||||
|
|
||||||
public static boolean connect(Player player, String server) {
|
public static boolean connect(Player player, String server) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (server.length() == 0) {
|
if (server.length() == 0) {
|
||||||
player.sendMessage("§cTarget server was \"\" (empty string) cannot connect to it.");
|
player.sendMessage("§cTarget server was \"\" (empty string) cannot connect to it.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
|
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
|
||||||
DataOutputStream out = new DataOutputStream(byteArray);
|
DataOutputStream out = new DataOutputStream(byteArray);
|
||||||
|
|
||||||
out.writeUTF("Connect");
|
out.writeUTF("Connect");
|
||||||
out.writeUTF(server); // Target Server.
|
out.writeUTF(server); // Target Server.
|
||||||
|
|
||||||
player.sendPluginMessage(ChestCommands.getInstance(), "BungeeCord", byteArray.toByteArray());
|
player.sendPluginMessage(ChestCommands.getInstance(), "BungeeCord", byteArray.toByteArray());
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
player.sendMessage(ChatColor.RED + "An unexpected exception has occurred. Please notify the server's staff about this. (They should look at the console).");
|
player.sendMessage(ChatColor.RED + "An unexpected exception has occurred. Please notify the server's staff about this. (They should look at the console).");
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
ChestCommands.getInstance().getLogger().warning("Could not connect \"" + player.getName() + "\" to the server \"" + server + "\".");
|
ChestCommands.getInstance().getLogger().warning("Could not connect \"" + player.getName() + "\" to the server \"" + server + "\".");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,151 +1,151 @@
|
||||||
package com.gmail.filoghost.chestcommands.command;
|
package com.gmail.filoghost.chestcommands.command;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for the default command executor.
|
* Wrapper for the default command executor.
|
||||||
*/
|
*/
|
||||||
public abstract class CommandFramework implements CommandExecutor {
|
public abstract class CommandFramework implements CommandExecutor {
|
||||||
|
|
||||||
/***************************************************
|
/***************************************************
|
||||||
*
|
*
|
||||||
* STATIC REGISTER METHOD
|
* STATIC REGISTER METHOD
|
||||||
*
|
*
|
||||||
***************************************************/
|
***************************************************/
|
||||||
public static boolean register(JavaPlugin plugin, CommandFramework command) {
|
public static boolean register(JavaPlugin plugin, CommandFramework command) {
|
||||||
PluginCommand pluginCommand = plugin.getCommand(command.label);
|
PluginCommand pluginCommand = plugin.getCommand(command.label);
|
||||||
|
|
||||||
if (pluginCommand == null) {
|
if (pluginCommand == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginCommand.setExecutor(command);
|
pluginCommand.setExecutor(command);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************
|
/***************************************************
|
||||||
*
|
*
|
||||||
* COMMAND FRAMEWORK CLASS
|
* COMMAND FRAMEWORK CLASS
|
||||||
*
|
*
|
||||||
***************************************************/
|
***************************************************/
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
public CommandFramework(String label) {
|
public CommandFramework(String label) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
execute(sender, label, args);
|
execute(sender, label, args);
|
||||||
|
|
||||||
} catch (CommandException ex) {
|
} catch (CommandException ex) {
|
||||||
|
|
||||||
if (ex.getMessage() != null && !ex.getMessage().isEmpty()) {
|
if (ex.getMessage() != null && !ex.getMessage().isEmpty()) {
|
||||||
// Use RED by default.
|
// Use RED by default.
|
||||||
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void execute(CommandSender sender, String label, String[] args);
|
public abstract void execute(CommandSender sender, String label, String[] args);
|
||||||
|
|
||||||
|
|
||||||
/***************************************************
|
/***************************************************
|
||||||
*
|
*
|
||||||
* COMMAND EXCEPTION
|
* COMMAND EXCEPTION
|
||||||
*
|
*
|
||||||
***************************************************/
|
***************************************************/
|
||||||
public static class CommandException extends RuntimeException {
|
public static class CommandException extends RuntimeException {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public CommandException(String msg) {
|
public CommandException(String msg) {
|
||||||
super(msg);
|
super(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***************************************************
|
/***************************************************
|
||||||
*
|
*
|
||||||
* VALIDATE CLASS
|
* VALIDATE CLASS
|
||||||
*
|
*
|
||||||
***************************************************/
|
***************************************************/
|
||||||
public static class CommandValidate {
|
public static class CommandValidate {
|
||||||
|
|
||||||
public static void notNull(Object o, String msg) {
|
public static void notNull(Object o, String msg) {
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
throw new CommandException(msg);
|
throw new CommandException(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void isTrue(boolean b, String msg) {
|
public static void isTrue(boolean b, String msg) {
|
||||||
if (!b) {
|
if (!b) {
|
||||||
throw new CommandException(msg);
|
throw new CommandException(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPositiveInteger(String input) {
|
public static int getPositiveInteger(String input) {
|
||||||
try {
|
try {
|
||||||
int i = Integer.parseInt(input);
|
int i = Integer.parseInt(input);
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
throw new CommandException("The number must be 0 or positive.");
|
throw new CommandException("The number must be 0 or positive.");
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new CommandException("Invalid number \"" + input + "\".");
|
throw new CommandException("Invalid number \"" + input + "\".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPositiveIntegerNotZero(String input) {
|
public static int getPositiveIntegerNotZero(String input) {
|
||||||
try {
|
try {
|
||||||
int i = Integer.parseInt(input);
|
int i = Integer.parseInt(input);
|
||||||
if (i <= 0) {
|
if (i <= 0) {
|
||||||
throw new CommandException("The number must be positive.");
|
throw new CommandException("The number must be positive.");
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new CommandException("Invalid number \"" + input + "\".");
|
throw new CommandException("Invalid number \"" + input + "\".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getPositiveDouble(String input) {
|
public static double getPositiveDouble(String input) {
|
||||||
try {
|
try {
|
||||||
double d = Double.parseDouble(input);
|
double d = Double.parseDouble(input);
|
||||||
if (d < 0) {
|
if (d < 0) {
|
||||||
throw new CommandException("The number must be 0 or positive.");
|
throw new CommandException("The number must be 0 or positive.");
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new CommandException("Invalid number \"" + input + "\".");
|
throw new CommandException("Invalid number \"" + input + "\".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getPositiveDoubleNotZero(String input) {
|
public static double getPositiveDoubleNotZero(String input) {
|
||||||
try {
|
try {
|
||||||
double d = Integer.parseInt(input);
|
double d = Integer.parseInt(input);
|
||||||
if (d <= 0) {
|
if (d <= 0) {
|
||||||
throw new CommandException("The number must be positive.");
|
throw new CommandException("The number must be positive.");
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new CommandException("Invalid number \"" + input + "\".");
|
throw new CommandException("Invalid number \"" + input + "\".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void minLength(Object[] array, int minLength, String msg) {
|
public static void minLength(Object[] array, int minLength, String msg) {
|
||||||
if (array.length < minLength) {
|
if (array.length < minLength) {
|
||||||
throw new CommandException(msg);
|
throw new CommandException(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,128 +1,128 @@
|
||||||
package com.gmail.filoghost.chestcommands.command;
|
package com.gmail.filoghost.chestcommands.command;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
import com.gmail.filoghost.chestcommands.Permissions;
|
import com.gmail.filoghost.chestcommands.Permissions;
|
||||||
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
||||||
import com.gmail.filoghost.chestcommands.task.ErrorLoggerTask;
|
import com.gmail.filoghost.chestcommands.task.ErrorLoggerTask;
|
||||||
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
||||||
|
|
||||||
public class CommandHandler extends CommandFramework {
|
public class CommandHandler extends CommandFramework {
|
||||||
|
|
||||||
public CommandHandler(String label) {
|
public CommandHandler(String label) {
|
||||||
super(label);
|
super(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String label, String[] args) {
|
public void execute(CommandSender sender, String label, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
// This info is accessible to anyone. Please don't remove it, remember that Chest Commands is developed for FREE.
|
// This info is accessible to anyone. Please don't remove it, remember that Chest Commands is developed for FREE.
|
||||||
sender.sendMessage(ChestCommands.CHAT_PREFIX);
|
sender.sendMessage(ChestCommands.CHAT_PREFIX);
|
||||||
sender.sendMessage(ChatColor.GREEN + "Version: " + ChatColor.GRAY + ChestCommands.getInstance().getDescription().getVersion());
|
sender.sendMessage(ChatColor.GREEN + "Version: " + ChatColor.GRAY + ChestCommands.getInstance().getDescription().getVersion());
|
||||||
sender.sendMessage(ChatColor.GREEN + "Developer: " + ChatColor.GRAY + "filoghost");
|
sender.sendMessage(ChatColor.GREEN + "Developer: " + ChatColor.GRAY + "filoghost");
|
||||||
sender.sendMessage(ChatColor.GREEN + "Commands: " + ChatColor.GRAY + "/" + label + " help");
|
sender.sendMessage(ChatColor.GREEN + "Commands: " + ChatColor.GRAY + "/" + label + " help");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("help")) {
|
if (args[0].equalsIgnoreCase("help")) {
|
||||||
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "help"), "You don't have permission.");
|
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "help"), "You don't have permission.");
|
||||||
sender.sendMessage(ChestCommands.CHAT_PREFIX + " Commands:");
|
sender.sendMessage(ChestCommands.CHAT_PREFIX + " Commands:");
|
||||||
sender.sendMessage(ChatColor.WHITE + "/" + label + " reload" + ChatColor.GRAY + " - Reloads the plugin.");
|
sender.sendMessage(ChatColor.WHITE + "/" + label + " reload" + ChatColor.GRAY + " - Reloads the plugin.");
|
||||||
sender.sendMessage(ChatColor.WHITE + "/" + label + " list" + ChatColor.GRAY + " - Lists the loaded menus.");
|
sender.sendMessage(ChatColor.WHITE + "/" + label + " list" + ChatColor.GRAY + " - Lists the loaded menus.");
|
||||||
sender.sendMessage(ChatColor.WHITE + "/" + label + " open <menu> [player]" + ChatColor.GRAY + " - Opens a menu for a player.");
|
sender.sendMessage(ChatColor.WHITE + "/" + label + " open <menu> [player]" + ChatColor.GRAY + " - Opens a menu for a player.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("reload")) {
|
if (args[0].equalsIgnoreCase("reload")) {
|
||||||
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "reload"), "You don't have permission.");
|
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "reload"), "You don't have permission.");
|
||||||
|
|
||||||
ChestCommands.closeAllMenus();
|
ChestCommands.closeAllMenus();
|
||||||
|
|
||||||
ErrorLogger errorLogger = new ErrorLogger();
|
ErrorLogger errorLogger = new ErrorLogger();
|
||||||
ChestCommands.getInstance().load(errorLogger);
|
ChestCommands.getInstance().load(errorLogger);
|
||||||
|
|
||||||
ChestCommands.setLastReloadErrors(errorLogger.getSize());
|
ChestCommands.setLastReloadErrors(errorLogger.getSize());
|
||||||
|
|
||||||
if (!errorLogger.hasErrors()) {
|
if (!errorLogger.hasErrors()) {
|
||||||
sender.sendMessage(ChestCommands.CHAT_PREFIX + "Plugin reloaded.");
|
sender.sendMessage(ChestCommands.CHAT_PREFIX + "Plugin reloaded.");
|
||||||
} else {
|
} else {
|
||||||
new ErrorLoggerTask(errorLogger).run();
|
new ErrorLoggerTask(errorLogger).run();
|
||||||
sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Plugin reloaded with " + errorLogger.getSize() + " error(s).");
|
sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Plugin reloaded with " + errorLogger.getSize() + " error(s).");
|
||||||
if (!(sender instanceof ConsoleCommandSender)) {
|
if (!(sender instanceof ConsoleCommandSender)) {
|
||||||
sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Please check the console.");
|
sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Please check the console.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("open")) {
|
if (args[0].equalsIgnoreCase("open")) {
|
||||||
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "open"), "You don't have permission.");
|
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "open"), "You don't have permission.");
|
||||||
CommandValidate.minLength(args, 2, "Usage: /" + label + " open <menu> [player]");
|
CommandValidate.minLength(args, 2, "Usage: /" + label + " open <menu> [player]");
|
||||||
|
|
||||||
Player target = null;
|
Player target = null;
|
||||||
|
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
CommandValidate.minLength(args, 3, "You must specify a player from the console.");
|
CommandValidate.minLength(args, 3, "You must specify a player from the console.");
|
||||||
target = Bukkit.getPlayerExact(args[2]);
|
target = Bukkit.getPlayerExact(args[2]);
|
||||||
} else {
|
} else {
|
||||||
if (args.length > 2) {
|
if (args.length > 2) {
|
||||||
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "open.others"), "You don't have permission to open menus for others.");
|
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "open.others"), "You don't have permission to open menus for others.");
|
||||||
target = Bukkit.getPlayerExact(args[2]);
|
target = Bukkit.getPlayerExact(args[2]);
|
||||||
} else {
|
} else {
|
||||||
target = (Player) sender;
|
target = (Player) sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandValidate.notNull(target, "That player is not online.");
|
CommandValidate.notNull(target, "That player is not online.");
|
||||||
|
|
||||||
String menuName = args[1].toLowerCase().endsWith(".yml") ? args[1] : args[1] + ".yml";
|
String menuName = args[1].toLowerCase().endsWith(".yml") ? args[1] : args[1] + ".yml";
|
||||||
ExtendedIconMenu menu = ChestCommands.getFileNameToMenuMap().get(menuName);
|
ExtendedIconMenu menu = ChestCommands.getFileNameToMenuMap().get(menuName);
|
||||||
CommandValidate.notNull(menu, "The menu \"" + menuName + "\" was not found.");
|
CommandValidate.notNull(menu, "The menu \"" + menuName + "\" was not found.");
|
||||||
|
|
||||||
if (!sender.hasPermission(menu.getPermission())) {
|
if (!sender.hasPermission(menu.getPermission())) {
|
||||||
menu.sendNoPermissionMessage(sender);
|
menu.sendNoPermissionMessage(sender);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender.getName().equalsIgnoreCase(target.getName())) {
|
if (sender.getName().equalsIgnoreCase(target.getName())) {
|
||||||
if (!ChestCommands.getLang().open_menu.isEmpty()) {
|
if (!ChestCommands.getLang().open_menu.isEmpty()) {
|
||||||
sender.sendMessage(ChestCommands.getLang().open_menu.replace("{menu}", menuName));
|
sender.sendMessage(ChestCommands.getLang().open_menu.replace("{menu}", menuName));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!ChestCommands.getLang().open_menu_others.isEmpty()) {
|
if (!ChestCommands.getLang().open_menu_others.isEmpty()) {
|
||||||
sender.sendMessage(ChestCommands.getLang().open_menu_others.replace("{menu}", menuName).replace("{player}", target.getName()));
|
sender.sendMessage(ChestCommands.getLang().open_menu_others.replace("{menu}", menuName).replace("{player}", target.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.open(target);
|
menu.open(target);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("list")) {
|
if (args[0].equalsIgnoreCase("list")) {
|
||||||
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "list"), "You don't have permission.");
|
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_BASE + "list"), "You don't have permission.");
|
||||||
sender.sendMessage(ChestCommands.CHAT_PREFIX + " Loaded menus:");
|
sender.sendMessage(ChestCommands.CHAT_PREFIX + " Loaded menus:");
|
||||||
for (String file : ChestCommands.getFileNameToMenuMap().keySet()) {
|
for (String file : ChestCommands.getFileNameToMenuMap().keySet()) {
|
||||||
sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.WHITE + file);
|
sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.WHITE + file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.RED + "Unknown sub-command \"" + args[0] + "\".");
|
sender.sendMessage(ChatColor.RED + "Unknown sub-command \"" + args[0] + "\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,100 +1,100 @@
|
||||||
package com.gmail.filoghost.chestcommands.config;
|
package com.gmail.filoghost.chestcommands.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringEscapeUtils;
|
import org.apache.commons.lang.StringEscapeUtils;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is not a real YAML file ;)
|
* This is not a real YAML file ;)
|
||||||
*/
|
*/
|
||||||
public class AsciiPlaceholders {
|
public class AsciiPlaceholders {
|
||||||
|
|
||||||
private static Map<String, String> placeholders = Utils.newHashMap();
|
private static Map<String, String> placeholders = Utils.newHashMap();
|
||||||
|
|
||||||
|
|
||||||
public static void load(ErrorLogger errorLogger) throws IOException, Exception {
|
public static void load(ErrorLogger errorLogger) throws IOException, Exception {
|
||||||
|
|
||||||
placeholders.clear();
|
placeholders.clear();
|
||||||
File file = new File(ChestCommands.getInstance().getDataFolder(), "placeholders.yml");
|
File file = new File(ChestCommands.getInstance().getDataFolder(), "placeholders.yml");
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
Utils.saveResourceSafe(ChestCommands.getInstance(), "placeholders.yml");
|
Utils.saveResourceSafe(ChestCommands.getInstance(), "placeholders.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> lines = Utils.readLines(file);
|
List<String> lines = Utils.readLines(file);
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
|
|
||||||
// Comment or empty line.
|
// Comment or empty line.
|
||||||
if (line.isEmpty() || line.startsWith("#")) {
|
if (line.isEmpty() || line.startsWith("#")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!line.contains(":")) {
|
if (!line.contains(":")) {
|
||||||
errorLogger.addError("Unable to parse a line(" + line + ") from placeholders.yml: it must contain ':' to separate the placeholder and the replacement.");
|
errorLogger.addError("Unable to parse a line(" + line + ") from placeholders.yml: it must contain ':' to separate the placeholder and the replacement.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int indexOf = line.indexOf(':');
|
int indexOf = line.indexOf(':');
|
||||||
String placeholder = unquote(line.substring(0, indexOf).trim());
|
String placeholder = unquote(line.substring(0, indexOf).trim());
|
||||||
String replacement = Utils.addColors(StringEscapeUtils.unescapeJava(unquote(line.substring(indexOf + 1, line.length()).trim())));
|
String replacement = Utils.addColors(StringEscapeUtils.unescapeJava(unquote(line.substring(indexOf + 1, line.length()).trim())));
|
||||||
|
|
||||||
if (placeholder.length() == 0 || replacement.length() == 0) {
|
if (placeholder.length() == 0 || replacement.length() == 0) {
|
||||||
errorLogger.addError("Unable to parse a line(" + line + ") from placeholders.yml: the placeholder and the replacement must have both at least 1 character.");
|
errorLogger.addError("Unable to parse a line(" + line + ") from placeholders.yml: the placeholder and the replacement must have both at least 1 character.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (placeholder.length() > 100) {
|
if (placeholder.length() > 100) {
|
||||||
errorLogger.addError("Unable to parse a line(" + line + ") from placeholders.yml: the placeholder cannot be longer than 100 characters.");
|
errorLogger.addError("Unable to parse a line(" + line + ") from placeholders.yml: the placeholder cannot be longer than 100 characters.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
placeholders.put(placeholder, replacement);
|
placeholders.put(placeholder, replacement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> placeholdersToSymbols(List<String> input) {
|
public static List<String> placeholdersToSymbols(List<String> input) {
|
||||||
if (input == null) return null;
|
if (input == null) return null;
|
||||||
for (int i = 0; i < input.size(); i++) {
|
for (int i = 0; i < input.size(); i++) {
|
||||||
input.set(i, placeholdersToSymbols(input.get(i)));
|
input.set(i, placeholdersToSymbols(input.get(i)));
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String placeholdersToSymbols(String input) {
|
public static String placeholdersToSymbols(String input) {
|
||||||
if (input == null) return null;
|
if (input == null) return null;
|
||||||
for (Entry<String, String> entry : placeholders.entrySet()) {
|
for (Entry<String, String> entry : placeholders.entrySet()) {
|
||||||
input = input.replace(entry.getKey(), entry.getValue());
|
input = input.replace(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String symbolsToPlaceholders(String input) {
|
public static String symbolsToPlaceholders(String input) {
|
||||||
if (input == null) return null;
|
if (input == null) return null;
|
||||||
for (Entry<String, String> entry : placeholders.entrySet()) {
|
for (Entry<String, String> entry : placeholders.entrySet()) {
|
||||||
input = input.replace(entry.getValue(), entry.getKey());
|
input = input.replace(entry.getValue(), entry.getKey());
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String unquote(String input) {
|
private static String unquote(String input) {
|
||||||
if (input.length() < 2) {
|
if (input.length() < 2) {
|
||||||
// Cannot be quoted.
|
// Cannot be quoted.
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
if (input.startsWith("'") && input.endsWith("'")) {
|
if (input.startsWith("'") && input.endsWith("'")) {
|
||||||
return input.substring(1, input.length() - 1);
|
return input.substring(1, input.length() - 1);
|
||||||
} else if (input.startsWith("\"") && input.endsWith("\"")) {
|
} else if (input.startsWith("\"") && input.endsWith("\"")) {
|
||||||
return input.substring(1, input.length() - 1);
|
return input.substring(1, input.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,22 +1,22 @@
|
||||||
package com.gmail.filoghost.chestcommands.config;
|
package com.gmail.filoghost.chestcommands.config;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.config.yaml.PluginConfig;
|
import com.gmail.filoghost.chestcommands.config.yaml.PluginConfig;
|
||||||
import com.gmail.filoghost.chestcommands.config.yaml.SpecialConfig;
|
import com.gmail.filoghost.chestcommands.config.yaml.SpecialConfig;
|
||||||
|
|
||||||
public class Lang extends SpecialConfig {
|
public class Lang extends SpecialConfig {
|
||||||
|
|
||||||
public String no_open_permission = "&cYou don't have permission &e{permission} &cto use this menu.";
|
public String no_open_permission = "&cYou don't have permission &e{permission} &cto use this menu.";
|
||||||
public String default_no_icon_permission = "&cYou don't have permission for this icon.";
|
public String default_no_icon_permission = "&cYou don't have permission for this icon.";
|
||||||
public String no_required_item = "&cYou must have &e{amount}x {material} &c(ID: {id}, data value: {datavalue}) for this.";
|
public String no_required_item = "&cYou must have &e{amount}x {material} &c(ID: {id}, data value: {datavalue}) for this.";
|
||||||
public String no_money = "&cYou need {money}$ for this.";
|
public String no_money = "&cYou need {money}$ for this.";
|
||||||
public String no_points = "&cYou need {points} player points for this.";
|
public String no_points = "&cYou need {points} player points for this.";
|
||||||
public String no_exp = "&cYou need {levels} XP levels for this.";
|
public String no_exp = "&cYou need {levels} XP levels for this.";
|
||||||
public String menu_not_found = "&cMenu not found! Please inform the staff.";
|
public String menu_not_found = "&cMenu not found! Please inform the staff.";
|
||||||
public String open_menu = "&aOpening the menu \"{menu}\".";
|
public String open_menu = "&aOpening the menu \"{menu}\".";
|
||||||
public String open_menu_others = "&aOpening the menu \"{menu}\" to {player}.";
|
public String open_menu_others = "&aOpening the menu \"{menu}\" to {player}.";
|
||||||
public String any = "any"; // Used in no_required_item when data value is not restrictive.
|
public String any = "any"; // Used in no_required_item when data value is not restrictive.
|
||||||
|
|
||||||
public Lang(PluginConfig config) {
|
public Lang(PluginConfig config) {
|
||||||
super(config);
|
super(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,21 +1,21 @@
|
||||||
package com.gmail.filoghost.chestcommands.config;
|
package com.gmail.filoghost.chestcommands.config;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.config.yaml.PluginConfig;
|
import com.gmail.filoghost.chestcommands.config.yaml.PluginConfig;
|
||||||
import com.gmail.filoghost.chestcommands.config.yaml.SpecialConfig;
|
import com.gmail.filoghost.chestcommands.config.yaml.SpecialConfig;
|
||||||
|
|
||||||
public class Settings extends SpecialConfig {
|
public class Settings extends SpecialConfig {
|
||||||
|
|
||||||
public boolean use_console_colors = true;
|
public boolean use_console_colors = true;
|
||||||
public String default_color__name = "&f";
|
public String default_color__name = "&f";
|
||||||
public String default_color__lore = "&7";
|
public String default_color__lore = "&7";
|
||||||
public String multiple_commands_separator = ";";
|
public String multiple_commands_separator = ";";
|
||||||
public boolean update_notifications = true;
|
public boolean update_notifications = true;
|
||||||
public int anti_click_spam_delay = 200;
|
public int anti_click_spam_delay = 200;
|
||||||
public boolean use_only_commands_without_args = true;
|
public boolean use_only_commands_without_args = true;
|
||||||
|
|
||||||
public Settings(PluginConfig config) {
|
public Settings(PluginConfig config) {
|
||||||
super(config);
|
super(config);
|
||||||
setHeader("ChestCommands configuration file.\nTutorial: http://dev.bukkit.org/bukkit-plugins/chest-commands\n");
|
setHeader("ChestCommands configuration file.\nTutorial: http://dev.bukkit.org/bukkit-plugins/chest-commands\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,59 +1,59 @@
|
||||||
package com.gmail.filoghost.chestcommands.config.yaml;
|
package com.gmail.filoghost.chestcommands.config.yaml;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple utility class to manage configurations with a file associated to them.
|
* A simple utility class to manage configurations with a file associated to them.
|
||||||
*/
|
*/
|
||||||
public class PluginConfig extends YamlConfiguration {
|
public class PluginConfig extends YamlConfiguration {
|
||||||
|
|
||||||
private File file;
|
private File file;
|
||||||
private Plugin plugin;
|
private Plugin plugin;
|
||||||
|
|
||||||
public PluginConfig(Plugin plugin, File file) {
|
public PluginConfig(Plugin plugin, File file) {
|
||||||
super();
|
super();
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginConfig(Plugin plugin, String name) {
|
public PluginConfig(Plugin plugin, String name) {
|
||||||
this(plugin, new File(plugin.getDataFolder(), name));
|
this(plugin, new File(plugin.getDataFolder(), name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load() throws IOException, InvalidConfigurationException {
|
public void load() throws IOException, InvalidConfigurationException {
|
||||||
|
|
||||||
if (!file.isFile()) {
|
if (!file.isFile()) {
|
||||||
if (plugin.getResource(file.getName()) != null) {
|
if (plugin.getResource(file.getName()) != null) {
|
||||||
plugin.saveResource(file.getName(), false);
|
plugin.saveResource(file.getName(), false);
|
||||||
} else {
|
} else {
|
||||||
if (file.getParentFile() != null) {
|
if (file.getParentFile() != null) {
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// To reset all the values when loading.
|
// To reset all the values when loading.
|
||||||
for (String section : this.getKeys(false)) {
|
for (String section : this.getKeys(false)) {
|
||||||
set(section, null);
|
set(section, null);
|
||||||
}
|
}
|
||||||
load(file);
|
load(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() throws IOException {
|
public void save() throws IOException {
|
||||||
this.save(file);
|
this.save(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin getPlugin() {
|
public Plugin getPlugin() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return file.getName();
|
return file.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,121 +1,121 @@
|
||||||
package com.gmail.filoghost.chestcommands.config.yaml;
|
package com.gmail.filoghost.chestcommands.config.yaml;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A special configuration wrapper that reads the values using reflection.
|
* A special configuration wrapper that reads the values using reflection.
|
||||||
* It will also save default values if not set.
|
* It will also save default values if not set.
|
||||||
*/
|
*/
|
||||||
public class SpecialConfig {
|
public class SpecialConfig {
|
||||||
|
|
||||||
private transient PluginConfig config;
|
private transient PluginConfig config;
|
||||||
private transient String header;
|
private transient String header;
|
||||||
private transient Map<String, Object> defaultValuesMap;
|
private transient Map<String, Object> defaultValuesMap;
|
||||||
|
|
||||||
public SpecialConfig(PluginConfig config) {
|
public SpecialConfig(PluginConfig config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHeader(String header) {
|
public void setHeader(String header) {
|
||||||
this.header = header;
|
this.header = header;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load() throws IOException, InvalidConfigurationException, Exception {
|
public void load() throws IOException, InvalidConfigurationException, Exception {
|
||||||
|
|
||||||
// Check if the configuration was initialized.
|
// Check if the configuration was initialized.
|
||||||
if (defaultValuesMap == null) {
|
if (defaultValuesMap == null) {
|
||||||
defaultValuesMap = new HashMap<String, Object>();
|
defaultValuesMap = new HashMap<String, Object>();
|
||||||
|
|
||||||
// Put the values in the default values map.
|
// Put the values in the default values map.
|
||||||
for (Field field : getClass().getDeclaredFields()) {
|
for (Field field : getClass().getDeclaredFields()) {
|
||||||
if (!isValidField(field)) continue;
|
if (!isValidField(field)) continue;
|
||||||
|
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
String configKey = formatFieldName(field);
|
String configKey = formatFieldName(field);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Object defaultValue = field.get(this);
|
Object defaultValue = field.get(this);
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
defaultValuesMap.put(configKey, defaultValue);
|
defaultValuesMap.put(configKey, defaultValue);
|
||||||
} else {
|
} else {
|
||||||
config.getPlugin().getLogger().warning("The field " + field.getName() + " was not provided with a default value, please inform the developer.");
|
config.getPlugin().getLogger().warning("The field " + field.getName() + " was not provided with a default value, please inform the developer.");
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// First of all, try to load the yaml file.
|
// First of all, try to load the yaml file.
|
||||||
config.load();
|
config.load();
|
||||||
|
|
||||||
// Save default values not set.
|
// Save default values not set.
|
||||||
boolean needsSave = false;
|
boolean needsSave = false;
|
||||||
for (Entry<String, Object> entry : defaultValuesMap.entrySet()) {
|
for (Entry<String, Object> entry : defaultValuesMap.entrySet()) {
|
||||||
if (!config.isSet(entry.getKey())) {
|
if (!config.isSet(entry.getKey())) {
|
||||||
needsSave = true;
|
needsSave = true;
|
||||||
config.set(entry.getKey(), entry.getValue());
|
config.set(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needsSave) {
|
if (needsSave) {
|
||||||
config.options().header(header);
|
config.options().header(header);
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now read change the fields.
|
// Now read change the fields.
|
||||||
for (Field field : getClass().getDeclaredFields()) {
|
for (Field field : getClass().getDeclaredFields()) {
|
||||||
|
|
||||||
if (!isValidField(field)) continue;
|
if (!isValidField(field)) continue;
|
||||||
|
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
String configKey = formatFieldName(field);
|
String configKey = formatFieldName(field);
|
||||||
|
|
||||||
|
|
||||||
if (config.isSet(configKey)) {
|
if (config.isSet(configKey)) {
|
||||||
|
|
||||||
Class<?> type = field.getType();
|
Class<?> type = field.getType();
|
||||||
|
|
||||||
if (type == boolean.class || type == Boolean.class) {
|
if (type == boolean.class || type == Boolean.class) {
|
||||||
field.set(this, config.getBoolean(configKey));
|
field.set(this, config.getBoolean(configKey));
|
||||||
|
|
||||||
} else if (type == int.class || type == Integer.class) {
|
} else if (type == int.class || type == Integer.class) {
|
||||||
field.set(this, config.getInt(configKey));
|
field.set(this, config.getInt(configKey));
|
||||||
|
|
||||||
} else if (type == double.class || type == Double.class) {
|
} else if (type == double.class || type == Double.class) {
|
||||||
field.set(this, config.getDouble(configKey));
|
field.set(this, config.getDouble(configKey));
|
||||||
|
|
||||||
} else if (type == String.class) {
|
} else if (type == String.class) {
|
||||||
field.set(this, Utils.addColors(config.getString(configKey))); // Always add colors.
|
field.set(this, Utils.addColors(config.getString(configKey))); // Always add colors.
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
config.getPlugin().getLogger().warning("Unknown field type: " + field.getType().getName() + " (" + field.getName() + "). Please inform the developer.");
|
config.getPlugin().getLogger().warning("Unknown field type: " + field.getType().getName() + " (" + field.getName() + "). Please inform the developer.");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
field.set(this, defaultValuesMap.get(configKey));
|
field.set(this, defaultValuesMap.get(configKey));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isValidField(Field field) {
|
private boolean isValidField(Field field) {
|
||||||
int modifiers = field.getModifiers();
|
int modifiers = field.getModifiers();
|
||||||
return !Modifier.isTransient(modifiers) && !Modifier.isStatic(modifiers) && !Modifier.isFinal(modifiers);
|
return !Modifier.isTransient(modifiers) && !Modifier.isStatic(modifiers) && !Modifier.isFinal(modifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatFieldName(Field field) {
|
private String formatFieldName(Field field) {
|
||||||
return field.getName().replace("__", ".").replace("_", "-");
|
return field.getName().replace("__", ".").replace("_", "-");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
package com.gmail.filoghost.chestcommands.exception;
|
package com.gmail.filoghost.chestcommands.exception;
|
||||||
|
|
||||||
public class FormatException extends Exception {
|
public class FormatException extends Exception {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public FormatException(String message) {
|
public FormatException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,53 +1,53 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal;
|
package com.gmail.filoghost.chestcommands.internal;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.util.ClickType;
|
import com.gmail.filoghost.chestcommands.util.ClickType;
|
||||||
import com.gmail.filoghost.chestcommands.util.Validate;
|
import com.gmail.filoghost.chestcommands.util.Validate;
|
||||||
|
|
||||||
public class BoundItem {
|
public class BoundItem {
|
||||||
|
|
||||||
private ExtendedIconMenu menu;
|
private ExtendedIconMenu menu;
|
||||||
private Material material;
|
private Material material;
|
||||||
private short data;
|
private short data;
|
||||||
private ClickType clickType;
|
private ClickType clickType;
|
||||||
|
|
||||||
public BoundItem(ExtendedIconMenu menu, Material material, ClickType clickType) {
|
public BoundItem(ExtendedIconMenu menu, Material material, ClickType clickType) {
|
||||||
Validate.notNull(material, "Material cannot be null");
|
Validate.notNull(material, "Material cannot be null");
|
||||||
Validate.notNull(material, "ClickType cannot be null");
|
Validate.notNull(material, "ClickType cannot be null");
|
||||||
Validate.isTrue(material != Material.AIR, "Material cannot be AIR");
|
Validate.isTrue(material != Material.AIR, "Material cannot be AIR");
|
||||||
|
|
||||||
this.menu = menu;
|
this.menu = menu;
|
||||||
this.material = material;
|
this.material = material;
|
||||||
this.clickType = clickType;
|
this.clickType = clickType;
|
||||||
data = -1; // -1 = any.
|
data = -1; // -1 = any.
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRestrictiveData(short data) {
|
public void setRestrictiveData(short data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtendedIconMenu getMenu() {
|
public ExtendedIconMenu getMenu() {
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidTrigger(ItemStack item, Action action) {
|
public boolean isValidTrigger(ItemStack item, Action action) {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, they must have the same material.
|
// First, they must have the same material.
|
||||||
if (this.material != item.getType()) {
|
if (this.material != item.getType()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check if the data value is valid (-1 = any data value).
|
// Check if the data value is valid (-1 = any data value).
|
||||||
if (this.data != -1 && this.data != item.getDurability()) {
|
if (this.data != -1 && this.data != item.getDurability()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally checks the action.
|
// Finally checks the action.
|
||||||
return clickType.isValidInteract(action);
|
return clickType.isValidInteract(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,22 +1,22 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal;
|
package com.gmail.filoghost.chestcommands.internal;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.util.VersionUtils;
|
import com.gmail.filoghost.chestcommands.util.VersionUtils;
|
||||||
|
|
||||||
public class CachedGetters {
|
public class CachedGetters {
|
||||||
|
|
||||||
private static long lastOnlinePlayersRefresh;
|
private static long lastOnlinePlayersRefresh;
|
||||||
private static int onlinePlayers;
|
private static int onlinePlayers;
|
||||||
|
|
||||||
|
|
||||||
public static int getOnlinePlayers() {
|
public static int getOnlinePlayers() {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if (lastOnlinePlayersRefresh == 0 || now - lastOnlinePlayersRefresh > 1000) {
|
if (lastOnlinePlayersRefresh == 0 || now - lastOnlinePlayersRefresh > 1000) {
|
||||||
// getOnlinePlayers() could be expensive if called frequently
|
// getOnlinePlayers() could be expensive if called frequently
|
||||||
lastOnlinePlayersRefresh = now;
|
lastOnlinePlayersRefresh = now;
|
||||||
onlinePlayers = VersionUtils.getOnlinePlayers().size();
|
onlinePlayers = VersionUtils.getOnlinePlayers().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
return onlinePlayers;
|
return onlinePlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,43 +1,43 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal;
|
package com.gmail.filoghost.chestcommands.internal;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.api.ClickHandler;
|
import com.gmail.filoghost.chestcommands.api.ClickHandler;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.command.OpenIconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.command.OpenIconCommand;
|
||||||
|
|
||||||
public class CommandsClickHandler implements ClickHandler {
|
public class CommandsClickHandler implements ClickHandler {
|
||||||
|
|
||||||
private List<IconCommand> commands;
|
private List<IconCommand> commands;
|
||||||
private boolean closeOnClick;
|
private boolean closeOnClick;
|
||||||
|
|
||||||
public CommandsClickHandler(List<IconCommand> commands, boolean closeOnClick) {
|
public CommandsClickHandler(List<IconCommand> commands, boolean closeOnClick) {
|
||||||
this.commands = commands;
|
this.commands = commands;
|
||||||
this.closeOnClick = closeOnClick;
|
this.closeOnClick = closeOnClick;
|
||||||
|
|
||||||
if (commands != null && commands.size() > 0) {
|
if (commands != null && commands.size() > 0) {
|
||||||
for (IconCommand command : commands) {
|
for (IconCommand command : commands) {
|
||||||
if (command instanceof OpenIconCommand) {
|
if (command instanceof OpenIconCommand) {
|
||||||
// Fix GUI closing if KEEP-OPEN is not set, and a command should open another GUI.
|
// Fix GUI closing if KEEP-OPEN is not set, and a command should open another GUI.
|
||||||
this.closeOnClick = false;
|
this.closeOnClick = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onClick(Player player) {
|
public boolean onClick(Player player) {
|
||||||
if (commands != null && commands.size() > 0) {
|
if (commands != null && commands.size() > 0) {
|
||||||
for (IconCommand command : commands) {
|
for (IconCommand command : commands) {
|
||||||
command.execute(player);
|
command.execute(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return closeOnClick;
|
return closeOnClick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,129 +1,129 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal;
|
package com.gmail.filoghost.chestcommands.internal;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
import com.gmail.filoghost.chestcommands.Permissions;
|
import com.gmail.filoghost.chestcommands.Permissions;
|
||||||
import com.gmail.filoghost.chestcommands.api.IconMenu;
|
import com.gmail.filoghost.chestcommands.api.IconMenu;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.ExtendedIcon;
|
import com.gmail.filoghost.chestcommands.internal.icon.ExtendedIcon;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.nms.AttributeRemover;
|
import com.gmail.filoghost.chestcommands.nms.AttributeRemover;
|
||||||
|
|
||||||
public class ExtendedIconMenu extends IconMenu {
|
public class ExtendedIconMenu extends IconMenu {
|
||||||
|
|
||||||
private String fileName;
|
private String fileName;
|
||||||
private String permission;
|
private String permission;
|
||||||
private List<IconCommand> openActions;
|
private List<IconCommand> openActions;
|
||||||
|
|
||||||
private int refreshTicks;
|
private int refreshTicks;
|
||||||
|
|
||||||
public ExtendedIconMenu(String title, int rows, String fileName) {
|
public ExtendedIconMenu(String title, int rows, String fileName) {
|
||||||
super(title, rows);
|
super(title, rows);
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
this.permission = Permissions.OPEN_MENU_BASE + fileName;
|
this.permission = Permissions.OPEN_MENU_BASE + fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IconCommand> getOpenActions() {
|
public List<IconCommand> getOpenActions() {
|
||||||
return openActions;
|
return openActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOpenActions(List<IconCommand> openAction) {
|
public void setOpenActions(List<IconCommand> openAction) {
|
||||||
this.openActions = openAction;
|
this.openActions = openAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPermission() {
|
public String getPermission() {
|
||||||
return permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRefreshTicks() {
|
public int getRefreshTicks() {
|
||||||
return refreshTicks;
|
return refreshTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRefreshTicks(int refreshTicks) {
|
public void setRefreshTicks(int refreshTicks) {
|
||||||
this.refreshTicks = refreshTicks;
|
this.refreshTicks = refreshTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void open(Player player) {
|
public void open(Player player) {
|
||||||
try {
|
try {
|
||||||
if (openActions != null) {
|
if (openActions != null) {
|
||||||
for (IconCommand openAction : openActions) {
|
for (IconCommand openAction : openActions) {
|
||||||
openAction.execute(player);
|
openAction.execute(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Inventory inventory = Bukkit.createInventory(new MenuInventoryHolder(this), icons.length, title);
|
Inventory inventory = Bukkit.createInventory(new MenuInventoryHolder(this), icons.length, title);
|
||||||
|
|
||||||
for (int i = 0; i < icons.length; i++) {
|
for (int i = 0; i < icons.length; i++) {
|
||||||
if (icons[i] != null) {
|
if (icons[i] != null) {
|
||||||
|
|
||||||
if (icons[i] instanceof ExtendedIcon && !((ExtendedIcon) icons[i]).canViewIcon(player)) {
|
if (icons[i] instanceof ExtendedIcon && !((ExtendedIcon) icons[i]).canViewIcon(player)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
inventory.setItem(i, AttributeRemover.hideAttributes(icons[i].createItemstack(player)));
|
inventory.setItem(i, AttributeRemover.hideAttributes(icons[i].createItemstack(player)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
player.openInventory(inventory);
|
player.openInventory(inventory);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
player.sendMessage(ChatColor.RED + "An internal error occurred while opening the menu. The staff should check the console for errors.");
|
player.sendMessage(ChatColor.RED + "An internal error occurred while opening the menu. The staff should check the console for errors.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh(Player player, Inventory inventory) {
|
public void refresh(Player player, Inventory inventory) {
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < icons.length; i++) {
|
for (int i = 0; i < icons.length; i++) {
|
||||||
if (icons[i] != null && icons[i] instanceof ExtendedIcon) {
|
if (icons[i] != null && icons[i] instanceof ExtendedIcon) {
|
||||||
ExtendedIcon extIcon = (ExtendedIcon) icons[i];
|
ExtendedIcon extIcon = (ExtendedIcon) icons[i];
|
||||||
|
|
||||||
if (extIcon.hasViewPermission() || extIcon.hasVariables()) {
|
if (extIcon.hasViewPermission() || extIcon.hasVariables()) {
|
||||||
// Then we have to refresh it
|
// Then we have to refresh it
|
||||||
if (extIcon.canViewIcon(player)) {
|
if (extIcon.canViewIcon(player)) {
|
||||||
|
|
||||||
if (inventory.getItem(i) == null) {
|
if (inventory.getItem(i) == null) {
|
||||||
ItemStack newItem = AttributeRemover.hideAttributes(extIcon.createItemstack(player));
|
ItemStack newItem = AttributeRemover.hideAttributes(extIcon.createItemstack(player));
|
||||||
inventory.setItem(i, newItem);
|
inventory.setItem(i, newItem);
|
||||||
} else {
|
} else {
|
||||||
// Performance, only update name and lore.
|
// Performance, only update name and lore.
|
||||||
ItemStack oldItem = AttributeRemover.hideAttributes(inventory.getItem(i));
|
ItemStack oldItem = AttributeRemover.hideAttributes(inventory.getItem(i));
|
||||||
ItemMeta meta = oldItem.getItemMeta();
|
ItemMeta meta = oldItem.getItemMeta();
|
||||||
meta.setDisplayName(extIcon.calculateName(player));
|
meta.setDisplayName(extIcon.calculateName(player));
|
||||||
meta.setLore(extIcon.calculateLore(player));
|
meta.setLore(extIcon.calculateLore(player));
|
||||||
oldItem.setItemMeta(meta);
|
oldItem.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
inventory.setItem(i, null);
|
inventory.setItem(i, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
player.sendMessage(ChatColor.RED + "An internal error occurred while refreshing the menu. The staff should check the console for errors.");
|
player.sendMessage(ChatColor.RED + "An internal error occurred while refreshing the menu. The staff should check the console for errors.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void sendNoPermissionMessage(CommandSender sender) {
|
public void sendNoPermissionMessage(CommandSender sender) {
|
||||||
String noPermMessage = ChestCommands.getLang().no_open_permission;
|
String noPermMessage = ChestCommands.getLang().no_open_permission;
|
||||||
if (noPermMessage != null && !noPermMessage.isEmpty()) {
|
if (noPermMessage != null && !noPermMessage.isEmpty()) {
|
||||||
sender.sendMessage(noPermMessage.replace("{permission}", this.permission));
|
sender.sendMessage(noPermMessage.replace("{permission}", this.permission));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,97 +1,97 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal;
|
package com.gmail.filoghost.chestcommands.internal;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.util.ClickType;
|
import com.gmail.filoghost.chestcommands.util.ClickType;
|
||||||
|
|
||||||
public class MenuData {
|
public class MenuData {
|
||||||
|
|
||||||
// Required data.
|
// Required data.
|
||||||
private String title;
|
private String title;
|
||||||
private int rows;
|
private int rows;
|
||||||
|
|
||||||
// Optional data.
|
// Optional data.
|
||||||
private String[] commands;
|
private String[] commands;
|
||||||
private Material boundMaterial;
|
private Material boundMaterial;
|
||||||
private short boundDataValue;
|
private short boundDataValue;
|
||||||
private ClickType clickType;
|
private ClickType clickType;
|
||||||
private List<IconCommand> openActions;
|
private List<IconCommand> openActions;
|
||||||
private int refreshTenths;
|
private int refreshTenths;
|
||||||
|
|
||||||
public MenuData(String title, int rows) {
|
public MenuData(String title, int rows) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.rows = rows;
|
this.rows = rows;
|
||||||
boundDataValue = -1; // -1 = any.
|
boundDataValue = -1; // -1 = any.
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRows() {
|
public int getRows() {
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCommands() {
|
public boolean hasCommands() {
|
||||||
return commands != null && commands.length > 0;
|
return commands != null && commands.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCommands(String[] commands) {
|
public void setCommands(String[] commands) {
|
||||||
this.commands = commands;
|
this.commands = commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getCommands() {
|
public String[] getCommands() {
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBoundMaterial() {
|
public boolean hasBoundMaterial() {
|
||||||
return boundMaterial != null;
|
return boundMaterial != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getBoundMaterial() {
|
public Material getBoundMaterial() {
|
||||||
return boundMaterial;
|
return boundMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoundMaterial(Material boundMaterial) {
|
public void setBoundMaterial(Material boundMaterial) {
|
||||||
this.boundMaterial = boundMaterial;
|
this.boundMaterial = boundMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBoundDataValue() {
|
public boolean hasBoundDataValue() {
|
||||||
return boundDataValue > -1;
|
return boundDataValue > -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getBoundDataValue() {
|
public short getBoundDataValue() {
|
||||||
return boundDataValue;
|
return boundDataValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoundDataValue(short boundDataValue) {
|
public void setBoundDataValue(short boundDataValue) {
|
||||||
this.boundDataValue = boundDataValue;
|
this.boundDataValue = boundDataValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClickType getClickType() {
|
public ClickType getClickType() {
|
||||||
return clickType;
|
return clickType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClickType(ClickType clickType) {
|
public void setClickType(ClickType clickType) {
|
||||||
this.clickType = clickType;
|
this.clickType = clickType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IconCommand> getOpenActions() {
|
public List<IconCommand> getOpenActions() {
|
||||||
return openActions;
|
return openActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOpenActions(List<IconCommand> openAction) {
|
public void setOpenActions(List<IconCommand> openAction) {
|
||||||
this.openActions = openAction;
|
this.openActions = openAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRefreshTenths() {
|
public int getRefreshTenths() {
|
||||||
return refreshTenths;
|
return refreshTenths;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRefreshTenths(int refreshTenths) {
|
public void setRefreshTenths(int refreshTenths) {
|
||||||
this.refreshTenths = refreshTenths;
|
this.refreshTenths = refreshTenths;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,39 +1,39 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal;
|
package com.gmail.filoghost.chestcommands.internal;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.api.IconMenu;
|
import com.gmail.filoghost.chestcommands.api.IconMenu;
|
||||||
import com.gmail.filoghost.chestcommands.util.Validate;
|
import com.gmail.filoghost.chestcommands.util.Validate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class links an IconMenu with an Inventory, via InventoryHolder.
|
* This class links an IconMenu with an Inventory, via InventoryHolder.
|
||||||
*/
|
*/
|
||||||
public class MenuInventoryHolder implements InventoryHolder {
|
public class MenuInventoryHolder implements InventoryHolder {
|
||||||
|
|
||||||
private IconMenu iconMenu;
|
private IconMenu iconMenu;
|
||||||
|
|
||||||
public MenuInventoryHolder(IconMenu iconMenu) {
|
public MenuInventoryHolder(IconMenu iconMenu) {
|
||||||
this.iconMenu = iconMenu;
|
this.iconMenu = iconMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Inventory getInventory() {
|
public Inventory getInventory() {
|
||||||
// This inventory will not do anything.
|
// This inventory will not do anything.
|
||||||
// I'm 90% sure that it doesn't break any other plugin,
|
// I'm 90% sure that it doesn't break any other plugin,
|
||||||
// because the only way you can get here is using InventoryClickEvent,
|
// because the only way you can get here is using InventoryClickEvent,
|
||||||
// that is cancelled by ChestCommands, or using InventoryOpenEvent.
|
// that is cancelled by ChestCommands, or using InventoryOpenEvent.
|
||||||
return Bukkit.createInventory(null, iconMenu.getSize());
|
return Bukkit.createInventory(null, iconMenu.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public IconMenu getIconMenu() {
|
public IconMenu getIconMenu() {
|
||||||
return iconMenu;
|
return iconMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIconMenu(IconMenu iconMenu) {
|
public void setIconMenu(IconMenu iconMenu) {
|
||||||
Validate.notNull(iconMenu, "IconMenu cannot be null");
|
Validate.notNull(iconMenu, "IconMenu cannot be null");
|
||||||
this.iconMenu = iconMenu;
|
this.iconMenu = iconMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,99 +1,99 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal;
|
package com.gmail.filoghost.chestcommands.internal;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.util.Validate;
|
import com.gmail.filoghost.chestcommands.util.Validate;
|
||||||
|
|
||||||
public class RequiredItem {
|
public class RequiredItem {
|
||||||
|
|
||||||
private Material material;
|
private Material material;
|
||||||
private int amount;
|
private int amount;
|
||||||
private short dataValue;
|
private short dataValue;
|
||||||
private boolean isDurabilityRestrictive = false;
|
private boolean isDurabilityRestrictive = false;
|
||||||
|
|
||||||
public RequiredItem(Material material, int amount) {
|
public RequiredItem(Material material, int amount) {
|
||||||
Validate.notNull(material, "Material cannot be null");
|
Validate.notNull(material, "Material cannot be null");
|
||||||
Validate.isTrue(material != Material.AIR, "Material cannot be air");
|
Validate.isTrue(material != Material.AIR, "Material cannot be air");
|
||||||
|
|
||||||
this.material = material;
|
this.material = material;
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack createItemStack() {
|
public ItemStack createItemStack() {
|
||||||
return new ItemStack(material, amount, dataValue);
|
return new ItemStack(material, amount, dataValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getMaterial() {
|
public Material getMaterial() {
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAmount() {
|
public int getAmount() {
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getDataValue() {
|
public short getDataValue() {
|
||||||
return dataValue;
|
return dataValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRestrictiveDataValue(short data) {
|
public void setRestrictiveDataValue(short data) {
|
||||||
Validate.isTrue(data >= 0, "Data value cannot be negative");
|
Validate.isTrue(data >= 0, "Data value cannot be negative");
|
||||||
|
|
||||||
this.dataValue = data;
|
this.dataValue = data;
|
||||||
isDurabilityRestrictive = true;
|
isDurabilityRestrictive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasRestrictiveDataValue() {
|
public boolean hasRestrictiveDataValue() {
|
||||||
return isDurabilityRestrictive;
|
return isDurabilityRestrictive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidDataValue(short data) {
|
public boolean isValidDataValue(short data) {
|
||||||
if (!isDurabilityRestrictive) return true;
|
if (!isDurabilityRestrictive) return true;
|
||||||
return data == this.dataValue;
|
return data == this.dataValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasItem(Player player) {
|
public boolean hasItem(Player player) {
|
||||||
int amountFound = 0;
|
int amountFound = 0;
|
||||||
|
|
||||||
for (ItemStack item : player.getInventory().getContents()) {
|
for (ItemStack item : player.getInventory().getContents()) {
|
||||||
if (item != null && item.getType() == material && isValidDataValue(item.getDurability())) {
|
if (item != null && item.getType() == material && isValidDataValue(item.getDurability())) {
|
||||||
amountFound += item.getAmount();
|
amountFound += item.getAmount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return amountFound >= amount;
|
return amountFound >= amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean takeItem(Player player) {
|
public boolean takeItem(Player player) {
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int itemsToTake = amount; //start from amount and decrease
|
int itemsToTake = amount; //start from amount and decrease
|
||||||
|
|
||||||
ItemStack[] contents = player.getInventory().getContents();
|
ItemStack[] contents = player.getInventory().getContents();
|
||||||
ItemStack current = null;
|
ItemStack current = null;
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < contents.length; i++) {
|
for (int i = 0; i < contents.length; i++) {
|
||||||
|
|
||||||
current = contents[i];
|
current = contents[i];
|
||||||
|
|
||||||
if (current != null && current.getType() == material && isValidDataValue(current.getDurability())) {
|
if (current != null && current.getType() == material && isValidDataValue(current.getDurability())) {
|
||||||
if (current.getAmount() > itemsToTake) {
|
if (current.getAmount() > itemsToTake) {
|
||||||
current.setAmount(current.getAmount() - itemsToTake);
|
current.setAmount(current.getAmount() - itemsToTake);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
itemsToTake -= current.getAmount();
|
itemsToTake -= current.getAmount();
|
||||||
player.getInventory().setItem(i, new ItemStack(Material.AIR));
|
player.getInventory().setItem(i, new ItemStack(Material.AIR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The end
|
// The end
|
||||||
if (itemsToTake <= 0) return true;
|
if (itemsToTake <= 0) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,66 +1,66 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal;
|
package com.gmail.filoghost.chestcommands.internal;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.bridge.EconomyBridge;
|
import com.gmail.filoghost.chestcommands.bridge.EconomyBridge;
|
||||||
import com.gmail.filoghost.chestcommands.bridge.PlayerPointsBridge;
|
import com.gmail.filoghost.chestcommands.bridge.PlayerPointsBridge;
|
||||||
|
|
||||||
public enum Variable {
|
public enum Variable {
|
||||||
|
|
||||||
PLAYER("{player}") {
|
PLAYER("{player}") {
|
||||||
public String getReplacement(Player executor) {
|
public String getReplacement(Player executor) {
|
||||||
return executor.getName();
|
return executor.getName();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
ONLINE("{online}") {
|
ONLINE("{online}") {
|
||||||
public String getReplacement(Player executor) {
|
public String getReplacement(Player executor) {
|
||||||
return String.valueOf(CachedGetters.getOnlinePlayers());
|
return String.valueOf(CachedGetters.getOnlinePlayers());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
MAX_PLAYERS("{max_players}") {
|
MAX_PLAYERS("{max_players}") {
|
||||||
public String getReplacement(Player executor) {
|
public String getReplacement(Player executor) {
|
||||||
return String.valueOf(Bukkit.getMaxPlayers());
|
return String.valueOf(Bukkit.getMaxPlayers());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
MONEY("{money}") {
|
MONEY("{money}") {
|
||||||
public String getReplacement(Player executor) {
|
public String getReplacement(Player executor) {
|
||||||
if (EconomyBridge.hasValidEconomy()) {
|
if (EconomyBridge.hasValidEconomy()) {
|
||||||
return EconomyBridge.formatMoney(EconomyBridge.getMoney(executor));
|
return EconomyBridge.formatMoney(EconomyBridge.getMoney(executor));
|
||||||
} else {
|
} else {
|
||||||
return "[ECONOMY PLUGIN NOT FOUND]";
|
return "[ECONOMY PLUGIN NOT FOUND]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
POINTS("{points}") {
|
POINTS("{points}") {
|
||||||
public String getReplacement(Player executor) {
|
public String getReplacement(Player executor) {
|
||||||
if (PlayerPointsBridge.hasValidPlugin()) {
|
if (PlayerPointsBridge.hasValidPlugin()) {
|
||||||
return String.valueOf(PlayerPointsBridge.getPoints(executor));
|
return String.valueOf(PlayerPointsBridge.getPoints(executor));
|
||||||
} else {
|
} else {
|
||||||
return "[PLAYER POINTS PLUGIN NOT FOUND]";
|
return "[PLAYER POINTS PLUGIN NOT FOUND]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
WORLD("{world}") {
|
WORLD("{world}") {
|
||||||
public String getReplacement(Player executor) {
|
public String getReplacement(Player executor) {
|
||||||
return executor.getWorld().getName();
|
return executor.getWorld().getName();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
private Variable(String text) {
|
private Variable(String text) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getText() {
|
public String getText() {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getReplacement(Player executor);
|
public abstract String getReplacement(Player executor);
|
||||||
}
|
}
|
|
@ -1,247 +1,247 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon;
|
package com.gmail.filoghost.chestcommands.internal.icon;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryView;
|
import org.bukkit.inventory.InventoryView;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
import com.gmail.filoghost.chestcommands.api.Icon;
|
import com.gmail.filoghost.chestcommands.api.Icon;
|
||||||
import com.gmail.filoghost.chestcommands.bridge.EconomyBridge;
|
import com.gmail.filoghost.chestcommands.bridge.EconomyBridge;
|
||||||
import com.gmail.filoghost.chestcommands.bridge.PlayerPointsBridge;
|
import com.gmail.filoghost.chestcommands.bridge.PlayerPointsBridge;
|
||||||
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
||||||
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
|
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
|
||||||
import com.gmail.filoghost.chestcommands.internal.RequiredItem;
|
import com.gmail.filoghost.chestcommands.internal.RequiredItem;
|
||||||
import com.gmail.filoghost.chestcommands.util.StringUtils;
|
import com.gmail.filoghost.chestcommands.util.StringUtils;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class ExtendedIcon extends Icon {
|
public class ExtendedIcon extends Icon {
|
||||||
|
|
||||||
private String permission;
|
private String permission;
|
||||||
private String permissionMessage;
|
private String permissionMessage;
|
||||||
private String viewPermission;
|
private String viewPermission;
|
||||||
|
|
||||||
private boolean permissionNegated;
|
private boolean permissionNegated;
|
||||||
private boolean viewPermissionNegated;
|
private boolean viewPermissionNegated;
|
||||||
|
|
||||||
private double moneyPrice;
|
private double moneyPrice;
|
||||||
private int playerPointsPrice;
|
private int playerPointsPrice;
|
||||||
private int expLevelsPrice;
|
private int expLevelsPrice;
|
||||||
private RequiredItem requiredItem;
|
private RequiredItem requiredItem;
|
||||||
|
|
||||||
public ExtendedIcon() {
|
public ExtendedIcon() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canClickIcon(Player player) {
|
public boolean canClickIcon(Player player) {
|
||||||
if (permission == null) {
|
if (permission == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (permissionNegated) {
|
if (permissionNegated) {
|
||||||
return !player.hasPermission(permission);
|
return !player.hasPermission(permission);
|
||||||
} else {
|
} else {
|
||||||
return player.hasPermission(permission);
|
return player.hasPermission(permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPermission(String permission) {
|
public void setPermission(String permission) {
|
||||||
if (StringUtils.isNullOrEmpty(permission)) {
|
if (StringUtils.isNullOrEmpty(permission)) {
|
||||||
permission = null;
|
permission = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (permission != null) {
|
if (permission != null) {
|
||||||
if (permission.startsWith("-")) {
|
if (permission.startsWith("-")) {
|
||||||
permissionNegated = true;
|
permissionNegated = true;
|
||||||
permission = permission.substring(1, permission.length()).trim();
|
permission = permission.substring(1, permission.length()).trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPermissionMessage() {
|
public String getPermissionMessage() {
|
||||||
return permissionMessage;
|
return permissionMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPermissionMessage(String permissionMessage) {
|
public void setPermissionMessage(String permissionMessage) {
|
||||||
this.permissionMessage = permissionMessage;
|
this.permissionMessage = permissionMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasViewPermission() {
|
public boolean hasViewPermission() {
|
||||||
return viewPermission != null;
|
return viewPermission != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canViewIcon(Player player) {
|
public boolean canViewIcon(Player player) {
|
||||||
if (viewPermission == null) {
|
if (viewPermission == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewPermissionNegated) {
|
if (viewPermissionNegated) {
|
||||||
return !player.hasPermission(viewPermission);
|
return !player.hasPermission(viewPermission);
|
||||||
} else {
|
} else {
|
||||||
return player.hasPermission(viewPermission);
|
return player.hasPermission(viewPermission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setViewPermission(String viewPermission) {
|
public void setViewPermission(String viewPermission) {
|
||||||
if (StringUtils.isNullOrEmpty(viewPermission)) {
|
if (StringUtils.isNullOrEmpty(viewPermission)) {
|
||||||
viewPermission = null;
|
viewPermission = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewPermission != null) {
|
if (viewPermission != null) {
|
||||||
if (viewPermission.startsWith("-")) {
|
if (viewPermission.startsWith("-")) {
|
||||||
viewPermissionNegated = true;
|
viewPermissionNegated = true;
|
||||||
viewPermission = viewPermission.substring(1, viewPermission.length()).trim();
|
viewPermission = viewPermission.substring(1, viewPermission.length()).trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.viewPermission = viewPermission;
|
this.viewPermission = viewPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMoneyPrice() {
|
public double getMoneyPrice() {
|
||||||
return moneyPrice;
|
return moneyPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMoneyPrice(double moneyPrice) {
|
public void setMoneyPrice(double moneyPrice) {
|
||||||
this.moneyPrice = moneyPrice;
|
this.moneyPrice = moneyPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPlayerPointsPrice() {
|
public int getPlayerPointsPrice() {
|
||||||
return playerPointsPrice;
|
return playerPointsPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayerPointsPrice(int playerPointsPrice) {
|
public void setPlayerPointsPrice(int playerPointsPrice) {
|
||||||
this.playerPointsPrice = playerPointsPrice;
|
this.playerPointsPrice = playerPointsPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getExpLevelsPrice() {
|
public int getExpLevelsPrice() {
|
||||||
return expLevelsPrice;
|
return expLevelsPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExpLevelsPrice(int expLevelsPrice) {
|
public void setExpLevelsPrice(int expLevelsPrice) {
|
||||||
this.expLevelsPrice = expLevelsPrice;
|
this.expLevelsPrice = expLevelsPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequiredItem getRequiredItem() {
|
public RequiredItem getRequiredItem() {
|
||||||
return requiredItem;
|
return requiredItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRequiredItem(RequiredItem requiredItem) {
|
public void setRequiredItem(RequiredItem requiredItem) {
|
||||||
this.requiredItem = requiredItem;
|
this.requiredItem = requiredItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String calculateName(Player pov) {
|
public String calculateName(Player pov) {
|
||||||
return super.calculateName(pov);
|
return super.calculateName(pov);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> calculateLore(Player pov) {
|
public List<String> calculateLore(Player pov) {
|
||||||
return super.calculateLore(pov);
|
return super.calculateLore(pov);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public boolean onClick(Player player) {
|
public boolean onClick(Player player) {
|
||||||
|
|
||||||
// Check all the requirements.
|
// Check all the requirements.
|
||||||
|
|
||||||
if (!canClickIcon(player)) {
|
if (!canClickIcon(player)) {
|
||||||
if (permissionMessage != null) {
|
if (permissionMessage != null) {
|
||||||
player.sendMessage(permissionMessage);
|
player.sendMessage(permissionMessage);
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChestCommands.getLang().default_no_icon_permission);
|
player.sendMessage(ChestCommands.getLang().default_no_icon_permission);
|
||||||
}
|
}
|
||||||
return closeOnClick;
|
return closeOnClick;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (moneyPrice > 0) {
|
if (moneyPrice > 0) {
|
||||||
if (!EconomyBridge.hasValidEconomy()) {
|
if (!EconomyBridge.hasValidEconomy()) {
|
||||||
player.sendMessage(ChatColor.RED + "This command has a price, but Vault with a compatible economy plugin was not found. For security, the command has been blocked. Please inform the staff.");
|
player.sendMessage(ChatColor.RED + "This command has a price, but Vault with a compatible economy plugin was not found. For security, the command has been blocked. Please inform the staff.");
|
||||||
return closeOnClick;
|
return closeOnClick;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EconomyBridge.hasMoney(player, moneyPrice)) {
|
if (!EconomyBridge.hasMoney(player, moneyPrice)) {
|
||||||
player.sendMessage(ChestCommands.getLang().no_money.replace("{money}", EconomyBridge.formatMoney(moneyPrice)));
|
player.sendMessage(ChestCommands.getLang().no_money.replace("{money}", EconomyBridge.formatMoney(moneyPrice)));
|
||||||
return closeOnClick;
|
return closeOnClick;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerPointsPrice > 0) {
|
if (playerPointsPrice > 0) {
|
||||||
if (!PlayerPointsBridge.hasValidPlugin()) {
|
if (!PlayerPointsBridge.hasValidPlugin()) {
|
||||||
player.sendMessage(ChatColor.RED + "This command has a price in points, but the plugin PlayerPoints was not found. For security, the command has been blocked. Please inform the staff.");
|
player.sendMessage(ChatColor.RED + "This command has a price in points, but the plugin PlayerPoints was not found. For security, the command has been blocked. Please inform the staff.");
|
||||||
return closeOnClick;
|
return closeOnClick;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PlayerPointsBridge.hasPoints(player, playerPointsPrice)) {
|
if (!PlayerPointsBridge.hasPoints(player, playerPointsPrice)) {
|
||||||
player.sendMessage(ChestCommands.getLang().no_points.replace("{points}", Integer.toString(playerPointsPrice)));
|
player.sendMessage(ChestCommands.getLang().no_points.replace("{points}", Integer.toString(playerPointsPrice)));
|
||||||
return closeOnClick;
|
return closeOnClick;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expLevelsPrice > 0) {
|
if (expLevelsPrice > 0) {
|
||||||
if (player.getLevel() < expLevelsPrice) {
|
if (player.getLevel() < expLevelsPrice) {
|
||||||
player.sendMessage(ChestCommands.getLang().no_exp.replace("{levels}", Integer.toString(expLevelsPrice)));
|
player.sendMessage(ChestCommands.getLang().no_exp.replace("{levels}", Integer.toString(expLevelsPrice)));
|
||||||
return closeOnClick;
|
return closeOnClick;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requiredItem != null) {
|
if (requiredItem != null) {
|
||||||
|
|
||||||
if (!requiredItem.hasItem(player)) {
|
if (!requiredItem.hasItem(player)) {
|
||||||
player.sendMessage(ChestCommands.getLang().no_required_item
|
player.sendMessage(ChestCommands.getLang().no_required_item
|
||||||
.replace("{material}", Utils.formatMaterial(requiredItem.getMaterial()))
|
.replace("{material}", Utils.formatMaterial(requiredItem.getMaterial()))
|
||||||
.replace("{id}", Integer.toString(requiredItem.getMaterial().getId()))
|
.replace("{id}", Integer.toString(requiredItem.getMaterial().getId()))
|
||||||
.replace("{amount}", Integer.toString(requiredItem.getAmount()))
|
.replace("{amount}", Integer.toString(requiredItem.getAmount()))
|
||||||
.replace("{datavalue}", requiredItem.hasRestrictiveDataValue() ? Short.toString(requiredItem.getDataValue()) : ChestCommands.getLang().any)
|
.replace("{datavalue}", requiredItem.hasRestrictiveDataValue() ? Short.toString(requiredItem.getDataValue()) : ChestCommands.getLang().any)
|
||||||
);
|
);
|
||||||
return closeOnClick;
|
return closeOnClick;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take the money, the points and the required item.
|
// Take the money, the points and the required item.
|
||||||
|
|
||||||
boolean changedVariables = false; // To update the placeholders.
|
boolean changedVariables = false; // To update the placeholders.
|
||||||
|
|
||||||
if (moneyPrice > 0) {
|
if (moneyPrice > 0) {
|
||||||
if (!EconomyBridge.takeMoney(player, moneyPrice)) {
|
if (!EconomyBridge.takeMoney(player, moneyPrice)) {
|
||||||
player.sendMessage(ChatColor.RED + "Error: the transaction couldn't be executed. Please inform the staff.");
|
player.sendMessage(ChatColor.RED + "Error: the transaction couldn't be executed. Please inform the staff.");
|
||||||
return closeOnClick;
|
return closeOnClick;
|
||||||
}
|
}
|
||||||
changedVariables = true;
|
changedVariables = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerPointsPrice > 0) {
|
if (playerPointsPrice > 0) {
|
||||||
if (!PlayerPointsBridge.takePoints(player, playerPointsPrice)) {
|
if (!PlayerPointsBridge.takePoints(player, playerPointsPrice)) {
|
||||||
player.sendMessage(ChatColor.RED + "Error: the transaction couldn't be executed. Please inform the staff.");
|
player.sendMessage(ChatColor.RED + "Error: the transaction couldn't be executed. Please inform the staff.");
|
||||||
return closeOnClick;
|
return closeOnClick;
|
||||||
}
|
}
|
||||||
changedVariables = true;
|
changedVariables = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expLevelsPrice > 0) {
|
if (expLevelsPrice > 0) {
|
||||||
player.setLevel(player.getLevel() - expLevelsPrice);
|
player.setLevel(player.getLevel() - expLevelsPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requiredItem != null) {
|
if (requiredItem != null) {
|
||||||
requiredItem.takeItem(player);
|
requiredItem.takeItem(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changedVariables) {
|
if (changedVariables) {
|
||||||
InventoryView view = player.getOpenInventory();
|
InventoryView view = player.getOpenInventory();
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
Inventory topInventory = view.getTopInventory();
|
Inventory topInventory = view.getTopInventory();
|
||||||
if (topInventory.getHolder() instanceof MenuInventoryHolder) {
|
if (topInventory.getHolder() instanceof MenuInventoryHolder) {
|
||||||
MenuInventoryHolder menuHolder = (MenuInventoryHolder) topInventory.getHolder();
|
MenuInventoryHolder menuHolder = (MenuInventoryHolder) topInventory.getHolder();
|
||||||
|
|
||||||
if (menuHolder.getIconMenu() instanceof ExtendedIconMenu) {
|
if (menuHolder.getIconMenu() instanceof ExtendedIconMenu) {
|
||||||
((ExtendedIconMenu) menuHolder.getIconMenu()).refresh(player, topInventory);
|
((ExtendedIconMenu) menuHolder.getIconMenu()).refresh(player, topInventory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onClick(player);
|
return super.onClick(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,41 +1,41 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon;
|
package com.gmail.filoghost.chestcommands.internal.icon;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.config.AsciiPlaceholders;
|
import com.gmail.filoghost.chestcommands.config.AsciiPlaceholders;
|
||||||
import com.gmail.filoghost.chestcommands.internal.Variable;
|
import com.gmail.filoghost.chestcommands.internal.Variable;
|
||||||
|
|
||||||
public abstract class IconCommand {
|
public abstract class IconCommand {
|
||||||
|
|
||||||
protected String command;
|
protected String command;
|
||||||
private List<Variable> containedVariables;
|
private List<Variable> containedVariables;
|
||||||
|
|
||||||
public IconCommand(String command) {
|
public IconCommand(String command) {
|
||||||
this.command = AsciiPlaceholders.placeholdersToSymbols(command).trim();
|
this.command = AsciiPlaceholders.placeholdersToSymbols(command).trim();
|
||||||
this.containedVariables = new ArrayList<Variable>();
|
this.containedVariables = new ArrayList<Variable>();
|
||||||
|
|
||||||
for (Variable variable : Variable.values()) {
|
for (Variable variable : Variable.values()) {
|
||||||
if (command.contains(variable.getText())) {
|
if (command.contains(variable.getText())) {
|
||||||
containedVariables.add(variable);
|
containedVariables.add(variable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getParsedCommand(Player executor) {
|
public String getParsedCommand(Player executor) {
|
||||||
if (containedVariables.isEmpty()) {
|
if (containedVariables.isEmpty()) {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
String commandCopy = command;
|
String commandCopy = command;
|
||||||
for (Variable variable : containedVariables) {
|
for (Variable variable : containedVariables) {
|
||||||
commandCopy = commandCopy.replace(variable.getText(), variable.getReplacement(executor));
|
commandCopy = commandCopy.replace(variable.getText(), variable.getReplacement(executor));
|
||||||
}
|
}
|
||||||
return commandCopy;
|
return commandCopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void execute(Player player);
|
public abstract void execute(Player player);
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,21 +1,21 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class BroadcastIconCommand extends IconCommand {
|
public class BroadcastIconCommand extends IconCommand {
|
||||||
|
|
||||||
public BroadcastIconCommand(String command) {
|
public BroadcastIconCommand(String command) {
|
||||||
super(Utils.addColors(command));
|
super(Utils.addColors(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player player) {
|
public void execute(Player player) {
|
||||||
Bukkit.broadcastMessage(getParsedCommand(player));
|
Bukkit.broadcastMessage(getParsedCommand(player));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,19 +1,19 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
|
|
||||||
public class ConsoleIconCommand extends IconCommand {
|
public class ConsoleIconCommand extends IconCommand {
|
||||||
|
|
||||||
public ConsoleIconCommand(String command) {
|
public ConsoleIconCommand(String command) {
|
||||||
super(command);
|
super(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player player) {
|
public void execute(Player player) {
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), getParsedCommand(player));
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), getParsedCommand(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,36 +1,36 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.bridge.BarAPIBridge;
|
import com.gmail.filoghost.chestcommands.bridge.BarAPIBridge;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class DragonBarIconCommand extends IconCommand {
|
public class DragonBarIconCommand extends IconCommand {
|
||||||
|
|
||||||
private String message;
|
private String message;
|
||||||
private int seconds;
|
private int seconds;
|
||||||
|
|
||||||
public DragonBarIconCommand(String command) {
|
public DragonBarIconCommand(String command) {
|
||||||
super(command);
|
super(command);
|
||||||
|
|
||||||
seconds = 1;
|
seconds = 1;
|
||||||
message = command;
|
message = command;
|
||||||
|
|
||||||
String[] split = command.split("\\|", 2); // Max of 2 pieces.
|
String[] split = command.split("\\|", 2); // Max of 2 pieces.
|
||||||
if (split.length > 1 && Utils.isValidPositiveInteger(split[0].trim())) {
|
if (split.length > 1 && Utils.isValidPositiveInteger(split[0].trim())) {
|
||||||
seconds = Integer.parseInt(split[0].trim());
|
seconds = Integer.parseInt(split[0].trim());
|
||||||
message = split[1].trim();
|
message = split[1].trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
message = Utils.addColors(message);
|
message = Utils.addColors(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player player) {
|
public void execute(Player player) {
|
||||||
if (BarAPIBridge.hasValidPlugin()) {
|
if (BarAPIBridge.hasValidPlugin()) {
|
||||||
BarAPIBridge.setMessage(player, message, seconds);
|
BarAPIBridge.setMessage(player, message, seconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,38 +1,38 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.exception.FormatException;
|
import com.gmail.filoghost.chestcommands.exception.FormatException;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.util.ItemStackReader;
|
import com.gmail.filoghost.chestcommands.util.ItemStackReader;
|
||||||
|
|
||||||
public class GiveIconCommand extends IconCommand {
|
public class GiveIconCommand extends IconCommand {
|
||||||
|
|
||||||
private ItemStack itemToGive;
|
private ItemStack itemToGive;
|
||||||
private String errorMessage;
|
private String errorMessage;
|
||||||
|
|
||||||
public GiveIconCommand(String command) {
|
public GiveIconCommand(String command) {
|
||||||
super(command);
|
super(command);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ItemStackReader reader = new ItemStackReader(command, true);
|
ItemStackReader reader = new ItemStackReader(command, true);
|
||||||
itemToGive = reader.createStack();
|
itemToGive = reader.createStack();
|
||||||
|
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
errorMessage = ChatColor.RED + "Invalid item to give: " + e.getMessage();
|
errorMessage = ChatColor.RED + "Invalid item to give: " + e.getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player player) {
|
public void execute(Player player) {
|
||||||
if (errorMessage != null) {
|
if (errorMessage != null) {
|
||||||
player.sendMessage(errorMessage);
|
player.sendMessage(errorMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.getInventory().addItem(itemToGive.clone());
|
player.getInventory().addItem(itemToGive.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,40 +1,40 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.bridge.EconomyBridge;
|
import com.gmail.filoghost.chestcommands.bridge.EconomyBridge;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class GiveMoneyIconCommand extends IconCommand {
|
public class GiveMoneyIconCommand extends IconCommand {
|
||||||
|
|
||||||
private double moneyToGive;
|
private double moneyToGive;
|
||||||
private String errorMessage;
|
private String errorMessage;
|
||||||
|
|
||||||
public GiveMoneyIconCommand(String command) {
|
public GiveMoneyIconCommand(String command) {
|
||||||
super(command);
|
super(command);
|
||||||
|
|
||||||
if (!Utils.isValidPositiveDouble(command)) {
|
if (!Utils.isValidPositiveDouble(command)) {
|
||||||
errorMessage = ChatColor.RED + "Invalid money amount: " + command;
|
errorMessage = ChatColor.RED + "Invalid money amount: " + command;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
moneyToGive = Double.parseDouble(command);
|
moneyToGive = Double.parseDouble(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player player) {
|
public void execute(Player player) {
|
||||||
if (errorMessage != null) {
|
if (errorMessage != null) {
|
||||||
player.sendMessage(errorMessage);
|
player.sendMessage(errorMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EconomyBridge.hasValidEconomy()) {
|
if (EconomyBridge.hasValidEconomy()) {
|
||||||
EconomyBridge.giveMoney(player, moneyToGive);
|
EconomyBridge.giveMoney(player, moneyToGive);
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.RED + "Vault with a compatible economy plugin not found. Please inform the staff.");
|
player.sendMessage(ChatColor.RED + "Vault with a compatible economy plugin not found. Please inform the staff.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,40 +1,40 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.bridge.PlayerPointsBridge;
|
import com.gmail.filoghost.chestcommands.bridge.PlayerPointsBridge;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class GivePointsIconCommand extends IconCommand {
|
public class GivePointsIconCommand extends IconCommand {
|
||||||
|
|
||||||
private int pointsToGive;
|
private int pointsToGive;
|
||||||
private String errorMessage;
|
private String errorMessage;
|
||||||
|
|
||||||
public GivePointsIconCommand(String command) {
|
public GivePointsIconCommand(String command) {
|
||||||
super(command);
|
super(command);
|
||||||
|
|
||||||
if (!Utils.isValidPositiveInteger(command)) {
|
if (!Utils.isValidPositiveInteger(command)) {
|
||||||
errorMessage = ChatColor.RED + "Invalid points amount: " + command;
|
errorMessage = ChatColor.RED + "Invalid points amount: " + command;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pointsToGive = Integer.parseInt(command);
|
pointsToGive = Integer.parseInt(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player player) {
|
public void execute(Player player) {
|
||||||
if (errorMessage != null) {
|
if (errorMessage != null) {
|
||||||
player.sendMessage(errorMessage);
|
player.sendMessage(errorMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PlayerPointsBridge.hasValidPlugin()) {
|
if (PlayerPointsBridge.hasValidPlugin()) {
|
||||||
PlayerPointsBridge.givePoints(player, pointsToGive);
|
PlayerPointsBridge.givePoints(player, pointsToGive);
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.RED + "The plugin PlayerPoints was not found. Please inform the staff.");
|
player.sendMessage(ChatColor.RED + "The plugin PlayerPoints was not found. Please inform the staff.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,26 +1,26 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
|
|
||||||
public class OpIconCommand extends IconCommand {
|
public class OpIconCommand extends IconCommand {
|
||||||
|
|
||||||
public OpIconCommand(String command) {
|
public OpIconCommand(String command) {
|
||||||
super(command);
|
super(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player player) {
|
public void execute(Player player) {
|
||||||
|
|
||||||
if (player.isOp()) {
|
if (player.isOp()) {
|
||||||
player.chat("/" + getParsedCommand(player));
|
player.chat("/" + getParsedCommand(player));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
player.setOp(true);
|
player.setOp(true);
|
||||||
player.chat("/" + getParsedCommand(player));
|
player.chat("/" + getParsedCommand(player));
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,39 +1,39 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
|
|
||||||
public class OpenIconCommand extends IconCommand {
|
public class OpenIconCommand extends IconCommand {
|
||||||
|
|
||||||
public OpenIconCommand(String command) {
|
public OpenIconCommand(String command) {
|
||||||
super(command);
|
super(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final Player player) {
|
public void execute(final Player player) {
|
||||||
final ExtendedIconMenu menu = ChestCommands.getFileNameToMenuMap().get(command.toLowerCase());
|
final ExtendedIconMenu menu = ChestCommands.getFileNameToMenuMap().get(command.toLowerCase());
|
||||||
if (menu != null) {
|
if (menu != null) {
|
||||||
|
|
||||||
// Delay the task, since this command is executed in ClickInventoryEvent
|
// Delay the task, since this command is executed in ClickInventoryEvent
|
||||||
// and opening another inventory in the same moment is not a good idea.
|
// and opening another inventory in the same moment is not a good idea.
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (player.hasPermission(menu.getPermission())) {
|
if (player.hasPermission(menu.getPermission())) {
|
||||||
menu.open(player);
|
menu.open(player);
|
||||||
} else {
|
} else {
|
||||||
menu.sendNoPermissionMessage(player);
|
menu.sendNoPermissionMessage(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.RED + "Menu not found! Please inform the staff.");
|
player.sendMessage(ChatColor.RED + "Menu not found! Please inform the staff.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,18 +1,18 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
|
|
||||||
public class PlayerIconCommand extends IconCommand {
|
public class PlayerIconCommand extends IconCommand {
|
||||||
|
|
||||||
public PlayerIconCommand(String command) {
|
public PlayerIconCommand(String command) {
|
||||||
super(command);
|
super(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player player) {
|
public void execute(Player player) {
|
||||||
player.chat('/' + getParsedCommand(player));
|
player.chat('/' + getParsedCommand(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,19 +1,19 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.bridge.bungee.BungeeCordUtils;
|
import com.gmail.filoghost.chestcommands.bridge.bungee.BungeeCordUtils;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
|
|
||||||
public class ServerIconCommand extends IconCommand {
|
public class ServerIconCommand extends IconCommand {
|
||||||
|
|
||||||
public ServerIconCommand(String command) {
|
public ServerIconCommand(String command) {
|
||||||
super(command);
|
super(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player player) {
|
public void execute(Player player) {
|
||||||
BungeeCordUtils.connect(player, command);
|
BungeeCordUtils.connect(player, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,54 +1,54 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class SoundIconCommand extends IconCommand {
|
public class SoundIconCommand extends IconCommand {
|
||||||
|
|
||||||
private Sound sound;
|
private Sound sound;
|
||||||
private float pitch;
|
private float pitch;
|
||||||
private float volume;
|
private float volume;
|
||||||
private String errorMessage;
|
private String errorMessage;
|
||||||
|
|
||||||
public SoundIconCommand(String command) {
|
public SoundIconCommand(String command) {
|
||||||
super(command);
|
super(command);
|
||||||
|
|
||||||
pitch = 1.0f;
|
pitch = 1.0f;
|
||||||
volume = 1.0f;
|
volume = 1.0f;
|
||||||
|
|
||||||
String[] split = command.split(",");
|
String[] split = command.split(",");
|
||||||
|
|
||||||
sound = Utils.matchSound(split[0]);
|
sound = Utils.matchSound(split[0]);
|
||||||
if (sound == null) {
|
if (sound == null) {
|
||||||
errorMessage = ChatColor.RED + "Invalid sound \"" + split[0].trim() + "\".";
|
errorMessage = ChatColor.RED + "Invalid sound \"" + split[0].trim() + "\".";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
try {
|
try {
|
||||||
pitch = Float.parseFloat(split[1].trim());
|
pitch = Float.parseFloat(split[1].trim());
|
||||||
} catch (NumberFormatException e) { }
|
} catch (NumberFormatException e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (split.length > 2) {
|
if (split.length > 2) {
|
||||||
try {
|
try {
|
||||||
volume = Float.parseFloat(split[2].trim());
|
volume = Float.parseFloat(split[2].trim());
|
||||||
} catch (NumberFormatException e) { }
|
} catch (NumberFormatException e) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player player) {
|
public void execute(Player player) {
|
||||||
if (errorMessage != null) {
|
if (errorMessage != null) {
|
||||||
player.sendMessage(errorMessage);
|
player.sendMessage(errorMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.playSound(player.getLocation(), sound, volume, pitch);
|
player.playSound(player.getLocation(), sound, volume, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,19 +1,19 @@
|
||||||
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class TellIconCommand extends IconCommand {
|
public class TellIconCommand extends IconCommand {
|
||||||
|
|
||||||
public TellIconCommand(String command) {
|
public TellIconCommand(String command) {
|
||||||
super(Utils.addColors(command));
|
super(Utils.addColors(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player player) {
|
public void execute(Player player) {
|
||||||
player.sendMessage(getParsedCommand(player));
|
player.sendMessage(getParsedCommand(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,41 +1,41 @@
|
||||||
package com.gmail.filoghost.chestcommands.listener;
|
package com.gmail.filoghost.chestcommands.listener;
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
||||||
import com.gmail.filoghost.chestcommands.util.StringUtils;
|
import com.gmail.filoghost.chestcommands.util.StringUtils;
|
||||||
|
|
||||||
public class CommandListener implements Listener {
|
public class CommandListener implements Listener {
|
||||||
|
|
||||||
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onCommand(PlayerCommandPreprocessEvent event) {
|
public void onCommand(PlayerCommandPreprocessEvent event) {
|
||||||
|
|
||||||
if (ChestCommands.getSettings().use_only_commands_without_args && event.getMessage().contains(" ")) {
|
if (ChestCommands.getSettings().use_only_commands_without_args && event.getMessage().contains(" ")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Very fast method compared to split & substring.
|
// Very fast method compared to split & substring.
|
||||||
String command = StringUtils.getCleanCommand(event.getMessage());
|
String command = StringUtils.getCleanCommand(event.getMessage());
|
||||||
|
|
||||||
if (command.isEmpty()) {
|
if (command.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtendedIconMenu menu = ChestCommands.getCommandToMenuMap().get(command);
|
ExtendedIconMenu menu = ChestCommands.getCommandToMenuMap().get(command);
|
||||||
|
|
||||||
if (menu != null) {
|
if (menu != null) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
if (event.getPlayer().hasPermission(menu.getPermission())) {
|
if (event.getPlayer().hasPermission(menu.getPermission())) {
|
||||||
menu.open(event.getPlayer());
|
menu.open(event.getPlayer());
|
||||||
} else {
|
} else {
|
||||||
menu.sendNoPermissionMessage(event.getPlayer());
|
menu.sendNoPermissionMessage(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,82 +1,82 @@
|
||||||
package com.gmail.filoghost.chestcommands.listener;
|
package com.gmail.filoghost.chestcommands.listener;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
import com.gmail.filoghost.chestcommands.api.Icon;
|
import com.gmail.filoghost.chestcommands.api.Icon;
|
||||||
import com.gmail.filoghost.chestcommands.api.IconMenu;
|
import com.gmail.filoghost.chestcommands.api.IconMenu;
|
||||||
import com.gmail.filoghost.chestcommands.internal.BoundItem;
|
import com.gmail.filoghost.chestcommands.internal.BoundItem;
|
||||||
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
|
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
|
||||||
import com.gmail.filoghost.chestcommands.task.ExecuteCommandsTask;
|
import com.gmail.filoghost.chestcommands.task.ExecuteCommandsTask;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class InventoryListener implements Listener {
|
public class InventoryListener implements Listener {
|
||||||
|
|
||||||
private static Map<Player, Long> antiClickSpam = Utils.newHashMap();
|
private static Map<Player, Long> antiClickSpam = Utils.newHashMap();
|
||||||
|
|
||||||
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = false)
|
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = false)
|
||||||
public void onInteract(PlayerInteractEvent event) {
|
public void onInteract(PlayerInteractEvent event) {
|
||||||
if (event.hasItem() && event.getAction() != Action.PHYSICAL) {
|
if (event.hasItem() && event.getAction() != Action.PHYSICAL) {
|
||||||
for (BoundItem boundItem : ChestCommands.getBoundItems()) {
|
for (BoundItem boundItem : ChestCommands.getBoundItems()) {
|
||||||
if (boundItem.isValidTrigger(event.getItem(), event.getAction())) {
|
if (boundItem.isValidTrigger(event.getItem(), event.getAction())) {
|
||||||
if (event.getPlayer().hasPermission(boundItem.getMenu().getPermission())) {
|
if (event.getPlayer().hasPermission(boundItem.getMenu().getPermission())) {
|
||||||
boundItem.getMenu().open(event.getPlayer());
|
boundItem.getMenu().open(event.getPlayer());
|
||||||
} else {
|
} else {
|
||||||
boundItem.getMenu().sendNoPermissionMessage(event.getPlayer());
|
boundItem.getMenu().sendNoPermissionMessage(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = false)
|
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = false)
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
if (event.getInventory().getHolder() instanceof MenuInventoryHolder) {
|
if (event.getInventory().getHolder() instanceof MenuInventoryHolder) {
|
||||||
|
|
||||||
event.setCancelled(true); // First thing to do, if an exception is thrown at least the player doesn't take the item.
|
event.setCancelled(true); // First thing to do, if an exception is thrown at least the player doesn't take the item.
|
||||||
|
|
||||||
IconMenu menu = ((MenuInventoryHolder) event.getInventory().getHolder()).getIconMenu();
|
IconMenu menu = ((MenuInventoryHolder) event.getInventory().getHolder()).getIconMenu();
|
||||||
int slot = event.getRawSlot();
|
int slot = event.getRawSlot();
|
||||||
|
|
||||||
if (slot >= 0 && slot < menu.getSize()) {
|
if (slot >= 0 && slot < menu.getSize()) {
|
||||||
|
|
||||||
Icon icon = menu.getIconRaw(slot);
|
Icon icon = menu.getIconRaw(slot);
|
||||||
|
|
||||||
if (icon != null && event.getInventory().getItem(slot) != null) {
|
if (icon != null && event.getInventory().getItem(slot) != null) {
|
||||||
Player clicker = (Player) event.getWhoClicked();
|
Player clicker = (Player) event.getWhoClicked();
|
||||||
|
|
||||||
Long cooldownUntil = antiClickSpam.get(clicker);
|
Long cooldownUntil = antiClickSpam.get(clicker);
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
int minDelay = ChestCommands.getSettings().anti_click_spam_delay;
|
int minDelay = ChestCommands.getSettings().anti_click_spam_delay;
|
||||||
|
|
||||||
if (minDelay > 0) {
|
if (minDelay > 0) {
|
||||||
if (cooldownUntil != null && cooldownUntil > now) {
|
if (cooldownUntil != null && cooldownUntil > now) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
antiClickSpam.put(clicker, now + minDelay);
|
antiClickSpam.put(clicker, now + minDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Closes the inventory and executes commands AFTER the event.
|
// Closes the inventory and executes commands AFTER the event.
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), new ExecuteCommandsTask(clicker, icon));
|
Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), new ExecuteCommandsTask(clicker, icon));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onQuit(PlayerQuitEvent event) {
|
public void onQuit(PlayerQuitEvent event) {
|
||||||
antiClickSpam.remove(event.getPlayer());
|
antiClickSpam.remove(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,26 +1,26 @@
|
||||||
package com.gmail.filoghost.chestcommands.listener;
|
package com.gmail.filoghost.chestcommands.listener;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
import com.gmail.filoghost.chestcommands.Permissions;
|
import com.gmail.filoghost.chestcommands.Permissions;
|
||||||
|
|
||||||
public class JoinListener implements Listener {
|
public class JoinListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent event) {
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
|
|
||||||
if (ChestCommands.getLastReloadErrors() > 0 && event.getPlayer().hasPermission(Permissions.SEE_ERRORS)) {
|
if (ChestCommands.getLastReloadErrors() > 0 && event.getPlayer().hasPermission(Permissions.SEE_ERRORS)) {
|
||||||
event.getPlayer().sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "The plugin found " + ChestCommands.getLastReloadErrors() + " error(s) last time it was loaded. You can see them by doing \"/cc reload\" in the console.");
|
event.getPlayer().sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "The plugin found " + ChestCommands.getLastReloadErrors() + " error(s) last time it was loaded. You can see them by doing \"/cc reload\" in the console.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ChestCommands.hasNewVersion() && ChestCommands.getSettings().update_notifications && event.getPlayer().hasPermission(Permissions.UPDATE_NOTIFICATIONS)) {
|
if (ChestCommands.hasNewVersion() && ChestCommands.getSettings().update_notifications && event.getPlayer().hasPermission(Permissions.UPDATE_NOTIFICATIONS)) {
|
||||||
event.getPlayer().sendMessage(ChestCommands.CHAT_PREFIX + "Found an update: " + ChestCommands.getNewVersion() + ". Download:");
|
event.getPlayer().sendMessage(ChestCommands.CHAT_PREFIX + "Found an update: " + ChestCommands.getNewVersion() + ". Download:");
|
||||||
event.getPlayer().sendMessage(ChatColor.DARK_GREEN + ">> " + ChatColor.GREEN + "http://dev.bukkit.org/bukkit-plugins/chest-commands");
|
event.getPlayer().sendMessage(ChatColor.DARK_GREEN + ">> " + ChatColor.GREEN + "http://dev.bukkit.org/bukkit-plugins/chest-commands");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,81 +1,81 @@
|
||||||
package com.gmail.filoghost.chestcommands.listener;
|
package com.gmail.filoghost.chestcommands.listener;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
import com.gmail.filoghost.chestcommands.Permissions;
|
import com.gmail.filoghost.chestcommands.Permissions;
|
||||||
import com.gmail.filoghost.chestcommands.api.IconMenu;
|
import com.gmail.filoghost.chestcommands.api.IconMenu;
|
||||||
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class SignListener implements Listener {
|
public class SignListener implements Listener {
|
||||||
|
|
||||||
@EventHandler (priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler (priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onInteract(PlayerInteractEvent event) {
|
public void onInteract(PlayerInteractEvent event) {
|
||||||
|
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && isSign(event.getClickedBlock().getType())) {
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && isSign(event.getClickedBlock().getType())) {
|
||||||
|
|
||||||
Sign sign = (Sign) event.getClickedBlock().getState();
|
Sign sign = (Sign) event.getClickedBlock().getState();
|
||||||
if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]")) {
|
if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]")) {
|
||||||
|
|
||||||
sign.getLine(1);
|
sign.getLine(1);
|
||||||
ExtendedIconMenu iconMenu = ChestCommands.getFileNameToMenuMap().get(Utils.addYamlExtension(sign.getLine(1)));
|
ExtendedIconMenu iconMenu = ChestCommands.getFileNameToMenuMap().get(Utils.addYamlExtension(sign.getLine(1)));
|
||||||
if (iconMenu != null) {
|
if (iconMenu != null) {
|
||||||
|
|
||||||
if (event.getPlayer().hasPermission(iconMenu.getPermission())) {
|
if (event.getPlayer().hasPermission(iconMenu.getPermission())) {
|
||||||
iconMenu.open(event.getPlayer());
|
iconMenu.open(event.getPlayer());
|
||||||
} else {
|
} else {
|
||||||
iconMenu.sendNoPermissionMessage(event.getPlayer());
|
iconMenu.sendNoPermissionMessage(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sign.setLine(0, ChatColor.RED + ChatColor.stripColor(sign.getLine(0)));
|
sign.setLine(0, ChatColor.RED + ChatColor.stripColor(sign.getLine(0)));
|
||||||
event.getPlayer().sendMessage(ChestCommands.getLang().menu_not_found);
|
event.getPlayer().sendMessage(ChestCommands.getLang().menu_not_found);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler (priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler (priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onSignChange(SignChangeEvent event) {
|
public void onSignChange(SignChangeEvent event) {
|
||||||
if (event.getLine(0).equalsIgnoreCase("[menu]") && event.getPlayer().hasPermission(Permissions.SIGN_CREATE)) {
|
if (event.getLine(0).equalsIgnoreCase("[menu]") && event.getPlayer().hasPermission(Permissions.SIGN_CREATE)) {
|
||||||
|
|
||||||
if (event.getLine(1).isEmpty()) {
|
if (event.getLine(1).isEmpty()) {
|
||||||
event.setLine(0, ChatColor.RED + event.getLine(0));
|
event.setLine(0, ChatColor.RED + event.getLine(0));
|
||||||
event.getPlayer().sendMessage(ChatColor.RED + "You must set a valid menu name in the second line.");
|
event.getPlayer().sendMessage(ChatColor.RED + "You must set a valid menu name in the second line.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IconMenu iconMenu = ChestCommands.getFileNameToMenuMap().get(Utils.addYamlExtension(event.getLine(1)));
|
IconMenu iconMenu = ChestCommands.getFileNameToMenuMap().get(Utils.addYamlExtension(event.getLine(1)));
|
||||||
if (iconMenu == null) {
|
if (iconMenu == null) {
|
||||||
event.setLine(0, ChatColor.RED + event.getLine(0));
|
event.setLine(0, ChatColor.RED + event.getLine(0));
|
||||||
event.getPlayer().sendMessage(ChatColor.RED + "That menu was not found.");
|
event.getPlayer().sendMessage(ChatColor.RED + "That menu was not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setLine(0, ChatColor.DARK_BLUE + event.getLine(0));
|
event.setLine(0, ChatColor.DARK_BLUE + event.getLine(0));
|
||||||
event.getPlayer().sendMessage(ChatColor.GREEN + "Successfully created a sign for the menu " + Utils.addYamlExtension(event.getLine(1)) + ".");
|
event.getPlayer().sendMessage(ChatColor.GREEN + "Successfully created a sign for the menu " + Utils.addYamlExtension(event.getLine(1)) + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onSignChangeMonitor(SignChangeEvent event) {
|
public void onSignChangeMonitor(SignChangeEvent event) {
|
||||||
// Prevent players with permissions for creating colored signs from creating menu signs.
|
// Prevent players with permissions for creating colored signs from creating menu signs.
|
||||||
if (event.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]") && !event.getPlayer().hasPermission(Permissions.SIGN_CREATE)) {
|
if (event.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]") && !event.getPlayer().hasPermission(Permissions.SIGN_CREATE)) {
|
||||||
event.setLine(0, ChatColor.stripColor(event.getLine(0)));
|
event.setLine(0, ChatColor.stripColor(event.getLine(0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSign(Material material) {
|
private boolean isSign(Material material) {
|
||||||
return material == Material.WALL_SIGN || material == Material.SIGN_POST;
|
return material == Material.WALL_SIGN || material == Material.SIGN_POST;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,121 +1,121 @@
|
||||||
package com.gmail.filoghost.chestcommands.nms;
|
package com.gmail.filoghost.chestcommands.nms;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemFlag;
|
import org.bukkit.inventory.ItemFlag;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class AttributeRemover {
|
public class AttributeRemover {
|
||||||
|
|
||||||
private static boolean useItemFlags;
|
private static boolean useItemFlags;
|
||||||
private static boolean useReflection;
|
private static boolean useReflection;
|
||||||
|
|
||||||
// Reflection stuff
|
// Reflection stuff
|
||||||
private static Class<?> nbtTagCompoundClass;
|
private static Class<?> nbtTagCompoundClass;
|
||||||
private static Class<?> nbtTagListClass;
|
private static Class<?> nbtTagListClass;
|
||||||
private static Class<?> nmsItemstackClass;
|
private static Class<?> nmsItemstackClass;
|
||||||
private static Method asNmsCopyMethod; // static
|
private static Method asNmsCopyMethod; // static
|
||||||
private static Method asCraftMirrorMethod; // static
|
private static Method asCraftMirrorMethod; // static
|
||||||
private static Method hasTagMethod;
|
private static Method hasTagMethod;
|
||||||
private static Method getTagMethod;
|
private static Method getTagMethod;
|
||||||
private static Method setTagMethod;
|
private static Method setTagMethod;
|
||||||
private static Method nbtSetMethod;
|
private static Method nbtSetMethod;
|
||||||
|
|
||||||
|
|
||||||
public static boolean setup() {
|
public static boolean setup() {
|
||||||
|
|
||||||
if (Utils.isClassLoaded("org.bukkit.inventory.ItemFlag")) {
|
if (Utils.isClassLoaded("org.bukkit.inventory.ItemFlag")) {
|
||||||
// We can use the new Bukkit API (1.8.3+)
|
// We can use the new Bukkit API (1.8.3+)
|
||||||
useItemFlags = true;
|
useItemFlags = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Try to get the NMS methods and classes
|
// Try to get the NMS methods and classes
|
||||||
nbtTagCompoundClass = getNmsClass("NBTTagCompound");
|
nbtTagCompoundClass = getNmsClass("NBTTagCompound");
|
||||||
nbtTagListClass = getNmsClass("NBTTagList");
|
nbtTagListClass = getNmsClass("NBTTagList");
|
||||||
nmsItemstackClass = getNmsClass("ItemStack");
|
nmsItemstackClass = getNmsClass("ItemStack");
|
||||||
|
|
||||||
asNmsCopyMethod = getObcClass("inventory.CraftItemStack").getMethod("asNMSCopy", ItemStack.class);
|
asNmsCopyMethod = getObcClass("inventory.CraftItemStack").getMethod("asNMSCopy", ItemStack.class);
|
||||||
asCraftMirrorMethod = getObcClass("inventory.CraftItemStack").getMethod("asCraftMirror", nmsItemstackClass);
|
asCraftMirrorMethod = getObcClass("inventory.CraftItemStack").getMethod("asCraftMirror", nmsItemstackClass);
|
||||||
|
|
||||||
hasTagMethod = nmsItemstackClass.getMethod("hasTag");
|
hasTagMethod = nmsItemstackClass.getMethod("hasTag");
|
||||||
getTagMethod = nmsItemstackClass.getMethod("getTag");
|
getTagMethod = nmsItemstackClass.getMethod("getTag");
|
||||||
setTagMethod = nmsItemstackClass.getMethod("setTag", nbtTagCompoundClass);
|
setTagMethod = nmsItemstackClass.getMethod("setTag", nbtTagCompoundClass);
|
||||||
|
|
||||||
nbtSetMethod = nbtTagCompoundClass.getMethod("set", String.class, getNmsClass("NBTBase"));
|
nbtSetMethod = nbtTagCompoundClass.getMethod("set", String.class, getNmsClass("NBTBase"));
|
||||||
|
|
||||||
useReflection = true;
|
useReflection = true;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ChestCommands.getInstance().getLogger().info("Could not enable the attribute remover for this version (" + e + "). Attributes will show up on items.");
|
ChestCommands.getInstance().getLogger().info("Could not enable the attribute remover for this version (" + e + "). Attributes will show up on items.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static Class<?> getNmsClass(String name) throws ClassNotFoundException {
|
private static Class<?> getNmsClass(String name) throws ClassNotFoundException {
|
||||||
return Class.forName("net.minecraft.server." + Utils.getBukkitVersion() + "." + name);
|
return Class.forName("net.minecraft.server." + Utils.getBukkitVersion() + "." + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> getObcClass(String name) throws ClassNotFoundException {
|
private static Class<?> getObcClass(String name) throws ClassNotFoundException {
|
||||||
return Class.forName("org.bukkit.craftbukkit." + Utils.getBukkitVersion() + "." + name);
|
return Class.forName("org.bukkit.craftbukkit." + Utils.getBukkitVersion() + "." + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack hideAttributes(ItemStack item) {
|
public static ItemStack hideAttributes(ItemStack item) {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useItemFlags) {
|
if (useItemFlags) {
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
if (isNullOrEmpty(meta.getItemFlags())) {
|
if (isNullOrEmpty(meta.getItemFlags())) {
|
||||||
// Add them only if necessary
|
// Add them only if necessary
|
||||||
meta.addItemFlags(ItemFlag.values());
|
meta.addItemFlags(ItemFlag.values());
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
|
|
||||||
} else if (useReflection) {
|
} else if (useReflection) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Object nmsItemstack = asNmsCopyMethod.invoke(null, item);
|
Object nmsItemstack = asNmsCopyMethod.invoke(null, item);
|
||||||
if (nmsItemstack == null) {
|
if (nmsItemstack == null) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object nbtCompound;
|
Object nbtCompound;
|
||||||
if ((Boolean) hasTagMethod.invoke(nmsItemstack)) {
|
if ((Boolean) hasTagMethod.invoke(nmsItemstack)) {
|
||||||
nbtCompound = getTagMethod.invoke(nmsItemstack);
|
nbtCompound = getTagMethod.invoke(nmsItemstack);
|
||||||
} else {
|
} else {
|
||||||
nbtCompound = nbtTagCompoundClass.newInstance();
|
nbtCompound = nbtTagCompoundClass.newInstance();
|
||||||
setTagMethod.invoke(nmsItemstack, nbtCompound);
|
setTagMethod.invoke(nmsItemstack, nbtCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbtCompound == null) {
|
if (nbtCompound == null) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object nbtList = nbtTagListClass.newInstance();
|
Object nbtList = nbtTagListClass.newInstance();
|
||||||
nbtSetMethod.invoke(nbtCompound, "AttributeModifiers", nbtList);
|
nbtSetMethod.invoke(nbtCompound, "AttributeModifiers", nbtList);
|
||||||
return (ItemStack) asCraftMirrorMethod.invoke(null, nmsItemstack);
|
return (ItemStack) asCraftMirrorMethod.invoke(null, nmsItemstack);
|
||||||
|
|
||||||
} catch (Exception e) { }
|
} catch (Exception e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
// On failure
|
// On failure
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isNullOrEmpty(Collection<?> coll) {
|
private static boolean isNullOrEmpty(Collection<?> coll) {
|
||||||
return coll == null || coll.isEmpty();
|
return coll == null || coll.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,98 +1,98 @@
|
||||||
package com.gmail.filoghost.chestcommands.serializer;
|
package com.gmail.filoghost.chestcommands.serializer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.command.BroadcastIconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.command.BroadcastIconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.command.ConsoleIconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.command.ConsoleIconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.command.DragonBarIconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.command.DragonBarIconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.command.GiveIconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.command.GiveIconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.command.GiveMoneyIconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.command.GiveMoneyIconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.command.GivePointsIconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.command.GivePointsIconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.command.OpIconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.command.OpIconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.command.OpenIconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.command.OpenIconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.command.PlayerIconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.command.PlayerIconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.command.ServerIconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.command.ServerIconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.command.SoundIconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.command.SoundIconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.command.TellIconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.command.TellIconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class CommandSerializer {
|
public class CommandSerializer {
|
||||||
|
|
||||||
private static Map<Pattern, Class<? extends IconCommand>> commandTypesMap = Utils.newHashMap();
|
private static Map<Pattern, Class<? extends IconCommand>> commandTypesMap = Utils.newHashMap();
|
||||||
static {
|
static {
|
||||||
commandTypesMap.put(commandPattern("console:"), ConsoleIconCommand.class);
|
commandTypesMap.put(commandPattern("console:"), ConsoleIconCommand.class);
|
||||||
commandTypesMap.put(commandPattern("op:"), OpIconCommand.class);
|
commandTypesMap.put(commandPattern("op:"), OpIconCommand.class);
|
||||||
commandTypesMap.put(commandPattern("(open|menu):"), OpenIconCommand.class);
|
commandTypesMap.put(commandPattern("(open|menu):"), OpenIconCommand.class);
|
||||||
commandTypesMap.put(commandPattern("server:?"), ServerIconCommand.class); // The colon is optional.
|
commandTypesMap.put(commandPattern("server:?"), ServerIconCommand.class); // The colon is optional.
|
||||||
commandTypesMap.put(commandPattern("tell:"), TellIconCommand.class);
|
commandTypesMap.put(commandPattern("tell:"), TellIconCommand.class);
|
||||||
commandTypesMap.put(commandPattern("broadcast:"), BroadcastIconCommand.class);
|
commandTypesMap.put(commandPattern("broadcast:"), BroadcastIconCommand.class);
|
||||||
commandTypesMap.put(commandPattern("give:"), GiveIconCommand.class);
|
commandTypesMap.put(commandPattern("give:"), GiveIconCommand.class);
|
||||||
commandTypesMap.put(commandPattern("give-?money:"), GiveMoneyIconCommand.class);
|
commandTypesMap.put(commandPattern("give-?money:"), GiveMoneyIconCommand.class);
|
||||||
commandTypesMap.put(commandPattern("give-?points:"), GivePointsIconCommand.class);
|
commandTypesMap.put(commandPattern("give-?points:"), GivePointsIconCommand.class);
|
||||||
commandTypesMap.put(commandPattern("sound:"), SoundIconCommand.class);
|
commandTypesMap.put(commandPattern("sound:"), SoundIconCommand.class);
|
||||||
commandTypesMap.put(commandPattern("dragon-?bar:"), DragonBarIconCommand.class);
|
commandTypesMap.put(commandPattern("dragon-?bar:"), DragonBarIconCommand.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Pattern commandPattern(String regex) {
|
private static Pattern commandPattern(String regex) {
|
||||||
return Pattern.compile("^(?i)" + regex); // Case insensitive and only at the beginning.
|
return Pattern.compile("^(?i)" + regex); // Case insensitive and only at the beginning.
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkClassConstructors(ErrorLogger errorLogger) {
|
public static void checkClassConstructors(ErrorLogger errorLogger) {
|
||||||
for (Class<? extends IconCommand> clazz : commandTypesMap.values()) {
|
for (Class<? extends IconCommand> clazz : commandTypesMap.values()) {
|
||||||
try {
|
try {
|
||||||
clazz.getDeclaredConstructor(String.class).newInstance("");
|
clazz.getDeclaredConstructor(String.class).newInstance("");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
String className = clazz.getName().replace("Command", "");
|
String className = clazz.getName().replace("Command", "");
|
||||||
className = className.substring(className.lastIndexOf('.') + 1, className.length());
|
className = className.substring(className.lastIndexOf('.') + 1, className.length());
|
||||||
errorLogger.addError("Unable to register the \"" + className + "\" command type(" + ex.getClass().getName() + "), please inform the developer (filoghost). The plugin will still work, but all the \"" + className + "\" commands will be treated as normal commands.");
|
errorLogger.addError("Unable to register the \"" + className + "\" command type(" + ex.getClass().getName() + "), please inform the developer (filoghost). The plugin will still work, but all the \"" + className + "\" commands will be treated as normal commands.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<IconCommand> readCommands(String input) {
|
public static List<IconCommand> readCommands(String input) {
|
||||||
String separator = ChestCommands.getSettings().multiple_commands_separator;
|
String separator = ChestCommands.getSettings().multiple_commands_separator;
|
||||||
if (separator == null || separator.length() == 0) {
|
if (separator == null || separator.length() == 0) {
|
||||||
separator = ";";
|
separator = ";";
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] split = input.split(Pattern.quote(separator));
|
String[] split = input.split(Pattern.quote(separator));
|
||||||
List<IconCommand> iconCommands = Utils.newArrayList();
|
List<IconCommand> iconCommands = Utils.newArrayList();
|
||||||
|
|
||||||
for (String command : split) {
|
for (String command : split) {
|
||||||
String trim = command.trim();
|
String trim = command.trim();
|
||||||
|
|
||||||
if (trim.length() > 0) {
|
if (trim.length() > 0) {
|
||||||
iconCommands.add(matchCommand(trim));
|
iconCommands.add(matchCommand(trim));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return iconCommands;
|
return iconCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IconCommand matchCommand(String input) {
|
public static IconCommand matchCommand(String input) {
|
||||||
|
|
||||||
for (Entry<Pattern, Class<? extends IconCommand>> entry : commandTypesMap.entrySet()) {
|
for (Entry<Pattern, Class<? extends IconCommand>> entry : commandTypesMap.entrySet()) {
|
||||||
Matcher matcher = entry.getKey().matcher(input);
|
Matcher matcher = entry.getKey().matcher(input);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
// Remove the command prefix and trim the spaces.
|
// Remove the command prefix and trim the spaces.
|
||||||
String cleanCommand = matcher.replaceFirst("").trim();
|
String cleanCommand = matcher.replaceFirst("").trim();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return entry.getValue().getDeclaredConstructor(String.class).newInstance(cleanCommand);
|
return entry.getValue().getDeclaredConstructor(String.class).newInstance(cleanCommand);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Checked at startup.
|
// Checked at startup.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PlayerIconCommand(input); // Normal command, no match found.
|
return new PlayerIconCommand(input); // Normal command, no match found.
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,94 +1,94 @@
|
||||||
package com.gmail.filoghost.chestcommands.serializer;
|
package com.gmail.filoghost.chestcommands.serializer;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
||||||
import com.gmail.filoghost.chestcommands.util.StringUtils;
|
import com.gmail.filoghost.chestcommands.util.StringUtils;
|
||||||
|
|
||||||
public class EnchantmentSerializer {
|
public class EnchantmentSerializer {
|
||||||
|
|
||||||
private static Map<String, Enchantment> enchantmentsMap = new HashMap<String, Enchantment>();
|
private static Map<String, Enchantment> enchantmentsMap = new HashMap<String, Enchantment>();
|
||||||
static {
|
static {
|
||||||
enchantmentsMap.put(formatLowercase("Protection"), Enchantment.PROTECTION_ENVIRONMENTAL);
|
enchantmentsMap.put(formatLowercase("Protection"), Enchantment.PROTECTION_ENVIRONMENTAL);
|
||||||
enchantmentsMap.put(formatLowercase("Fire Protection"), Enchantment.PROTECTION_FIRE);
|
enchantmentsMap.put(formatLowercase("Fire Protection"), Enchantment.PROTECTION_FIRE);
|
||||||
enchantmentsMap.put(formatLowercase("Feather Falling"), Enchantment.PROTECTION_FALL);
|
enchantmentsMap.put(formatLowercase("Feather Falling"), Enchantment.PROTECTION_FALL);
|
||||||
enchantmentsMap.put(formatLowercase("Blast Protection"), Enchantment.PROTECTION_EXPLOSIONS);
|
enchantmentsMap.put(formatLowercase("Blast Protection"), Enchantment.PROTECTION_EXPLOSIONS);
|
||||||
enchantmentsMap.put(formatLowercase("Projectile Protection"), Enchantment.PROTECTION_PROJECTILE);
|
enchantmentsMap.put(formatLowercase("Projectile Protection"), Enchantment.PROTECTION_PROJECTILE);
|
||||||
enchantmentsMap.put(formatLowercase("Respiration"), Enchantment.OXYGEN);
|
enchantmentsMap.put(formatLowercase("Respiration"), Enchantment.OXYGEN);
|
||||||
enchantmentsMap.put(formatLowercase("Aqua Affinity"), Enchantment.WATER_WORKER);
|
enchantmentsMap.put(formatLowercase("Aqua Affinity"), Enchantment.WATER_WORKER);
|
||||||
enchantmentsMap.put(formatLowercase("Thorns"), Enchantment.THORNS);
|
enchantmentsMap.put(formatLowercase("Thorns"), Enchantment.THORNS);
|
||||||
enchantmentsMap.put(formatLowercase("Sharpness"), Enchantment.DAMAGE_ALL);
|
enchantmentsMap.put(formatLowercase("Sharpness"), Enchantment.DAMAGE_ALL);
|
||||||
enchantmentsMap.put(formatLowercase("Smite"), Enchantment.DAMAGE_UNDEAD);
|
enchantmentsMap.put(formatLowercase("Smite"), Enchantment.DAMAGE_UNDEAD);
|
||||||
enchantmentsMap.put(formatLowercase("Bane Of Arthropods"), Enchantment.DAMAGE_ARTHROPODS);
|
enchantmentsMap.put(formatLowercase("Bane Of Arthropods"), Enchantment.DAMAGE_ARTHROPODS);
|
||||||
enchantmentsMap.put(formatLowercase("Knockback"), Enchantment.KNOCKBACK);
|
enchantmentsMap.put(formatLowercase("Knockback"), Enchantment.KNOCKBACK);
|
||||||
enchantmentsMap.put(formatLowercase("Fire Aspect"), Enchantment.FIRE_ASPECT);
|
enchantmentsMap.put(formatLowercase("Fire Aspect"), Enchantment.FIRE_ASPECT);
|
||||||
enchantmentsMap.put(formatLowercase("Looting"), Enchantment.LOOT_BONUS_MOBS);
|
enchantmentsMap.put(formatLowercase("Looting"), Enchantment.LOOT_BONUS_MOBS);
|
||||||
enchantmentsMap.put(formatLowercase("Efficiency"), Enchantment.DIG_SPEED);
|
enchantmentsMap.put(formatLowercase("Efficiency"), Enchantment.DIG_SPEED);
|
||||||
enchantmentsMap.put(formatLowercase("Silk Touch"), Enchantment.SILK_TOUCH);
|
enchantmentsMap.put(formatLowercase("Silk Touch"), Enchantment.SILK_TOUCH);
|
||||||
enchantmentsMap.put(formatLowercase("Unbreaking"), Enchantment.DURABILITY);
|
enchantmentsMap.put(formatLowercase("Unbreaking"), Enchantment.DURABILITY);
|
||||||
enchantmentsMap.put(formatLowercase("Fortune"), Enchantment.LOOT_BONUS_BLOCKS);
|
enchantmentsMap.put(formatLowercase("Fortune"), Enchantment.LOOT_BONUS_BLOCKS);
|
||||||
enchantmentsMap.put(formatLowercase("Power"), Enchantment.ARROW_DAMAGE);
|
enchantmentsMap.put(formatLowercase("Power"), Enchantment.ARROW_DAMAGE);
|
||||||
enchantmentsMap.put(formatLowercase("Punch"), Enchantment.ARROW_KNOCKBACK);
|
enchantmentsMap.put(formatLowercase("Punch"), Enchantment.ARROW_KNOCKBACK);
|
||||||
enchantmentsMap.put(formatLowercase("Flame"), Enchantment.ARROW_FIRE);
|
enchantmentsMap.put(formatLowercase("Flame"), Enchantment.ARROW_FIRE);
|
||||||
enchantmentsMap.put(formatLowercase("Infinity"), Enchantment.ARROW_INFINITE);
|
enchantmentsMap.put(formatLowercase("Infinity"), Enchantment.ARROW_INFINITE);
|
||||||
enchantmentsMap.put(formatLowercase("Lure"), Enchantment.LURE);
|
enchantmentsMap.put(formatLowercase("Lure"), Enchantment.LURE);
|
||||||
enchantmentsMap.put(formatLowercase("Luck Of The Sea"), Enchantment.LUCK);
|
enchantmentsMap.put(formatLowercase("Luck Of The Sea"), Enchantment.LUCK);
|
||||||
|
|
||||||
for (Enchantment enchant : Enchantment.values()) {
|
for (Enchantment enchant : Enchantment.values()) {
|
||||||
if (enchant != null) {
|
if (enchant != null) {
|
||||||
// Accepts the ugly default names too.
|
// Accepts the ugly default names too.
|
||||||
enchantmentsMap.put(formatLowercase(enchant.getName()), enchant);
|
enchantmentsMap.put(formatLowercase(enchant.getName()), enchant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String formatLowercase(String string) {
|
private static String formatLowercase(String string) {
|
||||||
return StringUtils.stripChars(string, " _-").toLowerCase();
|
return StringUtils.stripChars(string, " _-").toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<Enchantment, Integer> loadEnchantments(String input, String iconName, String menuFileName, ErrorLogger errorLogger) {
|
public static Map<Enchantment, Integer> loadEnchantments(String input, String iconName, String menuFileName, ErrorLogger errorLogger) {
|
||||||
Map<Enchantment, Integer> output = new HashMap<Enchantment, Integer>();
|
Map<Enchantment, Integer> output = new HashMap<Enchantment, Integer>();
|
||||||
|
|
||||||
if (input == null || input.isEmpty()) {
|
if (input == null || input.isEmpty()) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String singleEnchant : input.split(";")) {
|
for (String singleEnchant : input.split(";")) {
|
||||||
|
|
||||||
int level = 1;
|
int level = 1;
|
||||||
|
|
||||||
if (singleEnchant.contains(",")) {
|
if (singleEnchant.contains(",")) {
|
||||||
String[] levelSplit = singleEnchant.split(",");
|
String[] levelSplit = singleEnchant.split(",");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
level = Integer.parseInt(levelSplit[1].trim());
|
level = Integer.parseInt(levelSplit[1].trim());
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid enchantment level: " + levelSplit[1]);
|
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid enchantment level: " + levelSplit[1]);
|
||||||
}
|
}
|
||||||
singleEnchant = levelSplit[0];
|
singleEnchant = levelSplit[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
Enchantment ench = matchEnchantment(singleEnchant);
|
Enchantment ench = matchEnchantment(singleEnchant);
|
||||||
|
|
||||||
if (ench == null) {
|
if (ench == null) {
|
||||||
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid enchantment: " + singleEnchant);
|
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid enchantment: " + singleEnchant);
|
||||||
} else {
|
} else {
|
||||||
output.put(ench, level);
|
output.put(ench, level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Enchantment matchEnchantment(String input) {
|
public static Enchantment matchEnchantment(String input) {
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return enchantmentsMap.get(formatLowercase(input));
|
return enchantmentsMap.get(formatLowercase(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,242 +1,242 @@
|
||||||
package com.gmail.filoghost.chestcommands.serializer;
|
package com.gmail.filoghost.chestcommands.serializer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.api.Icon;
|
import com.gmail.filoghost.chestcommands.api.Icon;
|
||||||
import com.gmail.filoghost.chestcommands.config.AsciiPlaceholders;
|
import com.gmail.filoghost.chestcommands.config.AsciiPlaceholders;
|
||||||
import com.gmail.filoghost.chestcommands.exception.FormatException;
|
import com.gmail.filoghost.chestcommands.exception.FormatException;
|
||||||
import com.gmail.filoghost.chestcommands.internal.CommandsClickHandler;
|
import com.gmail.filoghost.chestcommands.internal.CommandsClickHandler;
|
||||||
import com.gmail.filoghost.chestcommands.internal.RequiredItem;
|
import com.gmail.filoghost.chestcommands.internal.RequiredItem;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.ExtendedIcon;
|
import com.gmail.filoghost.chestcommands.internal.icon.ExtendedIcon;
|
||||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||||
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
||||||
import com.gmail.filoghost.chestcommands.util.ItemStackReader;
|
import com.gmail.filoghost.chestcommands.util.ItemStackReader;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
import com.gmail.filoghost.chestcommands.util.Validate;
|
import com.gmail.filoghost.chestcommands.util.Validate;
|
||||||
|
|
||||||
public class IconSerializer {
|
public class IconSerializer {
|
||||||
|
|
||||||
private static class Nodes {
|
private static class Nodes {
|
||||||
|
|
||||||
public static final
|
public static final
|
||||||
String ID = "ID",
|
String ID = "ID",
|
||||||
DATA_VALUE = "DATA-VALUE",
|
DATA_VALUE = "DATA-VALUE",
|
||||||
AMOUNT = "AMOUNT",
|
AMOUNT = "AMOUNT",
|
||||||
NAME = "NAME",
|
NAME = "NAME",
|
||||||
LORE = "LORE",
|
LORE = "LORE",
|
||||||
ENCHANT = "ENCHANTMENT",
|
ENCHANT = "ENCHANTMENT",
|
||||||
COLOR = "COLOR",
|
COLOR = "COLOR",
|
||||||
SKULL_OWNER = "SKULL-OWNER",
|
SKULL_OWNER = "SKULL-OWNER",
|
||||||
COMMAND = "COMMAND",
|
COMMAND = "COMMAND",
|
||||||
PRICE = "PRICE",
|
PRICE = "PRICE",
|
||||||
POINTS = "POINTS",
|
POINTS = "POINTS",
|
||||||
EXP_LEVELS = "LEVELS",
|
EXP_LEVELS = "LEVELS",
|
||||||
REQUIRED_ITEM = "REQUIRED-ITEM",
|
REQUIRED_ITEM = "REQUIRED-ITEM",
|
||||||
PERMISSION = "PERMISSION",
|
PERMISSION = "PERMISSION",
|
||||||
PERMISSION_MESSAGE = "PERMISSION-MESSAGE",
|
PERMISSION_MESSAGE = "PERMISSION-MESSAGE",
|
||||||
VIEW_PERMISSION = "VIEW-PERMISSION",
|
VIEW_PERMISSION = "VIEW-PERMISSION",
|
||||||
KEEP_OPEN = "KEEP-OPEN",
|
KEEP_OPEN = "KEEP-OPEN",
|
||||||
POSITION_X = "POSITION-X",
|
POSITION_X = "POSITION-X",
|
||||||
POSITION_Y = "POSITION-Y";
|
POSITION_Y = "POSITION-Y";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Coords {
|
public static class Coords {
|
||||||
|
|
||||||
private Integer x, y;
|
private Integer x, y;
|
||||||
|
|
||||||
protected Coords(Integer x, Integer y) {
|
protected Coords(Integer x, Integer y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSetX() {
|
public boolean isSetX() {
|
||||||
return x != null;
|
return x != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSetY() {
|
public boolean isSetY() {
|
||||||
return y != null;
|
return y != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getX() {
|
public Integer getX() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getY() {
|
public Integer getY() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Icon loadIconFromSection(ConfigurationSection section, String iconName, String menuFileName, ErrorLogger errorLogger) {
|
public static Icon loadIconFromSection(ConfigurationSection section, String iconName, String menuFileName, ErrorLogger errorLogger) {
|
||||||
Validate.notNull(section, "ConfigurationSection cannot be null");
|
Validate.notNull(section, "ConfigurationSection cannot be null");
|
||||||
|
|
||||||
// The icon is valid even without a Material.
|
// The icon is valid even without a Material.
|
||||||
ExtendedIcon icon = new ExtendedIcon();
|
ExtendedIcon icon = new ExtendedIcon();
|
||||||
|
|
||||||
if (section.isSet(Nodes.ID)) {
|
if (section.isSet(Nodes.ID)) {
|
||||||
try {
|
try {
|
||||||
ItemStackReader itemReader = new ItemStackReader(section.getString(Nodes.ID), true);
|
ItemStackReader itemReader = new ItemStackReader(section.getString(Nodes.ID), true);
|
||||||
icon.setMaterial(itemReader.getMaterial());
|
icon.setMaterial(itemReader.getMaterial());
|
||||||
icon.setDataValue(itemReader.getDataValue());
|
icon.setDataValue(itemReader.getDataValue());
|
||||||
icon.setAmount(itemReader.getAmount());
|
icon.setAmount(itemReader.getAmount());
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid ID: " + e.getMessage());
|
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid ID: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section.isSet(Nodes.DATA_VALUE)) {
|
if (section.isSet(Nodes.DATA_VALUE)) {
|
||||||
icon.setDataValue((short) section.getInt(Nodes.DATA_VALUE));
|
icon.setDataValue((short) section.getInt(Nodes.DATA_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section.isSet(Nodes.AMOUNT)) {
|
if (section.isSet(Nodes.AMOUNT)) {
|
||||||
icon.setAmount(section.getInt(Nodes.AMOUNT));
|
icon.setAmount(section.getInt(Nodes.AMOUNT));
|
||||||
}
|
}
|
||||||
|
|
||||||
icon.setName(AsciiPlaceholders.placeholdersToSymbols(Utils.colorizeName(section.getString(Nodes.NAME))));
|
icon.setName(AsciiPlaceholders.placeholdersToSymbols(Utils.colorizeName(section.getString(Nodes.NAME))));
|
||||||
icon.setLore(AsciiPlaceholders.placeholdersToSymbols(Utils.colorizeLore(section.getStringList(Nodes.LORE))));
|
icon.setLore(AsciiPlaceholders.placeholdersToSymbols(Utils.colorizeLore(section.getStringList(Nodes.LORE))));
|
||||||
|
|
||||||
if (section.isSet(Nodes.ENCHANT)) {
|
if (section.isSet(Nodes.ENCHANT)) {
|
||||||
icon.setEnchantments(EnchantmentSerializer.loadEnchantments(section.getString(Nodes.ENCHANT), iconName, menuFileName, errorLogger));
|
icon.setEnchantments(EnchantmentSerializer.loadEnchantments(section.getString(Nodes.ENCHANT), iconName, menuFileName, errorLogger));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section.isSet(Nodes.COLOR)) {
|
if (section.isSet(Nodes.COLOR)) {
|
||||||
try {
|
try {
|
||||||
icon.setColor(Utils.parseColor(section.getString(Nodes.COLOR)));
|
icon.setColor(Utils.parseColor(section.getString(Nodes.COLOR)));
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid COLOR: " + e.getMessage());
|
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid COLOR: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
icon.setSkullOwner(section.getString(Nodes.SKULL_OWNER));
|
icon.setSkullOwner(section.getString(Nodes.SKULL_OWNER));
|
||||||
|
|
||||||
icon.setPermission(section.getString(Nodes.PERMISSION));
|
icon.setPermission(section.getString(Nodes.PERMISSION));
|
||||||
icon.setPermissionMessage(Utils.addColors(section.getString(Nodes.PERMISSION_MESSAGE)));
|
icon.setPermissionMessage(Utils.addColors(section.getString(Nodes.PERMISSION_MESSAGE)));
|
||||||
icon.setViewPermission(section.getString(Nodes.VIEW_PERMISSION));
|
icon.setViewPermission(section.getString(Nodes.VIEW_PERMISSION));
|
||||||
|
|
||||||
boolean closeOnClick = !section.getBoolean(Nodes.KEEP_OPEN);
|
boolean closeOnClick = !section.getBoolean(Nodes.KEEP_OPEN);
|
||||||
icon.setCloseOnClick(closeOnClick);
|
icon.setCloseOnClick(closeOnClick);
|
||||||
|
|
||||||
if (section.isSet(Nodes.COMMAND)) {
|
if (section.isSet(Nodes.COMMAND)) {
|
||||||
|
|
||||||
List<IconCommand> commands;
|
List<IconCommand> commands;
|
||||||
|
|
||||||
if (section.isList(Nodes.COMMAND)) {
|
if (section.isList(Nodes.COMMAND)) {
|
||||||
commands = Utils.newArrayList();
|
commands = Utils.newArrayList();
|
||||||
|
|
||||||
for (String commandString : section.getStringList(Nodes.COMMAND)) {
|
for (String commandString : section.getStringList(Nodes.COMMAND)) {
|
||||||
if (commandString.isEmpty()) {
|
if (commandString.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
commands.add(CommandSerializer.matchCommand(commandString));
|
commands.add(CommandSerializer.matchCommand(commandString));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
commands = CommandSerializer.readCommands(section.getString(Nodes.COMMAND));
|
commands = CommandSerializer.readCommands(section.getString(Nodes.COMMAND));
|
||||||
}
|
}
|
||||||
|
|
||||||
icon.setClickHandler(new CommandsClickHandler(commands, closeOnClick));
|
icon.setClickHandler(new CommandsClickHandler(commands, closeOnClick));
|
||||||
}
|
}
|
||||||
|
|
||||||
double price = section.getDouble(Nodes.PRICE);
|
double price = section.getDouble(Nodes.PRICE);
|
||||||
if (price > 0.0) {
|
if (price > 0.0) {
|
||||||
icon.setMoneyPrice(price);
|
icon.setMoneyPrice(price);
|
||||||
} else if (price < 0.0) {
|
} else if (price < 0.0) {
|
||||||
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has a negative PRICE: " + price);
|
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has a negative PRICE: " + price);
|
||||||
}
|
}
|
||||||
|
|
||||||
int points = section.getInt(Nodes.POINTS);
|
int points = section.getInt(Nodes.POINTS);
|
||||||
if (points > 0) {
|
if (points > 0) {
|
||||||
icon.setPlayerPointsPrice(points);
|
icon.setPlayerPointsPrice(points);
|
||||||
} else if (points < 0) {
|
} else if (points < 0) {
|
||||||
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has negative POINTS: " + points);
|
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has negative POINTS: " + points);
|
||||||
}
|
}
|
||||||
|
|
||||||
int levels = section.getInt(Nodes.EXP_LEVELS);
|
int levels = section.getInt(Nodes.EXP_LEVELS);
|
||||||
if (levels > 0) {
|
if (levels > 0) {
|
||||||
icon.setExpLevelsPrice(levels);
|
icon.setExpLevelsPrice(levels);
|
||||||
} else if (levels < 0) {
|
} else if (levels < 0) {
|
||||||
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has negative LEVELS: " + levels);
|
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has negative LEVELS: " + levels);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section.isSet(Nodes.REQUIRED_ITEM)) {
|
if (section.isSet(Nodes.REQUIRED_ITEM)) {
|
||||||
try {
|
try {
|
||||||
ItemStackReader itemReader = new ItemStackReader(section.getString(Nodes.REQUIRED_ITEM), true);
|
ItemStackReader itemReader = new ItemStackReader(section.getString(Nodes.REQUIRED_ITEM), true);
|
||||||
RequiredItem requiredItem = new RequiredItem(itemReader.getMaterial(), itemReader.getAmount());
|
RequiredItem requiredItem = new RequiredItem(itemReader.getMaterial(), itemReader.getAmount());
|
||||||
if (itemReader.hasExplicitDataValue()) {
|
if (itemReader.hasExplicitDataValue()) {
|
||||||
requiredItem.setRestrictiveDataValue(itemReader.getDataValue());
|
requiredItem.setRestrictiveDataValue(itemReader.getDataValue());
|
||||||
}
|
}
|
||||||
icon.setRequiredItem(requiredItem);
|
icon.setRequiredItem(requiredItem);
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid REQUIRED-ITEM: " + e.getMessage());
|
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid REQUIRED-ITEM: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Coords loadCoordsFromSection(ConfigurationSection section) {
|
public static Coords loadCoordsFromSection(ConfigurationSection section) {
|
||||||
Validate.notNull(section, "ConfigurationSection cannot be null");
|
Validate.notNull(section, "ConfigurationSection cannot be null");
|
||||||
|
|
||||||
Integer x = null;
|
Integer x = null;
|
||||||
Integer y = null;
|
Integer y = null;
|
||||||
|
|
||||||
if (section.isInt(Nodes.POSITION_X)) {
|
if (section.isInt(Nodes.POSITION_X)) {
|
||||||
x = section.getInt(Nodes.POSITION_X);
|
x = section.getInt(Nodes.POSITION_X);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section.isInt(Nodes.POSITION_Y)) {
|
if (section.isInt(Nodes.POSITION_Y)) {
|
||||||
y = section.getInt(Nodes.POSITION_Y);
|
y = section.getInt(Nodes.POSITION_Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Coords(x, y);
|
return new Coords(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * Reads a list of strings or a single String as list.
|
// * Reads a list of strings or a single String as list.
|
||||||
// */
|
// */
|
||||||
// private static List<String> readAsList(ConfigurationSection section, String node) {
|
// private static List<String> readAsList(ConfigurationSection section, String node) {
|
||||||
// if (section.isList(node)) {
|
// if (section.isList(node)) {
|
||||||
// return section.getStringList(node);
|
// return section.getStringList(node);
|
||||||
// } else if (section.isString(node)) {
|
// } else if (section.isString(node)) {
|
||||||
// return Arrays.asList(section.getString(node));
|
// return Arrays.asList(section.getString(node));
|
||||||
// } else {
|
// } else {
|
||||||
// return null;
|
// return null;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static void saveToSection(Icon icon, ConfigurationSection section) {
|
public static void saveToSection(Icon icon, ConfigurationSection section) {
|
||||||
Validate.notNull(icon, "Icon cannot be null");
|
Validate.notNull(icon, "Icon cannot be null");
|
||||||
Validate.notNull(section, "ConfigurationSection cannot be null");
|
Validate.notNull(section, "ConfigurationSection cannot be null");
|
||||||
|
|
||||||
section.set(Nodes.ID, serializeIconID(icon));
|
section.set(Nodes.ID, serializeIconID(icon));
|
||||||
|
|
||||||
if (icon.getEnchantments().size() > 0) {
|
if (icon.getEnchantments().size() > 0) {
|
||||||
section.set(Nodes.ENCHANT, 1);
|
section.set(Nodes.ENCHANT, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO not finished
|
//TODO not finished
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String serializeIconID(Icon icon) {
|
public static String serializeIconID(Icon icon) {
|
||||||
if (icon.getMaterial() == null) {
|
if (icon.getMaterial() == null) {
|
||||||
return "Not set";
|
return "Not set";
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder output = new StringBuilder();
|
StringBuilder output = new StringBuilder();
|
||||||
output.append(Utils.formatMaterial(icon.getMaterial()));
|
output.append(Utils.formatMaterial(icon.getMaterial()));
|
||||||
|
|
||||||
if (icon.getDataValue() > 0) {
|
if (icon.getDataValue() > 0) {
|
||||||
output.append(":");
|
output.append(":");
|
||||||
output.append(icon.getDataValue());
|
output.append(icon.getDataValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (icon.getAmount() != 1) {
|
if (icon.getAmount() != 1) {
|
||||||
output.append(", ");
|
output.append(", ");
|
||||||
output.append(icon.getAmount());
|
output.append(icon.getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
return output.toString();
|
return output.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,133 +1,133 @@
|
||||||
package com.gmail.filoghost.chestcommands.serializer;
|
package com.gmail.filoghost.chestcommands.serializer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.api.Icon;
|
import com.gmail.filoghost.chestcommands.api.Icon;
|
||||||
import com.gmail.filoghost.chestcommands.config.yaml.PluginConfig;
|
import com.gmail.filoghost.chestcommands.config.yaml.PluginConfig;
|
||||||
import com.gmail.filoghost.chestcommands.exception.FormatException;
|
import com.gmail.filoghost.chestcommands.exception.FormatException;
|
||||||
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
||||||
import com.gmail.filoghost.chestcommands.internal.MenuData;
|
import com.gmail.filoghost.chestcommands.internal.MenuData;
|
||||||
import com.gmail.filoghost.chestcommands.serializer.IconSerializer.Coords;
|
import com.gmail.filoghost.chestcommands.serializer.IconSerializer.Coords;
|
||||||
import com.gmail.filoghost.chestcommands.util.ClickType;
|
import com.gmail.filoghost.chestcommands.util.ClickType;
|
||||||
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
||||||
import com.gmail.filoghost.chestcommands.util.ItemStackReader;
|
import com.gmail.filoghost.chestcommands.util.ItemStackReader;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class MenuSerializer {
|
public class MenuSerializer {
|
||||||
|
|
||||||
private static class Nodes {
|
private static class Nodes {
|
||||||
|
|
||||||
public static final String MENU_NAME = "menu-settings.name";
|
public static final String MENU_NAME = "menu-settings.name";
|
||||||
public static final String MENU_ROWS = "menu-settings.rows";
|
public static final String MENU_ROWS = "menu-settings.rows";
|
||||||
public static final String MENU_COMMAND = "menu-settings.command";
|
public static final String MENU_COMMAND = "menu-settings.command";
|
||||||
|
|
||||||
public static final String OPEN_ACTION = "menu-settings.open-action";
|
public static final String OPEN_ACTION = "menu-settings.open-action";
|
||||||
|
|
||||||
public static final String OPEN_ITEM_MATERIAL = "menu-settings.open-with-item.id";
|
public static final String OPEN_ITEM_MATERIAL = "menu-settings.open-with-item.id";
|
||||||
public static final String OPEN_ITEM_LEFT_CLICK = "menu-settings.open-with-item.left-click";
|
public static final String OPEN_ITEM_LEFT_CLICK = "menu-settings.open-with-item.left-click";
|
||||||
public static final String OPEN_ITEM_RIGHT_CLICK = "menu-settings.open-with-item.right-click";
|
public static final String OPEN_ITEM_RIGHT_CLICK = "menu-settings.open-with-item.right-click";
|
||||||
|
|
||||||
public static final String AUTO_REFRESH = "menu-settings.auto-refresh";
|
public static final String AUTO_REFRESH = "menu-settings.auto-refresh";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExtendedIconMenu loadMenu(PluginConfig config, String title, int rows, ErrorLogger errorLogger) {
|
public static ExtendedIconMenu loadMenu(PluginConfig config, String title, int rows, ErrorLogger errorLogger) {
|
||||||
ExtendedIconMenu iconMenu = new ExtendedIconMenu(title, rows, config.getFileName());
|
ExtendedIconMenu iconMenu = new ExtendedIconMenu(title, rows, config.getFileName());
|
||||||
|
|
||||||
for (String subSectionName : config.getKeys(false)) {
|
for (String subSectionName : config.getKeys(false)) {
|
||||||
if (subSectionName.equals("menu-settings")) {
|
if (subSectionName.equals("menu-settings")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigurationSection iconSection = config.getConfigurationSection(subSectionName);
|
ConfigurationSection iconSection = config.getConfigurationSection(subSectionName);
|
||||||
|
|
||||||
Icon icon = IconSerializer.loadIconFromSection(iconSection, subSectionName, config.getFileName(), errorLogger);
|
Icon icon = IconSerializer.loadIconFromSection(iconSection, subSectionName, config.getFileName(), errorLogger);
|
||||||
Coords coords = IconSerializer.loadCoordsFromSection(iconSection);
|
Coords coords = IconSerializer.loadCoordsFromSection(iconSection);
|
||||||
|
|
||||||
if (!coords.isSetX() || !coords.isSetY()) {
|
if (!coords.isSetX() || !coords.isSetY()) {
|
||||||
errorLogger.addError("The icon \"" + subSectionName + "\" in the menu \"" + config.getFileName() + " is missing POSITION-X and/or POSITION-Y.");
|
errorLogger.addError("The icon \"" + subSectionName + "\" in the menu \"" + config.getFileName() + " is missing POSITION-X and/or POSITION-Y.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iconMenu.getIcon(coords.getX(), coords.getY()) != null) {
|
if (iconMenu.getIcon(coords.getX(), coords.getY()) != null) {
|
||||||
errorLogger.addError("The icon \"" + subSectionName + "\" in the menu \"" + config.getFileName() + " is overriding another icon with the same position.");
|
errorLogger.addError("The icon \"" + subSectionName + "\" in the menu \"" + config.getFileName() + " is overriding another icon with the same position.");
|
||||||
}
|
}
|
||||||
|
|
||||||
iconMenu.setIcon(coords.getX(), coords.getY(), icon);
|
iconMenu.setIcon(coords.getX(), coords.getY(), icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
return iconMenu;
|
return iconMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads all the settings of a menu. It will never return a null title, even if not set.
|
* Reads all the settings of a menu. It will never return a null title, even if not set.
|
||||||
*/
|
*/
|
||||||
public static MenuData loadMenuData(PluginConfig config, ErrorLogger errorLogger) {
|
public static MenuData loadMenuData(PluginConfig config, ErrorLogger errorLogger) {
|
||||||
|
|
||||||
String title = Utils.addColors(config.getString(Nodes.MENU_NAME));
|
String title = Utils.addColors(config.getString(Nodes.MENU_NAME));
|
||||||
int rows;
|
int rows;
|
||||||
|
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
errorLogger.addError("The menu \"" + config.getFileName() + "\" doesn't have a name set.");
|
errorLogger.addError("The menu \"" + config.getFileName() + "\" doesn't have a name set.");
|
||||||
title = ChatColor.DARK_RED + "No title set";
|
title = ChatColor.DARK_RED + "No title set";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (title.length() > 32) {
|
if (title.length() > 32) {
|
||||||
title = title.substring(0, 32);
|
title = title.substring(0, 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.isInt(Nodes.MENU_ROWS)) {
|
if (config.isInt(Nodes.MENU_ROWS)) {
|
||||||
rows = config.getInt(Nodes.MENU_ROWS);
|
rows = config.getInt(Nodes.MENU_ROWS);
|
||||||
|
|
||||||
if (rows <= 0) {
|
if (rows <= 0) {
|
||||||
rows = 1;
|
rows = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
rows = 6; // Defaults to 6 rows.
|
rows = 6; // Defaults to 6 rows.
|
||||||
errorLogger.addError("The menu \"" + config.getFileName() + "\" doesn't have a the number of rows set, it will have 6 rows by default.");
|
errorLogger.addError("The menu \"" + config.getFileName() + "\" doesn't have a the number of rows set, it will have 6 rows by default.");
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuData menuData = new MenuData(title, rows);
|
MenuData menuData = new MenuData(title, rows);
|
||||||
|
|
||||||
if (config.isSet(Nodes.MENU_COMMAND)) {
|
if (config.isSet(Nodes.MENU_COMMAND)) {
|
||||||
menuData.setCommands(config.getString(Nodes.MENU_COMMAND).replace(" ", "").split(";"));
|
menuData.setCommands(config.getString(Nodes.MENU_COMMAND).replace(" ", "").split(";"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.isSet(Nodes.OPEN_ACTION)) {
|
if (config.isSet(Nodes.OPEN_ACTION)) {
|
||||||
menuData.setOpenActions(CommandSerializer.readCommands(config.getString(Nodes.OPEN_ACTION)));
|
menuData.setOpenActions(CommandSerializer.readCommands(config.getString(Nodes.OPEN_ACTION)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.isSet(Nodes.OPEN_ITEM_MATERIAL)) {
|
if (config.isSet(Nodes.OPEN_ITEM_MATERIAL)) {
|
||||||
try {
|
try {
|
||||||
ItemStackReader itemReader = new ItemStackReader(config.getString(Nodes.OPEN_ITEM_MATERIAL), false);
|
ItemStackReader itemReader = new ItemStackReader(config.getString(Nodes.OPEN_ITEM_MATERIAL), false);
|
||||||
menuData.setBoundMaterial(itemReader.getMaterial());
|
menuData.setBoundMaterial(itemReader.getMaterial());
|
||||||
|
|
||||||
if (itemReader.hasExplicitDataValue()) {
|
if (itemReader.hasExplicitDataValue()) {
|
||||||
menuData.setBoundDataValue(itemReader.getDataValue());
|
menuData.setBoundDataValue(itemReader.getDataValue());
|
||||||
}
|
}
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
errorLogger.addError("The item \""+ config.getString(Nodes.OPEN_ITEM_MATERIAL) + "\" used to open the menu \"" + config.getFileName() + "\" is invalid: " + e.getMessage());
|
errorLogger.addError("The item \""+ config.getString(Nodes.OPEN_ITEM_MATERIAL) + "\" used to open the menu \"" + config.getFileName() + "\" is invalid: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean leftClick = config.getBoolean(Nodes.OPEN_ITEM_LEFT_CLICK);
|
boolean leftClick = config.getBoolean(Nodes.OPEN_ITEM_LEFT_CLICK);
|
||||||
boolean rightClick = config.getBoolean(Nodes.OPEN_ITEM_RIGHT_CLICK);
|
boolean rightClick = config.getBoolean(Nodes.OPEN_ITEM_RIGHT_CLICK);
|
||||||
|
|
||||||
if (leftClick || rightClick) {
|
if (leftClick || rightClick) {
|
||||||
menuData.setClickType(ClickType.fromOptions(leftClick, rightClick));
|
menuData.setClickType(ClickType.fromOptions(leftClick, rightClick));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.isSet(Nodes.AUTO_REFRESH)) {
|
if (config.isSet(Nodes.AUTO_REFRESH)) {
|
||||||
int tenthsToRefresh = (int) (config.getDouble(Nodes.AUTO_REFRESH) * 10.0);
|
int tenthsToRefresh = (int) (config.getDouble(Nodes.AUTO_REFRESH) * 10.0);
|
||||||
if (tenthsToRefresh < 1) {
|
if (tenthsToRefresh < 1) {
|
||||||
tenthsToRefresh = 1;
|
tenthsToRefresh = 1;
|
||||||
}
|
}
|
||||||
menuData.setRefreshTenths(tenthsToRefresh);
|
menuData.setRefreshTenths(tenthsToRefresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
return menuData;
|
return menuData;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,42 +1,42 @@
|
||||||
package com.gmail.filoghost.chestcommands.task;
|
package com.gmail.filoghost.chestcommands.task;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
import com.gmail.filoghost.chestcommands.util.ErrorLogger;
|
||||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||||
|
|
||||||
public class ErrorLoggerTask implements Runnable {
|
public class ErrorLoggerTask implements Runnable {
|
||||||
|
|
||||||
private ErrorLogger errorLogger;
|
private ErrorLogger errorLogger;
|
||||||
|
|
||||||
public ErrorLoggerTask(ErrorLogger errorLogger) {
|
public ErrorLoggerTask(ErrorLogger errorLogger) {
|
||||||
this.errorLogger = errorLogger;
|
this.errorLogger = errorLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
List<String> lines = Utils.newArrayList();
|
List<String> lines = Utils.newArrayList();
|
||||||
|
|
||||||
lines.add(" ");
|
lines.add(" ");
|
||||||
lines.add(ChatColor.RED + "#------------------- Chest Commands Errors -------------------#");
|
lines.add(ChatColor.RED + "#------------------- Chest Commands Errors -------------------#");
|
||||||
int count = 1;
|
int count = 1;
|
||||||
for (String error : errorLogger.getErrors()) {
|
for (String error : errorLogger.getErrors()) {
|
||||||
lines.add(ChatColor.GRAY + "" + (count++) + ") " + ChatColor.WHITE + error);
|
lines.add(ChatColor.GRAY + "" + (count++) + ") " + ChatColor.WHITE + error);
|
||||||
}
|
}
|
||||||
lines.add(ChatColor.RED + "#-------------------------------------------------------------#");
|
lines.add(ChatColor.RED + "#-------------------------------------------------------------#");
|
||||||
|
|
||||||
String output = Utils.join(lines, "\n");
|
String output = Utils.join(lines, "\n");
|
||||||
|
|
||||||
if (ChestCommands.getSettings().use_console_colors) {
|
if (ChestCommands.getSettings().use_console_colors) {
|
||||||
Bukkit.getConsoleSender().sendMessage(output);
|
Bukkit.getConsoleSender().sendMessage(output);
|
||||||
} else {
|
} else {
|
||||||
System.out.println(ChatColor.stripColor(output));
|
System.out.println(ChatColor.stripColor(output));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,29 +1,29 @@
|
||||||
package com.gmail.filoghost.chestcommands.task;
|
package com.gmail.filoghost.chestcommands.task;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.api.Icon;
|
import com.gmail.filoghost.chestcommands.api.Icon;
|
||||||
|
|
||||||
public class ExecuteCommandsTask implements Runnable {
|
public class ExecuteCommandsTask implements Runnable {
|
||||||
|
|
||||||
private Player player;
|
private Player player;
|
||||||
private Icon icon;
|
private Icon icon;
|
||||||
|
|
||||||
|
|
||||||
public ExecuteCommandsTask(Player player, Icon icon) {
|
public ExecuteCommandsTask(Player player, Icon icon) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean close = icon.onClick(player);
|
boolean close = icon.onClick(player);
|
||||||
|
|
||||||
if (close) {
|
if (close) {
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,44 +1,44 @@
|
||||||
package com.gmail.filoghost.chestcommands.task;
|
package com.gmail.filoghost.chestcommands.task;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryView;
|
import org.bukkit.inventory.InventoryView;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
||||||
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
|
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
|
||||||
import com.gmail.filoghost.chestcommands.util.VersionUtils;
|
import com.gmail.filoghost.chestcommands.util.VersionUtils;
|
||||||
|
|
||||||
public class RefreshMenusTask implements Runnable {
|
public class RefreshMenusTask implements Runnable {
|
||||||
|
|
||||||
private long elapsedTenths;
|
private long elapsedTenths;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
for (Player player : VersionUtils.getOnlinePlayers()) {
|
for (Player player : VersionUtils.getOnlinePlayers()) {
|
||||||
|
|
||||||
InventoryView view = player.getOpenInventory();
|
InventoryView view = player.getOpenInventory();
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Inventory topInventory = view.getTopInventory();
|
Inventory topInventory = view.getTopInventory();
|
||||||
if (topInventory.getHolder() instanceof MenuInventoryHolder) {
|
if (topInventory.getHolder() instanceof MenuInventoryHolder) {
|
||||||
MenuInventoryHolder menuHolder = (MenuInventoryHolder) topInventory.getHolder();
|
MenuInventoryHolder menuHolder = (MenuInventoryHolder) topInventory.getHolder();
|
||||||
|
|
||||||
if (menuHolder.getIconMenu() instanceof ExtendedIconMenu) {
|
if (menuHolder.getIconMenu() instanceof ExtendedIconMenu) {
|
||||||
ExtendedIconMenu extMenu = (ExtendedIconMenu) menuHolder.getIconMenu();
|
ExtendedIconMenu extMenu = (ExtendedIconMenu) menuHolder.getIconMenu();
|
||||||
|
|
||||||
if (extMenu.getRefreshTicks() > 0) {
|
if (extMenu.getRefreshTicks() > 0) {
|
||||||
if (elapsedTenths % extMenu.getRefreshTicks() == 0) {
|
if (elapsedTenths % extMenu.getRefreshTicks() == 0) {
|
||||||
extMenu.refresh(player, topInventory);
|
extMenu.refresh(player, topInventory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
elapsedTenths++;
|
elapsedTenths++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,49 +1,49 @@
|
||||||
package com.gmail.filoghost.chestcommands.util;
|
package com.gmail.filoghost.chestcommands.util;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class CaseInsensitiveMap<V> extends HashMap<String, V> {
|
public class CaseInsensitiveMap<V> extends HashMap<String, V> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 4712822893326841081L;
|
private static final long serialVersionUID = 4712822893326841081L;
|
||||||
|
|
||||||
public static <K> CaseInsensitiveMap<K> create() {
|
public static <K> CaseInsensitiveMap<K> create() {
|
||||||
return new CaseInsensitiveMap<K>();
|
return new CaseInsensitiveMap<K>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public V put(String key, V value) {
|
public V put(String key, V value) {
|
||||||
return super.put(key.toLowerCase(), value);
|
return super.put(key.toLowerCase(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public V get(Object key) {
|
public V get(Object key) {
|
||||||
return super.get(key.getClass() == String.class ? key.toString().toLowerCase() : key);
|
return super.get(key.getClass() == String.class ? key.toString().toLowerCase() : key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKey(V value) {
|
public String getKey(V value) {
|
||||||
for (java.util.Map.Entry<String, V> entry : entrySet()) {
|
for (java.util.Map.Entry<String, V> entry : entrySet()) {
|
||||||
if (entry.getValue().equals(value)) {
|
if (entry.getValue().equals(value)) {
|
||||||
return entry.getKey();
|
return entry.getKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsKey(Object key) {
|
public boolean containsKey(Object key) {
|
||||||
return super.containsKey(key.getClass() == String.class ? key.toString().toLowerCase() : key);
|
return super.containsKey(key.getClass() == String.class ? key.toString().toLowerCase() : key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public V remove(Object key) {
|
public V remove(Object key) {
|
||||||
return super.remove(key.getClass() == String.class ? key.toString().toLowerCase() : key);
|
return super.remove(key.getClass() == String.class ? key.toString().toLowerCase() : key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putAll(Map<? extends String, ? extends V> m) {
|
public void putAll(Map<? extends String, ? extends V> m) {
|
||||||
throw new UnsupportedOperationException("putAll not supported");
|
throw new UnsupportedOperationException("putAll not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,33 +1,33 @@
|
||||||
package com.gmail.filoghost.chestcommands.util;
|
package com.gmail.filoghost.chestcommands.util;
|
||||||
|
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
|
|
||||||
public enum ClickType {
|
public enum ClickType {
|
||||||
|
|
||||||
LEFT,
|
LEFT,
|
||||||
RIGHT,
|
RIGHT,
|
||||||
BOTH;
|
BOTH;
|
||||||
|
|
||||||
public static ClickType fromOptions(boolean left, boolean right) {
|
public static ClickType fromOptions(boolean left, boolean right) {
|
||||||
if (left && right) {
|
if (left && right) {
|
||||||
return BOTH;
|
return BOTH;
|
||||||
} else if (left && !right) {
|
} else if (left && !right) {
|
||||||
return LEFT;
|
return LEFT;
|
||||||
} else if (!left && right) {
|
} else if (!left && right) {
|
||||||
return RIGHT;
|
return RIGHT;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidInteract(Action action) {
|
public boolean isValidInteract(Action action) {
|
||||||
if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) {
|
if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) {
|
||||||
return this == LEFT || this == BOTH;
|
return this == LEFT || this == BOTH;
|
||||||
} else if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
|
} else if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
|
||||||
return this == RIGHT || this == BOTH;
|
return this == RIGHT || this == BOTH;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,29 +1,29 @@
|
||||||
package com.gmail.filoghost.chestcommands.util;
|
package com.gmail.filoghost.chestcommands.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a class to collect all the errors found while loading the plugin.
|
* This is a class to collect all the errors found while loading the plugin.
|
||||||
*/
|
*/
|
||||||
public class ErrorLogger {
|
public class ErrorLogger {
|
||||||
|
|
||||||
private List<String> errors = new ArrayList<String>();
|
private List<String> errors = new ArrayList<String>();
|
||||||
|
|
||||||
public void addError(String error) {
|
public void addError(String error) {
|
||||||
errors.add(error);
|
errors.add(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getErrors() {
|
public List<String> getErrors() {
|
||||||
return new ArrayList<String>(errors);
|
return new ArrayList<String>(errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasErrors() {
|
public boolean hasErrors() {
|
||||||
return errors.size() > 0;
|
return errors.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return errors.size();
|
return errors.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,38 +1,38 @@
|
||||||
package com.gmail.filoghost.chestcommands.util;
|
package com.gmail.filoghost.chestcommands.util;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class InventoryUtils {
|
public class InventoryUtils {
|
||||||
|
|
||||||
public static boolean hasInventoryFull(Player player) {
|
public static boolean hasInventoryFull(Player player) {
|
||||||
return player.getInventory().firstEmpty() == -1;
|
return player.getInventory().firstEmpty() == -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean containsAtLeast(Inventory inv, Material material, int minAmount) {
|
public static boolean containsAtLeast(Inventory inv, Material material, int minAmount) {
|
||||||
int contained = 0;
|
int contained = 0;
|
||||||
|
|
||||||
for (ItemStack item : inv.getContents()) {
|
for (ItemStack item : inv.getContents()) {
|
||||||
if (item != null && item.getType() == material) {
|
if (item != null && item.getType() == material) {
|
||||||
contained += item.getAmount();
|
contained += item.getAmount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return contained >= minAmount;
|
return contained >= minAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean containsAtLeast(Inventory inv, Material material, int minAmount, short data) {
|
public static boolean containsAtLeast(Inventory inv, Material material, int minAmount, short data) {
|
||||||
int contained = 0;
|
int contained = 0;
|
||||||
|
|
||||||
for (ItemStack item : inv.getContents()) {
|
for (ItemStack item : inv.getContents()) {
|
||||||
if (item != null && item.getType() == material && item.getDurability() == data) {
|
if (item != null && item.getType() == material && item.getDurability() == data) {
|
||||||
contained += item.getAmount();
|
contained += item.getAmount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return contained >= minAmount;
|
return contained >= minAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,95 +1,95 @@
|
||||||
package com.gmail.filoghost.chestcommands.util;
|
package com.gmail.filoghost.chestcommands.util;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.exception.FormatException;
|
import com.gmail.filoghost.chestcommands.exception.FormatException;
|
||||||
|
|
||||||
public class ItemStackReader {
|
public class ItemStackReader {
|
||||||
|
|
||||||
private Material material = Material.STONE; // In the worst case (bad exception handling) we just get stone.
|
private Material material = Material.STONE; // In the worst case (bad exception handling) we just get stone.
|
||||||
private int amount = 1;
|
private int amount = 1;
|
||||||
private short dataValue = 0;
|
private short dataValue = 0;
|
||||||
private boolean explicitDataValue = false;
|
private boolean explicitDataValue = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads item in the format "id:data, amount"
|
* Reads item in the format "id:data, amount"
|
||||||
* id can be either the id of the material or its name.
|
* id can be either the id of the material or its name.
|
||||||
* for example wool:5, 3 is a valid input.
|
* for example wool:5, 3 is a valid input.
|
||||||
*/
|
*/
|
||||||
public ItemStackReader(String input, boolean parseAmount) throws FormatException {
|
public ItemStackReader(String input, boolean parseAmount) throws FormatException {
|
||||||
Validate.notNull(input, "input cannot be null");
|
Validate.notNull(input, "input cannot be null");
|
||||||
|
|
||||||
// Remove spaces, they're not needed.
|
// Remove spaces, they're not needed.
|
||||||
input = StringUtils.stripChars(input, " _-");
|
input = StringUtils.stripChars(input, " _-");
|
||||||
|
|
||||||
if (parseAmount) {
|
if (parseAmount) {
|
||||||
// Read the optional amount.
|
// Read the optional amount.
|
||||||
String[] splitAmount = input.split(",");
|
String[] splitAmount = input.split(",");
|
||||||
|
|
||||||
if (splitAmount.length > 1) {
|
if (splitAmount.length > 1) {
|
||||||
|
|
||||||
if (!Utils.isValidInteger(splitAmount[1])) {
|
if (!Utils.isValidInteger(splitAmount[1])) {
|
||||||
throw new FormatException("invalid amount \"" + splitAmount[1] + "\"");
|
throw new FormatException("invalid amount \"" + splitAmount[1] + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
int amount = Integer.parseInt(splitAmount[1]);
|
int amount = Integer.parseInt(splitAmount[1]);
|
||||||
if (amount <= 0) throw new FormatException("invalid amount \"" + splitAmount[1] + "\"");
|
if (amount <= 0) throw new FormatException("invalid amount \"" + splitAmount[1] + "\"");
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
|
|
||||||
// Only keep the first part as input.
|
// Only keep the first part as input.
|
||||||
input = splitAmount[0];
|
input = splitAmount[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Read the optional data value.
|
// Read the optional data value.
|
||||||
String[] splitByColons = input.split(":");
|
String[] splitByColons = input.split(":");
|
||||||
|
|
||||||
if (splitByColons.length > 1) {
|
if (splitByColons.length > 1) {
|
||||||
|
|
||||||
if (!Utils.isValidShort(splitByColons[1])) {
|
if (!Utils.isValidShort(splitByColons[1])) {
|
||||||
throw new FormatException("invalid data value \"" + splitByColons[1] + "\"");
|
throw new FormatException("invalid data value \"" + splitByColons[1] + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
short dataValue = Short.parseShort(splitByColons[1]);
|
short dataValue = Short.parseShort(splitByColons[1]);
|
||||||
if (dataValue < 0) {
|
if (dataValue < 0) {
|
||||||
throw new FormatException("invalid data value \"" + splitByColons[1] + "\"");
|
throw new FormatException("invalid data value \"" + splitByColons[1] + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.explicitDataValue = true;
|
this.explicitDataValue = true;
|
||||||
this.dataValue = dataValue;
|
this.dataValue = dataValue;
|
||||||
|
|
||||||
// Only keep the first part as input.
|
// Only keep the first part as input.
|
||||||
input = splitByColons[0];
|
input = splitByColons[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
Material material = Utils.matchMaterial(input);
|
Material material = Utils.matchMaterial(input);
|
||||||
|
|
||||||
if (material == null || material == Material.AIR) {
|
if (material == null || material == Material.AIR) {
|
||||||
throw new FormatException("invalid material \"" + input + "\"");
|
throw new FormatException("invalid material \"" + input + "\"");
|
||||||
}
|
}
|
||||||
this.material = material;
|
this.material = material;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getMaterial() {
|
public Material getMaterial() {
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAmount() {
|
public int getAmount() {
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getDataValue() {
|
public short getDataValue() {
|
||||||
return dataValue;
|
return dataValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasExplicitDataValue() {
|
public boolean hasExplicitDataValue() {
|
||||||
return explicitDataValue;
|
return explicitDataValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack createStack() {
|
public ItemStack createStack() {
|
||||||
return new ItemStack(material, amount, dataValue);
|
return new ItemStack(material, amount, dataValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,88 +1,88 @@
|
||||||
package com.gmail.filoghost.chestcommands.util;
|
package com.gmail.filoghost.chestcommands.util;
|
||||||
|
|
||||||
public class StringUtils {
|
public class StringUtils {
|
||||||
|
|
||||||
public static String stripChars(String input, String removed) {
|
public static String stripChars(String input, String removed) {
|
||||||
if (removed == null || removed.isEmpty()) {
|
if (removed == null || removed.isEmpty()) {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
return stripChars(input, removed.toCharArray());
|
return stripChars(input, removed.toCharArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes the first slash, and returns the all the chars until a space is encontered.
|
// Removes the first slash, and returns the all the chars until a space is encontered.
|
||||||
public static String getCleanCommand(String message) {
|
public static String getCleanCommand(String message) {
|
||||||
char[] chars = message.toCharArray();
|
char[] chars = message.toCharArray();
|
||||||
|
|
||||||
if (chars.length <= 1) {
|
if (chars.length <= 1) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (int i = 1; i < chars.length; i++) {
|
for (int i = 1; i < chars.length; i++) {
|
||||||
if (chars[i] == ' ') {
|
if (chars[i] == ' ') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
chars[(pos++)] = chars[i];
|
chars[(pos++)] = chars[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return new String(chars, 0, pos);
|
return new String(chars, 0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String stripChars(String input, char... removed) {
|
public static String stripChars(String input, char... removed) {
|
||||||
if (input == null || input.isEmpty() || removed.length == 0) {
|
if (input == null || input.isEmpty() || removed.length == 0) {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
char[] chars = input.toCharArray();
|
char[] chars = input.toCharArray();
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (int i = 0; i < chars.length; i++) {
|
for (int i = 0; i < chars.length; i++) {
|
||||||
if (!arrayContains(removed, chars[i])) {
|
if (!arrayContains(removed, chars[i])) {
|
||||||
chars[(pos++)] = chars[i];
|
chars[(pos++)] = chars[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new String(chars, 0, pos);
|
return new String(chars, 0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean arrayContains(char[] arr, char match) {
|
private static boolean arrayContains(char[] arr, char match) {
|
||||||
for (char c : arr) {
|
for (char c : arr) {
|
||||||
if (c == match) {
|
if (c == match) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String capitalizeFully(String input) {
|
public static String capitalizeFully(String input) {
|
||||||
if (input == null) return null;
|
if (input == null) return null;
|
||||||
|
|
||||||
String s = input.toLowerCase();
|
String s = input.toLowerCase();
|
||||||
|
|
||||||
int strLen = s.length();
|
int strLen = s.length();
|
||||||
StringBuffer buffer = new StringBuffer(strLen);
|
StringBuffer buffer = new StringBuffer(strLen);
|
||||||
boolean capitalizeNext = true;
|
boolean capitalizeNext = true;
|
||||||
for (int i = 0; i < strLen; i++) {
|
for (int i = 0; i < strLen; i++) {
|
||||||
char ch = s.charAt(i);
|
char ch = s.charAt(i);
|
||||||
|
|
||||||
if (Character.isWhitespace(ch)) {
|
if (Character.isWhitespace(ch)) {
|
||||||
buffer.append(ch);
|
buffer.append(ch);
|
||||||
capitalizeNext = true;
|
capitalizeNext = true;
|
||||||
} else if (capitalizeNext) {
|
} else if (capitalizeNext) {
|
||||||
buffer.append(Character.toTitleCase(ch));
|
buffer.append(Character.toTitleCase(ch));
|
||||||
capitalizeNext = false;
|
capitalizeNext = false;
|
||||||
} else {
|
} else {
|
||||||
buffer.append(ch);
|
buffer.append(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNullOrEmpty(String s) {
|
public static boolean isNullOrEmpty(String s) {
|
||||||
return s == null || s.isEmpty();
|
return s == null || s.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,345 +1,345 @@
|
||||||
package com.gmail.filoghost.chestcommands.util;
|
package com.gmail.filoghost.chestcommands.util;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryView;
|
import org.bukkit.inventory.InventoryView;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.gmail.filoghost.chestcommands.ChestCommands;
|
import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||||
import com.gmail.filoghost.chestcommands.exception.FormatException;
|
import com.gmail.filoghost.chestcommands.exception.FormatException;
|
||||||
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
import com.gmail.filoghost.chestcommands.internal.ExtendedIconMenu;
|
||||||
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
|
import com.gmail.filoghost.chestcommands.internal.MenuInventoryHolder;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
// Default material names are ugly.
|
// Default material names are ugly.
|
||||||
private static Map<String, Material> materialMap = newHashMap();
|
private static Map<String, Material> materialMap = newHashMap();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (Material mat : Material.values()) {
|
for (Material mat : Material.values()) {
|
||||||
materialMap.put(StringUtils.stripChars(mat.toString(), "_").toLowerCase(), mat);
|
materialMap.put(StringUtils.stripChars(mat.toString(), "_").toLowerCase(), mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Material> tempMap = newHashMap();
|
Map<String, Material> tempMap = newHashMap();
|
||||||
|
|
||||||
tempMap.put("iron bar", Material.IRON_FENCE);
|
tempMap.put("iron bar", Material.IRON_FENCE);
|
||||||
tempMap.put("iron bars", Material.IRON_FENCE);
|
tempMap.put("iron bars", Material.IRON_FENCE);
|
||||||
tempMap.put("glass pane", Material.THIN_GLASS);
|
tempMap.put("glass pane", Material.THIN_GLASS);
|
||||||
tempMap.put("nether wart", Material.NETHER_STALK);
|
tempMap.put("nether wart", Material.NETHER_STALK);
|
||||||
tempMap.put("nether warts", Material.NETHER_STALK);
|
tempMap.put("nether warts", Material.NETHER_STALK);
|
||||||
tempMap.put("slab", Material.STEP);
|
tempMap.put("slab", Material.STEP);
|
||||||
tempMap.put("double slab", Material.DOUBLE_STEP);
|
tempMap.put("double slab", Material.DOUBLE_STEP);
|
||||||
tempMap.put("stone brick", Material.SMOOTH_BRICK);
|
tempMap.put("stone brick", Material.SMOOTH_BRICK);
|
||||||
tempMap.put("stone bricks", Material.SMOOTH_BRICK);
|
tempMap.put("stone bricks", Material.SMOOTH_BRICK);
|
||||||
tempMap.put("stone stair", Material.SMOOTH_STAIRS);
|
tempMap.put("stone stair", Material.SMOOTH_STAIRS);
|
||||||
tempMap.put("stone stairs", Material.SMOOTH_STAIRS);
|
tempMap.put("stone stairs", Material.SMOOTH_STAIRS);
|
||||||
tempMap.put("potato", Material.POTATO_ITEM);
|
tempMap.put("potato", Material.POTATO_ITEM);
|
||||||
tempMap.put("carrot", Material.CARROT_ITEM);
|
tempMap.put("carrot", Material.CARROT_ITEM);
|
||||||
tempMap.put("brewing stand", Material.BREWING_STAND_ITEM);
|
tempMap.put("brewing stand", Material.BREWING_STAND_ITEM);
|
||||||
tempMap.put("cauldron", Material.CAULDRON_ITEM);
|
tempMap.put("cauldron", Material.CAULDRON_ITEM);
|
||||||
tempMap.put("carrot on stick", Material.CARROT_STICK);
|
tempMap.put("carrot on stick", Material.CARROT_STICK);
|
||||||
tempMap.put("carrot on a stick", Material.CARROT_STICK);
|
tempMap.put("carrot on a stick", Material.CARROT_STICK);
|
||||||
tempMap.put("cobblestone wall", Material.COBBLE_WALL);
|
tempMap.put("cobblestone wall", Material.COBBLE_WALL);
|
||||||
// tempMap.put("acacia wood stairs", Material.ACACIA_STAIRS);
|
// tempMap.put("acacia wood stairs", Material.ACACIA_STAIRS);
|
||||||
// tempMap.put("dark oak wood stairs", Material.DARK_OAK_STAIRS);
|
// tempMap.put("dark oak wood stairs", Material.DARK_OAK_STAIRS);
|
||||||
tempMap.put("wood slab", Material.WOOD_STEP);
|
tempMap.put("wood slab", Material.WOOD_STEP);
|
||||||
tempMap.put("double wood slab", Material.WOOD_DOUBLE_STEP);
|
tempMap.put("double wood slab", Material.WOOD_DOUBLE_STEP);
|
||||||
tempMap.put("repeater", Material.DIODE);
|
tempMap.put("repeater", Material.DIODE);
|
||||||
tempMap.put("piston", Material.PISTON_BASE);
|
tempMap.put("piston", Material.PISTON_BASE);
|
||||||
tempMap.put("sticky piston", Material.PISTON_STICKY_BASE);
|
tempMap.put("sticky piston", Material.PISTON_STICKY_BASE);
|
||||||
tempMap.put("flower pot", Material.FLOWER_POT_ITEM);
|
tempMap.put("flower pot", Material.FLOWER_POT_ITEM);
|
||||||
tempMap.put("wood showel", Material.WOOD_SPADE);
|
tempMap.put("wood showel", Material.WOOD_SPADE);
|
||||||
tempMap.put("stone showel", Material.STONE_SPADE);
|
tempMap.put("stone showel", Material.STONE_SPADE);
|
||||||
tempMap.put("gold showel", Material.GOLD_SPADE);
|
tempMap.put("gold showel", Material.GOLD_SPADE);
|
||||||
tempMap.put("iron showel", Material.IRON_SPADE);
|
tempMap.put("iron showel", Material.IRON_SPADE);
|
||||||
tempMap.put("diamond showel", Material.DIAMOND_SPADE);
|
tempMap.put("diamond showel", Material.DIAMOND_SPADE);
|
||||||
tempMap.put("steak", Material.COOKED_BEEF);
|
tempMap.put("steak", Material.COOKED_BEEF);
|
||||||
tempMap.put("cooked porkchop", Material.GRILLED_PORK);
|
tempMap.put("cooked porkchop", Material.GRILLED_PORK);
|
||||||
tempMap.put("raw porkchop", Material.PORK);
|
tempMap.put("raw porkchop", Material.PORK);
|
||||||
tempMap.put("hardened clay", Material.HARD_CLAY);
|
tempMap.put("hardened clay", Material.HARD_CLAY);
|
||||||
tempMap.put("huge brown mushroom", Material.HUGE_MUSHROOM_1);
|
tempMap.put("huge brown mushroom", Material.HUGE_MUSHROOM_1);
|
||||||
tempMap.put("huge red mushroom", Material.HUGE_MUSHROOM_2);
|
tempMap.put("huge red mushroom", Material.HUGE_MUSHROOM_2);
|
||||||
tempMap.put("mycelium", Material.MYCEL);
|
tempMap.put("mycelium", Material.MYCEL);
|
||||||
tempMap.put("poppy", Material.RED_ROSE);
|
tempMap.put("poppy", Material.RED_ROSE);
|
||||||
tempMap.put("comparator", Material.REDSTONE_COMPARATOR);
|
tempMap.put("comparator", Material.REDSTONE_COMPARATOR);
|
||||||
tempMap.put("skull", Material.SKULL_ITEM);
|
tempMap.put("skull", Material.SKULL_ITEM);
|
||||||
tempMap.put("head", Material.SKULL_ITEM);
|
tempMap.put("head", Material.SKULL_ITEM);
|
||||||
tempMap.put("redstone torch", Material.REDSTONE_TORCH_ON);
|
tempMap.put("redstone torch", Material.REDSTONE_TORCH_ON);
|
||||||
tempMap.put("redstone lamp", Material.REDSTONE_LAMP_OFF);
|
tempMap.put("redstone lamp", Material.REDSTONE_LAMP_OFF);
|
||||||
tempMap.put("glistering melon", Material.SPECKLED_MELON);
|
tempMap.put("glistering melon", Material.SPECKLED_MELON);
|
||||||
// tempMap.put("acacia leaves", Material.LEAVES_2); It wouldn't work with 1.6 :/
|
// tempMap.put("acacia leaves", Material.LEAVES_2); It wouldn't work with 1.6 :/
|
||||||
// tempMap.put("acacia log", Material.LOG_2);
|
// tempMap.put("acacia log", Material.LOG_2);
|
||||||
tempMap.put("gunpowder", Material.SULPHUR);
|
tempMap.put("gunpowder", Material.SULPHUR);
|
||||||
tempMap.put("lilypad", Material.WATER_LILY);
|
tempMap.put("lilypad", Material.WATER_LILY);
|
||||||
tempMap.put("command block", Material.COMMAND);
|
tempMap.put("command block", Material.COMMAND);
|
||||||
tempMap.put("dye", Material.INK_SACK);
|
tempMap.put("dye", Material.INK_SACK);
|
||||||
|
|
||||||
for (Entry<String, Material> tempEntry : tempMap.entrySet()) {
|
for (Entry<String, Material> tempEntry : tempMap.entrySet()) {
|
||||||
materialMap.put(StringUtils.stripChars(tempEntry.getKey(), " _-").toLowerCase(), tempEntry.getValue());
|
materialMap.put(StringUtils.stripChars(tempEntry.getKey(), " _-").toLowerCase(), tempEntry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String bukkitVersion;
|
private static String bukkitVersion;
|
||||||
|
|
||||||
public static String getBukkitVersion() {
|
public static String getBukkitVersion() {
|
||||||
if (bukkitVersion == null) {
|
if (bukkitVersion == null) {
|
||||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
bukkitVersion = packageName.substring(packageName.lastIndexOf('.') + 1);
|
bukkitVersion = packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bukkitVersion;
|
return bukkitVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String colorizeName(String input) {
|
public static String colorizeName(String input) {
|
||||||
if (input == null || input.isEmpty()) return input;
|
if (input == null || input.isEmpty()) return input;
|
||||||
|
|
||||||
if (input.charAt(0) != ChatColor.COLOR_CHAR) {
|
if (input.charAt(0) != ChatColor.COLOR_CHAR) {
|
||||||
return ChestCommands.getSettings().default_color__name + addColors(input);
|
return ChestCommands.getSettings().default_color__name + addColors(input);
|
||||||
} else {
|
} else {
|
||||||
return addColors(input);
|
return addColors(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> colorizeLore(List<String> input) {
|
public static List<String> colorizeLore(List<String> input) {
|
||||||
if (input == null || input.isEmpty()) return input;
|
if (input == null || input.isEmpty()) return input;
|
||||||
|
|
||||||
for (int i = 0; i < input.size(); i++) {
|
for (int i = 0; i < input.size(); i++) {
|
||||||
|
|
||||||
String line = input.get(i);
|
String line = input.get(i);
|
||||||
|
|
||||||
if (line.isEmpty()) continue;
|
if (line.isEmpty()) continue;
|
||||||
|
|
||||||
if (line.charAt(0) != ChatColor.COLOR_CHAR) {
|
if (line.charAt(0) != ChatColor.COLOR_CHAR) {
|
||||||
input.set(i, ChestCommands.getSettings().default_color__lore + addColors(line));
|
input.set(i, ChestCommands.getSettings().default_color__lore + addColors(line));
|
||||||
} else {
|
} else {
|
||||||
input.set(i, addColors(line));
|
input.set(i, addColors(line));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void refreshMenu(Player player) {
|
public static void refreshMenu(Player player) {
|
||||||
InventoryView view = player.getOpenInventory();
|
InventoryView view = player.getOpenInventory();
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
Inventory topInventory = view.getTopInventory();
|
Inventory topInventory = view.getTopInventory();
|
||||||
if (topInventory.getHolder() instanceof MenuInventoryHolder) {
|
if (topInventory.getHolder() instanceof MenuInventoryHolder) {
|
||||||
MenuInventoryHolder menuHolder = (MenuInventoryHolder) topInventory.getHolder();
|
MenuInventoryHolder menuHolder = (MenuInventoryHolder) topInventory.getHolder();
|
||||||
|
|
||||||
if (menuHolder.getIconMenu() instanceof ExtendedIconMenu) {
|
if (menuHolder.getIconMenu() instanceof ExtendedIconMenu) {
|
||||||
((ExtendedIconMenu) menuHolder.getIconMenu()).refresh(player, topInventory);
|
((ExtendedIconMenu) menuHolder.getIconMenu()).refresh(player, topInventory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String addColors(String input) {
|
public static String addColors(String input) {
|
||||||
if (input == null || input.isEmpty()) return input;
|
if (input == null || input.isEmpty()) return input;
|
||||||
return ChatColor.translateAlternateColorCodes('&', input);
|
return ChatColor.translateAlternateColorCodes('&', input);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> addColors(List<String> input) {
|
public static List<String> addColors(List<String> input) {
|
||||||
if (input == null || input.isEmpty()) return input;
|
if (input == null || input.isEmpty()) return input;
|
||||||
for (int i = 0; i < input.size(); i++) {
|
for (int i = 0; i < input.size(); i++) {
|
||||||
input.set(i, addColors(input.get(i)));
|
input.set(i, addColors(input.get(i)));
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String addYamlExtension(String input) {
|
public static String addYamlExtension(String input) {
|
||||||
if (input == null) return null;
|
if (input == null) return null;
|
||||||
return input.toLowerCase().endsWith(".yml") ? input : input + ".yml";
|
return input.toLowerCase().endsWith(".yml") ? input : input + ".yml";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DecimalFormat decimalFormat = new DecimalFormat("0.##");
|
private static DecimalFormat decimalFormat = new DecimalFormat("0.##");
|
||||||
public static String decimalFormat(double number) {
|
public static String decimalFormat(double number) {
|
||||||
return decimalFormat.format(number);
|
return decimalFormat.format(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static Material matchMaterial(String input) {
|
public static Material matchMaterial(String input) {
|
||||||
if (input == null) return null;
|
if (input == null) return null;
|
||||||
|
|
||||||
input = StringUtils.stripChars(input.toLowerCase(), " _-");
|
input = StringUtils.stripChars(input.toLowerCase(), " _-");
|
||||||
|
|
||||||
if (isValidInteger(input)) {
|
if (isValidInteger(input)) {
|
||||||
return Material.getMaterial(Integer.parseInt(input));
|
return Material.getMaterial(Integer.parseInt(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
return materialMap.get(input);
|
return materialMap.get(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Sound matchSound(String input) {
|
public static Sound matchSound(String input) {
|
||||||
if (input == null) return null;
|
if (input == null) return null;
|
||||||
|
|
||||||
input = StringUtils.stripChars(input.toLowerCase(), " _-");
|
input = StringUtils.stripChars(input.toLowerCase(), " _-");
|
||||||
|
|
||||||
for (Sound sound : Sound.values()) {
|
for (Sound sound : Sound.values()) {
|
||||||
if (StringUtils.stripChars(sound.toString().toLowerCase(), "_").equals(input)) return sound;
|
if (StringUtils.stripChars(sound.toString().toLowerCase(), "_").equals(input)) return sound;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatMaterial(Material material) {
|
public static String formatMaterial(Material material) {
|
||||||
return StringUtils.capitalizeFully(material.toString().replace("_", " "));
|
return StringUtils.capitalizeFully(material.toString().replace("_", " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int makePositive(int i) {
|
public static int makePositive(int i) {
|
||||||
return i < 0 ? 0 : i;
|
return i < 0 ? 0 : i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidInteger(String input) {
|
public static boolean isValidInteger(String input) {
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(input);
|
Integer.parseInt(input);
|
||||||
return true;
|
return true;
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidPositiveInteger(String input) {
|
public static boolean isValidPositiveInteger(String input) {
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(input) > 0;
|
return Integer.parseInt(input) > 0;
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidShort(String input) {
|
public static boolean isValidShort(String input) {
|
||||||
try {
|
try {
|
||||||
Short.parseShort(input);
|
Short.parseShort(input);
|
||||||
return true;
|
return true;
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidPositiveDouble(String input) {
|
public static boolean isValidPositiveDouble(String input) {
|
||||||
try {
|
try {
|
||||||
return Double.parseDouble(input) > 0.0;
|
return Double.parseDouble(input) > 0.0;
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> readLines(File file) throws IOException, Exception {
|
public static List<String> readLines(File file) throws IOException, Exception {
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> lines = newArrayList();
|
List<String> lines = newArrayList();
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
throw new FileNotFoundException();
|
throw new FileNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
br = new BufferedReader(new FileReader(file));
|
br = new BufferedReader(new FileReader(file));
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
|
|
||||||
while (line != null) {
|
while (line != null) {
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
line = br.readLine();
|
line = br.readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Color parseColor(String input) throws FormatException {
|
public static Color parseColor(String input) throws FormatException {
|
||||||
String[] split = StringUtils.stripChars(input, " ").split(",");
|
String[] split = StringUtils.stripChars(input, " ").split(",");
|
||||||
|
|
||||||
if (split.length != 3) {
|
if (split.length != 3) {
|
||||||
throw new FormatException("it must be in the format \"red, green, blue\".");
|
throw new FormatException("it must be in the format \"red, green, blue\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
int red, green, blue;
|
int red, green, blue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
red = Integer.parseInt(split[0]);
|
red = Integer.parseInt(split[0]);
|
||||||
green = Integer.parseInt(split[1]);
|
green = Integer.parseInt(split[1]);
|
||||||
blue = Integer.parseInt(split[2]);
|
blue = Integer.parseInt(split[2]);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
throw new FormatException("it contains invalid numbers.");
|
throw new FormatException("it contains invalid numbers.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) {
|
if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) {
|
||||||
throw new FormatException("it should only contain numbers between 0 and 255.");
|
throw new FormatException("it should only contain numbers between 0 and 255.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Color.fromRGB(red, green, blue);
|
return Color.fromRGB(red, green, blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void saveResourceSafe(Plugin plugin, String name) {
|
public static void saveResourceSafe(Plugin plugin, String name) {
|
||||||
try {
|
try {
|
||||||
plugin.saveResource(name, false);
|
plugin.saveResource(name, false);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
// Shhh...
|
// Shhh...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Set<T> newHashSet() {
|
public static <T> Set<T> newHashSet() {
|
||||||
return new HashSet<T>();
|
return new HashSet<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, V> Map<T, V> newHashMap() {
|
public static <T, V> Map<T, V> newHashMap() {
|
||||||
return new HashMap<T, V>();
|
return new HashMap<T, V>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> List<T> newArrayList() {
|
public static <T> List<T> newArrayList() {
|
||||||
return new ArrayList<T>();
|
return new ArrayList<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String join(Iterable<?> iterable, String separator) {
|
public static String join(Iterable<?> iterable, String separator) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
Iterator<?> iter = iterable.iterator();
|
Iterator<?> iter = iterable.iterator();
|
||||||
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
builder.append(separator);
|
builder.append(separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append(iter.next());
|
builder.append(iter.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isClassLoaded(String name) {
|
public static boolean isClassLoaded(String name) {
|
||||||
try {
|
try {
|
||||||
Class.forName(name);
|
Class.forName(name);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,23 +1,23 @@
|
||||||
package com.gmail.filoghost.chestcommands.util;
|
package com.gmail.filoghost.chestcommands.util;
|
||||||
|
|
||||||
public class Validate {
|
public class Validate {
|
||||||
|
|
||||||
public static void notNull(Object object, String error) {
|
public static void notNull(Object object, String error) {
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
throw new NullPointerException(error);
|
throw new NullPointerException(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void isTrue(boolean statement, String error) {
|
public static void isTrue(boolean statement, String error) {
|
||||||
if (!statement) {
|
if (!statement) {
|
||||||
throw new IllegalArgumentException(error);
|
throw new IllegalArgumentException(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void isFalse(boolean statement, String error) {
|
public static void isFalse(boolean statement, String error) {
|
||||||
if (statement) {
|
if (statement) {
|
||||||
throw new IllegalArgumentException(error);
|
throw new IllegalArgumentException(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,41 +1,41 @@
|
||||||
package com.gmail.filoghost.chestcommands.util;
|
package com.gmail.filoghost.chestcommands.util;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
public class VersionUtils {
|
public class VersionUtils {
|
||||||
|
|
||||||
private static boolean setup;
|
private static boolean setup;
|
||||||
private static Method oldGetOnlinePlayersMethod;
|
private static Method oldGetOnlinePlayersMethod;
|
||||||
private static boolean useReflection;
|
private static boolean useReflection;
|
||||||
|
|
||||||
public static Collection<? extends Player> getOnlinePlayers() {
|
public static Collection<? extends Player> getOnlinePlayers() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (!setup) {
|
if (!setup) {
|
||||||
oldGetOnlinePlayersMethod = Bukkit.class.getDeclaredMethod("getOnlinePlayers");
|
oldGetOnlinePlayersMethod = Bukkit.class.getDeclaredMethod("getOnlinePlayers");
|
||||||
if (oldGetOnlinePlayersMethod.getReturnType() == Player[].class) {
|
if (oldGetOnlinePlayersMethod.getReturnType() == Player[].class) {
|
||||||
useReflection = true;
|
useReflection = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
setup = true;
|
setup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!useReflection) {
|
if (!useReflection) {
|
||||||
return Bukkit.getOnlinePlayers();
|
return Bukkit.getOnlinePlayers();
|
||||||
} else {
|
} else {
|
||||||
Player[] playersArray = (Player[]) oldGetOnlinePlayersMethod.invoke(null);
|
Player[] playersArray = (Player[]) oldGetOnlinePlayersMethod.invoke(null);
|
||||||
return ImmutableList.copyOf(playersArray);
|
return ImmutableList.copyOf(playersArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,204 +1,204 @@
|
||||||
######################
|
######################
|
||||||
#+ +#
|
#+ +#
|
||||||
# MENU SETTINGS #
|
# MENU SETTINGS #
|
||||||
#+ +#
|
#+ +#
|
||||||
######################
|
######################
|
||||||
|
|
||||||
menu-settings:
|
menu-settings:
|
||||||
|
|
||||||
# name - appears as the title - REQUIRED
|
# name - appears as the title - REQUIRED
|
||||||
name: '&1Example menu'
|
name: '&1Example menu'
|
||||||
|
|
||||||
# rows - the number of rows of the chest - REQUIRED
|
# rows - the number of rows of the chest - REQUIRED
|
||||||
rows: 3
|
rows: 3
|
||||||
|
|
||||||
# command - OPTIONAL (you can remove this or set it to '')
|
# command - OPTIONAL (you can remove this or set it to '')
|
||||||
# Bind multiple commands using ; (command: 'menu; m; me')
|
# Bind multiple commands using ; (command: 'menu; m; me')
|
||||||
command: 'menu'
|
command: 'menu'
|
||||||
|
|
||||||
# auto-refresh - OPTIONAL
|
# auto-refresh - OPTIONAL
|
||||||
# How frequently the menu will be refreshed, in seconds.
|
# How frequently the menu will be refreshed, in seconds.
|
||||||
# Useful if you have variables in items' descriptions.
|
# Useful if you have variables in items' descriptions.
|
||||||
auto-refresh: 5
|
auto-refresh: 5
|
||||||
|
|
||||||
# This command command will be execute when the menu is opened.
|
# This command command will be execute when the menu is opened.
|
||||||
# Supports all the icon command types.
|
# Supports all the icon command types.
|
||||||
open-action: 'sound: note pling; tell: &eYou opened the example menu.'
|
open-action: 'sound: note pling; tell: &eYou opened the example menu.'
|
||||||
|
|
||||||
# open-with-item - OPTIONAL
|
# open-with-item - OPTIONAL
|
||||||
# The menu will open only right-clicking with orange wool [35:1]
|
# The menu will open only right-clicking with orange wool [35:1]
|
||||||
open-with-item:
|
open-with-item:
|
||||||
id: wool:1
|
id: wool:1
|
||||||
left-click: false
|
left-click: false
|
||||||
right-click: true
|
right-click: true
|
||||||
|
|
||||||
|
|
||||||
######################
|
######################
|
||||||
#+ +#
|
#+ +#
|
||||||
# ITEMS #
|
# ITEMS #
|
||||||
#+ +#
|
#+ +#
|
||||||
######################
|
######################
|
||||||
|
|
||||||
|
|
||||||
spawncmd:
|
spawncmd:
|
||||||
COMMAND: 'spawn'
|
COMMAND: 'spawn'
|
||||||
NAME: '&e/spawn'
|
NAME: '&e/spawn'
|
||||||
LORE:
|
LORE:
|
||||||
- 'It justs executes /spawn'
|
- 'It justs executes /spawn'
|
||||||
- 'as the player who clicked.'
|
- 'as the player who clicked.'
|
||||||
ID: bed
|
ID: bed
|
||||||
POSITION-X: 1
|
POSITION-X: 1
|
||||||
POSITION-Y: 1
|
POSITION-Y: 1
|
||||||
|
|
||||||
|
|
||||||
colored-enchanted-stacked-wool:
|
colored-enchanted-stacked-wool:
|
||||||
NAME: '&aWool with additional data'
|
NAME: '&aWool with additional data'
|
||||||
LORE:
|
LORE:
|
||||||
- 'This wool has a data value, an amount'
|
- 'This wool has a data value, an amount'
|
||||||
- 'greater than 1, and two enchantments.'
|
- 'greater than 1, and two enchantments.'
|
||||||
ID: wool
|
ID: wool
|
||||||
DATA-VALUE: 1
|
DATA-VALUE: 1
|
||||||
AMOUNT: 10
|
AMOUNT: 10
|
||||||
ENCHANTMENT: knockback, 10; durability, 10
|
ENCHANTMENT: knockback, 10; durability, 10
|
||||||
POSITION-X: 2
|
POSITION-X: 2
|
||||||
POSITION-Y: 1
|
POSITION-Y: 1
|
||||||
|
|
||||||
|
|
||||||
this-text-will-not-appear:
|
this-text-will-not-appear:
|
||||||
NAME: '&dFormatting codes'
|
NAME: '&dFormatting codes'
|
||||||
LORE:
|
LORE:
|
||||||
- 'You can use all the formatting codes!'
|
- 'You can use all the formatting codes!'
|
||||||
- '&fColors: &c#c &a#a &9#9 &e#e &f... ...'
|
- '&fColors: &c#c &a#a &9#9 &e#e &f... ...'
|
||||||
- '&fRandom (#k): &kfy379!H'
|
- '&fRandom (#k): &kfy379!H'
|
||||||
- '&fBold (#l): &lexample'
|
- '&fBold (#l): &lexample'
|
||||||
- '&fStrikethrough (#m): &mexample'
|
- '&fStrikethrough (#m): &mexample'
|
||||||
- '&fUnderline (#n): &nexample'
|
- '&fUnderline (#n): &nexample'
|
||||||
- '&fItalic (#o): &oexample'
|
- '&fItalic (#o): &oexample'
|
||||||
ID: paper
|
ID: paper
|
||||||
POSITION-X: 3
|
POSITION-X: 3
|
||||||
POSITION-Y: 1
|
POSITION-Y: 1
|
||||||
|
|
||||||
|
|
||||||
test-from-console:
|
test-from-console:
|
||||||
COMMAND: 'console: say Hello {player}!'
|
COMMAND: 'console: say Hello {player}!'
|
||||||
NAME: '&cRuns command from the console.'
|
NAME: '&cRuns command from the console.'
|
||||||
LORE:
|
LORE:
|
||||||
- 'It broadcasts your name with the command /say.'
|
- 'It broadcasts your name with the command /say.'
|
||||||
ID: command block
|
ID: command block
|
||||||
POSITION-X: 4
|
POSITION-X: 4
|
||||||
POSITION-Y: 1
|
POSITION-Y: 1
|
||||||
|
|
||||||
|
|
||||||
test-as-op:
|
test-as-op:
|
||||||
COMMAND: 'op: say Hello world!'
|
COMMAND: 'op: say Hello world!'
|
||||||
NAME: '&cRuns command as OP.'
|
NAME: '&cRuns command as OP.'
|
||||||
LORE:
|
LORE:
|
||||||
- 'Be careful with this type of commands.'
|
- 'Be careful with this type of commands.'
|
||||||
- 'It will ignore nearly all the permissions.'
|
- 'It will ignore nearly all the permissions.'
|
||||||
ID: command block
|
ID: command block
|
||||||
POSITION-X: 5
|
POSITION-X: 5
|
||||||
POSITION-Y: 1
|
POSITION-Y: 1
|
||||||
|
|
||||||
|
|
||||||
test-with-placeholder:
|
test-with-placeholder:
|
||||||
COMMAND: 'tell: &9Online players: &f{online}/{max_players}; tell: &9Your name: &f{player}; tell: &9The world you are in: &f{world}; tell: &9Money: &f{money}'
|
COMMAND: 'tell: &9Online players: &f{online}/{max_players}; tell: &9Your name: &f{player}; tell: &9The world you are in: &f{world}; tell: &9Money: &f{money}'
|
||||||
NAME: '&6This message contains some placeholders'
|
NAME: '&6This message contains some placeholders'
|
||||||
LORE:
|
LORE:
|
||||||
- 'Placeholders will be replaced when the item'
|
- 'Placeholders will be replaced when the item'
|
||||||
- 'is clicked.'
|
- 'is clicked.'
|
||||||
ID: empty map
|
ID: empty map
|
||||||
POSITION-X: 6
|
POSITION-X: 6
|
||||||
POSITION-Y: 1
|
POSITION-Y: 1
|
||||||
|
|
||||||
|
|
||||||
economy-give:
|
economy-give:
|
||||||
COMMAND: 'tell: &aYou have paid 50$ for this command!; give: gold_ingot'
|
COMMAND: 'tell: &aYou have paid 50$ for this command!; give: gold_ingot'
|
||||||
NAME: '&eEconomy & Give command'
|
NAME: '&eEconomy & Give command'
|
||||||
LORE:
|
LORE:
|
||||||
- 'This command will be executed'
|
- 'This command will be executed'
|
||||||
- 'only if you have at least 50$!'
|
- 'only if you have at least 50$!'
|
||||||
- 'It gives you a gold ingot.'
|
- 'It gives you a gold ingot.'
|
||||||
ID: gold ingot
|
ID: gold ingot
|
||||||
PRICE: 50
|
PRICE: 50
|
||||||
POSITION-X: 7
|
POSITION-X: 7
|
||||||
POSITION-Y: 1
|
POSITION-Y: 1
|
||||||
|
|
||||||
|
|
||||||
economy-take:
|
economy-take:
|
||||||
REQUIRED-ITEM: 'gold_ingot'
|
REQUIRED-ITEM: 'gold_ingot'
|
||||||
COMMAND: 'tell: &aYou have been paid 50$; givemoney: 50'
|
COMMAND: 'tell: &aYou have been paid 50$; givemoney: 50'
|
||||||
NAME: '&eEconomy & Required item'
|
NAME: '&eEconomy & Required item'
|
||||||
LORE:
|
LORE:
|
||||||
- 'This command is the opposite of the previous.'
|
- 'This command is the opposite of the previous.'
|
||||||
- 'It will take you a gold ingot and give you $50.'
|
- 'It will take you a gold ingot and give you $50.'
|
||||||
ID: gold ingot
|
ID: gold ingot
|
||||||
POSITION-X: 8
|
POSITION-X: 8
|
||||||
POSITION-Y: 1
|
POSITION-Y: 1
|
||||||
|
|
||||||
|
|
||||||
will-not-close:
|
will-not-close:
|
||||||
NAME: '&2Info'
|
NAME: '&2Info'
|
||||||
LORE:
|
LORE:
|
||||||
- '&7The menu will not close'
|
- '&7The menu will not close'
|
||||||
- '&7clicking on this item.'
|
- '&7clicking on this item.'
|
||||||
ID: sign
|
ID: sign
|
||||||
KEEP-OPEN: true
|
KEEP-OPEN: true
|
||||||
POSITION-X: 9
|
POSITION-X: 9
|
||||||
POSITION-Y: 1
|
POSITION-Y: 1
|
||||||
|
|
||||||
|
|
||||||
a-talking-head:
|
a-talking-head:
|
||||||
COMMAND: 'tell: This is a simple message, without using commands!'
|
COMMAND: 'tell: This is a simple message, without using commands!'
|
||||||
NAME: '&3Tells you something.'
|
NAME: '&3Tells you something.'
|
||||||
LORE:
|
LORE:
|
||||||
- '&7It tells you something without commands.'
|
- '&7It tells you something without commands.'
|
||||||
ID: head
|
ID: head
|
||||||
DATA-VALUE: 3
|
DATA-VALUE: 3
|
||||||
POSITION-X: 1
|
POSITION-X: 1
|
||||||
POSITION-Y: 2
|
POSITION-Y: 2
|
||||||
|
|
||||||
|
|
||||||
a-talking-head:
|
a-talking-head:
|
||||||
COMMAND: 'tell: This is a simple message, without using commands!'
|
COMMAND: 'tell: This is a simple message, without using commands!'
|
||||||
NAME: '&3Tells you something.'
|
NAME: '&3Tells you something.'
|
||||||
LORE:
|
LORE:
|
||||||
- '&7It tells you something without commands.'
|
- '&7It tells you something without commands.'
|
||||||
ID: head
|
ID: head
|
||||||
DATA-VALUE: 3
|
DATA-VALUE: 3
|
||||||
POSITION-X: 1
|
POSITION-X: 1
|
||||||
POSITION-Y: 2
|
POSITION-Y: 2
|
||||||
|
|
||||||
|
|
||||||
test-multiple-command:
|
test-multiple-command:
|
||||||
COMMAND: 'console: Say Did you know that...; console: say you can run multiple commands?;'
|
COMMAND: 'console: Say Did you know that...; console: say you can run multiple commands?;'
|
||||||
NAME: '&aMultiple commands'
|
NAME: '&aMultiple commands'
|
||||||
LORE:
|
LORE:
|
||||||
- 'Example of multiple commands.'
|
- 'Example of multiple commands.'
|
||||||
ID: golden apple
|
ID: golden apple
|
||||||
POSITION-X: 2
|
POSITION-X: 2
|
||||||
POSITION-Y: 2
|
POSITION-Y: 2
|
||||||
|
|
||||||
|
|
||||||
permission:
|
permission:
|
||||||
COMMAND: 'tell: &a[v] You have the correct permission!'
|
COMMAND: 'tell: &a[v] You have the correct permission!'
|
||||||
NAME: '&8Permission test'
|
NAME: '&8Permission test'
|
||||||
LORE:
|
LORE:
|
||||||
- 'To use this item, you need the'
|
- 'To use this item, you need the'
|
||||||
- 'permission "chestcommands.test".'
|
- 'permission "chestcommands.test".'
|
||||||
- 'Otherwise, a configurable error'
|
- 'Otherwise, a configurable error'
|
||||||
- 'message will be displayed.'
|
- 'message will be displayed.'
|
||||||
ID: iron bar
|
ID: iron bar
|
||||||
POSITION-X: 3
|
POSITION-X: 3
|
||||||
POSITION-Y: 2
|
POSITION-Y: 2
|
||||||
PERMISSION: chestcommands.test
|
PERMISSION: chestcommands.test
|
||||||
PERMISSION-MESSAGE: 'You don''t have the correct permission!'
|
PERMISSION-MESSAGE: 'You don''t have the correct permission!'
|
||||||
|
|
||||||
|
|
||||||
menu-close-no-commands-no-lore:
|
menu-close-no-commands-no-lore:
|
||||||
NAME: '&6Close the menu'
|
NAME: '&6Close the menu'
|
||||||
ID: redstone lamp
|
ID: redstone lamp
|
||||||
LORE:
|
LORE:
|
||||||
- 'Create an item without command,'
|
- 'Create an item without command,'
|
||||||
- 'the GUI will just close.'
|
- 'the GUI will just close.'
|
||||||
POSITION-X: 9
|
POSITION-X: 9
|
||||||
POSITION-Y: 3
|
POSITION-Y: 3
|
|
@ -1,21 +1,21 @@
|
||||||
#
|
#
|
||||||
# This is the configuration file for static placeholders.
|
# This is the configuration file for static placeholders.
|
||||||
# Dynamic placeholders are {online}, {max_players}, ...
|
# Dynamic placeholders are {online}, {max_players}, ...
|
||||||
# Static placeholders are symbols.
|
# Static placeholders are symbols.
|
||||||
#
|
#
|
||||||
# List of unicode symbols: http://www.fileformat.info/info/unicode/index.htm
|
# List of unicode symbols: http://www.fileformat.info/info/unicode/index.htm
|
||||||
#
|
#
|
||||||
<3: \u2764
|
<3: \u2764
|
||||||
[*]: \u2605
|
[*]: \u2605
|
||||||
[**]: \u2739
|
[**]: \u2739
|
||||||
[p]: \u2022
|
[p]: \u2022
|
||||||
[v]: \u2714
|
[v]: \u2714
|
||||||
[+]: \u25C6
|
[+]: \u25C6
|
||||||
[++]: \u2726
|
[++]: \u2726
|
||||||
[x]: \u2588
|
[x]: \u2588
|
||||||
[/]: \u258C
|
[/]: \u258C
|
||||||
[cross]: \u2720
|
[cross]: \u2720
|
||||||
[arrow_right]: \u27A1
|
[arrow_right]: \u27A1
|
||||||
[arrow_left]: \u2B05
|
[arrow_left]: \u2B05
|
||||||
[arrow_up]: \u2B06
|
[arrow_up]: \u2B06
|
||||||
[arrow_down]:\u2B07
|
[arrow_down]:\u2B07
|
|
@ -1,15 +1,15 @@
|
||||||
name: ChestCommands
|
name: ${project.name}
|
||||||
main: com.gmail.filoghost.chestcommands.ChestCommands
|
main: com.gmail.filoghost.chestcommands.ChestCommands
|
||||||
version: 3.1.4
|
version: ${project.version}
|
||||||
softdepend: [Vault, BarAPI, PlayerPoints]
|
softdepend: [Vault, BarAPI, PlayerPoints]
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
chestcommands:
|
chestcommands:
|
||||||
description: Main command for ChestCommands.
|
description: Main command for ChestCommands.
|
||||||
usage: /<command> (Startup error)
|
usage: /<command> (Startup error)
|
||||||
aliases: [cc]
|
aliases: [cc]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
chestcommands.economy.bypass:
|
chestcommands.economy.bypass:
|
||||||
description: Bypass command costs.
|
description: Bypass command costs.
|
||||||
default: false
|
default: false
|
Loading…
Reference in New Issue