Maven + UTF-8 + New Arconix

This commit is contained in:
NovaFox161 2018-05-07 10:27:48 -05:00
parent efcedc1d2e
commit 865bab0ecf
97 changed files with 9171 additions and 0 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@
out/
\.idea/
/EpicSpawners.iml
/src/main/resources/META-INF/MANIFEST.MF

224
pom.xml Normal file
View File

@ -0,0 +1,224 @@
<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>EpicSpawners</artifactId>
<version>4.2.5</version>
<packaging>jar</packaging>
<build>
<finalName>EpicSpawners</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</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>
<!--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>
<!--WorldGuard Repo-->
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
<!--Vault Repo-->
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<!--uSkyBlock Repo-->
<repository>
<id>uSkyBlock-mvn-repo</id>
<url>https://raw.github.com/rlf/uSkyBlock/mvn-repo/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<!--aAkyBlock Repo-->
<repository>
<id>bintray-tastybento-maven-repo</id>
<name>bintray</name>
<url>http://dl.bintray.com/tastybento/maven-repo</url>
</repository>
<!--PlaceHolderAPI Repo-->
<repository>
<id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</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>
<!--Spigot API-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</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>
<!--WorldGuard API-->
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>6.1.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--Vault API-->
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.6</version>
<scope>provided</scope>
</dependency>
<!--Towny API-->
<dependency>
<groupId>com.palmergames</groupId>
<artifactId>Towny</artifactId>
<version>0.92.0.0</version>
<scope>provided</scope>
</dependency>
<!--uSkyBlock API-->
<dependency>
<groupId>com.github.rlf</groupId>
<artifactId>uSkyBlock-API</artifactId>
<version>2.6.4</version>
<scope>provided</scope>
</dependency>
<!--RedProtect API-->
<dependency>
<groupId>br.net.fabiozumbi12</groupId>
<artifactId>RedProtect</artifactId>
<version>7.3.0</version>
<scope>provided</scope>
</dependency>
<!--PlotSquared API-->
<dependency>
<groupId>com.intellectualcrafters</groupId>
<artifactId>PlotSquared</artifactId>
<version>18.05.01</version>
<scope>provided</scope>
</dependency>
<!--Kingdoms API-->
<dependency>
<groupId>org.kingdoms</groupId>
<artifactId>Kingdoms</artifactId>
<version>13.3.40</version>
<scope>provided</scope>
</dependency>
<!--GriefPrevention API-->
<dependency>
<groupId>com.github.TechFortress</groupId>
<artifactId>GriefPrevention</artifactId>
<version>16.7.1</version>
<scope>provided</scope>
</dependency>
<!--FactionsFramework API-->
<dependency>
<groupId>me.markeh</groupId>
<artifactId>factionsframework</artifactId>
<version>1.2.0</version>
<scope>provided</scope>
</dependency>
<!--aSkyBlock API-->
<dependency>
<groupId>com.wasteofplastic</groupId>
<artifactId>askyblock</artifactId>
<version>3.0.8.2</version>
<scope>provided</scope>
</dependency>
<!--StackMob API-->
<dependency>
<groupId>uk.antiperson</groupId>
<artifactId>StackMob</artifactId>
<version>2.2.9-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--PlaceHolder API-->
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.8.4</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>
<!--https://mvnrepository.com/artifact/commons-lang/commons-lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</project>

View 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;
}
}

View File

@ -0,0 +1,340 @@
package com.songoda.epicspawners;
import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.api.EpicSpawnersAPI;
import com.songoda.epicspawners.handlers.*;
import com.songoda.epicspawners.listeners.*;
import com.songoda.epicspawners.spawners.Shop;
import com.songoda.epicspawners.spawners.SpawnerEditor;
import com.songoda.epicspawners.utils.Heads;
import com.songoda.epicspawners.utils.Methods;
import com.songoda.epicspawners.utils.SettingsManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.*;
/**
* Created by songoda on 2/25/2017.
*/
public class EpicSpawners extends JavaPlugin implements Listener {
public static CommandSender console = Bukkit.getConsoleSender();
private static EpicSpawners INSTANCE;
public Map<String, Integer> cache = new HashMap<>();
public BlacklistHandler blacklist;
public HookHandler hooks;
public Shop shop;
public SpawnerEditor editor;
public HologramHandler holo;
public Heads heads;
public SettingsManager sm;
public EpicSpawnersAPI api;
public List<Player> change = new ArrayList<>();
public List<Player> boosting = new ArrayList<>();
public Map<Player, Integer> boostAmt = new HashMap<>();
public Map<Player, Integer> infPage = new HashMap<>();
public HashMap<String, Long> tickTracker = new HashMap<>();
public HashMap<String, Long> tickTracker2 = new HashMap<>();
public boolean v1_12 = Bukkit.getServer().getClass().getPackage().getName().contains("1_12");
public boolean v1_11 = Bukkit.getServer().getClass().getPackage().getName().contains("1_11");
public boolean v1_7 = Bukkit.getServer().getClass().getPackage().getName().contains("1_7");
public boolean v1_8 = Bukkit.getServer().getClass().getPackage().getName().contains("1_8");
public boolean v1_9 = Bukkit.getServer().getClass().getPackage().getName().contains("1_9");
public boolean v1_10 = Bukkit.getServer().getClass().getPackage().getName().contains("1_10");
public boolean v1_8_R1 = Bukkit.getServer().getClass().getPackage().getName().contains("1_8_R1");
public List<ItemStack> itemEditorInstance = new ArrayList<>();
public List<String> entityEditorInstance = new ArrayList<>();
public List<String> commandEditorInstance = new ArrayList<>();
public List<String> blockEditorInstance = new ArrayList<>();
public String newSpawnerName = "";
public boolean isItemInstanceSaved = false;
public boolean isEntityInstanceSaved = false;
public boolean isCommandInstanceSaved = false;
public boolean isBlockInstanceSaved = false;
public Map<Player, Integer> editing = new HashMap<>();
public Map<Player, String> subediting = new HashMap<>();
public Map<Player, String> chatEditing = new HashMap<>();
public Map<Player, String> inShow = new HashMap<>();
public Map<Player, Integer> page = new HashMap<>();
public Map<Player, Boolean> pickup = new HashMap<>();
public Map<Player, Location> freePickup = new HashMap<>();
public Map<Location, Date> lastSpawn = new HashMap<>();
private Locale locale;
public ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml");
public ConfigWrapper spawnerFile = new ConfigWrapper(this, "", "spawners.yml");
public References references = null;
public Map<Player, Block> spawnerLoc = new HashMap<>();
public Map<Player, Block> lastSpawner = new HashMap<>();
public void onDisable() {
thinData();
dataFile.saveConfig();
spawnerFile.saveConfig();
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7EpicSpawners " + this.getDescription() + " by &5Brianna <3!"));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &cDisabling&7..."));
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
}
public void onEnable() {
INSTANCE = this;
Arconix.pl().hook(this);
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7EpicSpawners " + this.getDescription().getVersion() + " by &5Brianna <3&7!"));
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &aEnabling&7..."));
Bukkit.getServer().getPluginManager().registerEvents(this, this);
hooks = new HookHandler();
hooks.hook();
heads = new Heads();
api = new EpicSpawnersAPI();
sm = new SettingsManager();
setupConfig();
setupSpawners();
dataFile.createNewFile("Loading Data File", "EpicSpawners Data File");
loadDataFile();
// Locales
Locale.init(this);
Locale.saveDefaultLocale("en_US");
this.locale = Locale.getLocale(this.getConfig().getString("Locale", "en_US"));
thinData();
blacklist = new BlacklistHandler();
references = new References();
shop = new Shop(this);
editor = new SpawnerEditor(this);
holo = new HologramHandler();
new OmniHandler();
new BoostHandler();
new ItemHandler();
new com.massivestats.MassiveStats(this, 900);
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
thinData();
dataFile.saveConfig();
}, 50000L, 50000L);
this.getCommand("EpicSpawners").setExecutor(new CommandHandler(this));
this.getCommand("SpawnerStats").setExecutor(new CommandHandler(this));
this.getCommand("SpawnerShop").setExecutor(new CommandHandler(this));
getServer().getPluginManager().registerEvents(new BlockListeners(this), this);
getServer().getPluginManager().registerEvents(new ChatListeners(), this);
getServer().getPluginManager().registerEvents(new EntityListeners(), this);
getServer().getPluginManager().registerEvents(new InteractListeners(this), this);
getServer().getPluginManager().registerEvents(new InventoryListeners(this), this);
getServer().getPluginManager().registerEvents(new SpawnerListeners(), this);
if (!v1_7) {
getServer().getPluginManager().registerEvents(new com.songoda.epicspawners.listeners.TestListeners(), this);
}
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
}
private void setupConfig() {
sm.updateSettings();
getConfig().options().copyDefaults(true);
saveConfig();
}
private void setupSpawners() {
for (final EntityType value : EntityType.values()) {
if (value.isSpawnable() && value.isAlive() &&
!value.toString().toLowerCase().contains("armor") &&
!value.toString().toLowerCase().contains("giant"))
processDefault(value.name());
}
processDefault("Omni");
spawnerFile.getConfig().options().copyDefaults(true);
spawnerFile.saveConfig();
}
public void processDefault(String value) {
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".Display-Name"))
spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(value) + ".Display-Name", Methods.getTypeFromString(value));
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".Pickup-cost"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".Pickup-cost", 0);
String spawnBlock = "AIR";
if (value.equalsIgnoreCase("pig") || value.equalsIgnoreCase("sheep") || value.equalsIgnoreCase("chicken") ||
value.equalsIgnoreCase("cow") || value.equalsIgnoreCase("rabbit") || value.equalsIgnoreCase("llamma") ||
value.equalsIgnoreCase("horse") || value.equalsIgnoreCase("OCELOT")) {
spawnBlock = "GRASS";
}
if (value.equalsIgnoreCase("MUSHROOM_COW")) {
spawnBlock = "MYCEL";
}
if (value.equalsIgnoreCase("SQUID") || value.equalsIgnoreCase("ELDER_GUARDIAN")) {
spawnBlock = "WATER";
}
if (value.equalsIgnoreCase("OCELOT")) {
spawnBlock = ", LEAVES";
}
for (final EntityType val : EntityType.values()) {
if (val.isSpawnable() && val.isAlive()) {
if (val.name().equals(value)) {
List<String> list = new ArrayList<>();
list.add(value);
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".entities"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".entities", list);
}
}
}
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".Spawn-Block"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".Spawn-Block", spawnBlock);
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".Allowed"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".Allowed", true);
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".Spawn-On-Fire"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".Spawn-On-Fire", false);
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".Has-AI") && !EpicSpawners.getInstance().v1_7)
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".Has-AI", true);
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".Upgradable"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".Upgradable", true);
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".Convertible"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".Convertible", true);
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".Convert-Price"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".Convert-Price", "45%");
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".Limited"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".Limited", 0);
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".In-Shop"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".In-Shop", true);
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".Shop-Price"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".Shop-Price", 1000.00);
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".CustomGoal"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".CustomGoal", 0);
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".Custom-ECO-Cost"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".Custom-ECO-Cost", 0);
if (!spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(value) + ".Custom-XP-Cost"))
spawnerFile.getConfig().addDefault("Entities." + Methods.getTypeFromString(value) + ".Custom-XP-Cost", 0);
}
private void loadDataFile() {
dataFile.getConfig().options().copyDefaults(true);
dataFile.saveConfig();
}
public void reload() {
locale.reloadMessages();
spawnerFile.createNewFile("Loading Spawners File", "EpicSpawners Spawners File");
hooks.hooksFile.createNewFile("Loading Hooks File", "EpicSpawners Spawners File");
hooks = new HookHandler();
hooks.hook();
references = new References();
blacklist.reload();
reloadConfig();
saveConfig();
}
public void thinData() {
if (dataFile.getConfig().contains("data.entityshop")) {
ConfigurationSection cs = dataFile.getConfig().getConfigurationSection("data.entityshop");
for (String key : cs.getKeys(true)) {
if (isDead(UUID.fromString(key))) {
dataFile.getConfig().set("data.entityshop." + key, null);
}
}
}
if (getConfig().getBoolean("System.Remove Dead Entities from Data File")) {
if (dataFile.getConfig().contains("data.Entities")) {
ConfigurationSection cs = dataFile.getConfig().getConfigurationSection("data.Entities");
for (String key : cs.getKeys(true)) {
if (isDead(UUID.fromString(key))) {
dataFile.getConfig().set("data.Entities." + key, null);
}
}
}
} else {
dataFile.getConfig().set("data.Entities", null);
}
if (!getConfig().getBoolean("Spawner Drops.Allow Killing Mobs To Drop Spawners")) {
if (dataFile.getConfig().contains("data.kills")) {
dataFile.getConfig().set("data.kills", null);
}
}
}
public boolean isDead(UUID uniqueId) {
for (World world : Bukkit.getWorlds()) {
for (Entity entity : world.getEntities()) {
if (entity.getUniqueId().equals(uniqueId)) {
return false;
}
}
}
return true;
}
public Locale getLocale() {
return locale;
}
public EpicSpawnersAPI getApi() {
return api;
}
public static EpicSpawners pl() {
return INSTANCE;
}
public static EpicSpawners getInstance() {
return INSTANCE;
}
}

View File

