mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-22 18:26:12 +01:00
New Arconix, UTF-8, Maven
This commit is contained in:
parent
acc70f46c4
commit
0cf8b9b199
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ out/
|
||||
UltimateKits\.iml
|
||||
|
||||
target/
|
||||
/src/main/java/META-INF/MANIFEST.MF
|
||||
|
116
pom.xml
Normal file
116
pom.xml
Normal file
@ -0,0 +1,116 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>UltimateKits</artifactId>
|
||||
<version>1.0.1</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
<build>
|
||||
<finalName>UltimateKits</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jcenter</id>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
<!--Bukkit Repo-->
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<!--Vault Repo-->
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
<!--Songoda Repo-->
|
||||
<repository>
|
||||
<id>songoda-public</id>
|
||||
<url>http://jenkins.songoda.com:8081/repository/songoda-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>songoda-private</id>
|
||||
<url>http://jenkins.songoda.com:8081/repository/songoda-private/</url>
|
||||
</repository>
|
||||
<!---Essentials Repo-->
|
||||
<repository>
|
||||
<id>ess-repo</id>
|
||||
<url>http://repo.ess3.net/content/groups/essentials</url>
|
||||
</repository>
|
||||
<!--PlaceHolder API Repo-->
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!--Bukkit API-->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--Vault API-->
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--Essentials API-->
|
||||
<dependency>
|
||||
<groupId>com.earth2me</groupId>
|
||||
<artifactId>essentials-x</artifactId>
|
||||
<version>2.15.02</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--UltimateCore API-->
|
||||
<dependency>
|
||||
<groupId>com.github.Bammerbom</groupId>
|
||||
<artifactId>UltimateCore</artifactId>
|
||||
<version>2.1.25</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--Arconix API-->
|
||||
<dependency>
|
||||
<groupId>com.songoda.arconix</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda.arconix</groupId>
|
||||
<artifactId>plugin</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--CB 1.7 R4-->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.7.10</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--PlaceHolderAPI-->
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.8.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
490
src/main/java/com/massivestats/MassiveStats.java
Normal file
490
src/main/java/com/massivestats/MassiveStats.java
Normal file
@ -0,0 +1,490 @@
|
||||
/*
|
||||
* Copyright 2018 (c) Massive Statistics LLC - All Rights Reserved
|
||||
* This file may only be used in conjunction with the 'MassiveStats' service.
|
||||
*/
|
||||
|
||||
package com.massivestats;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* MassiveStats collects plugin and server information for plugin authors.
|
||||
* You can learn more at our website: https://www.massivestats.com/
|
||||
*
|
||||
* @version 3.0
|
||||
* @author Sam Jakob Harker, Brianna Hazel O'Keefe
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class MassiveStats implements Listener {
|
||||
|
||||
/* START: MASSIVESTATS SETTINGS */
|
||||
public static final int CLIENT_VERSION = 0; // v3.0
|
||||
public static final String API_URL = "https://report.massivestats.com/v2/";
|
||||
|
||||
public static final String MASSIVE_UPDATE_PERMISSION = "massivestats.update";
|
||||
/* END: MASSIVESTATS SETTINGS */
|
||||
|
||||
private MassiveStatsUpdateTask task = null;
|
||||
private int pingInterval;
|
||||
|
||||
private MassiveStatsDataResponse lastResponse;
|
||||
private boolean listenerDisabled;
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
private Class jsonElement;
|
||||
private Class jsonParser;
|
||||
private Class jsonObject;
|
||||
private Class jsonPrimitive;
|
||||
|
||||
/**
|
||||
* @param plugin The plugin you wish to collect data for.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public MassiveStats(JavaPlugin plugin){
|
||||
this(plugin, 900); // default value: 900 seconds (= 15 minutes)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plugin The plugin you wish to collect data for.
|
||||
* @param pingInterval Duration between requests.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public MassiveStats(JavaPlugin plugin, int pingInterval){
|
||||
try {
|
||||
jsonElement = Class.forName("com.google.gson.JsonElement");
|
||||
jsonParser = Class.forName("com.google.gson.JsonParser");
|
||||
jsonObject = Class.forName("com.google.gson.JsonObject");
|
||||
jsonPrimitive = Class.forName("com.google.gson.JsonPrimitive");
|
||||
}catch(ClassNotFoundException ex){
|
||||
// Gson not included in classpath (so use NMS version)
|
||||
try {
|
||||
jsonElement = Class.forName("net.minecraft.util.com.google.gson.JsonElement");
|
||||
jsonParser = Class.forName("net.minecraft.util.com.google.gson.JsonParser");
|
||||
jsonObject = Class.forName("net.minecraft.util.com.google.gson.JsonObject");
|
||||
jsonPrimitive = Class.forName("net.minecraft.util.com.google.gson.JsonPrimitive");
|
||||
}catch(ClassNotFoundException ignored){
|
||||
Bukkit.getLogger().severe("MassiveStats could not find an instance/version of Gson to use.");
|
||||
this.plugin = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the pingInterval that is set is reasonable.
|
||||
if(pingInterval < 10 || pingInterval > 86400){
|
||||
pingInterval = 900;
|
||||
}
|
||||
|
||||
// Ensure that a plugin instance has been provided.
|
||||
if(plugin == null){
|
||||
throw new IllegalArgumentException("You must provide a plugin for MassiveStats to collect data for!");
|
||||
}
|
||||
|
||||
// Set the ping interval.
|
||||
this.pingInterval = pingInterval;
|
||||
// Set the plugin reference.
|
||||
this.plugin = plugin;
|
||||
// and start sending data to the MassiveStats server immediately.
|
||||
start();
|
||||
|
||||
// Register join/leave events for the plugin
|
||||
Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether or not the built-in MassiveStats {@link org.bukkit.event.player.PlayerJoinEvent} listener is enabled.
|
||||
* @return Whether or not the MassiveStats listener is enabled.
|
||||
*/
|
||||
public boolean isListenerDisabled(){
|
||||
return listenerDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not the built-in MassiveStats {@link org.bukkit.event.player.PlayerJoinEvent} listener is enabled.
|
||||
* @param listenerDisabled Whether or not the MassiveStats listener is enabled.
|
||||
*/
|
||||
public void setListenerDisabled(boolean listenerDisabled){
|
||||
this.listenerDisabled = listenerDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the MassiveStats reporting timer.
|
||||
* If the timer is already running, this method will do nothing.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public void start(){
|
||||
if(this.plugin == null){
|
||||
Bukkit.getLogger().severe("MassiveStats could not find an instance/version of Gson to use and thus cannot start.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(task == null){
|
||||
// If the API endpoint URL is invalid, don't start a new task to prevent the user from being spammed.
|
||||
try {
|
||||
new URL(MassiveStats.API_URL);
|
||||
}catch(MalformedURLException ex){
|
||||
getPlugin()
|
||||
.getLogger().warning("You have specified an invalid API endpoint for MassiveStats.");
|
||||
return;
|
||||
}
|
||||
|
||||
task = new MassiveStatsUpdateTask(this);
|
||||
task.runTaskTimerAsynchronously(plugin, 0L, pingInterval * 20L);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the MassiveStats reporting timer.
|
||||
* Requests will no longer be sent to the server - or until {@link #start()} is invoked.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public void stop(){
|
||||
if(task == null){
|
||||
return;
|
||||
}
|
||||
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the duration, in seconds, that MassiveStats should wait before sending another request to the server.
|
||||
* @param pingInterval Duration between requests.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public void setPingInterval(int pingInterval){
|
||||
this.pingInterval = pingInterval;
|
||||
|
||||
stop();
|
||||
start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the duration, in seconds, that MassiveStats will wait before sending another request to the server.
|
||||
* @return Duration between requests.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public int getPingInterval(){
|
||||
return pingInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plugin that this MassiveStats instance is collecting data for.
|
||||
* @return MassiveStats instance plugin.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public JavaPlugin getPlugin(){
|
||||
return plugin;
|
||||
}
|
||||
|
||||
void setLastResponse(MassiveStatsDataResponse lastResponse){
|
||||
this.lastResponse = lastResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of the last response from the MassiveStats server.
|
||||
* @return MassiveStats server response.
|
||||
* @author Sam Jakob Harker
|
||||
*/
|
||||
public MassiveStatsDataResponse getLastResponse() {
|
||||
return lastResponse;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event){
|
||||
// Ensure the listener should be active
|
||||
if(lastResponse == null || listenerDisabled){
|
||||
return;
|
||||
}
|
||||
|
||||
// Of course, only notify the user if the plugin is not up to date.
|
||||
if(lastResponse.isUpToDate()){
|
||||
return;
|
||||
}
|
||||
|
||||
// and only notify operators - or players with the correct permission.
|
||||
if(!event.getPlayer().isOp() && !event.getPlayer().hasPermission(MassiveStats.MASSIVE_UPDATE_PERMISSION)){
|
||||
return;
|
||||
}
|
||||
|
||||
event.getPlayer().sendMessage(lastResponse.getUpdateMessage());
|
||||
}
|
||||
|
||||
Class getJsonElement(){
|
||||
return jsonElement;
|
||||
}
|
||||
|
||||
Class getJsonParser(){
|
||||
return jsonParser;
|
||||
}
|
||||
|
||||
Class getJsonObject(){
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
Class getJsonPrimitive(){
|
||||
return jsonPrimitive;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MassiveStatsUpdateTask extends BukkitRunnable {
|
||||
|
||||
private final MassiveStats instance;
|
||||
|
||||
MassiveStatsUpdateTask(MassiveStats requester){
|
||||
instance = requester;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("all")
|
||||
public void run(){
|
||||
try {
|
||||
// Generate the request payload and serialize it as JSON.
|
||||
String payload = new MassiveStatsDataRequest(instance).serialize();
|
||||
|
||||
// Then create a new HttpsUrlConnection to the API server and open it.
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(MassiveStats.API_URL).openConnection();
|
||||
|
||||
// Ensure that we don't hang the server with our 'dang shenanigans'.
|
||||
connection.setConnectTimeout(2500);
|
||||
connection.setReadTimeout(3500);
|
||||
|
||||
// Set the all-important request headers before we begin POSTing...
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Accept", "application/json");
|
||||
connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
|
||||
connection.setRequestProperty("User-Agent", "Massive/" + MassiveStats.CLIENT_VERSION);
|
||||
|
||||
// Open the output stream, write the payload, and then close the stream.
|
||||
connection.setDoOutput(true);
|
||||
DataOutputStream output = new DataOutputStream(connection.getOutputStream());
|
||||
output.writeBytes(payload);
|
||||
output.flush();
|
||||
output.close();
|
||||
|
||||
// Ensure that the server was happy with our data.
|
||||
int responseCode = connection.getResponseCode();
|
||||
if(responseCode != 200){
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
// Now, read the server's response to our payload...
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
StringBuilder response = new StringBuilder();
|
||||
|
||||
// ...line by line.
|
||||
String line;
|
||||
while((line = input.readLine()) != null){
|
||||
response.append(line);
|
||||
}
|
||||
input.close();
|
||||
|
||||
// Now, we parse the JSON object.
|
||||
try {
|
||||
if(response.toString().contains("ERR_DATA_MISSING")){
|
||||
Bukkit.getLogger().severe("MassiveStats has encountered an error for the following plugin: "
|
||||
+ instance.getPlugin().getName());
|
||||
instance.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
Object parser = instance.getJsonParser().newInstance();
|
||||
|
||||
// JsonElement
|
||||
Object serverResponseRaw =
|
||||
parser.getClass().getMethod("parse", String.class).invoke(parser, response.toString());
|
||||
|
||||
// JsonObject
|
||||
Object serverResponse = serverResponseRaw.getClass().getMethod("getAsJsonObject", null)
|
||||
.invoke(serverResponseRaw, null);
|
||||
|
||||
Method serverResponseGet = instance.getJsonObject().getMethod("get", String.class);
|
||||
|
||||
Method getAsBoolean =
|
||||
instance.getJsonPrimitive().getMethod("getAsBoolean", null);
|
||||
Method getAsString =
|
||||
instance.getJsonPrimitive().getMethod("getAsString", null);
|
||||
|
||||
if(serverResponseGet.invoke(serverResponse, "upToDate") == null){
|
||||
Bukkit.getLogger().severe("MassiveStats has encountered an error for the following plugin: "
|
||||
+ instance.getPlugin().getName());
|
||||
instance.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if(serverResponseGet.invoke(serverResponse, "notice") != null) {
|
||||
Bukkit.getLogger().severe(
|
||||
(String) getAsString.invoke(serverResponseGet.invoke(serverResponse, "notice"))
|
||||
);
|
||||
instance.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean upToDate = (boolean) getAsBoolean.invoke(serverResponseGet.invoke(serverResponse, "upToDate"), null);
|
||||
String latestVersion = (String) getAsString.invoke(serverResponseGet.invoke(serverResponse, "latestVersion"), null);
|
||||
String updateMessage = ChatColor.translateAlternateColorCodes(
|
||||
'&', (String) getAsString.invoke(serverResponseGet.invoke(serverResponse, "updateMessage"), null)
|
||||
);
|
||||
|
||||
instance.setLastResponse(new MassiveStatsDataResponse(
|
||||
upToDate, latestVersion, updateMessage
|
||||
));
|
||||
|
||||
}catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
|
||||
instance.getPlugin()
|
||||
.getLogger().warning("MassiveStats returned an invalid response for this plugin.");
|
||||
}
|
||||
|
||||
// Finally, call an event to mark the update.
|
||||
} catch(MalformedURLException ex){
|
||||
instance.getPlugin()
|
||||
.getLogger().warning("You have specified an invalid API endpoint for MassiveStats.");
|
||||
}catch(IOException ex){
|
||||
instance.getPlugin()
|
||||
.getLogger().warning("MassiveStats was unable to communicate with its API endpoint.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MassiveStatsDataRequest {
|
||||
|
||||
private Object jsonObject;
|
||||
|
||||
MassiveStatsDataRequest(MassiveStats requester){
|
||||
try {
|
||||
jsonObject = requester.getJsonObject().newInstance();
|
||||
|
||||
Method add =
|
||||
requester.getJsonObject().newInstance().getClass().getMethod("add", String.class, requester.getJsonElement());
|
||||
Method addPropertyString =
|
||||
requester.getJsonObject().newInstance().getClass().getMethod("addProperty", String.class, String.class);
|
||||
Method addPropertyNumber =
|
||||
requester.getJsonObject().newInstance().getClass().getMethod("addProperty", String.class, Number.class);
|
||||
Method addPropertyBoolean =
|
||||
requester.getJsonObject().newInstance().getClass().getMethod("addProperty", String.class, Boolean.class);
|
||||
|
||||
addPropertyNumber.invoke(jsonObject, "now", System.currentTimeMillis());
|
||||
|
||||
/* PLUGIN DATA */
|
||||
Object pluginObject = jsonObject.getClass().newInstance();
|
||||
addPropertyString.invoke(pluginObject, "name", requester.getPlugin().getDescription().getName());
|
||||
addPropertyString.invoke(pluginObject, "version", requester.getPlugin().getDescription().getVersion());
|
||||
add.invoke(jsonObject, "plugin", pluginObject);
|
||||
|
||||
/* SERVER DATA */
|
||||
Object minecraftServerObject = jsonObject.getClass().newInstance();
|
||||
addPropertyNumber.invoke(minecraftServerObject, "players", Bukkit.getServer().getOnlinePlayers().size());
|
||||
addPropertyBoolean.invoke(minecraftServerObject, "onlineMode", Bukkit.getServer().getOnlineMode());
|
||||
addPropertyString.invoke(minecraftServerObject, "version", Bukkit.getServer().getVersion());
|
||||
|
||||
Object javaServerObject = jsonObject.getClass().newInstance();
|
||||
addPropertyString.invoke(javaServerObject, "version", System.getProperty("java.version"));
|
||||
|
||||
Object osServerObject = jsonObject.getClass().newInstance();
|
||||
addPropertyString.invoke(osServerObject, "name", System.getProperty("os.name"));
|
||||
addPropertyString.invoke(osServerObject, "arch", System.getProperty("os.arch"));
|
||||
addPropertyString.invoke(osServerObject, "version", System.getProperty("os.version"));
|
||||
|
||||
Object hardwareServerObject = jsonObject.getClass().newInstance();
|
||||
addPropertyNumber.invoke(hardwareServerObject, "cores", Runtime.getRuntime().availableProcessors());
|
||||
|
||||
Object serverObject = jsonObject.getClass().newInstance();
|
||||
add.invoke(serverObject, "minecraft", minecraftServerObject);
|
||||
add.invoke(serverObject, "java", javaServerObject);
|
||||
add.invoke(serverObject, "os", osServerObject);
|
||||
add.invoke(serverObject,"hardware", hardwareServerObject);
|
||||
|
||||
add.invoke(jsonObject, "server", serverObject);
|
||||
|
||||
/* MASSIVE DATA */
|
||||
Object massiveObject = jsonObject.getClass().newInstance();
|
||||
addPropertyNumber.invoke(massiveObject, "version", MassiveStats.CLIENT_VERSION);
|
||||
addPropertyNumber.invoke(massiveObject, "pingInterval", requester.getPingInterval());
|
||||
|
||||
//object.add("Massive", massiveObject);
|
||||
add.invoke(jsonObject,"Massive", massiveObject);
|
||||
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public String serialize(){
|
||||
//return object.toString();
|
||||
try {
|
||||
Method toString = jsonObject.getClass().getMethod("toString", null);
|
||||
return (String) toString.invoke(jsonObject);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
final class MassiveStatsDataResponse {
|
||||
|
||||
private final boolean isUpToDate;
|
||||
private final String newVersion;
|
||||
private final String updateMessage;
|
||||
|
||||
MassiveStatsDataResponse(boolean isUpToDate, String newVersion, String updateMessage){
|
||||
this.isUpToDate = isUpToDate;
|
||||
|
||||
if(!isUpToDate) {
|
||||
this.newVersion = newVersion;
|
||||
this.updateMessage = updateMessage;
|
||||
return;
|
||||
}
|
||||
|
||||
this.newVersion = null;
|
||||
this.updateMessage = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether or not this version of the plugin is the latest.
|
||||
* True = This is the latest version of the plugin.
|
||||
* False = There is an update available.
|
||||
* @return Whether or not there is an update available.
|
||||
*/
|
||||
public boolean isUpToDate() {
|
||||
return isUpToDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the latest version. If this is the latest version, it returns null.
|
||||
* @return The name of the latest version.
|
||||
*/
|
||||
public String getLatestVersion(){
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message to display, convincing the user to update to the new version of the plugin.
|
||||
* @return The update message to display.
|
||||
*/
|
||||
public String getUpdateMessage(){
|
||||
return updateMessage;
|
||||
}
|
||||
|
||||
}
|
178
src/main/java/com/songoda/ultimatekits/Lang.java
Normal file
178
src/main/java/com/songoda/ultimatekits/Lang.java
Normal file
@ -0,0 +1,178 @@
|
||||
package com.songoda.ultimatekits;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public enum Lang {
|
||||
|
||||
PREFIX("prefix", "&8[&9UltimateKits&8]"),
|
||||
|
||||
NO_CONSOLE_ACCESS("no-console", "&cOnly players may do that."),
|
||||
|
||||
NO_PERM("no-permission", "&cYou do not have permission to do that!"),
|
||||
|
||||
PREVIEW_NO_KIT_SUPPLIED("no-kit-supplied", "&7Please include a kit to preview."),
|
||||
|
||||
KIT_DOESNT_EXIST("kit-doesnt-exist", "&cThat kit does not exist."),
|
||||
|
||||
KIT_ALREADY_EXISTS("kit-already-exist", "&cThat kit already exists."),
|
||||
|
||||
PLAYER_NOT_FOUND("player-not-found", "&cThis player is not online or doesn't exist."),
|
||||
|
||||
GUI_KIT_NAME("gui-kit-showableName", "&c{KIT}"),
|
||||
|
||||
PREVIEWING_KIT("Previewing-kit", "&9You are now previewing kit &7{KIT}&9."),
|
||||
|
||||
SIGN_TITLE("sign-title", "&8[&9PreviewKit&8]"),
|
||||
|
||||
PREVIEW_SIGN_CREATED("sign-created", "&aPreview sign created for kit &7{KIT}&9."),
|
||||
|
||||
PREVIEW_ONLY_HOLOGRAM("Preview-only-holo", "Click to Preview!"),
|
||||
|
||||
PREVIEW_HOLOGRAM("Preview-holo", "Right-Click to Preview!"),
|
||||
|
||||
BUY_LINK_HOLOGRAM("Buy-link-holo", "Left-Click for Buy Link!"),
|
||||
|
||||
BUY_ECO_HOLOGRAM("Buy-eco-holo", "Left-Click to buy for &a${PRICE}&f!"),
|
||||
|
||||
OPEN_CRATE_HOLOGRAM("open-crate-holo", "Left-Click with a key to open!"),
|
||||
DAILY_HOLOGRAM("daily-holo", "Left-Click to claim!"),
|
||||
|
||||
WRONG_KEY("wrong-key", "&cThis key does not go to this kit."),
|
||||
NOT_KEY("not-key", "&cYou are not holding a key."),
|
||||
NOT_YET("not-yet", "&cYou need to wait &4{TIME} &cbefore you can use this."),
|
||||
|
||||
CANNOT_AFFORD("Cannot-afford", "&9You cannot afford to buy kit &7{KIT}&9."),
|
||||
|
||||
NOT_TWICE("Not-twice", "&9You can only receive this kit once."),
|
||||
PURCHASE_SUCCESS("Purchase_success", "&9You have purchased kit &7{KIT}&9."),
|
||||
GIVE_SUCCESS("Give_success", "&9You have received kit &7{KIT}&9."),
|
||||
|
||||
NO_COMMANDS("No-commands", "&9There are no commands attached to this kit. You cannot buy a kit if there are no commands assigned to it."),
|
||||
|
||||
YES("yes", "yes"),
|
||||
|
||||
NO("no", "no"),
|
||||
|
||||
DELAY("Delay", "&9Please wait {TIME}"),
|
||||
|
||||
COMMAND("Command", "&7Command"),
|
||||
|
||||
MONEY("Money", "&6Money"),
|
||||
|
||||
LINK("Link", "&9Link"),
|
||||
BUYNOW("Buy-now", "&aBuy Now"),
|
||||
BACK("Back", "&9Back"),
|
||||
EXIT("Exit", "&cExit"),
|
||||
|
||||
BUYCANCELLED("buy-cancelled", "&cPurchase Cancelled."),
|
||||
|
||||
TIMEOUT("buy-timeout", "&cPurchase timed out."),
|
||||
|
||||
AREYOUSURE("are-you-sure", "&9Are you sure you would like to buy this kit for &a${PRICE}&9?"),
|
||||
|
||||
YESORNO("yesorno", "&9Type &7Yes &9or &7no&9 into the chat."),
|
||||
|
||||
SYNTAX("Synax", "&9Incorrect syntax. Please refer to /KP help"),
|
||||
|
||||
CLICKLINK("Click-link", "&7Click to get Link."),
|
||||
|
||||
CLICKECO("Click-eco", "&7Click to buy for &a${PRICE}&7."),
|
||||
|
||||
PREVIEW("Preview", "&7Click to preview."),
|
||||
|
||||
ALLKITS("All-kit", "&9All kit"),
|
||||
ALLKITS_LORE("All-kit-lore", "&7Display all kit."),
|
||||
|
||||
ALLSALE("All-sale", "&9All For Sale kit"),
|
||||
ALLSALE_LORE("All-sale-lore", "&7Display all kit for sale."),
|
||||
|
||||
UNLOCKED("Unlocked", "&9All Unlocked kit"),
|
||||
UNLOCKED_LORE("Unlocked-lore", "&7Display all unlocked kit."),
|
||||
|
||||
FREE("Free", "Free"),
|
||||
|
||||
GUI_TITLE_YESNO("gui-title-yesno", "&9Buy for &a${COST}&9?"),
|
||||
|
||||
YES_GUI("yes-gui", "&a&lYes"),
|
||||
|
||||
NO_GUI("no-gui", "&c&lNo"),
|
||||
|
||||
PREVIEW_TITLE("preview-title", "&9Previewing kit: &8{KIT}"),
|
||||
|
||||
KEY_TITLE("key-title", "&5{KIT} &fKit Key"),
|
||||
|
||||
KEY_GIVEN("Key-given", "&9You have received a &a{KIT} &9kit key."),
|
||||
|
||||
KEY_SUCCESS("key-success", "&9You have successfully redeemed a key for the kit &7{KIT}&9."),
|
||||
|
||||
KEY_DESC1("key-desc1", "&rRight-Click on a &c&l{KIT}&r kit"),
|
||||
|
||||
KEY_DESC2("key-desc2", "&rand receive its contents!"),
|
||||
|
||||
KEY_DESC3("key-desc3", "&rand receive some of its contents!"),
|
||||
|
||||
KEY_DESC4("key-desc4", "&rGives kit &c&l{AMT} &rtimes."),
|
||||
|
||||
KITS_TITLE("kit-title", "&8Server kits"),
|
||||
|
||||
DETAILS("Details", "&7Hello &e{PLAYER}&7!|&7Listed below are our servers kit.||&7Click on the &eicon &7representing the &ekit |&7inorder to &epreview, claim or buy &7it."),
|
||||
|
||||
ABOUT_KIT("About-kit", "&7Can't open a kit?|&7Rank up to gain access!"),
|
||||
|
||||
ONCE("Once", "&7Cooldown: &6You already claimed this kit!"),
|
||||
READY("Ready", "&7Cooldown: &6Ready for use!"),
|
||||
PLEASE_WAIT("Please-wait", "&7Cooldown: &6{TIME}"),
|
||||
NO_ACCESS("No-access", "&7Cooldown: &cNo Access.."),
|
||||
|
||||
LEFT_PREVIEW("Left_preview", "&6&lLEFT CLICK &7to preview kit."),
|
||||
RIGHT_CLAIM("Right_claim", "&6&lRIGHT CLICK &7to claim kit."),
|
||||
RIGHT_BUY("Right_buy", "&6&lRIGHT CLICK &7to buy kit."),
|
||||
|
||||
NEXT("Next", "&7Next Page"),
|
||||
LAST("Last", "&7Last Page"),
|
||||
ECO_SENT("Eco_Sent", "&7You received &a{AMT}&7."),
|
||||
|
||||
INVENTORY_FULL("Inventory-full", "&cYour inventory is too full to claim this kit!");
|
||||
|
||||
|
||||
private String path;
|
||||
private String def;
|
||||
private static FileConfiguration LANG;
|
||||
|
||||
Lang(String path, String start) {
|
||||
this.path = path;
|
||||
this.def = start;
|
||||
}
|
||||
|
||||
public static void setFile(final FileConfiguration config) {
|
||||
LANG = config;
|
||||
}
|
||||
|
||||
public String getDefault() {
|
||||
return this.def;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public String getConfigValue(Object ob) {
|
||||
String value = ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, this.def));
|
||||
|
||||
if (ob != null) {
|
||||
value = value.replace("{PLAYER}", ob.toString());
|
||||
value = value.replace("{KIT}", ob.toString());
|
||||
value = value.replace("{AMT}", ob.toString());
|
||||
value = value.replace("{COST}", ob.toString());
|
||||
value = value.replace("{PRICE}", ob.toString());
|
||||
value = value.replace("{TIME}", ob.toString());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getConfigValue() {
|
||||
String value = ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, this.def));
|
||||
return value;
|
||||
}
|
||||
}
|
33
src/main/java/com/songoda/ultimatekits/References.java
Normal file
33
src/main/java/com/songoda/ultimatekits/References.java
Normal file
@ -0,0 +1,33 @@
|
||||
package com.songoda.ultimatekits;
|
||||
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Sound;
|
||||
|
||||
public class References {
|
||||
|
||||
private String prefix = null;
|
||||
private boolean playSound = false;
|
||||
private Sound sound = null;
|
||||
|
||||
public References() {
|
||||
try {
|
||||
prefix = Lang.PREFIX.getConfigValue() + " ";
|
||||
playSound = UltimateKits.getInstance().getConfig().getBoolean("Main.Sounds Enabled");
|
||||
sound = Sound.valueOf(UltimateKits.getInstance().getConfig().getString("Main.Sound Played While Clicking In Inventories"));
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public boolean isPlaySound() {
|
||||
return this.playSound;
|
||||
}
|
||||
|
||||
public Sound getSound() {
|
||||
return this.sound;
|
||||
}
|
||||
}
|
395
src/main/java/com/songoda/ultimatekits/UltimateKits.java
Normal file
395
src/main/java/com/songoda/ultimatekits/UltimateKits.java
Normal file
@ -0,0 +1,395 @@
|
||||
package com.songoda.ultimatekits;
|
||||
|
||||
import com.songoda.arconix.api.utils.ConfigWrapper;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.conversion.Convert;
|
||||
import com.songoda.ultimatekits.events.*;
|
||||
import com.songoda.ultimatekits.handlers.CommandHandler;
|
||||
import com.songoda.ultimatekits.handlers.DisplayItemHandler;
|
||||
import com.songoda.ultimatekits.handlers.HologramHandler;
|
||||
import com.songoda.ultimatekits.handlers.ParticleHandler;
|
||||
import com.songoda.ultimatekits.key.Key;
|
||||
import com.songoda.ultimatekits.key.KeyManager;
|
||||
import com.songoda.ultimatekits.kit.BlockEditor;
|
||||
import com.songoda.ultimatekits.kit.KitEditor;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.object.KitManager;
|
||||
import com.songoda.ultimatekits.kit.object.KitType;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import com.songoda.ultimatekits.utils.SettingsManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
public class UltimateKits extends JavaPlugin {
|
||||
public static CommandSender console = Bukkit.getConsoleSender();
|
||||
|
||||
public ConfigWrapper langFile = new ConfigWrapper(this, "", "lang.yml");
|
||||
private ConfigWrapper kitFile = new ConfigWrapper(this, "", "kit.yml");
|
||||
private ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml");
|
||||
private ConfigWrapper keyFile = new ConfigWrapper(this, "", "keys.yml");
|
||||
|
||||
public References references;
|
||||
|
||||
public HologramHandler holo;
|
||||
private SettingsManager settingsManager;
|
||||
|
||||
public boolean v1_7 = Bukkit.getServer().getClass().getPackage().getName().contains("1_7");
|
||||
public boolean v1_8 = Bukkit.getServer().getClass().getPackage().getName().contains("1_8");
|
||||
|
||||
private static UltimateKits INSTANCE;
|
||||
|
||||
public DisplayItemHandler displayitem;
|
||||
|
||||
private KitManager kitManager;
|
||||
|
||||
private KeyManager keyManager;
|
||||
|
||||
private KitEditor kitEditor;
|
||||
|
||||
private BlockEditor blockEditor;
|
||||
|
||||
public Map<UUID, Integer> page = new HashMap<>();
|
||||
|
||||
public Map<UUID, String> buy = new HashMap<>();
|
||||
public Map<String, String> kits = new HashMap<>();
|
||||
|
||||
public Map<UUID, Kit> inKit = new HashMap<>();
|
||||
|
||||
public Map<UUID, String> whereAt = new HashMap<>();
|
||||
|
||||
public List<UUID> kitsMode = new ArrayList<>();
|
||||
|
||||
/*
|
||||
* On plugin enable.
|
||||
*/
|
||||
public void onEnable() {
|
||||
INSTANCE = this;
|
||||
Arconix.pl().hook(this);
|
||||
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7UltimateKits " + this.getDescription().getVersion() + " by &5Songoda <3!"));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &aEnabling&7..."));
|
||||
|
||||
loadLanguageFile();
|
||||
|
||||
new Convert(this);
|
||||
|
||||
references = new References();
|
||||
|
||||
holo = new HologramHandler(this);
|
||||
new ParticleHandler(this);
|
||||
displayitem = new DisplayItemHandler(this);
|
||||
settingsManager = new SettingsManager(this);
|
||||
settingsManager.updateSettings();
|
||||
setupConfig();
|
||||
|
||||
kitManager = new KitManager();
|
||||
keyManager = new KeyManager();
|
||||
kitEditor = new KitEditor(this);
|
||||
blockEditor = new BlockEditor(this);
|
||||
|
||||
loadFromFile();
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000);
|
||||
|
||||
|
||||
new com.massivestats.MassiveStats(this, 900);
|
||||
|
||||
if (!getConfig().getBoolean("Main.Enabled Custom Kits And Kit Commands")) {
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7The &a/kit&7 and &a/kit &7features have been &cdisabled&7."));
|
||||
} else {
|
||||
registerCommandDynamically("kits", new CommandHandler(this));
|
||||
registerCommandDynamically("kit", new CommandHandler(this));
|
||||
}
|
||||
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
|
||||
this.getCommand("UltimateKits").setExecutor(new CommandHandler(this));
|
||||
this.getCommand("PreviewKit").setExecutor(new CommandHandler(this));
|
||||
|
||||
getServer().getPluginManager().registerEvents(new BlockListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new ChatListeners(this), this);
|
||||
if (!v1_7) getServer().getPluginManager().registerEvents(new EntityListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new InteractListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new InventoryListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new QuitListeners(this), this);
|
||||
}
|
||||
|
||||
/*
|
||||
* On plugin disable.
|
||||
*/
|
||||
public void onDisable() {
|
||||
for (UUID uuid : whereAt.keySet()) {
|
||||
Bukkit.getPlayer(uuid).closeInventory();
|
||||
}
|
||||
saveToFile();
|
||||
whereAt.clear();
|
||||
kitManager.clearKits();
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7UltimateKits " + this.getDescription().getVersion() + " by &5Songoda <3!"));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &cDisabling&7..."));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
}
|
||||
|
||||
private void registerCommandDynamically(String command, CommandExecutor executor) {
|
||||
try {
|
||||
// Retrieve the SimpleCommandMap from the server
|
||||
Class<?> classCraftServer = Bukkit.getServer().getClass();
|
||||
Field fieldCommandMap = classCraftServer.getDeclaredField("commandMap");
|
||||
fieldCommandMap.setAccessible(true);
|
||||
SimpleCommandMap commandMap = (SimpleCommandMap) fieldCommandMap.get(Bukkit.getServer());
|
||||
|
||||
// Construct a new Command object
|
||||
Constructor<PluginCommand> constructorPluginCommand = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
|
||||
constructorPluginCommand.setAccessible(true);
|
||||
PluginCommand commandObject = constructorPluginCommand.newInstance(command, this);
|
||||
commandObject.setExecutor(executor);
|
||||
|
||||
// Register the command
|
||||
Field fieldKnownCommands = commandMap.getClass().getDeclaredField("knownCommands");
|
||||
fieldKnownCommands.setAccessible(true);
|
||||
Map<String, Command> knownCommands = (Map<String, Command>) fieldKnownCommands.get(commandMap);
|
||||
knownCommands.put(command, commandObject);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Load configuration files into memory.
|
||||
*/
|
||||
private void loadFromFile() {
|
||||
|
||||
//Empty kits from manager.
|
||||
kitManager.clearKits();
|
||||
|
||||
/*
|
||||
* Register kit into KitManager from Configuration.
|
||||
*/
|
||||
for (String kitName : kitFile.getConfig().getConfigurationSection("Kits").getKeys(false)) {
|
||||
try {
|
||||
int delay = kitFile.getConfig().getInt("Kits." + kitName + ".delay");
|
||||
String title = kitFile.getConfig().getString("Kits." + kitName + ".title");
|
||||
String link = kitFile.getConfig().getString("Kits." + kitName + ".link");
|
||||
Material material = kitFile.getConfig().contains("Kits." + kitName + ".displayItem") ? Material.valueOf(kitFile.getConfig().getString("Kits." + kitName + ".displayItem")) : null;
|
||||
boolean hidden = kitFile.getConfig().getBoolean("Kits." + kitName + ".hidden");
|
||||
double price = kitFile.getConfig().getDouble("Kits." + kitName + ".price");
|
||||
List<String> contents = kitFile.getConfig().getStringList("Kits." + kitName + ".items");
|
||||
|
||||
Kit kit = new Kit(kitName, title, link, price, material, delay, hidden, contents);
|
||||
kitManager.addKit(kit);
|
||||
} catch (Exception ex) {
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&cYour kit &4" + kitName + " &cis setup incorrectly."));
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Register kit locations into KitManager from Configuration.
|
||||
*/
|
||||
if (dataFile.getConfig().contains("BlockData")) {
|
||||
for (String key : dataFile.getConfig().getConfigurationSection("BlockData").getKeys(false)) {
|
||||
Location location = Arconix.pl().getApi().serialize().unserializeLocation(key);
|
||||
Kit kit = kitManager.getKit(dataFile.getConfig().getString("BlockData." + key + ".kit"));
|
||||
KitType type = KitType.valueOf(dataFile.getConfig().getString("BlockData." + key + ".type", "PREVIEW"));
|
||||
boolean holograms = dataFile.getConfig().getBoolean("BlockData." + key + ".holograms");
|
||||
boolean displayItems = dataFile.getConfig().getBoolean("BlockData." + key + ".displayItems");
|
||||
boolean particles = dataFile.getConfig().getBoolean("BlockData." + key + ".particles");
|
||||
boolean itemOverride = dataFile.getConfig().getBoolean("BlockData." + key + ".itemOverride");
|
||||
|
||||
if (kit == null) dataFile.getConfig().set("BlockData." + key, null);
|
||||
else kitManager.addKitToLocation(kit, location, type, holograms, particles, displayItems, itemOverride);
|
||||
}
|
||||
}
|
||||
|
||||
//Apply default keys.
|
||||
checkKeyDefaults();
|
||||
|
||||
//Empty keys from manager.
|
||||
keyManager.clear();
|
||||
|
||||
/*
|
||||
* Register keys into KitManager from Configuration.
|
||||
*/
|
||||
if (keyFile.getConfig().contains("Keys")) {
|
||||
for (String keyName : keyFile.getConfig().getConfigurationSection("Keys").getKeys(false)) {
|
||||
int amt = keyFile.getConfig().getInt("Keys." + keyName + ".Item Amount");
|
||||
int kitAmount = keyFile.getConfig().getInt("Keys." + keyName + ".Amount of kit received");
|
||||
|
||||
Key key = new Key(keyName, amt, kitAmount);
|
||||
keyManager.addKey(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Saves registered kits to file.
|
||||
*/
|
||||
private void saveToFile() {
|
||||
|
||||
// Wipe old kit information
|
||||
kitFile.getConfig().set("Kits", null);
|
||||
|
||||
/*
|
||||
* Save kit from KitManager to Configuration.
|
||||
*/
|
||||
for (Kit kit : kitManager.getKits()) {
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".delay", kit.getDelay());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".title", kit.getTitle());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".link", kit.getLink());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".price", kit.getPrice());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".hidden", kit.isHidden());
|
||||
if (kit.getDisplayItem() != null)
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".displayItem", kit.getDisplayItem().toString());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".items", kit.getContents());
|
||||
}
|
||||
|
||||
// Wipe old block information.
|
||||
dataFile.getConfig().set("BlockData", null);
|
||||
|
||||
/*
|
||||
* Save kit locations from KitManager to Configuration.
|
||||
*/
|
||||
for (KitBlockData kitBlockData : kitManager.getKitLocations().values()) {
|
||||
String locationStr = Arconix.pl().getApi().serialize().serializeLocation(kitBlockData.getLocation());
|
||||
dataFile.getConfig().set("BlockData." + locationStr + ".type", kitBlockData.getType().name());
|
||||
dataFile.getConfig().set("BlockData." + locationStr + ".kit", kitBlockData.getKit().getName());
|
||||
dataFile.getConfig().set("BlockData." + locationStr + ".holograms", kitBlockData.showHologram());
|
||||
dataFile.getConfig().set("BlockData." + locationStr + ".displayItems", kitBlockData.isDisplayingItems());
|
||||
dataFile.getConfig().set("BlockData." + locationStr + ".particles", kitBlockData.hasParticles());
|
||||
dataFile.getConfig().set("BlockData." + locationStr + ".itemOverride", kitBlockData.isItemOverride());
|
||||
}
|
||||
|
||||
// Save to file
|
||||
kitFile.saveConfig();
|
||||
dataFile.saveConfig();
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert default key list into config.
|
||||
*/
|
||||
public void checkKeyDefaults() {
|
||||
if (keyFile.getConfig().contains("Keys")) return;
|
||||
keyFile.getConfig().set("Keys.Regular.Item Amount", 3);
|
||||
keyFile.getConfig().set("Keys.Regular.Amount overrides", Collections.singletonList("Tools:2"));
|
||||
keyFile.getConfig().set("Keys.Regular.Amount of kit received", 1);
|
||||
keyFile.getConfig().set("Keys.Ultra.Item Amount", -1);
|
||||
keyFile.getConfig().set("Keys.Ultra.Amount of kit received", 1);
|
||||
keyFile.getConfig().set("Keys.Insane.Item Amount", -1);
|
||||
keyFile.getConfig().set("Keys.Insane.Amount of kit received", 2);
|
||||
keyFile.saveConfig();
|
||||
}
|
||||
|
||||
private void setupConfig() {
|
||||
settingsManager.updateSettings();
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void loadLanguageFile() {
|
||||
Lang.setFile(langFile.getConfig());
|
||||
|
||||
for (final Lang value : Lang.values()) {
|
||||
langFile.getConfig().addDefault(value.getPath(), value.getDefault());
|
||||
}
|
||||
|
||||
langFile.getConfig().options().copyDefaults(true);
|
||||
langFile.saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload plugin yaml files.
|
||||
*/
|
||||
public void reload() {
|
||||
try {
|
||||
reloadConfig();
|
||||
kitFile.reloadConfig();
|
||||
langFile.reloadConfig();
|
||||
loadLanguageFile();
|
||||
references = new References();
|
||||
reloadConfig();
|
||||
loadFromFile();
|
||||
holo.updateHolograms();
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get instance of KitManager
|
||||
*
|
||||
* @return instance of KitManager
|
||||
*/
|
||||
public KitManager getKitManager() {
|
||||
return kitManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get instance of KeyManager
|
||||
*
|
||||
* @return instance of KeyManager
|
||||
*/
|
||||
public KeyManager getKeyManager() {
|
||||
return keyManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab instance of Kit File Configuration Wrapper
|
||||
*
|
||||
* @return instance of KitFile
|
||||
*/
|
||||
public ConfigWrapper getKitFile() {
|
||||
return kitFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get KitEditor.
|
||||
*
|
||||
* @return KitEditor.
|
||||
*/
|
||||
public KitEditor getKitEditor() {
|
||||
return kitEditor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get BlockEditor.
|
||||
*
|
||||
* @return BlockEditor.
|
||||
*/
|
||||
public BlockEditor getBlockEditor() {
|
||||
return blockEditor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab instance of Data File Configuration Wrapper
|
||||
*
|
||||
* @return instance of DataFile
|
||||
*/
|
||||
public ConfigWrapper getDataFile() {
|
||||
return dataFile;
|
||||
}
|
||||
|
||||
public SettingsManager getSettingsManager() {
|
||||
return settingsManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab instance of UltimateKits
|
||||
*
|
||||
* @return instance of UltimateKits
|
||||
*/
|
||||
public static UltimateKits getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.songoda.ultimatekits.conversion;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.conversion.hooks.DefaultHook;
|
||||
import com.songoda.ultimatekits.conversion.hooks.EssentialsHook;
|
||||
import com.songoda.ultimatekits.conversion.hooks.UltimateCoreHook;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Convert {
|
||||
|
||||
private final UltimateKits instance;
|
||||
|
||||
private Hook hook;
|
||||
|
||||
public Convert(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
if (instance.getServer().getPluginManager().getPlugin("Essentials") != null) {
|
||||
try {
|
||||
Class.forName("com.earth2me.essentials.metrics.MetricsListener");
|
||||
hook = new DefaultHook();
|
||||
} catch (ClassNotFoundException ex) {
|
||||
hook = new EssentialsHook();
|
||||
}
|
||||
} else if (instance.getServer().getPluginManager().getPlugin("UltimateCore") != null) {
|
||||
hook = new UltimateCoreHook();
|
||||
} else {
|
||||
hook = new DefaultHook();
|
||||
}
|
||||
|
||||
if (hook.getKits().size() == 0) hook = new DefaultHook();
|
||||
|
||||
convertKits();
|
||||
}
|
||||
|
||||
|
||||
public void convertKits() {
|
||||
Set<String> kits = hook.getKits();
|
||||
|
||||
if (instance.getKitFile().getConfig().contains("Kits")) return;
|
||||
|
||||
for (String kit : kits) {
|
||||
List<String> serializedItems = new ArrayList<>();
|
||||
for (ItemStack item : hook.getItems(kit)) {
|
||||
serializedItems.add(Methods.serializeItemStack(item));
|
||||
}
|
||||
instance.getKitFile().getConfig().set("Kits." + kit + ".items", serializedItems);
|
||||
instance.getKitFile().getConfig().set("Kits." + kit + ".delay", hook.getDelay(kit));
|
||||
instance.getKitFile().getConfig().set("Kits." + kit + ".price", 0D);
|
||||
}
|
||||
instance.getKitFile().saveConfig();
|
||||
}
|
||||
}
|
14
src/main/java/com/songoda/ultimatekits/conversion/Hook.java
Normal file
14
src/main/java/com/songoda/ultimatekits/conversion/Hook.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.songoda.ultimatekits.conversion;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface Hook {
|
||||
|
||||
Set<String> getKits();
|
||||
|
||||
Set<ItemStack> getItems(String kit);
|
||||
|
||||
long getDelay(String kit);
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.songoda.ultimatekits.conversion.hooks;
|
||||
|
||||
import com.songoda.ultimatekits.conversion.Hook;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class DefaultHook implements Hook {
|
||||
|
||||
public enum Kits {
|
||||
TOOLS(10, "STONE_PICKAXE 1", "STONE_AXE 1", "STONE_SPADE 1", "STONE_HOE 1"),
|
||||
BETTER_TOOLS(300, "DIAMOND_PICKAXE 1 DIG_SPEED:5 DURABILITY:2", "DIAMOND_AXE 1 DIG_SPEED:2 DURABILITY:2", "DIAMOND_SPADE 1 DIG_SPEED:1", "DIAMOND_HOE 1 DURABILITY:3"),
|
||||
BRIANNA(0, "SKULL_ITEM:3 1 player:Songoda");
|
||||
|
||||
public String[] items;
|
||||
public int delay;
|
||||
|
||||
Kits(int delay, String... items) {
|
||||
this.items = items;
|
||||
this.delay = delay;
|
||||
}
|
||||
}
|
||||
|
||||
public Set<ItemStack> getItems(String kitName) {
|
||||
Set<ItemStack> items = new HashSet<>();
|
||||
|
||||
for (Kits kit : Kits.values()) {
|
||||
if (!kit.name().equalsIgnoreCase(kitName)) continue;
|
||||
for (String string : kit.items) {
|
||||
items.add(Methods.deserializeItemStack(string));
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
public Set<String> getKits() {
|
||||
Set<String> kits = new HashSet<>();
|
||||
|
||||
for (Kits kit : Kits.values()) {
|
||||
kits.add(kit.name().toLowerCase());
|
||||
}
|
||||
|
||||
return kits;
|
||||
}
|
||||
|
||||
public long getDelay(String kitName) {
|
||||
for (Kits kit : Kits.values()) {
|
||||
if (!kit.name().equalsIgnoreCase(kitName)) continue;
|
||||
return kit.delay;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.songoda.ultimatekits.conversion.hooks;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.Kit;
|
||||
import com.earth2me.essentials.MetaItemStack;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.conversion.Hook;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class EssentialsHook implements Hook {
|
||||
|
||||
private Essentials essentials;
|
||||
|
||||
public EssentialsHook() {
|
||||
essentials = (Essentials) UltimateKits.getInstance().getServer().getPluginManager().getPlugin("Essentials");
|
||||
}
|
||||
|
||||
public Set<ItemStack> getItems(String kitName) {
|
||||
Set<ItemStack> stacks = new HashSet<>();
|
||||
try {
|
||||
Kit kit = new Kit(kitName, essentials);
|
||||
|
||||
for (String nonParse : kit.getItems()) {
|
||||
String[] parts = nonParse.split(" +");
|
||||
ItemStack item = essentials.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
|
||||
MetaItemStack metaStack = new MetaItemStack(item);
|
||||
if (parts.length > 2 != nonParse.startsWith("/")) {
|
||||
try {
|
||||
metaStack.parseStringMeta(null, true, parts, 2, essentials);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
stacks.add(metaStack.getItemStack());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public Set<String> getKits() {
|
||||
ConfigurationSection cs = essentials.getSettings().getKits();
|
||||
Set<String> kits = new HashSet<>();
|
||||
try {
|
||||
cs.getKeys(false);
|
||||
} catch (Exception e) {
|
||||
return kits;
|
||||
}
|
||||
kits.addAll(cs.getKeys(false));
|
||||
return kits;
|
||||
}
|
||||
|
||||
public long getDelay(String kitName) {
|
||||
return Integer.toUnsignedLong((int)essentials.getSettings().getKit(kitName).getOrDefault("delay", 0));
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.songoda.ultimatekits.conversion.hooks;
|
||||
|
||||
import bammerbom.ultimatecore.bukkit.api.UC;
|
||||
import bammerbom.ultimatecore.bukkit.api.UKit;
|
||||
import com.songoda.ultimatekits.conversion.Hook;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class UltimateCoreHook implements Hook {
|
||||
|
||||
@Override
|
||||
public Set<String> getKits() {
|
||||
Set<String> list = new HashSet<>();
|
||||
List<UKit> kits = UC.getServer().getKits();
|
||||
for (UKit kit : kits) {
|
||||
list.add(kit.getName());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ItemStack> getItems(String kit) {
|
||||
UKit uKit = new UKit(kit);
|
||||
Set<ItemStack> items = new HashSet<>(uKit.getItems());
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDelay(String kit) {
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.songoda.ultimatekits.events;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class BlockListeners implements Listener {
|
||||
|
||||
private final UltimateKits instance;
|
||||
|
||||
public BlockListeners(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
try {
|
||||
Block b = event.getBlock();
|
||||
KitBlockData kitBlockData = instance.getKitManager().getKit(b.getLocation());
|
||||
if (kitBlockData == null) return;
|
||||
Kit kit = kitBlockData.getKit();
|
||||
instance.getKitManager().removeKitFromLocation(b.getLocation());
|
||||
instance.holo.updateHolograms();
|
||||
event.getPlayer().sendMessage(Arconix.pl().getApi().format().formatText(UltimateKits.getInstance().references.getPrefix() + "&8Kit &9" + kit.getName() + " &8unassigned from: &a" + b.getType() + "&8."));
|
||||
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
try {
|
||||
Block b = e.getBlockAgainst();
|
||||
KitBlockData kitBlockData = instance.getKitManager().getKit(b.getLocation());
|
||||
if (kitBlockData != null) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
} catch (Exception ee) {
|
||||
Debugger.runReport(ee);
|
||||
}
|
||||
}
|
||||
}
|
149
src/main/java/com/songoda/ultimatekits/events/ChatListeners.java
Normal file
149
src/main/java/com/songoda/ultimatekits/events/ChatListeners.java
Normal file
@ -0,0 +1,149 @@
|
||||
package com.songoda.ultimatekits.events;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.KitEditor;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitEditorPlayerData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class ChatListeners implements Listener {
|
||||
|
||||
private final UltimateKits instance;
|
||||
|
||||
public ChatListeners(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
try {
|
||||
final Player p = e.getPlayer();
|
||||
|
||||
KitEditorPlayerData playerData = instance.getKitEditor().getDataFor(p);
|
||||
|
||||
if (playerData.getEditorType() == KitEditorPlayerData.EditorType.NOTIN) return;
|
||||
|
||||
KitEditor edit = instance.getKitEditor();
|
||||
String msg = e.getMessage().trim();
|
||||
Kit kit = playerData.getKit();
|
||||
e.setCancelled(true);
|
||||
|
||||
switch (playerData.getEditorType()) {
|
||||
case PRICE:
|
||||
if (instance.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
p.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&8You must have &aVault &8installed to utilize economy.."));
|
||||
} else if (!Arconix.pl().getApi().doMath().isNumeric(msg)) {
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&a" + msg + " &8is not a number. Please do not include a &a$&8."));
|
||||
} else {
|
||||
|
||||
if (kit.getLink() != null) {
|
||||
kit.setLink(null);
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8LINK has been removed from this kit. Note you cannot have ECO & LINK set at the same time.."));
|
||||
}
|
||||
Double eco = Double.parseDouble(msg);
|
||||
kit.setPrice(eco);
|
||||
instance.holo.updateHolograms();
|
||||
}
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
edit.selling(p);
|
||||
break;
|
||||
case DELAY:
|
||||
if (!Arconix.pl().getApi().doMath().isNumeric(msg)) {
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&a" + msg + " &8is not a number. Please do not include a &a$&8."));
|
||||
} else {
|
||||
kit.setDelay(Integer.parseInt(msg));
|
||||
}
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
edit.general(p);
|
||||
break;
|
||||
case LINK:
|
||||
if (kit.getPrice() != 0) {
|
||||
kit.setPrice(0);
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8ECO has been removed from this kit. Note you cannot have ECO & LINK set at the same time.."));
|
||||
}
|
||||
kit.setLink(msg);
|
||||
instance.holo.updateHolograms();
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
edit.selling(p);
|
||||
break;
|
||||
case TITLE:
|
||||
kit.setTitle(msg);
|
||||
instance.saveConfig();
|
||||
instance.holo.updateHolograms();
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Title &5" + msg + "&8 added to Kit &a" + kit.getShowableName() + "&8."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
edit.gui(p);
|
||||
break;
|
||||
case COMMAND:
|
||||
ItemStack parseStack = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta meta = parseStack.getItemMeta();
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
|
||||
int index = 0;
|
||||
while (index < msg.length()) {
|
||||
lore.add("§a/" + msg.substring(index, Math.min(index + 30, msg.length())));
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(Lang.COMMAND.getConfigValue());
|
||||
parseStack.setItemMeta(meta);
|
||||
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Command &5" + msg + "&8 has been added to your kit."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
edit.openOverview(kit, p,false, parseStack);
|
||||
break;
|
||||
case MONEY:
|
||||
ItemStack parseStack2 = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta meta2 = parseStack2.getItemMeta();
|
||||
|
||||
ArrayList<String> lore2 = new ArrayList<>();
|
||||
|
||||
int index2 = 0;
|
||||
while (index2 < msg.length()) {
|
||||
lore2.add("§a$" + msg.substring(index2, Math.min(index2 + 30, msg.length())));
|
||||
index2 += 30;
|
||||
}
|
||||
meta2.setLore(lore2);
|
||||
meta2.setDisplayName(Lang.MONEY.getConfigValue());
|
||||
parseStack2.setItemMeta(meta2);
|
||||
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Money &5$" + msg + "&8 has been added to your kit."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
edit.openOverview(kit, p, false, parseStack2);
|
||||
break;
|
||||
default:
|
||||
e.setCancelled(false);
|
||||
break;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCommandPreprocess(AsyncPlayerChatEvent event) {
|
||||
try {
|
||||
if (event.getMessage().equalsIgnoreCase("/kit") || event.getMessage().equalsIgnoreCase("/kit")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.songoda.ultimatekits.events;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||
|
||||
public class EntityListeners implements Listener {
|
||||
|
||||
private final UltimateKits instance;
|
||||
|
||||
public EntityListeners(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerEntityInteract(EntityDamageEvent e) {
|
||||
try {
|
||||
if (e.getEntity().getType() != EntityType.ARMOR_STAND || instance.getConfig().getString("data.holo") == null) {
|
||||
return;
|
||||
}
|
||||
ConfigurationSection section = instance.getConfig().getConfigurationSection("data.holo");
|
||||
for (String loc : section.getKeys(false)) {
|
||||
String str[] = loc.split(":");
|
||||
World w = Bukkit.getServer().getWorld(str[1].substring(0, str[1].length() - 1));
|
||||
double x = Double.parseDouble(str[2].substring(0, str[2].length() - 1)) + .5;
|
||||
double z = Double.parseDouble(str[4]) + .5;
|
||||
if (w == e.getEntity().getLocation().getWorld() && x == e.getEntity().getLocation().getX() && z == e.getEntity().getLocation().getZ()) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerEntityInteract(PlayerInteractAtEntityEvent e) {
|
||||
try {
|
||||
if (e.getRightClicked().getType() != EntityType.ARMOR_STAND || instance.getConfig().getString("data.holo") == null) {
|
||||
return;
|
||||
}
|
||||
ConfigurationSection section = instance.getConfig().getConfigurationSection("data.holo");
|
||||
for (String loc : section.getKeys(false)) {
|
||||
String str[] = loc.split(":");
|
||||
World w = Bukkit.getServer().getWorld(str[1].substring(0, str[1].length() - 1));
|
||||
double x = Double.parseDouble(str[2].substring(0, str[2].length() - 1)) + .5;
|
||||
double z = Double.parseDouble(str[4]) + .5;
|
||||
if (w == e.getRightClicked().getLocation().getWorld() && x == e.getRightClicked().getLocation().getX() && z == e.getRightClicked().getLocation().getZ()) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package com.songoda.ultimatekits.events;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.object.KitType;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public class InteractListeners implements Listener {
|
||||
|
||||
private final UltimateKits instance;
|
||||
|
||||
public InteractListeners(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockInteract(PlayerInteractEvent e) {
|
||||
try {
|
||||
boolean chand = true; // This needs to be out of my code.
|
||||
if (!UltimateKits.getInstance().v1_7 && !UltimateKits.getInstance().v1_8) {
|
||||
if (e.getHand() != EquipmentSlot.HAND) {
|
||||
chand = false;
|
||||
}
|
||||
}
|
||||
|
||||
Block b = e.getClickedBlock();
|
||||
|
||||
if (!chand) return;
|
||||
|
||||
if (e.getClickedBlock() == null) return;
|
||||
|
||||
KitBlockData kitBlockData = instance.getKitManager().getKit(b.getLocation());
|
||||
if (kitBlockData == null) return;
|
||||
Kit kit = kitBlockData.getKit();
|
||||
|
||||
String loc = Arconix.pl().getApi().serialize().serializeLocation(b);
|
||||
Player p = e.getPlayer();
|
||||
if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
|
||||
if (p.isSneaking()) return;
|
||||
e.setCancelled(true);
|
||||
|
||||
if (p.getItemInHand() != null && p.getItemInHand().getType() != null && p.getItemInHand().getType() == Material.TRIPWIRE_HOOK) {
|
||||
e.setCancelled(true);
|
||||
kit.give(p, true, false, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (kitBlockData.getType() != KitType.PREVIEW) {
|
||||
if (kitBlockData.getType() == KitType.CRATE) {
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + Lang.NOT_KEY.getConfigValue()));
|
||||
} else if (kitBlockData.getType() == KitType.CLAIM) {
|
||||
if (!p.hasPermission("essentials.kit." + kit.getName().toLowerCase()) || !p.hasPermission("ultimatekits.kit." + kit.getName().toLowerCase())) {
|
||||
p.sendMessage(instance.references.getPrefix() + Lang.NO_PERM.getConfigValue());
|
||||
return;
|
||||
}
|
||||
if (kit.getNextUse(p) <= 0) {
|
||||
kit.give(p, false, false, false);
|
||||
kit.updateDelay(p);
|
||||
} else {
|
||||
long time = kit.getNextUse(p);
|
||||
p.sendMessage(instance.references.getPrefix() + Lang.NOT_YET.getConfigValue(Arconix.pl().getApi().format().readableTime(time)));
|
||||
}
|
||||
}
|
||||
} else if (kit.getLink() != null || kit.getPrice() != 0) {
|
||||
kit.buy(p);
|
||||
} else {
|
||||
kit.display(p, false);
|
||||
}
|
||||
} else if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (b.getState() instanceof InventoryHolder || b.getType() == Material.ENDER_CHEST) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
if (p.isSneaking() && p.hasPermission("ultimatekits.admin")) {
|
||||
instance.getBlockEditor().openOverview(p, b.getLocation());
|
||||
return;
|
||||
}
|
||||
if (p.getItemInHand() != null && p.getItemInHand().getType() != null && p.getItemInHand().getType() == Material.TRIPWIRE_HOOK) {
|
||||
e.setCancelled(true);
|
||||
kit.give(p, true, false, false);
|
||||
return;
|
||||
}
|
||||
kit.display(p, false);
|
||||
|
||||
}
|
||||
} catch (Exception x) {
|
||||
Debugger.runReport(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,352 @@
|
||||
package com.songoda.ultimatekits.events;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.BlockEditor;
|
||||
import com.songoda.ultimatekits.kit.KitEditor;
|
||||
import com.songoda.ultimatekits.kit.KitsGUI;
|
||||
import com.songoda.ultimatekits.kit.object.BlockEditorPlayerData;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitEditorPlayerData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
public class InventoryListeners implements Listener {
|
||||
|
||||
private final UltimateKits instance;
|
||||
|
||||
public InventoryListeners(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event) {
|
||||
try {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (instance.buy.containsKey(player.getUniqueId())) {
|
||||
if (event.getSlot() == 11) {
|
||||
Kit kit = instance.getKitManager().getKit(instance.buy.get(player.getUniqueId()));
|
||||
kit.buyWithEconomy(player);
|
||||
player.closeInventory();
|
||||
instance.buy.remove(player.getUniqueId());
|
||||
} else if (event.getSlot() == 15) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + Lang.BUYCANCELLED.getConfigValue()));
|
||||
player.closeInventory();
|
||||
instance.buy.remove(player.getUniqueId());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
} else if (instance.whereAt.containsKey(event.getWhoClicked().getUniqueId()) && instance.whereAt.get(event.getWhoClicked().getUniqueId()).equals("kits")) {
|
||||
event.setCancelled(true);
|
||||
if (instance.references.isPlaySound())
|
||||
player.playSound(event.getWhoClicked().getLocation(), instance.references.getSound(), 10.0F, 1.0F);
|
||||
if (event.getAction() == InventoryAction.NOTHING
|
||||
|| event.getCurrentItem().getType() == Material.AIR
|
||||
|| event.getCurrentItem().getItemMeta().getDisplayName() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack clicked = event.getCurrentItem();
|
||||
int page = instance.page.get(player.getUniqueId());
|
||||
|
||||
if (event.getClick() == ClickType.MIDDLE && player.hasPermission("ultimatekits.admin")) {
|
||||
if (instance.kitsMode.contains(player.getUniqueId())) {
|
||||
instance.kitsMode.remove(player.getUniqueId());
|
||||
} else {
|
||||
instance.kitsMode.add(player.getUniqueId());
|
||||
}
|
||||
KitsGUI.show(player, page);
|
||||
return;
|
||||
}
|
||||
|
||||
String kitName = instance.kits.get(clicked.getItemMeta().getDisplayName());
|
||||
|
||||
Kit kit = instance.getKitManager().getKit(kitName);
|
||||
|
||||
if (instance.kitsMode.contains(player.getUniqueId())) {
|
||||
if (event.getClick() == ClickType.RIGHT) {
|
||||
instance.getKitManager().moveKit(kit, true);
|
||||
} else if (event.getClick() == ClickType.LEFT) {
|
||||
instance.getKitManager().moveKit(kit, false);
|
||||
|
||||
}
|
||||
KitsGUI.show(player, page);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getSlot() == 4) return;
|
||||
|
||||
if (ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(Lang.NEXT.getConfigValue()))) {
|
||||
KitsGUI.show(player, page + 1);
|
||||
} else if (ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(Lang.LAST.getConfigValue()))) {
|
||||
KitsGUI.show(player, page - 1);
|
||||
} else if (ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(Lang.EXIT.getConfigValue()))) {
|
||||
player.closeInventory();
|
||||
} else if (!ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).equalsIgnoreCase("")) {
|
||||
if (!clicked.getItemMeta().hasDisplayName()) return;
|
||||
|
||||
if (event.getClick().isLeftClick()) {
|
||||
kit.display(player, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getClick().isRightClick()) {
|
||||
kit.buy(player);
|
||||
KitsGUI.show(player, page);
|
||||
}
|
||||
}
|
||||
} else if (instance.whereAt.containsKey(event.getWhoClicked().getUniqueId()) && instance.whereAt.get(event.getWhoClicked().getUniqueId()).equals("display")) {
|
||||
event.setCancelled(true);
|
||||
if (instance.references.isPlaySound()) {
|
||||
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), instance.references.getSound(), 10.0F, 1.0F);
|
||||
}
|
||||
if (event.getAction() == InventoryAction.NOTHING
|
||||
|| event.getCurrentItem().getType() == Material.AIR
|
||||
|| event.getCurrentItem().getItemMeta().getDisplayName() == null) {
|
||||
return;
|
||||
}
|
||||
ItemStack clicked = event.getCurrentItem();
|
||||
if (ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(Lang.BACK.getConfigValue()))) {
|
||||
KitsGUI.show(player, 1);
|
||||
}
|
||||
if (ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(Lang.EXIT.getConfigValue()))) {
|
||||
player.closeInventory();
|
||||
}
|
||||
if (ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(Lang.BUYNOW.getConfigValue()))) {
|
||||
player.closeInventory();
|
||||
String kitName = instance.inKit.get(player.getUniqueId()).getName();
|
||||
Kit kit = instance.getKitManager().getKit(kitName);
|
||||
kit.buy(player);
|
||||
}
|
||||
} else if (instance.getBlockEditor().getDataFor(player).getEditorType() != BlockEditorPlayerData.EditorType.NOTIN) {
|
||||
BlockEditor edit = instance.getBlockEditor();
|
||||
if (instance.getBlockEditor().getDataFor(player).getEditorType() == BlockEditorPlayerData.EditorType.OVERVIEW) {
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getCurrentItem().getItemMeta().getDisplayName() == null) return;
|
||||
ItemStack clicked = event.getCurrentItem();
|
||||
if (ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(Lang.EXIT.getConfigValue())))
|
||||
player.closeInventory();
|
||||
if ((event.getSlot() > 44 || event.getSlot() < 9) && event.getInventory().getType() == InventoryType.CHEST) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
switch (event.getSlot()) {
|
||||
case 11:
|
||||
edit.changeDisplayType(player);
|
||||
break;
|
||||
case 13:
|
||||
edit.decor(player);
|
||||
break;
|
||||
case 15:
|
||||
instance.getKitEditor().openOverview(instance.getBlockEditor().getDataFor(player).getKit(), player, true, null);
|
||||
break;
|
||||
}
|
||||
} else if (instance.getBlockEditor().getDataFor(player).getEditorType() == BlockEditorPlayerData.EditorType.DECOR) {
|
||||
event.setCancelled(true);
|
||||
switch (event.getSlot()) {
|
||||
case 10:
|
||||
edit.toggleHologram(player);
|
||||
break;
|
||||
case 12:
|
||||
edit.toggleParticles(player);
|
||||
break;
|
||||
case 14:
|
||||
edit.toggleDisplayItems(player);
|
||||
break;
|
||||
case 16:
|
||||
edit.toggleItemOverride(player);
|
||||
break;
|
||||
}
|
||||
if (event.getCurrentItem().getItemMeta() == null || !event.getCurrentItem().getItemMeta().hasDisplayName())
|
||||
return;
|
||||
if (ChatColor.stripColor(event.getCurrentItem().getItemMeta().getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(Lang.EXIT.getConfigValue()))) {
|
||||
player.closeInventory();
|
||||
}
|
||||
if (ChatColor.stripColor(event.getCurrentItem().getItemMeta().getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(Lang.BACK.getConfigValue()))) {
|
||||
if (event.getInventory().getTitle().contains("Editing decor for")) {
|
||||
instance.getBlockEditor().openOverview(player, instance.getBlockEditor().getDataFor(player).getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (instance.getKitEditor().getDataFor(player).getEditorType() != KitEditorPlayerData.EditorType.NOTIN) {
|
||||
KitEditor edit = instance.getKitEditor();
|
||||
if (instance.getKitEditor().getDataFor(player).getEditorType() == KitEditorPlayerData.EditorType.OVERVIEW) {
|
||||
KitEditorPlayerData playerData = edit.getDataFor(player);
|
||||
if ((event.getSlot() < 10 || event.getSlot() > 43) || event.getSlot() == 17 || event.getSlot() == 36) {
|
||||
if (event.getInventory() != null && event.getInventory().getType() == InventoryType.CHEST) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (event.getInventory() == player.getInventory()
|
||||
&&(!playerData.isInInventory())) {
|
||||
event.setCancelled(true);
|
||||
if (event.getInventory() == player.getInventory()) {
|
||||
switch (event.getSlot()) {
|
||||
case 9:
|
||||
edit.general(player);
|
||||
break;
|
||||
case 10:
|
||||
edit.selling(player);
|
||||
break;
|
||||
case 12:
|
||||
edit.gui(player);
|
||||
break;
|
||||
case 13:
|
||||
edit.createCommand(player);
|
||||
break;
|
||||
case 14:
|
||||
edit.createMoney(player);
|
||||
break;
|
||||
case 17:
|
||||
edit.saveKit(player, player.getOpenInventory().getTopInventory());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event.getSlot() == 49) {
|
||||
if (!playerData.isInInventory()) {
|
||||
player.getInventory().setContents(playerData.getInventory());
|
||||
playerData.setInInventory(true);
|
||||
player.updateInventory();
|
||||
} else edit.getInvItems(player, playerData);
|
||||
edit.updateInvButton(event.getInventory(), playerData);
|
||||
}
|
||||
} else if (instance.getKitEditor().getDataFor(player).getEditorType() == KitEditorPlayerData.EditorType.SELLING) {
|
||||
event.setCancelled(true);
|
||||
switch (event.getSlot()) {
|
||||
case 11:
|
||||
edit.setNoSale(player);
|
||||
break;
|
||||
case 13:
|
||||
edit.editLink(player);
|
||||
break;
|
||||
case 15:
|
||||
edit.editPrice(player);
|
||||
break;
|
||||
}
|
||||
} else if (instance.getKitEditor().getDataFor(player).getEditorType() == KitEditorPlayerData.EditorType.GUI) {
|
||||
event.setCancelled(true);
|
||||
switch (event.getSlot()) {
|
||||
case 11:
|
||||
if (event.getClick() == ClickType.RIGHT)
|
||||
edit.setTitle(player,false);
|
||||
else if (event.getClick() == ClickType.LEFT)
|
||||
edit.setTitle(player,true);
|
||||
break;
|
||||
case 13:
|
||||
if (event.getClick() == ClickType.LEFT)
|
||||
edit.setKitsDisplayItem(player, true);
|
||||
else if (event.getClick() == ClickType.RIGHT)
|
||||
edit.setKitsDisplayItem(player,false);
|
||||
break;
|
||||
case 15:
|
||||
edit.hide(player);
|
||||
break;
|
||||
}
|
||||
} else if (instance.getKitEditor().getDataFor(player).getEditorType() == KitEditorPlayerData.EditorType.GENERAL) {
|
||||
event.setCancelled(true);
|
||||
switch (event.getSlot()) {
|
||||
case 13:
|
||||
edit.setDelay(player);
|
||||
break;
|
||||
case 15:
|
||||
instance.getKitManager().removeKit(edit.getDataFor(player).getKit());
|
||||
player.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&cKit destroyed successfully."));
|
||||
player.closeInventory();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (event.getCurrentItem() == null) return;
|
||||
if (event.getCurrentItem().getItemMeta() == null || !event.getCurrentItem().getItemMeta().hasDisplayName())
|
||||
return;
|
||||
if (ChatColor.stripColor(event.getCurrentItem().getItemMeta().getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(Lang.EXIT.getConfigValue()))) {
|
||||
player.closeInventory();
|
||||
}
|
||||
if (ChatColor.stripColor(event.getCurrentItem().getItemMeta().getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(Lang.BACK.getConfigValue()))) {
|
||||
if (event.getInventory().getTitle().contains("You are editing kit")) {
|
||||
instance.getBlockEditor().openOverview(player, instance.getBlockEditor().getDataFor(player).getLocation());
|
||||
} else {
|
||||
edit.openOverview(edit.getDataFor(player).getKit(), player, false, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDrag(InventoryDragEvent event) {
|
||||
try {
|
||||
if (!event.getInventory().getTitle().startsWith("Previewing")
|
||||
|| !(instance.whereAt.containsKey(event.getWhoClicked().getUniqueId()) && instance.whereAt.get(event.getWhoClicked().getUniqueId()).equals("display")))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
if (instance.references.isPlaySound())
|
||||
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), instance.references.getSound(), 10.0F, 1.0F);
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(InventoryInteractEvent event) {
|
||||
try {
|
||||
if (!event.getInventory().getTitle().startsWith("Previewing")
|
||||
|| !(instance.whereAt.containsKey(event.getWhoClicked().getUniqueId()) && instance.whereAt.get(event.getWhoClicked().getUniqueId()).equals("display")))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
if (instance.references.isPlaySound())
|
||||
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), instance.references.getSound(), 10.0F, 1.0F);
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClose(InventoryCloseEvent event) {
|
||||
try {
|
||||
final Player p = (Player) event.getPlayer();
|
||||
|
||||
KitEditorPlayerData kitPlayerData = instance.getKitEditor().getDataFor(p);
|
||||
|
||||
if (!kitPlayerData.isInInventory() && kitPlayerData.getInventory().length != 0) {
|
||||
p.getInventory().setContents(kitPlayerData.getInventory());
|
||||
kitPlayerData.setInInventory(true);
|
||||
p.updateInventory();
|
||||
}
|
||||
|
||||
kitPlayerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
|
||||
BlockEditorPlayerData blockPlayerData = instance.getBlockEditor().getDataFor(p);
|
||||
blockPlayerData.setEditorType(BlockEditorPlayerData.EditorType.NOTIN);
|
||||
|
||||
instance.buy.remove(p.getUniqueId());
|
||||
|
||||
if (!instance.whereAt.containsKey(p.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
instance.whereAt.remove(p.getUniqueId());
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(instance, () -> {
|
||||
if (!p.getOpenInventory().getTopInventory().getType().equals(InventoryType.CHEST))
|
||||
p.closeInventory();
|
||||
}, 1L);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.songoda.ultimatekits.events;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.BlockEditorPlayerData;
|
||||
import com.songoda.ultimatekits.kit.object.KitEditorPlayerData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class QuitListeners implements Listener {
|
||||
|
||||
private final UltimateKits instance;
|
||||
|
||||
public QuitListeners(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void quit(PlayerQuitEvent event) {
|
||||
try {
|
||||
Player p = event.getPlayer();
|
||||
|
||||
KitEditorPlayerData playerData = instance.getKitEditor().getDataFor(p);
|
||||
|
||||
if (!playerData.isInInventory() && playerData.getInventory().length != 0) {
|
||||
p.getInventory().setContents(playerData.getInventory());
|
||||
playerData.setInInventory(true);
|
||||
p.updateInventory();
|
||||
}
|
||||
instance.getKitEditor().removeFromInstance(p);
|
||||
|
||||
BlockEditorPlayerData blockPlayerData = instance.getBlockEditor().getDataFor(p);
|
||||
blockPlayerData.setEditorType(BlockEditorPlayerData.EditorType.NOTIN);
|
||||
|
||||
instance.whereAt.remove(p.getUniqueId());
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,303 @@
|
||||
package com.songoda.ultimatekits.handlers;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.key.Key;
|
||||
import com.songoda.ultimatekits.kit.KitsGUI;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class CommandHandler implements CommandExecutor {
|
||||
|
||||
private final UltimateKits instance;
|
||||
|
||||
public CommandHandler(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void help(CommandSender sender, int page) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText("&7Page: &a" + page + " of 2 ======================"));
|
||||
if (page == 1) {
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7" + instance.getDescription().getVersion() + " Created by &5&l&oBrianna"));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- " + "&cKits &7View all available kit."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- " + "&dPK <kit> &7Preview a kit."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- " + "&aUK help <page> &7Displays this page."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- " + "&aUK reload &7Reload the Configuration and Language files."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- " + "&aUK edit <kit> &7Edit a kit."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- " + "&aUK set <kit> &7Make the block you are looking at display a kit"));
|
||||
} else if (page == 2) {
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- " + "&aUK createkit <kit> &7Create a kit in a GUI."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- " + "&aUK remove &7Remove a kit from the block you are looking at."));
|
||||
StringBuilder keys = new StringBuilder();
|
||||
for (Key key : instance.getKeyManager().getKeys()) {
|
||||
keys.append("/").append(key.getName());
|
||||
}
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- " + "&aUK key <kit/all> <" + keys.substring(1) + "> <player/all> <amount> &7Give a kit key to the players of your server. These keys can be used to redeem kit."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText("&aTo edit a kit block hold shift and right click it."));
|
||||
} else {
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "That page does not exist!"));
|
||||
}
|
||||
sender.sendMessage("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
try {
|
||||
if (cmd.getName().equalsIgnoreCase("kits")) {
|
||||
KitsGUI.show((Player) sender, 1);
|
||||
}
|
||||
if (cmd.getName().equalsIgnoreCase("kit")) {
|
||||
if (args.length == 0) {
|
||||
KitsGUI.show((Player) sender, 1);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
Player p = (Player) sender;
|
||||
String kitName = args[0].toLowerCase();
|
||||
if (!Methods.doesKitExist(kitName)) {
|
||||
p.sendMessage(instance.references.getPrefix() + Lang.KIT_DOESNT_EXIST.getConfigValue(kitName));
|
||||
return true;
|
||||
}
|
||||
Kit kit = instance.getKitManager().getKit(kitName);
|
||||
if (sender.hasPermission("ultimatekits.admin")) {
|
||||
kit.give(p, false, false, true);
|
||||
} else {
|
||||
kit.buy(p);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
String kitName = args[0].toLowerCase();
|
||||
if (!Methods.doesKitExist(kitName)) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.KIT_DOESNT_EXIST.getConfigValue(kitName));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Bukkit.getPlayerExact(args[1]) == null) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.PLAYER_NOT_FOUND.getConfigValue(kitName));
|
||||
return true;
|
||||
}
|
||||
Player p2 = Bukkit.getPlayer(args[1]);
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
if (!Methods.canGiveKit(p)) {
|
||||
p.sendMessage(instance.references.getPrefix() + Lang.NO_PERM.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Kit kit = instance.getKitManager().getKit(kitName);
|
||||
kit.give(p2, false, false, true);
|
||||
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&7You gave &9" + p2.getDisplayName() + "&7 kit &9" + kit.getShowableName() + "&7."));
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.SYNTAX.getConfigValue()));
|
||||
return true;
|
||||
|
||||
}
|
||||
if (cmd.getName().equalsIgnoreCase("ultimatekits")) {
|
||||
if (instance.getConfig().getBoolean("Main.Block Help Page For Non Admins") && !sender.hasPermission("ultimatekits.admin")) {
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7" + instance.getDescription().getVersion() + " " + Lang.NO_PERM.getConfigValue()));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0 || args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
|
||||
if (args.length == 2) {
|
||||
help(sender, Integer.parseInt(args[1]));
|
||||
} else {
|
||||
help(sender, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("edit")) {
|
||||
Player player = (Player) sender;
|
||||
Block block = player.getTargetBlock(null, 200);
|
||||
String loc = Arconix.pl().getApi().serialize().serializeLocation(block);
|
||||
if (args.length > 2) return true;
|
||||
if (!player.hasPermission("ultimatekits.admin")) {
|
||||
player.sendMessage(instance.references.getPrefix() + Lang.NO_PERM.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
if (instance.getConfig().getString("data.block." + loc) == null) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8This block does not contain a kit."));
|
||||
return true;
|
||||
}
|
||||
instance.getBlockEditor().openOverview(player, block.getLocation());
|
||||
} else {
|
||||
String kitStr = args[1].toLowerCase().trim();
|
||||
if (!Methods.doesKitExist(kitStr)) {
|
||||
player.sendMessage(instance.references.getPrefix() + Lang.KIT_DOESNT_EXIST.getConfigValue(kitStr));
|
||||
return true;
|
||||
}
|
||||
|
||||
instance.getKitEditor().openOverview(instance.getKitManager().getKit(kitStr), player, false, null);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("createkit")) {
|
||||
Player p = (Player) sender;
|
||||
if (args.length != 2) return true;
|
||||
if (!p.hasPermission("ultimatekits.admin")) {
|
||||
p.sendMessage(instance.references.getPrefix() + Lang.NO_PERM.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
String kitStr = args[1].toLowerCase();
|
||||
if (Methods.doesKitExist(kitStr)) {
|
||||
p.sendMessage(instance.references.getPrefix() + Lang.KIT_ALREADY_EXISTS.getConfigValue(kitStr));
|
||||
return true;
|
||||
}
|
||||
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText("&aThat kit doesn't exist. Creating it now."));
|
||||
Kit kit = new Kit(kitStr.trim());
|
||||
UltimateKits.getInstance().getKitManager().addKit(kit);
|
||||
instance.getKitEditor().openOverview(kit, p, false, null);
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (!sender.hasPermission("ultimatekits.admin")) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERM.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
|
||||
instance.reload();
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7Configuration files reloaded."));
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("settings")) {
|
||||
if (!sender.hasPermission("ultimatekits.admin")) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERM.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
Player p = (Player) sender;
|
||||
instance.getSettingsManager().openSettingsManager(p);
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("key")) {
|
||||
//UK key <kit/all> <"+keys.substring(1)+"> <player/all> <amount>
|
||||
if (args.length != 4 && args.length != 5) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.SYNTAX.getConfigValue()));
|
||||
return true;
|
||||
}
|
||||
if (!sender.hasPermission("ultimatekits.admin")) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERM.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
Kit kit = instance.getKitManager().getKit(args[1]);
|
||||
if (kit == null && !args[1].toLowerCase().equals("all")) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.KIT_DOESNT_EXIST.getConfigValue(kit));
|
||||
return true;
|
||||
}
|
||||
if (Bukkit.getPlayer(args[3]) == null && !args[3].trim().equalsIgnoreCase("all")) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&cThat username does not exist, or the user is offline!"));
|
||||
return true;
|
||||
}
|
||||
int amt = 1;
|
||||
if (args.length == 5) {
|
||||
if (!Arconix.pl().getApi().doMath().isNumeric(args[4])) {
|
||||
amt = 0;
|
||||
} else {
|
||||
amt = Integer.parseInt(args[4]);
|
||||
}
|
||||
}
|
||||
if (amt == 0) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&a" + args[3] + " &cis not a number."));
|
||||
return true;
|
||||
}
|
||||
|
||||
Key key = instance.getKeyManager().getKey(args[2]);
|
||||
if (key == null) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&a" + args[3] + " &cis not a key."));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (!args[3].trim().equals("all")) {
|
||||
Player p = Bukkit.getPlayer(args[3]);
|
||||
p.getInventory().addItem(key.getKeyItem(kit, amt));
|
||||
p.sendMessage(instance.references.getPrefix() + Lang.KEY_GIVEN.getConfigValue(kit.getShowableName()));
|
||||
return true;
|
||||
}
|
||||
for (Player pl : instance.getServer().getOnlinePlayers()) {
|
||||
pl.getInventory().addItem(key.getKeyItem(kit, amt));
|
||||
pl.sendMessage(instance.references.getPrefix() + Lang.KEY_GIVEN.getConfigValue(kit.getShowableName()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("set")) {
|
||||
if (args.length != 2) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.PREVIEW_NO_KIT_SUPPLIED.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
if (!sender.hasPermission("ultimatekits.admin")) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERM.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
String kit = args[1].toLowerCase();
|
||||
if (!Methods.doesKitExist(kit)) {
|
||||
player.sendMessage(instance.references.getPrefix() + Lang.KIT_DOESNT_EXIST.getConfigValue(kit));
|
||||
return true;
|
||||
}
|
||||
Block b = player.getTargetBlock(null, 200);
|
||||
instance.getKitManager().addKitToLocation(instance.getKitManager().getKit(kit), b.getLocation());
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Kit &a" + kit + " &8set to: &a" + b.getType().toString() + "&8."));
|
||||
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("remove")) {
|
||||
if (args.length != 1) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.PREVIEW_NO_KIT_SUPPLIED.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
if (!sender.hasPermission("ultimatekits.admin")) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERM.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
Block b = player.getTargetBlock(null, 200);
|
||||
Kit kit = instance.getKitManager().removeKitFromLocation(b.getLocation());
|
||||
UltimateKits.getInstance().holo.updateHolograms();
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(UltimateKits.getInstance().references.getPrefix() + "&8Kit &9" + kit.getName() + " &8unassigned from: &a" + b.getType().toString() + "&8."));
|
||||
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Invalid argument.. Looking for &9/pk " + args[0] + "&8?"));
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("previewkit")) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.NO_CONSOLE_ACCESS.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
Player p = (Player) sender;
|
||||
if (args.length != 1) {
|
||||
p.sendMessage(instance.references.getPrefix() + Lang.PREVIEW_NO_KIT_SUPPLIED.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
Kit kit = instance.getKitManager().getKit(args[0].toLowerCase().trim());
|
||||
if (kit == null) {
|
||||
p.sendMessage(instance.references.getPrefix() + Lang.KIT_DOESNT_EXIST.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
kit.display(p, false);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package com.songoda.ultimatekits.handlers;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class DisplayItemHandler {
|
||||
|
||||
private final UltimateKits instance;
|
||||
|
||||
public DisplayItemHandler(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(UltimateKits.getInstance(), this::displayItems, 30L, 30L);
|
||||
}
|
||||
|
||||
|
||||
private void displayItems() {
|
||||
try {
|
||||
for (KitBlockData kitBlockData : instance.getKitManager().getKitLocations().values()) {
|
||||
displayItem(kitBlockData);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
public void displayItem(KitBlockData kitBlockData) {
|
||||
Location location = kitBlockData.getLocation();
|
||||
location.add(0.5, 0, 0.5);
|
||||
|
||||
Kit kit = kitBlockData.getKit();
|
||||
|
||||
List<ItemStack> list = kit.getReadableContents(null, false);
|
||||
for (Entity e : location.getChunk().getEntities()) {
|
||||
if (e.getType() != EntityType.DROPPED_ITEM
|
||||
|| e.getLocation().getX() != location.getX()
|
||||
|| e.getLocation().getZ() != location.getZ()) {
|
||||
continue;
|
||||
}
|
||||
Item i = (Item) e;
|
||||
if (i.getItemStack().getItemMeta().getDisplayName() == null) {
|
||||
i.remove();
|
||||
return;
|
||||
}
|
||||
int inum = Integer.parseInt(i.getItemStack().getItemMeta().getDisplayName()) + 1;
|
||||
if (inum > list.size()) inum = 1;
|
||||
|
||||
ItemStack is = list.get(inum - 1);
|
||||
if (kitBlockData.isItemOverride()) {
|
||||
if (kit.getDisplayItem() != null)
|
||||
is = new ItemStack(kit.getDisplayItem());
|
||||
}
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
is.setAmount(1);
|
||||
meta.setDisplayName(Integer.toString(inum));
|
||||
is.setItemMeta(meta);
|
||||
i.setItemStack(is);
|
||||
i.setPickupDelay(9999);
|
||||
return;
|
||||
}
|
||||
if (!kitBlockData.isDisplayingItems()) return;
|
||||
|
||||
ItemStack is = list.get(0);
|
||||
is.setAmount(1);
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
meta.setDisplayName("0");
|
||||
is.setItemMeta(meta);
|
||||
Item i = location.getWorld().dropItem(location.add(0, 1, 0), list.get(0));
|
||||
Vector vec = new Vector(0, 0, 0);
|
||||
i.setVelocity(vec);
|
||||
i.setPickupDelay(9999);
|
||||
i.setMetadata("displayItem", new FixedMetadataValue(UltimateKits.getInstance(), true));
|
||||
i.setMetadata("betterdrops_ignore", new FixedMetadataValue(UltimateKits.getInstance(), true));
|
||||
}
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
package com.songoda.ultimatekits.handlers;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.object.KitType;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class HologramHandler {
|
||||
|
||||
private final UltimateKits instance;
|
||||
|
||||
|
||||
public HologramHandler(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(instance, this::updateHolograms, 0L, 5000L);
|
||||
}
|
||||
|
||||
public void updateHolograms() {
|
||||
try {
|
||||
if (instance.v1_7) return;
|
||||
|
||||
Map<Location, KitBlockData> kitBlocks = instance.getKitManager().getKitLocations();
|
||||
for (KitBlockData kitBlockData : kitBlocks.values()) {
|
||||
if (kitBlockData.getLocation().getWorld() == null) continue;
|
||||
|
||||
KitType kitType = kitBlockData.getType();
|
||||
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
List<String> order = instance.getConfig().getStringList("Main.Hologram Layout");
|
||||
|
||||
Kit kit = kitBlockData.getKit();
|
||||
|
||||
for (String o : order) {
|
||||
switch (o.toUpperCase()) {
|
||||
case "{TITLE}":
|
||||
String title = kit.getTitle();
|
||||
if (title == null) {
|
||||
lines.add(Arconix.pl().getApi().format().formatText("&5" + Arconix.pl().getApi().format().formatText(kit.getName(), true)));
|
||||
} else {
|
||||
lines.add(Arconix.pl().getApi().format().formatText("&5" + Arconix.pl().getApi().format().formatText(title)));
|
||||
}
|
||||
break;
|
||||
case "{RIGHT-CLICK}":
|
||||
if (kitType == KitType.CRATE) {
|
||||
lines.add(Arconix.pl().getApi().format().formatText(Lang.OPEN_CRATE_HOLOGRAM.getConfigValue()));
|
||||
break;
|
||||
}
|
||||
if (kit.getLink() != null) {
|
||||
lines.add(Arconix.pl().getApi().format().formatText(Lang.BUY_LINK_HOLOGRAM.getConfigValue()));
|
||||
break;
|
||||
}
|
||||
if (kit.getPrice() != 0) {
|
||||
double cost = kit.getPrice();
|
||||
if (cost != 0) {
|
||||
lines.add(Arconix.pl().getApi().format().formatText(Lang.BUY_ECO_HOLOGRAM.getConfigValue(Arconix.pl().getApi().format().formatEconomy(cost))));
|
||||
} else {
|
||||
lines.add(Lang.BUY_ECO_HOLOGRAM.getConfigValue(Arconix.pl().getApi().format().formatText(Lang.FREE.getConfigValue())));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "{LEFT-CLICK}":
|
||||
if (kitType == KitType.CLAIM) {
|
||||
lines.add(Arconix.pl().getApi().format().formatText(Lang.DAILY_HOLOGRAM.getConfigValue(kit)));
|
||||
break;
|
||||
}
|
||||
if (kit.getLink() == null && kit.getPrice() == 0) {
|
||||
lines.add(Arconix.pl().getApi().format().formatText(Lang.PREVIEW_ONLY_HOLOGRAM.getConfigValue(kit)));
|
||||
} else {
|
||||
lines.add(Arconix.pl().getApi().format().formatText(Lang.PREVIEW_HOLOGRAM.getConfigValue(kit)));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lines.add(Arconix.pl().getApi().format().formatText(o));
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
double multi = .25 * lines.size();
|
||||
Location location = kitBlockData.getLocation();
|
||||
location.add(.5, .75, .5);
|
||||
Block b = location.getBlock();
|
||||
|
||||
if (kitBlockData.isDisplayingItems()) multi += .40;
|
||||
|
||||
if (b.getType() == Material.TRAPPED_CHEST
|
||||
|| b.getType() == Material.CHEST
|
||||
|| b.getType() == Material.SIGN
|
||||
|| b.getType() == Material.ENDER_CHEST) multi -= .15;
|
||||
|
||||
location.add(0, multi, 0);
|
||||
|
||||
remove(location);
|
||||
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (kitBlockData.showHologram()) {
|
||||
remove(location);
|
||||
Arconix.pl().getApi().packetLibrary.getHologramManager().spawnHolograms(location, lines);
|
||||
}
|
||||
}, 5L);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Location location) {
|
||||
|
||||
|
||||
for (Entity e : Methods.getNearbyEntities(location, 1, 50, 1)) {
|
||||
if (e.getType().equals(EntityType.ARMOR_STAND))
|
||||
Arconix.pl().getApi().packetLibrary.getHologramManager().despawnHologram(e.getLocation());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.songoda.ultimatekits.handlers;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class ParticleHandler {
|
||||
|
||||
private final UltimateKits instance;
|
||||
|
||||
public ParticleHandler(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
checkDefaults();
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(UltimateKits.getInstance(), this::applyParticles, 0, 10L);
|
||||
}
|
||||
|
||||
private void applyParticles() {
|
||||
try {
|
||||
int amt = instance.getConfig().getInt("data.particlesettings.ammount");
|
||||
String type = instance.getConfig().getString("data.particlesettings.type");
|
||||
|
||||
Map<Location, KitBlockData> kitBlocks = instance.getKitManager().getKitLocations();
|
||||
for (KitBlockData kitBlockData : kitBlocks.values()) {
|
||||
if (kitBlockData.getLocation().getWorld() == null || !kitBlockData.hasParticles()) continue;
|
||||
|
||||
Location location = kitBlockData.getLocation();
|
||||
location.add(.5, 0, .5);
|
||||
|
||||
if (instance.v1_8 || instance.v1_7) {
|
||||
//Could not manage to get the original message to resolve, so I am doing this. --Nova
|
||||
location.getWorld().playEffect(location, Effect.valueOf(type), 1, 0);
|
||||
//location.getWorld().spigot.playEffect(location, org.bukkit.Effect.valueOf(type), 1, 0, (float) 0.25, (float) 0.25, (float) 0.25, 1, amt, 100);
|
||||
} else {
|
||||
location.getWorld().spawnParticle(org.bukkit.Particle.valueOf(type), location, amt, 0.25, 0.25, 0.25);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDefaults() {
|
||||
try {
|
||||
if (instance.getConfig().getInt("data.particlesettings.ammount") == 0) {
|
||||
instance.getConfig().set("data.particlesettings.ammount", 25);
|
||||
instance.saveConfig();
|
||||
}
|
||||
if (instance.getConfig().getString("data.particlesettings.type") != null) return;
|
||||
if (instance.v1_7 || instance.v1_8) {
|
||||
instance.getConfig().set("data.particlesettings.type", "WITCH_MAGIC");
|
||||
} else {
|
||||
instance.getConfig().set("data.particlesettings.type", "SPELL_WITCH");
|
||||
}
|
||||
instance.saveConfig();
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
78
src/main/java/com/songoda/ultimatekits/key/Key.java
Normal file
78
src/main/java/com/songoda/ultimatekits/key/Key.java
Normal file
@ -0,0 +1,78 @@
|
||||
package com.songoda.ultimatekits.key;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Key {
|
||||
|
||||
// The name of the key.
|
||||
private String name;
|
||||
|
||||
// The amount of items this key will give you. -1 is all;
|
||||
private int amt;
|
||||
|
||||
// The amount of kit given when the key is used.
|
||||
private int kitAmount;
|
||||
|
||||
public Key(String name, int amt, int kitAmount) {
|
||||
this.name = name;
|
||||
this.amt = amt;
|
||||
this.kitAmount = kitAmount;
|
||||
}
|
||||
|
||||
public ItemStack getKeyItem(Kit kit, int amt) {
|
||||
ItemStack is = null;
|
||||
try {
|
||||
is = new ItemStack(Material.TRIPWIRE_HOOK, amt);
|
||||
|
||||
String kitName;
|
||||
if (kit != null)
|
||||
kitName = Arconix.pl().getApi().format().formatText(kit.getShowableName(), true);
|
||||
else
|
||||
kitName = "All";
|
||||
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
meta.setDisplayName(Arconix.pl().getApi().format().formatText(Lang.KEY_TITLE.getConfigValue(kitName)));
|
||||
|
||||
meta.addEnchant(Enchantment.DURABILITY, 1, true);
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText(name + " &fKey"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText(Lang.KEY_DESC1.getConfigValue(kitName)));
|
||||
if (this.amt == -1)
|
||||
lore.add(Arconix.pl().getApi().format().formatText(Lang.KEY_DESC2.getConfigValue()));
|
||||
else
|
||||
lore.add(Arconix.pl().getApi().format().formatText(Lang.KEY_DESC3.getConfigValue()));
|
||||
if (kitAmount > 1)
|
||||
lore.add(Arconix.pl().getApi().format().formatText(Lang.KEY_DESC4.getConfigValue(this.kitAmount)));
|
||||
meta.setLore(lore);
|
||||
|
||||
is.setItemMeta(meta);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getAmt() {
|
||||
return amt;
|
||||
}
|
||||
|
||||
public int getKitAmount() {
|
||||
return kitAmount;
|
||||
}
|
||||
}
|
34
src/main/java/com/songoda/ultimatekits/key/KeyManager.java
Normal file
34
src/main/java/com/songoda/ultimatekits/key/KeyManager.java
Normal file
@ -0,0 +1,34 @@
|
||||
package com.songoda.ultimatekits.key;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public final class KeyManager {
|
||||
|
||||
private final Set<Key> registeredKeys = new HashSet<>();
|
||||
|
||||
public boolean addKey(Key key) {
|
||||
if (key == null) return false;
|
||||
return registeredKeys.add(key);
|
||||
}
|
||||
|
||||
public void removeKey(Key key) {
|
||||
registeredKeys.remove(key);
|
||||
}
|
||||
|
||||
public Key getKey(String name) {
|
||||
for (Key key : registeredKeys)
|
||||
if (key.getName().equalsIgnoreCase(name)) return key;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Set<Key> getKeys() {
|
||||
return Collections.unmodifiableSet(registeredKeys);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
registeredKeys.clear();
|
||||
}
|
||||
}
|
342
src/main/java/com/songoda/ultimatekits/kit/BlockEditor.java
Normal file
342
src/main/java/com/songoda/ultimatekits/kit/BlockEditor.java
Normal file
@ -0,0 +1,342 @@
|
||||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.BlockEditorPlayerData;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.object.KitType;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/3/2017.
|
||||
*/
|
||||
public class BlockEditor {
|
||||
|
||||
private final Map<UUID, BlockEditorPlayerData> blockPlayerData = new HashMap<>();
|
||||
|
||||
private UltimateKits instance;
|
||||
|
||||
public BlockEditor(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void openOverview(Player player, Location location) {
|
||||
try {
|
||||
BlockEditorPlayerData playerData = getDataFor(player);
|
||||
playerData.setLocation(location);
|
||||
KitBlockData kitBlockData = instance.getKitManager().getKit(location);
|
||||
playerData.setKitBlockData(kitBlockData);
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 27, Arconix.pl().getApi().format().formatText("&8This contains &a" + Arconix.pl().getApi().format().formatTitle(playerData.getKit().getShowableName())));
|
||||
|
||||
Methods.fillGlass(i);
|
||||
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(8, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(10, Methods.getBackgroundGlass(false));
|
||||
i.setItem(16, Methods.getBackgroundGlass(false));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
i.setItem(18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(19, Methods.getBackgroundGlass(true));
|
||||
i.setItem(20, Methods.getBackgroundGlass(false));
|
||||
i.setItem(24, Methods.getBackgroundGlass(false));
|
||||
i.setItem(25, Methods.getBackgroundGlass(true));
|
||||
i.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
ItemStack exit = new ItemStack(Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(Lang.EXIT.getConfigValue());
|
||||
exit.setItemMeta(exitmeta);
|
||||
i.setItem(8, exit);
|
||||
|
||||
ItemStack alli = new ItemStack(Material.REDSTONE_COMPARATOR);
|
||||
ItemMeta allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&5&lSwitch kit type"));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click to swap this kit blocks function."));
|
||||
lore.add("");
|
||||
|
||||
if (kitBlockData.getType() == KitType.PREVIEW) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&6Preview"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Crate"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Claim"));
|
||||
} else if (kitBlockData.getType() == KitType.CRATE) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Preview"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&6Crate"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Claim"));
|
||||
} else if (kitBlockData.getType() == KitType.CLAIM) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Preview"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Crate"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&6Claim"));
|
||||
}
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(11, alli);
|
||||
|
||||
alli = new ItemStack(Material.RED_ROSE);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&9&lDecor Options"));
|
||||
lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click to edit the decoration"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7options for this kit."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(13, alli);
|
||||
|
||||
alli = new ItemStack(Material.DIAMOND_PICKAXE);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&a&lEdit kit"));
|
||||
lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click to edit the kit"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7contained in this block."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(15, alli);
|
||||
|
||||
player.openInventory(i);
|
||||
playerData.setEditorType(BlockEditorPlayerData.EditorType.OVERVIEW);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void decor(Player player) {
|
||||
try {
|
||||
BlockEditorPlayerData playerData = getDataFor(player);
|
||||
|
||||
KitBlockData kitBlockData = playerData.getKitBlockData();
|
||||
Kit kit = kitBlockData.getKit();
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 27, Arconix.pl().getApi().format().formatText("&8Editing decor for &a" + Arconix.pl().getApi().format().formatTitle(kit.getShowableName()) + "&8."));
|
||||
|
||||
Methods.fillGlass(i);
|
||||
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(8, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(10, Methods.getBackgroundGlass(false));
|
||||
i.setItem(16, Methods.getBackgroundGlass(false));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
i.setItem(18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(19, Methods.getBackgroundGlass(true));
|
||||
i.setItem(20, Methods.getBackgroundGlass(false));
|
||||
i.setItem(24, Methods.getBackgroundGlass(false));
|
||||
i.setItem(25, Methods.getBackgroundGlass(true));
|
||||
i.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
ItemStack exit = new ItemStack(Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(Lang.EXIT.getConfigValue());
|
||||
exit.setItemMeta(exitmeta);
|
||||
|
||||
|
||||
ItemStack head2 = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
|
||||
ItemStack back = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
back.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(Lang.BACK.getConfigValue());
|
||||
back.setItemMeta(skull2Meta);
|
||||
|
||||
i.setItem(0, back);
|
||||
i.setItem(8, exit);
|
||||
|
||||
ItemStack alli = new ItemStack(Material.SIGN);
|
||||
ItemMeta allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&9&lToggle Holograms"));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
if (kitBlockData.showHologram()) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &aEnabled&7."));
|
||||
} else {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently &cDisabled&7."));
|
||||
}
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(10, alli);
|
||||
|
||||
alli = new ItemStack(Material.POTION);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&9&lToggle Particles"));
|
||||
lore = new ArrayList<>();
|
||||
if (kitBlockData.hasParticles()) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &aEnabled&7."));
|
||||
} else {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently &cDisabled&7."));
|
||||
}
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(12, alli);
|
||||
|
||||
alli = new ItemStack(Material.GRASS);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&9&lToggle DisplayItems"));
|
||||
lore = new ArrayList<>();
|
||||
if (kitBlockData.isDisplayingItems()) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &aEnabled&7."));
|
||||
} else {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently &cDisabled&7."));
|
||||
}
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(14, alli);
|
||||
|
||||
alli = new ItemStack(Material.BEACON);
|
||||
if (kit.getDisplayItem() != null) {
|
||||
alli.setType(kit.getDisplayItem());
|
||||
}
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&9&lToggle DisplayItem Override"));
|
||||
lore = new ArrayList<>();
|
||||
if (kitBlockData.isItemOverride()) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &aEnabled&7."));
|
||||
} else {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently &cDisabled&7."));
|
||||
}
|
||||
lore.add("");
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Enabling this option will "));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7override the DisplayItems"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7above your kit to the single"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7DisplayItem set in this kit"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7GUI options."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(16, alli);
|
||||
|
||||
player.openInventory(i);
|
||||
playerData.setEditorType(BlockEditorPlayerData.EditorType.DECOR);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void toggleHologram(Player player) {
|
||||
try {
|
||||
KitBlockData kitBlockData = getDataFor(player).getKitBlockData();
|
||||
if (kitBlockData.showHologram()) {
|
||||
kitBlockData.setShowHologram(false);
|
||||
} else {
|
||||
kitBlockData.setShowHologram(true);
|
||||
}
|
||||
UltimateKits.getInstance().holo.updateHolograms();
|
||||
decor(player);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleParticles(Player player) {
|
||||
try {
|
||||
KitBlockData kitBlockData = getDataFor(player).getKitBlockData();
|
||||
if (kitBlockData.hasParticles()) {
|
||||
kitBlockData.setHasParticles(false);
|
||||
} else {
|
||||
kitBlockData.setHasParticles(true);
|
||||
}
|
||||
decor(player);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleDisplayItems(Player player) {
|
||||
try {
|
||||
KitBlockData kitBlockData = getDataFor(player).getKitBlockData();
|
||||
|
||||
boolean isHolo = kitBlockData.showHologram();
|
||||
|
||||
if (isHolo) {
|
||||
kitBlockData.setShowHologram(false);
|
||||
instance.holo.updateHolograms();
|
||||
}
|
||||
|
||||
if (kitBlockData.isDisplayingItems()) {
|
||||
kitBlockData.setDisplayingItems(false);
|
||||
} else {
|
||||
kitBlockData.setDisplayingItems(true);
|
||||
}
|
||||
decor(player);
|
||||
if (isHolo) {
|
||||
kitBlockData.setShowHologram(true);
|
||||
UltimateKits.getInstance().holo.updateHolograms();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void toggleItemOverride(Player player) {
|
||||
try {
|
||||
KitBlockData kitBlockData = getDataFor(player).getKitBlockData();
|
||||
|
||||
if (kitBlockData.isItemOverride()) {
|
||||
kitBlockData.setItemOverride(false);
|
||||
} else {
|
||||
kitBlockData.setItemOverride(true);
|
||||
}
|
||||
decor(player);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void changeDisplayType(Player player) {
|
||||
try {
|
||||
UltimateKits instance = UltimateKits.getInstance();
|
||||
BlockEditorPlayerData playerData = getDataFor(player);
|
||||
KitBlockData kitBlockData = playerData.getKitBlockData();
|
||||
|
||||
if (kitBlockData.getType() == KitType.PREVIEW) kitBlockData.setType(KitType.CRATE);
|
||||
else if (kitBlockData.getType() == KitType.CRATE) kitBlockData.setType(KitType.CLAIM);
|
||||
else if (kitBlockData.getType() == KitType.CLAIM) kitBlockData.setType(KitType.PREVIEW);
|
||||
|
||||
instance.saveConfig();
|
||||
instance.holo.updateHolograms();
|
||||
openOverview(player, playerData.getLocation());
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BlockEditorPlayerData getDataFor(Player player) {
|
||||
return blockPlayerData.computeIfAbsent(player.getUniqueId(), uuid -> new BlockEditorPlayerData());
|
||||
}
|
||||
|
||||
public void removeFromInstance(Player player) {
|
||||
blockPlayerData.remove(player);
|
||||
}
|
||||
}
|
804
src/main/java/com/songoda/ultimatekits/kit/KitEditor.java
Normal file
804
src/main/java/com/songoda/ultimatekits/kit/KitEditor.java
Normal file
@ -0,0 +1,804 @@
|
||||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitEditorPlayerData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/2/2017.
|
||||
*/
|
||||
public class KitEditor {
|
||||
|
||||
private final Map<UUID, KitEditorPlayerData> editorPlayerData = new HashMap<>();
|
||||
|
||||
private UltimateKits instance;
|
||||
|
||||
public KitEditor(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void openOverview(Kit kit, Player player, boolean backb, ItemStack command) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
|
||||
//assign kit to object.
|
||||
playerData.setKit(kit);
|
||||
|
||||
player.updateInventory();
|
||||
String name = kit.getShowableName();
|
||||
Inventory i = Bukkit.createInventory(null, 54, Arconix.pl().getApi().format().formatTitle("&8You are editing kit: &9" + name + "&8."));
|
||||
|
||||
ItemStack exit = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(Lang.EXIT.getConfigValue());
|
||||
exit.setItemMeta(exitmeta);
|
||||
|
||||
ItemStack head2 = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
|
||||
ItemStack back = head2;
|
||||
if (!instance.v1_7)
|
||||
back = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
if (instance.v1_7)
|
||||
skull2Meta.setOwner("MHF_ArrowLeft");
|
||||
back.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(Lang.BACK.getConfigValue());
|
||||
back.setItemMeta(skull2Meta);
|
||||
|
||||
|
||||
ItemStack it = new ItemStack(Material.CHEST, 1);
|
||||
ItemMeta itmeta = it.getItemMeta();
|
||||
itmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&5&l" + playerData.getKit().getName()));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&fPermissions:"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7essentials.kit." + playerData.getKit().getName().toLowerCase()));
|
||||
itmeta.setLore(lore);
|
||||
it.setItemMeta(itmeta);
|
||||
|
||||
ItemStack glass = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7);
|
||||
ItemMeta glassmeta = glass.getItemMeta();
|
||||
glassmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&" + playerData.getKit().getName().replaceAll(".(?!$)", "$0&")));
|
||||
glass.setItemMeta(glassmeta);
|
||||
|
||||
if (backb)
|
||||
i.setItem(0, back);
|
||||
i.setItem(4, it);
|
||||
i.setItem(8, exit);
|
||||
|
||||
int num = 10;
|
||||
List<ItemStack> list = kit.getReadableContents(player, true);
|
||||
for (ItemStack is : list) {
|
||||
/*
|
||||
ItemMeta meta;
|
||||
|
||||
if (is.hasItemMeta()) meta = is.getItemMeta();
|
||||
else meta = Bukkit.getItemFactory().getItemMeta(is.getType());
|
||||
|
||||
List<String> itemLore;
|
||||
|
||||
if (meta.hasLore()) itemLore = meta.getLore();
|
||||
else itemLore = new ArrayList<>();
|
||||
|
||||
itemLore.add("");
|
||||
itemLore.add(TextComponent.formatText("&7Left-Click: &6To set a display item."));
|
||||
itemLore.add(TextComponent.formatText("&7Middle-Click: &6To set a display name."));
|
||||
itemLore.add(TextComponent.formatText("&7Right-Click: &6To set display lore."));
|
||||
itemLore.add(TextComponent.formatText("&7Shift-Click: &6To set crate percentage."));
|
||||
itemLore.add("");
|
||||
itemLore.add(TextComponent.formatText("&6Leave function mode to move items."));
|
||||
meta.setLore(itemLore);
|
||||
is.setItemMeta(meta);
|
||||
*/
|
||||
if (num == 17 || num == 36)
|
||||
num++;
|
||||
if (is.getAmount() > 64) {
|
||||
int overflow = is.getAmount() % 64;
|
||||
int stackamt = (int) ((long) (is.getAmount() / 64));
|
||||
int num3 = 0;
|
||||
while (num3 != stackamt) {
|
||||
is.setAmount(64);
|
||||
i.setItem(num, is);
|
||||
num++;
|
||||
num3++;
|
||||
}
|
||||
if (overflow != 0) {
|
||||
is.setAmount(overflow);
|
||||
i.setItem(num, is);
|
||||
num++;
|
||||
}
|
||||
} else {
|
||||
i.setItem(num, is);
|
||||
num++;
|
||||
}
|
||||
}
|
||||
if (command != null)
|
||||
i.setItem(num, command);
|
||||
|
||||
i.setItem(3, Methods.getGlass());
|
||||
i.setItem(5, Methods.getGlass());
|
||||
|
||||
i.setItem(48, Methods.getGlass());
|
||||
i.setItem(50, Methods.getGlass());
|
||||
|
||||
if (!backb)
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(54 - 18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(54 - 9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(54 - 8, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(54 - 10, Methods.getBackgroundGlass(true));
|
||||
i.setItem(54 - 2, Methods.getBackgroundGlass(true));
|
||||
i.setItem(54 - 1, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(54 - 7, Methods.getBackgroundGlass(false));
|
||||
i.setItem(54 - 3, Methods.getBackgroundGlass(false));
|
||||
|
||||
|
||||
player.openInventory(i);
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.OVERVIEW);
|
||||
|
||||
getInvItems(player, playerData);
|
||||
updateInvButton(i, playerData);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateInvButton(Inventory i, KitEditorPlayerData playerData) {
|
||||
ItemStack alli = new ItemStack(Material.ITEM_FRAME, 1);
|
||||
ItemMeta allmeta = alli.getItemMeta();
|
||||
if (!playerData.isInInventory()) {
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&6Switch To Your Inventory"));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Clicking to switch to"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7your inventory."));
|
||||
allmeta.setLore(lore);
|
||||
} else {
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&6Switch To Kit Functions"));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Clicking to switch back"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7to the kit functions."));
|
||||
allmeta.setLore(lore);
|
||||
}
|
||||
alli.setItemMeta(allmeta);
|
||||
i.setItem(49, alli);
|
||||
}
|
||||
|
||||
public void getInvItems(Player player, KitEditorPlayerData playerData) {
|
||||
|
||||
playerData.setInventory(player.getInventory().getContents().clone());
|
||||
playerData.setInInventory(false);
|
||||
player.getInventory().clear();
|
||||
|
||||
ItemStack alli = new ItemStack(Material.REDSTONE_TORCH_ON, 1);
|
||||
ItemMeta allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&6General Options"));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click to edit adjust"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7general options."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
player.getInventory().setItem(9, alli);
|
||||
|
||||
alli = new ItemStack(Material.EMERALD, 1);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&9Selling Options"));
|
||||
lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click to edit adjust"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7selling options."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
player.getInventory().setItem(10, alli);
|
||||
|
||||
alli = new ItemStack(Material.ITEM_FRAME, 1);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&5GUI Options"));
|
||||
lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click to edit GUI options"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7for this kit."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
player.getInventory().setItem(12, alli);
|
||||
|
||||
alli = new ItemStack(Material.PAPER, 1);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&fAdd Command"));
|
||||
lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click to add a command"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7to this kit."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
player.getInventory().setItem(13, alli);
|
||||
|
||||
alli = new ItemStack(Material.DOUBLE_PLANT, 1);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&6Add Economy"));
|
||||
lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click to add money"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7to this kit."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
player.getInventory().setItem(14, alli);
|
||||
|
||||
alli = new ItemStack(Material.REDSTONE, 1);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&aSave Changes"));
|
||||
lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click to save all changes."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
player.getInventory().setItem(17, alli);
|
||||
}
|
||||
|
||||
public void selling(Player player) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
Kit kit = playerData.getKit();
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 27, Arconix.pl().getApi().format().formatTitle("&8Selling Options for &a" + kit.getShowableName() + "&8."));
|
||||
|
||||
Methods.fillGlass(i);
|
||||
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(8, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(10, Methods.getBackgroundGlass(false));
|
||||
i.setItem(16, Methods.getBackgroundGlass(false));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
i.setItem(18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(19, Methods.getBackgroundGlass(true));
|
||||
i.setItem(20, Methods.getBackgroundGlass(false));
|
||||
i.setItem(24, Methods.getBackgroundGlass(false));
|
||||
i.setItem(25, Methods.getBackgroundGlass(true));
|
||||
i.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
ItemStack exit = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(Lang.EXIT.getConfigValue());
|
||||
exit.setItemMeta(exitmeta);
|
||||
|
||||
ItemStack head2 = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
|
||||
ItemStack back = head2;
|
||||
if (!instance.v1_7)
|
||||
back = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
if (instance.v1_7)
|
||||
skull2Meta.setOwner("MHF_ArrowLeft");
|
||||
back.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(Lang.BACK.getConfigValue());
|
||||
back.setItemMeta(skull2Meta);
|
||||
|
||||
i.setItem(0, back);
|
||||
i.setItem(8, exit);
|
||||
|
||||
ItemStack alli = new ItemStack(Material.DIAMOND_HELMET);
|
||||
ItemMeta allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&c&lSet not for sale"));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
|
||||
if (kit.getPrice() != 0 ||
|
||||
kit.getLink() != null)
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently &aFor Sale&7."));
|
||||
else
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently &cNot For Sale&7."));
|
||||
lore.add(Arconix.pl().getApi().format().formatText(""));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Clicking this option will"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7remove this kit from sale."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(11, alli);
|
||||
|
||||
alli = new ItemStack(Material.DIAMOND_HELMET);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&a&lSet kit link"));
|
||||
lore = new ArrayList<>();
|
||||
if (kit.getLink() != null)
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &a" + kit.getLink() + "&7."));
|
||||
else
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &cNot set&7."));
|
||||
lore.add(Arconix.pl().getApi().format().formatText(""));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Clicking this option will"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7allow you to set a link"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7that players will receive"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7when attempting to purchase"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7this kit."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(13, alli);
|
||||
|
||||
alli = new ItemStack(Material.DIAMOND_HELMET);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&a&lSet kit price"));
|
||||
lore = new ArrayList<>();
|
||||
if (kit.getPrice() != 0)
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &a$" + Arconix.pl().getApi().format().formatEconomy(kit.getPrice()) + "&7."));
|
||||
else
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &cNot set&7."));
|
||||
lore.add(Arconix.pl().getApi().format().formatText(""));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Clicking this option will"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7allow you to set a price"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7that players will be able to"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7purchase this kit for"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7requires &aVault&7."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(15, alli);
|
||||
|
||||
player.openInventory(i);
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.SELLING);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void gui(Player player) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
Kit kit = playerData.getKit();
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 27, Arconix.pl().getApi().format().formatTitle("&8GUI Options for &a" + kit.getShowableName() + "&8."));
|
||||
|
||||
Methods.fillGlass(i);
|
||||
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(8, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(10, Methods.getBackgroundGlass(false));
|
||||
i.setItem(16, Methods.getBackgroundGlass(false));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
i.setItem(18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(19, Methods.getBackgroundGlass(true));
|
||||
i.setItem(20, Methods.getBackgroundGlass(false));
|
||||
i.setItem(24, Methods.getBackgroundGlass(false));
|
||||
i.setItem(25, Methods.getBackgroundGlass(true));
|
||||
i.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
ItemStack exit = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(Lang.EXIT.getConfigValue());
|
||||
exit.setItemMeta(exitmeta);
|
||||
|
||||
ItemStack head2 = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
|
||||
ItemStack back = head2;
|
||||
if (!instance.v1_7)
|
||||
back = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
if (instance.v1_7)
|
||||
skull2Meta.setOwner("MHF_ArrowLeft");
|
||||
back.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(Lang.BACK.getConfigValue());
|
||||
back.setItemMeta(skull2Meta);
|
||||
|
||||
i.setItem(0, back);
|
||||
i.setItem(8, exit);
|
||||
|
||||
ItemStack alli = new ItemStack(Material.DIAMOND_HELMET);
|
||||
ItemMeta allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&9&lSet Title"));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
if (kit.getTitle() != null)
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &a" + kit.getTitle() + "&7."));
|
||||
else
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &cNot set&7."));
|
||||
lore.add(Arconix.pl().getApi().format().formatText(""));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Left-Click: &9to set"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&9the kit title for holograms"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&9and the kit / kit GUIs."));
|
||||
lore.add(Arconix.pl().getApi().format().formatText(""));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Right-Click: &9to reset."));
|
||||
allmeta.setLore(lore);
|
||||
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(11, alli);
|
||||
|
||||
alli = new ItemStack(Material.BEACON);
|
||||
if (kit.getDisplayItem() != null) {
|
||||
alli.setType(kit.getDisplayItem());
|
||||
}
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&9&lSet DisplayItem"));
|
||||
lore = new ArrayList<>();
|
||||
if (kit.getDisplayItem() != null) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently set to: &a" + kit.getDisplayItem().toString() + "&7."));
|
||||
} else {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently &cDisabled&7."));
|
||||
}
|
||||
lore.add("");
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Right-Click to: &9Set a"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&9display item for this kit"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&9to the item in your hand."));
|
||||
lore.add("");
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Left-Click to: &9Remove the item."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(13, alli);
|
||||
|
||||
alli = new ItemStack(Material.COAL);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&9&lHide kit"));
|
||||
lore = new ArrayList<>();
|
||||
if (kit.isHidden()) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &cHidden&7."));
|
||||
} else {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &aVisible&7."));
|
||||
}
|
||||
lore.add("");
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7A hidden kit will not"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7show up in the /kit gui."));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7This is usually optimal for"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7preventing players from seeing"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7non obtainable kit or starter kit."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(15, alli);
|
||||
|
||||
player.openInventory(i);
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.GUI);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void general(Player player) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
Kit kit = playerData.getKit();
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 27, Arconix.pl().getApi().format().formatTitle("&8General Options for &a" + kit.getShowableName() + "&8."));
|
||||
|
||||
Methods.fillGlass(i);
|
||||
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(8, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(10, Methods.getBackgroundGlass(false));
|
||||
i.setItem(16, Methods.getBackgroundGlass(false));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
i.setItem(18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(19, Methods.getBackgroundGlass(true));
|
||||
i.setItem(20, Methods.getBackgroundGlass(false));
|
||||
i.setItem(24, Methods.getBackgroundGlass(false));
|
||||
i.setItem(25, Methods.getBackgroundGlass(true));
|
||||
i.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
ItemStack exit = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(Lang.EXIT.getConfigValue());
|
||||
exit.setItemMeta(exitmeta);
|
||||
|
||||
ItemStack head2 = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
|
||||
ItemStack back = head2;
|
||||
if (!instance.v1_7)
|
||||
back = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
if (instance.v1_7)
|
||||
skull2Meta.setOwner("MHF_ArrowLeft");
|
||||
back.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(Lang.BACK.getConfigValue());
|
||||
back.setItemMeta(skull2Meta);
|
||||
|
||||
i.setItem(0, back);
|
||||
i.setItem(8, exit);
|
||||
|
||||
ItemStack alli = new ItemStack(Material.DIAMOND_HELMET);
|
||||
ItemMeta allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&9&lSet Title"));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
if (kit.getTitle() != null)
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &a" + kit.getDelay() + "&7."));
|
||||
else
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &cNot set&7."));
|
||||
lore.add(Arconix.pl().getApi().format().formatText(""));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Left-Click: &9to set"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&9the kit title for holograms"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&9and the kit / kit GUIs."));
|
||||
lore.add(Arconix.pl().getApi().format().formatText(""));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Right-Click: &9to reset."));
|
||||
allmeta.setLore(lore);
|
||||
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
/*i.setItem(11, alli);*/
|
||||
|
||||
alli = new ItemStack(Material.WATCH);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&9&lChange Delay"));
|
||||
lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently set to: &a" + kit.getDelay() + "&7."));
|
||||
lore.add("");
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Use this to alter this kit delay."));
|
||||
lore.add("");
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Use &6-1 &7to make this kit single"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7use only."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(13, alli);
|
||||
|
||||
alli = new ItemStack(Material.TNT);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&c&lDestroy Kit"));
|
||||
lore = new ArrayList<>();
|
||||
lore.add("");
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click this to destroy this kit."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(15, alli);
|
||||
|
||||
player.openInventory(i);
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.GENERAL);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void setKitsDisplayItem(Player player, boolean type) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
Kit kit = playerData.getKit();
|
||||
if (type) {
|
||||
ItemStack is = player.getItemInHand();
|
||||
if (is == null || is.getType() == Material.AIR) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8You must be holding an item to use this function."));
|
||||
return;
|
||||
}
|
||||
kit.setDisplayItem(is.getType());
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Custom Item Display set for kit &a" + kit.getShowableName() + "&8."));
|
||||
} else {
|
||||
kit.setDisplayItem(null);
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Custom Item Display removed from kit &a" + kit.getShowableName() + "&8."));
|
||||
}
|
||||
gui(player);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void createCommand(Player player) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (playerData.getEditorType() == KitEditorPlayerData.EditorType.COMMAND) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "Editing Timed out."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
}
|
||||
}, 500L);
|
||||
player.closeInventory();
|
||||
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.COMMAND);
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText("Please type a command. Example: &aeco give {player} 1000"));
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText("do not include a &a/"));
|
||||
player.sendMessage("");
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void createMoney(Player player) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (playerData.getEditorType() == KitEditorPlayerData.EditorType.MONEY) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "Editing Timed out."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
}
|
||||
}, 500L);
|
||||
player.closeInventory();
|
||||
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.MONEY);
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText("Please type a dollar amount. Example: &a10000"));
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText("do not include a &a$"));
|
||||
player.sendMessage("");
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveKit(Player player, Inventory i) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
Kit kit = playerData.getKit();
|
||||
|
||||
ItemStack[] items = i.getContents();
|
||||
int num = 0;
|
||||
for (ItemStack item : items) {
|
||||
if (num < 10 || num == 17 || num == 36) {
|
||||
items[num] = null;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
|
||||
items = Arrays.copyOf(items, items.length - 10);
|
||||
|
||||
kit.saveKit(Arrays.asList(items));
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Changes to &a" + kit.getShowableName() + " &8saved successfully."));
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void hide(Player player) {
|
||||
Kit kit = getDataFor(player).getKit();
|
||||
try {
|
||||
if (kit.isHidden()) {
|
||||
kit.setHidden(false);
|
||||
} else {
|
||||
kit.setHidden(true);
|
||||
}
|
||||
gui(player);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void setNoSale(Player player) {
|
||||
try {
|
||||
Kit kit = getDataFor(player).getKit();
|
||||
kit.setPrice(0);
|
||||
kit.setLink(null);
|
||||
instance.holo.updateHolograms();
|
||||
selling(player);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDelay(Player player) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
|
||||
player.closeInventory();
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (playerData.getEditorType() == KitEditorPlayerData.EditorType.DELAY) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "Editing Timed out."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
}
|
||||
}, 200L);
|
||||
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.DELAY);
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText("Type a delay in seconds for this kit. Example: 10"));
|
||||
player.sendMessage("");
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTitle(Player player, boolean type) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
Kit kit = playerData.getKit();
|
||||
|
||||
if (type) {
|
||||
player.closeInventory();
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (playerData.getEditorType() == KitEditorPlayerData.EditorType.TITLE) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "Editing Timed out."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
}
|
||||
}, 200L);
|
||||
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.TITLE);
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText("Type a title for the GUI. Example: &aThe Cool Kids Kit"));
|
||||
player.sendMessage("");
|
||||
} else {
|
||||
instance.getConfig().set("data.kit." + kit.getName() + ".title", null);
|
||||
instance.saveConfig();
|
||||
instance.holo.updateHolograms();
|
||||
gui(player);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void editPrice(Player player) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (playerData.getEditorType() == KitEditorPlayerData.EditorType.PRICE) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "Editing Timed out."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
}
|
||||
}, 200L);
|
||||
player.closeInventory();
|
||||
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.PRICE);
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText("Please type a price. Example: &a50000"));
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText("&cUse only numbers."));
|
||||
player.sendMessage("");
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void editLink(Player player) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (playerData.getEditorType() == KitEditorPlayerData.EditorType.LINK) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "Editing Timed out."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
}
|
||||
}, 200L);
|
||||
player.closeInventory();
|
||||
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.LINK);
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText("Please type a link. Example: &ahttp://buy.viscernity.com/"));
|
||||
player.sendMessage("");
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public KitEditorPlayerData getDataFor(Player player) {
|
||||
return editorPlayerData.computeIfAbsent(player.getUniqueId(), uuid -> new KitEditorPlayerData());
|
||||
}
|
||||
|
||||
public void removeFromInstance(Player player) {
|
||||
editorPlayerData.remove(player);
|
||||
}
|
||||
}
|
244
src/main/java/com/songoda/ultimatekits/kit/KitsGUI.java
Normal file
244
src/main/java/com/songoda/ultimatekits/kit/KitsGUI.java
Normal file
@ -0,0 +1,244 @@
|
||||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/16/2017.
|
||||
*/
|
||||
public class KitsGUI {
|
||||
|
||||
public static void show(Player player, int page) {
|
||||
try {
|
||||
UltimateKits instance = UltimateKits.getInstance();
|
||||
|
||||
UltimateKits.getInstance().page.put(player.getUniqueId(), page);
|
||||
UltimateKits.getInstance().kits.clear();
|
||||
|
||||
String guititle = Lang.KITS_TITLE.getConfigValue();
|
||||
|
||||
ItemStack exit = new ItemStack(Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(Lang.EXIT.getConfigValue());
|
||||
exit.setItemMeta(exitmeta);
|
||||
|
||||
List<String> kitList = new ArrayList<>();
|
||||
|
||||
int ino = 14;
|
||||
if (UltimateKits.getInstance().getConfig().getBoolean("Interfaces.Do Not Use Glass Borders")) ino = 54;
|
||||
int num = 0;
|
||||
int start = (page - 1) * ino;
|
||||
int show = 1;
|
||||
for (Kit kit : UltimateKits.getInstance().getKitManager().getKits()) {
|
||||
if (!kit.isHidden()
|
||||
&& (!UltimateKits.getInstance().getConfig().getBoolean("Main.Only Show Players Kits They Have Permission To Use") || kit.hasPermission(player))
|
||||
&& num >= start
|
||||
&& show <= ino) {
|
||||
kitList.add(kit.getName());
|
||||
show++;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
|
||||
boolean glassless = UltimateKits.getInstance().getConfig().getBoolean("Interfaces.Do Not Use Glass Borders");
|
||||
|
||||
int n = 7;
|
||||
if (glassless)
|
||||
n = 9;
|
||||
int max = 27;
|
||||
if (kitList.size() > n) {
|
||||
max = 36;
|
||||
}
|
||||
if (glassless) {
|
||||
if (kitList.size() > n + 34)
|
||||
max = max + 34;
|
||||
else if (kitList.size() > n + 25)
|
||||
max = max + 25;
|
||||
else if (kitList.size() > n + 16)
|
||||
max = max + 16;
|
||||
else if (kitList.size() > n + 7)
|
||||
max = max + 7;
|
||||
}
|
||||
if (glassless) max -= 18;
|
||||
Inventory i = Bukkit.createInventory(null, max, Arconix.pl().getApi().format().formatTitle(guititle));
|
||||
|
||||
if (!glassless) {
|
||||
num = 0;
|
||||
while (num != max) {
|
||||
ItemStack glass = Methods.getGlass();
|
||||
i.setItem(num, glass);
|
||||
num++;
|
||||
}
|
||||
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(8, Methods.getBackgroundGlass(true));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(max - 18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(max - 9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(max - 8, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(max - 10, Methods.getBackgroundGlass(true));
|
||||
i.setItem(max - 2, Methods.getBackgroundGlass(true));
|
||||
i.setItem(max - 1, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(max - 7, Methods.getBackgroundGlass(false));
|
||||
i.setItem(max - 3, Methods.getBackgroundGlass(false));
|
||||
}
|
||||
|
||||
num = 10;
|
||||
if (glassless) num = 0;
|
||||
int id = 0;
|
||||
int tmax = max;
|
||||
if (!glassless)
|
||||
tmax = tmax - 10;
|
||||
for (int index = num; index != tmax; index++) {
|
||||
if (!glassless && index == 17) index = 19;
|
||||
if (id > kitList.size() - 1) {
|
||||
i.setItem(index, new ItemStack(Material.AIR));
|
||||
continue;
|
||||
}
|
||||
String kitItem = kitList.get(id);
|
||||
|
||||
Kit kit = UltimateKits.getInstance().getKitManager().getKit(kitItem);
|
||||
|
||||
String title = Lang.GUI_KIT_NAME.getConfigValue(Arconix.pl().getApi().format().formatText(kitItem, true));
|
||||
if (kit.getTitle() != null)
|
||||
title = Arconix.pl().getApi().format().formatText(kit.getTitle());
|
||||
UltimateKits.getInstance().kits.put(title, kitItem);
|
||||
|
||||
ItemStack item = new ItemStack(Material.ENCHANTED_BOOK);
|
||||
if (kit.getDisplayItem() != null)
|
||||
item.setType(kit.getDisplayItem());
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Arconix.pl().getApi().format().formatText(title));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
if (kit.getPrice() != 0)
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7This kit costs &a$" + kit.getPrice() + "&7."));
|
||||
else if (kit.getLink() != null)
|
||||
lore.add(Lang.LINK.getConfigValue());
|
||||
|
||||
|
||||
if (!instance.kitsMode.contains(player.getUniqueId())) {
|
||||
if (!Lang.ABOUT_KIT.getConfigValue().trim().equals("")) {
|
||||
String[] parts = Lang.ABOUT_KIT.getConfigValue().split("\\|");
|
||||
lore.add("");
|
||||
for (String line : parts)
|
||||
lore.add(Arconix.pl().getApi().format().formatText(line));
|
||||
}
|
||||
if (kit.hasPermission(player)) {
|
||||
if (kit.getNextUse(player) == -1) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText(Lang.ONCE.getConfigValue()));
|
||||
} else if (kit.getNextUse(player) > 0) {
|
||||
if (!Lang.PLEASE_WAIT.getConfigValue().trim().equals("")) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText(Lang.PLEASE_WAIT.getConfigValue(Arconix.pl().getApi().format().readableTime(kit.getNextUse(player)))));
|
||||
}
|
||||
} else if (!Lang.READY.getConfigValue().trim().equals("")) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText(Lang.READY.getConfigValue()));
|
||||
}
|
||||
} else
|
||||
lore.add(Arconix.pl().getApi().format().formatText(Lang.NO_ACCESS.getConfigValue()));
|
||||
lore.add("");
|
||||
lore.add(Arconix.pl().getApi().format().formatText(Lang.LEFT_PREVIEW.getConfigValue()));
|
||||
if (kit.hasPermission(player)) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText(Lang.RIGHT_CLAIM.getConfigValue()));
|
||||
} else if (kit.getPrice() != 0 || kit.getLink() != null) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText(Lang.RIGHT_BUY.getConfigValue()));
|
||||
}
|
||||
|
||||
if (player.hasPermission("ultimatekits.admin")) {
|
||||
lore.add("");
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&6Middle Click &7to edit positioning."));
|
||||
}
|
||||
} else {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&6&lEdit Mode"));
|
||||
|
||||
lore.add("");
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&6Left Click &7to move kit left"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&6Right Click &7to move kit right"));
|
||||
lore.add("");
|
||||
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&6Middle Click &7to go back."));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
i.setItem(index, item);
|
||||
id++;
|
||||
}
|
||||
|
||||
ItemStack info = new ItemStack(Material.BOOK, 1);
|
||||
ItemMeta infometa = info.getItemMeta();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
String[] parts = Lang.DETAILS.getConfigValue(player.getName()).split("\\|");
|
||||
boolean hit = false;
|
||||
for (String line : parts) {
|
||||
if (!hit)
|
||||
infometa.setDisplayName(Arconix.pl().getApi().format().formatText(line));
|
||||
else
|
||||
lore.add(Arconix.pl().getApi().format().formatText(line));
|
||||
hit = true;
|
||||
}
|
||||
infometa.setLore(lore);
|
||||
info.setItemMeta(infometa);
|
||||
|
||||
ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
|
||||
ItemStack skull = head;
|
||||
if (!UltimateKits.getInstance().v1_7)
|
||||
skull = Arconix.pl().getApi().getGUI().addTexture(head, "http://textures.minecraft.net/texture/1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
|
||||
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
|
||||
if (UltimateKits.getInstance().v1_7)
|
||||
skullMeta.setOwner("MHF_ArrowRight");
|
||||
skull.setDurability((short) 3);
|
||||
skullMeta.setDisplayName(Lang.NEXT.getConfigValue());
|
||||
skull.setItemMeta(skullMeta);
|
||||
|
||||
ItemStack head2 = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
|
||||
ItemStack skull2 = head2;
|
||||
if (!UltimateKits.getInstance().v1_7)
|
||||
skull2 = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta();
|
||||
if (UltimateKits.getInstance().v1_7)
|
||||
skull2Meta.setOwner("MHF_ArrowLeft");
|
||||
skull2.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(Lang.LAST.getConfigValue());
|
||||
skull2.setItemMeta(skull2Meta);
|
||||
|
||||
if (!UltimateKits.getInstance().getConfig().getBoolean("Interfaces.Do Not Use Glass Borders"))
|
||||
i.setItem(max - 5, exit);
|
||||
if (kitList.size() == 14)
|
||||
i.setItem(max - 4, skull);
|
||||
if (page != 1)
|
||||
i.setItem(max - 6, skull2);
|
||||
if (!UltimateKits.getInstance().getConfig().getBoolean("Interfaces.Do Not Use Glass Borders"))
|
||||
i.setItem(4, info);
|
||||
player.openInventory(i);
|
||||
|
||||
UltimateKits.getInstance().whereAt.remove(player.getUniqueId());
|
||||
UltimateKits.getInstance().whereAt.put(player.getUniqueId(), "kits");
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.songoda.ultimatekits.kit.object;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BlockEditorPlayerData {
|
||||
|
||||
public enum EditorType { OVERVIEW, DECOR, NOTIN }
|
||||
|
||||
private Location location;
|
||||
private Player player;
|
||||
private KitBlockData kitBlockData;
|
||||
private EditorType editorType = EditorType.NOTIN;
|
||||
|
||||
public Kit getKit() {
|
||||
return kitBlockData.getKit();
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = roundLocation(location);
|
||||
}
|
||||
|
||||
public EditorType getEditorType() {
|
||||
return editorType;
|
||||
}
|
||||
|
||||
public void setEditorType(EditorType editorType) {
|
||||
this.editorType = editorType;
|
||||
}
|
||||
|
||||
public KitBlockData getKitBlockData() {
|
||||
return kitBlockData;
|
||||
}
|
||||
|
||||
public void setKitBlockData(KitBlockData kitBlockData) {
|
||||
this.kitBlockData = kitBlockData;
|
||||
}
|
||||
|
||||
private Location roundLocation(Location location) {
|
||||
location = location.clone();
|
||||
location.setX(location.getBlockX());
|
||||
location.setY(location.getBlockY());
|
||||
location.setZ(location.getBlockZ());
|
||||
return location;
|
||||
}
|
||||
}
|
705
src/main/java/com/songoda/ultimatekits/kit/object/Kit.java
Normal file
705
src/main/java/com/songoda/ultimatekits/kit/object/Kit.java
Normal file
@ -0,0 +1,705 @@
|
||||
package com.songoda.ultimatekits.kit.object;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.key.Key;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import com.sun.xml.internal.ws.util.StringUtils;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class Kit {
|
||||
|
||||
private final String name, showableName;
|
||||
|
||||
private double price;
|
||||
private String link, title;
|
||||
|
||||
private int delay;
|
||||
|
||||
private boolean hidden;
|
||||
|
||||
private Material displayItem;
|
||||
|
||||
private List<String> contents;
|
||||
|
||||
public Kit(String name, String title, String link, double price, Material displayItem, int delay, boolean hidden, List<String> contents) {
|
||||
this.name = name;
|
||||
this.showableName = Arconix.pl().getApi().format().formatText(name, true);
|
||||
this.price = price;
|
||||
this.link = link;
|
||||
this.title = title;
|
||||
this.delay = delay;
|
||||
this.hidden = hidden;
|
||||
this.displayItem = displayItem;
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
public Kit(String name) {
|
||||
this(name, null, null, 0, null, 0, false, new ArrayList<>());
|
||||
}
|
||||
|
||||
public void buy(Player p) {
|
||||
try {
|
||||
if (hasPermission(p) && UltimateKits.getInstance().getConfig().getBoolean("Main.Allow Players To Receive Kits For Free If They Have Permission")) {
|
||||
give(p, false, false, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!p.hasPermission("ultimatekits.buy."+name)) {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Lang.NO_PERM.getConfigValue());
|
||||
return;
|
||||
}
|
||||
|
||||
if (link != null) {
|
||||
p.sendMessage("");
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText("&a" + link));
|
||||
p.sendMessage("");
|
||||
p.closeInventory();
|
||||
} else if (price != 0) {
|
||||
confirmBuy(name, p);
|
||||
} else {
|
||||
p.sendMessage(Lang.NO_PERM.getConfigValue());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private List<ItemStack> getItemContents() {
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
for (String str : this.getContents()) {
|
||||
if ((!str.startsWith("/") && !str.startsWith("$")))
|
||||
items.add(Methods.deserializeItemStack(str));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private boolean hasRoom(Player p) {
|
||||
int space = 0;
|
||||
|
||||
for (ItemStack content : p.getInventory().getContents()) {
|
||||
if (content == null) {
|
||||
space++;
|
||||
}
|
||||
}
|
||||
|
||||
return space >= getItemContents().size();
|
||||
}
|
||||
|
||||
public void give(Player p, boolean useKey, boolean economy, boolean console) {
|
||||
try {
|
||||
if (UltimateKits.getInstance().getConfig().getBoolean("Main.Prevent The Redeeming of a Kit When Inventory Is Full") && !hasRoom(p)) {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.INVENTORY_FULL.getConfigValue()));
|
||||
return;
|
||||
}
|
||||
if (UltimateKits.getInstance().getConfig().getBoolean("Main.Sounds Enabled")) {
|
||||
if (!UltimateKits.getInstance().v1_8 && !UltimateKits.getInstance().v1_7) {
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.6F, 15.0F);
|
||||
} else {
|
||||
p.playSound(p.getLocation(), Sound.valueOf("LEVEL_UP"), 2F, 15.0F);
|
||||
}
|
||||
}
|
||||
if (useKey) {
|
||||
if (p.getItemInHand().getType() != Material.TRIPWIRE_HOOK || !p.getItemInHand().hasItemMeta()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Key key = UltimateKits.getInstance().getKeyManager().getKey(ChatColor.stripColor(p.getItemInHand().getItemMeta().getLore().get(0)).replace(" Key", ""));
|
||||
|
||||
if (!p.getItemInHand().getItemMeta().getDisplayName().equals(Lang.KEY_TITLE.getConfigValue(showableName)) && !p.getItemInHand().getItemMeta().getDisplayName().equals(Lang.KEY_TITLE.getConfigValue("All"))) {
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(UltimateKits.getInstance().references.getPrefix() + Lang.WRONG_KEY.getConfigValue()));
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < key.getKitAmount(); i++)
|
||||
givePartKit(p, key);
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.KEY_SUCCESS.getConfigValue(showableName)));
|
||||
if (p.getInventory().getItemInHand().getAmount() != 1) {
|
||||
ItemStack is = p.getItemInHand();
|
||||
is.setAmount(is.getAmount() - 1);
|
||||
p.setItemInHand(is);
|
||||
} else {
|
||||
p.setItemInHand(null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (getNextUse(p) == -1 && !economy && !console) {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.NOT_TWICE.getConfigValue(showableName)));
|
||||
} else if (getNextUse(p) <= 0 || economy || console) {
|
||||
giveKit(p);
|
||||
if (economy) {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.PURCHASE_SUCCESS.getConfigValue(showableName)));
|
||||
} else {
|
||||
updateDelay(p);
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.GIVE_SUCCESS.getConfigValue(showableName)));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.DELAY.getConfigValue(Arconix.pl().getApi().format().readableTime(getNextUse(p)))));
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void display(Player p, boolean back) {
|
||||
try {
|
||||
if (!p.hasPermission("previewkit.use")
|
||||
&& !p.hasPermission("previewkit." + name)
|
||||
&& !p.hasPermission("ultimatekits.use")
|
||||
&& !p.hasPermission("ultimatekits." + name)) {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Lang.NO_PERM.getConfigValue());
|
||||
return;
|
||||
}
|
||||
if (name == null) {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Lang.KIT_DOESNT_EXIST.getConfigValue(showableName));
|
||||
return;
|
||||
}
|
||||
UltimateKits.getInstance().inKit.put(p.getUniqueId(), this);
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Lang.PREVIEWING_KIT.getConfigValue(showableName));
|
||||
String guititle = Arconix.pl().getApi().format().formatTitle(Lang.PREVIEW_TITLE.getConfigValue(showableName));
|
||||
if (title != null) {
|
||||
guititle = Lang.PREVIEW_TITLE.getConfigValue(Arconix.pl().getApi().format().formatText(title, true));
|
||||
}
|
||||
|
||||
guititle = Arconix.pl().getApi().format().formatText(guititle);
|
||||
|
||||
List<ItemStack> list = getReadableContents(p, true);
|
||||
|
||||
int amt = 0;
|
||||
for (ItemStack is : list) {
|
||||
if (is.getAmount() > 64) {
|
||||
int overflow = is.getAmount() % 64;
|
||||
int stackamt = is.getAmount() / 64;
|
||||
int num3 = 0;
|
||||
while (num3 != stackamt) {
|
||||
amt++;
|
||||
num3++;
|
||||
}
|
||||
if (overflow != 0) {
|
||||
amt++;
|
||||
}
|
||||
} else {
|
||||
amt++;
|
||||
}
|
||||
}
|
||||
boolean buyable = false;
|
||||
if (link != null || price != 0) {
|
||||
buyable = true;
|
||||
}
|
||||
int min = 0;
|
||||
if (UltimateKits.getInstance().getConfig().getBoolean("Interfaces.Do Not Use Glass Borders")) {
|
||||
min = 9;
|
||||
if (!buyable) {
|
||||
min = min + 9;
|
||||
}
|
||||
}
|
||||
Inventory i = Bukkit.createInventory(null, 54 - min, Arconix.pl().getApi().format().formatTitle(guititle));
|
||||
int max = 54 - min;
|
||||
if (amt <= 7) {
|
||||
i = Bukkit.createInventory(null, 27 - min, Arconix.pl().getApi().format().formatTitle(guititle));
|
||||
max = 27 - min;
|
||||
} else if (amt <= 16) {
|
||||
i = Bukkit.createInventory(null, 36 - min, Arconix.pl().getApi().format().formatTitle(guititle));
|
||||
max = 36 - min;
|
||||
} else if (amt <= 23) {
|
||||
i = Bukkit.createInventory(null, 45 - min, Arconix.pl().getApi().format().formatTitle(guititle));
|
||||
max = 45 - min;
|
||||
}
|
||||
|
||||
|
||||
int num = 0;
|
||||
if (!UltimateKits.getInstance().getConfig().getBoolean("Interfaces.Do Not Use Glass Borders")) {
|
||||
ItemStack exit = new ItemStack(Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(Lang.EXIT.getConfigValue());
|
||||
exit.setItemMeta(exitmeta);
|
||||
while (num != 10) {
|
||||
i.setItem(num, Methods.getGlass());
|
||||
num++;
|
||||
}
|
||||
int num2 = max - 10;
|
||||
while (num2 != max) {
|
||||
i.setItem(num2, Methods.getGlass());
|
||||
num2++;
|
||||
}
|
||||
i.setItem(8, exit);
|
||||
|
||||
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(max - 18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(max - 9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(max - 8, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(max - 10, Methods.getBackgroundGlass(true));
|
||||
i.setItem(max - 2, Methods.getBackgroundGlass(true));
|
||||
i.setItem(max - 1, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(max - 7, Methods.getBackgroundGlass(false));
|
||||
i.setItem(max - 3, Methods.getBackgroundGlass(false));
|
||||
}
|
||||
|
||||
if (buyable) {
|
||||
ItemStack link = new ItemStack(Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Buy Icon")), 1);
|
||||
ItemMeta linkmeta = link.getItemMeta();
|
||||
linkmeta.setDisplayName(Lang.BUYNOW.getConfigValue());
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
if (hasPermission(p) && UltimateKits.getInstance().getConfig().getBoolean("Main.Allow Players To Receive Kits For Free If They Have Permission")) {
|
||||
lore.add(Lang.CLICKECO.getConfigValue("0"));
|
||||
if (p.isOp()) {
|
||||
lore.add("");
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7This is free because"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7you have perms for it."));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Everyone else buys"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7this for &a$" + Arconix.pl().getApi().format().formatEconomy(price) + "&7."));
|
||||
}
|
||||
} else {
|
||||
lore.add(Lang.CLICKECO.getConfigValue(Arconix.pl().getApi().format().formatEconomy(price)));
|
||||
}
|
||||
if (delay != 0 && p.isOp()) {
|
||||
lore.add("");
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7You do not have a delay"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7because you have perms"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7to bypass the delay."));
|
||||
}
|
||||
linkmeta.setLore(lore);
|
||||
link.setItemMeta(linkmeta);
|
||||
i.setItem(max - 5, link);
|
||||
}
|
||||
|
||||
for (ItemStack is : list) {
|
||||
if (!UltimateKits.getInstance().getConfig().getBoolean("Interfaces.Do Not Use Glass Borders")) {
|
||||
if (num == 17)
|
||||
num++;
|
||||
if (num == (max - 18))
|
||||
num++;
|
||||
}
|
||||
if (is.getAmount() > 64) {
|
||||
if (is.hasItemMeta() && is.getItemMeta().hasLore()) {
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
for (String str : is.getItemMeta().getLore()) {
|
||||
str = str.replace("{PLAYER}", p.getName());
|
||||
str = str.replace("<PLAYER>", p.getName());
|
||||
lore.add(str);
|
||||
}
|
||||
is.getItemMeta().setLore(lore);
|
||||
|
||||
}
|
||||
int overflow = is.getAmount() % 64;
|
||||
int stackamt = is.getAmount() / 64;
|
||||
int num3 = 0;
|
||||
while (num3 != stackamt) {
|
||||
is.setAmount(64);
|
||||
i.setItem(num, is);
|
||||
num++;
|
||||
num3++;
|
||||
}
|
||||
if (overflow != 0) {
|
||||
is.setAmount(overflow);
|
||||
i.setItem(num, is);
|
||||
num++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!UltimateKits.getInstance().getConfig().getBoolean("Main.Dont Preview Commands In Kits") || is.getType() != Material.PAPER || !is.getItemMeta().hasDisplayName() || !is.getItemMeta().getDisplayName().equals(Lang.COMMAND.getConfigValue())) {
|
||||
i.setItem(num, is);
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
if (back && !UltimateKits.getInstance().getConfig().getBoolean("Interfaces.Do Not Use Glass Borders")) {
|
||||
|
||||
ItemStack head2 = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
|
||||
ItemStack skull2 = head2;
|
||||
if (!UltimateKits.getInstance().v1_7)
|
||||
skull2 = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta();
|
||||
if (UltimateKits.getInstance().v1_7)
|
||||
skull2Meta.setOwner("MHF_ArrowLeft");
|
||||
skull2.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(Lang.BACK.getConfigValue());
|
||||
skull2.setItemMeta(skull2Meta);
|
||||
i.setItem(0, skull2);
|
||||
}
|
||||
|
||||
p.openInventory(i);
|
||||
UltimateKits.getInstance().whereAt.remove(p.getUniqueId());
|
||||
UltimateKits.getInstance().whereAt.put(p.getUniqueId(), "display");
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void saveKit(List<ItemStack> items) {
|
||||
try {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (ItemStack is : items) {
|
||||
if (is != null && is.getType() != null && is.getType() != Material.AIR) {
|
||||
if (is.getType() == Material.PAPER && ChatColor.stripColor(is.getItemMeta().getDisplayName()).equals("Command")) {
|
||||
StringBuilder command = new StringBuilder();
|
||||
for (String line : is.getItemMeta().getLore()) {
|
||||
command.append(line);
|
||||
}
|
||||
list.add(ChatColor.stripColor(command.toString()));
|
||||
} else if (is.getType() == Material.PAPER && ChatColor.stripColor(is.getItemMeta().getDisplayName()).equals("Money")) {
|
||||
String money = is.getItemMeta().getLore().get(0);
|
||||
list.add(ChatColor.stripColor(money));
|
||||
} else {
|
||||
String serialized = Methods.serializeItemStack(is);
|
||||
list.add(serialized);
|
||||
}
|
||||
}
|
||||
}
|
||||
contents = list;
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<ItemStack> getReadableContents(Player player, boolean commands) {
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
try {
|
||||
for (String str : getContents()) {
|
||||
if ((!str.startsWith("/") && !str.startsWith("$")) || commands) {
|
||||
ItemStack parseStack;
|
||||
if (str.startsWith("$")) {
|
||||
parseStack = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta meta = parseStack.getItemMeta();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add("§a" + str.trim());
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(Lang.MONEY.getConfigValue());
|
||||
parseStack.setItemMeta(meta);
|
||||
} else if (str.startsWith("/")) {
|
||||
parseStack = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta meta = parseStack.getItemMeta();
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
|
||||
int index = 0;
|
||||
while (index < str.length()) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&a" + str.substring(index, Math.min(index + 30, str.length()))));
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(Lang.COMMAND.getConfigValue());
|
||||
parseStack.setItemMeta(meta);
|
||||
} else {
|
||||
parseStack = Methods.deserializeItemStack(str);
|
||||
}
|
||||
ItemStack fin = parseStack;
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI") && parseStack.getItemMeta().getLore() != null) {
|
||||
ArrayList<String> lore2 = new ArrayList<>();
|
||||
ItemMeta meta2 = parseStack.getItemMeta();
|
||||
for (String lor : parseStack.getItemMeta().getLore()) {
|
||||
lor = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, lor.replace(" ", "_")).replace("_", " ");
|
||||
lore2.add(lor);
|
||||
}
|
||||
meta2.setLore(lore2);
|
||||
fin.setItemMeta(meta2);
|
||||
}
|
||||
stacks.add(fin);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public void giveKit(Player player) {
|
||||
try {
|
||||
givePartKit(player, null);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void givePartKit(Player player, Key key) {
|
||||
try {
|
||||
|
||||
List<String> innerContents = new ArrayList<>(getContents());
|
||||
int amt = innerContents.size();
|
||||
|
||||
if (key != null && key.getAmt() != -1 && key.getAmt() < innerContents.size()) {
|
||||
amt = innerContents.size() - key.getAmt();
|
||||
}
|
||||
|
||||
while (key != null && amt != 0 && key.getAmt() != -1) {
|
||||
int num = ThreadLocalRandom.current().nextInt(0, innerContents.size());
|
||||
innerContents.remove(num);
|
||||
amt--;
|
||||
}
|
||||
for (String line : innerContents) {
|
||||
if (line.startsWith("$")) {
|
||||
try {
|
||||
Methods.pay(player, Double.parseDouble(line.substring("$".length()).trim()));
|
||||
player.sendMessage(Lang.ECO_SENT.getConfigValue(Arconix.pl().getApi().format().formatEconomy(Double.parseDouble(line.substring("$".length()).trim()))));
|
||||
} catch (NumberFormatException ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
continue;
|
||||
} else if (line.startsWith("/")) {
|
||||
String parsed = line.substring(1);
|
||||
parsed = parsed.replace("{player}", player.getName());
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), parsed); // Not proud of this.
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack parseStack = Methods.deserializeItemStack(line);
|
||||
if (parseStack.getType() == Material.AIR) continue;
|
||||
|
||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(parseStack);
|
||||
|
||||
|
||||
for (ItemStack item : overfilled.values()) {
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), item);
|
||||
}
|
||||
}
|
||||
|
||||
player.updateInventory();
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDelay(Player player) {
|
||||
UltimateKits.getInstance().getDataFile().getConfig().set("Kits." + name + ".delays." + player.getUniqueId().toString(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public Long getNextUse(Player player) {
|
||||
String configSectionPlayer = "Kits." + name + ".delays." + player.getUniqueId().toString();
|
||||
FileConfiguration config = UltimateKits.getInstance().getDataFile().getConfig();
|
||||
|
||||
if (!config.contains(configSectionPlayer)) {
|
||||
return 0L;
|
||||
} else if (this.delay == -1) return -1L;
|
||||
|
||||
|
||||
long last = config.getLong(configSectionPlayer);
|
||||
long delay = (long) this.delay * 1000;
|
||||
|
||||
return (last + delay) >= System.currentTimeMillis() ? (last + delay) - System.currentTimeMillis() : 0L;
|
||||
}
|
||||
|
||||
public void confirmBuy(String kitName, Player p) {
|
||||
try {
|
||||
|
||||
double cost = price;
|
||||
if (hasPermission(p) && UltimateKits.getInstance().getConfig().getBoolean("Main.Allow Players To Receive Kits For Free If They Have Permission")) {
|
||||
cost = 0;
|
||||
}
|
||||
Inventory i = Bukkit.createInventory(null, 27, Arconix.pl().getApi().format().formatTitle(Lang.GUI_TITLE_YESNO.getConfigValue(cost)));
|
||||
|
||||
String title = Arconix.pl().getApi().format().formatTitle("&c" + StringUtils.capitalize(kitName.toLowerCase()));
|
||||
ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
|
||||
if (displayItem != null) item = new ItemStack(displayItem);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(title);
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&a$" + Arconix.pl().getApi().format().formatEconomy(cost)));
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
i.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(8, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(10, Methods.getBackgroundGlass(false));
|
||||
i.setItem(16, Methods.getBackgroundGlass(false));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
i.setItem(18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(19, Methods.getBackgroundGlass(true));
|
||||
i.setItem(20, Methods.getBackgroundGlass(false));
|
||||
i.setItem(24, Methods.getBackgroundGlass(false));
|
||||
i.setItem(25, Methods.getBackgroundGlass(true));
|
||||
i.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
ItemStack item2 = new ItemStack(Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Buy Icon")), 1);
|
||||
ItemMeta itemmeta2 = item2.getItemMeta();
|
||||
itemmeta2.setDisplayName(Lang.YES_GUI.getConfigValue());
|
||||
item2.setItemMeta(itemmeta2);
|
||||
|
||||
ItemStack item3 = new ItemStack(Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta itemmeta3 = item3.getItemMeta();
|
||||
itemmeta3.setDisplayName(Lang.NO_GUI.getConfigValue());
|
||||
item3.setItemMeta(itemmeta3);
|
||||
|
||||
i.setItem(4, item);
|
||||
i.setItem(11, item2);
|
||||
i.setItem(15, item3);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateKits.getInstance(), () -> {
|
||||
p.openInventory(i);
|
||||
UltimateKits.getInstance().buy.put(p.getUniqueId(), kitName);
|
||||
}, 1);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void buyWithEconomy(Player p) {
|
||||
try {
|
||||
if (UltimateKits.getInstance().getServer().getPluginManager().getPlugin("Vault") == null) return;
|
||||
RegisteredServiceProvider<Economy> rsp = UltimateKits.getInstance().getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
if (!econ.has(p, price) && !hasPermission(p)) {
|
||||
if (!hasPermission(p))
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.NO_PERM.getConfigValue(showableName)));
|
||||
else
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.CANNOT_AFFORD.getConfigValue(showableName)));
|
||||
return;
|
||||
}
|
||||
if (this.delay > 0) {
|
||||
|
||||
if (getNextUse(p) == -1) {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.NOT_TWICE.getConfigValue(showableName)));
|
||||
} else if (getNextUse(p) != 0) {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.DELAY.getConfigValue(Arconix.pl().getApi().format().readableTime(getNextUse(p)))));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (delay != 0) {
|
||||
updateDelay(p); //updates delay on buy
|
||||
}
|
||||
econ.withdrawPlayer(p, price);
|
||||
give(p, false, true, false);
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean hasPermission(Player player) {
|
||||
try {
|
||||
if (player.hasPermission("uc.kit." + name.toLowerCase())) return true;
|
||||
if (player.hasPermission("essentials.kit." + name.toLowerCase())) return true;
|
||||
if (player.hasPermission("ultimatekits.kit." + name.toLowerCase())) return true;
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
|
||||
public void setLink(String link) {
|
||||
this.link = link;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public void setDelay(int delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public List<String> getContents() {
|
||||
return this.contents;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getShowableName() {
|
||||
return showableName;
|
||||
}
|
||||
|
||||
public Material getDisplayItem() {
|
||||
return displayItem;
|
||||
}
|
||||
|
||||
public void setDisplayItem(Material displayItem) {
|
||||
this.displayItem = displayItem;
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
|
||||
public void setHidden(boolean hidden) {
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
public void setContents(List<String> contents) {
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * (name != null ? name.hashCode() : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Kit)) return false;
|
||||
|
||||
Kit kit = (Kit) o;
|
||||
return Objects.equals(name, kit.name);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package com.songoda.ultimatekits.kit.object;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class KitBlockData {
|
||||
|
||||
private boolean hologram, particles, items;
|
||||
|
||||
private boolean itemOverride;
|
||||
|
||||
private KitType type;
|
||||
|
||||
private final Kit kit;
|
||||
|
||||
private final Location location;
|
||||
|
||||
public KitBlockData(Kit kit, Location location, KitType type, boolean hologram, boolean particles, boolean items, boolean itemOverride) {
|
||||
this.kit = kit;
|
||||
this.location = location;
|
||||
this.hologram = hologram;
|
||||
this.particles = particles;
|
||||
this.items = items;
|
||||
this.itemOverride = itemOverride;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
setShowHologram(false);
|
||||
setDisplayingItems(false);
|
||||
setHasParticles(false);
|
||||
UltimateKits.getInstance().displayitem.displayItem(this);
|
||||
UltimateKits.getInstance().holo.updateHolograms();
|
||||
}
|
||||
|
||||
public KitBlockData(Kit kit, Location location) {
|
||||
this(kit, location, KitType.PREVIEW, false, false, false, false);
|
||||
}
|
||||
|
||||
public Kit getKit() {
|
||||
return kit;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location.clone();
|
||||
}
|
||||
|
||||
public boolean showHologram() {
|
||||
return hologram;
|
||||
}
|
||||
|
||||
public void setShowHologram(boolean hologram) {
|
||||
this.hologram = hologram;
|
||||
}
|
||||
|
||||
public boolean hasParticles() {
|
||||
return particles;
|
||||
}
|
||||
|
||||
public void setHasParticles(boolean particles) {
|
||||
this.particles = particles;
|
||||
}
|
||||
|
||||
public boolean isDisplayingItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setDisplayingItems(boolean items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public boolean isItemOverride() {
|
||||
return itemOverride;
|
||||
}
|
||||
|
||||
public void setItemOverride(boolean itemOverride) {
|
||||
this.itemOverride = itemOverride;
|
||||
}
|
||||
|
||||
public KitType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(KitType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.songoda.ultimatekits.kit.object;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class KitEditorPlayerData {
|
||||
|
||||
public enum EditorType { OVERVIEW, GENERAL, SELLING, GUI, COMMAND, MONEY, DELAY, TITLE, PRICE, LINK, NOTIN }
|
||||
|
||||
private Kit kit;
|
||||
private EditorType editorType = EditorType.NOTIN;
|
||||
private ItemStack[] inventory = new ItemStack[0];
|
||||
private boolean showInventory = false;
|
||||
|
||||
public Kit getKit() {
|
||||
return kit;
|
||||
}
|
||||
|
||||
public void setKit(Kit kit) {
|
||||
this.kit = kit;
|
||||
}
|
||||
|
||||
public EditorType getEditorType() {
|
||||
return editorType;
|
||||
}
|
||||
|
||||
public void setEditorType(EditorType editorType) {
|
||||
this.editorType = editorType;
|
||||
}
|
||||
|
||||
public boolean isInInventory() {
|
||||
return showInventory;
|
||||
}
|
||||
|
||||
public void setInInventory(boolean showInventory) {
|
||||
this.showInventory = showInventory;
|
||||
}
|
||||
|
||||
public ItemStack[] getInventory() {
|
||||
return Arrays.copyOf(inventory, inventory.length);
|
||||
}
|
||||
|
||||
public void setInventory(ItemStack[] inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.songoda.ultimatekits.kit.object;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public final class KitManager {
|
||||
|
||||
private List<Kit> registeredKits = new LinkedList<>();
|
||||
private final Map<Location, KitBlockData> kitsAtLocations = new HashMap<>();
|
||||
|
||||
public boolean addKit(Kit kit) {
|
||||
if (kit == null) return false;
|
||||
return registeredKits.add(kit);
|
||||
}
|
||||
|
||||
public void removeKit(Kit kit) {
|
||||
registeredKits.remove(kit);
|
||||
removeLocationsFromKit(kit);
|
||||
}
|
||||
|
||||
public void removeLocationsFromKit(Kit kit) {
|
||||
for (Map.Entry<Location, KitBlockData> entry : kitsAtLocations.entrySet()) {
|
||||
if (entry.getValue().getKit() == kit) {
|
||||
entry.getValue().reset();
|
||||
kitsAtLocations.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addKitToLocation(Kit kit, Location location) {
|
||||
kitsAtLocations.put(roundLocation(location), new KitBlockData(kit, location));
|
||||
}
|
||||
|
||||
public void addKitToLocation(Kit kit, Location location, KitType type, boolean hologram, boolean particles, boolean items, boolean itemOverride) {
|
||||
kitsAtLocations.put(roundLocation(location), new KitBlockData(kit, location, type, hologram, particles, items, itemOverride));
|
||||
}
|
||||
|
||||
public Kit removeKitFromLocation(Location location) {
|
||||
getKit(roundLocation(location)).reset();
|
||||
|
||||
KitBlockData removed = kitsAtLocations.remove(roundLocation(location));
|
||||
return (removed != null ? removed.getKit() : null);
|
||||
}
|
||||
|
||||
public Kit getKit(String name) {
|
||||
for (Kit kit : registeredKits)
|
||||
if (kit.getName().equalsIgnoreCase(name)) return kit;
|
||||
return null;
|
||||
}
|
||||
|
||||
public KitBlockData getKit(Location location) {
|
||||
return kitsAtLocations.get(roundLocation(location));
|
||||
}
|
||||
|
||||
public List<Kit> getKits() {
|
||||
return Collections.unmodifiableList(registeredKits);
|
||||
}
|
||||
|
||||
public Map<Location, KitBlockData> getKitLocations() {
|
||||
return Collections.unmodifiableMap(kitsAtLocations);
|
||||
}
|
||||
|
||||
public void clearKits() {
|
||||
this.registeredKits.clear();
|
||||
this.kitsAtLocations.clear();
|
||||
}
|
||||
|
||||
private Location roundLocation(Location location) {
|
||||
location = location.clone();
|
||||
location.setX(location.getBlockX());
|
||||
location.setY(location.getBlockY());
|
||||
location.setZ(location.getBlockZ());
|
||||
return location;
|
||||
}
|
||||
|
||||
public void moveKit(Kit kit, boolean up) {
|
||||
if (kit == null) return;
|
||||
|
||||
int i = 0;
|
||||
for (Kit kit2 : registeredKits) {
|
||||
if (kit == kit2)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
|
||||
int action = i-1;
|
||||
if (up) action = i+1;
|
||||
|
||||
if (action >= 0 && action < registeredKits.size())
|
||||
Collections.swap(registeredKits, i, action);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package com.songoda.ultimatekits.kit.object;
|
||||
|
||||
public enum KitType { PREVIEW, CRATE, CLAIM }
|
31
src/main/java/com/songoda/ultimatekits/utils/Debugger.java
Normal file
31
src/main/java/com/songoda/ultimatekits/utils/Debugger.java
Normal file
@ -0,0 +1,31 @@
|
||||
package com.songoda.ultimatekits.utils;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/21/2017.
|
||||
*/
|
||||
public class Debugger {
|
||||
|
||||
|
||||
public static void runReport(Exception e) {
|
||||
if (isDebug()) {
|
||||
System.out.println("==============================================================");
|
||||
System.out.println("The following is an error encountered in UltimateKits.");
|
||||
System.out.println("--------------------------------------------------------------");
|
||||
e.printStackTrace();
|
||||
System.out.println("==============================================================");
|
||||
}
|
||||
sendReport(e);
|
||||
}
|
||||
|
||||
public static void sendReport(Exception e) {
|
||||
|
||||
}
|
||||
|
||||
public static boolean isDebug() {
|
||||
UltimateKits plugin = UltimateKits.getInstance();
|
||||
return plugin.getConfig().getBoolean("System.Debugger Enabled");
|
||||
}
|
||||
|
||||
}
|
385
src/main/java/com/songoda/ultimatekits/utils/Methods.java
Normal file
385
src/main/java/com/songoda/ultimatekits/utils/Methods.java
Normal file
@ -0,0 +1,385 @@
|
||||
package com.songoda.ultimatekits.utils;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.*;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class Methods {
|
||||
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
UltimateKits plugin = UltimateKits.getInstance();
|
||||
return Arconix.pl().getApi().getGUI().getGlass(plugin.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), plugin.getConfig().getInt("Interfaces.Glass Type 1"));
|
||||
}
|
||||
|
||||
public static ItemStack getBackgroundGlass(boolean type) {
|
||||
UltimateKits plugin = UltimateKits.getInstance();
|
||||
if (type)
|
||||
return Arconix.pl().getApi().getGUI().getGlass(false, plugin.getConfig().getInt("Interfaces.Glass Type 2"));
|
||||
else
|
||||
return Arconix.pl().getApi().getGUI().getGlass(false, plugin.getConfig().getInt("Interfaces.Glass Type 3"));
|
||||
}
|
||||
|
||||
public static void fillGlass(Inventory i) {
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
ItemStack glass = getGlass();
|
||||
i.setItem(nu, glass);
|
||||
nu++;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canGiveKit(Player player) {
|
||||
try {
|
||||
if (player.hasPermission("ultimatekits.cangive")) return true;
|
||||
|
||||
if (player.hasPermission("essentials.kit.others")) return true;
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean doesKitExist(String kit) {
|
||||
return UltimateKits.getInstance().getKitFile().getConfig().contains("Kits." + kit);
|
||||
}
|
||||
|
||||
public static Collection<Entity> getNearbyEntities(Location location, double x, double y, double z) {
|
||||
if (!UltimateKits.getInstance().v1_7) return location.getWorld().getNearbyEntities(location, x, y, z);
|
||||
|
||||
if (location == null) return Collections.emptyList();
|
||||
|
||||
World world = location.getWorld();
|
||||
net.minecraft.server.v1_7_R4.AxisAlignedBB aabb = net.minecraft.server.v1_7_R4.AxisAlignedBB
|
||||
.a(location.getX() - x, location.getY() - y, location.getZ() - z, location.getX() + x, location.getY() + y, location.getZ() + z);
|
||||
List<net.minecraft.server.v1_7_R4.Entity> entityList = ((org.bukkit.craftbukkit.v1_7_R4.CraftWorld) world).getHandle().getEntities(null, aabb, null);
|
||||
List<Entity> bukkitEntityList = new ArrayList<>();
|
||||
|
||||
for (Object entity : entityList) {
|
||||
bukkitEntityList.add(((net.minecraft.server.v1_7_R4.Entity) entity).getBukkitEntity());
|
||||
}
|
||||
|
||||
return bukkitEntityList;
|
||||
}
|
||||
|
||||
public static boolean pay(Player p, double amount) {
|
||||
if (UltimateKits.getInstance().getServer().getPluginManager().getPlugin("Vault") == null) return false;
|
||||
RegisteredServiceProvider<Economy> rsp = UltimateKits.getInstance().getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
|
||||
econ.depositPlayer(p, amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String serializeItemStack(ItemStack item) {
|
||||
StringBuilder str = new StringBuilder(item.getType().name());
|
||||
if (item.getDurability() != 0)
|
||||
str.append(":").append(item.getDurability()).append(" ");
|
||||
else
|
||||
str.append(" ");
|
||||
|
||||
str.append(item.getAmount()).append(" ");
|
||||
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta.hasDisplayName())
|
||||
str.append("title:").append(fixLine(meta.getDisplayName())).append(" ");
|
||||
if (meta.hasLore()) {
|
||||
str.append("lore:");
|
||||
int num = 0;
|
||||
for (String line : meta.getLore()) {
|
||||
num++;
|
||||
str.append(fixLine(line));
|
||||
if (meta.getLore().size() != num)
|
||||
str.append("|");
|
||||
}
|
||||
str.append(" ");
|
||||
}
|
||||
|
||||
for (Enchantment ench : item.getEnchantments().keySet()) {
|
||||
str.append(ench.getName()).append(":").append(item.getEnchantmentLevel(ench)).append(" ");
|
||||
}
|
||||
|
||||
Set<ItemFlag> flags = meta.getItemFlags();
|
||||
if (flags != null && !flags.isEmpty()) {
|
||||
str.append("itemflags:");
|
||||
boolean first = true;
|
||||
for (ItemFlag flag : flags) {
|
||||
if (!first) {
|
||||
str.append(",");
|
||||
}
|
||||
str.append(flag.name());
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (item.getType()) {
|
||||
case WRITTEN_BOOK:
|
||||
BookMeta bookMeta = (BookMeta) item.getItemMeta();
|
||||
if (bookMeta.hasTitle()) {
|
||||
str.append("title:").append(bookMeta.getTitle().replace(" ", "_")).append(" ");
|
||||
}
|
||||
if (bookMeta.hasAuthor()) {
|
||||
str.append("author:").append(bookMeta.getAuthor()).append(" ");
|
||||
}
|
||||
if (bookMeta.hasPages()) {
|
||||
StringBuilder title = new StringBuilder(bookMeta.getAuthor());
|
||||
int num = 0;
|
||||
while (UltimateKits.getInstance().getDataFile().getConfig().contains("Books.pages." + title)) {
|
||||
title.append(num);
|
||||
}
|
||||
str.append("id:").append(bookMeta.getAuthor()).append(" ");
|
||||
int pNum = 0;
|
||||
for (String page : bookMeta.getPages()) {
|
||||
pNum++;
|
||||
UltimateKits.getInstance().getDataFile().getConfig().set("Books.pages." + title + "." + pNum, page);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ENCHANTED_BOOK:
|
||||
EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) item.getItemMeta();
|
||||
for (Enchantment e : enchantmentStorageMeta.getStoredEnchants().keySet()) {
|
||||
str.append(e.getName().toLowerCase()).append(":").append(enchantmentStorageMeta.getStoredEnchantLevel(e)).append(" ");
|
||||
}
|
||||
break;
|
||||
case FIREWORK:
|
||||
FireworkMeta fireworkMeta = (FireworkMeta) item.getItemMeta();
|
||||
if (fireworkMeta.hasEffects()) {
|
||||
for (FireworkEffect effect : fireworkMeta.getEffects()) {
|
||||
if (effect.getColors() != null && !effect.getColors().isEmpty()) {
|
||||
str.append("color:");
|
||||
boolean first = true;
|
||||
for (Color c : effect.getColors()) {
|
||||
if (!first) {
|
||||
str.append(",");
|
||||
}
|
||||
str.append(c.asRGB());
|
||||
first = false;
|
||||
}
|
||||
str.append(" ");
|
||||
}
|
||||
|
||||
str.append("shape: ").append(effect.getType().name()).append(" ");
|
||||
if (effect.getFadeColors() != null && !effect.getFadeColors().isEmpty()) {
|
||||
str.append("fade:");
|
||||
boolean first = true;
|
||||
for (Color c : effect.getFadeColors()) {
|
||||
if (!first) {
|
||||
str.append(",");
|
||||
}
|
||||
str.append(c.asRGB());
|
||||
first = false;
|
||||
}
|
||||
str.append(" ");
|
||||
}
|
||||
}
|
||||
str.append("power: ").append(fireworkMeta.getPower()).append(" ");
|
||||
}
|
||||
break;
|
||||
case POTION:
|
||||
PotionMeta potion = ((PotionMeta) item.getItemMeta());
|
||||
if (!UltimateKits.getInstance().v1_8 && !UltimateKits.getInstance().v1_7) {
|
||||
if (potion.hasColor()) {
|
||||
str.append("color:").append(potion.getColor().asRGB()).append(" ");
|
||||
}
|
||||
if (potion.getBasePotionData() != null
|
||||
&& potion.getBasePotionData().getType() != null
|
||||
&& potion.getBasePotionData().getType().getEffectType() != null) {
|
||||
PotionEffectType e = potion.getBasePotionData().getType().getEffectType();
|
||||
str.append("effect:").append(e.getName().toLowerCase()).append(" ").append("duration:").append(e.getDurationModifier()).append(" ");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SKULL_ITEM:
|
||||
SkullMeta skullMeta = (SkullMeta) item.getItemMeta();
|
||||
if (skullMeta != null && skullMeta.hasOwner()) {
|
||||
str.append("player:").append(skullMeta.getOwner()).append(" ");
|
||||
}
|
||||
break;
|
||||
case LEATHER_HELMET:
|
||||
case LEATHER_CHESTPLATE:
|
||||
case LEATHER_LEGGINGS:
|
||||
case LEATHER_BOOTS:
|
||||
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) item.getItemMeta();
|
||||
int rgb = leatherArmorMeta.getColor().asRGB();
|
||||
str.append("color:").append(rgb).append(" ");
|
||||
break;
|
||||
case BANNER:
|
||||
BannerMeta bannerMeta = (BannerMeta) item.getItemMeta();
|
||||
if (bannerMeta != null) {
|
||||
int basecolor = bannerMeta.getBaseColor().getColor().asRGB();
|
||||
str.append("basecolor:").append(basecolor).append(" ");
|
||||
for (org.bukkit.block.banner.Pattern p : bannerMeta.getPatterns()) {
|
||||
String type = p.getPattern().getIdentifier();
|
||||
int color = p.getColor().getColor().asRGB();
|
||||
str.append(type).append(",").append(color).append(" ");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SHIELD:
|
||||
BlockStateMeta shieldMeta = (BlockStateMeta) item.getItemMeta();
|
||||
Banner shieldBannerMeta = (Banner) shieldMeta.getBlockState();
|
||||
int basecolor = shieldBannerMeta.getBaseColor().getColor().asRGB();
|
||||
str.append("basecolor:").append(basecolor).append(" ");
|
||||
for (org.bukkit.block.banner.Pattern p : shieldBannerMeta.getPatterns()) {
|
||||
String type = p.getPattern().getIdentifier();
|
||||
int color = p.getColor().getColor().asRGB();
|
||||
str.append(type).append(",").append(color).append(" ");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return str.toString().replace("§", "&").trim();
|
||||
}
|
||||
|
||||
public static ItemStack deserializeItemStack(String string) {
|
||||
string = string.replace("&", "§");
|
||||
String[] splited = string.split("\\s+");
|
||||
|
||||
String[] val = splited[0].split(":");
|
||||
ItemStack item;
|
||||
if (Arconix.pl().getApi().doMath().isNumeric(val[0])) {
|
||||
item = new ItemStack(Integer.parseInt(val[0]));
|
||||
} else {
|
||||
item = new ItemStack(Material.valueOf(val[0]));
|
||||
}
|
||||
|
||||
if (item.getType() == Material.SKULL_ITEM) {
|
||||
item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
|
||||
}
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if (val.length == 2) {
|
||||
item.setDurability(Short.parseShort(val[1]));
|
||||
}
|
||||
if (splited.length >= 2) {
|
||||
if (Arconix.pl().getApi().doMath().isNumeric(splited[1])) {
|
||||
item.setAmount(Integer.parseInt(splited[1]));
|
||||
}
|
||||
|
||||
for (String st : splited) {
|
||||
String str = unfixLine(st);
|
||||
if (!str.contains(":")) continue;
|
||||
String[] ops = str.split(":", 2);
|
||||
|
||||
String option = ops[0];
|
||||
String value = ops[1];
|
||||
|
||||
if (Enchantment.getByName(option.replace(" ", "_").toUpperCase()) != null) {
|
||||
Enchantment enchantment = Enchantment.getByName(option.replace(" ", "_").toUpperCase());
|
||||
if (item.getType() != Material.ENCHANTED_BOOK) {
|
||||
meta.addEnchant(enchantment, Integer.parseInt(value), true);
|
||||
} else {
|
||||
((EnchantmentStorageMeta) meta).addStoredEnchant(enchantment, Integer.parseInt(value), true);
|
||||
}
|
||||
}
|
||||
|
||||
String effect = "";
|
||||
int duration = 0;
|
||||
int hit = 0;
|
||||
|
||||
value = value.replace("_", " ");
|
||||
switch (option) {
|
||||
case "title":
|
||||
if (item.getType() == Material.WRITTEN_BOOK) {
|
||||
((BookMeta) meta).setTitle(value);
|
||||
} else meta.setDisplayName(value);
|
||||
break;
|
||||
case "lore":
|
||||
String[] parts = value.split("\\|");
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
for (String line : parts)
|
||||
lore.add(Arconix.pl().getApi().format().formatText(line));
|
||||
meta.setLore(lore);
|
||||
break;
|
||||
case "player":
|
||||
if (item.getType() == Material.SKULL_ITEM) {
|
||||
((SkullMeta) meta).setOwner(value);
|
||||
}
|
||||
break;
|
||||
case "author":
|
||||
if (item.getType() == Material.WRITTEN_BOOK) {
|
||||
((BookMeta) meta).setAuthor(value);
|
||||
}
|
||||
break;
|
||||
case "effect":
|
||||
case "duration":
|
||||
hit++;
|
||||
if (option.equalsIgnoreCase("effect")) {
|
||||
effect = value;
|
||||
} else {
|
||||
duration = Integer.parseInt(value);
|
||||
}
|
||||
|
||||
if (hit == 2) {
|
||||
PotionEffect effect2 = PotionEffectType.getByName(effect).createEffect(duration, 0);
|
||||
((PotionMeta) meta).addCustomEffect(effect2, false);
|
||||
}
|
||||
|
||||
break;
|
||||
case "id":
|
||||
if (item.getType() == Material.WRITTEN_BOOK) {
|
||||
if (!UltimateKits.getInstance().getDataFile().getConfig().contains("Books.pages." + value))
|
||||
continue;
|
||||
ConfigurationSection cs = UltimateKits.getInstance().getDataFile().getConfig().getConfigurationSection("Books.pages." + value);
|
||||
for (String key : cs.getKeys(false)) {
|
||||
((BookMeta) meta).addPage(UltimateKits.getInstance().getDataFile().getConfig().getString("Books.pages." + value + "." + key));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "color":
|
||||
switch (item.getType()) {
|
||||
case POTION:
|
||||
if (!UltimateKits.getInstance().v1_8 && !UltimateKits.getInstance().v1_7) {
|
||||
((PotionMeta) meta).setColor(Color.fromRGB(Integer.parseInt(value)));
|
||||
}
|
||||
break;
|
||||
case LEATHER_HELMET:
|
||||
case LEATHER_CHESTPLATE:
|
||||
case LEATHER_LEGGINGS:
|
||||
case LEATHER_BOOTS:
|
||||
((LeatherArmorMeta) meta).setColor(Color.fromRGB(Integer.parseInt(value)));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static String fixLine(String line) {
|
||||
line = line.replace(" ", "_");
|
||||
return line;
|
||||
}
|
||||
|
||||
public static String unfixLine(String line) {
|
||||
line = line.replace("_", " ");
|
||||
return line;
|
||||
}
|
||||
|
||||
public static String getKitFromLocation(Location location) {
|
||||
return UltimateKits.getInstance().getConfig().getString("data.block." + Arconix.pl().getApi().serialize().serializeLocation(location));
|
||||
}
|
||||
}
|
@ -0,0 +1,256 @@
|
||||
package com.songoda.ultimatekits.utils;
|
||||
|
||||
import com.songoda.arconix.api.utils.ConfigWrapper;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by songo on 6/4/2017.
|
||||
*/
|
||||
public class SettingsManager implements Listener {
|
||||
|
||||
String pluginName = "UltimateKits";
|
||||
private final UltimateKits instance;
|
||||
|
||||
private static ConfigWrapper defs;
|
||||
|
||||
private Map<Player, String> cat = new HashMap<>();
|
||||
|
||||
public SettingsManager(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
instance.saveResource("SettingDefinitions.yml", true);
|
||||
defs = new ConfigWrapper(instance, "", "SettingDefinitions.yml");
|
||||
defs.createNewFile("Loading data file", "UltimateKits SettingDefinitions file");
|
||||
instance.getServer().getPluginManager().registerEvents(this, instance);
|
||||
}
|
||||
|
||||
public Map<Player, String> current = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
if (e.getInventory() == null
|
||||
|| e.getCurrentItem() == null
|
||||
|| !e.getCurrentItem().hasItemMeta()
|
||||
|| !e.getCurrentItem().getItemMeta().hasDisplayName()
|
||||
|| e.getWhoClicked().getOpenInventory().getTopInventory() != e.getInventory()) {
|
||||
return;
|
||||
}
|
||||
if (e.getInventory().getTitle().equals(pluginName + " Settings Manager")) {
|
||||
|
||||
if (e.getCurrentItem().getType().equals(Material.STAINED_GLASS_PANE)) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
String type = ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName());
|
||||
cat.put((Player) e.getWhoClicked(), type);
|
||||
openEditor((Player) e.getWhoClicked());
|
||||
e.setCancelled(true);
|
||||
} else if (e.getInventory().getTitle().equals(pluginName + " Settings KitEditor")) {
|
||||
|
||||
if (e.getCurrentItem().getType().equals(Material.STAINED_GLASS_PANE)) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
e.setCancelled(true);
|
||||
|
||||
String key = cat.get(p) + "." + ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName());
|
||||
|
||||
if (instance.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
|
||||
boolean bool = (Boolean) instance.getConfig().get(key);
|
||||
if (!bool)
|
||||
instance.getConfig().set(key, true);
|
||||
else
|
||||
instance.getConfig().set(key, false);
|
||||
finishEditing(p);
|
||||
} else {
|
||||
editObject(p, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
if (!current.containsKey(p)) {
|
||||
return;
|
||||
}
|
||||
switch (instance.getConfig().get(current.get(p)).getClass().getName()) {
|
||||
case "java.lang.Integer":
|
||||
instance.getConfig().set(current.get(p), Integer.parseInt(e.getMessage()));
|
||||
break;
|
||||
case "java.lang.Double":
|
||||
instance.getConfig().set(current.get(p), Double.parseDouble(e.getMessage()));
|
||||
break;
|
||||
case "java.lang.String":
|
||||
instance.getConfig().set(current.get(p), e.getMessage());
|
||||
break;
|
||||
}
|
||||
finishEditing(p);
|
||||
e.setCancelled(true);
|
||||
|
||||
}
|
||||
|
||||
public void finishEditing(Player p) {
|
||||
current.remove(p);
|
||||
instance.saveConfig();
|
||||
openEditor(p);
|
||||
}
|
||||
|
||||
|
||||
public void editObject(Player p, String current) {
|
||||
this.current.put(p, ChatColor.stripColor(current));
|
||||
p.closeInventory();
|
||||
p.sendMessage("");
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&7Please enter a value for &6" + current + "&7."));
|
||||
if (instance.getConfig().get(current).getClass().getName().equals("java.lang.Integer")) {
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&cUse only numbers."));
|
||||
}
|
||||
p.sendMessage("");
|
||||
}
|
||||
|
||||
public void openSettingsManager(Player p) {
|
||||
Inventory i = Bukkit.createInventory(null, 27, pluginName + " Settings Manager");
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
i.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
|
||||
int spot = 10;
|
||||
for (String key : instance.getConfig().getConfigurationSection("").getKeys(false)) {
|
||||
ItemStack item = new ItemStack(Material.WOOL, 1, (byte) (spot - 9));
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setLore(Collections.singletonList(Arconix.pl().getApi().format().formatText("&6Click To Edit This Category.")));
|
||||
meta.setDisplayName(Arconix.pl().getApi().format().formatText("&f&l" + key));
|
||||
item.setItemMeta(meta);
|
||||
i.setItem(spot, item);
|
||||
spot++;
|
||||
}
|
||||
p.openInventory(i);
|
||||
}
|
||||
|
||||
public void openEditor(Player p) {
|
||||
Inventory i = Bukkit.createInventory(null, 54, pluginName + " Settings KitEditor");
|
||||
|
||||
int num = 0;
|
||||
for (String key : instance.getConfig().getConfigurationSection(cat.get(p)).getKeys(true)) {
|
||||
String fKey = cat.get(p) + "." + key;
|
||||
ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Arconix.pl().getApi().format().formatText("&6" + key));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
switch (instance.getConfig().get(fKey).getClass().getName()) {
|
||||
case "java.lang.Boolean":
|
||||
|
||||
item.setType(Material.LEVER);
|
||||
boolean bool = (Boolean) instance.getConfig().get(fKey);
|
||||
|
||||
if (!bool)
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&c" + false));
|
||||
else
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&a" + true));
|
||||
|
||||
break;
|
||||
case "java.lang.String":
|
||||
item.setType(Material.PAPER);
|
||||
String str = (String) instance.getConfig().get(fKey);
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&9" + str));
|
||||
break;
|
||||
case "java.lang.Integer":
|
||||
item.setType(Material.WATCH);
|
||||
|
||||
int in = (Integer) instance.getConfig().get(fKey);
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&5" + in));
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
if (defs.getConfig().contains(fKey)) {
|
||||
String text = defs.getConfig().getString(key);
|
||||
|
||||
Pattern regex = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL);
|
||||
Matcher m = regex.matcher(text);
|
||||
while (m.find()) {
|
||||
if (m.end() != text.length() || m.group().length() != 0)
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7" + m.group()));
|
||||
}
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
i.setItem(num, item);
|
||||
num++;
|
||||
}
|
||||
p.openInventory(i);
|
||||
}
|
||||
|
||||
public void updateSettings() {
|
||||
for (settings s : settings.values()) {
|
||||
FileConfiguration config = instance.getConfig();
|
||||
if (config.contains(s.oldSetting)) {
|
||||
config.addDefault(s.setting, config.get(s.oldSetting));
|
||||
config.set(s.setting, config.get(s.oldSetting));
|
||||
config.set(s.oldSetting, null);
|
||||
} else if (s.setting.equals("Main.Upgrade Particle Type")) {
|
||||
if (instance.v1_7 || instance.v1_8)
|
||||
config.addDefault(s.setting, "WITCH_MAGIC");
|
||||
else
|
||||
config.addDefault(s.setting, s.option);
|
||||
} else
|
||||
config.addDefault(s.setting, s.option);
|
||||
}
|
||||
}
|
||||
|
||||
public enum settings {
|
||||
|
||||
o1("Lock-KP-Commands", "Main.Block Help Page For Non Admins", false),
|
||||
o2("Enabled-Kits", "Main.Enabled Custom Kits And Kit Commands", true),
|
||||
o3("Only-Show-Kits-With-Perms", "Main.Only Show Players Kits They Have Permission To Use", false),
|
||||
o4("Kits-Free-With-Perms", "Main.Allow Players To Receive Kits For Free If They Have Permission", true),
|
||||
o5("Dont-Preview-Commands", "Main.Dont Preview Commands In Kits", false),
|
||||
o6("Hologram-Layout", "Main.Hologram Layout", Arrays.asList("{TITLE}", "{LEFT-CLICK}", "{RIGHT-CLICK}")),
|
||||
o7("EnableSound", "Main.Sounds Enabled", true),
|
||||
o8("Sound", "Main.Sound Played While Clicking In Inventories", "ENTITY_ENDERMEN_TELEPORT"),
|
||||
o85("Sound", "Main.Prevent The Redeeming of a Kit When Inventory Is Full", true),
|
||||
|
||||
o9("Exit-Icon", "Interfaces.Exit Icon", "WOOD_DOOR"),
|
||||
o10("Buy-Icon", "Interfaces.Buy Icon", "EMERALD"),
|
||||
o11("Glass-Type-1", "Interfaces.Glass Type 1", 7),
|
||||
o12("Glass-Type-2", "Interfaces.Glass Type 2", 11),
|
||||
o13("Glass-Type-3", "Interfaces.Glass Type 3", 3),
|
||||
o14("Rainbow-Glass", "Interfaces.Replace Glass Type 1 With Rainbow Glass", false),
|
||||
o15("glassless", "Interfaces.Do Not Use Glass Borders", false),
|
||||
|
||||
o16("Debug-Mode", "System.Debugger Enabled", false);
|
||||
|
||||
private String setting;
|
||||
private String oldSetting;
|
||||
private Object option;
|
||||
|
||||
settings(String oldSetting, String setting, Object option) {
|
||||
this.oldSetting = oldSetting;
|
||||
this.setting = setting;
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ version: 1.0.1
|
||||
depend: [Arconix]
|
||||
softdepend: [PlaceholderAPI, Vault, UltimateCore, Essentials, MiniKitPvP]
|
||||
description: View a kit before you purchase it!
|
||||
author: songoda
|
||||
author: Songoda
|
||||
commands:
|
||||
ultimatekits:
|
||||
description: View information on this plugin.
|
Loading…
Reference in New Issue
Block a user