mirror of
https://github.com/songoda/UltimateRepairing.git
synced 2025-01-06 00:08:06 +01:00
Maven + UTF-8 + New Arconix
This commit is contained in:
parent
67c89b62a0
commit
0f0070cd9e
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ out/
|
||||
\.idea/
|
||||
|
||||
RepairPlus\.iml
|
||||
/src/main/java/META-INF/MANIFEST.MF
|
||||
|
78
pom.xml
Normal file
78
pom.xml
Normal file
@ -0,0 +1,78 @@
|
||||
<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>RepairPlus</artifactId>
|
||||
<version>1.3.5</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
<build>
|
||||
<finalName>RepairPlus</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>
|
||||
</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>
|
||||
<!--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>
|
||||
</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.
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;
|
||||
}
|
||||
|
||||
}
|
103
src/main/java/com/songoda/repairplus/Lang.java
Normal file
103
src/main/java/com/songoda/repairplus/Lang.java
Normal file
@ -0,0 +1,103 @@
|
||||
package com.songoda.repairplus;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public enum Lang {
|
||||
|
||||
PREFIX("prefix", "&7[&9RepairPlus&7]"),
|
||||
|
||||
NOT_ENOUGH("not-enough", "&cYou don't have enough {TYPE} &cto repair this item!"),
|
||||
|
||||
NEED_SPACE("need-space", "&cYou need to have free space above the anvil!"),
|
||||
|
||||
CANT_REPAIR("cant-repair", "&cYou can't repair this!"),
|
||||
|
||||
ALREADY_REPAIRING("already-repairing", "&cYou are already repairing something!"),
|
||||
|
||||
TIME_OUT("time-out", "&cYour repair timed out..."),
|
||||
|
||||
COST("cost", "&aRepairing will cost you: &9{COST} XP Level(s)&a."),
|
||||
|
||||
COST_ECO("cost-eco", "&aRepairing will cost you: &9${COST}&a."),
|
||||
|
||||
YES_NO("yes-no", "&aType &9yes &aor &9no &ain chat."),
|
||||
|
||||
NOT_DAMAGED("not-damaged", "&aThis item is not damaged."),
|
||||
|
||||
SUCCESS("success", "&aYour item has been successfully repaired!"),
|
||||
|
||||
WOULD_YOU_LIKE("would-you-like", "&aWould you like to repair your &9{ITEM}&a?"),
|
||||
|
||||
CANCELLED("cancelled", "&cCancelled repairing."),
|
||||
|
||||
YES("yes", "Yes"),
|
||||
|
||||
NO("no", "No"),
|
||||
|
||||
ECO_GUI("eco-gui", "${COST}"),
|
||||
|
||||
CLICK("click", "Left-Click with an item"),
|
||||
|
||||
SWAPCLICK("swap-click", "Right-Click with an item"),
|
||||
|
||||
ONECLICK("one-click", "Click with an item"),
|
||||
|
||||
TOREPAIR("torepair", "to &6Repair&r!"),
|
||||
|
||||
XP("XP", "&9XP"),
|
||||
ECO("ECO", "&9Economy"),
|
||||
ITEM("Item", "&9{ITEM}"),
|
||||
|
||||
XP_LORE("XP-lore", "&7Click to repair with XP."),
|
||||
ECO_LORE("ECO-lore", "&7Click to repair with Economy."),
|
||||
ITEM_LORE("Item-lore", "&7Click to repair with {ITEM}."),
|
||||
|
||||
GUI_TITLE("gui-title", "&9How do you want to repair?"),
|
||||
|
||||
GUI_TITLE_YESNO("gui-title-yesno", "&9Repair for &a{COST}&9?"),
|
||||
|
||||
NEXT("Next", "&9Next"),
|
||||
BACK("Back", "&9Back"),
|
||||
|
||||
YES_GUI("yes-gui", "&a&lYes"),
|
||||
|
||||
NO_GUI("no-gui", "&c&lNo");
|
||||
|
||||
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() {
|
||||
return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, this.def));
|
||||
}
|
||||
|
||||
public String getConfigValue(String arg) {
|
||||
String value = ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, this.def));
|
||||
|
||||
if (arg != null) {
|
||||
value = value.replace("{ITEM}", arg);
|
||||
value = value.replace("{XP}", arg);
|
||||
value = value.replace("{COST}", arg);
|
||||
value = value.replace("{TYPE}", arg);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
14
src/main/java/com/songoda/repairplus/References.java
Normal file
14
src/main/java/com/songoda/repairplus/References.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.songoda.repairplus;
|
||||
|
||||
public class References {
|
||||
|
||||
private String prefix;
|
||||
|
||||
public References() {
|
||||
prefix = Lang.PREFIX.getConfigValue(null) + " ";
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
}
|
118
src/main/java/com/songoda/repairplus/RepairPlus.java
Normal file
118
src/main/java/com/songoda/repairplus/RepairPlus.java
Normal file
@ -0,0 +1,118 @@
|
||||
package com.songoda.repairplus;
|
||||
|
||||
import com.songoda.arconix.api.utils.ConfigWrapper;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.repairplus.events.BlockListeners;
|
||||
import com.songoda.repairplus.events.InteractListeners;
|
||||
import com.songoda.repairplus.events.InventoryListeners;
|
||||
import com.songoda.repairplus.events.PlayerListeners;
|
||||
import com.songoda.repairplus.handlers.CommandHandler;
|
||||
import com.songoda.repairplus.handlers.HologramHandler;
|
||||
import com.songoda.repairplus.handlers.ParticleHandler;
|
||||
import com.songoda.repairplus.handlers.RepairHandler;
|
||||
import com.songoda.repairplus.utils.Debugger;
|
||||
import com.songoda.repairplus.utils.SettingsManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class RepairPlus extends JavaPlugin implements Listener {
|
||||
public static CommandSender console = Bukkit.getConsoleSender();
|
||||
|
||||
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 RepairPlus INSTANCE;
|
||||
|
||||
public References references = null;
|
||||
private ConfigWrapper langFile = new ConfigWrapper(this, "", "lang.yml");
|
||||
|
||||
public RepairHandler repair;
|
||||
public HologramHandler holo = null;
|
||||
public SettingsManager settingsManager;
|
||||
|
||||
public void onEnable() {
|
||||
INSTANCE = this;
|
||||
|
||||
Arconix.pl().hook(this);
|
||||
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7RepairPlus " + this.getDescription().getVersion() + " by &5Brianna <3!"));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &aEnabling&7..."));
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
|
||||
settingsManager = new SettingsManager(this);
|
||||
settingsManager.updateSettings();
|
||||
setupConfig();
|
||||
|
||||
langFile.createNewFile("Loading language file", "RepairPlus language file");
|
||||
loadLanguageFile();
|
||||
references = new References();
|
||||
|
||||
repair = new RepairHandler();
|
||||
holo = new HologramHandler(this);
|
||||
new ParticleHandler(this);
|
||||
|
||||
new com.massivestats.MassiveStats(this, 900);
|
||||
|
||||
this.getCommand("RPAnvil").setExecutor(new CommandHandler(this));
|
||||
this.getCommand("RepairPlus").setExecutor(new CommandHandler(this));
|
||||
|
||||
getServer().getPluginManager().registerEvents(new PlayerListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new BlockListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new InteractListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new InventoryListeners(this), this);
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7RepairPlus " + this.getDescription().getVersion() + " by &5Brianna <3!"));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &cDisabling&7..."));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void setupConfig() {
|
||||
try {
|
||||
settingsManager.updateSettings();
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
try {
|
||||
langFile.createNewFile("Loading language file", "RepairPlus language file");
|
||||
loadLanguageFile();
|
||||
references = new References();
|
||||
reloadConfig();
|
||||
saveConfig();
|
||||
holo.updateHolograms();
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadLanguageFile() {
|
||||
try {
|
||||
Lang.setFile(langFile.getConfig());
|
||||
|
||||
for (final Lang value : Lang.values()) {
|
||||
langFile.getConfig().addDefault(value.getPath(), value.getDefault());
|
||||
}
|
||||
|
||||
langFile.getConfig().options().copyDefaults(true);
|
||||
langFile.saveConfig();
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static RepairPlus getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package com.songoda.repairplus.anvil;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class PlayerAnvilData {
|
||||
|
||||
public enum RepairType { ECONOMY, ITEM, XP }
|
||||
|
||||
private Location location;
|
||||
private int price;
|
||||
private RepairType type;
|
||||
private Item item;
|
||||
private ItemStack toBeRepaired;
|
||||
private Location locations;
|
||||
private boolean inRepair;
|
||||
private boolean beingRepaired;
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setPrice(int price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public int getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setType(RepairType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public RepairType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setItem(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setToBeRepaired(ItemStack toBeRepaired) {
|
||||
this.toBeRepaired = toBeRepaired;
|
||||
}
|
||||
|
||||
public ItemStack getToBeRepaired() {
|
||||
return toBeRepaired;
|
||||
}
|
||||
|
||||
public void setLocations(Location locations) {
|
||||
this.locations = locations;
|
||||
}
|
||||
|
||||
public Location getLocations() {
|
||||
return locations;
|
||||
}
|
||||
|
||||
public boolean getInRepair() {
|
||||
return inRepair;
|
||||
}
|
||||
|
||||
public void setInRepair(boolean inRepair) {
|
||||
this.inRepair = inRepair;
|
||||
}
|
||||
|
||||
public boolean isBeingRepaired() {
|
||||
return beingRepaired;
|
||||
}
|
||||
|
||||
public void setBeingRepaired(boolean beingRepaired) {
|
||||
this.beingRepaired = beingRepaired;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.songoda.repairplus.events;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.repairplus.RepairPlus;
|
||||
import com.songoda.repairplus.utils.Debugger;
|
||||
import org.bukkit.Material;
|
||||
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/25/2017.
|
||||
*/
|
||||
public class BlockListeners implements Listener {
|
||||
|
||||
private final RepairPlus instance;
|
||||
|
||||
public BlockListeners(RepairPlus instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
try {
|
||||
if (!e.getPlayer().hasPermission("repairplus.permPlace") || !e.getBlockPlaced().getType().equals(Material.ANVIL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String loc = Arconix.pl().getApi().serialize().serializeLocation(e.getBlock());
|
||||
instance.getConfig().set("data.anvil." + loc + ".permPlaced", true);
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onBlockBreak(BlockBreakEvent e) {
|
||||
try {
|
||||
String loc = Arconix.pl().getApi().serialize().serializeLocation(e.getBlock());
|
||||
|
||||
if (!e.getBlock().getType().equals(Material.ANVIL) && !instance.getConfig().contains("data.anvil." + loc)) {
|
||||
return;
|
||||
}
|
||||
|
||||
instance.getConfig().set("data.anvil." + loc + ".holo", null);
|
||||
instance.holo.updateHolograms();
|
||||
instance.getConfig().set("data.anvil." + loc, null);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.songoda.repairplus.events;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.repairplus.RepairPlus;
|
||||
import com.songoda.repairplus.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
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.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/25/2017.
|
||||
*/
|
||||
|
||||
public class InteractListeners implements Listener {
|
||||
|
||||
private final RepairPlus instance;
|
||||
|
||||
public InteractListeners(RepairPlus instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAnvilClick(PlayerInteractEvent e) {
|
||||
try {
|
||||
boolean repair = false;
|
||||
boolean anvil = false;
|
||||
Player p = e.getPlayer();
|
||||
if (e.getClickedBlock() == null) {
|
||||
return;
|
||||
}
|
||||
String loc = Arconix.pl().getApi().serialize().serializeLocation(e.getClickedBlock());
|
||||
if (e.getClickedBlock().getType() != Material.ANVIL
|
||||
|| !((instance.getConfig().getBoolean("data.anvil." + loc + ".permPlaced")
|
||||
|| !instance.getConfig().getBoolean("settings.Perms-Only")))) {
|
||||
return;
|
||||
}
|
||||
if (instance.getConfig().getString("data.anvil." + loc + ".inf") != null) {
|
||||
byte data = e.getClickedBlock().getData();
|
||||
if ((data == 4) || (data == 8))
|
||||
data = 0;
|
||||
if ((data == 5) || (data == 9))
|
||||
data = 1;
|
||||
if ((data == 6) || (data == 10))
|
||||
data = 2;
|
||||
if ((data == 7) || (data == 11))
|
||||
data = 3;
|
||||
e.getClickedBlock().setType(Material.ANVIL);
|
||||
e.getClickedBlock().setData(data);
|
||||
}
|
||||
if (!instance.getConfig().getBoolean("settings.Enable-Default-Anvil-Function") && !p.isSneaking())
|
||||
e.setCancelled(true);
|
||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK &&
|
||||
!p.isSneaking()) {
|
||||
if (instance.getConfig().getBoolean("settings.Swap-Functions"))
|
||||
repair = true;
|
||||
else if (!instance.getConfig().getBoolean("settings.Enable-Default-Anvil-Function"))
|
||||
repair = true;
|
||||
}
|
||||
if (e.getAction() == Action.LEFT_CLICK_BLOCK &&
|
||||
!p.isSneaking()) {
|
||||
if (instance.getConfig().getBoolean("settings.Swap-Functions")) {
|
||||
if (instance.getConfig().getBoolean("settings.Enable-Default-Anvil-Function"))
|
||||
anvil = true;
|
||||
else
|
||||
repair = true;
|
||||
} else
|
||||
repair = true;
|
||||
}
|
||||
if (repair) {
|
||||
instance.repair.initRepair(p, e.getClickedBlock().getLocation());
|
||||
e.setCancelled(true);
|
||||
} else if (anvil && instance.getConfig().getBoolean("settings.Enable-Default-Anvil-Function")) {
|
||||
Inventory inv = Bukkit.createInventory(null, InventoryType.ANVIL, "Repair & Name");
|
||||
p.openInventory(inv);
|
||||
e.setCancelled(true);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.songoda.repairplus.events;
|
||||
|
||||
import com.songoda.repairplus.Lang;
|
||||
import com.songoda.repairplus.RepairPlus;
|
||||
import com.songoda.repairplus.anvil.PlayerAnvilData.RepairType;
|
||||
import com.songoda.repairplus.utils.Debugger;
|
||||
import org.bukkit.Location;
|
||||
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.inventory.InventoryPickupItemEvent;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/25/2017.
|
||||
*/
|
||||
public class InventoryListeners implements Listener {
|
||||
|
||||
private final RepairPlus instance;
|
||||
|
||||
public InventoryListeners(RepairPlus instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void OnPickup(InventoryPickupItemEvent event) {
|
||||
if (event.getItem().hasMetadata("RepairPlus"))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event) {
|
||||
try {
|
||||
Player p = (Player) event.getWhoClicked();
|
||||
if (instance.repair.getDataFor(p).getInRepair()) {
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getSlot() == 11) {
|
||||
instance.repair.finish(true, p);
|
||||
p.closeInventory();
|
||||
} else if (event.getSlot() == 15) {
|
||||
instance.repair.finish(false, p);
|
||||
p.closeInventory();
|
||||
}
|
||||
} else if (event.getInventory().getTitle().equals(Lang.GUI_TITLE.getConfigValue(null))) {
|
||||
event.setCancelled(true);
|
||||
Location loc = instance.repair.getDataFor(p).getLocation();
|
||||
if (event.getSlot() == 11) {
|
||||
p.closeInventory();
|
||||
if (p.hasPermission("repairplus.use.ECO"))
|
||||
instance.repair.preRepair(p, RepairType.ECONOMY, loc);
|
||||
} else if (event.getSlot() == 13) {
|
||||
p.closeInventory();
|
||||
if (p.hasPermission("repairplus.use.ITEM"))
|
||||
instance.repair.preRepair(p, RepairType.ITEM, loc);
|
||||
} else if (event.getSlot() == 15) {
|
||||
p.closeInventory();
|
||||
if (p.hasPermission("repairplus.use.XP"))
|
||||
instance.repair.preRepair(p, RepairType.XP, loc);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.songoda.repairplus.events;
|
||||
|
||||
import com.songoda.repairplus.RepairPlus;
|
||||
import com.songoda.repairplus.anvil.PlayerAnvilData;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerListeners implements Listener {
|
||||
|
||||
|
||||
private final RepairPlus instance;
|
||||
|
||||
public PlayerListeners(RepairPlus instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeave(PlayerQuitEvent event) {
|
||||
|
||||
if (!instance.repair.hasInstance(event.getPlayer()) || !instance.repair.getDataFor(event.getPlayer()).getInRepair()) return;
|
||||
|
||||
PlayerAnvilData playerData = instance.repair.getDataFor(event.getPlayer());
|
||||
instance.repair.removeItem(playerData, event.getPlayer());
|
||||
}
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
package com.songoda.repairplus.handlers;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.repairplus.RepairPlus;
|
||||
import com.songoda.repairplus.utils.Debugger;
|
||||
import org.bukkit.Material;
|
||||
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/25/2017.
|
||||
*/
|
||||
public class CommandHandler implements CommandExecutor {
|
||||
|
||||
private final RepairPlus instance;
|
||||
|
||||
public CommandHandler(RepairPlus instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
try {
|
||||
if (cmd.getName().equalsIgnoreCase("RPAnvil")) {
|
||||
Player player = (Player) sender;
|
||||
if (player.hasPermission("repairplus.rpanvil"))
|
||||
instance.repair.initRepair(player, player.getLocation());
|
||||
} else if (cmd.getName().equalsIgnoreCase("repairplus")) {
|
||||
if (args.length == 0 || args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
|
||||
sender.sendMessage("");
|
||||
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- " + "&aRP help &7Displays this page."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- " + "&aRP reload &7Reload the Configuration and Language files."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- " + "&aRP holo &7Toggle a hologram for the anvil you are looking at."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- " + "&aRP particles &7Toggle particles for the anvil you are looking at."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- " + "&aRP inf &7Toggle unbreaking for the anvil you are looking at."));
|
||||
sender.sendMessage("");
|
||||
} else if (args[0].equalsIgnoreCase("reload") &&
|
||||
sender.hasPermission("repairplus.admin")) {
|
||||
instance.reload();
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Configuration and Language files reloaded."));
|
||||
} else if (args[0].equalsIgnoreCase("holo")) {
|
||||
if (instance.v1_7) {
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7Holograms are not currently supported on 1.7... SORRY!"));
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if (player.hasPermission("repairplus.admin")) {
|
||||
Block block = player.getTargetBlock(null, 200);
|
||||
|
||||
if (block.getType() != Material.ANVIL) return true;
|
||||
|
||||
String loc = Arconix.pl().getApi().serialize().serializeLocation(block);
|
||||
if (instance.getConfig().getString("data.anvil." + loc + ".active") == null)
|
||||
instance.getConfig().set("data.anvil." + loc + ".active", true);
|
||||
|
||||
if (instance.getConfig().getString("data.anvil." + loc + ".holo") == null) {
|
||||
instance.getConfig().set("data.anvil." + loc + ".holo", true);
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&aHolograms &9enabled &afor this anvil."));
|
||||
} else {
|
||||
instance.getConfig().set("data.anvil." + loc + ".holo", null);
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&aHolograms &9disabled &afor this anvil."));
|
||||
}
|
||||
instance.holo.updateHolograms();
|
||||
instance.saveConfig();
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("particles")) {
|
||||
Player player = (Player) sender;
|
||||
if (player.hasPermission("repairplus.admin")) {
|
||||
Block block = player.getTargetBlock(null, 200);
|
||||
if (block.getType() == Material.ANVIL) {
|
||||
String loc = Arconix.pl().getApi().serialize().serializeLocation(block);
|
||||
if (instance.getConfig().getString("data.anvil." + loc + ".active") == null)
|
||||
instance.getConfig().set("data.anvil." + loc + ".active", true);
|
||||
if (instance.getConfig().getString("data.anvil." + loc + ".particles") == null) {
|
||||
instance.getConfig().set("data.anvil." + loc + ".particles", true);
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&aParticles &9enabled &afor this anvil."));
|
||||
} else {
|
||||
instance.getConfig().set("data.anvil." + loc + ".particles", null);
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&aParticles &9disabled &afor this anvil."));
|
||||
}
|
||||
instance.saveConfig();
|
||||
}
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("settings")) {
|
||||
if (sender.hasPermission("repairPlus.admin")) {
|
||||
Player player = (Player) sender;
|
||||
instance.settingsManager.openEditor(player);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("inf") || args[0].equalsIgnoreCase("infinity")) {
|
||||
Player player = (Player) sender;
|
||||
if (player.hasPermission("repairplus.admin") || player.hasPermission("repairplus.infinity")) {
|
||||
Block b = player.getTargetBlock(null, 200);
|
||||
if (b.getType() == Material.ANVIL) {
|
||||
String loc = Arconix.pl().getApi().serialize().serializeLocation(b);
|
||||
if (instance.getConfig().getString("data.anvil." + loc + ".active") == null)
|
||||
instance.getConfig().set("data.anvil." + loc + ".active", true);
|
||||
if (instance.getConfig().getString("data.anvil." + loc + ".inf") == null) {
|
||||
instance.getConfig().set("data.anvil." + loc + ".inf", true);
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&aInfinity &9enabled &afor this anvil."));
|
||||
} else {
|
||||
instance.getConfig().set("data.anvil." + loc + ".inf", null);
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&aInfinity &9disabled &afor this anvil."));
|
||||
}
|
||||
instance.saveConfig();
|
||||
}
|
||||
}
|
||||
} else
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Invalid argument.."));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package com.songoda.repairplus.handlers;
|
||||
|
||||
import com.songoda.arconix.api.packets.Hologram;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.repairplus.Lang;
|
||||
import com.songoda.repairplus.RepairPlus;
|
||||
import com.songoda.repairplus.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class HologramHandler {
|
||||
|
||||
private final RepairPlus instance;
|
||||
|
||||
public HologramHandler(RepairPlus plugin) {
|
||||
this.instance = plugin;
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::updateHolograms, 0L, 5000L);
|
||||
}
|
||||
|
||||
public void updateHolograms() {
|
||||
try {
|
||||
FileConfiguration config = instance.getConfig();
|
||||
|
||||
if (instance.v1_7 || config.getString("data.anvil") == null) return;
|
||||
|
||||
ConfigurationSection section = config.getConfigurationSection("data.anvil");
|
||||
for (String loc : section.getKeys(false)) {
|
||||
String str[] = loc.split(":");
|
||||
String worldName = str[1].substring(0, str[1].length() - 1);
|
||||
|
||||
if (Bukkit.getWorld(worldName) == null) continue;
|
||||
|
||||
Location location = Arconix.pl().getApi().serialize().unserializeLocation(loc);
|
||||
location.add(.5, 1.10, .5);
|
||||
|
||||
this.remove(location);
|
||||
if (!config.getBoolean("data.anvil." + loc + ".holo")) continue;
|
||||
|
||||
List<String> lines = new ArrayList<>();
|
||||
|
||||
if (!config.getBoolean("settings.Enable-Default-Anvil-Function"))
|
||||
lines.add(Arconix.pl().getApi().format().formatText(Lang.ONECLICK.getConfigValue()));
|
||||
else if (config.getBoolean("settings.Swap-Functions"))
|
||||
lines.add(Arconix.pl().getApi().format().formatText(Lang.SWAPCLICK.getConfigValue()));
|
||||
else
|
||||
lines.add(Arconix.pl().getApi().format().formatText(Lang.CLICK.getConfigValue()));
|
||||
|
||||
lines.add(Arconix.pl().getApi().format().formatText(Lang.TOREPAIR.getConfigValue()));
|
||||
Arconix.pl().getApi().packetLibrary.getHologramManager().spawnHolograms(location, lines);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Location location) {
|
||||
try {
|
||||
Location loco = location.clone();
|
||||
Hologram hologramManager = Arconix.pl().getApi().packetLibrary.getHologramManager();
|
||||
|
||||
hologramManager.despawnHologram(loco);
|
||||
hologramManager.despawnHologram(loco.subtract(0, .25, 0));
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.songoda.repairplus.handlers;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.repairplus.RepairPlus;
|
||||
import com.songoda.repairplus.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class ParticleHandler implements Listener {
|
||||
|
||||
private RepairPlus instance;
|
||||
|
||||
public ParticleHandler(RepairPlus instance) {
|
||||
this.instance = instance;
|
||||
checkDefaults();
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(instance, this::applyParticles, 0L, 10L);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public void applyParticles() {
|
||||
try {
|
||||
if (instance.getConfig().getString("data.anvil") == null) return;
|
||||
|
||||
int amt = instance.getConfig().getInt("data.particlesettings.ammount");
|
||||
String type = instance.getConfig().getString("data.particlesettings.type");
|
||||
if (type == null) {
|
||||
System.out.println("Critical error in your RepairPlus config. Please add a correct particle type or regenerate the config.");
|
||||
return;
|
||||
}
|
||||
ConfigurationSection section = instance.getConfig().getConfigurationSection("data.anvil");
|
||||
for (String loc : section.getKeys(false)) {
|
||||
String str[] = loc.split(":");
|
||||
String worldName = str[1].substring(0, str[1].length() - 1);
|
||||
if (Bukkit.getServer().getWorld(worldName) == null ||
|
||||
instance.getConfig().getString("data.anvil." + loc + ".particles") == null) {
|
||||
continue;
|
||||
}
|
||||
World w = Bukkit.getServer().getWorld(str[1].substring(0, str[1].length() - 1));
|
||||
Location location = Arconix.pl().getApi().serialize().unserializeLocation(loc);
|
||||
location.add(.5, 0, .5);
|
||||
if (instance.v1_8 || instance.v1_7)
|
||||
w.playEffect(location, org.bukkit.Effect.valueOf(type), 1, 0);
|
||||
//Again, can't get this to resolve
|
||||
//w.spigot().playEffect(location, org.bukkit.Effect.valueOf(type), 1, 0, (float) 0.25, (float) 0.25, (float) 0.25, 1, amt, 100);
|
||||
else
|
||||
w.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;
|
||||
}
|
||||
|
||||
instance.getConfig().set("data.particlesettings.type", (instance.v1_7 || instance.v1_8) ? "WITCH_MAGIC" : "SPELL_WITCH");
|
||||
|
||||
instance.saveConfig();
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
359
src/main/java/com/songoda/repairplus/handlers/RepairHandler.java
Normal file
359
src/main/java/com/songoda/repairplus/handlers/RepairHandler.java
Normal file
@ -0,0 +1,359 @@
|
||||
package com.songoda.repairplus.handlers;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.repairplus.Lang;
|
||||
import com.songoda.repairplus.RepairPlus;
|
||||
import com.songoda.repairplus.anvil.PlayerAnvilData;
|
||||
import com.songoda.repairplus.anvil.PlayerAnvilData.RepairType;
|
||||
import com.songoda.repairplus.utils.Debugger;
|
||||
import com.songoda.repairplus.utils.Methods;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/25/2017.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class RepairHandler {
|
||||
|
||||
private final Map<UUID, PlayerAnvilData> playerAnvilData = new HashMap<>();
|
||||
|
||||
public void repairType(Player p) {
|
||||
try {
|
||||
if (getDataFor(p).getInRepair()) {
|
||||
yesNo(p,getDataFor(p).getType(), getDataFor(p).getToBeRepaired());
|
||||
return;
|
||||
}
|
||||
Inventory i = Bukkit.createInventory(null, 27, Arconix.pl().getApi().format().formatTitle(Lang.GUI_TITLE.getConfigValue()));
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
i.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
|
||||
ItemStack item = new ItemStack(Material.valueOf(RepairPlus.getInstance().getConfig().getString("settings.ECO-Icon")), 1);
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(Lang.ECO_LORE.getConfigValue());
|
||||
itemmeta.setLore(lore);
|
||||
itemmeta.setDisplayName(Lang.ECO.getConfigValue());
|
||||
item.setItemMeta(itemmeta);
|
||||
|
||||
Material mat = Methods.getType(p.getItemInHand());
|
||||
|
||||
ItemStack item3 = new ItemStack(mat, 1);
|
||||
String name = (mat.name().substring(0, 1).toUpperCase() + mat.name().toLowerCase().substring(1)).replace("_", " ");
|
||||
ItemMeta itemmeta3 = item3.getItemMeta();
|
||||
ArrayList<String> lore3 = new ArrayList<>();
|
||||
lore3.add(Lang.ITEM_LORE.getConfigValue(name));
|
||||
itemmeta3.setLore(lore3);
|
||||
itemmeta3.setDisplayName(Lang.ITEM.getConfigValue(name));
|
||||
item3.setItemMeta(itemmeta3);
|
||||
|
||||
ItemStack item2 = new ItemStack(Material.valueOf(RepairPlus.getInstance().getConfig().getString("settings.XP-Icon")), 1);
|
||||
ItemMeta itemmeta2 = item2.getItemMeta();
|
||||
ArrayList<String> lore2 = new ArrayList<>();
|
||||
lore2.add(Lang.XP_LORE.getConfigValue(item3.toString()));
|
||||
itemmeta2.setLore(lore2);
|
||||
itemmeta2.setDisplayName(Lang.XP.getConfigValue());
|
||||
item2.setItemMeta(itemmeta2);
|
||||
|
||||
if (p.hasPermission("repairplus.use.ECO"))
|
||||
i.setItem(11, item);
|
||||
if (p.hasPermission("repairplus.use.ITEM"))
|
||||
i.setItem(13, item3);
|
||||
if (p.hasPermission("repairplus.use.XP"))
|
||||
i.setItem(15, item2);
|
||||
|
||||
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));
|
||||
|
||||
p.openInventory(i);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void preRepair(Player p, RepairType type, Location loc) {
|
||||
try {
|
||||
if (loc.add(0, 1, 0).getBlock().getTypeId() != 0) {
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(RepairPlus.getInstance().references.getPrefix() + Lang.NEED_SPACE.getConfigValue()));
|
||||
return;
|
||||
}
|
||||
if (p.getItemInHand().getDurability() <= 0) {
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(RepairPlus.getInstance().references.getPrefix() + Lang.NOT_DAMAGED.getConfigValue()));
|
||||
return;
|
||||
}
|
||||
if (p.getItemInHand().getMaxStackSize() != 1) {
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(RepairPlus.getInstance().references.getPrefix() + Lang.CANT_REPAIR.getConfigValue()));
|
||||
return;
|
||||
}
|
||||
|
||||
Item i = p.getWorld().dropItem(loc.add(0.5, 2, 0.5), p.getItemInHand());
|
||||
|
||||
// Support for EpicHoppers suction.
|
||||
i.setMetadata("grabbed", new FixedMetadataValue(RepairPlus.getInstance(), "true"));
|
||||
|
||||
i.setMetadata("betterdrops_ignore", new FixedMetadataValue(RepairPlus.getInstance(), true));
|
||||
Vector vec = p.getEyeLocation().getDirection();
|
||||
vec.setX(0);
|
||||
vec.setY(0);
|
||||
vec.setZ(0);
|
||||
i.setVelocity(vec);
|
||||
i.setPickupDelay(3600);
|
||||
i.setMetadata("RepairPlus", new FixedMetadataValue(RepairPlus.getInstance(), ""));
|
||||
|
||||
// Get from Map, put new instance in Map if it doesn't exist
|
||||
PlayerAnvilData playerData = playerAnvilData.computeIfAbsent(p.getUniqueId(), uuid -> new PlayerAnvilData());
|
||||
playerData.setItem(i);
|
||||
playerData.setToBeRepaired(p.getItemInHand());
|
||||
playerData.setLocations(loc.add(0, -2, 0));
|
||||
|
||||
yesNo(p, type, p.getItemInHand());
|
||||
|
||||
|
||||
p.setItemInHand(null);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(RepairPlus.getInstance(), () -> {
|
||||
if (i.isValid() && !playerData.isBeingRepaired()) {
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(RepairPlus.getInstance().references.getPrefix() + Lang.TIME_OUT.getConfigValue()));
|
||||
removeItem(playerData, p);
|
||||
p.closeInventory();
|
||||
|
||||
}
|
||||
}, RepairPlus.getInstance().getConfig().getLong("settings.Timeout"));
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void initRepair(Player p, Location location) {
|
||||
int num = 0;
|
||||
if (p.hasPermission("repairplus.use.ECO"))
|
||||
num++;
|
||||
if (p.hasPermission("repairplus.use.XP"))
|
||||
num++;
|
||||
if (p.hasPermission("repairplus.use.ITEM"))
|
||||
num++;
|
||||
|
||||
if (num >= 2 || p.hasPermission("repairplus.use.*")) {
|
||||
repairType(p);
|
||||
getDataFor(p).setLocation(location);
|
||||
} else if (p.hasPermission("repairplus.use.eco"))
|
||||
RepairPlus.getInstance().repair.preRepair(p, RepairType.ECONOMY, location);
|
||||
else if (p.hasPermission("repairplus.use.XP"))
|
||||
RepairPlus.getInstance().repair.preRepair(p, RepairType.XP, location);
|
||||
else if (p.hasPermission("repairplus.use.ITEM"))
|
||||
RepairPlus.getInstance().repair.preRepair(p, RepairType.ITEM, location);
|
||||
}
|
||||
|
||||
public void yesNo(Player p, RepairType type, ItemStack item) {
|
||||
try {
|
||||
PlayerAnvilData playerData = getDataFor(p);
|
||||
|
||||
if (playerData.isBeingRepaired()) {
|
||||
return;
|
||||
}
|
||||
|
||||
playerData.setInRepair(true);
|
||||
|
||||
int price = Methods.getCost(type, item);
|
||||
String cost = "0";
|
||||
|
||||
Material mat = new Methods().getType(item);
|
||||
String name = Arconix.pl().getApi().format().formatText(mat.name(), true);
|
||||
|
||||
if (type == RepairType.XP)
|
||||
cost = price + " XP";
|
||||
else if (type == RepairType.ECONOMY)
|
||||
cost = Lang.ECO_GUI.getConfigValue(Integer.toString(price));
|
||||
else if (type == RepairType.ITEM)
|
||||
cost = price + " " + name;
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 27, Arconix.pl().getApi().format().formatTitle(Lang.GUI_TITLE_YESNO.getConfigValue(cost)));
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
i.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
|
||||
ItemStack item2 = new ItemStack(Material.valueOf(RepairPlus.getInstance().getConfig().getString("settings.Buy-Icon")), 1);
|
||||
ItemMeta itemmeta2 = item2.getItemMeta();
|
||||
itemmeta2.setDisplayName(Lang.YES_GUI.getConfigValue());
|
||||
item2.setItemMeta(itemmeta2);
|
||||
|
||||
ItemStack item3 = new ItemStack(Material.valueOf(RepairPlus.getInstance().getConfig().getString("settings.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(RepairPlus.getInstance(), () -> p.openInventory(i), 1);
|
||||
|
||||
playerData.setType(type);
|
||||
playerData.setPrice(price);
|
||||
|
||||
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));
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void finish(boolean answer, Player p) {
|
||||
try {
|
||||
PlayerAnvilData playerData = playerAnvilData.computeIfAbsent(p.getUniqueId(), uuid -> new PlayerAnvilData());
|
||||
if (!answer) {
|
||||
removeItem(playerData, p);
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(RepairPlus.getInstance().references.getPrefix() + Lang.CANCELLED.getConfigValue()));
|
||||
return;
|
||||
}
|
||||
RepairType type = playerData.getType();
|
||||
ItemStack players = playerData.getToBeRepaired();
|
||||
|
||||
boolean economy = false;
|
||||
boolean sold = false;
|
||||
if (RepairPlus.getInstance().getServer().getPluginManager().getPlugin("Vault") != null && type == RepairType.ECONOMY) {
|
||||
RegisteredServiceProvider<Economy> rsp = RepairPlus.getInstance().getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
int price = playerData.getPrice();
|
||||
|
||||
if (econ.has(p, price)) {
|
||||
econ.withdrawPlayer(p, price);
|
||||
sold = true;
|
||||
}
|
||||
economy = true;
|
||||
}
|
||||
|
||||
int cost = Methods.getCost(type, players);
|
||||
ItemStack item2 = new ItemStack(Methods.getType(players), cost);
|
||||
String name = (item2.getType().name().substring(0, 1).toUpperCase() + item2.getType().name().toLowerCase().substring(1)).replace("_", " ");
|
||||
if (type == RepairType.ITEM && Arconix.pl().getApi().getGUI().inventoryContains(p.getInventory(), item2)) {
|
||||
Arconix.pl().getApi().getGUI().removeFromInventory(p.getInventory(), item2);
|
||||
sold = true;
|
||||
}
|
||||
|
||||
if (type == RepairType.XP && p.getLevel() >= playerData.getPrice() || sold || p.getGameMode() == GameMode.CREATIVE) {
|
||||
playerData.setBeingRepaired(true);
|
||||
|
||||
Location location = playerData.getLocations();
|
||||
p.getWorld().playEffect(location, Effect.STEP_SOUND, 152);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(RepairPlus.getInstance(), () -> p.getWorld().playEffect(location, Effect.STEP_SOUND, 152), 5L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(RepairPlus.getInstance(), () -> {
|
||||
p.getWorld().playEffect(location, Effect.STEP_SOUND, 152);
|
||||
p.getWorld().playEffect(location, Effect.STEP_SOUND, 1);
|
||||
if (RepairPlus.getInstance().v1_8)
|
||||
Arconix.pl().getApi().getPlayer(p).playSound(Sound.valueOf("ANVIL_LAND"));
|
||||
else
|
||||
Arconix.pl().getApi().getPlayer(p).playSound(Sound.valueOf("BLOCK_ANVIL_LAND"));
|
||||
}, 10L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(RepairPlus.getInstance(), () -> p.getWorld().playEffect(location, Effect.STEP_SOUND, 152), 15L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(RepairPlus.getInstance(), () -> p.getWorld().playEffect(location, Effect.STEP_SOUND, 152), 20L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(RepairPlus.getInstance(), () -> {
|
||||
if (RepairPlus.getInstance().v1_8 || RepairPlus.getInstance().v1_7)
|
||||
Arconix.pl().getApi().getPlayer(p).playSound(Sound.valueOf("ANVIL_LAND"));
|
||||
else
|
||||
Arconix.pl().getApi().getPlayer(p).playSound(Sound.valueOf("BLOCK_ANVIL_LAND"));
|
||||
p.getWorld().playEffect(location, Effect.STEP_SOUND, 152);
|
||||
p.getWorld().playEffect(location, Effect.STEP_SOUND, 145);
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(RepairPlus.getInstance().references.getPrefix() + Lang.SUCCESS.getConfigValue()));
|
||||
ItemStack repairedi = playerData.getToBeRepaired();
|
||||
repairedi.setDurability((short) 0);
|
||||
Item repaired = p.getWorld().dropItemNaturally(p.getLocation(), repairedi);
|
||||
repaired.remove();
|
||||
p.getInventory().addItem(playerData.getToBeRepaired());
|
||||
playerData.getItem().remove();
|
||||
if (p.getGameMode() != GameMode.CREATIVE &&
|
||||
type == RepairType.XP) {
|
||||
p.setLevel(p.getLevel() - playerData.getPrice());
|
||||
}
|
||||
this.playerAnvilData.remove(p.getUniqueId());
|
||||
p.closeInventory();
|
||||
}, 25L);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == RepairType.ECONOMY) {
|
||||
if (!economy)
|
||||
p.sendMessage("Vault is not installed.");
|
||||
else
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(RepairPlus.getInstance().references.getPrefix() + Lang.NOT_ENOUGH.getConfigValue(Lang.ECO.getConfigValue())));
|
||||
} else if (type == RepairType.XP)
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(RepairPlus.getInstance().references.getPrefix() + Lang.NOT_ENOUGH.getConfigValue(Lang.XP.getConfigValue())));
|
||||
else
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(RepairPlus.getInstance().references.getPrefix() + Lang.NOT_ENOUGH.getConfigValue(name)));
|
||||
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeItem(PlayerAnvilData playerData, Player p) {
|
||||
try {
|
||||
p.getInventory().addItem(playerData.getToBeRepaired());
|
||||
playerData.getItem().remove();
|
||||
|
||||
this.playerAnvilData.remove(p.getUniqueId());
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasInstance(Player player) {
|
||||
return playerAnvilData.containsKey(player);
|
||||
}
|
||||
|
||||
public PlayerAnvilData getDataFor(Player player) {
|
||||
return playerAnvilData.computeIfAbsent(player.getUniqueId(), uuid -> new PlayerAnvilData());
|
||||
}
|
||||
|
||||
}
|
30
src/main/java/com/songoda/repairplus/utils/Debugger.java
Normal file
30
src/main/java/com/songoda/repairplus/utils/Debugger.java
Normal file
@ -0,0 +1,30 @@
|
||||
package com.songoda.repairplus.utils;
|
||||
|
||||
import com.songoda.repairplus.RepairPlus;
|
||||
|
||||
/**
|
||||
* 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 RepairPlus.");
|
||||
System.out.println("--------------------------------------------------------------");
|
||||
e.printStackTrace();
|
||||
System.out.println("==============================================================");
|
||||
}
|
||||
sendReport(e);
|
||||
}
|
||||
|
||||
public static void sendReport(Exception e) {
|
||||
|
||||
}
|
||||
|
||||
public static boolean isDebug() {
|
||||
return RepairPlus.getInstance().getConfig().getBoolean("settings.Debug-Mode");
|
||||
}
|
||||
|
||||
}
|
102
src/main/java/com/songoda/repairplus/utils/Methods.java
Normal file
102
src/main/java/com/songoda/repairplus/utils/Methods.java
Normal file
@ -0,0 +1,102 @@
|
||||
package com.songoda.repairplus.utils;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.repairplus.RepairPlus;
|
||||
import com.songoda.repairplus.anvil.PlayerAnvilData.RepairType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/25/2017.
|
||||
*/
|
||||
public class Methods {
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
try {
|
||||
return Arconix.pl().getApi().getGUI().getGlass(RepairPlus.getInstance().getConfig().getBoolean("settings.Rainbow-Glass"), RepairPlus.getInstance().getConfig().getInt("settings.Glass-Type-1"));
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack getBackgroundGlass(boolean type) {
|
||||
try {
|
||||
if (type)
|
||||
return Arconix.pl().getApi().getGUI().getGlass(false, RepairPlus.getInstance().getConfig().getInt("settings.Glass-Type-2"));
|
||||
else
|
||||
return Arconix.pl().getApi().getGUI().getGlass(false, RepairPlus.getInstance().getConfig().getInt("settings.Glass-Type-3"));
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getCost(RepairType type, ItemStack item) {
|
||||
try {
|
||||
|
||||
ScriptEngineManager mgr = new ScriptEngineManager();
|
||||
ScriptEngine engine = mgr.getEngineByName("JavaScript");
|
||||
|
||||
String equationXP = RepairPlus.getInstance().getConfig().getString("settings.XP-Cost-Equation");
|
||||
String equationECO = RepairPlus.getInstance().getConfig().getString("settings.ECO-Cost-Equation");
|
||||
String equationITEM = RepairPlus.getInstance().getConfig().getString("settings.ITEM-Cost-Equation");
|
||||
|
||||
equationXP = equationXP.replace("{MaxDurability}", Short.toString(item.getType().getMaxDurability()))
|
||||
.replace("{Durability}", Short.toString(item.getDurability()));
|
||||
int XPCost = (int) Math.round(Double.parseDouble(engine.eval(equationXP).toString()));
|
||||
|
||||
equationECO = equationECO.replace("{MaxDurability}", Short.toString(item.getType().getMaxDurability()))
|
||||
.replace("{Durability}", Short.toString(item.getDurability()))
|
||||
.replace("{XPCost}", Integer.toString(XPCost));
|
||||
|
||||
int ECOCost = (int) Math.round(Double.parseDouble(engine.eval(equationECO).toString()));
|
||||
|
||||
equationITEM = equationITEM.replace("{MaxDurability}", Short.toString(item.getType().getMaxDurability()))
|
||||
.replace("{Durability}", Short.toString(item.getDurability()))
|
||||
.replace("{XPCost}", Integer.toString(XPCost));
|
||||
|
||||
int ITEMCost = (int) Math.round(Double.parseDouble(engine.eval(equationITEM).toString()));
|
||||
|
||||
if (item.hasItemMeta() &&
|
||||
item.getItemMeta().hasEnchants()) {
|
||||
int multi = RepairPlus.getInstance().getConfig().getInt("settings.Enchanted-Item-Multiplier");
|
||||
XPCost = XPCost * multi;
|
||||
ECOCost = ECOCost * multi;
|
||||
ITEMCost = ITEMCost * multi;
|
||||
}
|
||||
|
||||
if (type == RepairType.XP)
|
||||
return XPCost;
|
||||
else if (type == RepairType.ITEM)
|
||||
return ITEMCost;
|
||||
else if (type == RepairType.ECONOMY)
|
||||
return ECOCost;
|
||||
} catch (ScriptException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 9999999;
|
||||
}
|
||||
|
||||
public static Material getType(ItemStack item) {
|
||||
if (RepairPlus.getInstance().getConfig().getBoolean("settings.Item-Match-Type")) {
|
||||
if (item.getType().name().contains("DIAMOND"))
|
||||
return Material.DIAMOND;
|
||||
if (item.getType().name().contains("IRON"))
|
||||
return Material.IRON_INGOT;
|
||||
if (item.getType().name().contains("GOLD"))
|
||||
return Material.GOLD_INGOT;
|
||||
if (item.getType().name().contains("LEATHER"))
|
||||
return Material.LEATHER;
|
||||
if (item.getType().name().contains("STONE"))
|
||||
return Material.STONE;
|
||||
if (item.getType().name().contains("WOOD"))
|
||||
return Material.WOOD;
|
||||
}
|
||||
return Material.valueOf(RepairPlus.getInstance().getConfig().getString("settings.ITEM"));
|
||||
}
|
||||
}
|
294
src/main/java/com/songoda/repairplus/utils/SettingsManager.java
Normal file
294
src/main/java/com/songoda/repairplus/utils/SettingsManager.java
Normal file
@ -0,0 +1,294 @@
|
||||
package com.songoda.repairplus.utils;
|
||||
|
||||
import com.songoda.arconix.api.utils.ConfigWrapper;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.repairplus.Lang;
|
||||
import com.songoda.repairplus.RepairPlus;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
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 org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by songo on 6/4/2017.
|
||||
*/
|
||||
public class SettingsManager implements Listener {
|
||||
|
||||
private final RepairPlus instance;
|
||||
|
||||
public Map<Player, Integer> page = new HashMap<>();
|
||||
|
||||
private static ConfigWrapper defs;
|
||||
|
||||
public SettingsManager(RepairPlus instance) {
|
||||
this.instance = instance;
|
||||
instance.saveResource("SettingDefinitions.yml", true);
|
||||
defs = new ConfigWrapper(instance, "", "SettingDefinitions.yml");
|
||||
defs.createNewFile("Loading data file", "RepairPlus 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) {
|
||||
if (e.getInventory().getTitle().equals("RepairPlus Settings Editor")) {
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
if (e.getCurrentItem().getType().equals(Material.STAINED_GLASS_PANE)) {
|
||||
e.setCancelled(true);
|
||||
} else if (e.getCurrentItem().getItemMeta().getDisplayName().equals(Lang.NEXT.getConfigValue())) {
|
||||
page.put(p, 2);
|
||||
openEditor(p);
|
||||
} else if (e.getCurrentItem().getItemMeta().getDisplayName().equals(Lang.BACK.getConfigValue())) {
|
||||
page.put(p, 1);
|
||||
openEditor(p);
|
||||
} else if (e.getCurrentItem() != null) {
|
||||
e.setCancelled(true);
|
||||
|
||||
String key = e.getCurrentItem().getItemMeta().getDisplayName().substring(2);
|
||||
|
||||
if (instance.getConfig().get("settings." + key).getClass().getName().equals("java.lang.Boolean")) {
|
||||
boolean bool = (Boolean) instance.getConfig().get("settings." + key);
|
||||
if (!bool)
|
||||
instance.getConfig().set("settings." + key, true);
|
||||
else
|
||||
instance.getConfig().set("settings." + 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("settings." + current.get(p)).getClass().getName()) {
|
||||
case "java.lang.Integer":
|
||||
instance.getConfig().set("settings." + current.get(p), Integer.parseInt(e.getMessage()));
|
||||
break;
|
||||
case "java.lang.Double":
|
||||
instance.getConfig().set("settings." + current.get(p), Double.parseDouble(e.getMessage()));
|
||||
break;
|
||||
case "java.lang.String":
|
||||
instance.getConfig().set("settings." + 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, current);
|
||||
p.closeInventory();
|
||||
p.sendMessage("");
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&7Please enter a value for &6" + current + "&7."));
|
||||
if (instance.getConfig().get("settings." + current).getClass().getName().equals("java.lang.Integer"))
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&cUse only numbers."));
|
||||
p.sendMessage("");
|
||||
}
|
||||
|
||||
|
||||
public void openEditor(Player p) {
|
||||
int pmin = 1;
|
||||
|
||||
if (page.containsKey(p))
|
||||
pmin = page.get(p);
|
||||
|
||||
if (pmin != 1)
|
||||
pmin = 45;
|
||||
|
||||
int pmax = pmin * 44;
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 54, "RepairPlus Settings Editor");
|
||||
|
||||
int num = 0;
|
||||
int total = 0;
|
||||
ConfigurationSection cs = instance.getConfig().getConfigurationSection("settings");
|
||||
for (String key : cs.getKeys(true)) {
|
||||
if (!key.contains("levels") && total >= pmin - 1 && total <= pmax) {
|
||||
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("settings." + key).getClass().getName()) {
|
||||
case "java.lang.Boolean":
|
||||
|
||||
item.setType(Material.LEVER);
|
||||
boolean bool = (Boolean) instance.getConfig().get("settings." + key);
|
||||
|
||||
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("settings." + key);
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&9" + str));
|
||||
break;
|
||||
case "java.lang.Integer":
|
||||
item.setType(Material.WATCH);
|
||||
|
||||
int in = (Integer) instance.getConfig().get("settings." + key);
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&5" + in));
|
||||
break;
|
||||
}
|
||||
if (defs.getConfig().contains(key)) {
|
||||
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++;
|
||||
}
|
||||
total++;
|
||||
}
|
||||
|
||||
|
||||
int nu = 45;
|
||||
while (nu != 54) {
|
||||
i.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
|
||||
|
||||
ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
|
||||
ItemStack skull = head;
|
||||
if (!instance.v1_7)
|
||||
skull = Arconix.pl().getApi().getGUI().addTexture(head, "http://textures.minecraft.net/texture/1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
|
||||
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
|
||||
if (instance.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 (!instance.v1_7)
|
||||
skull2 = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta();
|
||||
if (instance.v1_7)
|
||||
skull2Meta.setOwner("MHF_ArrowLeft");
|
||||
skull2.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(Lang.BACK.getConfigValue());
|
||||
skull2.setItemMeta(skull2Meta);
|
||||
|
||||
if (pmin != 1)
|
||||
i.setItem(46, skull2);
|
||||
if (pmin == 1)
|
||||
i.setItem(52, skull);
|
||||
|
||||
p.openInventory(i);
|
||||
}
|
||||
|
||||
|
||||
public void updateSettings() {
|
||||
for (settings s : settings.values()) {
|
||||
if (s.setting.equals("Upgrade-particle-type")) {
|
||||
if (instance.v1_7 || instance.v1_8)
|
||||
instance.getConfig().addDefault("settings." + s.setting, "WITCH_MAGIC");
|
||||
else
|
||||
instance.getConfig().addDefault("settings." + s.setting, s.option);
|
||||
} else
|
||||
instance.getConfig().addDefault("settings." + s.setting, s.option);
|
||||
}
|
||||
|
||||
ConfigurationSection cs = instance.getConfig().getConfigurationSection("settings");
|
||||
for (String key : cs.getKeys(true)) {
|
||||
if (key.contains("levels") ||
|
||||
contains(key)) {
|
||||
continue;
|
||||
}
|
||||
instance.getConfig().set("settings." + key, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean contains(String test) {
|
||||
for (settings c : settings.values()) {
|
||||
if (c.setting.equals(test))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public enum settings {
|
||||
|
||||
o1("Timeout", 200L),
|
||||
|
||||
o2("XP-Cost-Equation", "{MaxDurability} - ({MaxDurability} - {Durability} / 40) + 1"),
|
||||
o3("ECO-Cost-Equation", "{XPCost} * 5"),
|
||||
o4("ITEM-Cost-Equation", "{XPCost} * 3"),
|
||||
o5("Enchanted-Item-Multiplier", 2),
|
||||
|
||||
o6("ECO-Icon", "DOUBLE_PLANT"),
|
||||
o7("XP-Icon", "EXP_BOTTLE"),
|
||||
o8("ITEM", "DIAMOND"),
|
||||
|
||||
o9("Exit-Icon", "WOOD_DOOR"),
|
||||
o10("Buy-Icon", "EMERALD"),
|
||||
o11("Buy-Icon", "EMERALD"),
|
||||
|
||||
o12("Glass-Type-1", 7),
|
||||
o13("Glass-Type-2", 11),
|
||||
o14("Glass-Type-3", 3),
|
||||
|
||||
o15("Rainbow-Glass", false),
|
||||
|
||||
o16("Item-Match-Type", true),
|
||||
|
||||
o17("Enable-Default-Anvil-Function", true),
|
||||
|
||||
o18("Swap-Functions", false),
|
||||
|
||||
o19("Perms-Only", false),
|
||||
o20("Debug-Mode", false);
|
||||
|
||||
private String setting;
|
||||
private Object option;
|
||||
|
||||
private settings(String setting, Object option) {
|
||||
this.setting = setting;
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
17
src/main/resources/plugin.yml
Normal file
17
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,17 @@
|
||||
name: RepairPlus
|
||||
description: RepairPlus
|
||||
main: com.songoda.repairplus.RepairPlus
|
||||
depend: [Arconix]
|
||||
softdepend: [Vault]
|
||||
version: 1.3.5
|
||||
author: Songoda
|
||||
commands:
|
||||
repairplus:
|
||||
description: View information on this plugin.
|
||||
default: true
|
||||
aliases: [rp]
|
||||
usage: /RP
|
||||
rpanvil:
|
||||
description: View information on this plugin.
|
||||
default: true
|
||||
usage: /rpanvil
|
BIN
src/plugin.yml
BIN
src/plugin.yml
Binary file not shown.
Loading…
Reference in New Issue
Block a user