@ -0,0 +1,365 @@
package com.songoda.epicspawners;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.apache.commons.io.IOUtils;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Assists in the creation of multiple localizations and languages,
* as well as the generation of default .lang files
*
* @author Parker Hawke - 2008Choco
*/
public class Locale {
private static JavaPlugin plugin;
private static final List<Locale> LOCALES = Lists.newArrayList();
private static final Pattern NODE_PATTERN = Pattern.compile("(\\w+(?:\\.{1}\\w+)*)\\s*=\\s*\"(.*)\"");
private static final String FILE_EXTENSION = ".lang";
private static File localeFolder;
private static String defaultLocale;
private final Map<String, String> nodes = new HashMap<>();
private final File file;
private final String name, region;
private Locale(String name, String region) {
if (plugin == null)
throw new IllegalStateException("Cannot generate locales without first initializing the class (Locale#init(JavaPlugin))");
this.name = name.toLowerCase();
this.region = region.toUpperCase();
String fileName = name + "_" + region + FILE_EXTENSION;
this.file = new File(localeFolder, fileName);
if (this.reloadMessages()) return;
plugin.getLogger().info("Loaded locale " + fileName);
}
/**
* Get the name of the language that this locale is based on.
* (i.e. "en" for English, or "fr" for French)
*
* @return the name of the language
*/
public String getName() {
return name;
}
/**
* Get the name of the region that this locale is from.
* (i.e. "US" for United States or "CA" for Canada)
*
* @return the name of the region
*/
public String getRegion() {
return region;
}
/**
* Return the entire locale tag (i.e. "en_US")
*
* @return the language tag
*/
public String getLanguageTag() {
return name + "_" + region;
}
/**
* Get the file that represents this locale
*
* @return the locale file (.lang)
*/
public File getFile() {
return file;
}
/**
* Get a message set for a specific node
*
* @param node the node to get
* @return the message for the specified node
*/
public String getMessage(String node) {
return ChatColor.translateAlternateColorCodes('&', this.getMessageOrDefault(node, node));
}
/**
* Get a message set for a specific node and replace its params with a supplied arguments.
*
* @param node the node to get
* @param args the replacement arguments
* @return the message for the specified node
*/
public String getMessage(String node, Object... args) {
String message = getMessage(node);
for (Object arg : args) {
message = message.replaceFirst("\\%.*?\\%", arg.toString());
}
return message;
}
/**
* Get a message set for a specific node
*
* @param node the node to get
* @param defaultValue the default value given that a value for the node was not found
*
* @return the message for the specified node. Default if none found
*/
public String getMessageOrDefault(String node, String defaultValue) {
return this.nodes.getOrDefault(node, defaultValue);
}
/**
* Get the key-value map of nodes to messages
*
* @return node-message map
*/
public Map<String, String> getMessageNodeMap() {
return ImmutableMap.copyOf(nodes);
}
/**
* Clear the previous message cache and load new messages directly from file
*
* @return reload messages from file
*/
public boolean reloadMessages() {
if (!this.file.exists()) {
plugin.getLogger().warning("Could not find file for locale " + this.name);
return false;
}
this.nodes.clear(); // Clear previous data (if any)
try(BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
for (int lineNumber = 0; (line = reader.readLine()) != null; lineNumber++) {
if (line.isEmpty() || line.startsWith("#") /* Comment */) continue;
Matcher matcher = NODE_PATTERN.matcher(line);
if (!matcher.find()) {
System.err.println("Invalid locale syntax at (line=" + lineNumber + ")");
continue;
}
nodes.put(matcher.group(1), matcher.group(2));
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
/**
* Initialize the locale class to generate information and search for localizations.
* This must be called before any other methods in the Locale class can be invoked.
* Note that this will also call {@link #searchForLocales()}, so there is no need to
* invoke it for yourself after the initialization
*
* @param plugin the plugin instance
*/
public static void init(JavaPlugin plugin) {
Locale.plugin = plugin;
if (localeFolder == null) {
localeFolder = new File(plugin.getDataFolder(), "locales/");
}
localeFolder.mkdirs();
Locale.searchForLocales();
}
/**
* Find all .lang file locales under the "locales" folder
*/
public static void searchForLocales() {
if (!localeFolder.exists()) localeFolder.mkdirs();
for (File file : localeFolder.listFiles()) {
String name = file.getName();
if (!name.endsWith(".lang")) continue;
String fileName = name.substring(0, name.lastIndexOf('.'));
String[] localeValues = fileName.split("_");
if (localeValues.length != 2) continue;
if (localeExists(localeValues[0] + "_" + localeValues[1])) continue;
LOCALES.add(new Locale(localeValues[0], localeValues[1]));
plugin.getLogger().info("Found and loaded locale \"" + fileName + "\"");
}
}
/**
* Get a locale by its entire proper name (i.e. "en_US")
*
* @param name the full name of the locale
* @return locale of the specified name
*/
public static Locale getLocale(String name) {
for (Locale locale : LOCALES)
if (locale.getLanguageTag().equalsIgnoreCase(name)) return locale;
return null;
}
/**
* Get a locale from the cache by its name (i.e. "en" from "en_US")
*
* @param name the name of the language
* @return locale of the specified language. Null if not cached
*/
public static Locale getLocaleByName(String name) {
for (Locale locale : LOCALES)
if (locale.getName().equalsIgnoreCase(name)) return locale;
return null;
}
/**
* Get a locale from the cache by its region (i.e. "US" from "en_US")
*
* @param region the name of the region
* @return locale of the specified region. Null if not cached
*/
public static Locale getLocaleByRegion(String region) {
for (Locale locale : LOCALES)
if (locale.getRegion().equalsIgnoreCase(region)) return locale;
return null;
}
/**
* Check whether a locale exists and is registered or not
*
* @param name the whole language tag (i.e. "en_US")
* @return true if it exists
*/
public static boolean localeExists(String name) {
for (Locale locale : LOCALES)
if (locale.getLanguageTag().equals(name)) return true;
return false;
}
/**
* Get an immutable list of all currently loaded locales
*
* @return list of all locales
*/
public static List<Locale> getLocales() {
return ImmutableList.copyOf(LOCALES);
}
/**
* Save a default locale file from the project source directory, to the locale folder
*
* @param path the path to the file to save
* @param fileName the name of the file to save
*
* @return true if the operation was successful, false otherwise
*/
public static boolean saveDefaultLocale(String path, String fileName) {
if (!localeFolder.exists()) localeFolder.mkdirs();
if (!fileName.endsWith(FILE_EXTENSION))
fileName = (fileName.lastIndexOf(".") == -1 ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + FILE_EXTENSION;
File destinationFile = new File(localeFolder, fileName);
if (destinationFile.exists()) {
return compareFiles(plugin.getResource(fileName), destinationFile);
}
try (OutputStream outputStream = new FileOutputStream(destinationFile)) {
IOUtils.copy(plugin.getResource(fileName), outputStream);
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
String[] localeValues = fileName.split("_");
if (localeValues.length != 2) return false;
LOCALES.add(new Locale(localeValues[0], localeValues[1]));
if (defaultLocale == null) defaultLocale = fileName;
return true;
} catch (IOException e) {
return false;
}
}
/**
* Save a default locale file from the project source directory, to the locale folder
*
* @param fileName the name of the file to save
* @return true if the operation was successful, false otherwise
*/
public static boolean saveDefaultLocale(String fileName) {
return saveDefaultLocale("", fileName);
}
/**
* Clear all current locale data
*/
public static void clearLocaleData() {
for (Locale locale : LOCALES)
locale.nodes.clear();
LOCALES.clear();
}
// Write new changes to existing files, if any at all
private static boolean compareFiles(InputStream defaultFile, File existingFile) {
// Look for default
if (defaultFile == null) {
defaultFile = plugin.getResource(defaultLocale != null ? defaultLocale : "en_US");
if (defaultFile == null) return false; // No default at all
}
boolean changed = false;
List<String> defaultLines, existingLines;
try (BufferedReader defaultReader = new BufferedReader(new InputStreamReader(defaultFile));
BufferedReader existingReader = new BufferedReader(new FileReader(existingFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(existingFile, true))) {
defaultLines = defaultReader.lines().collect(Collectors.toList());
existingLines = existingReader.lines().map(s -> s.split("\\s*=")[0]).collect(Collectors.toList());
for (String defaultValue : defaultLines) {
if (defaultValue.isEmpty() || defaultValue.startsWith("#")) continue;
String key = defaultValue.split("\\s*=")[0];
if (!existingLines.contains(key)) {
if (!changed) {
writer.newLine(); writer.newLine();
writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion());
}
writer.newLine();
writer.write(defaultValue);
changed = true;
}
}
} catch (IOException e) {
return false;
}
return changed;
}
}

View File

@ -0,0 +1,14 @@
package com.songoda.epicspawners;
public class References {
private String prefix;
public References() {
prefix = EpicSpawners.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
}
public String getPrefix() {
return this.prefix;
}
}

View File

@ -0,0 +1,428 @@
package com.songoda.epicspawners.api;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.spawners.Spawner;
import com.songoda.epicspawners.spawners.SpawnerItem;
import com.songoda.epicspawners.utils.Debugger;
import com.songoda.epicspawners.utils.Methods;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
/**
* Created by songoda on 3/17/2017.
*/
public class EpicSpawnersAPI {
public int getSpawnerMultiplier(Location location) {
int amt = 0;
try {
if (location.getBlock().getType() != Material.MOB_SPAWNER)
return 0;
else {
Spawner spawner = new Spawner(location);
amt = 1;
if (location.getBlock() != null)
amt = spawner.getMulti();
return amt;
}
} catch (Exception e) {
Debugger.runReport(e);
}
return amt;
}
public boolean setMultiplier(Location location, int multi) {
try {
EpicSpawners.getInstance().dataFile.getConfig().set("data.spawner." + Arconix.pl().getApi().serialize().serializeLocation(location), multi);
} catch (Exception e) {
Debugger.runReport(e);
return false;
}
return true;
}
public String getSpawnerType(Block b) {
return getSpawnerType(b.getLocation());
}
public String getSpawnerType(Location location) {
Spawner eSpawner = new Spawner(location);
return eSpawner.spawnedTypeU;
}
public ItemStack addOmniSpawner(SpawnerItem spawner, ItemStack item) {
try {
List<SpawnerItem> ents = getOmniList(item);
boolean hit = false;
boolean maxed = false;
for (SpawnerItem ent : ents) {
if (spawner.getType().equals(ent.getType())) {
if (ent.getMulti() == EpicSpawners.getInstance().getConfig().getInt("settings.Spawner-max")) {
maxed = true;
} else {
ent.setMulti(ent.getMulti() + spawner.getMulti());
}
hit = true;
}
}
if (hit || ents.size() < EpicSpawners.getInstance().getConfig().getInt("Main.Max Spawners Inside A OmniSpawner")) {
if (!hit) {
ents.add(spawner);
}
if (!maxed) {
return newOmniSpawner(ents);
} else {
return null;
}
} else {
return null;
}
} catch (Exception e) {
//Debugger.runReport(e);
}
return null;
}
public ItemStack newOmniSpawner(SpawnerItem spawner, SpawnerItem spawner2) {
try {
List<SpawnerItem> ents = new ArrayList<>();
ents.add(spawner2);
ents.add(spawner);
return newOmniSpawner(ents);
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public ItemStack newOmniSpawner(List<SpawnerItem> ents) {
try {
ItemStack item = new ItemStack(Material.MOB_SPAWNER, 1);
ItemMeta meta = item.getItemMeta();
ArrayList<String> lore = new ArrayList<>();
StringBuilder str = new StringBuilder();
String str2 = getOmniString(ents);
for (SpawnerItem spawner : ents) {
str.append(spawner.getType()).append("-").append(spawner.getMulti()).append(":");
}
meta.setDisplayName(Methods.compileName("OMNI", 1, true));
lore.add(Arconix.pl().getApi().format().formatText(Arconix.pl().getApi().format().convertToInvisibleString(str.toString()) + str2));
meta.setLore(lore);
item.setItemMeta(meta);
return item;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public String getOmniString(List<SpawnerItem> ents) {
try {
StringBuilder str2 = new StringBuilder("&7");
for (SpawnerItem spawner : ents) {
str2.append(Methods.properType(spawner.getType())).append(" ").append(spawner.getMulti()).append("x, ");
}
return str2.substring(0, str2.length() - 2);
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public void updateDisplayItem(String type, Location location) {
try {
Spawner eSpawner = new Spawner(location);
eSpawner.getSpawner().setSpawnedType(EntityType.DROPPED_ITEM);
eSpawner.update();
Location nloc = location.clone();
nloc.add(.5, -.4, .5);
List<Entity> near = (List<Entity>) nloc.getWorld().getNearbyEntities(nloc, 8, 8, 8);
for (Entity e : near) {
if (e.getLocation().getX() == nloc.getX() && e.getLocation().getY() == nloc.getY() && e.getLocation().getZ() == nloc.getZ()) {
e.remove();
}
}
try {
EntityType next = EntityType.valueOf(Methods.restoreType(type));
eSpawner.getSpawner().setSpawnedType(next);
eSpawner.update();
} catch (Exception ex) {
location.setPitch(-360);
ArmorStand as = (ArmorStand) location.getWorld().spawnEntity(nloc, EntityType.ARMOR_STAND);
as.setSmall(true);
as.setVisible(false);
as.setCustomNameVisible(false);
as.setGravity(false);
as.setCanPickupItems(false);
as.setBasePlate(true);
try {
if (EpicSpawners.getInstance().spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(type) + ".Display-Item")) {
as.setHelmet(new ItemStack(Material.valueOf(EpicSpawners.getInstance().spawnerFile.getConfig().getString("Entities." + Methods.getTypeFromString(type) + ".Display-Item"))));
} else {
as.setHelmet(new ItemStack(Material.DIRT));
}
} catch (Exception ee) {
as.setHelmet(new ItemStack(Material.DIRT));
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
public ItemStack newSpawnerItem(SpawnerItem item, int amount) {
return newSpawnerItem(item.getType(), item.getMulti(), amount);
}
public ItemStack newSpawnerItem(String type, int amount) {
try {
return newSpawnerItem(type, 0, amount);
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public ItemStack newSpawnerItem(EntityType type, int amount) {
try {
try {
return newSpawnerItem(type.name(), 0, amount);
} catch (Exception e) {
return newSpawnerItem("PIG", 0, amount);
}
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public ItemStack newSpawnerItem(String type, int multi, int amount) {
try {
if (multi == 0)
multi = 1;
ItemStack item = new ItemStack(Material.MOB_SPAWNER, amount);
ItemMeta itemmeta = item.getItemMeta();
String name = Methods.compileName(type, multi, true);
itemmeta.setDisplayName(name);
/* BlockStateMeta bsm = (BlockStateMeta) item.getItemMeta();
CreatureSpawner cs = (CreatureSpawner) bsm.getBlockState();
cs.setSpawnedType(type);
bsm.setBlockState(cs);
item.setItemMeta(bsm); */
item.setItemMeta(itemmeta);
return item;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public boolean isOmniBlock(Location location) {
if (location != null) {
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(location) + ".type")) {
return EpicSpawners.getInstance().dataFile.getConfig().getString("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(location) + ".type").equals("OMNI");
}
}
return false;
}
public void clearOmni(Location location) {
try {
EpicSpawners.getInstance().dataFile.getConfig().set("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(location) + ".entities", null);
EpicSpawners.getInstance().dataFile.getConfig().set("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(location) + ".type", null);
} catch (Exception e) {
Debugger.runReport(e);
}
}
public void saveCustomSpawner(ItemStack item, Block b) {
try {
if (getIType(item).equals("OMNI")) {
EpicSpawners.getInstance().dataFile.getConfig().set("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(b) + ".type", getIType(item));
List<SpawnerItem> entities = getOmniList(item);
List<String> ents = new ArrayList<>();
for (SpawnerItem spawner : entities)
ents.add(spawner.getType() + "-" + spawner.getMulti());
EpicSpawners.getInstance().dataFile.getConfig().set("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(b) + ".entities", ents);
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
public List<SpawnerItem> getOmniList(ItemStack item) {
List<SpawnerItem> entities = new ArrayList<>();
try {
String[] arr = (item.getItemMeta().getLore().get(0).replace("§", "")).split(":");
int num = 1;
for (String str : arr) {
if (arr.length != num) {
String[] arr2 = str.split("-");
entities.add(new SpawnerItem(arr2[0], Integer.parseInt(arr2[1])));
}
num++;
}
} catch (Exception e) {
Debugger.runReport(e);
}
return entities;
}
public int getIMulti(ItemStack item) {
try {
if (item.getItemMeta().getDisplayName().contains("§fSpaw§fner")) {
if (item.getItemMeta().getDisplayName().contains("§fSpaw§fner §c")) {
String arr[] = item.getItemMeta().getDisplayName().split("§fSpaw§fner §c");
return Integer.parseInt(arr[1]);
}
return 1;
} else {
String arr[] = (item.getItemMeta().getDisplayName().replace("§", "")).split(":");
return Integer.parseInt(arr[1]);
}
} catch (Exception e) {
return 1;
}
}
public String getType(ItemStack item) {
if (getIType(item) != null && !getIType(item).equals(""))
return Methods.restoreType(getIType(item));
else
return null;
}
public String getIType(ItemStack item) {
try {
if (item != null) {
try {
if (item.getItemMeta().getDisplayName().contains("§fSpaw§fner")) {
String[] arr = ChatColor.stripColor(item.getItemMeta().getDisplayName()).split(" Spawner");
String otype = arr[0];
return otype.replaceAll(" ", "_").toUpperCase();
} else if (item.getItemMeta().getDisplayName().contains(":")) {
String arr[] = (item.getItemMeta().getDisplayName().replace("§", "")).split(":");
return arr[0];
} else {
for (final EntityType value : EntityType.values()) {
if (value.isSpawnable() && value.isAlive()) {
String str = item.getItemMeta().getDisplayName().toLowerCase();
str = str.replace(" ", "_");
if (str.contains(value.name().toLowerCase())) {
return value.toString();
}
}
}
}
return "";
} catch (Exception e) {
BlockStateMeta bsm = (BlockStateMeta) item.getItemMeta();
CreatureSpawner bs = (CreatureSpawner) bsm.getBlockState();
return bs.getSpawnedType().toString();
}
} else {
return "";
}
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public List<SpawnerItem> convertFromList(List<String> list) {
try {
List<SpawnerItem> entities = new ArrayList<>();
for (String ent : list) {
String[] arr2 = ent.split("-");
entities.add(new SpawnerItem(arr2[0], Integer.parseInt(arr2[1])));
}
return entities;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public List<ItemStack> removeOmni(ItemStack item) {
try {
List<ItemStack> items = new ArrayList<>();
List<SpawnerItem> entities = getOmniList(item);
items.add(newSpawnerItem(entities.get(entities.size() - 1), 1));
entities.remove(entities.size() - 1);
if (entities.size() == 1) {
items.add(newSpawnerItem(entities.get(entities.size() - 1), 1));
} else {
items.add(newOmniSpawner(entities));
}
return items;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public List<ItemStack> removeSpawner(ItemStack item) {
try {
List<ItemStack> items = new ArrayList<>();
int multi = getIMulti(item);
if (multi > 1) {
items.add(newSpawnerItem(getIType(item), multi - 1, 1));
items.add(newSpawnerItem(getIType(item), 1, 1));
}
return items;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public int removeBoosts(String type, String value) {
int removes = 0;
try {
ConfigurationSection cs = EpicSpawners.getInstance().dataFile.getConfig().getConfigurationSection("data.boosts");
for (String key : cs.getKeys(false)) {
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.boosts." + key + "." + type)) {
if (EpicSpawners.getInstance().dataFile.getConfig().getString("data.boosts." + key + "." + type).equals(value)) {
EpicSpawners.getInstance().dataFile.getConfig().set("data.boosts." + key, null);
removes++;
}
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
return removes;
}
}

View File

@ -0,0 +1,105 @@
package com.songoda.epicspawners.entity;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.spawners.SpawnerDropEvent;
import com.songoda.epicspawners.spawners.SpawnerItem;
import com.songoda.epicspawners.utils.Debugger;
import com.songoda.epicspawners.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.List;
/**
* Created by songoda on 2/25/2017.
*/
public class EPlayer {
private Player p;
public EPlayer(Player p) {
this.p = p;
}
public void plus(Entity entity, int amt) {
try {
EpicSpawners instance = EpicSpawners.getInstance();
if (instance.getConfig().getInt("Spawner Drops.Kills Needed for Drop") != 0 && instance.getConfig().getBoolean("Spawner Drops.Allow Killing Mobs To Drop Spawners") && p.hasPermission("epicspawners.Killcounter")) {
String type = Methods.getType(entity.getType());
if (instance.spawnerFile.getConfig().getBoolean("Entities." + type + ".Allowed")) {
String uuid = p.getUniqueId().toString();
int total = 0;
if (instance.dataFile.getConfig().getInt("data.kills." + uuid + "." + type) != 0)
total = instance.dataFile.getConfig().getInt("data.kills." + uuid + "." + type);
int goal = instance.getConfig().getInt("Spawner Drops.Kills Needed for Drop");
if (instance.spawnerFile.getConfig().getInt("Entities." + type + ".CustomGoal") != 0) {
goal = instance.spawnerFile.getConfig().getInt("Entities." + type + ".CustomGoal");
}
if (total > goal)
total = 1;
total = amt + total;
if (instance.getConfig().getInt("Spawner Drops.Alert Every X Before Drop") != 0) {
if (total % instance.getConfig().getInt("Spawner Drops.Alert Every X Before Drop") == 0 && total != goal) {
Arconix.pl().getApi().packetLibrary.getActionBarManager().sendActionBar(p, instance.getLocale().getMessage("event.goal.alert", goal - total, type));
}
}
if (total % goal == 0) {
dropSpawner(entity.getLocation(), 0, entity.getType().name());
instance.dataFile.getConfig().set("data.kills." + uuid + "." + type, 0);
Arconix.pl().getApi().packetLibrary.getActionBarManager().sendActionBar(p, instance.getLocale().getMessage("event.goal.reached", type));
} else
instance.dataFile.getConfig().set("data.kills." + uuid + "." + type, total);
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
public void dropSpawner(Location location, int multi, String type) {
try {
SpawnerDropEvent event = new SpawnerDropEvent(location, p);
Bukkit.getPluginManager().callEvent(event);
ItemStack item;
if (!event.isCancelled()) {
if (!type.toUpperCase().equals("OMNI")) {
item = EpicSpawners.getInstance().getApi().newSpawnerItem(Methods.restoreType(type), multi, 1);
} else {
if (!p.isSneaking() || p.isSneaking() && !EpicSpawners.getInstance().getConfig().getBoolean("Main.Sneak To Recive A Stacked Spawner")) {
List<SpawnerItem> spawners = EpicSpawners.getInstance().getApi().convertFromList(EpicSpawners.getInstance().dataFile.getConfig().getStringList("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(location) + ".entities"));
List<ItemStack> items = EpicSpawners.getInstance().getApi().removeOmni(EpicSpawners.getInstance().getApi().newOmniSpawner(spawners));
item = items.get(0);
if (EpicSpawners.getInstance().getApi().getType(items.get(1)).equals("OMNI"))
EpicSpawners.getInstance().getApi().saveCustomSpawner(items.get(1), location.getBlock());
} else {
List<SpawnerItem> spawners = EpicSpawners.getInstance().getApi().convertFromList(EpicSpawners.getInstance().dataFile.getConfig().getStringList("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(location) + ".entities"));
item = EpicSpawners.getInstance().getApi().newOmniSpawner(spawners);
}
}
if (EpicSpawners.getInstance().getConfig().getBoolean("Main.Add Spawner To Inventory On Drop") && p != null) {
if (p.getInventory().firstEmpty() == -1)
location.getWorld().dropItemNaturally(location, item);
else
p.getInventory().addItem(item);
} else
location.getWorld().dropItemNaturally(location, item);
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
public Player getP() {
return p;
}
}

View File

@ -0,0 +1,68 @@
package com.songoda.epicspawners.handlers;
import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
/**
* Created by songoda on 2/25/2017.
*/
public class BlacklistHandler {
private ConfigWrapper blackFile = new ConfigWrapper(EpicSpawners.getInstance(), "", "main/resources/blacklist.yml");
public BlacklistHandler() {
try {
blackFile.createNewFile("Loading language file", "EpicSpawners blacklist file");
loadBlacklistFile();
} catch (Exception e) {
Debugger.runReport(e);
}
}
public boolean isBlacklisted(Player p, boolean yell) {
try {
List<String> list = blackFile.getConfig().getStringList("settings.blacklist");
String cworld = p.getWorld().getName();
for (String world : list) {
if (cworld.equalsIgnoreCase(world)) {
if (yell)
p.sendMessage(EpicSpawners.getInstance().getLocale().getMessage("event.block.blacklisted"));
return true;
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
private void loadBlacklistFile() {
try {
List<String> list = new ArrayList<>();
list.add("world2");
list.add("world3");
list.add("world4");
list.add("world5");
blackFile.getConfig().addDefault("settings.blacklist", list);
blackFile.getConfig().options().copyDefaults(true);
blackFile.saveConfig();
} catch (Exception e) {
Debugger.runReport(e);
}
}
public void reload() {
try {
blackFile.createNewFile("Loading blacklist file", "EpicSpawnesrs.java blacklist file");
loadBlacklistFile();
} catch (Exception e) {
Debugger.runReport(e);
}
}
}

View File

@ -0,0 +1,65 @@
package com.songoda.epicspawners.handlers;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
/**
* Created by songo on 9/3/2017.
*/
public class BoostHandler {
public BoostHandler() {
try {
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(EpicSpawners.getInstance(), BoostHandler::animate, 2L, 9L);
} catch (Exception e) {
Debugger.runReport(e);
}
}
public static void animate() {
try {
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.boosts")) {
ConfigurationSection cs = EpicSpawners.getInstance().dataFile.getConfig().getConfigurationSection("data.boosts");
for (String key : cs.getKeys(false)) {
Location location = null;
boolean yes = false;
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.boosts." + key + ".location")) {
location = Arconix.pl().getApi().serialize().unserializeLocation(EpicSpawners.getInstance().dataFile.getConfig().getString("data.boosts." + key + ".location"));
yes = true;
if (location.getBlock().getType() != Material.MOB_SPAWNER) {
yes = false;
EpicSpawners.getInstance().dataFile.getConfig().set("data.boosts." + key, null);
}
} else if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.boosts." + key + ".player")) {
String uuid = EpicSpawners.getInstance().dataFile.getConfig().getString("data.boosts." + key + ".player");
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawnerstats")) {
ConfigurationSection cs2 = EpicSpawners.getInstance().dataFile.getConfig().getConfigurationSection("data.spawnerstats");
for (String key2 : cs2.getKeys(false)) {
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawnerstats." + key2 + ".player")) {
if (EpicSpawners.getInstance().dataFile.getConfig().getString("data.spawnerstats." + key2 + ".player").equals(uuid)) {
location = Arconix.pl().getApi().serialize().unserializeLocation(key2);
yes = true;
}
}
}
}
}
if (yes) {
location.add(.5, .5, .5);
float x = (float) (0 + (Math.random() * .75));
float y = (float) (0 + (Math.random() * 1));
float z = (float) (0 + (Math.random() * .75));
Arconix.pl().getApi().packetLibrary.getParticleManager().broadcastParticle(location, x, y, z, 0, "SPELL", 2);
}
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
}

View File

@ -0,0 +1,541 @@
package com.songoda.epicspawners.handlers;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.spawners.Spawner;
import com.songoda.epicspawners.utils.Debugger;
import com.songoda.epicspawners.utils.Methods;
import org.bukkit.Bukkit;
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.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
/**
* Created by songoda on 2/24/2017.
*/
public class CommandHandler implements CommandExecutor {
private EpicSpawners instance;
public CommandHandler(EpicSpawners instance) {
this.instance = instance;
}
public void help(CommandSender sender, int page) {
try {
sender.sendMessage("");
int of = 3;
if (!sender.hasPermission("epicspawners.admin")) {
of = 1;
}
sender.sendMessage(Arconix.pl().getApi().format().formatText("&7Page: &a" + page + " of " + of + " ======================"));
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- &aes help &7Displays this page."));
if (page == 2 && sender.hasPermission("epicspawners.admin")) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aes editor &7Opens the spawner editor."));
}
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aspawnershop &7Opens the spawner shop."));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aspawnerstats &7Allows a player to overView their current EpicSpawners stats and see how many kills they have left to get a specific spawner drop."));
} else if (page == 2 && sender.hasPermission("epicspawners.admin")) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aes change <type> &7Changes the entity for the spawner you are looking at."));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aes give [player/all] [spawnertype/random] [multiplier] [amount] &7Gives an operator the ability to spawn a spawner of his or her choice."));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aes setshop <type> &7Assigns a spawner shop to the block you are looking at."));
} else if (page == 3 && sender.hasPermission("epicspawners.admin")) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aes settings &7Edit the EpicSpawners Settings."));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aes boost <p:player, f:faction, t:town, i:islandOwner> <amount> [m:minute, h:hour, d:day, y:year] &7This allows you to boost the amount of spawns that are got from placed spawners."));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aes removeboosts <p:player, f:faction, t:town, i:islandOwner> &7This allows you to remove boosts."));
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aes removeshop &7Unassigns a spawner shop to the block you are looking at."));
} else {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "That page does not exist!"));
}
sender.sendMessage("");
} catch (Exception e) {
Debugger.runReport(e);
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
try {
if (cmd.getName().equalsIgnoreCase("EpicSpawners")) {
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);
}
} else if (args[0].equalsIgnoreCase("reload")) {
if (!sender.hasPermission("epicspawners.admin")) {
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
} else {
instance.reload();
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Configuration and Language files reloaded."));
}
} else if (args[0].equalsIgnoreCase("change")) {
if (!sender.hasPermission("epicspawners.admin") && !sender.hasPermission("epicspawners.change.*") && !sender.hasPermission("epicspawners.change." + args[1].toUpperCase())) {
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
} else {
Player p = (Player) sender;
Block b = p.getTargetBlock(null, 200);
if (b.getType().equals(Material.MOB_SPAWNER)) {
Spawner eSpawner = new Spawner(b);
try {
eSpawner.getSpawner().setSpawnedType(EntityType.valueOf(args[1].toUpperCase()));
eSpawner.update();
instance.holo.processChange(b);
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7Successfully changed this spawner to &6" + args[1] + "&7."));
} catch (Exception ee) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7That Entity does not exist."));
}
} else {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&cThis is not a spawner."));
}
}
} else if (args[0].equalsIgnoreCase("editor")) {
if (!sender.hasPermission("epicspawners.admin")) {
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
} else {
instance.editor.open((Player) sender, 1);
}
} else if (args[0].equalsIgnoreCase("removeboosts")) {
if (!sender.hasPermission("epicspawners.admin")) {
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
} else {
if (args.length == 2) {
if (instance.dataFile.getConfig().contains("data.boosts")) {
if (args[1].contains("p:") || args[1].contains("player:") ||
args[1].contains("f:") || args[1].contains("faction:") ||
args[1].contains("t:") || args[1].contains("town:") ||
args[1].contains("i:") || args[1].contains("island:")) {
String[] arr = (args[1]).split(":");
String type = "";
String att = "";
if (arr[0].equalsIgnoreCase("p") || arr[0].equalsIgnoreCase("player")) {
if (Bukkit.getOfflinePlayer(arr[1]) == null) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&cThat player does not exist..."));
} else {
type = "player";
att = Bukkit.getOfflinePlayer(arr[1]).getUniqueId().toString();
}
} else if (arr[0].equalsIgnoreCase("f") || arr[0].equalsIgnoreCase("faction")) {
if (instance.hooks.getFactionId(arr[1]) == null) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&cThat faction does not exist..."));
return true;
} else {
type = "faction";
att = instance.hooks.getFactionId(arr[1]);
}
} else if (arr[0].equalsIgnoreCase("t") || arr[0].equalsIgnoreCase("town")) {
if (instance.hooks.getFactionId(arr[1]) == null) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&cThat town does not exist..."));
return true;
} else {
type = "town";
att = instance.hooks.getTownId(arr[1]);
}
} else if (arr[0].equalsIgnoreCase("i") || arr[0].equalsIgnoreCase("island")) {
if (instance.hooks.getFactionId(arr[1]) == null) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&cThat island does not exist..."));
return true;
} else {
type = "island";
att = instance.hooks.getIslandId(arr[1]);
}
}
int removes = instance.getApi().removeBoosts(type, att);
if (removes == 0) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&cNo boosts were found matching your search."));
} else {
if (removes == 1)
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&6" + removes + " &7boost was removed."));
else
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&6" + removes + " &7boosts were removed."));
}
} else {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&6" + args[1] + " &7this is incorrect"));
}
} else {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&cThe boost database is currently empty."));
}
} else {
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&7Syntax error..."));
}
}
} else if (args[0].equalsIgnoreCase("boost")) {
if (!sender.hasPermission("epicspawners.admin")) {
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
} else {
if (args.length >= 3) {
if (args[1].contains("p:") || args[1].contains("player:") ||
args[1].contains("f:") || args[1].contains("faction:") ||
args[1].contains("t:") || args[1].contains("town:") ||
args[1].contains("i:") || args[1].contains("island:")) {
String[] arr = (args[1]).split(":");
if (!Arconix.pl().getApi().doMath().isNumeric(args[2])) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&6" + args[2] + " &7is not a number..."));
} else {
Calendar c = Calendar.getInstance();
Date currentDate = new Date();
c.setTime(currentDate);
String response = " &6" + arr[1] + "&7 has been given a spawner boost of &6" + args[2];
if (args.length > 3) {
if (args[3].contains("m:")) {
String[] arr2 = (args[3]).split(":");
c.add(Calendar.MINUTE, Integer.parseInt(arr2[1]));
response += " &7for &6" + arr2[1] + " minutes&7.";
} else if (args[3].contains("h:")) {
String[] arr2 = (args[3]).split(":");
c.add(Calendar.HOUR, Integer.parseInt(arr2[1]));
response += " &7for &6" + arr2[1] + " hours&7.";
} else if (args[3].contains("d:")) {
String[] arr2 = (args[3]).split(":");
c.add(Calendar.HOUR, Integer.parseInt(arr2[1]) * 24);
response += " &7for &6" + arr2[1] + " days&7.";
} else if (args[3].contains("y:")) {
String[] arr2 = (args[3]).split(":");
c.add(Calendar.YEAR, Integer.parseInt(arr2[1]));
response += " &7for &6" + arr2[1] + " years&7.";
} else {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7" + args[3] + " &7is invalid."));
return true;
}
} else {
c.add(Calendar.YEAR, 10);
response += "&6.";
}
String uuid = UUID.randomUUID().toString();
String start = "&7";
if (arr[0].equalsIgnoreCase("p") || arr[0].equalsIgnoreCase("player")) {
if (Bukkit.getOfflinePlayer(arr[1]) == null) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&cThat player does not exist..."));
} else {
start += "The player";
instance.dataFile.getConfig().set("data.boosts." + uuid + ".player", Bukkit.getOfflinePlayer(arr[1]).getUniqueId().toString());
}
} else if (arr[0].equalsIgnoreCase("f") || arr[0].equalsIgnoreCase("faction")) {
if (instance.hooks.getFactionId(arr[1]) == null) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&cThat faction does not exist..."));
return true;
} else {
start += "The faction";
instance.dataFile.getConfig().set("data.boosts." + uuid + ".faction", instance.hooks.getFactionId(arr[1]));
}
} else if (arr[0].equalsIgnoreCase("t") || arr[0].equalsIgnoreCase("town")) {
if (instance.hooks.getTownId(arr[1]) == null) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&cThat town does not exist..."));
return true;
} else {
start += "The town";
instance.dataFile.getConfig().set("data.boosts." + uuid + ".town", instance.hooks.getTownId(arr[1]));
}
} else if (arr[0].equalsIgnoreCase("i") || arr[0].equalsIgnoreCase("island")) {
if (instance.hooks.getIslandId(arr[1]) == null) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&cThat island does not exist..."));
return true;
} else {
start += "The island";
instance.dataFile.getConfig().set("data.boosts." + uuid + ".island", instance.hooks.getIslandId(arr[1]));
}
}
instance.dataFile.getConfig().set("data.boosts." + uuid + ".boosted", Integer.parseInt(args[2]));
instance.dataFile.getConfig().set("data.boosts." + uuid + ".end", c.getTime().getTime());
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + start + response));
}
} else {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&6" + args[1] + " &7this is incorrect"));
}
} else {
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&7Syntax error..."));
}
}
} else if (args[0].equalsIgnoreCase("settings")) {
if (!sender.hasPermission("epicspawners.admin")) {
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
} else {
Player p = (Player) sender;
instance.sm.openSettingsManager(p);
}
} else if (args[0].equalsIgnoreCase("setshop")) {
if (args.length >= 2) {
Player p = (Player) sender;
if (!sender.hasPermission("epicspawners.admin")) {
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
} else {
String type = null;
ConfigurationSection css = instance.spawnerFile.getConfig().getConfigurationSection("Entities");
for (String key : css.getKeys(false)) {
String input = args[1].toUpperCase().replace("_", "").replace(" ", "");
String compare = key.toUpperCase().replace("_", "").replace(" ", "");
if (input.equals(compare))
type = key;
}
if (type == null) {
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7The entity type &6" + args[1] + " &7does not exist. Try one of these:"));
StringBuilder list = new StringBuilder();
for (final EntityType value : EntityType.values()) {
if (value.isSpawnable() && value.isAlive()) {
list.append(value.toString()).append("&7, &6");
}
}
sender.sendMessage(Arconix.pl().getApi().format().formatText("&6" + list));
} else {
Entity ent = null;
if (Arconix.pl().getApi().getPlayer(p).getTarget() != null) {
if (ent instanceof ItemFrame) {
ent = Arconix.pl().getApi().getPlayer(p).getTarget();
}
}
if (ent != null) {
instance.dataFile.getConfig().set("data.entityshop." + ent.getUniqueId().toString(), type);
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&aShop setup successfully."));
} else {
if (p.getTargetBlock(null, 200) != null) {
Block b = p.getTargetBlock(null, 200);
String loc = Arconix.pl().getApi().serialize().serializeLocation(b);
instance.dataFile.getConfig().set("data.blockshop." + loc, args[1]);
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&aShop setup successfully."));
}
}
}
}
}
} else if (args[0].equalsIgnoreCase("removeshop")) {
if (!sender.hasPermission("epicspawners.admin")) {
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
} else {
Player p = (Player) sender;
Entity ent = null;
if (Arconix.pl().getApi().getPlayer(p).getTarget() != null &&
ent.getType() == EntityType.ITEM_FRAME) {
ent = Arconix.pl().getApi().getPlayer(p).getTarget();
}
if (ent != null) {
instance.dataFile.getConfig().set("data.entityshop." + ent.getUniqueId().toString(), null);
return true;
}
Block b = p.getTargetBlock(null, 200);
String loc = Arconix.pl().getApi().serialize().serializeLocation(b);
instance.dataFile.getConfig().set("data.blockshop." + loc, null);
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&aShop removed successfully."));
}
} else if (args[0].equalsIgnoreCase("shop")) {
if (!sender.hasPermission("epicspawners.openshop")) {
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
return true;
}
Player p = (Player) sender;
instance.shop.open(p, 1);
} else if (args[0].equalsIgnoreCase("give")) {
if (args.length <= 3) {
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&7Syntax error..."));
return true;
}
if (!sender.hasPermission("epicspawners.admin")) {
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
return true;
}
if (Bukkit.getPlayerExact(args[1]) == null && !args[1].toLowerCase().equals("all")) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&cThat username does not exist, or the user is not online!"));
return true;
}
int multi = 0;
String type = null;
ConfigurationSection css = instance.spawnerFile.getConfig().getConfigurationSection("Entities");
for (String key : css.getKeys(false)) {
String input = args[2].toUpperCase().replace("_", "").replace(" ", "");
String compare = key.toUpperCase().replace("_", "").replace(" ", "");
if (input.equals(compare))
type = key;
}
if (type == null && !args[2].equalsIgnoreCase("random")) {
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7The entity type &6" + args[2] + " &7does not exist. Try one of these:"));
StringBuilder list = new StringBuilder();
ConfigurationSection cs = instance.spawnerFile.getConfig().getConfigurationSection("Entities");
for (String key : cs.getKeys(false)) {
key = key.toUpperCase().replace(" ", "_");
list.append(key).append("&7, &6");
}
sender.sendMessage(Arconix.pl().getApi().format().formatText("&6" + list));
} else {
if (args[2].equalsIgnoreCase("random")) {
ConfigurationSection cs = instance.spawnerFile.getConfig().getConfigurationSection("Entities");
List<String> list = new ArrayList<>();
for (String key : cs.getKeys(false)) {
if (instance.spawnerFile.getConfig().getBoolean("Entities." + key + ".Allowed")) {
key = key.toUpperCase().replace(" ", "_");
list.add(key);
}
}
Random rand = new Random();
int n = rand.nextInt(list.size() - 1);
type = list.get(n);
}
if (args.length == 4) {
if (!Arconix.pl().getApi().doMath().isNumeric(args[3])) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&6" + args[3] + "&7 is not a number."));
return true;
}
int amt = Integer.parseInt(args[3]);
ItemStack spawnerItem = instance.api.newSpawnerItem(type, 0, Integer.parseInt(args[3]));
if (args[1].toLowerCase().equals("all")) {
for (Player pl : Bukkit.getOnlinePlayers()) {
pl.getInventory().addItem(spawnerItem);
pl.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + instance.getLocale().getMessage("command.give.success", amt, Methods.compileName(type, multi, false))));
}
} else {
Player pl = Bukkit.getPlayerExact(args[1]);
pl.getInventory().addItem(spawnerItem);
pl.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + instance.getLocale().getMessage("command.give.success", amt, Methods.compileName(type, multi, false))));
}
} else {
if (!Arconix.pl().getApi().doMath().isNumeric(args[3])) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&6" + args[3] + "&7 is not a number."));
return true;
}
if (!Arconix.pl().getApi().doMath().isNumeric(args[3])) {
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&6" + args[4] + "&7 is not a number."));
return true;
}
int amt = Integer.parseInt(args[3]);
multi = Integer.parseInt(args[4]);
ItemStack spawnerItem = instance.api.newSpawnerItem(type, multi, amt);
if (args[1].toLowerCase().equals("all")) {
for (Player pl : Bukkit.getOnlinePlayers()) {
pl.getInventory().addItem(spawnerItem);
pl.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + instance.getLocale().getMessage("command.give.success", amt, Methods.compileName(type, multi, false))));
}
} else {
Player pl = Bukkit.getPlayerExact(args[1]);
pl.getInventory().addItem(spawnerItem);
pl.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + instance.getLocale().getMessage("command.give.success", amt, Methods.compileName(type, multi, false))));
}
}
}
}
} else if (cmd.getName().equalsIgnoreCase("SpawnerShop")) {
if (!sender.hasPermission("epicspawners.openshop")) {
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
} else {
Player p = (Player) sender;
instance.shop.open(p, 1);
}
} else if (cmd.getName().equalsIgnoreCase("SpawnerStats")) {
if (!sender.hasPermission("epicspawners.stats")) {
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
} else {
Player p = (Player) sender;
String uuid = p.getUniqueId().toString();
int size = 0;
if (instance.dataFile.getConfig().contains("data.kills")) {
for (String u : instance.dataFile.getConfig().getConfigurationSection("data.kills." + uuid).getKeys(false)) {
if (instance.spawnerFile.getConfig().getInt("Entities." + u + ".CustomGoal") != 0) {
size++;
}
}
}
String title = instance.getLocale().getMessage("interface.spawnerstats.title");
Inventory i = Bukkit.createInventory(null, 54, title);
int max2 = 54;
if (size <= 9) {
i = Bukkit.createInventory(null, 18, title);
max2 = 18;
} else if (size <= 18) {
i = Bukkit.createInventory(null, 36, title);
max2 = 36;
} else if (size <= 27) {
i = Bukkit.createInventory(null, 45, title);
max2 = 45;
}
int num = 0;
while (num != 9) {
i.setItem(num, Methods.getGlass());
num++;
}
ItemStack exit = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Exit Icon")), 1);
ItemMeta exitmeta = exit.getItemMeta();
exitmeta.setDisplayName(instance.getLocale().getMessage("general.nametag.exit"));
exit.setItemMeta(exitmeta);
i.setItem(8, exit);
short place = 9;
p.sendMessage("");
if (instance.dataFile.getConfig().getString("data.kills." + uuid) == null) {
p.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("interface.spawnerstats.nokills"));
} else {
p.sendMessage(instance.references.getPrefix());
p.sendMessage(instance.getLocale().getMessage("interface.spawnerstats.prefix"));
for (String u : instance.dataFile.getConfig().getConfigurationSection("data.kills." + uuid).getKeys(false)) {
int goal = instance.getConfig().getInt("Spawner Drops.Kills Needed for Drop");
if (instance.spawnerFile.getConfig().getInt("Entities." + u + ".CustomGoal") != 0) {
goal = instance.spawnerFile.getConfig().getInt("Entities." + u + ".CustomGoal");
}
ItemStack it = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
ItemStack item = instance.heads.addTexture(it, Methods.restoreType(u));
ItemMeta itemmeta = item.getItemMeta();
ArrayList<String> lore = new ArrayList<>();
itemmeta.setLore(lore);
itemmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&6" + u + "&7: &e" + instance.dataFile.getConfig().getInt("data.kills." + uuid + "." + u) + "&7/&e" + goal));
item.setItemMeta(itemmeta);
i.setItem(place, item);
place++;
p.sendMessage(Arconix.pl().getApi().format().formatText(" &7- &6" + u + "&7: &e" + instance.dataFile.getConfig().getInt("data.kills." + uuid + "." + u) + "&7/&e" + goal));
}
p.sendMessage(instance.getLocale().getMessage("interface.spawnerstats.ongoal"));
}
p.sendMessage("");
if (instance.dataFile.getConfig().getString("data.kills." + uuid) != null)
p.openInventory(i);
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
}

View File

@ -0,0 +1,217 @@
package com.songoda.epicspawners.handlers;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.spawners.Spawner;
import com.songoda.epicspawners.utils.Debugger;
import com.songoda.epicspawners.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.Collection;
/**
* Created by songoda on 3/12/2017.
*/
public class HologramHandler {
public HologramHandler() {
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(EpicSpawners.getInstance(), this::updateHolograms, 5000L, 5000L);
loadHolograms();
}
public void loadHolograms() {
if ((boolean) EpicSpawners.getInstance().getConfig().get("Main.Spawners Have Holograms")) {
if (!EpicSpawners.getInstance().v1_7) {
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawner")) {
ConfigurationSection cs = EpicSpawners.getInstance().dataFile.getConfig().getConfigurationSection("data.spawner");
for (String key : cs.getKeys(true)) {
if (Arconix.pl().getApi().serialize().unserializeLocation(key).getWorld() != null) {
updateHologram(Arconix.pl().getApi().serialize().unserializeLocation(key).getBlock());
}
}
}
}
}
}
public void updateHolograms() {
try {
/*
if (!EpicSpawners.getInstance().v1_7) {
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.holograms")) {
ConfigurationSection cs = EpicSpawners.getInstance().dataFile.getConfig().getConfigurationSection("data.holograms");
for (String key : cs.getKeys(true)) {
if (Methods.getEntityByUniqueId(UUID.fromString(key)) != null) {
EpicSpawners.getInstance().dataFile.getConfig().set("data.holograms." + key, null);
Methods.getEntityByUniqueId(UUID.fromString(key)).remove();
}
}
}
if ((boolean) EpicSpawners.getInstance().getConfig().get("Main.Spawners Have Holograms")) {
EpicSpawners.getInstance().dataFile.getConfig().set("data.holograms", null);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawner")) {
ConfigurationSection cs = EpicSpawners.getInstance().dataFile.getConfig().getConfigurationSection("data.spawner");
for (String key : cs.getKeys(true)) {
if (Arconix.pl().serialize().unserializeLocation(key).getWorld() != null) {
updateHologram(Arconix.pl().serialize().unserializeLocation(key).getBlock());
}
}
}
}, 1L);
}
}
*/
} catch (Exception e) {
Debugger.runReport(e);
}
}
public void updateHologram(Block b) {
try {
Location olocation = b.getLocation();
Location location = null;
String face = null;
if (!EpicSpawners.getInstance().v1_7 && !EpicSpawners.getInstance().v1_8_R1) {
Collection<Entity> nearbyEntites = olocation.getWorld().getNearbyEntities(olocation, 5, 5, 5);
for (Entity entity : nearbyEntites) {
if (entity instanceof Player) {
face = Arconix.pl().getApi().getPlayer((Player) entity).getPlayerDirection();
}
}
Arconix.pl().getApi().packetLibrary.getHologramManager().despawnHologram(adjust("UP", b));
Arconix.pl().getApi().packetLibrary.getHologramManager().despawnHologram(adjust("NORTH", b));
Arconix.pl().getApi().packetLibrary.getHologramManager().despawnHologram(adjust("SOUTH", b));
Arconix.pl().getApi().packetLibrary.getHologramManager().despawnHologram(adjust("EAST", b));
Arconix.pl().getApi().packetLibrary.getHologramManager().despawnHologram(adjust("WEST", b));
Arconix.pl().getApi().packetLibrary.getHologramManager().despawnHologram(adjust("DOWN", b));
}
if (b.getType() == Material.MOB_SPAWNER) {
boolean go = true;
if (face != null && b.getRelative(BlockFace.UP).getType() != Material.AIR) {
if (b.getRelative(BlockFace.valueOf(face.toUpperCase())).getType() == Material.AIR) {
location = adjust(face.toUpperCase(), b);
go = false;
}
}
if (go) {
if (b.getRelative(BlockFace.UP).getType() == Material.AIR) {
location = adjust("UP", b);
} else if (b.getRelative(BlockFace.NORTH).getType() == Material.AIR) {
location = adjust("NORTH", b);
} else if (b.getRelative(BlockFace.SOUTH).getType() == Material.AIR) {
location = adjust("SOUTH", b);
} else if (b.getRelative(BlockFace.EAST).getType() == Material.AIR) {
location = adjust("EAST", b);
} else if (b.getRelative(BlockFace.WEST).getType() == Material.AIR) {
location = adjust("WEST", b);
} else if (b.getRelative(BlockFace.DOWN).getType() == Material.AIR) {
location = adjust("DOWN", b);
}
}
if (location != null) {
if ((boolean) EpicSpawners.getInstance().getConfig().get("Main.Spawners Have Holograms")) {
addHologram(location, olocation);
}
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
public Location adjust(String direction, Block b) {
Location location = null;
try {
switch (direction) {
case "UP":
location = b.getLocation().add(0.5, 1, 0.5);
break;
case "DOWN":
location = b.getLocation().subtract(0, 0.75, 0);
location = location.add(0.5, 0, 0.5);
break;
case "NORTH":
location = b.getLocation().subtract(0, 0, 0.5);
location = location.add(0.5, 0.15, 0);
break;
case "SOUTH":
location = b.getLocation().add(0, 0, 1.5);
location = location.add(0.5, 0.15, 0);
break;
case "EAST":
location = b.getLocation().add(1.5, 0, 0);
location = location.add(0, 0.15, 0.5);
break;
case "WEST":
location = b.getLocation().subtract(0.5, 0, 0);
location = location.add(0, 0.15, 0.5);
break;
}
} catch (Exception e) {
Debugger.runReport(e);
}
return location;
}
public void addHologram(Location location, Location olocation) {
try {
if (olocation.getBlock().getType() == Material.MOB_SPAWNER) {
Spawner spawner = new Spawner(olocation.getBlock());
int multi = EpicSpawners.getInstance().dataFile.getConfig().getInt("data.spawner." + spawner.locationStr);
String name;
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawnerstats." + spawner.locationStr + ".type")) {
name = Methods.compileName(EpicSpawners.getInstance().dataFile.getConfig().getString("data.spawnerstats." + spawner.locationStr + ".type"), multi, true);
} else {
name = Methods.formatName(spawner.spawner.getSpawnedType(), multi);
}
Arconix.pl().getApi().packetLibrary.getHologramManager().spawnHologram(location, name.trim());
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
public void processChange(Block b) {
try {
if (!EpicSpawners.getInstance().v1_7) {
Block spawner = null;
if (b.getType() == Material.MOB_SPAWNER) {
spawner = b;
} else if (b.getRelative(BlockFace.UP).getType() == Material.MOB_SPAWNER) {
spawner = b.getRelative(BlockFace.UP);
} else if (b.getRelative(BlockFace.DOWN).getType() == Material.MOB_SPAWNER) {
spawner = b.getRelative(BlockFace.DOWN);
} else if (b.getRelative(BlockFace.NORTH).getType() == Material.MOB_SPAWNER) {
spawner = b.getRelative(BlockFace.NORTH);
} else if (b.getRelative(BlockFace.SOUTH).getType() == Material.MOB_SPAWNER) {
spawner = b.getRelative(BlockFace.SOUTH);
} else if (b.getRelative(BlockFace.WEST).getType() == Material.MOB_SPAWNER) {
spawner = b.getRelative(BlockFace.WEST);
} else if (b.getRelative(BlockFace.EAST).getType() == Material.MOB_SPAWNER) {
spawner = b.getRelative(BlockFace.EAST);
}
final Block spawn = spawner;
if (spawner != null) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(EpicSpawners.getInstance(), () -> EpicSpawners.getInstance().holo.updateHologram(spawn), 1L);
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
}

View File

@ -0,0 +1,114 @@
package com.songoda.epicspawners.handlers;
import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.hooks.*;
import com.songoda.epicspawners.utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class HookHandler {
public Hook FactionsHook = null, RedProtectHook = null, ASkyBlockHook = null, USkyBlockHook = null,
WorldGuardHook = null, GriefPreventionHook = null, PlotSquaredHook = null, KingdomsHook = null,
TownyHook = null;
public ConfigWrapper hooksFile = new ConfigWrapper(EpicSpawners.getInstance(), "", "hooks.yml");
public HookHandler() {
}
public void hook() {
try {
hooksFile.createNewFile("Loading Hooks File", EpicSpawners.getInstance().getDescription().getName() + " Hooks File");
new FactionsHook();
new RedProtectHook();
new GriefPreventionHook();
new ASkyBlockHook();
new USkyBlockHook();
new WorldGuardHook();
new PlotSquaredHook();
new KingdomsHook();
new TownyHook();
hooksFile.getConfig().options().copyDefaults(true);
hooksFile.saveConfig();
} catch (Exception e) {
Debugger.runReport(e);
}
}
public boolean isInFaction(String name, Location l) {
if (FactionsHook != null) {
return FactionsHook.isInClaim(name, l);
}
return false;
}
public String getFactionId(String name) {
if (FactionsHook != null) {
return FactionsHook.getClaimId(name);
}
return null;
}
public boolean isInTown(String name, Location l) {
if (TownyHook != null) {
return TownyHook.isInClaim(name, l);
}
return false;
}
public String getTownId(String name) {
if (TownyHook != null) {
return TownyHook.getClaimId(name);
}
return null;
}
public boolean isInIsland(String name, Location l) {
if (USkyBlockHook != null)
return USkyBlockHook.isInClaim(name, l);
else if (ASkyBlockHook != null)
return ASkyBlockHook.isInClaim(name, l);
else
return false;
}
public String getIslandId(String name) {
try {
return Bukkit.getOfflinePlayer(name).getUniqueId().toString();
} catch (Exception ignore) {
}
return null;
}
public boolean canBuild(Player p, Location l) {
boolean result = true;
if (WorldGuardHook != null)
result = WorldGuardHook.canBuild(p, l);
if (RedProtectHook != null && result)
result = RedProtectHook.canBuild(p, l);
if (FactionsHook != null && result)
result = FactionsHook.canBuild(p, l);
if (ASkyBlockHook != null && result)
result = ASkyBlockHook.canBuild(p, l);
if (USkyBlockHook != null && result)
result = USkyBlockHook.canBuild(p, l);
if (GriefPreventionHook != null && result)
result = GriefPreventionHook.canBuild(p, l);
if (PlotSquaredHook != null && result)
result = PlotSquaredHook.canBuild(p, l);
if (KingdomsHook != null && result)
result = KingdomsHook.canBuild(p, l);
if (TownyHook != null && result)
result = TownyHook.canBuild(p, l);
return result;
}
}

View File

@ -0,0 +1,242 @@
package com.songoda.epicspawners.handlers;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.spawners.Spawner;
import com.songoda.epicspawners.spawners.SpawnerItem;
import com.songoda.epicspawners.utils.Debugger;
import com.songoda.epicspawners.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
/**
* Created by songo on 9/3/2017.
*/
public class ItemHandler {
public ItemHandler() {
try {
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(EpicSpawners.getInstance(), ItemHandler::dropItems, 10L, 20L);
} catch (Exception e) {
Debugger.runReport(e);
}
}
@SuppressWarnings("unchecked")
public static void dropItems() {
try {
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawner")) {
ConfigurationSection cs3 = EpicSpawners.getInstance().dataFile.getConfig().getConfigurationSection("data.spawner");
for (String key2 : cs3.getKeys(false)) {
Location spawnerLoc = Arconix.pl().getApi().serialize().unserializeLocation(key2);
int locx = spawnerLoc.getBlockX() >> 4;
int locz = spawnerLoc.getBlockZ() >> 4;
if (!spawnerLoc.getWorld().isChunkLoaded(locx, locz)) {
continue;
}
boolean playerFound = false;
Collection <Entity> nearbyEntite = Methods.getNearbyEntities(spawnerLoc.clone().add(0.5, 0.5, 0.5), 16, 16, 16);
if (nearbyEntite.size() >= 1) {
for (Entity ee : nearbyEntite) {
if (ee instanceof LivingEntity) {
if (ee instanceof Player) {
playerFound = true;
}
}
}
}
if (playerFound) {
Spawner sp = new Spawner(spawnerLoc);
//if (EpicSpawners.getInstance().hooksFile.getConfig().contains("Entities." + sp.spawnedTypeU + ".items") || sp.spawnedTypeU.equalsIgnoreCase("OMNI")) {
if (EpicSpawners.getInstance().spawnerFile.getConfig().contains("Entities." + sp.spawnedType + ".items")) {
try {
String type = Methods.getType(sp.getSpawner().getSpawnedType());
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(spawnerLoc) + ".type")) {
if (!EpicSpawners.getInstance().dataFile.getConfig().getString("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(spawnerLoc) + ".type").equals("OMNI")) {
type = Methods.getTypeFromString(EpicSpawners.getInstance().dataFile.getConfig().getString("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(spawnerLoc) + ".type"));
}
}
List<SpawnerItem> list = EpicSpawners.getInstance().getApi().convertFromList(EpicSpawners.getInstance().dataFile.getConfig().getStringList("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(spawnerLoc) + ".entities"));
if (list.size() == 0)
list.add(new SpawnerItem(type, 1));
for (SpawnerItem omni : list) {
if (EpicSpawners.getInstance().spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(omni.getType()) + ".items")) {
String key3 = key2 + omni.getType();
int rate = EpicSpawners.getInstance().spawnerFile.getConfig().getInt("Entities." + Methods.getTypeFromString(omni.getType()) + ".itemTickRate");
if (EpicSpawners.getInstance().api.getSpawnerMultiplier(spawnerLoc) != 1)
rate = rate / EpicSpawners.getInstance().api.getSpawnerMultiplier(spawnerLoc);
long cur = (System.currentTimeMillis() / 1000);
long next = cur + rate;
if (EpicSpawners.getInstance().tickTracker.containsKey(key3)) {
long goal = EpicSpawners.getInstance().tickTracker.get(key3);
if (cur >= goal) {
if (!sp.getSpawner().getBlock().isBlockPowered() && EpicSpawners.getInstance().getConfig().getBoolean("Main.Redstone Power Deactivates Spawners")) {
for (ItemStack item : (ArrayList<ItemStack>) EpicSpawners.getInstance().spawnerFile.getConfig().getList("Entities." + Methods.getTypeFromString(omni.getType()) + ".items")) {
Location loc = spawnerLoc.clone();
loc.add(.5, .9, .5);
Item it = loc.getWorld().dropItemNaturally(loc, item);
Random r = new Random();
double rx = -.2 + (.2 - -.2) * r.nextDouble();
r = new Random();
double ry = 0 + (.5 - 0) * r.nextDouble();
r = new Random();
double rz = -.2 + (.2 - -.2) * r.nextDouble();
it.setVelocity(new Vector(rx, ry, rz));
}
}
EpicSpawners.getInstance().tickTracker.put(key3, next);
}
} else
EpicSpawners.getInstance().tickTracker.put(key3, next);
}
}
} catch (Exception ignore) {
}
}
if (EpicSpawners.getInstance().spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(sp.spawnedType) + ".blocks")) {
for (String m : (ArrayList<String>) EpicSpawners.getInstance().spawnerFile.getConfig().getList("Entities." + Methods.getTypeFromString(sp.spawnedType) + ".blocks")) {
Material mat = Material.valueOf(m);
if (mat.isBlock()) {
double x = 1;
double y = 1;
double z = 1;
Location loc = spawnerLoc.clone();
loc.add(.5, 0, .5);
boolean good = false;
int num = 0;
while (!good && num != 150) {
num ++;
double testX = ThreadLocalRandom.current().nextDouble(-1, 1);
double testY = ThreadLocalRandom.current().nextDouble(-1, 2);
double testZ = ThreadLocalRandom.current().nextDouble(-1, 1);
x = loc.getX() + testX * (double) 3;
y = loc.getY() + testY;
z = loc.getZ() + testZ * (double) 3;
Location loc2 = new Location(loc.getWorld(), x, y, z);
Methods.isAir(loc.getBlock().getType());
Location loc3 = loc2.clone().subtract(0, 1, 0);
if (Methods.isAir(loc2.getBlock().getType()) && !loc3.getBlock().getType().equals(Material.AIR))
good = true;
}
if (good) {
Location location = new Location(loc.getWorld(), x,y,z);
location.getBlock().setType(mat);
}
}
}
}
if (EpicSpawners.getInstance().spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(sp.spawnedType) + ".commands")) {
try {
String key3 = key2 + sp.spawnedType;
int rate = EpicSpawners.getInstance().spawnerFile.getConfig().getInt("Entities." + Methods.getTypeFromString(sp.spawnedType) + ".commandTickRate");
if (EpicSpawners.getInstance().api.getSpawnerMultiplier(spawnerLoc) != 1)
rate = rate / EpicSpawners.getInstance().api.getSpawnerMultiplier(spawnerLoc);
long cur = (System.currentTimeMillis() / 1000);
long next = cur + rate;
if (EpicSpawners.getInstance().tickTracker2.containsKey(key3)) {
long goal = EpicSpawners.getInstance().tickTracker2.get(key3);
if (cur >= goal) {
if (!sp.getSpawner().getBlock().isBlockPowered() && EpicSpawners.getInstance().getConfig().getBoolean("Main.Redstone Power Deactivates Spawners")) {
for (String cmd : (ArrayList<String>) EpicSpawners.getInstance().spawnerFile.getConfig().getList("Entities." + Methods.getTypeFromString(sp.spawnedType) + ".commands")) {
Location loc = spawnerLoc.clone();
loc.add(.5, 0, .5);
double x = 1;
double y = 1;
double z = 1;
boolean good = false;
while (!good) {
double testX = ThreadLocalRandom.current().nextDouble(-1, 1);
double testY = ThreadLocalRandom.current().nextDouble(-1, 2);
double testZ = ThreadLocalRandom.current().nextDouble(-1, 1);
x = loc.getX() + testX * (double) 3;
y = loc.getY() + testY;
z = loc.getZ() + testZ * (double) 3;
Location loc2 = new Location(loc.getWorld(), x, y, z);
Methods.isAir(loc.getBlock().getType());
Location loc3 = loc2.clone().subtract(0, 1, 0);
if (Methods.isAir(loc2.getBlock().getType()) && !loc3.getBlock().getType().equals(Material.AIR))
good = true;
}
if (cmd.toLowerCase().contains("@x") || cmd.toLowerCase().contains("@y") || cmd.toLowerCase().contains("@z")) {
if (Methods.countEntitiesAroundLoation(spawnerLoc) > EpicSpawners.getInstance().spawnerFile.getConfig().getInt("Entities." + sp.spawnedType + ".commandSpawnLimit") &&
EpicSpawners.getInstance().spawnerFile.getConfig().getInt("Entities." + sp.spawnedType + ".commandSpawnLimit") != 0)
return;
}
boolean uP = true;
if (cmd.toLowerCase().contains("@p")) {
uP = false;
List<String> arr = Arrays.asList(EpicSpawners.getInstance().getConfig().getString("Main.Radius To Search Around Spawner").split("x"));
Collection<Entity> nearbyEntitee = Methods.getNearbyEntities(loc.clone().add(0.5, 0.5, 0.5), Integer.parseInt(arr.get(0)), Integer.parseInt(arr.get(1)), Integer.parseInt(arr.get(2)));
if (nearbyEntitee.size() >= 1) {
for (Entity ee : nearbyEntitee) {
if (ee instanceof LivingEntity) {
if (ee instanceof Player) {
uP = true;
cmd = cmd.replace("@p", ee.getName());
}
}
}
}
}
cmd = cmd.replace("@x", Integer.toString((int) Math.ceil(x)));
cmd = cmd.replace("@y", Integer.toString((int) Math.ceil(y)));
cmd = cmd.replace("@z", Integer.toString((int) Math.ceil(z)));
cmd = cmd.replace("@X", Integer.toString((int) Math.ceil(x)));
cmd = cmd.replace("@Y", Integer.toString((int) Math.ceil(y)));
cmd = cmd.replace("@Z", Integer.toString((int) Math.ceil(z)));
if (uP)
Bukkit.getServer().dispatchCommand(EpicSpawners.getInstance().getServer().getConsoleSender(), cmd);
}
}
EpicSpawners.getInstance().tickTracker2.put(key3, next);
}
} else
EpicSpawners.getInstance().tickTracker2.put(key3, next);
} catch (Exception ignore) {
}
}
}
}
}
} catch (Exception ignore) {
}
}
}

View File

@ -0,0 +1,79 @@
package com.songoda.epicspawners.handlers;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.spawners.Spawner;
import com.songoda.epicspawners.spawners.SpawnerItem;
import com.songoda.epicspawners.utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import java.util.List;
/**
* Created by songo on 5/17/2017.
*/
public class OmniHandler {
public OmniHandler() {
try {
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(EpicSpawners.getInstance(), OmniHandler::displayItems, 30L, 30L);
} catch (Exception e) {
Debugger.runReport(e);
}
}
public static void displayItems() {
try {
if (EpicSpawners.getInstance().getConfig().getBoolean("Main.OmniSpawners Enabled")) {
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawnerstats")) {
ConfigurationSection cs = EpicSpawners.getInstance().dataFile.getConfig().getConfigurationSection("data.spawnerstats");
for (String key : cs.getKeys(false)) {
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawnerstats." + key + ".type")) {
if (EpicSpawners.getInstance().dataFile.getConfig().getString("data.spawnerstats." + key + ".type").equals("OMNI")) {
Location loc = Arconix.pl().getApi().serialize().unserializeLocation(key);
if (loc != null && loc.getWorld() != null) {
int destx = loc.getBlockX() >> 4;
int destz = loc.getBlockZ() >> 4;
if (!loc.getWorld().isChunkLoaded(destx, destz)) {
continue;
}
if (loc.getBlock().getType() == Material.MOB_SPAWNER) {
Spawner eSpawner = new Spawner(loc);
String last = null;
String next = null;
List<SpawnerItem> list = EpicSpawners.getInstance().getApi().convertFromList(EpicSpawners.getInstance().dataFile.getConfig().getStringList("data.spawnerstats." + key + ".entities"));
for (SpawnerItem item : list) {
if (item.getType().equals(eSpawner.getOmniState())) {
last = item.getType();
} else if (last != null && next == null) {
next = item.getType();
}
}
if (next == null) {
next = list.get(0).getType();
}
EpicSpawners.getInstance().getApi().updateDisplayItem(next,loc);
eSpawner.setOmniState(next);
} else {
EpicSpawners.getInstance().dataFile.getConfig().set("data.spawnerstats." + key + ".type", null);
EpicSpawners.getInstance().dataFile.getConfig().set("data.spawnerstats." + key + ".entities", null);
}
} else {
EpicSpawners.getInstance().dataFile.getConfig().set("data.spawnerstats." + key + ".type", null);
EpicSpawners.getInstance().dataFile.getConfig().set("data.spawnerstats." + key + ".entities", null);
}
}
}
}
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
}

View File

@ -0,0 +1,64 @@
package com.songoda.epicspawners.hooks;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import com.wasteofplastic.askyblock.ASkyBlockAPI;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.Set;
import java.util.UUID;
/**
* Created by songoda on 3/17/2017.
*/
public class ASkyBlockHook extends Hook {
private ASkyBlockAPI as;
public ASkyBlockHook() {
super("ASkyblock");
if (isEnabled()) {
as = ASkyBlockAPI.getInstance();
EpicSpawners plugin = EpicSpawners.pl();
plugin.hooks.ASkyBlockHook = this;
}
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p) || as.getIslandAt(location) == null) return true;
UUID owner = as.getOwner(location);
List<UUID> list = as.getTeamMembers(owner);
Set<Location> list2 = as.getCoopIslands(p);
if (owner == null) return true;
for (UUID uuid : list) {
if (uuid.equals(p.getUniqueId())) {
return true;
}
}
for (Location loc: list2) {
if (as.getIslandAt(location).getOwner().equals(as.getIslandAt(loc).getOwner())) {
return true;
}
}
return owner.equals(p.getUniqueId());
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
@Override
public boolean isInClaim(String uuid, Location location) {
return as.getOwner(location).toString().equals(uuid);
}
}

View File

@ -0,0 +1,57 @@
package com.songoda.epicspawners.hooks;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import me.markeh.factionsframework.entities.FPlayer;
import me.markeh.factionsframework.entities.FPlayers;
import me.markeh.factionsframework.entities.Faction;
import me.markeh.factionsframework.entities.Factions;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class FactionsHook extends Hook {
public FactionsHook() {
super("Factions");
EpicSpawners plugin = EpicSpawners.pl();
if (isEnabled() && Bukkit.getPluginManager().isPluginEnabled("FactionsFramework"))
plugin.hooks.GriefPreventionHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
FPlayer fp = FPlayers.getBySender(p);
Faction faction = Factions.getFactionAt(location);
return (fp.getFaction().equals(faction) || faction.isNone());
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@Override
public boolean isInClaim(String id, Location location) {
Faction faction = Factions.getFactionAt(location);
return faction.getId().equals(id);
}
@Override
public String getClaimId(String name) {
try {
Faction faction = Factions.getByName(name, "");
return faction.getId();
} catch (Exception ignore) {
}
return null;
}
}

View File

@ -0,0 +1,37 @@
package com.songoda.epicspawners.hooks;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class GriefPreventionHook extends Hook {
public GriefPreventionHook() {
super("GriefPrevention");
EpicSpawners plugin = EpicSpawners.pl();
if (isEnabled())
plugin.hooks.GriefPreventionHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p))
return true;
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null);
return claim != null && claim.allowBuild(p, Material.STONE) == null;
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
}

View File

@ -0,0 +1,40 @@
package com.songoda.epicspawners.hooks;
import com.songoda.epicspawners.EpicSpawners;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public abstract class Hook {
final String pluginName;
protected Hook(String pluginName) {
this.pluginName = pluginName;
if (isEnabled())
EpicSpawners.getInstance().hooks.hooksFile.getConfig().addDefault("hooks." + pluginName, true);
}
protected boolean isEnabled() {
return (Bukkit.getPluginManager().isPluginEnabled(pluginName)
&& EpicSpawners.getInstance().hooks.hooksFile.getConfig().getBoolean("hooks." + pluginName,true));
}
boolean hasBypass(Player p) {
return p.hasPermission(EpicSpawners.getInstance().getDescription().getName() + ".bypass");
}
public abstract boolean canBuild(Player p, Location location);
public boolean isInClaim(String id, Location location) {
return false;
}
public String getClaimId(String name) {
return null;
}
}

View File

@ -0,0 +1,43 @@
package com.songoda.epicspawners.hooks;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.kingdoms.constants.land.Land;
import org.kingdoms.constants.land.SimpleChunkLocation;
import org.kingdoms.constants.player.OfflineKingdomPlayer;
import org.kingdoms.manager.game.GameManagement;
/**
* Created by songoda on 3/17/2017.
*/
public class KingdomsHook extends Hook {
public KingdomsHook() {
super("Kingdoms");
EpicSpawners plugin = EpicSpawners.pl();
if (isEnabled())
plugin.hooks.KingdomsHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p)) return true;
OfflineKingdomPlayer pl = GameManagement.getPlayerManager().getOfflineKingdomPlayer(p);
if (pl.getKingdomPlayer().getKingdom() == null) return true;
SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getWorld().getName(), location.getChunk().getX(), location.getChunk().getZ());
Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation);
String owner = land.getOwner();
return pl.getKingdomPlayer().getKingdom().getKingdomName().equals(owner) || owner == null;
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
}

View File

@ -0,0 +1,38 @@
package com.songoda.epicspawners.hooks;
import com.intellectualcrafters.plot.api.PlotAPI;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class PlotSquaredHook extends Hook {
private PlotAPI plotAPI;
public PlotSquaredHook() {
super("PlotSquared");
if (isEnabled()) {
EpicSpawners plugin = EpicSpawners.pl();
plugin.hooks.PlotSquaredHook = this;
this.plotAPI = new PlotAPI();
}
}
@Override
public boolean canBuild(Player p, Location location) {
try {
return hasBypass(p)
|| (plotAPI.getPlot(location) != null
&& plotAPI.isInPlot(p)
&& plotAPI.getPlot(p) == plotAPI.getPlot(location));
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
}

View File

@ -0,0 +1,33 @@
package com.songoda.epicspawners.hooks;
import br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI;
import br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class RedProtectHook extends Hook {
public RedProtectHook() {
super("RedProtect");
EpicSpawners plugin = EpicSpawners.pl();
if (isEnabled())
plugin.hooks.RedProtectHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
RedProtectAPI rpAPI = RedProtect.get().getAPI();
return hasBypass(p) || (rpAPI.getRegion(location) != null && rpAPI.getRegion(location).canBuild(p));
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
}

View File

@ -0,0 +1,56 @@
package com.songoda.epicspawners.hooks;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class TownyHook extends Hook {
public TownyHook() {
super("Towny");
EpicSpawners plugin = EpicSpawners.pl();
if (isEnabled())
plugin.hooks.TownyHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p) || TownyUniverse.isWilderness(location.getBlock())) return true;
if (!TownyUniverse.getTownBlock(location).hasTown()) return true;
Resident r = TownyUniverse.getDataSource().getResident(p.getName());
return r.hasTown() && TownyUniverse.getTownName(location).equals(r.getTown().getName());
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
@Override
public boolean isInClaim(String id, Location location) {
try {
return !TownyUniverse.isWilderness(location.getBlock())
&& TownyUniverse.getTownBlock(location).getTown().getUID() == Integer.parseInt(id);
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@Override
public String getClaimId(String name) {
try {
return TownyUniverse.getDataSource().getTown(name).getUID().toString();
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
}

View File

@ -0,0 +1,49 @@
package com.songoda.epicspawners.hooks;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
/**
* Created by songoda on 3/17/2017.
*/
public class USkyBlockHook extends Hook {
private uSkyBlockAPI usb;
public USkyBlockHook() {
super("USkyBlock");
if (isEnabled()) {
EpicSpawners plugin = EpicSpawners.pl();
plugin.hooks.USkyBlockHook = this;
this.usb = (uSkyBlockAPI) Bukkit.getPluginManager().getPlugin(pluginName);
}
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p)) return true;
for (Player pl : usb.getIslandInfo(location).getOnlineMembers()) {
if (pl.equals(p)) {
return true;
}
}
return usb.getIslandInfo(location).isLeader(p);
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@Override
public boolean isInClaim(String uuid, Location location) {
return usb.getIslandInfo(location).getLeader().equals(uuid);
}
}

View File

@ -0,0 +1,31 @@
package com.songoda.epicspawners.hooks;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class WorldGuardHook extends Hook {
private EpicSpawners plugin = EpicSpawners.pl();
public WorldGuardHook() {
super("WorldGuard");
if (isEnabled())
plugin.hooks.WorldGuardHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
return p.hasPermission(plugin.getDescription().getName() + ".bypass") || WorldGuardPlugin.inst() == null || WorldGuardPlugin.inst().canBuild(p, location);
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
}

View File

@ -0,0 +1,317 @@
package com.songoda.epicspawners.listeners;
import com.songoda.arconix.api.utils.Serializer;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.entity.EPlayer;
import com.songoda.epicspawners.spawners.Spawner;
import com.songoda.epicspawners.spawners.SpawnerBreakEvent;
import com.songoda.epicspawners.spawners.SpawnerPlaceEvent;
import com.songoda.epicspawners.utils.Debugger;
import com.songoda.epicspawners.utils.Methods;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
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.BlockFromToEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.RegisteredServiceProvider;
/**
* Created by songoda on 2/25/2017.
*/
public class BlockListeners implements Listener {
private final EpicSpawners instance;
public BlockListeners(EpicSpawners instance) {
this.instance = instance;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent e) {
try {
if (doLiquidRepel(e.getBlock(), false)) e.setCancelled(true);
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
private boolean doLiquidRepel(Block block, boolean from) {
int radius = instance.getConfig().getInt("Main.Spawner Repel Liquid Radius");
if (radius == 0) return false;
if (!from) radius++;
int bx = block.getX();
int by = block.getY();
int bz = block.getZ();
for (int fx = -radius; fx <= radius; fx++) {
for (int fy = -radius; fy <= radius; fy++) {
for (int fz = -radius; fz <= radius; fz++) {
Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
if (from) {
if ((b2.getType().equals(Material.STATIONARY_LAVA) || b2.getType().equals(Material.LAVA))
|| (b2.getType().equals(Material.STATIONARY_WATER) || b2.getType().equals(Material.WATER))) {
b2.setType(Material.AIR);
}
} else {
if (b2.getType().equals(Material.MOB_SPAWNER)) {
return true;
}
}
}
}
}
return false;
}
@EventHandler(ignoreCancelled = true)
public void onSpawnerPlace(BlockPlaceEvent e) {
try {
Player p = e.getPlayer();
Block b = e.getBlockPlaced();
if (b.getType().equals(Material.MOB_SPAWNER)) doLiquidRepel(b, true);
if (Methods.isOffhand(e)) {
if (p.getInventory().getItemInOffHand().getType() == Material.MOB_SPAWNER)
e.setCancelled(true);
return;
}
ItemStack inh = p.getItemInHand();
ItemMeta im = inh.getItemMeta();
if (im == null || b.getType() != Material.MOB_SPAWNER || im.getDisplayName() == null)
return;
String type = instance.getApi().getIType(inh);
FileConfiguration dataFile = instance.dataFile.getConfig();
if (!p.hasPermission("epicspawners.place." + type) && !p.hasPermission("epicspawners.place." + Methods.getTypeFromString(type)) && !p.hasPermission("epicspawners.place.*")) {
e.setCancelled(true);
return;
}
SpawnerPlaceEvent event = new SpawnerPlaceEvent(b.getLocation(), p, type);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
if (doForceCombine(p, b, dataFile, type)) {
e.setCancelled(true);
return;
}
Spawner eSpawner = new Spawner(b);
boolean isCustom = false;
if (!type.equals("OMNI")) {
try {
eSpawner.setSpawner(EntityType.valueOf(type));
} catch (Exception ex) {
isCustom = true;
eSpawner.setSpawner(EntityType.valueOf("DROPPED_ITEM"));
}
}
int multi = 0;
if (im.hasDisplayName()) {
if (instance.blacklist.isBlacklisted(p, true)) {
e.setCancelled(true);
} else {
multi = instance.getApi().getIMulti(inh);
eSpawner.updateDelay();
dataFile.set("data.spawner." + Arconix.pl().getApi().serialize().serializeLocation(b), multi);
if (!type.equals("OMNI") && isCustom) {
dataFile.set("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(b) + ".type", type);
}
dataFile.set("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(b) + ".player", p.getUniqueId().toString());
instance.getApi().saveCustomSpawner(inh, b);
}
}
if (instance.getConfig().getBoolean("Main.Alerts On Place And Break") &&
(!instance.blacklist.isBlacklisted(p, false) || !im.hasDisplayName())) {
p.sendMessage(instance.getLocale().getMessage("event.block.place", Methods.compileName(type, multi, true)));
}
instance.getApi().updateDisplayItem(type, b.getLocation());
if (multi <= 1) {
dataFile.set("data.spawner." + Arconix.pl().getApi().serialize().serializeLocation(b), 1);
if (!type.equals("OMNI") && isCustom) {
dataFile.set("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(b) + ".type", type);
}
dataFile.set("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(b) + ".player", p.getUniqueId().toString());
if (!p.isOp() && instance.spawnerFile.getConfig().getInt("Entities." + Methods.getTypeFromString(type) + ".Pickup-cost") != 0 && eSpawner.canCharge()) {
int cost = instance.spawnerFile.getConfig().getInt("Entities." + Methods.getTypeFromString(type) + ".Pickup-cost");
p.sendMessage(instance.getLocale().getMessage("event.block.chargeplace", Arconix.pl().getApi().format().formatEconomy(cost)));
instance.freePickup.put(p, b.getLocation());
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, () -> instance.freePickup.remove(p), 1200L);
}
}
instance.holo.processChange(e.getBlock());
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
public boolean doForceCombine(Player p, Block b, FileConfiguration dataFile, String type) {
if (instance.getConfig().getInt("Main.Force Combine Radius") == 0 || !dataFile.contains("data.spawner")) {
return false;
}
ConfigurationSection cs = dataFile.getConfigurationSection("data.spawner");
for (String key : cs.getKeys(false)) {
if (Arconix.pl().getApi().serialize().unserializeLocation(key).getWorld() == null
|| !Arconix.pl().getApi().serialize().unserializeLocation(key).getWorld().equals(b.getLocation().getWorld())
|| Arconix.pl().getApi().serialize().unserializeLocation(key).distance(b.getLocation()) >= instance.getConfig().getInt("Main.Force Combine Radius")
|| p.getItemInHand().getItemMeta().getDisplayName() == null
|| instance.getApi().isOmniBlock(Arconix.pl().getApi().serialize().unserializeLocation(key))) {
continue;
}
Spawner eSpawner = new Spawner(Arconix.pl().getApi().serialize().unserializeLocation(key).getBlock());
String name = eSpawner.getSpawner() == null || eSpawner.getSpawner().getSpawnedType().name().equals("DROPPED_ITEM")
? EpicSpawners.getInstance().dataFile.getConfig().getString("data.spawnerstats." + key + ".type")
: eSpawner.getSpawner().getSpawnedType().name();
if (name == null || !name.equals(type))
continue;
if (instance.getConfig().getBoolean("settings.serializer"))
p.sendMessage(instance.getLocale().getMessage("event.block.forcedeny"));
else if (eSpawner.processCombine(p, p.getItemInHand(), null))
p.sendMessage(instance.getLocale().getMessage("event.block.mergedistance"));
return true;
}
return false;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
//Leave this on high or WorldGuard will not work...
public void onBlockBreak(BlockBreakEvent e) {
try {
Block b = e.getBlock();
if (b.getType() != Material.MOB_SPAWNER) {
return;
}
Spawner eSpawner = new Spawner(b);
Player p = e.getPlayer();
e.setExpToDrop(0);
if (!eSpawner.canBreak()) {
return;
}
FileConfiguration dataFile = instance.dataFile.getConfig();
FileConfiguration config = instance.getConfig();
Serializer serializer = Arconix.pl().getApi().serialize();
String type = Methods.getType(eSpawner.getSpawner().getSpawnedType());
if (dataFile.contains("data.spawnerstats." + serializer.serializeLocation(eSpawner.getSpawner().getBlock()) + ".type")
&& !dataFile.getString("data.spawnerstats." + serializer.serializeLocation(eSpawner.getSpawner().getBlock()) + ".type").equals("OMNI"))
type = dataFile.getString("data.spawnerstats." + serializer.serializeLocation(eSpawner.getSpawner().getBlock()) + ".type");
int multi = eSpawner.getMulti();
int omulti = multi;
int newMulti = multi - 1;
if (instance.getApi().isOmniBlock(b.getLocation())) {
type = "Omni";
if (omulti > 2) {
multi = instance.getApi().convertFromList(dataFile.getStringList("data.spawnerstats." + serializer.serializeLocation(b) + ".entities")).size();
} else {
String old = dataFile.getStringList("data.spawnerstats." + serializer.serializeLocation(b) + ".entities").get(0);
newMulti = Integer.parseInt(old.split("-")[1]);
}
}
if (config.getBoolean("Spawner Drops.Only Drop Stacked Spawners") ||
p.isSneaking() && config.getBoolean("Main.Sneak To Receive A Stacked Spawner")) {
if (!instance.getApi().isOmniBlock(b.getLocation()))
newMulti = 0;
}
if (newMulti > 0) {
e.setCancelled(true);
}
SpawnerBreakEvent event = new SpawnerBreakEvent(b.getLocation(), p);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
if ((p.getItemInHand().getItemMeta() == null || !p.getItemInHand().getItemMeta().hasEnchant(Enchantment.SILK_TOUCH))
&& !p.hasPermission("epicspawners.no-silk-drop")) {
eSpawner.downgradeFinal(p, newMulti, omulti, type);
return;
}
if (!config.getBoolean("Spawner Drops.Drop On SilkTouch")) {
return;
}
if (!p.isOp()
&& !instance.freePickup.containsValue(b.getLocation())
&& instance.spawnerFile.getConfig().getInt("Entities." + type + ".Pickup-cost") != 0) {
int cost = instance.spawnerFile.getConfig().getInt("Entities." + type + ".Pickup-cost");
if (newMulti == 0)
cost = cost * multi;
if (!instance.pickup.containsKey(p)) {
p.sendMessage(instance.getLocale().getMessage("event.block.chargebreak", Arconix.pl().getApi().format().formatEconomy(cost)));
instance.pickup.put(p, true);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, () -> instance.pickup.remove(p), 300L);
e.setCancelled(true);
return;
} else if (eSpawner.canCharge()
&& instance.spawnerFile.getConfig().getInt("Entities." + type + ".Pickup-cost") != 0
&& instance.pickup.containsKey(p)
&& instance.getServer().getPluginManager().getPlugin("Vault") != null) {
RegisteredServiceProvider<Economy> rsp = instance.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
if (econ.has(p, cost)) {
econ.withdrawPlayer(p, cost);
} else {
p.sendMessage(instance.getLocale().getMessage("event.block.cannotbreak"));
e.setCancelled(true);
return;
}
} else {
e.setCancelled(true);
return;
}
}
instance.pickup.remove(p);
int ch = Integer.parseInt(config.getString(dataFile.contains("data.spawner." + serializer.serializeLocation(b))
? "Spawner Drops.Chance On Placed Silktouch" : "Spawner Drops.Chance On Natural Silktouch").replace("%", ""));
double rand = Math.random() * 100;
if (!p.isSneaking() && !config.getBoolean("Spawner Drops.Only Drop Stacked Spawners") || p.isSneaking() && !config.getBoolean("Main.Sneak To Receive A Stacked Spawner")) {
multi = 1;
}
if (rand - ch < 0 || ch == 100) {
if (p.hasPermission("epicspawners.silkdrop." + type) || p.hasPermission("epicspawners.silkdrop.*")) {
new EPlayer(p).dropSpawner(b.getLocation(), multi, type);
}
}
eSpawner.downgradeFinal(p, newMulti, omulti, type);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, () -> instance.holo.processChange(e.getBlock()), 10L);
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
}

View File

@ -0,0 +1,98 @@
package com.songoda.epicspawners.listeners;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import com.songoda.epicspawners.utils.Methods;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
/**
* Created by songoda on 2/25/2017.
*/
public class ChatListeners implements Listener {
@EventHandler
public void chatListeners(AsyncPlayerChatEvent e) {
try {
if (!e.isCancelled()) {
if (EpicSpawners.getInstance().chatEditing.containsKey(e.getPlayer())) {
switch (EpicSpawners.getInstance().chatEditing.get(e.getPlayer())) {
case "destroy":
EpicSpawners.getInstance().editor.destroyFinal(e.getPlayer(), e.getMessage());
break;
case "name":
EpicSpawners.getInstance().editor.saveSpawnerName(e.getPlayer(), e.getMessage());
break;
case "tick":
EpicSpawners.getInstance().editor.saveChatEdit(e.getPlayer(), Integer.parseInt(e.getMessage()));
break;
case "addEntity":
EpicSpawners.getInstance().isEntityInstanceSaved = true;
EpicSpawners.getInstance().editor.addEntity(e.getPlayer(), e.getMessage());
break;
case "Shop-Price":
if (Arconix.pl().getApi().doMath().isNumeric(e.getMessage())) {
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(e.getPlayer()))) + ".Shop-Price", Double.parseDouble(e.getMessage()));
} else {
e.getPlayer().sendMessage(Arconix.pl().getApi().format().formatText("&CYou must enter a number."));
}
EpicSpawners.getInstance().editor.basicSettings(e.getPlayer());
break;
case "Custom-ECO-Cost":
if (Arconix.pl().getApi().doMath().isNumeric(e.getMessage())) {
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(e.getPlayer()))) + ".Custom-ECO-Cost", Double.parseDouble(e.getMessage()));
} else {
e.getPlayer().sendMessage(Arconix.pl().getApi().format().formatText("&CYou must enter a number."));
}
EpicSpawners.getInstance().editor.basicSettings(e.getPlayer());
break;
case "Custom-XP-Cost":
if (Arconix.pl().getApi().doMath().isNumeric(e.getMessage())) {
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(e.getPlayer()))) + ".Custom-XP-Cost", Integer.parseInt(e.getMessage()));
} else {
e.getPlayer().sendMessage(Arconix.pl().getApi().format().formatText("&CYou must enter a number."));
}
EpicSpawners.getInstance().editor.basicSettings(e.getPlayer());
break;
case "Command":
String msg = e.getMessage();
e.getPlayer().sendMessage(Arconix.pl().getApi().format().formatText(EpicSpawners.getInstance().references.getPrefix() + "&8Command &5" + msg + "&8 saved to your inventory."));
EpicSpawners.getInstance().editor.addCommand(e.getPlayer(), e.getMessage());
break;
case "CustomGoal":
if (Arconix.pl().getApi().doMath().isNumeric(e.getMessage())) {
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(e.getPlayer()))) + ".CustomGoal", Integer.parseInt(e.getMessage()));
} else {
e.getPlayer().sendMessage(Arconix.pl().getApi().format().formatText("&CYou must enter a number."));
}
EpicSpawners.getInstance().editor.basicSettings(e.getPlayer());
break;
case "Pickup-cost":
if (Arconix.pl().getApi().doMath().isNumeric(e.getMessage())) {
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(e.getPlayer()))) + ".Pickup-cost", Double.parseDouble(e.getMessage()));
} else {
e.getPlayer().sendMessage(Arconix.pl().getApi().format().formatText("&CYou must enter a number."));
}
EpicSpawners.getInstance().editor.basicSettings(e.getPlayer());
break;
case "spawnLimit":
if (Arconix.pl().getApi().doMath().isNumeric(e.getMessage())) {
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(e.getPlayer()))) + ".commandSpawnLimit", Double.parseDouble(e.getMessage()));
EpicSpawners.getInstance().editor.editor(e.getPlayer(), "Command");
} else {
e.getPlayer().sendMessage(Arconix.pl().getApi().format().formatText("&CYou must enter a number."));
}
EpicSpawners.getInstance().editor.basicSettings(e.getPlayer());
break;
}
EpicSpawners.getInstance().chatEditing.remove(e.getPlayer());
e.setCancelled(true);
}
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
}

View File

@ -0,0 +1,115 @@
package com.songoda.epicspawners.listeners;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.entity.EPlayer;
import com.songoda.epicspawners.spawners.Spawner;
import com.songoda.epicspawners.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import java.util.List;
/**
* Created by songoda on 2/25/2017.
*/
public class EntityListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlow(EntityExplodeEvent e) {
try {
if (!e.isCancelled()) {
List<Block> destroyed = e.blockList();
for (Block b : destroyed) {
if (b.getType() == Material.MOB_SPAWNER) {
Location spawnLocation = b.getLocation();
if (EpicSpawners.getInstance().getConfig().getBoolean("Main.Prevent Spawners From Exploding"))
e.blockList().remove(b);
else if (e.getEntity() instanceof Creeper && EpicSpawners.getInstance().getConfig().getBoolean("Spawner Drops.Drop On Creeper Explosion") || e.getEntity() instanceof TNTPrimed && EpicSpawners.getInstance().getConfig().getBoolean("Spawner Drops.Drop On TNT Explosion")) {
int multi = 0;
Spawner spawner = new Spawner(b);
boolean canDrop = spawner.canBreak();
String locationStr = Arconix.pl().getApi().serialize().serializeLocation(b);
if (EpicSpawners.getInstance().dataFile.getConfig().getInt("data.spawner." + locationStr) != 0) {
multi = EpicSpawners.getInstance().dataFile.getConfig().getInt("data.spawner." + locationStr);
EpicSpawners.getInstance().dataFile.getConfig().set("data.spawner." + locationStr, null);
}
String type = spawner.spawnedType;
String chance = "";
if (e.getEntity() instanceof Creeper && EpicSpawners.getInstance().getConfig().getBoolean("Spawner Drops.Drop On Creeper Explosion"))
chance = EpicSpawners.getInstance().getConfig().getString("Spawner Drops.Chance On TNT Explosion");
else if (e.getEntity() instanceof TNTPrimed && EpicSpawners.getInstance().getConfig().getBoolean("Spawner Drops.Drop On TNT Explosion"))
chance = EpicSpawners.getInstance().getConfig().getString("Spawner Drops.Chance On Creeper Explosion");
int ch = Integer.parseInt(chance.replace("%", ""));
double rand = Math.random() * 100;
if (rand - ch < 0 || ch == 100) {
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(b.getLocation()) + ".type")) {
if (EpicSpawners.getInstance().dataFile.getConfig().getString("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(b.getLocation()) + ".type").equals("OMNI")) {
type = "Omni";
multi = 100;
}
}
if (canDrop)
new EPlayer(null).dropSpawner(spawnLocation, multi, type);
}
}
EpicSpawners.getInstance().holo.processChange(b);
Location nloc = spawnLocation.clone();
nloc.add(.5, -.4, .5);
List<Entity> near = (List<Entity>) nloc.getWorld().getNearbyEntities(nloc, 8, 8, 8);
for (Entity ee : near) {
if (ee.getLocation().getX() == nloc.getX() && ee.getLocation().getY() == nloc.getY() && ee.getLocation().getZ() == nloc.getZ()) {
ee.remove();
}
}
}
}
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
@EventHandler
public void onDeath(EntityDeathEvent e) {
try {
if (e.getEntity().getKiller() != null) {
if (e.getEntity().getKiller() instanceof Player) {
Player p = e.getEntity().getKiller();
if (!EpicSpawners.getInstance().dataFile.getConfig().getBoolean("data.Entities." + e.getEntity().getUniqueId()) || EpicSpawners.getInstance().getConfig().getBoolean("Spawner Drops.Count Unnatural Kills Towards Spawner Drop")) {
new EPlayer(p).plus(e.getEntity(), 1);
}
}
}
EpicSpawners.getInstance().dataFile.getConfig().set("data.Entities." + e.getEntity().getUniqueId(), null);
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
@EventHandler
public void onDeath(CreatureSpawnEvent e) {
try {
if (e.getSpawnReason() != CreatureSpawnEvent.SpawnReason.NATURAL &&
e.getSpawnReason() != CreatureSpawnEvent.SpawnReason.CHUNK_GEN) {
EpicSpawners.getInstance().dataFile.getConfig().set("data.Entities." + e.getEntity().getUniqueId(), true);
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
}

View File

@ -0,0 +1,177 @@
package com.songoda.epicspawners.listeners;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.spawners.Spawner;
import com.songoda.epicspawners.spawners.SpawnerChangeEvent;
import com.songoda.epicspawners.utils.Debugger;
import com.songoda.epicspawners.utils.Methods;
import com.songoda.epicspawners.utils.Reflection;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
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.ItemStack;
import org.bukkit.material.SpawnEgg;
/**
* Created by songoda on 2/25/2017.
*/
public class InteractListeners implements Listener {
EpicSpawners instance;
public InteractListeners(EpicSpawners instance) {
this.instance = instance;
}
@EventHandler(ignoreCancelled = true)
public void PlayerInteractEventEgg(PlayerInteractEvent e) {
try {
if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
return;
}
Player p = e.getPlayer();
Block b = e.getClickedBlock();
ItemStack i = e.getItem();
Material is = null;
if (e.getItem() != null) {
is = i.getType();
}
int radius = instance.getConfig().getInt("Main.Spawner Repel Liquid Radius");
if (e.getItem() != null
&& is.equals(Material.WATER_BUCKET)
&& radius != 0) {
Block block = e.getClickedBlock();
int bx = block.getX();
int by = block.getY();
int bz = block.getZ();
for (int fx = -radius; fx <= radius; fx++) {
for (int fy = -radius; fy <= radius; fy++) {
for (int fz = -radius; fz <= radius; fz++) {
Block b2 = e.getClickedBlock().getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
if (b2.getType().equals(Material.MOB_SPAWNER)) {
e.setCancelled(true);
}
}
}
}
}
if (e.getClickedBlock().getType() == Material.MOB_SPAWNER && is == Material.MONSTER_EGG && instance.blacklist.isBlacklisted(p, true))
e.setCancelled(true);
if (!(e.getClickedBlock().getType() == Material.MOB_SPAWNER && is == Material.MONSTER_EGG && !instance.blacklist.isBlacklisted(p, true))) {
return;
}
Spawner eSpawner = new Spawner(b);
String btype = Methods.getType(eSpawner.getSpawner().getSpawnedType());
if (!instance.getConfig().getBoolean("Main.Convert Spawners With Eggs")
|| !instance.spawnerFile.getConfig().getBoolean("Entities." + btype + ".Allowed")) {
e.setCancelled(true);
return;
}
int bmulti = 1;
if (instance.dataFile.getConfig().getInt("data.spawner." + Arconix.pl().getApi().serialize().serializeLocation(b)) != 0)
bmulti = instance.dataFile.getConfig().getInt("data.spawner." + Arconix.pl().getApi().serialize().serializeLocation(b));
int amt = p.getInventory().getItemInHand().getAmount();
EntityType itype;
if (instance.v1_7 || instance.v1_8)
itype = ((SpawnEgg) i.getData()).getSpawnedType();
else {
String str = Reflection.getNBTTagCompound(Reflection.getNMSItemStack(i)).toString();
if (str.contains("minecraft:"))
itype = EntityType.fromName(str.substring(str.indexOf("minecraft:") + 10, str.indexOf("\"}")));
else
itype = EntityType.fromName(str.substring(str.indexOf("EntityTag:{id:") + 15, str.indexOf("\"}")));
}
if (!p.hasPermission("epicspawners.egg." + itype) && !p.hasPermission("epicspawners.egg.*")) {
return;
}
if (amt < bmulti) {
p.sendMessage(instance.getLocale().getMessage("event.egg.needmore", bmulti));
e.setCancelled(true);
return;
}
SpawnerChangeEvent event = new SpawnerChangeEvent(b.getLocation(), p, btype, itype.name());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
if (btype.equals(Methods.getType(itype))) {
p.sendMessage(instance.getLocale().getMessage("event.egg.sametype", btype));
return;
}
eSpawner.getSpawner().setSpawnedType(itype);
eSpawner.update();
instance.holo.processChange(b);
if (p.getGameMode() != GameMode.CREATIVE) {
Methods.takeItem(p, bmulti - 1);
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
@EventHandler(ignoreCancelled = true)
public void PlayerInteractEvent(PlayerInteractEvent e) {
try {
if (e.getClickedBlock().getType() == Material.MOB_SPAWNER) {
instance.holo.processChange(e.getClickedBlock());
}
if (e.isCancelled()
|| Methods.isOffhand(e)) {
return;
}
Player p = e.getPlayer();
Block b = e.getClickedBlock();
ItemStack i = e.getItem();
String loc = Arconix.pl().getApi().serialize().serializeLocation(b);
if (instance.dataFile.getConfig().getString("data.blockshop." + loc) != null) {
e.setCancelled(true);
instance.shop.show(instance.dataFile.getConfig().getString("data.blockshop." + loc).toUpperCase(), 1, p);
return;
}
if (!instance.hooks.canBuild(e.getPlayer(), e.getClickedBlock().getLocation())
|| e.getClickedBlock() == null
|| e.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Material is = null;
if (e.getItem() != null) {
is = i.getType();
}
if (is == Material.MONSTER_EGG)
return;
if (e.getClickedBlock().getType() == Material.MOB_SPAWNER && is == Material.MOB_SPAWNER && !instance.blacklist.isBlacklisted(p, true)) {
Spawner eSpawner = new Spawner(b);
if (!p.isSneaking() && i.getItemMeta().getDisplayName() != null) {
String itype = instance.getApi().getIType(i);
if (p.hasPermission("epicspawners.combine." + itype) || p.hasPermission("epicspawners.combine.*")) {
eSpawner.processCombine(p, i, null);
e.setCancelled(true);
}
}
} else if (e.getClickedBlock().getType() == Material.MOB_SPAWNER && !instance.blacklist.isBlacklisted(p, false)) {
if (!p.isSneaking()) {
Spawner eSpawner = new Spawner(b);
eSpawner.overView(p, 1);
instance.holo.processChange(b);
e.setCancelled(true);
}
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
}

View File

@ -0,0 +1,389 @@
package com.songoda.epicspawners.listeners;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.spawners.Spawner;
import com.songoda.epicspawners.spawners.SpawnerItem;
import com.songoda.epicspawners.utils.Debugger;
import com.songoda.epicspawners.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.List;
/**
* Created by songoda on 2/25/2017.
*/
public class InventoryListeners implements Listener {
private EpicSpawners instance;
public InventoryListeners(EpicSpawners instance) {
this.instance = instance;
}
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
try {
if (e.getInventory() == null) return;
Inventory inv = e.getInventory();
Player p = (Player) e.getWhoClicked();
if (EpicSpawners.getInstance().getConfig().getBoolean("Main.Allow Stacking Spawners In Survival Inventories")
&& p.getOpenInventory().getType().equals(InventoryType.CRAFTING)) {
if ((inv == null)
&& (e.getCursor() == null)
&& (e.getCurrentItem() == null)) {
return;
}
ItemStack c = e.getCursor();
ItemStack item = e.getCurrentItem();
if (!e.isRightClick() && item.getType() != Material.MOB_SPAWNER) {
return;
}
if (c.getType() == Material.MOB_SPAWNER) {
if (item.getAmount() != 1 || c.getAmount() != 1) {
p.sendMessage(instance.getLocale().getMessage("event.combine.onlyone"));
return;
}
if (item.getAmount() == 1 && c.getAmount() - item.getAmount() == 1 || c.getAmount() == 1) {
Spawner eSpawner = new Spawner();
if (eSpawner.processCombine(p, item, c)) {
e.setCurrentItem(new ItemStack(Material.AIR));
}
}
} else if (c.getType() == Material.AIR) {
if (item.getAmount() != 1) {
return;
}
if (EpicSpawners.getInstance().getApi().getType(item).equals("OMNI")) {
List<ItemStack> items = EpicSpawners.getInstance().getApi().removeOmni(item);
e.setCurrentItem(items.get(0));
e.setCursor(items.get(1));
} else {
List<ItemStack> items = EpicSpawners.getInstance().getApi().removeSpawner(item);
if (items.size() == 2) {
e.setCurrentItem(items.get(1));
e.setCursor(items.get(0));
}
}
}
}
if (EpicSpawners.getInstance().inShow.containsKey(e.getWhoClicked())) {
e.setCancelled(true);
int amt = e.getInventory().getItem(22).getAmount();
if (e.getSlot() == 0) {
int page = EpicSpawners.getInstance().page.get(p);
EpicSpawners.getInstance().shop.open(p, page);
} else if (e.getSlot() == 8) {
p.closeInventory();
} else if (e.getSlot() == 19) {
if (amt != 1)
amt = 1;
EpicSpawners.getInstance().shop.show(EpicSpawners.getInstance().inShow.get(p), amt, p);
} else if (e.getSlot() == 29) {
if ((amt - 10) <= 64 && (amt - 10) >= 1)
amt = amt - 10;
EpicSpawners.getInstance().shop.show(EpicSpawners.getInstance().inShow.get(p), amt, p);
} else if (e.getSlot() == 11) {
if ((amt - 1) <= 64 && (amt - 1) >= 1)
amt = amt - 1;
EpicSpawners.getInstance().shop.show(EpicSpawners.getInstance().inShow.get(p), amt, p);
} else if (e.getSlot() == 15) {
if ((amt + 1) <= 64 && (amt + 1) >= 1)
amt = amt + 1;
EpicSpawners.getInstance().shop.show(EpicSpawners.getInstance().inShow.get(p), amt, p);
} else if (e.getSlot() == 33) {
if ((amt + 10) <= 64 && (amt + 10) >= 1)
amt = amt + 10;
EpicSpawners.getInstance().shop.show(EpicSpawners.getInstance().inShow.get(p), amt, p);
} else if (e.getSlot() == 25) {
if (amt != 64)
amt = 64;
EpicSpawners.getInstance().shop.show(EpicSpawners.getInstance().inShow.get(p), amt, p);
} else if (e.getSlot() == 40) {
EpicSpawners.getInstance().shop.confirm(p, amt);
p.closeInventory();
}
} else if (EpicSpawners.getInstance().boosting.contains(p)) {
e.setCancelled(true);
Spawner eSpawner = new Spawner(EpicSpawners.getInstance().lastSpawner.get(p));
if (e.getSlot() == 8) {
EpicSpawners.getInstance().boostAmt.put(p, EpicSpawners.getInstance().boostAmt.get(p) + 1);
eSpawner.playerBoost(p);
} else if (e.getSlot() == 0) {
EpicSpawners.getInstance().boostAmt.put(p, EpicSpawners.getInstance().boostAmt.get(p) - 1);
eSpawner.playerBoost(p);
} else if (e.getSlot() == 10) {
eSpawner.purchaseBoost(p, 5);
} else if (e.getSlot() == 12) {
eSpawner.purchaseBoost(p, 15);
} else if (e.getSlot() == 14) {
eSpawner.purchaseBoost(p, 30);
} else if (e.getSlot() == 16) {
eSpawner.purchaseBoost(p, 60);
}
} else if (e.getInventory().getTitle().equals(instance.getLocale().getMessage("interface.convert.title"))) {
e.setCancelled(true);
ItemStack clicked = e.getCurrentItem();
Spawner eSpawner = new Spawner(EpicSpawners.getInstance().spawnerLoc.get(p));
int page = EpicSpawners.getInstance().page.get(p);
if (e.getInventory().getType() == InventoryType.CHEST) {
if (e.getSlot() == 8) {
p.closeInventory();
} else if (e.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("general.nametag.back"))) {
if (page != 1) {
eSpawner.change(p, page - 1);
}
} else if (e.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("general.nametag.next"))) {
eSpawner.change(p, page + 1);
} else if (clicked.getType() == Material.SKULL_ITEM || clicked.getType() == Material.MOB_SPAWNER) {
eSpawner.convert(EpicSpawners.getInstance().getApi().getIType(clicked), p);
}
}
} else if (EpicSpawners.getInstance().spawnerLoc.containsKey(e.getWhoClicked())) {
e.setCancelled(true);
Spawner eSpawner = new Spawner(EpicSpawners.getInstance().spawnerLoc.get(p));
if (EpicSpawners.getInstance().spawnerFile.getConfig().getBoolean("Entities." + eSpawner.spawnedType + ".Upgradable")) {
if (e.getSlot() == 11) {
if (EpicSpawners.getInstance().getConfig().getBoolean("Main.Upgrade With XP")) {
if (!e.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
eSpawner.upgrade(p, "XP");
}
p.closeInventory();
}
} else if (e.getSlot() == 8) {
int page = 2;
if (EpicSpawners.getInstance().infPage.containsKey(p))
page = EpicSpawners.getInstance().infPage.get(p) + 1;
EpicSpawners.getInstance().infPage.put(p, page);
eSpawner.overView(p, page);
} else if (e.getSlot() == 13) {
if (e.getClick().isRightClick()) {
if (eSpawner.getBoost() == 0) {
eSpawner.playerBoost(p);
}
} else if (e.getClick().isLeftClick()) {
boolean omni = false;
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawnerstats." + eSpawner.locationStr + ".type")) {
if (EpicSpawners.getInstance().dataFile.getConfig().getString("data.spawnerstats." + eSpawner.locationStr + ".type").equals("OMNI")) {
List<SpawnerItem> list = EpicSpawners.getInstance().getApi().convertFromList(EpicSpawners.getInstance().dataFile.getConfig().getStringList("data.spawnerstats." + eSpawner.locationStr + ".entities"));
omni = true;
}
}
if (p.hasPermission("epicspawners.convert") && !omni) {
eSpawner.change(p, 1);
}
}
} else if (e.getSlot() == 15) {
if (EpicSpawners.getInstance().getConfig().getBoolean("Main.Upgrade With Economy")) {
if (!e.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
eSpawner.upgrade(p, "ECO");
p.closeInventory();
}
}
}
}
} else if (EpicSpawners.getInstance().editing.containsKey(p)) {
if (!EpicSpawners.getInstance().subediting.containsKey(p)) {
e.setCancelled(true);
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("general.nametag.back")))
EpicSpawners.getInstance().editor.open(p, EpicSpawners.getInstance().page.get(p));
else if (e.getSlot() == 11) {
if (!e.getClick().isLeftClick() && !e.getClick().isRightClick()) {
String name = EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p));
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(name) + ".Display-Item", p.getItemInHand().getType().toString());
p.sendMessage(Arconix.pl().getApi().format().formatText(EpicSpawners.getInstance().references.getPrefix() + "&7Display Item for &6" + name + " &7set to &6" + p.getItemInHand().getType().toString() + "&7."));
EpicSpawners.getInstance().editor.overview(p, EpicSpawners.getInstance().editing.get(p));
} else if (e.getClick().isLeftClick()) {
EpicSpawners.getInstance().editor.editSpawnerName(p);
}
} else if (e.getSlot() == 25)
EpicSpawners.getInstance().editor.editor(p, "Entity");
else if (e.getSlot() == 33)
EpicSpawners.getInstance().editor.editor(p, "Block");
else if (e.getSlot() == 28) {
boolean right = e.isRightClick();
for (final EntityType val : EntityType.values()) {
if (val.isSpawnable() && val.isAlive()) {
if (val.name().equals(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p)))) {
right = false;
}
}
}
if (!right) {
if (EpicSpawners.getInstance().spawnerFile.getConfig().getBoolean("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p))) + ".Allowed"))
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p))) + ".Allowed", false);
else
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p))) + ".Allowed", true);
EpicSpawners.getInstance().editor.overview(p, EpicSpawners.getInstance().editing.get(p));
} else {
EpicSpawners.getInstance().editor.destroy(p);
}
} else if (e.getSlot() == 23) {
EpicSpawners.getInstance().editor.basicSettings(p);
} else if (e.getSlot() == 30) {
EpicSpawners.getInstance().editor.save(p);
EpicSpawners.getInstance().editor.overview(p, EpicSpawners.getInstance().editing.get(p));
} else if (e.getSlot() == 41)
EpicSpawners.getInstance().editor.editor(p, "Item");
else if (e.getSlot() == 43)
EpicSpawners.getInstance().editor.editor(p, "Command");
} else {
if (EpicSpawners.getInstance().subediting.get(p).equals("basic")) {
if (e.getInventory().equals(p.getOpenInventory().getTopInventory())) {
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("general.nametag.back")))
EpicSpawners.getInstance().editor.overview(p, EpicSpawners.getInstance().editing.get(p));
else if (e.getSlot() == 13) {
if (EpicSpawners.getInstance().spawnerFile.getConfig().getBoolean("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p))) + ".Upgradable"))
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p))) + ".Upgradable", false);
else
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p))) + ".Upgradable", true);
EpicSpawners.getInstance().editor.basicSettings(p);
} else if (e.getSlot() == 19) {
EpicSpawners.getInstance().editor.alterSetting(p, "Shop-Price");
} else if (e.getSlot() == 20) {
if (EpicSpawners.getInstance().spawnerFile.getConfig().getBoolean("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p))) + ".In-Shop"))
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p))) + ".In-Shop", false);
else
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p))) + ".In-Shop", true);
EpicSpawners.getInstance().editor.basicSettings(p);
} else if (e.getSlot() == 22) {
if (EpicSpawners.getInstance().spawnerFile.getConfig().getBoolean("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p))) + ".Spawn-On-Fire"))
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p))) + ".Spawn-On-Fire", false);
else
EpicSpawners.getInstance().spawnerFile.getConfig().set("Entities." + Methods.getTypeFromString(EpicSpawners.getInstance().editor.getType(EpicSpawners.getInstance().editing.get(p))) + ".Spawn-On-Fire", true);
EpicSpawners.getInstance().editor.basicSettings(p);
} else if (e.getSlot() == 24) {
EpicSpawners.getInstance().editor.alterSetting(p, "Custom-ECO-Cost");
} else if (e.getSlot() == 25) {
EpicSpawners.getInstance().editor.alterSetting(p, "Custom-XP-Cost");
} else if (e.getSlot() == 30) {
EpicSpawners.getInstance().editor.alterSetting(p, "CustomGoal");
} else if (e.getSlot() == 32) {
EpicSpawners.getInstance().editor.alterSetting(p, "Pickup-cost");
}
e.setCancelled(true);
}
} else {
if (e.getInventory().equals(p.getOpenInventory().getTopInventory())) {
if ((e.getSlot() < 10 || e.getSlot() > 25) || e.getSlot() == 17 || e.getSlot() == 18) {
e.setCancelled(true);
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("general.nametag.back")))
EpicSpawners.getInstance().editor.overview(p, EpicSpawners.getInstance().editing.get(p));
else if (e.getCurrentItem().getItemMeta().getDisplayName().equals(Arconix.pl().getApi().format().formatText("&6Add Command")))
EpicSpawners.getInstance().editor.createCommand(p);
else if (e.getCurrentItem().getItemMeta().getDisplayName().equals(Arconix.pl().getApi().format().formatText("&6Add Entity")))
EpicSpawners.getInstance().editor.addEntityInit(p);
else if (e.getCurrentItem().getItemMeta().getDisplayName().equals(Arconix.pl().getApi().format().formatText("&aSave")))
EpicSpawners.getInstance().editor.saveInstance(p, EpicSpawners.getInstance().editor.getItems(p));
else if (e.getSlot() == 40)
EpicSpawners.getInstance().editor.editChatInit(p);
else if (e.getSlot() == 49)
EpicSpawners.getInstance().editor.editSpawnLimit(p);
}
}
}
}
} else if (e.getInventory().getTitle().equals("Spawner Editor")) {
e.setCancelled(true);
int page = EpicSpawners.getInstance().page.get(p);
if (e.getSlot() == 8) {
p.closeInventory();
} else if ((e.getCurrentItem().getType().equals(Material.SKULL_ITEM) || e.getCurrentItem().getType().equals(Material.MOB_SPAWNER)) &&
!e.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("general.nametag.next")) &&
!e.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("general.nametag.back"))) {
String idd = e.getCurrentItem().getItemMeta().getLore().get(1);
idd = idd.replace("§", "");
int id = Integer.parseInt(idd);
//if (e.getClick().isLeftClick())
EpicSpawners.getInstance().editor.overview(p, id);
} else if (e.getCurrentItem().getItemMeta().getDisplayName().equals(Arconix.pl().getApi().format().formatText("&9&lNew Spawner"))) {
EpicSpawners.getInstance().editor.overview(p, 0);
EpicSpawners.getInstance().editor.save(p);
EpicSpawners.getInstance().editor.open(p, 1);
} else if (e.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("general.nametag.back"))) {
if (page != 1) {
EpicSpawners.getInstance().editor.open(p, page - 1);
}
} else if (e.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("general.nametag.back"))) {
EpicSpawners.getInstance().editor.open(p, page + 1);
}
} else if (e.getInventory().getTitle().equals(instance.getLocale().getMessage("interface.spawnerstats.title"))) {
e.setCancelled(true);
if (e.getSlot() == 8) {
p.closeInventory();
}
} else if (e.getInventory().getTitle().equals(instance.getLocale().getMessage("interface.shop.title"))) {
e.setCancelled(true);
ItemStack clicked = e.getCurrentItem();
int page = EpicSpawners.getInstance().page.get(p);
if (e.getInventory().getType() == InventoryType.CHEST) {
if (e.getSlot() == 8) {
p.closeInventory();
} else if (e.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("general.nametag.back"))) {
if (page != 1) {
EpicSpawners.getInstance().shop.open(p, page - 1);
}
} else if (e.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("general.nametag.next"))) {
EpicSpawners.getInstance().shop.open(p, page + 1);
} else if (e.getSlot() >= 10 && e.getSlot() <= (e.getInventory().getSize() - 10) && e.getSlot() != 17 && e.getSlot() != (e.getInventory().getSize() - 18))
EpicSpawners.getInstance().shop.show(EpicSpawners.getInstance().getApi().getIType(clicked), 1, p);
}
}
if (e.getSlot() != 64537) {
if (e.getInventory().getType() == InventoryType.ANVIL) {
if (e.getAction() != InventoryAction.NOTHING) {
if (e.getCurrentItem().getType() != Material.AIR) {
ItemStack item = e.getCurrentItem();
if (item.getType() == Material.MOB_SPAWNER) {
e.setCancelled(true);
}
}
}
}
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onClose(InventoryCloseEvent event) {
try {
final Player p = (Player) event.getPlayer();
if (EpicSpawners.getInstance().boosting.contains(p) || EpicSpawners.getInstance().inShow.containsKey(p) || EpicSpawners.getInstance().spawnerLoc.containsKey(p)) {
EpicSpawners.getInstance().boosting.remove(p);
EpicSpawners.getInstance().inShow.remove(p);
EpicSpawners.getInstance().spawnerLoc.remove(p);
Bukkit.getScheduler().runTaskLater(EpicSpawners.getInstance(), () -> {
if (!p.getOpenInventory().getTopInventory().getType().equals(InventoryType.CHEST))
p.closeInventory();
}, 1L);
}
if (!p.getOpenInventory().getTopInventory().getTitle().contains("Editing"))
EpicSpawners.getInstance().editing.remove(p);
} catch (Exception e) {
Debugger.runReport(e);
}
}
}

