mirror of
https://github.com/songoda/EpicFarming.git
synced 2025-02-21 15:01:25 +01:00
Begin fundamental rewrite & moved levels to seperate yaml.
This commit is contained in:
parent
05e84e2b37
commit
c2a1418b71
@ -1,17 +0,0 @@
|
||||
<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>
|
||||
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicFarming-Parent</artifactId>
|
||||
<version>maven-version-number</version>
|
||||
</parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicFarming-API</artifactId>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>EpicFarming-API</finalName>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -1,17 +0,0 @@
|
||||
package com.songoda.epicfarming.api;
|
||||
|
||||
import com.songoda.epicfarming.api.farming.FarmManager;
|
||||
import com.songoda.epicfarming.api.farming.Level;
|
||||
import com.songoda.epicfarming.api.farming.LevelManager;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface EpicFarming {
|
||||
|
||||
int getLevelFromItem(ItemStack item);
|
||||
|
||||
ItemStack makeFarmItem(Level level);
|
||||
|
||||
FarmManager getFarmManager();
|
||||
|
||||
LevelManager getLevelManager();
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package com.songoda.epicfarming.api;
|
||||
/**
|
||||
* The access point of the EpicFarmingAPI, a class acting as a bridge between API
|
||||
* and plugin implementation. It is from here where developers should access the
|
||||
* important and core methods in the API. All static methods in this class will
|
||||
* call directly upon the implementation at hand (in most cases this will be the
|
||||
* EpicFarming plugin itself), therefore a call to {@link #getImplementation()} is
|
||||
* not required and redundant in most situations. Method calls from this class are
|
||||
* preferred the majority of time, though an instance of {@link EpicFarming} may
|
||||
* be passed if absolutely necessary.
|
||||
*
|
||||
* @see EpicFarming
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class EpicFarmingAPI {
|
||||
|
||||
private static EpicFarming implementation;
|
||||
|
||||
/**
|
||||
* Set the EpicFarming implementation. Once called for the first time, this
|
||||
* method will throw an exception on any subsequent invocations. The implementation
|
||||
* may only be set a single time, presumably by the EpicFarming plugin
|
||||
*
|
||||
* @param implementation the implementation to set
|
||||
*/
|
||||
public static void setImplementation(EpicFarming implementation) {
|
||||
if (EpicFarmingAPI.implementation != null) {
|
||||
throw new IllegalArgumentException("Cannot set API implementation twice");
|
||||
}
|
||||
|
||||
EpicFarmingAPI.implementation = implementation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the EpicFarming implementation. This method may be redundant in most
|
||||
* situations as all methods present in {@link EpicFarming} will be mirrored
|
||||
* with static modifiers in the {@link EpicFarmingAPI} class
|
||||
*
|
||||
* @return the EpicFarming implementation
|
||||
*/
|
||||
public static EpicFarming getImplementation() {
|
||||
return implementation;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,22 +0,0 @@
|
||||
package com.songoda.epicfarming.api.farming;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface Farm {
|
||||
Inventory getInventory();
|
||||
|
||||
List<Block> getCachedCrops();
|
||||
|
||||
Location getLocation();
|
||||
|
||||
UUID getPlacedBy();
|
||||
|
||||
void setLocation(Location location);
|
||||
|
||||
Level getLevel();
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.songoda.epicfarming.api.farming;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface FarmManager {
|
||||
void addFarm(Location location, Farm farm);
|
||||
|
||||
Farm removeFarm(Location location);
|
||||
|
||||
Farm getFarm(Location location);
|
||||
|
||||
Farm getFarm(Block block);
|
||||
|
||||
Map<Location, Farm> getFarms();
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.songoda.epicfarming.api.farming;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Level {
|
||||
List<String> getDescription();
|
||||
|
||||
int getLevel();
|
||||
|
||||
int getRadius();
|
||||
|
||||
boolean isAutoHarvest();
|
||||
|
||||
boolean isAutoReplant();
|
||||
|
||||
boolean isAutoBreeding();
|
||||
|
||||
double getSpeedMultiplier();
|
||||
|
||||
int getCostExperiance();
|
||||
|
||||
int getCostEconomy();
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.songoda.epicfarming.api.farming;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface LevelManager {
|
||||
|
||||
void addLevel(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant, boolean autoBreeding);
|
||||
|
||||
Level getLevel(int level);
|
||||
|
||||
Level getLowestLevel();
|
||||
|
||||
Level getHighestLevel();
|
||||
|
||||
boolean isLevel(int level);
|
||||
|
||||
Map<Integer, Level> getLevels();
|
||||
|
||||
void clear();
|
||||
}
|
@ -1,226 +0,0 @@
|
||||
<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>
|
||||
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicFarming-Parent</artifactId>
|
||||
<version>maven-version-number</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>EpicFarming-Plugin</artifactId>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>private</id>
|
||||
<url>http://repo.songoda.com/artifactory/private/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>songodaupdater</artifactId>
|
||||
<version>1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicFarming-API</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>skyblockearth</artifactId>
|
||||
<version>59</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.arcaniax</groupId>
|
||||
<artifactId>liquidtanks</artifactId>
|
||||
<version>2.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org</groupId>
|
||||
<artifactId>kingdoms</artifactId>
|
||||
<version>13.0.9</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl</groupId>
|
||||
<artifactId>vault</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.ryanhamshire</groupId>
|
||||
<artifactId>GriefPrevention</artifactId>
|
||||
<version>16.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>7.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>7.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com</groupId>
|
||||
<artifactId>plotsquared</artifactId>
|
||||
<version>BREAKING</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.palmergames.bukkit</groupId>
|
||||
<artifactId>towny</artifactId>
|
||||
<version>0.93.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.wasteofplastic</groupId>
|
||||
<artifactId>askyblock</artifactId>
|
||||
<version>3.0.6.8</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.talabrek</groupId>
|
||||
<artifactId>ultimateskyblock</artifactId>
|
||||
<version>2.7.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.markeh</groupId>
|
||||
<artifactId>factionsframework</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>br.net.fabiozumbi12</groupId>
|
||||
<artifactId>RedProtect</artifactId>
|
||||
<version>7.3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gmail.nossr50</groupId>
|
||||
<artifactId>mcmmo</artifactId>
|
||||
<version>1.5.09</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gamingmesh</groupId>
|
||||
<artifactId>jobs</artifactId>
|
||||
<version>4.6.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.botsko</groupId>
|
||||
<artifactId>prism</artifactId>
|
||||
<version>2.0.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.diddiz</groupId>
|
||||
<artifactId>logblock</artifactId>
|
||||
<version>1.10.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net</groupId>
|
||||
<artifactId>coreprotect</artifactId>
|
||||
<version>2.14.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>uk.antiperson</groupId>
|
||||
<artifactId>stackmob</artifactId>
|
||||
<version>2.2.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sothatsit</groupId>
|
||||
<artifactId>blockstore</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.black_ixx</groupId>
|
||||
<artifactId>playerpoints</artifactId>
|
||||
<version>2.1.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.wildseries</groupId>
|
||||
<artifactId>wildstacker</artifactId>
|
||||
<version>b6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>EpicFarming-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>shaded</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<shadedArtifactAttached>false</shadedArtifactAttached>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.songoda:songodaupdater</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -1,375 +0,0 @@
|
||||
package com.songoda.epicfarming;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
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 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 JavaPlugin plugin;
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 in 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(InputStream in, 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)) {
|
||||
copy(in == null ? plugin.getResource(fileName) : in, 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(null, 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;
|
||||
}
|
||||
|
||||
private static void copy(InputStream input, OutputStream output) {
|
||||
int n;
|
||||
byte[] buffer = new byte[1024 * 4];
|
||||
|
||||
try {
|
||||
while ((n = input.read(buffer)) != -1) {
|
||||
output.write(buffer, 0, n);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.trim().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;
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.songoda.epicfarming;
|
||||
|
||||
public class References {
|
||||
|
||||
private String prefix;
|
||||
|
||||
References() {
|
||||
prefix = EpicFarmingPlugin.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package com.songoda.epicfarming.command;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public abstract class AbstractCommand {
|
||||
|
||||
public enum ReturnType { SUCCESS, FAILURE, SYNTAX_ERROR }
|
||||
|
||||
private final AbstractCommand parent;
|
||||
|
||||
private final String command;
|
||||
|
||||
private final boolean noConsole;
|
||||
|
||||
protected AbstractCommand(String command, AbstractCommand parent, boolean noConsole) {
|
||||
this.command = command;
|
||||
this.parent = parent;
|
||||
this.noConsole = noConsole;
|
||||
}
|
||||
|
||||
public AbstractCommand getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public boolean isNoConsole() {
|
||||
return noConsole;
|
||||
}
|
||||
|
||||
protected abstract ReturnType runCommand(EpicFarmingPlugin instance, CommandSender sender, String... args);
|
||||
|
||||
public abstract String getPermissionNode();
|
||||
|
||||
public abstract String getSyntax();
|
||||
|
||||
public abstract String getDescription();
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
package com.songoda.epicfarming.command;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.command.commands.*;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandManager implements CommandExecutor {
|
||||
|
||||
private EpicFarmingPlugin instance;
|
||||
|
||||
private List<AbstractCommand> commands = new ArrayList<>();
|
||||
|
||||
public CommandManager(EpicFarmingPlugin instance) {
|
||||
this.instance = instance;
|
||||
|
||||
instance.getCommand("EpicFarming").setExecutor(this);
|
||||
|
||||
AbstractCommand commandEpicFarming = addCommand(new CommandEpicFarming());
|
||||
|
||||
addCommand(new CommandReload(commandEpicFarming));
|
||||
addCommand(new CommandSettings(commandEpicFarming));
|
||||
addCommand(new CommandGiveFarmItem(commandEpicFarming));
|
||||
addCommand(new CommandBoost(commandEpicFarming));
|
||||
}
|
||||
|
||||
private AbstractCommand addCommand(AbstractCommand abstractCommand) {
|
||||
commands.add(abstractCommand);
|
||||
return abstractCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
if (abstractCommand.getCommand().equalsIgnoreCase(command.getName())) {
|
||||
if (strings.length == 0) {
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName())) {
|
||||
String cmd = strings[0];
|
||||
if (cmd.equalsIgnoreCase(abstractCommand.getCommand())) {
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
commandSender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly."));
|
||||
return true;
|
||||
}
|
||||
|
||||
private void processRequirements(AbstractCommand command, CommandSender sender, String[] strings) {
|
||||
if (!(sender instanceof Player) && command.isNoConsole()) {
|
||||
sender.sendMessage("You must be a player to use this command.");
|
||||
return;
|
||||
}
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings);
|
||||
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cInvalid Syntax!"));
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
|
||||
}
|
||||
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return Collections.unmodifiableList(commands);
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
package com.songoda.epicfarming.hook;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.hook.hooks.*;
|
||||
import com.songoda.epicfarming.utils.ConfigWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HookManager {
|
||||
|
||||
private final EpicFarmingPlugin plugin;
|
||||
|
||||
private ConfigWrapper hooksFile;
|
||||
private List<ProtectionPluginHook> registeredHooks = new ArrayList<>();
|
||||
|
||||
public HookManager(EpicFarmingPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.hooksFile = new ConfigWrapper(plugin, "", "hooks.yml");
|
||||
this.hooksFile.createNewFile("Loading Hooks File", plugin.getDescription().getName() + " Hooks File");
|
||||
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
// Register default hooks
|
||||
if (pluginManager.isPluginEnabled("ASkyBlock")) this.register(HookASkyBlock::new);
|
||||
if (pluginManager.isPluginEnabled("FactionsFramework")) this.register(HookFactions::new);
|
||||
if (pluginManager.isPluginEnabled("GriefPrevention")) this.register(HookGriefPrevention::new);
|
||||
if (pluginManager.isPluginEnabled("Kingdoms")) this.register(HookKingdoms::new);
|
||||
if (pluginManager.isPluginEnabled("PlotSquared")) this.register(HookPlotSquared::new);
|
||||
if (pluginManager.isPluginEnabled("RedProtect")) this.register(HookRedProtect::new);
|
||||
if (pluginManager.isPluginEnabled("Towny")) this.register(HookTowny::new);
|
||||
if (pluginManager.isPluginEnabled("USkyBlock")) this.register(HookUSkyBlock::new);
|
||||
if (pluginManager.isPluginEnabled("FabledSkyBlock")) this.register(HookSkyBlockEarth::new);
|
||||
if (pluginManager.isPluginEnabled("WorldGuard")) this.register(HookWorldGuard::new);
|
||||
}
|
||||
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
if (player.hasPermission(EpicFarmingPlugin.getInstance().getDescription().getName() + ".bypass")) return true;
|
||||
|
||||
for (ProtectionPluginHook hook : registeredHooks) {
|
||||
if (!hook.isInClaim(location)) continue;
|
||||
|
||||
if (!hook.canBuild(player, location)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isInClaim(HookType hookType, String name, Location l) {
|
||||
List<ProtectionPluginHook> hooks = registeredHooks.stream().filter(hook -> hook.getHookType() == hookType).collect(Collectors.toList());
|
||||
for (ProtectionPluginHook hook : hooks) {
|
||||
if (hook.isInClaim(l, name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getClaimId(HookType hookType, String name) {
|
||||
List<ProtectionPluginHook> hooks = registeredHooks.stream().filter(hook -> hook.getHookType() == hookType).collect(Collectors.toList());
|
||||
for (ProtectionPluginHook hook : hooks) {
|
||||
return hook.getClaimID(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private ProtectionPluginHook register(Supplier<ProtectionPluginHook> hookSupplier) {
|
||||
return this.registerProtectionHook(hookSupplier.get());
|
||||
}
|
||||
|
||||
public ProtectionPluginHook registerProtectionHook(ProtectionPluginHook hook) {
|
||||
Preconditions.checkNotNull(hook, "Cannot register null hook");
|
||||
Preconditions.checkNotNull(hook.getPlugin(), "Protection plugin hook returns null plugin instance (#getPlugin())");
|
||||
|
||||
JavaPlugin hookPlugin = hook.getPlugin();
|
||||
for (ProtectionPluginHook existingHook : registeredHooks) {
|
||||
if (existingHook.getPlugin().equals(hookPlugin)) {
|
||||
throw new IllegalArgumentException("Hook already registered");
|
||||
}
|
||||
}
|
||||
|
||||
this.hooksFile.getConfig().addDefault("hooks." + hookPlugin.getName(), true);
|
||||
if (!hooksFile.getConfig().getBoolean("hooks." + hookPlugin.getName(), true)) return null;
|
||||
this.hooksFile.getConfig().options().copyDefaults(true);
|
||||
this.hooksFile.saveConfig();
|
||||
|
||||
this.registeredHooks.add(hook);
|
||||
plugin.getLogger().info("Registered protection hook for plugin: " + hook.getPlugin().getName());
|
||||
return hook;
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package com.songoda.epicfarming.hook;
|
||||
|
||||
public enum HookType {
|
||||
|
||||
FACTION, TOWN, ISLAND, REGULAR
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.songoda.epicfarming.hook;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public interface ProtectionPluginHook {
|
||||
|
||||
JavaPlugin getPlugin();
|
||||
|
||||
HookType getHookType();
|
||||
|
||||
boolean canBuild(Player player, Location location);
|
||||
|
||||
default boolean canBuild(Player player, Block block) {
|
||||
return block != null && canBuild(player, block.getLocation());
|
||||
}
|
||||
|
||||
boolean isInClaim(Location location);
|
||||
|
||||
boolean isInClaim(Location location, String id);
|
||||
|
||||
String getClaimID(String name);
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.songoda.epicfarming.hook.hooks;
|
||||
|
||||
import com.songoda.epicfarming.hook.HookType;
|
||||
import com.songoda.epicfarming.hook.ProtectionPluginHook;
|
||||
import com.wasteofplastic.askyblock.ASkyBlock;
|
||||
import com.wasteofplastic.askyblock.ASkyBlockAPI;
|
||||
import com.wasteofplastic.askyblock.Island;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class HookASkyBlock implements ProtectionPluginHook {
|
||||
|
||||
private final ASkyBlockAPI skyblock;
|
||||
|
||||
public HookASkyBlock() {
|
||||
this.skyblock = ASkyBlockAPI.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() {
|
||||
return ASkyBlock.getPlugin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.ISLAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
Island island = skyblock.getIslandAt(location);
|
||||
if (island == null) return true;
|
||||
|
||||
UUID owner = island.getOwner();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
if (owner == null || owner.equals(playerUUID)) return true;
|
||||
|
||||
List<UUID> teamMembers = skyblock.getTeamMembers(owner);
|
||||
if (teamMembers.contains(playerUUID)) return true;
|
||||
|
||||
Set<Location> coopIslands = skyblock.getCoopIslands(player);
|
||||
for (Location islandLocation : coopIslands) {
|
||||
if (skyblock.getIslandAt(islandLocation).getOwner().equals(playerUUID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
return skyblock.getIslandAt(location) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return skyblock.getOwner(location).toString().equals(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package com.songoda.epicfarming.hook.hooks;
|
||||
|
||||
import com.songoda.epicfarming.hook.HookType;
|
||||
import com.songoda.epicfarming.hook.ProtectionPluginHook;
|
||||
import me.markeh.factionsframework.FactionsFramework;
|
||||
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.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class HookFactions implements ProtectionPluginHook {
|
||||
|
||||
private final FactionsFramework factions;
|
||||
|
||||
public HookFactions() {
|
||||
this.factions = FactionsFramework.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() {
|
||||
return factions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.FACTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
FPlayer fPlayer = FPlayers.getBySender(player);
|
||||
Faction faction = Factions.getFactionAt(location);
|
||||
|
||||
return faction.isNone() || fPlayer.getFaction().equals(faction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
return !Factions.getFactionAt(location).isNone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return Factions.getFactionAt(location).getId().equals(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
Faction faction = Factions.getByName(name, "");
|
||||
return (faction != null) ? faction.getId() : null;
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.songoda.epicfarming.hook.hooks;
|
||||
|
||||
import com.songoda.epicfarming.hook.HookType;
|
||||
import com.songoda.epicfarming.hook.ProtectionPluginHook;
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class HookGriefPrevention implements ProtectionPluginHook {
|
||||
|
||||
private final GriefPrevention griefPrevention;
|
||||
|
||||
public HookGriefPrevention() {
|
||||
this.griefPrevention = GriefPrevention.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() {
|
||||
return griefPrevention;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.REGULAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
Claim claim = griefPrevention.dataStore.getClaimAt(location, false, null);
|
||||
return claim != null && claim.allowBuild(player, Material.STONE) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
return griefPrevention.dataStore.getClaimAt(location, false, null) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package com.songoda.epicfarming.hook.hooks;
|
||||
|
||||
import com.songoda.epicfarming.hook.HookType;
|
||||
import com.songoda.epicfarming.hook.ProtectionPluginHook;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.kingdoms.constants.land.Land;
|
||||
import org.kingdoms.constants.land.SimpleChunkLocation;
|
||||
import org.kingdoms.constants.player.KingdomPlayer;
|
||||
import org.kingdoms.main.Kingdoms;
|
||||
import org.kingdoms.manager.game.GameManagement;
|
||||
|
||||
public class HookKingdoms implements ProtectionPluginHook {
|
||||
|
||||
private final Kingdoms kingdoms;
|
||||
|
||||
public HookKingdoms() {
|
||||
this.kingdoms = Kingdoms.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() {
|
||||
return kingdoms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.REGULAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
KingdomPlayer kPlayer = GameManagement.getPlayerManager().getOfflineKingdomPlayer(player).getKingdomPlayer();
|
||||
if (kPlayer.getKingdom() == null) return true;
|
||||
|
||||
SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getChunk());
|
||||
Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation);
|
||||
String owner = land.getOwner();
|
||||
|
||||
return owner == null || kPlayer.getKingdom().getKingdomName().equals(owner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getChunk());
|
||||
Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation);
|
||||
String owner = land.getOwner();
|
||||
return owner != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package com.songoda.epicfarming.hook.hooks;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.api.PlotAPI;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.BukkitMain;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.songoda.epicfarming.hook.HookType;
|
||||
import com.songoda.epicfarming.hook.ProtectionPluginHook;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class HookPlotSquared implements ProtectionPluginHook {
|
||||
|
||||
private final PlotAPI plotSquared;
|
||||
|
||||
public HookPlotSquared() {
|
||||
this.plotSquared = new PlotAPI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() { // BukkitMain? Really?
|
||||
return JavaPlugin.getPlugin(BukkitMain.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.REGULAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location plotLocation =
|
||||
new com.github.intellectualsites.plotsquared.plot.object.Location(location.getWorld().getName(),
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
|
||||
Plot plot = plotLocation.getPlot();
|
||||
|
||||
return plot != null
|
||||
&& plot.getOwners().contains(player.getUniqueId())
|
||||
&& plot.getMembers().contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location plotLocation =
|
||||
new com.github.intellectualsites.plotsquared.plot.object.Location(location.getWorld().getName(),
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
|
||||
Plot plot = plotLocation.getPlot();
|
||||
return plot != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package com.songoda.epicfarming.hook.hooks;
|
||||
|
||||
import br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI;
|
||||
import br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect;
|
||||
import br.net.fabiozumbi12.RedProtect.Bukkit.Region;
|
||||
import com.songoda.epicfarming.hook.HookType;
|
||||
import com.songoda.epicfarming.hook.ProtectionPluginHook;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class HookRedProtect implements ProtectionPluginHook {
|
||||
|
||||
private final RedProtect redProtect;
|
||||
|
||||
public HookRedProtect() {
|
||||
this.redProtect = RedProtect.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() {
|
||||
return redProtect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.REGULAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
RedProtectAPI api = redProtect.getAPI();
|
||||
Region region = api.getRegion(location);
|
||||
|
||||
return region != null && region.canBuild(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
RedProtectAPI api = redProtect.getAPI();
|
||||
Region region = api.getRegion(location);
|
||||
return region != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package com.songoda.epicfarming.hook.hooks;
|
||||
|
||||
import com.songoda.epicfarming.hook.HookType;
|
||||
import com.songoda.epicfarming.hook.ProtectionPluginHook;
|
||||
import me.goodandevil.skyblock.SkyBlock;
|
||||
import me.goodandevil.skyblock.island.Island;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class HookSkyBlockEarth implements ProtectionPluginHook {
|
||||
|
||||
private final SkyBlock skyblock;
|
||||
|
||||
public HookSkyBlockEarth() {
|
||||
this.skyblock = SkyBlock.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() {
|
||||
return SkyBlock.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.ISLAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
Island island = skyblock.getIslandManager().getIslandAtLocation(location);
|
||||
if (island == null) return true;
|
||||
|
||||
UUID owner = island.getOwnerUUID();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
if (owner == null || owner.equals(playerUUID)) return true;
|
||||
|
||||
Set<UUID> teamMembers = island.getCoopPlayers();
|
||||
if (teamMembers.contains(playerUUID)) return true;
|
||||
|
||||
List<Island> coopIslands = skyblock.getIslandManager().getCoopIslands(player);
|
||||
for (Island is : coopIslands) {
|
||||
if (is.getOwnerUUID().equals(playerUUID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
return skyblock.getIslandManager().getIslandAtLocation(location) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return skyblock.getIslandManager().getIslandAtLocation(location).getOwnerUUID().toString().equals(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.songoda.epicfarming.hook.hooks;
|
||||
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import com.songoda.epicfarming.hook.HookType;
|
||||
import com.songoda.epicfarming.hook.ProtectionPluginHook;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class HookTowny implements ProtectionPluginHook {
|
||||
|
||||
private final Towny towny;
|
||||
|
||||
public HookTowny() {
|
||||
this.towny = Towny.getPlugin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() {
|
||||
return towny;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.TOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
if (TownyUniverse.isWilderness(location.getBlock()) || !TownyUniverse.getTownBlock(location).hasTown())
|
||||
return true;
|
||||
|
||||
try {
|
||||
Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
|
||||
return resident.hasTown() && TownyUniverse.getTownName(location).equals(resident.getTown().getName());
|
||||
} catch (NotRegisteredException e) {
|
||||
Debugger.runReport(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
return !TownyUniverse.isWilderness(location.getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
try {
|
||||
return (!TownyUniverse.isWilderness(location.getBlock())) && TownyUniverse.getTownBlock(location).getTown().getUID().toString().equals(id);
|
||||
} catch (NotRegisteredException e) {
|
||||
Debugger.runReport(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
try {
|
||||
return TownyUniverse.getDataSource().getTown(name).getUID().toString();
|
||||
} catch (NotRegisteredException e) {
|
||||
Debugger.runReport(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package com.songoda.epicfarming.hook.hooks;
|
||||
|
||||
import com.songoda.epicfarming.hook.HookType;
|
||||
import com.songoda.epicfarming.hook.ProtectionPluginHook;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
|
||||
|
||||
public class HookUSkyBlock implements ProtectionPluginHook {
|
||||
|
||||
private final uSkyBlockAPI uSkyblock;
|
||||
|
||||
public HookUSkyBlock() {
|
||||
this.uSkyblock = (uSkyBlockAPI) Bukkit.getPluginManager().getPlugin("USkyBlock");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() { // uSkyBlockAPI is also an instance of JavaPlugin
|
||||
return (JavaPlugin) uSkyblock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.ISLAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
return uSkyblock.getIslandInfo(location).getOnlineMembers().contains(player) || uSkyblock.getIslandInfo(location).isLeader(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
return uSkyblock.getIslandInfo(location) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return uSkyblock.getIslandInfo(location).getLeader().equals(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package com.songoda.epicfarming.hook.hooks;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import com.songoda.epicfarming.hook.HookType;
|
||||
import com.songoda.epicfarming.hook.ProtectionPluginHook;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class HookWorldGuard implements ProtectionPluginHook {
|
||||
|
||||
private final WorldGuard worldGuard;
|
||||
|
||||
public HookWorldGuard() {
|
||||
this.worldGuard = WorldGuard.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() {
|
||||
return WorldGuardPlugin.inst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.REGULAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
RegionQuery q = worldGuard.getPlatform().getRegionContainer().createQuery();
|
||||
ApplicableRegionSet ars = q.getApplicableRegions(BukkitAdapter.adapt(player.getLocation()));
|
||||
return ars.testState(WorldGuardPlugin.inst().wrapPlayer(player), Flags.BUILD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* ConfigWrapper made by @clip
|
||||
*/
|
||||
public class ConfigWrapper {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
private final String folderName, fileName;
|
||||
private FileConfiguration config;
|
||||
private File configFile;
|
||||
|
||||
public ConfigWrapper(final JavaPlugin instance, final String folderName, final String fileName) {
|
||||
this.plugin = instance;
|
||||
this.folderName = folderName;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public void createNewFile(final String message, final String header) {
|
||||
reloadConfig();
|
||||
saveConfig();
|
||||
loadConfig(header);
|
||||
|
||||
if (message != null) {
|
||||
plugin.getLogger().info(message);
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
if (config == null) {
|
||||
reloadConfig();
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
public void loadConfig(final String header) {
|
||||
config.options().header(header);
|
||||
config.options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
if (configFile == null) {
|
||||
configFile = new File(plugin.getDataFolder() + folderName, fileName);
|
||||
}
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
if (config == null || configFile == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
getConfig().save(configFile);
|
||||
} catch (final IOException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
|
||||
/**
|
||||
* 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 EpicFarming.");
|
||||
System.out.println("--------------------------------------------------------------");
|
||||
e.printStackTrace();
|
||||
System.out.println("==============================================================");
|
||||
}
|
||||
sendReport(e);
|
||||
}
|
||||
|
||||
public static void sendReport(Exception e) {
|
||||
|
||||
}
|
||||
|
||||
public static boolean isDebug() {
|
||||
EpicFarmingPlugin plugin = EpicFarmingPlugin.getInstance();
|
||||
return plugin.getConfig().getBoolean("System.Debugger Enabled");
|
||||
}
|
||||
|
||||
}
|
@ -1,695 +0,0 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* bStats collects some data for plugin authors.
|
||||
* <p>
|
||||
* Check out https://bStats.org/ to learn more about bStats!
|
||||
*/
|
||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||
public class Metrics {
|
||||
|
||||
static {
|
||||
// You can use the property to disable the check in your test environment
|
||||
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
|
||||
final String defaultPackage = new String(
|
||||
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
|
||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||
// We want to make sure nobody just copy & pastes the example and use the wrong package names
|
||||
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
|
||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The version of this bStats class
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
|
||||
// The url to which the data is sent
|
||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
||||
|
||||
// Is bStats enabled on this server?
|
||||
private boolean enabled;
|
||||
|
||||
// Should failed requests be logged?
|
||||
private static boolean logFailedRequests;
|
||||
|
||||
// Should the sent data be logged?
|
||||
private static boolean logSentData;
|
||||
|
||||
// Should the response text be logged?
|
||||
private static boolean logResponseStatusText;
|
||||
|
||||
// The uuid of the server
|
||||
private static String serverUUID;
|
||||
|
||||
// The plugin
|
||||
private final Plugin plugin;
|
||||
|
||||
// A list with all custom charts
|
||||
private final List<CustomChart> charts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param plugin The plugin which stats should be submitted.
|
||||
*/
|
||||
public Metrics(Plugin plugin) {
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("Plugin cannot be null!");
|
||||
}
|
||||
this.plugin = plugin;
|
||||
|
||||
// Get the config file
|
||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||
File configFile = new File(bStatsFolder, "config.yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
// Check if the config file exists
|
||||
if (!config.isSet("serverUuid")) {
|
||||
|
||||
// Add default values
|
||||
config.addDefault("enabled", true);
|
||||
// Every server gets it's unique random id.
|
||||
config.addDefault("serverUuid", UUID.randomUUID().toString());
|
||||
// Should failed request be logged?
|
||||
config.addDefault("logFailedRequests", false);
|
||||
// Should the sent data be logged?
|
||||
config.addDefault("logSentData", false);
|
||||
// Should the response text be logged?
|
||||
config.addDefault("logResponseStatusText", false);
|
||||
|
||||
// Inform the server owners about bStats
|
||||
config.options().header(
|
||||
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
|
||||
"To honor their work, you should not disable it.\n" +
|
||||
"This has nearly no effect on the server performance!\n" +
|
||||
"Check out https://bStats.org/ to learn more :)"
|
||||
).copyDefaults(true);
|
||||
try {
|
||||
config.save(configFile);
|
||||
} catch (IOException ignored) { }
|
||||
}
|
||||
|
||||
// Load the data
|
||||
enabled = config.getBoolean("enabled", true);
|
||||
serverUUID = config.getString("serverUuid");
|
||||
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
||||
logSentData = config.getBoolean("logSentData", false);
|
||||
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
||||
|
||||
if (enabled) {
|
||||
boolean found = false;
|
||||
// Search for all other bStats Metrics classes to see if we are the first one
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
found = true; // We aren't the first
|
||||
break;
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
}
|
||||
// Register our service
|
||||
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
|
||||
if (!found) {
|
||||
// We are the first!
|
||||
startSubmitting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if bStats is enabled.
|
||||
*
|
||||
* @return Whether bStats is enabled or not.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom chart.
|
||||
*
|
||||
* @param chart The chart to add.
|
||||
*/
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
if (chart == null) {
|
||||
throw new IllegalArgumentException("Chart cannot be null!");
|
||||
}
|
||||
charts.add(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Scheduler which submits our data every 30 minutes.
|
||||
*/
|
||||
private void startSubmitting() {
|
||||
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!plugin.isEnabled()) { // Plugin was disabled
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
||||
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
||||
Bukkit.getScheduler().runTask(plugin, () -> submitData());
|
||||
}
|
||||
}, 1000 * 60 * 5, 1000 * 60 * 30);
|
||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
||||
// WARNING: Just don't do it!
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin specific data.
|
||||
* This method is called using Reflection.
|
||||
*
|
||||
* @return The plugin specific data.
|
||||
*/
|
||||
public JSONObject getPluginData() {
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
String pluginName = plugin.getDescription().getName();
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
|
||||
data.put("pluginName", pluginName); // Append the name of the plugin
|
||||
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
|
||||
JSONArray customCharts = new JSONArray();
|
||||
for (CustomChart customChart : charts) {
|
||||
// Add the data of the custom charts
|
||||
JSONObject chart = customChart.getRequestJsonObject();
|
||||
if (chart == null) { // If the chart is null, we skip it
|
||||
continue;
|
||||
}
|
||||
customCharts.add(chart);
|
||||
}
|
||||
data.put("customCharts", customCharts);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server specific data.
|
||||
*
|
||||
* @return The server specific data.
|
||||
*/
|
||||
private JSONObject getServerData() {
|
||||
// Minecraft specific data
|
||||
int playerAmount;
|
||||
try {
|
||||
// Around MC 1.8 the return type was changed to a collection from an array,
|
||||
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||
} catch (Exception e) {
|
||||
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
|
||||
}
|
||||
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
||||
String bukkitVersion = Bukkit.getVersion();
|
||||
|
||||
// OS/Java specific data
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
String osName = System.getProperty("os.name");
|
||||
String osArch = System.getProperty("os.arch");
|
||||
String osVersion = System.getProperty("os.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
data.put("serverUUID", serverUUID);
|
||||
|
||||
data.put("playerAmount", playerAmount);
|
||||
data.put("onlineMode", onlineMode);
|
||||
data.put("bukkitVersion", bukkitVersion);
|
||||
|
||||
data.put("javaVersion", javaVersion);
|
||||
data.put("osName", osName);
|
||||
data.put("osArch", osArch);
|
||||
data.put("osVersion", osVersion);
|
||||
data.put("coreCount", coreCount);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the data and sends it afterwards.
|
||||
*/
|
||||
private void submitData() {
|
||||
final JSONObject data = getServerData();
|
||||
|
||||
JSONArray pluginData = new JSONArray();
|
||||
// Search for all other bStats Metrics classes to get their plugin data
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
|
||||
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
|
||||
try {
|
||||
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
|
||||
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
|
||||
}
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
}
|
||||
|
||||
data.put("plugins", pluginData);
|
||||
|
||||
// Create a new thread for the connection to the bStats server
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// Send the data
|
||||
sendData(plugin, data);
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the data to the bStats server.
|
||||
*
|
||||
* @param plugin Any plugin. It's just used to get a logger instance.
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(Plugin plugin, JSONObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data.toString());
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
|
||||
// Add headers
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
// Send data
|
||||
connection.setDoOutput(true);
|
||||
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
|
||||
outputStream.write(compressedData);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
bufferedReader.close();
|
||||
if (logResponseStatusText) {
|
||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given String.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
gzip.close();
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom chart.
|
||||
*/
|
||||
public static abstract class CustomChart {
|
||||
|
||||
// The id of the chart
|
||||
final String chartId;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
CustomChart(String chartId) {
|
||||
if (chartId == null || chartId.isEmpty()) {
|
||||
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
||||
}
|
||||
this.chartId = chartId;
|
||||
}
|
||||
|
||||
private JSONObject getRequestJsonObject() {
|
||||
JSONObject chart = new JSONObject();
|
||||
chart.put("chartId", chartId);
|
||||
try {
|
||||
JSONObject data = getChartData();
|
||||
if (data == null) {
|
||||
// If the data is null we don't send the chart.
|
||||
return null;
|
||||
}
|
||||
chart.put("data", data);
|
||||
} catch (Throwable t) {
|
||||
if (logFailedRequests) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return chart;
|
||||
}
|
||||
|
||||
protected abstract JSONObject getChartData() throws Exception;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple pie.
|
||||
*/
|
||||
public static class SimplePie extends CustomChart {
|
||||
|
||||
private final Callable<String> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimplePie(String chartId, Callable<String> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
String value = callable.call();
|
||||
if (value == null || value.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced pie.
|
||||
*/
|
||||
public static class AdvancedPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom drilldown pie.
|
||||
*/
|
||||
public static class DrilldownPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Map<String, Integer>> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean reallyAllSkipped = true;
|
||||
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||
JSONObject value = new JSONObject();
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||
value.put(valueEntry.getKey(), valueEntry.getValue());
|
||||
allSkipped = false;
|
||||
}
|
||||
if (!allSkipped) {
|
||||
reallyAllSkipped = false;
|
||||
values.put(entryValues.getKey(), value);
|
||||
}
|
||||
}
|
||||
if (reallyAllSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom single line chart.
|
||||
*/
|
||||
public static class SingleLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Integer> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
int value = callable.call();
|
||||
if (value == 0) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom multi line chart.
|
||||
*/
|
||||
public static class MultiLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple bar chart.
|
||||
*/
|
||||
public static class SimpleBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
categoryValues.add(entry.getValue());
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced bar chart.
|
||||
*/
|
||||
public static class AdvancedBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, int[]>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, int[]> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
||||
if (entry.getValue().length == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
for (int categoryValue : entry.getValue()) {
|
||||
categoryValues.add(categoryValue);
|
||||
}
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MySQLDatabase {
|
||||
|
||||
private final EpicFarmingPlugin instance;
|
||||
|
||||
private Connection connection;
|
||||
|
||||
public MySQLDatabase(EpicFarmingPlugin instance) {
|
||||
this.instance = instance;
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
|
||||
String url = "jdbc:mysql://" + instance.getConfig().getString("Database.IP") + ":" + instance.getConfig().getString("Database.Port") + "/" + instance.getConfig().getString("Database.Database Name") + "?autoReconnect=true&useSSL=false";
|
||||
this.connection = DriverManager.getConnection(url, instance.getConfig().getString("Database.Username"), instance.getConfig().getString("Database.Password"));
|
||||
|
||||
//ToDo: This is sloppy
|
||||
connection.createStatement().execute(
|
||||
"CREATE TABLE IF NOT EXISTS `" + instance.getConfig().getString("Database.Prefix") + "farms` (\n" +
|
||||
"\t`location` TEXT NULL,\n" +
|
||||
"\t`level` INT NULL,\n" +
|
||||
"\t`placedby` TEXT NULL,\n" +
|
||||
"\t`contents` TEXT NULL \n"+
|
||||
")");
|
||||
|
||||
connection.createStatement().execute("CREATE TABLE IF NOT EXISTS `" + instance.getConfig().getString("Database.Prefix") + "boosts` (\n" +
|
||||
"\t`endtime` TEXT NULL,\n" +
|
||||
"\t`amount` INT NULL,\n" +
|
||||
"\t`player` TEXT NULL\n" +
|
||||
")");
|
||||
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
System.out.println("Database connection failed.");
|
||||
}
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.songoda.epicfarming.utils.updateModules;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.update.Module;
|
||||
import com.songoda.update.Plugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
public class LocaleModule implements Module {
|
||||
|
||||
@Override
|
||||
public void run(Plugin plugin) {
|
||||
JSONObject json = plugin.getJson();
|
||||
try {
|
||||
JSONArray files = (JSONArray) json.get("neededFiles");
|
||||
for (Object o : files) {
|
||||
JSONObject file = (JSONObject) o;
|
||||
|
||||
if (file.get("type").equals("locale")) {
|
||||
InputStream in = new URL((String) file.get("link")).openStream();
|
||||
EpicFarmingPlugin.getInstance().getLocale().saveDefaultLocale(in, (String) file.get("name"));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
|
@ -1,34 +0,0 @@
|
||||
#General Messages
|
||||
|
||||
general.nametag.prefix = "&8[&6EpicFarming&8]"
|
||||
general.nametag.farm = "&eLevel %level% &fFarm"
|
||||
general.nametag.lore = ""
|
||||
|
||||
#Interface Messages
|
||||
|
||||
interface.button.upgradewithxp = "&aUpgrade with XP"
|
||||
interface.button.upgradewithxplore = "&7Cost: &a%cost% Levels"
|
||||
interface.button.upgradewitheconomy = "&aUpgrade with ECO"
|
||||
interface.button.upgradewitheconomylore = "&7Cost: &a$%cost%"
|
||||
interface.button.level = "&6Next Level &7%level%"
|
||||
interface.button.radius = "&7Radius: &6%speed%"
|
||||
interface.button.speed = "&7Speed: &6%speed%x"
|
||||
interface.button.autoharvest = "&7Auto Harvest: &6%status%"
|
||||
interface.button.autoreplant = "&7Auto Replant: &6%status%"
|
||||
interface.button.autobreeding = "&7Auto Breeding: &6%status%"
|
||||
interface.button.boostedstats = "&a&lCurrently boosted!|&7Yield rate multiplied by &6%amount%x&7.|&7Expires in &6%time%&7."
|
||||
|
||||
|
||||
#Command Messages
|
||||
|
||||
command.give.success = "&7You have been given a &6level %level% &7farm item."
|
||||
|
||||
#Event Messages
|
||||
|
||||
event.general.nopermission = "&cYou do not have permission to do that."
|
||||
event.upgrade.cannotafford = "&cYou cannot afford this upgrade."
|
||||
event.upgrade.success = "&7You successfully upgraded this farm to &6level %level%&7!"
|
||||
event.upgrade.maxed = "&6This farm is maxed out."
|
||||
event.upgrade.successmaxed = "&7You maxed out this farm at &6%level%x&7."
|
||||
event.limit.hit = "&7You can only have &6%limit% &7farms at a single time."
|
||||
event.warning.noauto = "&6Warning: &cThis item does not get farmed automatically"
|
@ -1,13 +0,0 @@
|
||||
n ame: EpicFarming
|
||||
description: EpicFarming
|
||||
main: com.songoda.epicfarming.EpicFarmingPlugin
|
||||
version: maven-version-number
|
||||
softdepend: [Arconix, SkyBlock, Towny, RedProtect, Kingdoms, PlotSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, PlaceholderAPI]
|
||||
author: Songoda
|
||||
api-version: 1.13
|
||||
commands:
|
||||
EpicFarming:
|
||||
description: View information on this plugin.
|
||||
default: true
|
||||
aliases: [efa]
|
||||
usage: /efa
|
77
pom.xml
77
pom.xml
@ -1,28 +1,11 @@
|
||||
<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>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicFarming-Parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<artifactId>EpicFurnaces</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>maven-version-number</version>
|
||||
|
||||
<modules>
|
||||
<module>EpicFarming-API</module>
|
||||
<module>EpicFarming-Plugin</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.14.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>EpicFurnaces-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@ -33,6 +16,45 @@
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>shaded</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<shadedArtifactAttached>false</shadedArtifactAttached>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.songoda:SongodaCore</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.songoda.core</pattern>
|
||||
<shadedPattern>${project.groupId}.epicfarming.core</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
@ -41,4 +63,17 @@
|
||||
<url>http://repo.songoda.com/artifactory/private/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.14.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,14 +1,16 @@
|
||||
package com.songoda.epicfarming;
|
||||
|
||||
import com.songoda.epicfarming.api.EpicFarming;
|
||||
import com.songoda.epicfarming.api.farming.Level;
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.commands.CommandManager;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.epicfarming.boost.BoostData;
|
||||
import com.songoda.epicfarming.boost.BoostManager;
|
||||
import com.songoda.epicfarming.command.CommandManager;
|
||||
import com.songoda.epicfarming.farming.EFarm;
|
||||
import com.songoda.epicfarming.farming.EFarmManager;
|
||||
import com.songoda.epicfarming.farming.ELevelManager;
|
||||
import com.songoda.epicfarming.hook.HookManager;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.farming.FarmManager;
|
||||
import com.songoda.epicfarming.farming.Level;
|
||||
import com.songoda.epicfarming.farming.LevelManager;
|
||||
import com.songoda.epicfarming.listeners.BlockListeners;
|
||||
import com.songoda.epicfarming.listeners.InteractListeners;
|
||||
import com.songoda.epicfarming.listeners.InventoryListeners;
|
||||
@ -22,29 +24,16 @@ import com.songoda.epicfarming.tasks.EntityTask;
|
||||
import com.songoda.epicfarming.tasks.FarmTask;
|
||||
import com.songoda.epicfarming.tasks.GrowthTask;
|
||||
import com.songoda.epicfarming.tasks.HopperTask;
|
||||
import com.songoda.epicfarming.utils.*;
|
||||
import com.songoda.epicfarming.utils.updateModules.LocaleModule;
|
||||
import com.songoda.update.Plugin;
|
||||
import com.songoda.update.SongodaUpdate;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -52,21 +41,18 @@ import java.util.UUID;
|
||||
/**
|
||||
* Created by songoda on 1/23/2018.
|
||||
*/
|
||||
public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
public class EpicFarming extends SongodaPlugin {
|
||||
|
||||
private static EpicFarmingPlugin INSTANCE;
|
||||
private static EpicFarming INSTANCE;
|
||||
|
||||
private SettingsManager settingsManager;
|
||||
private References references;
|
||||
private ConfigWrapper hooksFile = new ConfigWrapper(this, "", "hooks.yml");
|
||||
private ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml");
|
||||
private Locale locale;
|
||||
private EFarmManager farmManager;
|
||||
private ELevelManager levelManager;
|
||||
private final Config dataConfig = new Config(this, "data.yml");
|
||||
private final Config levelsFile = new Config(this, "levels.yml");
|
||||
|
||||
private FarmManager farmManager;
|
||||
private LevelManager levelManager;
|
||||
private PlayerActionManager playerActionManager;
|
||||
private CommandManager commandManager;
|
||||
private BoostManager boostManager;
|
||||
private HookManager hookManager;
|
||||
|
||||
private GrowthTask growthTask;
|
||||
private FarmTask farmTask;
|
||||
@ -74,39 +60,32 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
|
||||
private Storage storage;
|
||||
|
||||
public static EpicFarmingPlugin getInstance() {
|
||||
public static EpicFarming getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private boolean checkVersion() {
|
||||
int workingVersion = 13;
|
||||
int currentVersion = Integer.parseInt(Bukkit.getServer().getClass()
|
||||
.getPackage().getName().split("\\.")[3].split("_")[1]);
|
||||
|
||||
if (currentVersion < workingVersion) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
|
||||
Bukkit.getConsoleSender().sendMessage("");
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "You installed the 1." + workingVersion + "+ only version of " + this.getDescription().getName() + " on a 1." + currentVersion + " server. Since you are on the wrong version we disabled the plugin for you. Please install correct version to continue using " + this.getDescription().getName() + ".");
|
||||
Bukkit.getConsoleSender().sendMessage("");
|
||||
}, 20L);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@Override
|
||||
public void onPluginLoad() {
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Check to make sure the Bukkit version is compatible.
|
||||
if (!checkVersion()) return;
|
||||
public void onPluginDisable() {
|
||||
saveToFile();
|
||||
this.storage.closeConnection();
|
||||
for (PlayerData playerData : playerActionManager.getRegisteredPlayers()) {
|
||||
if (playerData.getPlayer() != null)
|
||||
playerData.getPlayer().closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginEnable() {
|
||||
// Run Songoda Updater
|
||||
SongodaCore.registerPlugin(this, 21, CompatibleMaterial.WHEAT);
|
||||
|
||||
checkStorage();
|
||||
INSTANCE = this;
|
||||
|
||||
CommandSender console = Bukkit.getConsoleSender();
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
console.sendMessage(Methods.formatText("&7EpicFarming " + this.getDescription().getVersion() + " by &5Songoda <3&7!"));
|
||||
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
|
||||
|
||||
this.settingsManager = new SettingsManager(this);
|
||||
this.setupConfig();
|
||||
|
||||
// Setup language
|
||||
@ -115,21 +94,15 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
Locale.saveDefaultLocale("en_US");
|
||||
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode", langMode));
|
||||
|
||||
//Running Songoda Updater
|
||||
Plugin plugin = new Plugin(this, 21);
|
||||
plugin.addModule(new LocaleModule());
|
||||
SongodaUpdate.load(plugin);
|
||||
|
||||
dataFile.createNewFile("Loading Data File", "EpicFarming Data File");
|
||||
this.loadDataFile();
|
||||
|
||||
this.loadLevelManager();
|
||||
|
||||
this.farmManager = new EFarmManager();
|
||||
this.farmManager = new FarmManager();
|
||||
this.playerActionManager = new PlayerActionManager();
|
||||
this.boostManager = new BoostManager();
|
||||
this.commandManager = new CommandManager(this);
|
||||
this.hookManager = new HookManager(this);
|
||||
|
||||
/*
|
||||
* Register Farms into FarmManger from configuration
|
||||
@ -141,11 +114,11 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
if (location == null || location.getWorld() == null) return;
|
||||
|
||||
int level = row.get("level").asInt();
|
||||
List<ItemStack> items =row.get("contents").asItemStackList();
|
||||
List<ItemStack> items = row.get("contents").asItemStackList();
|
||||
UUID placedBY = UUID.fromString(row.get("placedby").asString());
|
||||
EFarm farm = new EFarm(location,levelManager.getLevel(level),placedBY);
|
||||
Farm farm = new Farm(location, levelManager.getLevel(level), placedBY);
|
||||
farm.loadInventory(items);
|
||||
farmManager.addFarm(location,farm);
|
||||
farmManager.addFarm(location, farm);
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,11 +162,6 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
}, 20L);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000);
|
||||
|
||||
// Start Metrics
|
||||
new Metrics(this);
|
||||
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
}
|
||||
|
||||
private void checkStorage() {
|
||||
@ -204,23 +172,13 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
}
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
saveToFile();
|
||||
this.storage.closeConnection();
|
||||
for (PlayerData playerData : playerActionManager.getRegisteredPlayers()) {
|
||||
if (playerData.getPlayer() != null)
|
||||
playerData.getPlayer().closeInventory();
|
||||
}
|
||||
CommandSender console = Bukkit.getConsoleSender();
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
console.sendMessage(Methods.formatText("&7EpicFarming " + this.getDescription().getVersion() + " by &5Brianna <3!"));
|
||||
console.sendMessage(Methods.formatText("&7Action: &cDisabling&7..."));
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
}
|
||||
|
||||
private void loadLevelManager() {
|
||||
if (!levelsFile.getFile().exists())
|
||||
this.saveResource("levels.yml", false);
|
||||
levelsFile.load();
|
||||
|
||||
// Load an instance of LevelManager
|
||||
levelManager = new ELevelManager();
|
||||
levelManager = new LevelManager();
|
||||
|
||||
/*
|
||||
* Register Levels into LevelManager from configuration.
|
||||
@ -256,61 +214,6 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void setupConfig() {
|
||||
settingsManager.updateSettings();
|
||||
|
||||
if (!getConfig().contains("settings.levels.Level-1")) {
|
||||
ConfigurationSection levels =
|
||||
getConfig().createSection("settings.levels");
|
||||
|
||||
levels.set("Level-1.Radius", 1);
|
||||
levels.set("Level-1.Speed-Multiplier", 1);
|
||||
levels.set("Level-1.Cost-xp", 20);
|
||||
levels.set("Level-1.Cost-eco", 5000);
|
||||
|
||||
levels.set("Level-2.Radius", 2);
|
||||
levels.set("Level-2.Speed-Multiplier", 1.5);
|
||||
levels.set("Level-2.Auto-Harvest", true);
|
||||
levels.set("Level-2.Cost-xp", 20);
|
||||
levels.set("Level-2.Cost-eco", 5000);
|
||||
|
||||
levels.set("Level-3.Radius", 3);
|
||||
levels.set("Level-3.Speed-Multiplier", 1.5);
|
||||
levels.set("Level-3.Auto-Harvest", true);
|
||||
levels.set("Level-3.Auto-Replant", true);
|
||||
levels.set("Level-3.Auto-Breeding", true);
|
||||
levels.set("Level-3.Cost-xp", 25);
|
||||
levels.set("Level-3.Cost-eco", 7500);
|
||||
|
||||
levels.set("Level-4.Radius", 3);
|
||||
levels.set("Level-4.Speed-Multiplier", 2);
|
||||
levels.set("Level-4.Auto-Harvest", true);
|
||||
levels.set("Level-4.Auto-Replant", true);
|
||||
levels.set("Level-4.Auto-Breeding", true);
|
||||
levels.set("Level-4.Cost-xp", 30);
|
||||
levels.set("Level-4.Cost-eco", 10000);
|
||||
|
||||
levels.set("Level-5.Radius", 3);
|
||||
levels.set("Level-5.Speed-Multiplier", 2.5);
|
||||
levels.set("Level-5.Auto-Harvest", true);
|
||||
levels.set("Level-5.Auto-Replant", true);
|
||||
levels.set("Level-5.Auto-Breeding", true);
|
||||
levels.set("Level-5.Cost-xp", 35);
|
||||
levels.set("Level-5.Cost-eco", 12000);
|
||||
|
||||
levels.set("Level-6.Radius", 4);
|
||||
levels.set("Level-6.Speed-Multiplier", 3);
|
||||
levels.set("Level-6.Auto-Harvest", true);
|
||||
levels.set("Level-6.Auto-Replant", true);
|
||||
levels.set("Level-6.Auto-Breeding", true);
|
||||
levels.set("Level-6.Cost-xp", 40);
|
||||
levels.set("Level-6.Cost-eco", 25000);
|
||||
}
|
||||
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void loadDataFile() {
|
||||
dataFile.getConfig().options().copyDefaults(true);
|
||||
dataFile.saveConfig();
|
||||
@ -320,22 +223,16 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
return locale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevelFromItem(ItemStack item) {
|
||||
try {
|
||||
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) return 0;
|
||||
if (item.getItemMeta().getDisplayName().contains(":")) {
|
||||
return NumberUtils.toInt(item.getItemMeta().getDisplayName().replace("\u00A7", "").split(":")[0], 0);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) return 0;
|
||||
if (item.getItemMeta().getDisplayName().contains(":")) {
|
||||
return NumberUtils.toInt(item.getItemMeta().getDisplayName().replace("\u00A7", "").split(":")[0], 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack makeFarmItem(Level level) {
|
||||
ItemStack item = new ItemStack(Material.valueOf(EpicFarmingPlugin.getInstance().getConfig().getString("Main.Farm Block Material")), 1);
|
||||
ItemStack item = new ItemStack(Material.valueOf(EpicFarming.getInstance().getConfig().getString("Main.Farm Block Material")), 1);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Methods.formatText(Methods.formatName(level.getLevel(), true)));
|
||||
String line = getLocale().getMessage("general.nametag.lore");
|
||||
@ -344,24 +241,14 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EFarmManager getFarmManager() {
|
||||
public FarmManager getFarmManager() {
|
||||
return farmManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ELevelManager getLevelManager() {
|
||||
public LevelManager getLevelManager() {
|
||||
return levelManager;
|
||||
}
|
||||
|
||||
public References getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
||||
public SettingsManager getSettingsManager() {
|
||||
return settingsManager;
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
@ -374,10 +261,6 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
return playerActionManager;
|
||||
}
|
||||
|
||||
public HookManager getHookManager() {
|
||||
return hookManager;
|
||||
}
|
||||
|
||||
public GrowthTask getGrowthTask() {
|
||||
return growthTask;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfarming.command.commands;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.boost.BoostData;
|
||||
import com.songoda.epicfarming.command.AbstractCommand;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
@ -17,7 +17,7 @@ public class CommandBoost extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicFarmingPlugin instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(EpicFarming instance, CommandSender sender, String... args) {
|
||||
if (args.length < 3) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfarming.command.commands;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.command.AbstractCommand;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -12,7 +12,7 @@ public class CommandEpicFarming extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicFarmingPlugin instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(EpicFarming instance, CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.epicfarming.command.commands;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.command.AbstractCommand;
|
||||
import com.songoda.epicfarming.farming.ELevel;
|
||||
import com.songoda.epicfarming.farming.Level;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -15,10 +15,10 @@ public class CommandGiveFarmItem extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicFarmingPlugin instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(EpicFarming instance, CommandSender sender, String... args) {
|
||||
if (args.length == 2) return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
ELevel level = instance.getLevelManager().getLowestLevel();
|
||||
Level level = instance.getLevelManager().getLowestLevel();
|
||||
Player player;
|
||||
if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cThat player does not exist or is currently offline."));
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfarming.command.commands;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.command.AbstractCommand;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -12,7 +12,7 @@ public class CommandReload extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicFarmingPlugin instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(EpicFarming instance, CommandSender sender, String... args) {
|
||||
instance.reload();
|
||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Configuration and Language files reloaded."));
|
||||
return ReturnType.SUCCESS;
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfarming.command.commands;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.command.AbstractCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -12,7 +12,7 @@ public class CommandSettings extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicFarmingPlugin instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(EpicFarming instance, CommandSender sender, String... args) {
|
||||
instance.getSettingsManager().openSettingsManager((Player)sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.songoda.epicfarming.farming;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.api.farming.Farm;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.api.farming.Level;
|
||||
import com.songoda.epicfarming.api.farming.UpgradeType;
|
||||
import com.songoda.epicfarming.boost.BoostData;
|
||||
@ -26,7 +25,7 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
public class EFarm implements Farm {
|
||||
public class Farm {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private final List<Block> cachedCrops = new ArrayList<>();
|
||||
@ -37,7 +36,7 @@ public class EFarm implements Farm {
|
||||
private UUID viewing = null;
|
||||
private long lastCached = 0;
|
||||
|
||||
public EFarm(Location location, Level level, UUID placedBy) {
|
||||
public Farm(Location location, Level level, UUID placedBy) {
|
||||
this.location = location;
|
||||
this.level = level;
|
||||
this.placedBy = placedBy;
|
||||
@ -45,26 +44,21 @@ public class EFarm implements Farm {
|
||||
}
|
||||
|
||||
public void view(Player player) {
|
||||
try {
|
||||
if (!player.hasPermission("epicfarming.view"))
|
||||
return;
|
||||
if (!player.hasPermission("epicfarming.view"))
|
||||
return;
|
||||
|
||||
if (viewing != null) return;
|
||||
if (viewing != null) return;
|
||||
|
||||
setupOverview(player);
|
||||
setupOverview(player);
|
||||
|
||||
player.openInventory(inventory);
|
||||
this.viewing = player.getUniqueId();
|
||||
player.openInventory(inventory);
|
||||
this.viewing = player.getUniqueId();
|
||||
|
||||
PlayerData playerData = EpicFarmingPlugin.getInstance().getPlayerActionManager().getPlayerAction(player);
|
||||
PlayerData playerData = EpicFarming.getInstance().getPlayerActionManager().getPlayerAction(player);
|
||||
|
||||
playerData.setFarm(this);
|
||||
playerData.setFarm(this);
|
||||
|
||||
getInventory();
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
getInventory();
|
||||
}
|
||||
|
||||
private void setupOverview(Player player) {
|
||||
@ -72,9 +66,9 @@ public class EFarm implements Farm {
|
||||
inventory.setContents(this.inventory.getContents());
|
||||
this.inventory = inventory;
|
||||
|
||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
|
||||
ELevel nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel() + 1) : null;
|
||||
Level nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel() + 1) : null;
|
||||
|
||||
int level = this.level.getLevel();
|
||||
|
||||
@ -155,7 +149,6 @@ public class EFarm implements Farm {
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
@ -180,7 +173,7 @@ public class EFarm implements Farm {
|
||||
|
||||
public void upgrade(UpgradeType type, Player player) {
|
||||
try {
|
||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
if (instance.getLevelManager().getLevels().containsKey(this.level.getLevel() + 1)) {
|
||||
|
||||
com.songoda.epicfarming.api.farming.Level level = instance.getLevelManager().getLevel(this.level.getLevel() + 1);
|
||||
@ -222,7 +215,7 @@ public class EFarm implements Farm {
|
||||
|
||||
private void upgradeFinal(Level level, Player player) {
|
||||
try {
|
||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
this.level = level;
|
||||
if (instance.getLevelManager().getHighestLevel() != level) {
|
||||
player.sendMessage(instance.getLocale().getMessage("event.upgrade.success", level.getLevel()));
|
||||
@ -248,7 +241,7 @@ public class EFarm implements Farm {
|
||||
|
||||
public boolean tillLand(Location location) {
|
||||
Player player = Bukkit.getPlayer(placedBy);
|
||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
if (instance.getConfig().getBoolean("Main.Disable Auto Til Land")) return true;
|
||||
Block block = location.getBlock();
|
||||
int radius = level.getRadius();
|
||||
@ -264,7 +257,7 @@ public class EFarm implements Farm {
|
||||
// ToDo: enum for all flowers.
|
||||
if (b2.getType() == Material.TALL_GRASS || b2.getType() == Material.GRASS || b2.getType().name().contains("TULIP") || b2.getType() == Material.AZURE_BLUET ||
|
||||
b2.getType() == Material.BLUE_ORCHID || b2.getType() == Material.ALLIUM || b2.getType() == Material.POPPY || b2.getType() == Material.DANDELION) {
|
||||
Bukkit.getScheduler().runTaskLater(EpicFarmingPlugin.getInstance(), () -> {
|
||||
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
|
||||
b2.getRelative(BlockFace.DOWN).setType(Material.LEGACY_SOIL);
|
||||
b2.breakNaturally();
|
||||
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
|
||||
@ -273,7 +266,7 @@ public class EFarm implements Farm {
|
||||
}, random.nextInt(30) + 1);
|
||||
}
|
||||
if ((b2.getType() == Material.GRASS_BLOCK || b2.getType() == Material.DIRT) && b2.getRelative(BlockFace.UP).getType() == Material.AIR) {
|
||||
Bukkit.getScheduler().runTaskLater(EpicFarmingPlugin.getInstance(), () -> {
|
||||
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
|
||||
b2.setType(Material.LEGACY_SOIL);
|
||||
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
|
||||
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
|
||||
@ -303,7 +296,6 @@ public class EFarm implements Farm {
|
||||
cachedCrops.remove(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Block> getCachedCrops() {
|
||||
return new ArrayList<>(cachedCrops);
|
||||
}
|
||||
@ -320,22 +312,18 @@ public class EFarm implements Farm {
|
||||
this.lastCached = lastCached;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return location.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getPlacedBy() {
|
||||
return placedBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
package com.songoda.epicfarming.farming;
|
||||
|
||||
import com.songoda.epicfarming.api.farming.Farm;
|
||||
import com.songoda.epicfarming.api.farming.FarmManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
@ -9,31 +7,26 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class EFarmManager implements FarmManager {
|
||||
public class FarmManager {
|
||||
|
||||
private final Map<Location, Farm> registeredFarms = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void addFarm(Location location, Farm farm) {
|
||||
registeredFarms.put(roundLocation(location), farm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Farm removeFarm(Location location) {
|
||||
return registeredFarms.remove(roundLocation(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Farm getFarm(Location location) {
|
||||
return registeredFarms.get(roundLocation(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Farm getFarm(Block block) {
|
||||
return getFarm(block.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Location, Farm> getFarms() {
|
||||
return Collections.unmodifiableMap(registeredFarms);
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
package com.songoda.epicfarming.farming;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.api.farming.Level;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ELevel implements Level {
|
||||
public class Level {
|
||||
|
||||
private int level, costExperiance, costEconomy, radius;
|
||||
|
||||
@ -16,7 +15,7 @@ public class ELevel implements Level {
|
||||
|
||||
private List<String> description = new ArrayList<>();
|
||||
|
||||
ELevel(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant, boolean autoBreeding) {
|
||||
Level(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant, boolean autoBreeding) {
|
||||
this.level = level;
|
||||
this.costExperiance = costExperiance;
|
||||
this.costEconomy = costEconomy;
|
||||
@ -26,7 +25,7 @@ public class ELevel implements Level {
|
||||
this.autoReplant = autoReplant;
|
||||
this.autoBreeding = autoBreeding;
|
||||
|
||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
|
||||
description.add(instance
|
||||
.getLocale()
|
||||
@ -45,45 +44,38 @@ public class ELevel implements Level {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDescription() {
|
||||
return new ArrayList<>(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoHarvest() {
|
||||
return autoHarvest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoReplant() {
|
||||
return autoReplant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoBreeding() { return autoBreeding; }
|
||||
public boolean isAutoBreeding() {
|
||||
return autoBreeding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getSpeedMultiplier() {
|
||||
return speedMultiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCostExperiance() {
|
||||
return costExperiance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCostEconomy() {
|
||||
return costEconomy;
|
||||
}
|
@ -1,48 +1,38 @@
|
||||
package com.songoda.epicfarming.farming;
|
||||
|
||||
import com.songoda.epicfarming.api.farming.Level;
|
||||
import com.songoda.epicfarming.api.farming.LevelManager;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class ELevelManager implements LevelManager {
|
||||
public class LevelManager {
|
||||
|
||||
private final NavigableMap<Integer, ELevel> registeredLevels = new TreeMap<>();
|
||||
private final NavigableMap<Integer, Level> registeredLevels = new TreeMap<>();
|
||||
|
||||
@Override
|
||||
public void addLevel(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant, boolean autobreeding) {
|
||||
registeredLevels.put(level, new ELevel(level, costExperiance, costEconomy, speedMultiplier, radius, autoHarvest, autoReplant, autobreeding));
|
||||
registeredLevels.put(level, new Level(level, costExperiance, costEconomy, speedMultiplier, radius, autoHarvest, autoReplant, autobreeding));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ELevel getLevel(int level) {
|
||||
public Level getLevel(int level) {
|
||||
return registeredLevels.get(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ELevel getLowestLevel() {
|
||||
public Level getLowestLevel() {
|
||||
return registeredLevels.firstEntry().getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ELevel getHighestLevel() {
|
||||
public Level getHighestLevel() {
|
||||
return registeredLevels.lastEntry().getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLevel(int level) {
|
||||
return registeredLevels.containsKey(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Level> getLevels() {
|
||||
return Collections.unmodifiableMap(registeredLevels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
registeredLevels.clear();
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
package com.songoda.epicfarming.api.farming;
|
||||
package com.songoda.epicfarming.farming;
|
||||
|
||||
public enum UpgradeType {
|
||||
EXPERIENCE, ECONOMY
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package com.songoda.epicfarming.listeners;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.api.farming.Farm;
|
||||
import com.songoda.epicfarming.api.farming.Level;
|
||||
import com.songoda.epicfarming.farming.EFarm;
|
||||
import com.songoda.epicfarming.farming.EFarmManager;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.farming.FarmManager;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -32,9 +32,9 @@ import java.util.Collection;
|
||||
@SuppressWarnings("Duplicates")
|
||||
public class BlockListeners implements Listener {
|
||||
|
||||
private EpicFarmingPlugin instance;
|
||||
private EpicFarming instance;
|
||||
|
||||
public BlockListeners(EpicFarmingPlugin instance) {
|
||||
public BlockListeners(EpicFarming instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ public class BlockListeners implements Listener {
|
||||
|
||||
if (location.getBlock().getType() != farmBlock) return;
|
||||
|
||||
EFarm farm = new EFarm(location, instance.getLevelManager().getLevel(level), e.getPlayer().getUniqueId());
|
||||
Farm farm = new Farm(location, instance.getLevelManager().getLevel(level), e.getPlayer().getUniqueId());
|
||||
instance.getFarmManager().addFarm(location, farm);
|
||||
|
||||
farm.tillLand(e.getBlock().getLocation());
|
||||
@ -123,7 +123,7 @@ public class BlockListeners implements Listener {
|
||||
|
||||
private boolean checkForFarm(Location location) {
|
||||
|
||||
EFarmManager farmManager = instance.getFarmManager();
|
||||
FarmManager farmManager = instance.getFarmManager();
|
||||
|
||||
Block block = location.getBlock();
|
||||
for (Level level : instance.getLevelManager().getLevels().values()) {
|
||||
@ -176,7 +176,7 @@ public class BlockListeners implements Listener {
|
||||
block.setType(Material.AIR);
|
||||
block.getLocation().getWorld().dropItemNaturally(block.getLocation().add(.5, .5, .5), item);
|
||||
|
||||
for (ItemStack itemStack : ((EFarm) farm).dumpInventory()) {
|
||||
for (ItemStack itemStack : ((Farm) farm).dumpInventory()) {
|
||||
if (itemStack == null) continue;
|
||||
farm.getLocation().getWorld().dropItemNaturally(farm.getLocation().add(.5, .5, .5), itemStack);
|
||||
}
|
||||
@ -236,7 +236,7 @@ public class BlockListeners implements Listener {
|
||||
block.setType(Material.AIR);
|
||||
block.getLocation().getWorld().dropItemNaturally(block.getLocation().add(.5, .5, .5), item);
|
||||
|
||||
for (ItemStack itemStack : ((EFarm) farm).dumpInventory()) {
|
||||
for (ItemStack itemStack : ((Farm) farm).dumpInventory()) {
|
||||
if (itemStack == null) continue;
|
||||
farm.getLocation().getWorld().dropItemNaturally(farm.getLocation().add(.5, .5, .5), itemStack);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.songoda.epicfarming.listeners;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.farming.EFarm;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -16,9 +16,9 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
*/
|
||||
public class InteractListeners implements Listener {
|
||||
|
||||
private EpicFarmingPlugin instance;
|
||||
private EpicFarming instance;
|
||||
|
||||
public InteractListeners(EpicFarmingPlugin instance) {
|
||||
public InteractListeners(EpicFarming instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class InteractListeners implements Listener {
|
||||
|
||||
if (instance.getFarmManager().getFarms().containsKey(location)) {
|
||||
e.setCancelled(true);
|
||||
((EFarm)instance.getFarmManager().getFarm(location)).view(e.getPlayer());
|
||||
((Farm)instance.getFarmManager().getFarm(location)).view(e.getPlayer());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
@ -1,9 +1,8 @@
|
||||
package com.songoda.epicfarming.listeners;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.api.farming.UpgradeType;
|
||||
import com.songoda.epicfarming.farming.EFarm;
|
||||
import com.songoda.epicfarming.player.PlayerActionManager;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.player.PlayerData;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,9 +16,9 @@ import org.bukkit.event.inventory.InventoryType;
|
||||
*/
|
||||
public class InventoryListeners implements Listener {
|
||||
|
||||
private EpicFarmingPlugin instance;
|
||||
private EpicFarming instance;
|
||||
|
||||
public InventoryListeners(EpicFarmingPlugin instance) {
|
||||
public InventoryListeners(EpicFarming instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@ -32,7 +31,7 @@ public class InventoryListeners implements Listener {
|
||||
if (event.getInventory().getType() != InventoryType.CHEST) return;
|
||||
|
||||
PlayerData playerData = instance.getPlayerActionManager().getPlayerAction((Player)event.getWhoClicked());
|
||||
EFarm farm = playerData.getFarm();
|
||||
Farm farm = playerData.getFarm();
|
||||
if (event.getSlot() <= 26) {
|
||||
event.setCancelled(true);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfarming.player;
|
||||
|
||||
import com.songoda.epicfarming.farming.EFarm;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -9,17 +9,17 @@ import java.util.UUID;
|
||||
public class PlayerData {
|
||||
|
||||
private final UUID playerUUID;
|
||||
private EFarm farm = null;
|
||||
private Farm farm = null;
|
||||
|
||||
PlayerData(UUID playerUUID) {
|
||||
this.playerUUID = playerUUID;
|
||||
}
|
||||
|
||||
public EFarm getFarm() {
|
||||
public Farm getFarm() {
|
||||
return farm;
|
||||
}
|
||||
|
||||
public void setFarm(EFarm farm) {
|
||||
public void setFarm(Farm farm) {
|
||||
this.farm = farm;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
package com.songoda.epicfarming.settings;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -15,13 +16,12 @@ 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 {
|
||||
public class Settings implements Listener {
|
||||
|
||||
private String pluginName = "EpicFarming";
|
||||
|
||||
@ -29,9 +29,9 @@ public class SettingsManager implements Listener {
|
||||
|
||||
private Map<Player, String> cat = new HashMap<>();
|
||||
|
||||
private final EpicFarmingPlugin instance;
|
||||
private final EpicFarming instance;
|
||||
|
||||
public SettingsManager(EpicFarmingPlugin plugin) {
|
||||
public Settings(EpicFarming plugin) {
|
||||
this.instance = plugin;
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
@ -2,22 +2,19 @@ package com.songoda.epicfarming.storage;
|
||||
|
||||
import com.songoda.epicfarming.api.farming.Farm;
|
||||
import com.songoda.epicfarming.boost.BoostData;
|
||||
import com.songoda.epicfarming.farming.EFarm;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.ConfigWrapper;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Storage {
|
||||
|
||||
protected final EpicFarmingPlugin instance;
|
||||
protected final EpicFarming instance;
|
||||
protected final ConfigWrapper dataFile;
|
||||
|
||||
public Storage(EpicFarmingPlugin instance) {
|
||||
public Storage(EpicFarming instance) {
|
||||
this.instance = instance;
|
||||
this.dataFile = new ConfigWrapper(instance, "", "data.yml");
|
||||
this.dataFile.createNewFile(null, "EpicFarming Data File");
|
||||
@ -31,7 +28,7 @@ public abstract class Storage {
|
||||
|
||||
public abstract void prepareSaveItem(String group, StorageItem... items);
|
||||
|
||||
public void updateData(EpicFarmingPlugin instance) {
|
||||
public void updateData(EpicFarming instance) {
|
||||
/*
|
||||
* Dump FarmManager to file.
|
||||
*/
|
||||
@ -42,7 +39,7 @@ public abstract class Storage {
|
||||
prepareSaveItem("farms",new StorageItem("location",locstr),
|
||||
new StorageItem("level",farm.getLevel().getLevel()),
|
||||
new StorageItem("placedby",farm.getPlacedBy().toString()),
|
||||
new StorageItem("contents",((EFarm)farm).dumpInventory()));
|
||||
new StorageItem("contents",((Farm)farm).dumpInventory()));
|
||||
}
|
||||
|
||||
/*
|
@ -3,8 +3,7 @@ package com.songoda.epicfarming.storage.types;
|
||||
import com.songoda.epicfarming.storage.Storage;
|
||||
import com.songoda.epicfarming.storage.StorageItem;
|
||||
import com.songoda.epicfarming.storage.StorageRow;
|
||||
import com.songoda.epicfarming.utils.MySQLDatabase;
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.MySQLDatabase;
|
||||
|
||||
import java.sql.DatabaseMetaData;
|
||||
@ -22,7 +21,7 @@ public class StorageMysql extends Storage {
|
||||
private static Map<String, StorageItem[]> lastSave = new HashMap<>();
|
||||
private MySQLDatabase database;
|
||||
|
||||
public StorageMysql(EpicFarmingPlugin instance) {
|
||||
public StorageMysql(EpicFarming instance) {
|
||||
super(instance);
|
||||
this.database = new MySQLDatabase(instance);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfarming.storage.types;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.storage.Storage;
|
||||
import com.songoda.epicfarming.storage.StorageItem;
|
||||
import com.songoda.epicfarming.storage.StorageRow;
|
||||
@ -15,7 +15,7 @@ public class StorageYaml extends Storage {
|
||||
private static final Map<String, Object> toSave = new HashMap<>();
|
||||
private static Map<String, Object> lastSave = null;
|
||||
|
||||
public StorageYaml(EpicFarmingPlugin instance) {
|
||||
public StorageYaml(EpicFarming instance) {
|
||||
super(instance);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfarming.tasks;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.api.farming.Farm;
|
||||
import com.songoda.epicfarming.boost.BoostData;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
@ -24,9 +24,9 @@ public class EntityTask extends BukkitRunnable {
|
||||
private static Map<Entity, Integer> lastTicksLived = new HashMap<>();
|
||||
private static final Map<Entity, Integer> ticksLived = new HashMap<>();
|
||||
private static EntityTask instance;
|
||||
private static EpicFarmingPlugin plugin;
|
||||
private static EpicFarming plugin;
|
||||
|
||||
public static EntityTask startTask(EpicFarmingPlugin pl) {
|
||||
public static EntityTask startTask(EpicFarming pl) {
|
||||
if (instance == null) {
|
||||
instance = new EntityTask();
|
||||
plugin = pl;
|
@ -1,10 +1,10 @@
|
||||
package com.songoda.epicfarming.tasks;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.api.farming.Farm;
|
||||
import com.songoda.epicfarming.boost.BoostData;
|
||||
import com.songoda.epicfarming.farming.Crop;
|
||||
import com.songoda.epicfarming.farming.EFarm;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.utils.CropType;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
@ -23,9 +23,9 @@ import java.util.*;
|
||||
public class FarmTask extends BukkitRunnable {
|
||||
|
||||
private static FarmTask instance;
|
||||
private static EpicFarmingPlugin plugin;
|
||||
private static EpicFarming plugin;
|
||||
|
||||
public static FarmTask startTask(EpicFarmingPlugin pl) {
|
||||
public static FarmTask startTask(EpicFarming pl) {
|
||||
if (instance == null) {
|
||||
instance = new FarmTask();
|
||||
plugin = pl;
|
||||
@ -117,9 +117,9 @@ public class FarmTask extends BukkitRunnable {
|
||||
}
|
||||
|
||||
public List<Block> getCrops(Farm farm, boolean add) {
|
||||
if (System.currentTimeMillis() - ((EFarm)farm).getLastCached() > 30 * 1000 || !add) {
|
||||
((EFarm)farm).setLastCached(System.currentTimeMillis());
|
||||
if (add) ((EFarm)farm).clearCache();
|
||||
if (System.currentTimeMillis() - ((Farm)farm).getLastCached() > 30 * 1000 || !add) {
|
||||
((Farm)farm).setLastCached(System.currentTimeMillis());
|
||||
if (add) ((Farm)farm).clearCache();
|
||||
Block block = farm.getLocation().getBlock();
|
||||
int radius = farm.getLevel().getRadius();
|
||||
int bx = block.getX();
|
||||
@ -133,10 +133,10 @@ public class FarmTask extends BukkitRunnable {
|
||||
if (!(b2.getState().getData() instanceof Crops)) continue;
|
||||
|
||||
if (add) {
|
||||
((EFarm)farm).addCachedCrop(b2);
|
||||
((Farm)farm).addCachedCrop(b2);
|
||||
continue;
|
||||
}
|
||||
((EFarm)farm).removeCachedCrop(b2);
|
||||
((Farm)farm).removeCachedCrop(b2);
|
||||
plugin.getGrowthTask().removeCropByLocation(b2.getLocation());
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfarming.tasks;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.farming.Crop;
|
||||
import org.bukkit.CropState;
|
||||
import org.bukkit.Location;
|
||||
@ -19,7 +19,7 @@ public class GrowthTask extends BukkitRunnable {
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
public static GrowthTask startTask(EpicFarmingPlugin plugin) {
|
||||
public static GrowthTask startTask(EpicFarming plugin) {
|
||||
if (instance == null) {
|
||||
instance = new GrowthTask();
|
||||
instance.runTaskTimer(plugin, 0, plugin.getConfig().getInt("Main.Growth Tick Speed"));
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfarming.tasks;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.api.farming.Farm;
|
||||
import com.songoda.epicfarming.api.farming.FarmManager;
|
||||
import org.bukkit.Location;
|
||||
@ -17,12 +17,12 @@ public class HopperTask extends BukkitRunnable {
|
||||
private static HopperTask instance;
|
||||
private final FarmManager manager;
|
||||
|
||||
private HopperTask(EpicFarmingPlugin plugin) {
|
||||
private HopperTask(EpicFarming plugin) {
|
||||
this.manager = plugin.getFarmManager();
|
||||
}
|
||||
|
||||
|
||||
public static HopperTask startTask(EpicFarmingPlugin plugin) {
|
||||
public static HopperTask startTask(EpicFarming plugin) {
|
||||
if (instance == null) {
|
||||
instance = new HopperTask(plugin);
|
||||
instance.runTaskTimer(plugin, 0, 8);
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Item;
|
||||
@ -22,7 +22,7 @@ public class Methods {
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
try {
|
||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
return getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
@ -32,7 +32,7 @@ public class Methods {
|
||||
|
||||
public static ItemStack getBackgroundGlass(boolean type) {
|
||||
try {
|
||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
if (type)
|
||||
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2"));
|
||||
else
|
||||
@ -59,7 +59,7 @@ public class Methods {
|
||||
|
||||
public static String formatName(int level, boolean full) {
|
||||
try {
|
||||
String name = EpicFarmingPlugin.getInstance().getLocale().getMessage("general.nametag.farm", level);
|
||||
String name = EpicFarming.getInstance().getLocale().getMessage("general.nametag.farm", level);
|
||||
|
||||
String info = "";
|
||||
if (full) {
|
||||
@ -75,21 +75,21 @@ public class Methods {
|
||||
|
||||
public static void animate(Location location, Material mat) {
|
||||
try {
|
||||
if (!EpicFarmingPlugin.getInstance().getConfig().getBoolean("Main.Animate")) return;
|
||||
if (!EpicFarming.getInstance().getConfig().getBoolean("Main.Animate")) return;
|
||||
Block block = location.getBlock();
|
||||
if (block.getRelative(0, 1, 0).getType() != Material.AIR && EpicFarmingPlugin.getInstance().getConfig().getBoolean("Main.Do Dispenser Animation"))
|
||||
if (block.getRelative(0, 1, 0).getType() != Material.AIR && EpicFarming.getInstance().getConfig().getBoolean("Main.Do Dispenser Animation"))
|
||||
return;
|
||||
Item i = block.getWorld().dropItem(block.getLocation().add(0.5, 1, 0.5), new ItemStack(mat));
|
||||
|
||||
// Support for EpicHoppers suction.
|
||||
i.setMetadata("grabbed", new FixedMetadataValue(EpicFarmingPlugin.getInstance(), "true"));
|
||||
i.setMetadata("grabbed", new FixedMetadataValue(EpicFarming.getInstance(), "true"));
|
||||
|
||||
i.setMetadata("betterdrops_ignore", new FixedMetadataValue(EpicFarmingPlugin.getInstance(), true));
|
||||
i.setMetadata("betterdrops_ignore", new FixedMetadataValue(EpicFarming.getInstance(), true));
|
||||
i.setPickupDelay(3600);
|
||||
|
||||
i.setVelocity(new Vector(0, .3, 0));
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(EpicFarmingPlugin.getInstance(), i::remove, 10);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(EpicFarming.getInstance(), i::remove, 10);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
0
src/main/resources/levels.yml
Normal file
0
src/main/resources/levels.yml
Normal file
Loading…
Reference in New Issue
Block a user