View File

@ -0,0 +1,339 @@
package com.songoda.epicspawners.listeners;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.spawners.Spawner;
import com.songoda.epicspawners.spawners.SpawnerItem;
import com.songoda.epicspawners.utils.Debugger;
import com.songoda.epicspawners.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.event.entity.SpawnerSpawnEvent;
import org.bukkit.metadata.FixedMetadataValue;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Consumer;
/**
* Created by songoda on 2/25/2017.
*/
public class SpawnerListeners implements Listener {
@SuppressWarnings("unchecked")
@EventHandler
public void onSpawn(SpawnerSpawnEvent e) {
try {
String type = e.getEntityType().name();
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(e.getSpawner().getBlock()) + ".type")) {
if (!EpicSpawners.getInstance().dataFile.getConfig().getString("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(e.getSpawner().getBlock()) + ".type").equals("OMNI"))
type = EpicSpawners.getInstance().dataFile.getConfig().getString("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(e.getSpawner().getBlock()) + ".type");
}
if (e.getEntityType() == EntityType.FALLING_BLOCK)
return;
String sloc = Arconix.pl().getApi().serialize().serializeLocation(e.getSpawner().getBlock());
Spawner eSpawner = new Spawner(e.getSpawner().getBlock());
if (EpicSpawners.getInstance().dataFile.getConfig().getInt("data.spawner." + sloc) != 0) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(EpicSpawners.getInstance(), eSpawner::updateDelay, 10L);
}
if ((!e.getEntityType().equals(EntityType.IRON_GOLEM) && !e.getEntityType().equals(EntityType.GHAST) || !EpicSpawners.getInstance().getConfig().getBoolean("Entity.Use Default Minecraft Spawn Method For Large Entities")) && !e.isCancelled() && e.getLocation() != null) {
e.getEntity().remove();
if (EpicSpawners.getInstance().getConfig().getBoolean("Spawner Drops.Allow Killing Mobs To Drop Spawners")) {
EpicSpawners.getInstance().dataFile.getConfig().set("data.Entities." + e.getEntity().getUniqueId(), true);
}
if (Methods.countEntitiesAroundLoation(e.getSpawner().getLocation()) < EpicSpawners.getInstance().getConfig().getInt("Main.Max Entities Around Single Spawner")) {
long lastSpawn = 1001;
if (EpicSpawners.getInstance().lastSpawn.containsKey(e.getSpawner().getLocation())) {
lastSpawn = (new Date()).getTime() - EpicSpawners.getInstance().lastSpawn.get(e.getSpawner().getLocation()).getTime();
}
if (lastSpawn >= 1000) {
if (EpicSpawners.getInstance().dataFile.getConfig().contains("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(e.getSpawner().getLocation()) + ".type")
&& EpicSpawners.getInstance().dataFile.getConfig().getString("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(e.getSpawner().getLocation()) + ".type").equals("OMNI")) {
List<SpawnerItem> list = EpicSpawners.getInstance().getApi().convertFromList(EpicSpawners.getInstance().dataFile.getConfig().getStringList("data.spawnerstats." + Arconix.pl().getApi().serialize().serializeLocation(e.getSpawner().getLocation()) + ".entities"));
for (SpawnerItem ent : list) {
if (ent.getType().equals(e.getSpawner().getSpawnedType())) continue;
int high = eSpawner.getMulti();
int low = eSpawner.getMulti();
if (ent.getMulti() > eSpawner.getMulti()) {
high = ent.getMulti();
} else {
low = ent.getMulti();
}
String[] randomLowHigh = EpicSpawners.getInstance().getConfig().getString("Main.Random Amount Added To Each Spawn").split(":");
int rand = ThreadLocalRandom.current().nextInt(Integer.valueOf(randomLowHigh[0]), Integer.valueOf(randomLowHigh[1]));
int times = high - low + rand + eSpawner.getBoost();
for (String entt : (ArrayList<String>) EpicSpawners.getInstance().spawnerFile.getConfig().getList("Entities." + Methods.getTypeFromString(ent.getType()) + ".entities")) {
spawnEntity(e.getSpawner().getLocation(), EntityType.valueOf(entt), times);
}
}
}
String[] randomLowHigh = EpicSpawners.getInstance().getConfig().getString("Main.Random Amount Added To Each Spawn").split(":");
int rand = ThreadLocalRandom.current().nextInt(Integer.valueOf(randomLowHigh[0]), Integer.valueOf(randomLowHigh[1]));
String equation = EpicSpawners.getInstance().getConfig().getString("Main.Equations.Mobs Spawned Per Spawn");
equation = equation.replace("{RAND}", rand + "");
equation = equation.replace("{MULTI}", eSpawner.getMulti() + "");
int times;
if (!EpicSpawners.getInstance().cache.containsKey(equation)) {
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
times = (int) Math.round(Double.parseDouble(engine.eval(equation).toString()));
EpicSpawners.getInstance().cache.put(equation, times);
} else {
times = EpicSpawners.getInstance().cache.get(equation);
}
int size = EpicSpawners.getInstance().spawnerFile.getConfig().getList("Entities." + Methods.getTypeFromString(type) + ".entities", new ArrayList<>()).size();
if (size == 0)
size = 1;
times = (int) Math.ceil((times + eSpawner.getBoost()) / size);
if (EpicSpawners.getInstance().spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(type) + ".entities")) {
for (String ent : (ArrayList<String>) EpicSpawners.getInstance().spawnerFile.getConfig().getList("Entities." + Methods.getTypeFromString(type) + ".entities")) {
spawnEntity(e.getSpawner().getLocation(), EntityType.valueOf(ent), times);
}
}
EpicSpawners.getInstance().lastSpawn.put(e.getSpawner().getLocation(), new Date());
}
}
return;
}
int spawnAmt = 1;
if (EpicSpawners.getInstance().dataFile.getConfig().getInt("data.spawnerstats." + sloc + ".spawns") != 0) {
spawnAmt = EpicSpawners.getInstance().dataFile.getConfig().getInt("data.spawnerstats." + sloc + ".spawns") + 1;
}
EpicSpawners.getInstance().dataFile.getConfig().set("data.spawnerstats." + sloc + ".spawns", spawnAmt);
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
public void spawnEntity(Location location, EntityType type, int times) {
try {
Block b = location.getBlock();
if (b.isBlockPowered() && EpicSpawners.getInstance().getConfig().getBoolean("Main.Redstone Power Deactivates Spawners"))
return;
String sloc = Arconix.pl().getApi().serialize().serializeLocation(location);
int spawnAmt = 1;
if (EpicSpawners.getInstance().dataFile.getConfig().getInt("data.spawnerstats." + sloc + ".spawns") != 0) {
spawnAmt = EpicSpawners.getInstance().dataFile.getConfig().getInt("data.spawnerstats." + sloc + ".spawns") + 1;
}
int stack = 0;
if (EpicSpawners.getInstance().getServer().getPluginManager().getPlugin("StackMob") != null) {
stack = times;
times = 1;
}
int num = 0;
while (num != times) {
Location spot = null;
boolean in = false;
int amt = 0;
while (!in && amt <= 25) {
double testX = ThreadLocalRandom.current().nextDouble(-1, 1);
double testY = ThreadLocalRandom.current().nextDouble(-1, 2);
double testZ = ThreadLocalRandom.current().nextDouble(-1, 1);
double x = location.getX() + testX * (double) 3;
double y = location.getY() + testY;
double z = location.getZ() + testZ * (double) 3;
spot = new Location(location.getWorld(), x, y, z);
if (canSpawn(type, spot))
in = true;
amt++;
}
if (in) {
if (spot != null) {
float x = (float) (0 + (Math.random() * 1));
float y = (float) (0 + (Math.random() * 2));
float z = (float) (0 + (Math.random() * 1));
Arconix.pl().getApi().packetLibrary.getParticleManager().broadcastParticle(spot, x, y, z, 0, EpicSpawners.getInstance().getConfig().getString("Entity.Spawn Particle Effect"), 5);
Location loc = spot.clone();
loc.subtract(0, 1, 0);
if (type.equals(EntityType.IRON_GOLEM)) {
spot.add(.5, .5, .5);
} else {
spot = spot.clone().getBlock().getLocation();
double spawnX = ThreadLocalRandom.current().nextDouble(0.4, 0.6);
double spawnZ = ThreadLocalRandom.current().nextDouble(0.4, 0.6);
spot.add(spawnX, .5, spawnZ);
}
spawnMob(location, spot, type, CreatureSpawnEvent.SpawnReason.SPAWNER, stack);
}
}
spawnAmt++;
num++;
}
EpicSpawners.getInstance().dataFile.getConfig().set("data.spawnerstats." + sloc + ".spawns", spawnAmt);
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
private static Method spawnMethod = null;
private static Method methodGetHandle = null;
private static Method methodK = null;
public Entity spawnMob(Location spawnerLoc, Location loc, EntityType type, CreatureSpawnEvent.SpawnReason reason, int stack) {
try {
World world = loc.getWorld();
Class<? extends Entity> clazz = type.getEntityClass();
Entity e;
if (EpicSpawners.getInstance().v1_12 || EpicSpawners.getInstance().v1_11) {
if (spawnMethod == null)
spawnMethod = world.getClass().getMethod("spawn", Location.class, Class.class, Consumer.class, CreatureSpawnEvent.SpawnReason.class);
e = (Entity) spawnMethod.invoke(world, loc, clazz, null, reason);
} else {
if (spawnMethod == null)
spawnMethod = world.getClass().getMethod("spawn", Location.class, Class.class, CreatureSpawnEvent.SpawnReason.class);
e = (Entity) spawnMethod.invoke(world, loc, clazz, reason);
}
Spawner spawner = new Spawner(spawnerLoc);
if (spawner.isSpawningOnFire())
e.setFireTicks(160);
Bukkit.getScheduler().runTaskLater(EpicSpawners.getInstance(), () -> {
try {
if (!spawner.isSpawningWithAI() && !EpicSpawners.getInstance().v1_7) {
if (EpicSpawners.getInstance().v1_8) {
Class<?> claz = e.getClass();
if (methodGetHandle == null)
methodGetHandle = claz.getDeclaredMethod("getHandle");
Object nmsEntity = methodGetHandle.invoke(e);
if (methodK == null)
methodK = nmsEntity.getClass().getMethod("k", Boolean.TYPE);
methodK.invoke(nmsEntity, true);
} else {
((LivingEntity) e).setAI(false);
}
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
}, EpicSpawners.getInstance().getConfig().getLong("Main.Ticks Until AI Disabled"));
if (EpicSpawners.getInstance().getServer().getPluginManager().getPlugin("StackMob") != null && stack != 0) {
uk.antiperson.stackmob.StackMob sm = ((uk.antiperson.stackmob.StackMob) Bukkit.getPluginManager().getPlugin("StackMob"));
if (!sm.config.getCustomConfig().getStringList("no-stack-types").contains(e.getType().toString())) {
e.setMetadata(uk.antiperson.stackmob.tools.extras.GlobalValues.METATAG, new FixedMetadataValue(sm, stack));
e.setMetadata(uk.antiperson.stackmob.tools.extras.GlobalValues.NO_SPAWN_STACK, new FixedMetadataValue(sm, true));
}
}
if (EpicSpawners.getInstance().getConfig().getBoolean("Spawner Drops.Allow Killing Mobs To Drop Spawners")) {
EpicSpawners.getInstance().dataFile.getConfig().set("data.Entities." + e.getUniqueId(), true);
}
return e;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public boolean canSpawn(EntityType type, Location location) {
boolean canSpawn = true;
try {
String spawnBlocks = EpicSpawners.getInstance().spawnerFile.getConfig().getString("Entities." + Methods.getTypeFromString(Methods.getType(type)) + ".Spawn-Block");
List<String> blocks = Arrays.asList(spawnBlocks.split("\\s*,\\s*"));
if (!Methods.isAir(location.getBlock().getType()) && (!isWater(location.getBlock().getType()) && !blocks.contains("WATER"))) {
canSpawn = false;
}
boolean canSpawnUnder = false;
if (canSpawn != false) {
for (String block : blocks) {
Location loc = location.clone().subtract(0, 1, 0);
if (loc.getBlock().getType().toString().equalsIgnoreCase(block) || isWater(loc.getBlock().getType()) && blocks.contains("WATER")) {
canSpawnUnder = true;
}
}
canSpawn = canSpawnUnder;
}
} catch (Exception e) {
Debugger.runReport(e);
}
return canSpawn;
}
public boolean isWater(Material type) {
try {
if (type == Material.WATER || type == Material.STATIONARY_WATER) {
return true;
}
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onTarget(EntityTargetLivingEntityEvent event) {
try {
if (EpicSpawners.getInstance().getConfig().getBoolean("Entity.Hostile Mobs Attack Second")) {
if (event.getEntity().getLastDamageCause() != null) {
if (event.getEntity().getLastDamageCause().getCause().name().equals("ENTITY_ATTACK")) {
return;
}
}
event.setCancelled(true);
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
}

View File

@ -0,0 +1,59 @@
package com.songoda.epicspawners.listeners;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import org.bukkit.Rotation;
import org.bukkit.entity.ItemFrame;
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.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
/**
* Created by songoda on 3/13/2017.
*/
public class TestListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerEntityInteract(PlayerInteractAtEntityEvent e) {
try {
if (e.getRightClicked() instanceof ItemFrame) {
if (EpicSpawners.getInstance().dataFile.getConfig().getString("data.entityshop") != null) {
String uuid = e.getRightClicked().getUniqueId().toString();
if (EpicSpawners.getInstance().dataFile.getConfig().getString("data.entityshop." + uuid) != null) {
((ItemFrame) e.getRightClicked()).setRotation(Rotation.CLOCKWISE_45);
EpicSpawners.getInstance().shop.show(EpicSpawners.getInstance().dataFile.getConfig().getString("data.entityshop." + uuid).toUpperCase(), 1, e.getPlayer());
}
}
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
try {
Player p = e.getPlayer();
if (p.isOp() && EpicSpawners.getInstance().getConfig().getBoolean("Main.Display Helpful Tips For Operators")) {
if (EpicSpawners.getInstance().getServer().getPluginManager().getPlugin("Factions") != null && EpicSpawners.getInstance().hooks.FactionsHook == null) {
p.sendMessage("");
p.sendMessage(Arconix.pl().getApi().format().formatText(EpicSpawners.getInstance().references.getPrefix() + "&7Here's the deal,"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7I cannot give you full support for Factions out of the box."));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7Things will work without it but if you wan't a flawless"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7experience you need to download"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7&6https://www.spigotmc.org/resources/54337/&7."));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7If you don't care and don't want to see this message again"));
p.sendMessage(Arconix.pl().getApi().format().formatText("&7turn &6Helpful-Tips &7off in the config."));
p.sendMessage("");
}
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
}

View File

@ -0,0 +1,343 @@
package com.songoda.epicspawners.spawners;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import com.songoda.epicspawners.utils.Debugger;
import com.songoda.epicspawners.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
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;
/**
* Created by songoda on 3/10/2017.
*/
public class Shop {
private EpicSpawners instance;
public Shop(EpicSpawners instance) {
this.instance = instance;
}
public void open(Player p, int page) {
try {
EpicSpawners.getInstance().page.put(p, page);
List<String> entities = new ArrayList<>();
int num = 0;
int show = 0;
int start = (page - 1) * 32;
ConfigurationSection cs = EpicSpawners.getInstance().spawnerFile.getConfig().getConfigurationSection("Entities");
for (String value : cs.getKeys(false)) {
if (!value.toLowerCase().equals("omni")
&& EpicSpawners.getInstance().spawnerFile.getConfig().getBoolean("Entities." + Methods.getTypeFromString(value) + ".In-Shop")
&& (p.hasPermission("epicspawners.*") || p.hasPermission("epicspawners.shop.*")
|| p.hasPermission("epicspawners.shop." + Methods.getTypeFromString(value).replaceAll(" ", "_")))) {
if (num >= start && show <= 32) {
entities.add(value);
show++;
}
}
num++;
}
int amt = entities.size();
String title = Arconix.pl().getApi().format().formatTitle(instance.getLocale().getMessage("interface.shop.title"));
Inventory i = Bukkit.createInventory(null, 54, title);
int max2 = 54;
if (amt <= 7) {
i = Bukkit.createInventory(null, 27, title);
max2 = 27;
} else if (amt <= 15) {
i = Bukkit.createInventory(null, 36, title);
max2 = 36;
} else if (amt <= 25) {
i = Bukkit.createInventory(null, 45, title);
max2 = 45;
}
final int max22 = max2;
int place = 10;
for (String value : entities) {
if (place == 17)
place++;
if (place == (max22 - 18))
place++;
ItemStack it = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
ItemStack item = EpicSpawners.getInstance().heads.addTexture(it, Methods.getTypeFromString(value));
if (EpicSpawners.getInstance().spawnerFile.getConfig().getString("Entities." + Methods.getTypeFromString(value) + ".Display-Item") != null) {
Material mat = Material.valueOf(EpicSpawners.getInstance().spawnerFile.getConfig().getString("Entities." + Methods.getTypeFromString(value) + ".Display-Item"));
if (!mat.equals(Material.AIR))
item = new ItemStack(mat, 1);
}
ItemMeta itemmeta = item.getItemMeta();
String name = Methods.compileName(value, 0, true);
ArrayList<String> lore = new ArrayList<>();
double price = EpicSpawners.getInstance().spawnerFile.getConfig().getDouble("Entities." + Methods.getTypeFromString(value) + ".Shop-Price");
lore.add(Arconix.pl().getApi().format().formatText(instance.getLocale().getMessage("interface.shop.buyprice", Arconix.pl().getApi().format().formatEconomy(price))));
String loreString = instance.getLocale().getMessage("interface.shop.lore", Methods.getTypeFromString(Methods.getTypeFromString(value)));
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
loreString = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(p, loreString.replace(" ", "_")).replace("_", " ");
}
lore.add(loreString);
itemmeta.setLore(lore);
itemmeta.setDisplayName(name);
item.setItemMeta(itemmeta);
i.setItem(place, item);
place++;
}
int max = (int) Math.ceil((double) num / (double) 36);
num = 0;
while (num != 9) {
i.setItem(num, Methods.getGlass());
num++;
}
int num2 = max2 - 9;
while (num2 != max2) {
i.setItem(num2, Methods.getGlass());
num2++;
}
ItemStack exit = new ItemStack(Material.valueOf(EpicSpawners.getInstance().getConfig().getString("Interfaces.Exit Icon")), 1);
ItemMeta exitmeta = exit.getItemMeta();
exitmeta.setDisplayName(instance.getLocale().getMessage("general.nametag.exit"));
exit.setItemMeta(exitmeta);
ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
ItemStack skull = head;
if (!EpicSpawners.getInstance().v1_7)
skull = Arconix.pl().getApi().getGUI().addTexture(head, "http://textures.minecraft.net/texture/1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
if (EpicSpawners.getInstance().v1_7)
skullMeta.setOwner("MHF_ArrowRight");
skull.setDurability((short) 3);
skullMeta.setDisplayName(instance.getLocale().getMessage("general.nametag.next"));
skull.setItemMeta(skullMeta);
ItemStack head2 = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
ItemStack skull2 = head2;
if (!EpicSpawners.getInstance().v1_7)
skull2 = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta();
if (EpicSpawners.getInstance().v1_7)
skull2Meta.setOwner("MHF_ArrowLeft");
skull2.setDurability((short) 3);
skull2Meta.setDisplayName(instance.getLocale().getMessage("general.nametag.back"));
skull2.setItemMeta(skull2Meta);
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(max22 - 18, Methods.getBackgroundGlass(true));
i.setItem(max22 - 9, Methods.getBackgroundGlass(true));
i.setItem(max22 - 8, Methods.getBackgroundGlass(true));
i.setItem(max22 - 10, Methods.getBackgroundGlass(true));
i.setItem(max22 - 2, Methods.getBackgroundGlass(true));
i.setItem(max22 - 1, Methods.getBackgroundGlass(true));
i.setItem(2, Methods.getBackgroundGlass(false));
i.setItem(6, Methods.getBackgroundGlass(false));
i.setItem(max22 - 7, Methods.getBackgroundGlass(false));
i.setItem(max22 - 3, Methods.getBackgroundGlass(false));
if (page != 1) {
i.setItem(max22 - 8, skull2);
}
if (page != max) {
i.setItem(max22 - 2, skull);
}
p.openInventory(i);
} catch (Exception e) {
Debugger.runReport(e);
}
}
public void show(String type, int amt, Player p) {
try {
Inventory i = Bukkit.createInventory(null, 45, Arconix.pl().getApi().format().formatTitle(instance.getLocale().getMessage("interface.shop.spawnershowtitle", Methods.compileName(type, 1, false))));
int num = 0;
while (num != 9) {
i.setItem(num, Methods.getGlass());
num++;
}
num = 36;
while (num != 45) {
i.setItem(num, Methods.getGlass());
num++;
}
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(27, Methods.getBackgroundGlass(true));
i.setItem(36, Methods.getBackgroundGlass(true));
i.setItem(37, Methods.getBackgroundGlass(true));
i.setItem(35, Methods.getBackgroundGlass(true));
i.setItem(43, Methods.getBackgroundGlass(true));
i.setItem(44, Methods.getBackgroundGlass(true));
i.setItem(2, Methods.getBackgroundGlass(false));
i.setItem(6, Methods.getBackgroundGlass(false));
i.setItem(38, Methods.getBackgroundGlass(false));
i.setItem(42, Methods.getBackgroundGlass(false));
double price = EpicSpawners.getInstance().spawnerFile.getConfig().getDouble("Entities." + Methods.getTypeFromString(type) + ".Shop-Price") * amt;
ItemStack it = new ItemStack(Material.SKULL_ITEM, amt, (byte) 3);
ItemStack item = EpicSpawners.getInstance().heads.addTexture(it, Methods.getTypeFromString(type));
if (EpicSpawners.getInstance().spawnerFile.getConfig().getString("Entities." + Methods.getTypeFromString(type) + ".Display-Item") != null) {
Material mat = Material.valueOf(EpicSpawners.getInstance().spawnerFile.getConfig().getString("Entities." + Methods.getTypeFromString(type) + ".Display-Item"));
if (!mat.equals(Material.AIR))
item = new ItemStack(mat, 1);
}
item.setAmount(amt);
ItemMeta itemmeta = item.getItemMeta();
String name = Methods.compileName(type, 0, false);
itemmeta.setDisplayName(name);
ArrayList<String> lore = new ArrayList<>();
lore.add(instance.getLocale().getMessage("interface.shop.buyprice", Arconix.pl().getApi().format().formatEconomy(price)));
itemmeta.setLore(lore);
item.setItemMeta(itemmeta);
i.setItem(22, item);
ItemStack plus = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5);
ItemMeta plusmeta = plus.getItemMeta();
plusmeta.setDisplayName(instance.getLocale().getMessage("interface.shop.add1"));
plus.setItemMeta(plusmeta);
if (item.getAmount() + 1 <= 64) {
i.setItem(15, plus);
}
plus = new ItemStack(Material.STAINED_GLASS_PANE, 10, (short) 5);
plusmeta.setDisplayName(instance.getLocale().getMessage("interface.shop.add10"));
plus.setItemMeta(plusmeta);
if (item.getAmount() + 10 <= 64) {
i.setItem(33, plus);
}
plus = new ItemStack(Material.STAINED_GLASS_PANE, 64, (short) 5);
plusmeta.setDisplayName(instance.getLocale().getMessage("interface.shop.set64"));
plus.setItemMeta(plusmeta);
if (item.getAmount() != 64) {
i.setItem(25, plus);
}
ItemStack minus = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14);
ItemMeta minusmeta = minus.getItemMeta();
minusmeta.setDisplayName(instance.getLocale().getMessage("interface.shop.remove1"));
minus.setItemMeta(minusmeta);
if (item.getAmount() != 1) {
i.setItem(11, minus);
}
minus = new ItemStack(Material.STAINED_GLASS_PANE, 10, (short) 14);
minusmeta.setDisplayName(instance.getLocale().getMessage("interface.shop.remove10"));
minus.setItemMeta(minusmeta);
if (item.getAmount() - 10 >= 0) {
i.setItem(29, minus);
}
minus = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14);
minusmeta.setDisplayName(instance.getLocale().getMessage("interface.shop.set1"));
minus.setItemMeta(minusmeta);
if (item.getAmount() != 1) {
i.setItem(19, minus);
}
ItemStack exit = new ItemStack(Material.valueOf(EpicSpawners.getInstance().getConfig().getString("Interfaces.Exit Icon")), 1);
ItemMeta exitmeta = exit.getItemMeta();
exitmeta.setDisplayName(instance.getLocale().getMessage("general.nametag.exit"));
exit.setItemMeta(exitmeta);
i.setItem(8, exit);
ItemStack head2 = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
ItemStack skull2 = head2;
if (!EpicSpawners.getInstance().v1_7)
skull2 = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta();
if (EpicSpawners.getInstance().v1_7)
skull2Meta.setOwner("MHF_ArrowLeft");
skull2.setDurability((short) 3);
skull2Meta.setDisplayName(instance.getLocale().getMessage("general.nametag.back"));
skull2.setItemMeta(skull2Meta);
i.setItem(0, skull2);
ItemStack buy = new ItemStack(Material.valueOf(EpicSpawners.getInstance().getConfig().getString("Interfaces.Buy Icon")), 1);
ItemMeta buymeta = buy.getItemMeta();
buymeta.setDisplayName(instance.getLocale().getMessage("general.nametag.confirm"));
buy.setItemMeta(buymeta);
i.setItem(40, buy);
p.openInventory(i);
EpicSpawners.getInstance().inShow.put(p, type);
} catch (Exception e) {
Debugger.runReport(e);
}
}
public void confirm(Player p, int amt) {
try {
String type = EpicSpawners.getInstance().inShow.get(p);
if (EpicSpawners.getInstance().getServer().getPluginManager().getPlugin("Vault") == null) {
p.sendMessage("Vault is not installed.");
return;
}
RegisteredServiceProvider<net.milkbowl.vault.economy.Economy> rsp = EpicSpawners.getInstance().getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
double price = EpicSpawners.getInstance().spawnerFile.getConfig().getDouble("Entities." + Methods.getTypeFromString(type) + ".Shop-Price") * amt;
if (!p.isOp() && !econ.has(p, price)) {
p.sendMessage(EpicSpawners.getInstance().references.getPrefix() + instance.getLocale().getMessage("event.shop.cannotafford"));
return;
}
ItemStack item = EpicSpawners.getInstance().getApi().newSpawnerItem(type, amt);
p.getInventory().addItem(item);
p.sendMessage(EpicSpawners.getInstance().references.getPrefix() + instance.getLocale().getMessage("event.shop.purchasesuccess"));
if (!p.isOp()) {
econ.withdrawPlayer(p, price);
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,66 @@
package com.songoda.epicspawners.spawners;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Created by songoda on 4/22/2017.
*/
public class SpawnerBreakEvent extends Event implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList();
private Location location;
private Player player;
private int multi;
private String type;
private boolean canceled = false;
public SpawnerBreakEvent(Location location, Player player) {
Spawner spawner = new Spawner(location);
this.location = location;
this.player = player;
this.multi = spawner.getMulti();
if (spawner.getSpawner() == null)
this.type = null;
else
this.type = spawner.spawnedType;
}
public Location getLocation() {
return location;
}
public Player getPlayer() {
return player;
}
public int getMulti() {
return multi;
}
public String getType() {
return type;
}
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
@Override
public boolean isCancelled() {
return canceled;
}
@Override
public void setCancelled(boolean canceled) {
this.canceled = canceled;
}
}

View File

@ -0,0 +1,82 @@
package com.songoda.epicspawners.spawners;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Created by songoda on 4/22/2017.
*/
public class SpawnerChangeEvent extends Event implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList();
private Location location;
private Player player;
private int multi;
private int oldMulti;
private String type;
private String oldType;
private boolean canceled = false;
public SpawnerChangeEvent(Location location, Player player, int multi, int oldMulti) {
this.location = location;
this.player = player;
this.multi = multi;
this.oldMulti = oldMulti;
}
public SpawnerChangeEvent(Location location, Player player, String type, String oldType) {
this.location = location;
this.player = player;
this.type = type;
this.oldType = oldType;
}
public Block getSpawner() {
return location.getBlock();
}
public int getCurrentMulti() {
return multi;
}
public int getOldMulti() {
return oldMulti;
}
public String getType() {
return type;
}
public String getOldType() {
return oldType;
}
public Player getPlayer() {
return player;
}
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
@Override
public boolean isCancelled() {
return canceled;
}
@Override
public void setCancelled(boolean canceled) {
this.canceled = canceled;
}
}

View File

@ -0,0 +1,68 @@
package com.songoda.epicspawners.spawners;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Created by songoda on 4/22/2017.
*/
public class SpawnerDropEvent extends Event implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList();
private Location location;
private Player player;
private int multi;
private EntityType type;
private boolean canceled = false;
public SpawnerDropEvent(Location location, Player player) {
Spawner spawner = new Spawner(location);
this.location = location;
this.player = player;
this.multi = spawner.getMulti();
if (spawner.getSpawner() == null)
this.type = null;
else
this.type = spawner.getSpawner().getSpawnedType();
}
public Location getLocation() {
return location;
}
public Player getPlayer() {
return player;
}
public int getMulti() {
return multi;
}
public EntityType getType() {
return type;
}
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
@Override
public boolean isCancelled() {
return canceled;
}
@Override
public void setCancelled(boolean canceled) {
this.canceled = canceled;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
package com.songoda.epicspawners.spawners;
/**
* Created by songo on 5/21/2017.
*/
public class SpawnerItem {
private String type = "PIG";
private int multi = 1;
public SpawnerItem(String type, int multi) {
this.type = type;
this.multi = multi;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getMulti() {
return multi;
}
public void setMulti(int multi) {
this.multi = multi;
}
}

View File

@ -0,0 +1,63 @@
package com.songoda.epicspawners.spawners;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Created by songoda on 4/22/2017.
*/
public class SpawnerPlaceEvent extends Event implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList();
private Location location;
private Player player;
private int multi;
private String type;
private boolean canceled = false;
public SpawnerPlaceEvent(Location location, Player player, String type) {
Spawner spawner = new Spawner(location);
this.location = location;
this.player = player;
this.multi = spawner.getMulti();
this.type = type;
}
public Location getLocation() {
return location;
}
public Player getPlayer() {
return player;
}
public int getMulti() {
return multi;
}
public String getType() {
return type;
}
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
@Override
public boolean isCancelled() {
return canceled;
}
@Override
public void setCancelled(boolean canceled) {
this.canceled = canceled;
}
}

View File

@ -0,0 +1,31 @@
package com.songoda.epicspawners.utils;
import com.songoda.epicspawners.EpicSpawners;
/**
* 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 EpicSpawners.");
System.out.println("--------------------------------------------------------------");
e.printStackTrace();
System.out.println("==============================================================");
}
sendReport(e);
}
public static void sendReport(Exception e) {
}
public static boolean isDebug() {
EpicSpawners plugin = EpicSpawners.pl();
return plugin.getConfig().getBoolean("System.Debugger Enabled");
}
}

View File

@ -0,0 +1,68 @@
package com.songoda.epicspawners.utils;
/**
* Created by songoda on 3/20/2017.
*/
public enum HeadType {
BAT("http://textures.minecraft.net/texture/978862a56119227aaad4b7c246c8b2256db985db0951f55b0a1f8616c191f"),
BLAZE("http://textures.minecraft.net/texture/b78ef2e4cf2c41a2d14bfde9caff10219f5b1bf5b35a49eb51c6467882cb5f0"),
CHICKEN("http://textures.minecraft.net/texture/1638469a599ceef7207537603248a9ab11ff591fd378bea4735b346a7fae893"),
COW("http://textures.minecraft.net/texture/5d6c6eda942f7f5f71c3161c7306f4aed307d82895f9d2b07ab4525718edc5"),
CREEPER("http://textures.minecraft.net/texture/295ef836389af993158aba27ff37b6567185f7a721ca90fdfeb937a7cb5747"),
CAVE_SPIDER("http://textures.minecraft.net/texture/41645dfd77d09923107b3496e94eeb5c30329f97efc96ed76e226e98224"),
DONKEY("http://textures.minecraft.net/texture/9ffca9f0859834da81af524c2865fa3186b5bf58bd1c4e3742837c4fd6853887"),
ELDER_GUARDIAN("http://textures.minecraft.net/texture/dbb9491b7a1768e3291959796232eb6f61b9c39aa2f81e13d287a3ab5d16dec"),
ENDERMAN("http://textures.minecraft.net/texture/7a59bb0a7a32965b3d90d8eafa899d1835f424509eadd4e6b709ada50b9cf"),
ENDERMITE("http://textures.minecraft.net/texture/e8c6cb8ceaad5a2ad5cc9a67bce6d5bdbf5cbb7e312955ccf9f162509355b1"),
ENDER_DRAGON("http://textures.minecraft.net/texture/74ecc040785e54663e855ef0486da72154d69bb4b7424b7381ccf95b095a"),
EVOKER("http://textures.minecraft.net/texture/bb48ed634196b7ded7455fdde56f3fa9f51b28f7b73839f0c6783b3961d"),
GHAST("http://textures.minecraft.net/texture/8b6a72138d69fbbd2fea3fa251cabd87152e4f1c97e5f986bf685571db3cc0"),
GIANT("http://textures.minecraft.net/texture/56fc854bb84cf4b7697297973e02b79bc10698460b51a639c60e5e417734e11"),
GUARDIAN( "http://textures.minecraft.net/texture/932c24524c82ab3b3e57c2052c533f13dd8c0beb8bdd06369bb2554da86c123"),
HORSE("http://textures.minecraft.net/texture/61902898308730c4747299cb5a5da9c25838b1d059fe46fc36896fee662729"),
HUSK("http://textures.minecraft.net/texture/6ae3a5bfcaa943d126988ed17ce8e4a7fb4231b05a5c5c947e5cc9752a199962"),
ILLUSIONER("http://textures.minecraft.net/texture/c269a9dabe4f9fd6b4d74b7cd9c7ee6b24d87549b5acabbeb36cd756cc373"),
IRON_GOLEM("http://textures.minecraft.net/texture/89091d79ea0f59ef7ef94d7bba6e5f17f2f7d4572c44f90f76c4819a714"),
LLAMA("http://textures.minecraft.net/texture/6bc438fc1fbbaea2289aabecedd3fdf269ddc979bf8b5c6a8fc4bb8dcd4e1fe"),
MAGMA_CUBE("http://textures.minecraft.net/texture/38957d5023c937c4c41aa2412d43410bda23cf79a9f6ab36b76fef2d7c429"),
MULE("http://textures.minecraft.net/texture/36fcd3ec3bc84bafb4123ea479471f9d2f42d8fb9c5f11cf5f4e0d93226"),
MUSHROOM_COW("http://textures.minecraft.net/texture/d0bc61b9757a7b83e03cd2507a2157913c2cf016e7c096a4d6cf1fe1b8db"),
OCELOT("http://textures.minecraft.net/texture/5657cd5c2989ff97570fec4ddcdc6926a68a3393250c1be1f0b114a1db1"),
OMNI("http://textures.minecraft.net/texture/afe097f7f7a6568884198b562cb58cfb84a3936fbf72828954aaa1f58cba32"),
PARROT("http://textures.minecraft.net/texture/fd7cca30a1dc2fb25d3b7fb16318330ac79742d97deeeabe5393fb8a2cb878"),
PIG("http://textures.minecraft.net/texture/621668ef7cb79dd9c22ce3d1f3f4cb6e2559893b6df4a469514e667c16aa4"),
PIG_ZOMBIE("http://textures.minecraft.net/texture/74e9c6e98582ffd8ff8feb3322cd1849c43fb16b158abb11ca7b42eda7743eb"),
POLAR_BEAR("http://textures.minecraft.net/texture/d46d23f04846369fa2a3702c10f759101af7bfe8419966429533cd81a11d2b"),
RABBIT("http://textures.minecraft.net/texture/dc7a317ec5c1ed7788f89e7f1a6af3d2eeb92d1e9879c05343c57f9d863de130"),
SHEEP("http://textures.minecraft.net/texture/f31f9ccc6b3e32ecf13b8a11ac29cd33d18c95fc73db8a66c5d657ccb8be70"),
SHULKER("http://textures.minecraft.net/texture/1433a4b73273a64c8ab2830b0fff777a61a488c92f60f83bfb3e421f428a44"),
SILVERFISH("http://textures.minecraft.net/texture/453a6aedbc9e4a22266cd70d2d4a2850a7e4b5864fbcbddf952b748fbabdb2"),
SKELETON("http://textures.minecraft.net/texture/2e5be6a3c0159d2c1f3b1e4e1d8384b6f7ebac993d58b10b9f8989c78a232"),
SKELETON_HORSE("http://textures.minecraft.net/texture/39be68887f5cf8c8044ebcdc5e768a172b2ef3e99545acd75b5ff74a263a"),
SLIME("http://textures.minecraft.net/texture/16ad20fc2d579be250d3db659c832da2b478a73a698b7ea10d18c9162e4d9b5"),
SNOWMAN("http://textures.minecraft.net/texture/a528df1653962e4e995dfd064a72b2cbff9b7197912880143f941a37db46c"),
SPIDER("http://textures.minecraft.net/texture/cd541541daaff50896cd258bdbdd4cf80c3ba816735726078bfe393927e57f1"),
SQUID("http://textures.minecraft.net/texture/01433be242366af126da434b8735df1eb5b3cb2cede39145974e9c483607bac"),
STRAY("http://textures.minecraft.net/texture/96e58aeeaf75e9695813aeaabd3973c83d5ff8c285fe6b944550bc41b953"),
VEX("http://textures.minecraft.net/texture/6dc4b59be077f7f2f6b488666afb85e45d96cc57b57934ae11ba9734bb4811"),
VILLAGER("http://textures.minecraft.net/texture/822d8e751c8f2fd4c8942c44bdb2f5ca4d8ae8e575ed3eb34c18a86e93b"),
VINDICATOR("http://textures.minecraft.net/texture/7a5b31aeab7f728cd7e90f81e2ffad4cd198c1907574f57be2b7c42f49ddd"),
WITCH("http://textures.minecraft.net/texture/2e139130d7efd41fbad53735f64f8aff265bd7c54977189c02babbec4b0d07b"),
WITHER("http://textures.minecraft.net/texture/cdf74e323ed41436965f5c57ddf2815d5332fe999e68fbb9d6cf5c8bd4139f"),
WITHER_SKELETON("http://textures.minecraft.net/texture/233b41fa79cd53a230e2db942863843183a70404533bbc01fab744769bcb"),
WOLF("http://textures.minecraft.net/texture/e95cbb4f75ea87617f2f713c6d49dac3209ba1bd4b9369654b1459ea15317"),
ZOMBIE("http://textures.minecraft.net/texture/56fc854bb84cf4b7697297973e02b79bc10698460b51a639c60e5e417734e11"),
ZOMBIE_HORSE("http://textures.minecraft.net/texture/d898e3eacff9949a9de9777ddfada8a7f62a4102de47b54db35f9f843e1ce4"),
ZOMBIE_VILLAGER("http://textures.minecraft.net/texture/1a207a2b872fe8dd22ce5e27fc3263622621635efd8ea6abbdf317f99c5843"),
UNKNOWN("http://textures.minecraft.net/texture/452fe4ce1f1d53a12ed443eeba7297e81da581e0c7a39954d9d7bba7de59c46");
private String url;
HeadType(String url) {
this.url = url;
}
public String getUrl() {
return url;
}
}

View File

@ -0,0 +1,47 @@
package com.songoda.epicspawners.utils;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
/**
* Created by songoda on 3/19/2017.
*/
public class Heads {
private Map<String, String> textureURL = new HashMap<>();
private final EpicSpawners plugin = EpicSpawners.pl();
public Heads() {
try {
for (HeadType type : HeadType.values()) {
textureURL.put(type.name(), type.getUrl());
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
public ItemStack addTexture(ItemStack item, String name) {
try {
String headURL = textureURL.get(name.toUpperCase().replace(" ", "_"));
if (headURL == null) {
headURL = textureURL.get("UNKNOWN");
}
if (plugin.v1_7) {
item = new ItemStack(Material.MOB_SPAWNER, 1);
return item;
} else {
return Arconix.pl().getApi().getGUI().addTexture(item, headURL);
}
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
}

View File

@ -0,0 +1,283 @@
package com.songoda.epicspawners.utils;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
import net.minecraft.server.v1_7_R4.AxisAlignedBB;
import org.bukkit.*;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* Created by songoda on 2/24/2017.
*/
public class Methods {
public static String formatName(EntityType type, int multi) {
try {
if (multi <= 0)
multi = 1;
return compileName(type.name(), multi, true);
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static void takeItem(Player p, int amt) {
try {
if (p.getGameMode() != GameMode.CREATIVE) {
int result = p.getInventory().getItemInHand().getAmount() - amt;
if (result > 0) {
ItemStack is = p.getItemInHand();
is.setAmount(is.getAmount() - amt);
p.setItemInHand(is);
} else {
p.setItemInHand(null);
}
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
public static boolean isOffhand(PlayerInteractEvent e) {
try {
EpicSpawners plugin = EpicSpawners.pl();
if (!plugin.v1_8 && !plugin.v1_7) {
if (e.getHand() == EquipmentSlot.OFF_HAND)
return true;
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
return false;
}
public static boolean isOffhand(BlockPlaceEvent e) {
try {
EpicSpawners plugin = EpicSpawners.pl();
if (!plugin.v1_8 && !plugin.v1_7 && e.getHand() == EquipmentSlot.OFF_HAND)
return true;
} catch (Exception ee) {
Debugger.runReport(ee);
}
return false;
}
public static String getBoostCost(int time, int amt) {
try {
EpicSpawners plugin = EpicSpawners.pl();
String cost = "";
String un = plugin.getConfig().getString("Spawner Boosting.Item Charged For A Boost");
String[] parts = un.split(":");
String type = parts[0];
String multi = parts[1];
int co = boostCost(multi, time, amt);
if (!type.equals("ECO") && !type.equals("XP")) {
cost += "&6&l" + co;
cost += " &7" + type.substring(0, 1).toUpperCase() + type.toLowerCase().substring(1);
if (co != 1)
cost += "s";
} else if (type.equals("ECO")) {
cost += "&6&l$" + Arconix.pl().getApi().format().formatEconomy(co);
} else if (type.equals("XP")) {
cost += "&6&l" + co;
cost += " &7Levels";
}
return cost;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static int boostCost(String multi, int time, int amt) {
try {
return (int) Math.ceil((Double.parseDouble(multi) * time) * amt);
} catch (Exception e) {
Debugger.runReport(e);
}
return 99999;
}
public static String compileName(String type, int multi, boolean full) {
try {
if (multi == 0) multi = 1;
EpicSpawners plugin = EpicSpawners.pl();
String name = plugin.getConfig().getString("Main.Spawner Name Format");
String nme = getTypeFromString(type);
if (plugin.spawnerFile.getConfig().contains("Entities." + Methods.getTypeFromString(type) + ".Display-Name")) {
nme = plugin.spawnerFile.getConfig().getString("Entities." + Methods.getTypeFromString(type) + ".Display-Name");
}
name = name.replace("{TYPE}", nme);
if ((multi > 1 || plugin.getConfig().getBoolean("Main.Display Level In Spawner Title If Level 1") || plugin.getConfig().getBoolean("Main.Named Spawners Tiers")) && multi >= 0) {
if (plugin.getConfig().getBoolean("Main.Named Spawners Tiers") && plugin.getConfig().getStringList("Main.Tier Names").size() + 1 > multi) {
name = name.replace("{AMT}", plugin.getConfig().getStringList("Main.Tier Names").get(multi - 1));
} else {
name = name.replace("{AMT}", Integer.toString(multi));
}
name = name.replace("[", "").replace("]", "");
} else {
name = name.replaceAll("\\[.*?]", "");
}
String info = "";
if (full) {
info += Arconix.pl().getApi().format().convertToInvisibleString(type.toUpperCase().replaceAll(" ", "_") + ":" + multi + ":");
}
return info + Arconix.pl().getApi().format().formatText(name).trim();
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static ItemStack getGlass() {
try {
EpicSpawners plugin = EpicSpawners.pl();
return Arconix.pl().getApi().getGUI().getGlass(plugin.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), plugin.getConfig().getInt("Interfaces.Glass Type 1"));
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static ItemStack getBackgroundGlass(boolean type) {
try {
EpicSpawners plugin = EpicSpawners.pl();
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"));
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static String properType(String type) {
try {
EpicSpawners plugin = EpicSpawners.pl();
return plugin.spawnerFile.getConfig().getString("Entities." + Methods.getTypeFromString(type) + ".Display-Name");
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static String getType(EntityType typ) {
try {
String type = typ.toString().replaceAll("_", " ");
type = ChatColor.stripColor(type.substring(0, 1).toUpperCase() + type.toLowerCase().substring(1));
return type;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static String getTypeFromString(String typ) {
try {
if (typ == null)
return null;
String type = typ.replaceAll("_", " ");
type = ChatColor.stripColor(type.substring(0, 1).toUpperCase() + type.toLowerCase().substring(1));
return type;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static String restoreType(String typ) {
try {
String type = typ.replace(" ", "_");
type = type.toUpperCase();
return type;
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static boolean isAir(Material type) {
try {
if (type == Material.AIR || type == Material.WOOD_PLATE
|| type == Material.STONE_PLATE || type == Material.IRON_PLATE
|| type == Material.GOLD_PLATE)
return true;
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@SuppressWarnings("unchecked")
public static Collection<Entity> getNearbyEntities(Location location, double x, double y, double z) {
if (!EpicSpawners.getInstance().v1_7) return location.getWorld().getNearbyEntities(location,x,y,z);
if (location == null) return Collections.emptyList();
World world = location.getWorld();
AxisAlignedBB aabb = 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 = ((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 int countEntitiesAroundLoation(Location location) {
try {
int amt = 0;
String[] arr = EpicSpawners.getInstance().getConfig().getString("Main.Radius To Search Around Spawner").split("x");
Collection<Entity> nearbyEntite = getNearbyEntities(location.clone().add(0.5, 0.5, 0.5), Integer.parseInt(arr[0]), Integer.parseInt(arr[1]), Integer.parseInt(arr[2]));
if (nearbyEntite.size() < 1) return amt;
for (Entity ee : nearbyEntite) {
if (!(ee instanceof LivingEntity) || ee instanceof Player || ee.getType().name().toLowerCase().contains("armor")) {
continue;
}
if (EpicSpawners.getInstance().getServer().getPluginManager().getPlugin("StackMob") != null
&& ee.getMetadata(uk.antiperson.stackmob.tools.extras.GlobalValues.METATAG).size() != 0) {
amt = amt + ee.getMetadata(uk.antiperson.stackmob.tools.extras.GlobalValues.METATAG).get(0).asInt();
} else {
amt++;
}
}
return amt;
} catch (Exception e) {
Debugger.runReport(e);
}
return 0;
}
}

View File

@ -0,0 +1,54 @@
package com.songoda.epicspawners.utils;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
/**
* Created by songoda on 2/25/2017.
*/
@SuppressWarnings({"unchecked", "ConstantConditions"})
public class Reflection {
public static Object getNMSItemStack(ItemStack item) {
@SuppressWarnings("rawtypes")
Class cis = getCraftItemStack();
java.lang.reflect.Method method;
try {
method = cis.getMethod("asNMSCopy", ItemStack.class);
return method.invoke(cis, item);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static Object getNBTTagCompound(Object nmsitem) {
@SuppressWarnings("rawtypes")
Class c = nmsitem.getClass();
java.lang.reflect.Method method;
try {
method = c.getMethod("getTag");
return method.invoke(nmsitem);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@SuppressWarnings("rawtypes")
public static Class getCraftItemStack() {
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
try {
//Constructor<?> cons = c.getConstructor(ItemStack.class);
//return cons.newInstance(item);
return Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
} catch (Exception ex) {
System.out.println("Error in ItemNBTAPI! (Outdated plugin?)");
ex.printStackTrace();
return null;
}
}
}

View File

@ -0,0 +1,310 @@
package com.songoda.epicspawners.utils;
import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicspawners.EpicSpawners;
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.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 {
private EpicSpawners instance = EpicSpawners.pl();
private String pluginName = "EpicSpawners";
private Map<Player, String> cat = new HashMap<>();
private static ConfigWrapper defs;
public SettingsManager() {
instance.saveResource("SettingDefinitions.yml", true);
defs = new ConfigWrapper(instance, "", "SettingDefinitions.yml");
defs.createNewFile("Loading data file", pluginName + " 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 Editor")) {
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 Editor");
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()) {
if (instance.getConfig().contains("settings." + s.oldSetting)) {
instance.getConfig().addDefault(s.setting, instance.getConfig().get("settings." + s.oldSetting));
instance.getConfig().set("settings." + s.oldSetting, null);
} else if (s.setting.equals("Main.Upgrade Particle Type")) {
if (instance.v1_7 || instance.v1_8)
instance.getConfig().addDefault(s.setting, "WITCH_MAGIC");
else
instance.getConfig().addDefault(s.setting, s.option);
} else
instance.getConfig().addDefault(s.setting, s.option);
}
instance.getConfig().set("settings", null);
}
public enum settings {
o1("Spawner-max", "Main.Spawner Max Upgrade", 5),
o58("Name-format", "Main.Spawner Name Format", "&e{TYPE} &fSpawner [&c{AMT}x]"),
o2("Force-Combine-Radius", "Main.Force Combine Radius", 0),
o49("Force-Combine-Deny", "Main.Deny Place On Force Combine", false),
o3("Search-Radius", "Main.Radius To Search Around Spawner", "8x4x8"),
o10("Alter-Delay", "Main.Default Minecraft Spawner Cooldowns", true),
o17("Alert-place-break", "Main.Alerts On Place And Break", true),
o18("Sneak-for-stack", "Main.Sneak To Receive A Stacked Spawner", true),
o32("Spawner-holograms", "Main.Spawners Have Holograms", true),
o4("Only-drop-placed", "Main.Only Drop Placed Spawners", false),
o5("Only-charge-natural", "Main.Only Charge Natural Spawners", false),
o43("Random-Low & Random-High", "Main.Random Amount Added To Each Spawn", "1:3"),
o63("Sounds", "Main.Sounds Enabled", true),
o23("Display-Level-One", "Main.Display Level In Spawner Title If Level 1", false),
o19("OmniSpawners", "Main.OmniSpawners Enabled", true),
o21("Omni-Limit", "Main.Max Spawners Inside A OmniSpawner", 3),
o215("Eggs-convert-spawners", "Main.Convert Spawners With Eggs", true),
o42("Helpful-Tips", "Main.Display Helpful Tips For Operators", true),
o33("Upgrade-with-eco", "Main.Upgrade With Economy", true),
o34("Upgrade-with-xp", "Main.Upgrade With XP", true),
o35("Upgrade-xp-cost", "Main.Cost To Upgrade With XP", 50),
o36("Upgrade-eco-cost", "Main.Cost To Upgrade With Economy", 10000),
o55("Use-equations", "Main.Use Custom Equations for Upgrade Costs", false),
o62("spawners-repel-radius", "Main.Spawner Repel Liquid Radius", 1),
o60("redstone-activate", "Main.Redstone Power Deactivates Spawners", true),
o51("Max-Entities-Around-Single-Spawner", "Main.Max Entities Around Single Spawner", 6),
o523("How-to", "Main.Display Help Button In Spawner Overview", true),
o24("Inventory-Stacking", "Main.Allow Stacking Spawners In Survival Inventories", true),
o27("Spawners-dont-explode", "Main.Prevent Spawners From Exploding", false),
o53("Add-Spawner-To-Inventory-On-Drop", "Main.Add Spawner To Inventory On Drop", false),
o54("Upgrade-particle-type", "Main.Upgrade Particle Type", "SPELL_WITCH"),
o5344("ticks-until-disabled", "Main.Ticks Until AI Disabled", 20L),
o99("-", "Main.Named Spawners Tiers", false),
o98("-", "Main.Tier Names", Arrays.asList("&7Common", "&6Uncommon", "&4Rare", "&5Mythic")),
o56("XP-cost-equation", "Main.Equations.Calculate XP Upgrade Cost", "{XPCost} * {Level}"),
o57("ECO-cost-equation", "Main.Equations.Calculate Economy Upgrade Cost", "{ECOCost} * {Level}"),
o554("Spawner-Spawn-Equation", "Main.Equations.Mobs Spawned Per Spawn", "{MULTI} + {RAND}"),
o6("Spawner-Rate-Equation", "Main.Equations.Cooldown Between Spawns", "{DEFAULT} / {MULTI}"),
o81("Boost-Multiplier", "Spawner Boosting.Boost Multiplier", "0.5"),
o82("Max-Player-Boost", "Spawner Boosting.Max Multiplier For A Spawner Boost", 5),
o83("Boost-cost", "Spawner Boosting.Item Charged For A Boost", "DIAMOND:2"),
o30("Hostile-mobs-attack-second", "Entity.Hostile Mobs Attack Second", false),
o50("SpawnEffect", "Entity.Spawn Particle Effect", "EXPLOSION_NORMAL"),
o52("Large-Entity-Safe-Spawning", "Entity.Use Default Minecraft Spawn Method For Large Entities", true),
o41("Only-drop-stacked", "Spawner Drops.Only Drop Stacked Spawners", false),
o31("Mob-kill-counting", "Spawner Drops.Allow Killing Mobs To Drop Spawners", true),
o40("Count-unnatural-kills", "Spawner Drops.Count Unnatural Kills Towards Spawner Drop", false),
o623("Goal", "Spawner Drops.Kills Needed for Drop", 100),
o7("Alert-every", "Spawner Drops.Alert Every X Before Drop", 10),
o25("Drop-on-creeper-explosion", "Spawner Drops.Drop On Creeper Explosion", true),
o26("Drop-on-tnt-explosion", "Spawner Drops.Drop On TNT Explosion", true),
o28("Tnt-explosion-drop-chance", "Spawner Drops.Chance On TNT Explosion", "100%"),
o29("Creeper-explosion-drop-chance", "Spawner Drops.Chance On Creeper Explosion", "100%"),
o13("Silktouch-spawners", "Spawner Drops.Drop On SilkTouch", true),
o14("Silktouch-natural-drop-chance", "Spawner Drops.Chance On Natural Silktouch", "100%"),
o15("Silktouch-placed-drop-chance", "Spawner Drops.Chance On Placed Silktouch", "100%"),
o8("Exit-Icon", "Interfaces.Exit Icon", "WOOD_DOOR"),
o9("Buy-Icon", "Interfaces.Buy Icon", "EMERALD"),
o37("ECO-Icon", "Interfaces.Economy Icon", "DOUBLE_PLANT"),
o39("XP-Icon", "Interfaces.XP Icon", "EXP_BOTTLE"),
o11("Glass-Type-1", "Interfaces.Glass Type 1", 7),
o112("Glass-Type-2", "Interfaces.Glass Type 2", 11),
o113("Glass-Type-3", "Interfaces.Glass Type 3", 3),
o12("Rainbow-Glass", "Interfaces.Replace Glass Type 1 With Rainbow Glass", false),
o45("Thin-Entity-data", "System.Remove Dead Entities from Data File", true),
o48("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;
}
}
}

View File

@ -0,0 +1,21 @@
name: EpicSpawners
description: EpicSpawners
version: 4.2.5
depend: [Arconix]
softdepend: [Towny, RedProtect Kingdoms, PlotSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, Vault, PlaceholderAPI]
main: com.songoda.epicspawners.EpicSpawners
author: songoda
commands:
EpicSpawners:
description: I have no idea.
default: true
aliases: [es]
usage: /<command> [reload]
SpawnerStats:
description: I have no idea.
default: false
usage: /<command> [reload]
SpawnerShop:
description: I have no idea.
default: false
usage: /<command> [reload]

Binary file not shown.