mirror of
https://github.com/songoda/EpicFarming.git
synced 2024-11-30 14:33:28 +01:00
Maven + UTF-8 + Arconix2
This commit is contained in:
parent
ff0951b0db
commit
dede4cdaee
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,3 +4,5 @@ out/
|
||||
\.idea/
|
||||
|
||||
EpicFarming\.iml
|
||||
/src/main/resources/META-INF/MANIFEST.MF
|
||||
/target/
|
||||
|
185
pom.xml
Normal file
185
pom.xml
Normal file
@ -0,0 +1,185 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicFarming</artifactId>
|
||||
<version>1.1</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
<build>
|
||||
<finalName>EpicFarming</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jcenter</id>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
<!--Bukkit Repo-->
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<!--Songoda Repo-->
|
||||
<repository>
|
||||
<id>songoda-public</id>
|
||||
<url>http://jenkins.songoda.com:8081/repository/songoda-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>songoda-private</id>
|
||||
<url>http://jenkins.songoda.com:8081/repository/songoda-private/</url>
|
||||
</repository>
|
||||
<!--WorldGuard Repo-->
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>http://maven.sk89q.com/repo/</url>
|
||||
</repository>
|
||||
<!--Vault Repo-->
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
<!--uSkyBlock Repo-->
|
||||
<repository>
|
||||
<id>uSkyBlock-mvn-repo</id>
|
||||
<url>https://raw.github.com/rlf/uSkyBlock/mvn-repo/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<!--aAkyBlock Repo-->
|
||||
<repository>
|
||||
<id>bintray-tastybento-maven-repo</id>
|
||||
<name>bintray</name>
|
||||
<url>http://dl.bintray.com/tastybento/maven-repo</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!--Bukkit API-->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--Arconix API-->
|
||||
<dependency>
|
||||
<groupId>com.songoda.arconix</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda.arconix</groupId>
|
||||
<artifactId>plugin</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--WorldGuard API-->
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>6.1.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--Vault API-->
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--Towny API-->
|
||||
<dependency>
|
||||
<groupId>com.palmergames</groupId>
|
||||
<artifactId>Towny</artifactId>
|
||||
<version>0.92.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--uSkyBlock API-->
|
||||
<dependency>
|
||||
<groupId>com.github.rlf</groupId>
|
||||
<artifactId>uSkyBlock-API</artifactId>
|
||||
<version>2.6.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--RedProtect API-->
|
||||
<dependency>
|
||||
<groupId>br.net.fabiozumbi12</groupId>
|
||||
<artifactId>RedProtect</artifactId>
|
||||
<version>7.3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--PlotSquared API-->
|
||||
<dependency>
|
||||
<groupId>com.intellectualcrafters</groupId>
|
||||
<artifactId>PlotSquared</artifactId>
|
||||
<version>18.05.01</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--Kingdoms API-->
|
||||
<dependency>
|
||||
<groupId>org.kingdoms</groupId>
|
||||
<artifactId>Kingdoms</artifactId>
|
||||
<version>13.3.40</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--GriefPrevention API-->
|
||||
<dependency>
|
||||
<groupId>com.github.TechFortress</groupId>
|
||||
<artifactId>GriefPrevention</artifactId>
|
||||
<version>16.7.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--FactionsFramework API-->
|
||||
<dependency>
|
||||
<groupId>me.markeh</groupId>
|
||||
<artifactId>factionsframework</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--aSkyBlock API-->
|
||||
<dependency>
|
||||
<groupId>com.wasteofplastic</groupId>
|
||||
<artifactId>askyblock</artifactId>
|
||||
<version>3.0.8.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--https://mvnrepository.com/artifact/commons-lang/commons-lang -->
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
269
src/main/java/com/songoda/epicfarming/EpicFarming.java
Normal file
269
src/main/java/com/songoda/epicfarming/EpicFarming.java
Normal file
@ -0,0 +1,269 @@
|
||||
package com.songoda.epicfarming;
|
||||
|
||||
import com.songoda.arconix.api.mcupdate.MCUpdate;
|
||||
import com.songoda.arconix.api.utils.ConfigWrapper;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicfarming.events.BlockListeners;
|
||||
import com.songoda.epicfarming.events.EntityListeners;
|
||||
import com.songoda.epicfarming.events.InteractListeners;
|
||||
import com.songoda.epicfarming.events.InventoryListeners;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.farming.FarmManager;
|
||||
import com.songoda.epicfarming.farming.LevelManager;
|
||||
import com.songoda.epicfarming.handlers.CommandHandler;
|
||||
import com.songoda.epicfarming.handlers.FarmingHandler;
|
||||
import com.songoda.epicfarming.handlers.GrowthHandler;
|
||||
import com.songoda.epicfarming.handlers.HookHandler;
|
||||
import com.songoda.epicfarming.player.PlayerActionManager;
|
||||
import com.songoda.epicfarming.player.PlayerData;
|
||||
import com.songoda.epicfarming.utils.SettingsManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by songoda on 1/23/2018.
|
||||
*/
|
||||
public class EpicFarming extends JavaPlugin implements Listener {
|
||||
|
||||
private static EpicFarming INSTANCE;
|
||||
|
||||
public SettingsManager settingsManager;
|
||||
public References references;
|
||||
public HookHandler hooks;
|
||||
|
||||
private ConfigWrapper langFile = new ConfigWrapper(this, "", "lang.yml");
|
||||
|
||||
public boolean v1_10 = Bukkit.getServer().getClass().getPackage().getName().contains("1_10");
|
||||
public boolean v1_9 = Bukkit.getServer().getClass().getPackage().getName().contains("1_9");
|
||||
public boolean v1_7 = Bukkit.getServer().getClass().getPackage().getName().contains("1_7");
|
||||
public boolean v1_8 = Bukkit.getServer().getClass().getPackage().getName().contains("1_8");
|
||||
|
||||
|
||||
private FarmingHandler farmingHandler;
|
||||
private GrowthHandler growthHandler;
|
||||
|
||||
private FarmManager farmManager;
|
||||
private LevelManager levelManager;
|
||||
private PlayerActionManager playerActionManager;
|
||||
|
||||
public ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml");
|
||||
|
||||
public void onEnable() {
|
||||
INSTANCE = this;
|
||||
Arconix.pl().hook(this);
|
||||
|
||||
CommandSender console = Bukkit.getConsoleSender();
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7EpicFarming " + this.getDescription().getVersion() + " by &5Brianna <3&7!"));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &aEnabling&7..."));
|
||||
|
||||
langFile.createNewFile("Loading Language File", "EpicFarming Language File");
|
||||
loadLanguageFile();
|
||||
|
||||
settingsManager = new SettingsManager(this);
|
||||
setupConfig();
|
||||
levelManager = new LevelManager();
|
||||
|
||||
dataFile.createNewFile("Loading Data File", "EpicFarming Data File");
|
||||
loadDataFile();
|
||||
|
||||
/*
|
||||
* Register Levels into LevelManager from configuration.
|
||||
*/
|
||||
for (String levelName : getConfig().getConfigurationSection("settings.levels").getKeys(false)) {
|
||||
int level = Integer.valueOf(levelName.split("-")[1]);
|
||||
int radius = getConfig().getInt("settings.levels." + levelName + ".Radius");
|
||||
int costExperiance = getConfig().getInt("settings.levels." + levelName + ".Cost-xp");
|
||||
int costEconomy = getConfig().getInt("settings.levels." + levelName + ".Cost-eco");
|
||||
double speedMultiplier = getConfig().getDouble("settings.levels." + levelName + ".Speed-Multiplier");
|
||||
boolean autoHarvest = getConfig().getBoolean("settings.levels." + levelName + ".Auto-Harvest");
|
||||
boolean autoReplant = getConfig().getBoolean("settings.levels." + levelName + ".Auto-Replant");
|
||||
levelManager.addLevel(level, costExperiance, costEconomy, speedMultiplier, radius, autoHarvest, autoReplant);
|
||||
}
|
||||
|
||||
farmManager = new FarmManager();
|
||||
|
||||
/*
|
||||
* Register Farms into FarmManger from configuration
|
||||
*/
|
||||
if (dataFile.getConfig().contains("Farms")) {
|
||||
for (String locationStr : dataFile.getConfig().getConfigurationSection("Farms").getKeys(false)) {
|
||||
Location location = Arconix.pl().getApi().serialize().unserializeLocation(locationStr);
|
||||
int level = dataFile.getConfig().getInt("Farms." + locationStr + ".level");
|
||||
|
||||
List<ItemStack> items = (List<ItemStack>)dataFile.getConfig().getList("Farms." + locationStr + ".Contents");
|
||||
|
||||
Farm farm = new Farm(location, levelManager.getLevel(level));
|
||||
farm.loadInventory(items);
|
||||
|
||||
farmManager.addFarm(location, farm);
|
||||
}
|
||||
}
|
||||
playerActionManager = new PlayerActionManager();
|
||||
|
||||
hooks = new HookHandler();
|
||||
hooks.hook();
|
||||
|
||||
farmingHandler = new FarmingHandler(this);
|
||||
growthHandler = new GrowthHandler(this);
|
||||
references = new References();
|
||||
|
||||
this.getCommand("EpicFarming").setExecutor(new CommandHandler(this));
|
||||
|
||||
getServer().getPluginManager().registerEvents(new BlockListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new InteractListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new InventoryListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new EntityListeners(), this);
|
||||
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
|
||||
new MCUpdate(this, true);
|
||||
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
saveToFile();
|
||||
for (PlayerData playerData : playerActionManager.getRegisteredPlayers()) {
|
||||
if (playerData.getPlayer() != null)
|
||||
playerData.getPlayer().closeInventory();
|
||||
}
|
||||
CommandSender console = Bukkit.getConsoleSender();
|
||||
dataFile.saveConfig();
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7EpicFarming " + this.getDescription().getVersion() + " by &5Brianna <3!"));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &cDisabling&7..."));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
}
|
||||
|
||||
/*
|
||||
* Saves registered farms to file.
|
||||
*/
|
||||
private void saveToFile() {
|
||||
|
||||
// Wipe old kit information
|
||||
dataFile.getConfig().set("Farms", null);
|
||||
|
||||
/*
|
||||
* Dump FarmManager to file.
|
||||
*/
|
||||
for (Farm farm : farmManager.getFarms().values()) {
|
||||
String locationStr = Arconix.pl().getApi().serialize().serializeLocation(farm.getLocation());
|
||||
dataFile.getConfig().set("Farms." + locationStr + ".level", farm.getLevel().getLevel());
|
||||
dataFile.getConfig().set("Farms." + locationStr + ".Contents", farm.dumpInventory());
|
||||
}
|
||||
|
||||
//Save to file
|
||||
dataFile.saveConfig();
|
||||
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
langFile.createNewFile("Loading Language File", "EpicFarming Language File");
|
||||
hooks.hooksFile.createNewFile("Loading hooks File", "EpicFarming hooks File");
|
||||
hooks = new HookHandler();
|
||||
hooks.hook();
|
||||
loadLanguageFile();
|
||||
references = new References();
|
||||
reloadConfig();
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void setupConfig() {
|
||||
settingsManager.updateSettings();
|
||||
|
||||
if (!getConfig().contains("settings.levels.Level-1")) {
|
||||
getConfig().addDefault("settings.levels.Level-1.Radius", 1);
|
||||
getConfig().addDefault("settings.levels.Level-1.Speed-Multiplier", 1);
|
||||
getConfig().addDefault("settings.levels.Level-1.Cost-xp", 20);
|
||||
getConfig().addDefault("settings.levels.Level-1.Cost-eco", 5000);
|
||||
|
||||
getConfig().addDefault("settings.levels.Level-2.Radius", 2);
|
||||
getConfig().addDefault("settings.levels.Level-2.Speed-Multiplier", 1.5);
|
||||
getConfig().addDefault("settings.levels.Level-2.Auto-Harvest", true);
|
||||
getConfig().addDefault("settings.levels.Level-2.Cost-xp", 20);
|
||||
getConfig().addDefault("settings.levels.Level-2.Cost-eco", 5000);
|
||||
|
||||
getConfig().addDefault("settings.levels.Level-3.Radius", 3);
|
||||
getConfig().addDefault("settings.levels.Level-3.Speed-Multiplier", 1.5);
|
||||
getConfig().addDefault("settings.levels.Level-3.Auto-Harvest", true);
|
||||
getConfig().addDefault("settings.levels.Level-3.Auto-Replant", true);
|
||||
getConfig().addDefault("settings.levels.Level-3.Cost-xp", 25);
|
||||
getConfig().addDefault("settings.levels.Level-3.Cost-eco", 7500);
|
||||
|
||||
getConfig().addDefault("settings.levels.Level-4.Radius", 3);
|
||||
getConfig().addDefault("settings.levels.Level-4.Speed-Multiplier", 2);
|
||||
getConfig().addDefault("settings.levels.Level-4.Auto-Harvest", true);
|
||||
getConfig().addDefault("settings.levels.Level-4.Auto-Replant", true);
|
||||
getConfig().addDefault("settings.levels.Level-4.Cost-xp", 30);
|
||||
getConfig().addDefault("settings.levels.Level-4.Cost-eco", 10000);
|
||||
|
||||
getConfig().addDefault("settings.levels.Level-5.Radius", 3);
|
||||
getConfig().addDefault("settings.levels.Level-5.Speed-Multiplier", 2.5);
|
||||
getConfig().addDefault("settings.levels.Level-5.Auto-Harvest", true);
|
||||
getConfig().addDefault("settings.levels.Level-5.Auto-Replant", true);
|
||||
getConfig().addDefault("settings.levels.Level-5.Cost-xp", 35);
|
||||
getConfig().addDefault("settings.levels.Level-5.Cost-eco", 12000);
|
||||
|
||||
getConfig().addDefault("settings.levels.Level-6.Radius", 4);
|
||||
getConfig().addDefault("settings.levels.Level-6.Speed-Multiplier", 3);
|
||||
getConfig().addDefault("settings.levels.Level-6.Auto-Harvest", true);
|
||||
getConfig().addDefault("settings.levels.Level-6.Auto-Replant", true);
|
||||
getConfig().addDefault("settings.levels.Level-6.Cost-xp", 40);
|
||||
getConfig().addDefault("settings.levels.Level-6.Cost-eco", 25000);
|
||||
}
|
||||
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void loadLanguageFile() {
|
||||
Lang.setFile(langFile.getConfig());
|
||||
|
||||
for (final Lang value : Lang.values()) {
|
||||
langFile.getConfig().addDefault(value.getPath(), value.getDefault());
|
||||
}
|
||||
|
||||
langFile.getConfig().options().copyDefaults(true);
|
||||
langFile.saveConfig();
|
||||
}
|
||||
|
||||
private void loadDataFile() {
|
||||
dataFile.getConfig().options().copyDefaults(true);
|
||||
dataFile.saveConfig();
|
||||
}
|
||||
|
||||
public static EpicFarming pl() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static EpicFarming getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public FarmManager getFarmManager() {
|
||||
return farmManager;
|
||||
}
|
||||
|
||||
public LevelManager getLevelManager() {
|
||||
return levelManager;
|
||||
}
|
||||
|
||||
public FarmingHandler getFarmingHandler() {
|
||||
return farmingHandler;
|
||||
}
|
||||
|
||||
public PlayerActionManager getPlayerActionManager() {
|
||||
return playerActionManager;
|
||||
}
|
||||
|
||||
public GrowthHandler getGrowthHandler() {
|
||||
return growthHandler;
|
||||
}
|
||||
}
|
111
src/main/java/com/songoda/epicfarming/Lang.java
Normal file
111
src/main/java/com/songoda/epicfarming/Lang.java
Normal file
@ -0,0 +1,111 @@
|
||||
package com.songoda.epicfarming;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public enum Lang {
|
||||
|
||||
PREFIX("prefix", "&8[&6EpicFarming&8]"),
|
||||
NEXT("Next", "&9Next"),
|
||||
BACK("Back", "&9Back"),
|
||||
|
||||
XPTITLE("Xp-upgrade-title", "&aUpgrade with XP"),
|
||||
XPLORE("Xp-upgrade-lore", "&7Cost: &a{COST} Levels"),
|
||||
|
||||
ECOTITLE("Eco-upgrade-title", "&aUpgrade with ECO"),
|
||||
ECOLORE("Eco-upgrade-lore", "&7Cost: &a${COST}"),
|
||||
|
||||
LEVEL("Level", "&6Farm Level &7{LEVEL}"),
|
||||
NEXT_LEVEL("Next-Level", "&6Next Level &7{LEVEL}"),
|
||||
|
||||
NEXT_RADIUS("Next-Radius", "&7Radius: &6{RADIUS}"),
|
||||
NEXT_SPEED("Next-Speed", "&7Speed: &6{SPEED}x"),
|
||||
NEXT_AUTO_HARVEST("Next-Auto-Harvest", "&7Auto Harvest: &6{AUTOHARVEST}"),
|
||||
NEXT_AUTO_REPLANT("Next-Auto-Replant", "&7Auto Replant: &6{AUTOREPLANT}"),
|
||||
|
||||
CANT_AFFORD("Cant-afford", "&cYou cannot afford this upgrade."),
|
||||
|
||||
UPGRADE_MESSAGE("Upgrade-message", "&7You successfully upgraded this farm to &6level {LEVEL}&7!"),
|
||||
|
||||
MAXED("Maxed", "&6This farm is maxed out."),
|
||||
|
||||
YOU_MAXED("You-Maxed", "&7You maxed out this farm at &6{NEW}x&7."),
|
||||
|
||||
NAME_FORMAT("Name-format", "&eLevel {LEVEL} &fFarm"),
|
||||
|
||||
NO_PERMS("No-perms", "&cYou do not have permission to do that.");
|
||||
|
||||
private String path;
|
||||
private String def;
|
||||
private static FileConfiguration LANG;
|
||||
|
||||
Lang(String path, String start) {
|
||||
this.path = path;
|
||||
this.def = start;
|
||||
}
|
||||
|
||||
public static void setFile(final FileConfiguration config) {
|
||||
LANG = config;
|
||||
}
|
||||
|
||||
public String getDefault() {
|
||||
return this.def;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public String getConfigValue() {
|
||||
return getConfigValue(null, null, null);
|
||||
}
|
||||
|
||||
public String getConfigValue(String arg) {
|
||||
return getConfigValue(arg, null, null);
|
||||
}
|
||||
|
||||
public String getConfigValue(int arg) {
|
||||
return getConfigValue(Integer.toString(arg));
|
||||
}
|
||||
|
||||
public String getConfigValue(double arg) {
|
||||
return getConfigValue(Double.toString(arg));
|
||||
}
|
||||
|
||||
public String getConfigValue(boolean arg) {
|
||||
return getConfigValue(Boolean.toString(arg));
|
||||
}
|
||||
|
||||
public String getConfigValue(String arg, String arg2, String arg3) {
|
||||
String value = ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, this.def));
|
||||
|
||||
if (arg != null) {
|
||||
value = value.replace("{COST}", arg);
|
||||
value = value.replace("{GOAL}", arg);
|
||||
value = value.replace("{NEW}", arg);
|
||||
value = value.replace("{MAX}", arg);
|
||||
value = value.replace("{AMT}", arg);
|
||||
value = value.replace("{LEVEL}", arg);
|
||||
value = value.replace("{NEWM}", arg);
|
||||
|
||||
value = value.replace("{RADIUS}", arg);
|
||||
value = value.replace("{SPEED}", arg);
|
||||
value = value.replace("{AUTOHARVEST}", arg);
|
||||
value = value.replace("{AUTOREPLANT}", arg);
|
||||
|
||||
if (arg2 != null) {
|
||||
value = value.replace("{TYPE}", arg2);
|
||||
}
|
||||
value = value.replace("{TYPE}", arg);
|
||||
if (arg3 != null)
|
||||
value = value.replace("{TIME}", arg3);
|
||||
}
|
||||
|
||||
if (arg2 != null) {
|
||||
value = value.replace("{COST}", arg2).replace("{GOAL}", arg2).replace("{NEW}", arg2).replace("{MAX}", arg2).replace("{AMT}", arg2)
|
||||
.replace("{LEVEL}", arg2).replace("{TYPE}", arg2).replace("{NEWM}", arg2);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
14
src/main/java/com/songoda/epicfarming/References.java
Normal file
14
src/main/java/com/songoda/epicfarming/References.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.songoda.epicfarming;
|
||||
|
||||
public class References {
|
||||
|
||||
private String prefix;
|
||||
|
||||
public References() {
|
||||
prefix = Lang.PREFIX.getConfigValue() + " ";
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
}
|
130
src/main/java/com/songoda/epicfarming/events/BlockListeners.java
Normal file
130
src/main/java/com/songoda/epicfarming/events/BlockListeners.java
Normal file
@ -0,0 +1,130 @@
|
||||
package com.songoda.epicfarming.events;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.farming.FarmManager;
|
||||
import com.songoda.epicfarming.farming.Level;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
import org.bukkit.event.block.BlockGrowEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/14/2017.
|
||||
*/
|
||||
public class BlockListeners implements Listener {
|
||||
|
||||
private EpicFarming instance;
|
||||
|
||||
public BlockListeners(EpicFarming instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockFade(BlockFadeEvent e) {
|
||||
try {
|
||||
if (checkForFarm(e.getBlock().getLocation())) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onGrow(BlockGrowEvent e) {
|
||||
try {
|
||||
if (checkForFarm(e.getNewState().getLocation())) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
try {
|
||||
if (e.getPlayer().getItemInHand().getType() != Material.END_ROD
|
||||
|| Methods.getLevelFromItem(e.getItemInHand()) == 0) return;
|
||||
|
||||
if (e.getBlockAgainst().getType() == Material.END_ROD) e.setCancelled(true);
|
||||
|
||||
Location location = e.getBlock().getLocation();
|
||||
|
||||
Farm farm = new Farm(location, instance.getLevelManager().getLevel(Methods.getLevelFromItem(e.getItemInHand())));
|
||||
instance.getFarmManager().addFarm(location, farm);
|
||||
|
||||
farm.tillLand(e.getBlock().getLocation());
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkForFarm(Location location) {
|
||||
|
||||
FarmManager farmManager = instance.getFarmManager();
|
||||
|
||||
Block block = location.getBlock();
|
||||
for(Level level : instance.getLevelManager().getLevels().values()) {
|
||||
int radius = level.getRadius();
|
||||
int bx = block.getX();
|
||||
int by = block.getY();
|
||||
int bz = block.getZ();
|
||||
for (int fx = -radius; fx <= radius; fx++) {
|
||||
for (int fy = -2; fy <= 1; fy++) {
|
||||
for (int fz = -radius; fz <= radius; fz++) {
|
||||
Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
|
||||
if (b2.getType() == Material.END_ROD) {
|
||||
if (!farmManager.getFarms().containsKey(b2.getLocation())) continue;
|
||||
if (level.getRadius() != farmManager.getFarm(b2.getLocation()).getLevel().getRadius()) continue;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
try {
|
||||
if (event.getBlock().getType() != Material.END_ROD) return;
|
||||
|
||||
Farm farm = instance.getFarmManager().removeFarm(event.getBlock().getLocation());
|
||||
|
||||
instance.getFarmingHandler().getCrops(farm, false);
|
||||
|
||||
if (farm == null) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
ItemStack item = Methods.makeFarmItem(farm.getLevel().getLevel());
|
||||
|
||||
Block block = event.getBlock();
|
||||
|
||||
block.setType(Material.AIR);
|
||||
block.getLocation().getWorld().dropItemNaturally(block.getLocation().add(.5,.5,.5), item);
|
||||
|
||||
for (ItemStack itemStack : farm.dumpInventory()) {
|
||||
if (itemStack == null) continue;
|
||||
farm.getLocation().getWorld().dropItemNaturally(farm.getLocation().add(.5,.5,.5), itemStack);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.songoda.epicfarming.events;
|
||||
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||
|
||||
public class EntityListeners implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onHop(InventoryMoveItemEvent e) {
|
||||
try {
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void ondrop(EntityDeathEvent e) {
|
||||
try {
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.songoda.epicfarming.events;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/14/2017.
|
||||
*/
|
||||
public class InteractListeners implements Listener {
|
||||
|
||||
private EpicFarming instance;
|
||||
|
||||
public InteractListeners(EpicFarming instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockInteract(PlayerInteractEvent e) {
|
||||
try {
|
||||
if (e.getClickedBlock() != null && e.getClickedBlock().getType() != Material.END_ROD) return;
|
||||
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
|
||||
Location location = e.getClickedBlock().getLocation();
|
||||
|
||||
if (instance.getFarmManager().getFarms().containsKey(location)) {
|
||||
instance.getFarmManager().getFarm(location).view(e.getPlayer());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package com.songoda.epicfarming.events;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.player.PlayerData;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/14/2017.
|
||||
*/
|
||||
public class InventoryListeners implements Listener {
|
||||
|
||||
private EpicFarming instance;
|
||||
|
||||
public InventoryListeners(EpicFarming instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
try {
|
||||
if (instance.getPlayerActionManager().getPlayerAction((Player)event.getWhoClicked()).getFarm() == null
|
||||
|| event.getInventory() == null) return;
|
||||
|
||||
|
||||
if (event.getInventory().getType() != InventoryType.CHEST) return;
|
||||
|
||||
PlayerData playerData = instance.getPlayerActionManager().getPlayerAction((Player)event.getWhoClicked());
|
||||
Farm farm = playerData.getFarm();
|
||||
if (event.getSlot() <= 26) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
Player player = (Player)event.getWhoClicked();
|
||||
|
||||
if (event.getSlot() == 11 && player.hasPermission("EpicFarming.Upgrade.XP")) {
|
||||
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
|
||||
farm.upgrade("XP", player);
|
||||
player.closeInventory();
|
||||
}
|
||||
} else if (event.getSlot() == 15 && player.hasPermission("EpicFarming.Upgrade.ECO")) {
|
||||
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
|
||||
farm.upgrade("ECO", player);
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClose(InventoryCloseEvent event) {
|
||||
try {
|
||||
if (instance.getPlayerActionManager().getRegisteredPlayers().size() == 0
|
||||
|| instance.getPlayerActionManager().getPlayerAction((Player)event.getPlayer()).getFarm() != null) return;
|
||||
|
||||
instance.getPlayerActionManager().getPlayerAction((Player)event.getPlayer()).setFarm(null);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
32
src/main/java/com/songoda/epicfarming/farming/Crop.java
Normal file
32
src/main/java/com/songoda/epicfarming/farming/Crop.java
Normal file
@ -0,0 +1,32 @@
|
||||
package com.songoda.epicfarming.farming;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class Crop {
|
||||
|
||||
private Location location;
|
||||
|
||||
private int ticksLived = 1;
|
||||
private Farm farm;
|
||||
|
||||
public Crop(Location location, Farm farm) {
|
||||
this.location = location;
|
||||
this.farm = farm;
|
||||
}
|
||||
|
||||
public int getTicksLived() {
|
||||
return ticksLived;
|
||||
}
|
||||
|
||||
public void setTicksLived(int ticksLived) {
|
||||
this.ticksLived = ticksLived;
|
||||
}
|
||||
|
||||
public Farm getFarm() {
|
||||
return farm;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
296
src/main/java/com/songoda/epicfarming/farming/Farm.java
Normal file
296
src/main/java/com/songoda/epicfarming/farming/Farm.java
Normal file
@ -0,0 +1,296 @@
|
||||
package com.songoda.epicfarming.farming;
|
||||
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.Lang;
|
||||
import com.songoda.epicfarming.player.PlayerData;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class Farm implements InventoryHolder {
|
||||
|
||||
private Location location;
|
||||
private Level level;
|
||||
private Inventory inventory;
|
||||
|
||||
public Farm(Location location, Level level) {
|
||||
this.location = location;
|
||||
this.level = level;
|
||||
this.inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(),false));
|
||||
}
|
||||
|
||||
public void view(Player player) {
|
||||
try {
|
||||
if (!player.hasPermission("epicfarming.view"))
|
||||
return;
|
||||
|
||||
setupOverview(player);
|
||||
|
||||
player.openInventory(inventory);
|
||||
PlayerData playerData = EpicFarming.getInstance().getPlayerActionManager().getPlayerAction(player);
|
||||
|
||||
playerData.setFarm(this);
|
||||
|
||||
getInventory();
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void setupOverview(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(),false));
|
||||
inventory.setContents(this.inventory.getContents());
|
||||
this.inventory = inventory;
|
||||
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
|
||||
Level nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel()+1) : null;
|
||||
|
||||
int level = this.level.getLevel();
|
||||
|
||||
ItemStack item = new ItemStack(Material.END_ROD, 1);
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
itemmeta.setDisplayName(Arconix.pl().getApi().format().formatText(Lang.LEVEL.getConfigValue(level)));
|
||||
ArrayList<String> lore = this.level.getDescription();
|
||||
lore.add("");
|
||||
if (nextLevel == null) lore.add(Lang.MAXED.getConfigValue());
|
||||
else {
|
||||
lore.add(Lang.NEXT_LEVEL.getConfigValue(nextLevel.getLevel()));
|
||||
lore.addAll(nextLevel.getDescription());
|
||||
}
|
||||
|
||||
itemmeta.setLore(lore);
|
||||
item.setItemMeta(itemmeta);
|
||||
|
||||
ItemStack itemXP = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.XP Icon")), 1);
|
||||
ItemMeta itemmetaXP = itemXP.getItemMeta();
|
||||
itemmetaXP.setDisplayName(Lang.XPTITLE.getConfigValue());
|
||||
ArrayList<String> loreXP = new ArrayList<>();
|
||||
if (nextLevel != null)
|
||||
loreXP.add(Lang.XPLORE.getConfigValue(Integer.toString(nextLevel.getCostExperiance())));
|
||||
else
|
||||
loreXP.add(Lang.MAXED.getConfigValue());
|
||||
itemmetaXP.setLore(loreXP);
|
||||
itemXP.setItemMeta(itemmetaXP);
|
||||
|
||||
ItemStack itemECO = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Economy Icon")), 1);
|
||||
ItemMeta itemmetaECO = itemECO.getItemMeta();
|
||||
itemmetaECO.setDisplayName(Lang.ECOTITLE.getConfigValue());
|
||||
ArrayList<String> loreECO = new ArrayList<>();
|
||||
if (nextLevel != null)
|
||||
loreECO.add(Lang.ECOLORE.getConfigValue(Arconix.pl().getApi().format().formatEconomy(nextLevel.getCostExperiance())));
|
||||
else
|
||||
loreECO.add(Lang.MAXED.getConfigValue());
|
||||
itemmetaECO.setLore(loreECO);
|
||||
itemECO.setItemMeta(itemmetaECO);
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
inventory.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
if (instance.getConfig().getBoolean("Main.Upgrade With XP") && player != null && player.hasPermission("EpicDispensers.Upgrade.XP")) {
|
||||
inventory.setItem(11, itemXP);
|
||||
}
|
||||
|
||||
inventory.setItem(13, item);
|
||||
|
||||
if (instance.getConfig().getBoolean("Main.Upgrade With Economy") && player != null && player.hasPermission("EpicDispensers.Upgrade.ECO")) {
|
||||
inventory.setItem(15, itemECO);
|
||||
}
|
||||
|
||||
inventory.setItem(0, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(1, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(2, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(6, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(7, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(8, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(9, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(10, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(16, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(17, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(18, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(19, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(20, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(24, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(25, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public void loadInventory(List<ItemStack> items) {
|
||||
setupOverview(null);
|
||||
int i = 27;
|
||||
for (ItemStack item : items) {
|
||||
inventory.setItem(i++, item);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemStack> dumpInventory() {
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
|
||||
for(int i=27; i < inventory.getSize(); i++) {
|
||||
items.add(inventory.getItem(i));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
public void upgrade(String type, Player player) {
|
||||
try {
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
if (instance.getLevelManager().getLevels().containsKey(this.level.getLevel()+1)) {
|
||||
|
||||
Level level = instance.getLevelManager().getLevel(this.level.getLevel()+1);
|
||||
int cost;
|
||||
if (type == "XP") {
|
||||
cost = level.getCostExperiance();
|
||||
} else {
|
||||
cost = level.getCostEconomy();
|
||||
}
|
||||
|
||||
if (type == "ECO") {
|
||||
if (instance.getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
RegisteredServiceProvider<Economy> rsp = instance.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
if (econ.has(player, cost)) {
|
||||
econ.withdrawPlayer(player, cost);
|
||||
upgradeFinal(level, player);
|
||||
} else {
|
||||
player.sendMessage(instance.references.getPrefix() + Lang.CANT_AFFORD.getConfigValue(null));
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("Vault is not installed.");
|
||||
}
|
||||
} else if (type == "XP") {
|
||||
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
player.setLevel(player.getLevel() - cost);
|
||||
}
|
||||
upgradeFinal(level, player);
|
||||
} else {
|
||||
player.sendMessage(instance.references.getPrefix() + Lang.CANT_AFFORD.getConfigValue(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void upgradeFinal(Level level, Player player) {
|
||||
try {
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
this.level = level;
|
||||
if (instance.getLevelManager().getHighestLevel() != level) {
|
||||
player.sendMessage(Lang.UPGRADE_MESSAGE.getConfigValue(level.getLevel()));
|
||||
} else {
|
||||
player.sendMessage(Lang.YOU_MAXED.getConfigValue(Integer.toString(level.getLevel())));
|
||||
}
|
||||
if (instance.getConfig().getBoolean("settings.On-upgrade-particles")) {
|
||||
Location loc = location.clone().add(.5,.5,.5);
|
||||
if (!instance.v1_8 && !instance.v1_7) {
|
||||
player.getWorld().spawnParticle(org.bukkit.Particle.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), loc, 200, .5, .5, .5);
|
||||
} else {
|
||||
player.getWorld().playEffect(loc, org.bukkit.Effect.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), 1, 0);
|
||||
//Can't get that to resolve.
|
||||
//player.getWorld().spigot().playEffect(loc, org.bukkit.Effect.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), 1, 0, (float) 1, (float) 1, (float) 1, 1, 200, 10);
|
||||
}
|
||||
}
|
||||
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
|
||||
if (instance.getLevelManager().getHighestLevel() == level) {
|
||||
if (!instance.v1_8 && !instance.v1_7) {
|
||||
player.playSound(player.getLocation(), org.bukkit.Sound.ENTITY_PLAYER_LEVELUP, 0.6F, 15.0F);
|
||||
} else {
|
||||
player.playSound(player.getLocation(), org.bukkit.Sound.valueOf("LEVEL_UP"), 2F, 15.0F);
|
||||
}
|
||||
} else {
|
||||
if (!instance.v1_10 && !instance.v1_9 && !instance.v1_8 && !instance.v1_7) {
|
||||
player.playSound(player.getLocation(), org.bukkit.Sound.ENTITY_PLAYER_LEVELUP, 2F, 25.0F);
|
||||
player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_CHIME, 2F, 25.0F);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_CHIME, 1.2F, 35.0F), 5L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_CHIME, 1.8F, 35.0F), 10L);
|
||||
} else {
|
||||
player.playSound(player.getLocation(), org.bukkit.Sound.valueOf("LEVEL_UP"), 2F, 25.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
tillLand(location);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
public boolean tillLand(Location location) {
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
Block block = location.getBlock();
|
||||
int radius = level.getRadius();
|
||||
int bx = block.getX();
|
||||
int by = block.getY();
|
||||
int bz = block.getZ();
|
||||
for (int fx = -radius; fx <= radius; fx++) {
|
||||
for (int fy = -2; fy <= 1; fy++) {
|
||||
for (int fz = -radius; fz <= radius; fz++) {
|
||||
Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
|
||||
|
||||
// ToDo: enum for all flowers.
|
||||
if (b2.getType() == Material.LONG_GRASS || b2.getType() == Material.RED_ROSE || b2.getType() == Material.YELLOW_FLOWER) {
|
||||
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
|
||||
b2.getRelative(BlockFace.DOWN).setType(Material.SOIL);
|
||||
b2.breakNaturally();
|
||||
if (instance.getConfig().getBoolean("Main.Sounds Enabled"))
|
||||
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
|
||||
}, random.nextInt(30) + 1);
|
||||
}
|
||||
if ((b2.getType() == Material.GRASS || b2.getType() == Material.DIRT) && b2.getRelative(BlockFace.UP).getType() == Material.AIR) {
|
||||
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
|
||||
b2.setType(Material.SOIL);
|
||||
if (instance.getConfig().getBoolean("Main.Sounds Enabled"))
|
||||
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
|
||||
}, random.nextInt(30) + 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location.clone();
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.songoda.epicfarming.farming;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FarmManager {
|
||||
|
||||
private final Map<Location, Farm> registeredFarms = new HashMap<>();
|
||||
|
||||
public void addFarm(Location location, Farm farm) {
|
||||
registeredFarms.put(roundLocation(location), farm);
|
||||
}
|
||||
|
||||
public Farm removeFarm(Location location) {
|
||||
return registeredFarms.remove(roundLocation(location));
|
||||
}
|
||||
|
||||
public Farm getFarm(Location location) {
|
||||
return registeredFarms.get(roundLocation(location));
|
||||
}
|
||||
|
||||
public Map<Location, Farm> getFarms() {
|
||||
return Collections.unmodifiableMap(registeredFarms);
|
||||
}
|
||||
|
||||
private Location roundLocation(Location location) {
|
||||
location = location.clone();
|
||||
location.setX(location.getBlockX());
|
||||
location.setY(location.getBlockY());
|
||||
location.setZ(location.getBlockZ());
|
||||
return location;
|
||||
}
|
||||
}
|
68
src/main/java/com/songoda/epicfarming/farming/Level.java
Normal file
68
src/main/java/com/songoda/epicfarming/farming/Level.java
Normal file
@ -0,0 +1,68 @@
|
||||
package com.songoda.epicfarming.farming;
|
||||
|
||||
import com.songoda.epicfarming.Lang;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Level {
|
||||
|
||||
private int level, costExperiance, costEconomy, radius;
|
||||
|
||||
private double speedMultiplier;
|
||||
|
||||
private boolean autoHarvest, autoReplant;
|
||||
|
||||
private ArrayList<String> description = new ArrayList<>();
|
||||
|
||||
public Level(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant) {
|
||||
this.level = level;
|
||||
this.costExperiance = costExperiance;
|
||||
this.costEconomy = costEconomy;
|
||||
this.speedMultiplier = speedMultiplier;
|
||||
this.radius = radius;
|
||||
this.autoHarvest = autoHarvest;
|
||||
this.autoReplant = autoReplant;
|
||||
|
||||
description.add(Lang.NEXT_RADIUS.getConfigValue(radius));
|
||||
description.add(Lang.NEXT_SPEED.getConfigValue(speedMultiplier));
|
||||
|
||||
if (autoHarvest)
|
||||
description.add(Lang.NEXT_AUTO_HARVEST.getConfigValue(autoHarvest));
|
||||
|
||||
if (autoReplant)
|
||||
description.add(Lang.NEXT_AUTO_REPLANT.getConfigValue(autoReplant));
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<String> getDescription() {
|
||||
return (ArrayList<String>)description.clone();
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public int getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public boolean isAutoHarvest() {
|
||||
return autoHarvest;
|
||||
}
|
||||
|
||||
public boolean isAutoReplant() {
|
||||
return autoReplant;
|
||||
}
|
||||
|
||||
public double getSpeedMultiplier() {
|
||||
return speedMultiplier;
|
||||
}
|
||||
|
||||
public int getCostExperiance() {
|
||||
return costExperiance;
|
||||
}
|
||||
|
||||
public int getCostEconomy() {
|
||||
return costEconomy;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.songoda.epicfarming.farming;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class LevelManager {
|
||||
|
||||
private final NavigableMap<Integer, Level> registeredLevels = new TreeMap<>();
|
||||
|
||||
public void addLevel(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant) {
|
||||
registeredLevels.put(level, new Level(level, costExperiance, costEconomy, speedMultiplier, radius, autoHarvest, autoReplant));
|
||||
}
|
||||
|
||||
public Level getLevel(int level) {
|
||||
return registeredLevels.get(level);
|
||||
}
|
||||
|
||||
public Level getLowestLevel() {
|
||||
return registeredLevels.firstEntry().getValue();
|
||||
}
|
||||
|
||||
public Level getHighestLevel() {
|
||||
return registeredLevels.lastEntry().getValue();
|
||||
}
|
||||
public Map<Integer, Level> getLevels() {
|
||||
return Collections.unmodifiableMap(registeredLevels);
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package com.songoda.epicfarming.handlers;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.Lang;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/14/2017.
|
||||
*/
|
||||
|
||||
public class CommandHandler implements CommandExecutor {
|
||||
|
||||
private EpicFarming instance;
|
||||
|
||||
public CommandHandler(EpicFarming instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
try {
|
||||
if (args.length == 0 || args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7" + instance.getDescription().getVersion() + " Created by &5&l&oBrianna"));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEFA help &7Displays this page."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEFA settings &7Edit the EpicFarming Settings."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEFA reload &7Reloads Configuration and Language files."));
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEFA givefarmitem [player] &7Give a farm item to a player."));
|
||||
sender.sendMessage("");
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (!sender.hasPermission("epicfarming.admin")) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERMS.getConfigValue());
|
||||
} else {
|
||||
instance.reload();
|
||||
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Configuration and Language files reloaded."));
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("givefarmitem")) {
|
||||
if (!sender.hasPermission("epicfarming.admin")) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERMS.getConfigValue());
|
||||
return true;
|
||||
}
|
||||
//ToDo: add the ability to specify level.
|
||||
if (args.length == 1) {
|
||||
if (sender instanceof Player)
|
||||
((Player) sender).getInventory().addItem(Methods.makeFarmItem(1));
|
||||
} else if (Bukkit.getPlayerExact(args[1]) == null) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&cThat username does not exist, or the user is not online!"));
|
||||
} else {
|
||||
Bukkit.getPlayerExact(args[1]).getInventory().addItem(Methods.makeFarmItem(1));
|
||||
}
|
||||
} else if (sender instanceof Player) {
|
||||
if (args[0].equalsIgnoreCase("settings")) {
|
||||
if (!sender.hasPermission("epicfarming.admin")) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERMS.getConfigValue());
|
||||
} else {
|
||||
Player p = (Player) sender;
|
||||
instance.settingsManager.openSettingsManager(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
package com.songoda.epicfarming.handlers;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.farming.Crop;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.utils.CropType;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.CropState;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Crops;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class FarmingHandler {
|
||||
|
||||
private EpicFarming instance;
|
||||
|
||||
public FarmingHandler(EpicFarming instance) {
|
||||
this.instance = instance;
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.getInstance(), this::farmRunner, 0, instance.getConfig().getInt("Main.Farm Tick Speed"));
|
||||
}
|
||||
|
||||
|
||||
private void farmRunner() {
|
||||
try {
|
||||
for (Farm farm : instance.getFarmManager().getFarms().values()) {
|
||||
for (Block block : getCrops(farm, true)) {
|
||||
Crops crop = (Crops) block.getState().getData();
|
||||
|
||||
// Add to GrowthHandler
|
||||
if (!instance.getGrowthHandler().liveCrops.containsKey(block.getLocation()))
|
||||
instance.getGrowthHandler().liveCrops.put(block.getLocation(), new Crop(block.getLocation(), farm));
|
||||
|
||||
if (!farm.getLevel().isAutoHarvest()
|
||||
|| !crop.getState().equals(CropState.RIPE)
|
||||
|| !doDrop(farm, block.getType())) continue;
|
||||
|
||||
if (farm.getLevel().isAutoReplant()) {
|
||||
BlockState cropState = block.getState();
|
||||
Crops cropData = (Crops) cropState.getData();
|
||||
cropData.setState(CropState.VERY_SMALL);
|
||||
cropState.setData(cropData);
|
||||
cropState.update();
|
||||
continue;
|
||||
}
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doDrop(Farm farm, Material material) {
|
||||
Random random = new Random();
|
||||
|
||||
ItemStack stack = new ItemStack(CropType.getCropType(material).getYieldMaterial());
|
||||
ItemStack seedStack = new ItemStack(CropType.getCropType(material).getSeedMaterial(), random.nextInt(3));
|
||||
|
||||
if (!canMove(farm.getInventory(), stack)) return false;
|
||||
farm.getInventory().addItem(stack);
|
||||
farm.getInventory().addItem(seedStack);
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<Block> getCrops(Farm farm, boolean add) {
|
||||
List<Block> crops = new ArrayList<>();
|
||||
|
||||
Block block = farm.getLocation().getBlock();
|
||||
int radius = farm.getLevel().getRadius();
|
||||
int bx = block.getX();
|
||||
int by = block.getY();
|
||||
int bz = block.getZ();
|
||||
for (int fx = -radius; fx <= radius; fx++) {
|
||||
for (int fy = -2; fy <= 1; fy++) {
|
||||
for (int fz = -radius; fz <= radius; fz++) {
|
||||
Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
|
||||
|
||||
if (!(b2.getState().getData() instanceof Crops)) continue;
|
||||
if (add)
|
||||
crops.add(b2);
|
||||
else {
|
||||
instance.getGrowthHandler().liveCrops.remove(b2.getLocation());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return crops;
|
||||
}
|
||||
|
||||
private boolean canMove(Inventory inventory, ItemStack item) {
|
||||
try {
|
||||
if (inventory.firstEmpty() != -1) return true;
|
||||
|
||||
for (ItemStack stack : inventory.getContents()) {
|
||||
if (stack.isSimilar(item) && stack.getAmount() <= stack.getMaxStackSize()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package com.songoda.epicfarming.handlers;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.farming.Crop;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.CropState;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.material.Crops;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class GrowthHandler {
|
||||
|
||||
public GrowthHandler(EpicFarming instance) {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.getInstance(), this::growthRunner, 0, instance.getConfig().getInt("Main.Growth Tick Speed"));
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.getInstance(), this::clear, 0, instance.getConfig().getInt("Main.Clear Tick Speed"));
|
||||
}
|
||||
|
||||
Map<Location, Crop> liveCrops = new HashMap<>();
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
private void growthRunner() {
|
||||
|
||||
for (Crop crop : liveCrops.values()) {
|
||||
|
||||
if (!(crop.getLocation().getBlock().getState().getData() instanceof Crops)) continue;
|
||||
|
||||
//ToDO: This should be in config.
|
||||
int cap = (int)Math.ceil(60 / crop.getFarm().getLevel().getSpeedMultiplier()) - crop.getTicksLived();
|
||||
if (cap > 2) {
|
||||
int rand = random.nextInt(cap) + 1;
|
||||
|
||||
crop.setTicksLived(crop.getTicksLived() + 1);
|
||||
if (rand != cap - 1 && crop.getTicksLived() != cap / 2) continue;
|
||||
|
||||
}
|
||||
|
||||
BlockState cropState = crop.getLocation().getBlock().getState();
|
||||
Crops cropData = (Crops) cropState.getData();
|
||||
|
||||
switch(cropData.getState()) {
|
||||
case SEEDED:
|
||||
cropData.setState(CropState.GERMINATED);
|
||||
break;
|
||||
case GERMINATED:
|
||||
cropData.setState(CropState.VERY_SMALL);
|
||||
break;
|
||||
case VERY_SMALL:
|
||||
cropData.setState(CropState.SMALL);
|
||||
break;
|
||||
case SMALL:
|
||||
cropData.setState(CropState.MEDIUM);
|
||||
break;
|
||||
case MEDIUM:
|
||||
cropData.setState(CropState.TALL);
|
||||
break;
|
||||
case TALL:
|
||||
cropData.setState(CropState.VERY_TALL);
|
||||
break;
|
||||
case VERY_TALL:
|
||||
cropData.setState(CropState.RIPE);
|
||||
break;
|
||||
case RIPE:
|
||||
break;
|
||||
}
|
||||
cropState.setData(cropData);
|
||||
cropState.update();
|
||||
crop.setTicksLived(1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
liveCrops.clear();
|
||||
}
|
||||
}
|
114
src/main/java/com/songoda/epicfarming/handlers/HookHandler.java
Normal file
114
src/main/java/com/songoda/epicfarming/handlers/HookHandler.java
Normal file
@ -0,0 +1,114 @@
|
||||
package com.songoda.epicfarming.handlers;
|
||||
|
||||
import com.songoda.arconix.api.utils.ConfigWrapper;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.hooks.*;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/17/2017.
|
||||
*/
|
||||
public class HookHandler {
|
||||
|
||||
public Hook FactionsHook = null, RedProtectHook = null, ASkyBlockHook = null, USkyBlockHook = null,
|
||||
WorldGuardHook = null, GriefPreventionHook = null, PlotSquaredHook = null, KingdomsHook = null,
|
||||
TownyHook = null;
|
||||
|
||||
public ConfigWrapper hooksFile = new ConfigWrapper(EpicFarming.getInstance(), "", "hooks.yml");
|
||||
|
||||
public HookHandler() {
|
||||
}
|
||||
|
||||
public void hook() {
|
||||
try {
|
||||
hooksFile.createNewFile("Loading hooks File", EpicFarming.getInstance().getDescription().getName() + " hooks File");
|
||||
|
||||
new FactionsHook();
|
||||
new RedProtectHook();
|
||||
new GriefPreventionHook();
|
||||
new ASkyBlockHook();
|
||||
new USkyBlockHook();
|
||||
new WorldGuardHook();
|
||||
new PlotSquaredHook();
|
||||
new KingdomsHook();
|
||||
new TownyHook();
|
||||
|
||||
hooksFile.getConfig().options().copyDefaults(true);
|
||||
hooksFile.saveConfig();
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isInFaction(String name, Location l) {
|
||||
if (FactionsHook != null) {
|
||||
return FactionsHook.isInClaim(name, l);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getFactionId(String name) {
|
||||
if (FactionsHook != null) {
|
||||
return FactionsHook.getClaimId(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isInTown(String name, Location l) {
|
||||
if (TownyHook != null) {
|
||||
return TownyHook.isInClaim(name, l);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getTownId(String name) {
|
||||
if (TownyHook != null) {
|
||||
return TownyHook.getClaimId(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isInIsland(String name, Location l) {
|
||||
if (USkyBlockHook != null)
|
||||
return USkyBlockHook.isInClaim(name, l);
|
||||
else if (ASkyBlockHook != null)
|
||||
return ASkyBlockHook.isInClaim(name, l);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getIslandId(String name) {
|
||||
try {
|
||||
return Bukkit.getOfflinePlayer(name).getUniqueId().toString();
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canBuild(Player p, Location l) {
|
||||
boolean result = true;
|
||||
if (WorldGuardHook != null)
|
||||
result = WorldGuardHook.canBuild(p, l);
|
||||
if (RedProtectHook != null && result)
|
||||
result = RedProtectHook.canBuild(p, l);
|
||||
if (FactionsHook != null && result)
|
||||
result = FactionsHook.canBuild(p, l);
|
||||
if (ASkyBlockHook != null && result)
|
||||
result = ASkyBlockHook.canBuild(p, l);
|
||||
if (USkyBlockHook != null && result)
|
||||
result = USkyBlockHook.canBuild(p, l);
|
||||
if (GriefPreventionHook != null && result)
|
||||
result = GriefPreventionHook.canBuild(p, l);
|
||||
if (PlotSquaredHook != null && result)
|
||||
result = PlotSquaredHook.canBuild(p, l);
|
||||
if (KingdomsHook != null && result)
|
||||
result = KingdomsHook.canBuild(p, l);
|
||||
if (TownyHook != null && result)
|
||||
result = TownyHook.canBuild(p, l);
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import com.wasteofplastic.askyblock.ASkyBlockAPI;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/17/2017.
|
||||
*/
|
||||
public class ASkyBlockHook extends Hook {
|
||||
|
||||
private ASkyBlockAPI as;
|
||||
|
||||
public ASkyBlockHook() {
|
||||
super("ASkyblock");
|
||||
if (isEnabled()) {
|
||||
as = ASkyBlockAPI.getInstance();
|
||||
EpicFarming plugin = EpicFarming.pl();
|
||||
plugin.hooks.ASkyBlockHook = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player p, Location location) {
|
||||
try {
|
||||
if (hasBypass(p) || as.getIslandAt(location) == null) return true;
|
||||
|
||||
UUID owner = as.getOwner(location);
|
||||
List<UUID> list = as.getTeamMembers(owner);
|
||||
Set<Location> list2 = as.getCoopIslands(p);
|
||||
|
||||
if (owner == null) return true;
|
||||
|
||||
for (UUID uuid : list) {
|
||||
if (uuid.equals(p.getUniqueId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (Location loc: list2) {
|
||||
if (as.getIslandAt(location).getOwner().equals(as.getIslandAt(loc).getOwner())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return owner.equals(p.getUniqueId());
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(String uuid, Location location) {
|
||||
return as.getOwner(location).toString().equals(uuid);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import me.markeh.factionsframework.entities.FPlayer;
|
||||
import me.markeh.factionsframework.entities.FPlayers;
|
||||
import me.markeh.factionsframework.entities.Faction;
|
||||
import me.markeh.factionsframework.entities.Factions;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/17/2017.
|
||||
*/
|
||||
public class FactionsHook extends Hook {
|
||||
|
||||
public FactionsHook() {
|
||||
super("Factions");
|
||||
EpicFarming plugin = EpicFarming.pl();
|
||||
if (isEnabled())
|
||||
plugin.hooks.GriefPreventionHook = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player p, Location location) {
|
||||
try {
|
||||
FPlayer fp = FPlayers.getBySender(p);
|
||||
|
||||
Faction faction = Factions.getFactionAt(location);
|
||||
|
||||
return (fp.getFaction().equals(faction) || faction.isNone());
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(String id, Location location) {
|
||||
Faction faction = Factions.getFactionAt(location);
|
||||
|
||||
return faction.getId().equals(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimId(String name) {
|
||||
try {
|
||||
Faction faction = Factions.getByName(name, "");
|
||||
|
||||
return faction.getId();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/17/2017.
|
||||
*/
|
||||
public class GriefPreventionHook extends Hook {
|
||||
|
||||
private EpicFarming plugin = EpicFarming.pl();
|
||||
|
||||
public GriefPreventionHook() {
|
||||
super("GriefPrevention");
|
||||
if (isEnabled())
|
||||
plugin.hooks.GriefPreventionHook = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player p, Location location) {
|
||||
try {
|
||||
if (hasBypass(p))
|
||||
return true;
|
||||
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null);
|
||||
return claim != null && claim.allowBuild(p, Material.STONE) == null;
|
||||
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
40
src/main/java/com/songoda/epicfarming/hooks/Hook.java
Normal file
40
src/main/java/com/songoda/epicfarming/hooks/Hook.java
Normal file
@ -0,0 +1,40 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class Hook {
|
||||
|
||||
protected final String pluginName;
|
||||
|
||||
protected Hook(String pluginName) {
|
||||
this.pluginName = pluginName;
|
||||
if (isEnabled())
|
||||
EpicFarming.getInstance().hooks.hooksFile.getConfig().addDefault("hooks." + pluginName, true);
|
||||
}
|
||||
|
||||
protected boolean isEnabled() {
|
||||
return (Bukkit.getPluginManager().isPluginEnabled(pluginName)
|
||||
&& EpicFarming.getInstance().hooks.hooksFile.getConfig().getBoolean("hooks." + pluginName,true));
|
||||
}
|
||||
|
||||
protected boolean hasBypass(Player p) {
|
||||
return p.hasPermission(EpicFarming.getInstance().getDescription().getName() + ".bypass");
|
||||
}
|
||||
|
||||
public abstract boolean canBuild(Player p, Location location);
|
||||
|
||||
public boolean isInClaim(String id, Location location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getClaimId(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.kingdoms.constants.land.Land;
|
||||
import org.kingdoms.constants.land.SimpleChunkLocation;
|
||||
import org.kingdoms.constants.player.OfflineKingdomPlayer;
|
||||
import org.kingdoms.manager.game.GameManagement;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/17/2017.
|
||||
*/
|
||||
public class KingdomsHook extends Hook {
|
||||
|
||||
public KingdomsHook() {
|
||||
super("Kingdoms");
|
||||
EpicFarming plugin = EpicFarming.pl();
|
||||
if (isEnabled())
|
||||
plugin.hooks.KingdomsHook = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player p, Location location) {
|
||||
try {
|
||||
if (hasBypass(p)) return true;
|
||||
|
||||
OfflineKingdomPlayer pl = GameManagement.getPlayerManager().getOfflineKingdomPlayer(p);
|
||||
if (pl.getKingdomPlayer().getKingdom() == null) return true;
|
||||
|
||||
SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getWorld().getName(), location.getChunk().getX(), location.getChunk().getZ());
|
||||
Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation);
|
||||
String owner = land.getOwner();
|
||||
|
||||
return pl.getKingdomPlayer().getKingdom().getKingdomName().equals(owner) || owner == null;
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
|
||||
import com.intellectualcrafters.plot.api.PlotAPI;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/17/2017.
|
||||
*/
|
||||
public class PlotSquaredHook extends Hook {
|
||||
|
||||
private PlotAPI plotAPI;
|
||||
|
||||
public PlotSquaredHook() {
|
||||
super("PlotSquared");
|
||||
if (isEnabled()) {
|
||||
EpicFarming plugin = EpicFarming.pl();
|
||||
plugin.hooks.PlotSquaredHook = this;
|
||||
this.plotAPI = new PlotAPI();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player p, Location location) {
|
||||
try {
|
||||
return hasBypass(p)
|
||||
|| (plotAPI.getPlot(location) != null
|
||||
&& plotAPI.isInPlot(p)
|
||||
&& plotAPI.getPlot(p) == plotAPI.getPlot(location));
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
|
||||
import br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI;
|
||||
import br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/17/2017.
|
||||
*/
|
||||
public class RedProtectHook extends Hook {
|
||||
|
||||
private EpicFarming plugin = EpicFarming.pl();
|
||||
|
||||
public RedProtectHook() {
|
||||
super("RedProtect");
|
||||
if (isEnabled())
|
||||
plugin.hooks.RedProtectHook = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player p, Location location) {
|
||||
try {
|
||||
RedProtectAPI rpAPI = RedProtect.get().getAPI();
|
||||
return hasBypass(p) || (rpAPI.getRegion(location) != null && rpAPI.getRegion(location).canBuild(p));
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
56
src/main/java/com/songoda/epicfarming/hooks/TownyHook.java
Normal file
56
src/main/java/com/songoda/epicfarming/hooks/TownyHook.java
Normal file
@ -0,0 +1,56 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/17/2017.
|
||||
*/
|
||||
public class TownyHook extends Hook {
|
||||
|
||||
public TownyHook() {
|
||||
super("Towny");
|
||||
EpicFarming plugin = EpicFarming.pl();
|
||||
if (isEnabled())
|
||||
plugin.hooks.TownyHook = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player p, Location location) {
|
||||
try {
|
||||
if (hasBypass(p) || TownyUniverse.isWilderness(location.getBlock())) return true;
|
||||
if (!TownyUniverse.getTownBlock(location).hasTown()) return true;
|
||||
|
||||
Resident r = TownyUniverse.getDataSource().getResident(p.getName());
|
||||
return r.hasTown() && TownyUniverse.getTownName(location).equals(r.getTown().getName());
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(String id, Location location) {
|
||||
try {
|
||||
return !TownyUniverse.isWilderness(location.getBlock())
|
||||
&& TownyUniverse.getTownBlock(location).getTown().getUID() == Integer.parseInt(id);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimId(String name) {
|
||||
try {
|
||||
return TownyUniverse.getDataSource().getTown(name).getUID().toString();
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/17/2017.
|
||||
*/
|
||||
public class USkyBlockHook extends Hook {
|
||||
|
||||
private uSkyBlockAPI usb;
|
||||
private EpicFarming plugin = EpicFarming.pl();
|
||||
|
||||
public USkyBlockHook() {
|
||||
super("USkyBlock");
|
||||
if (isEnabled()) {
|
||||
plugin.hooks.USkyBlockHook = this;
|
||||
this.usb = (uSkyBlockAPI) Bukkit.getPluginManager().getPlugin(pluginName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player p, Location location) {
|
||||
try {
|
||||
if (hasBypass(p)) return true;
|
||||
|
||||
for (Player pl : usb.getIslandInfo(location).getOnlineMembers()) {
|
||||
if (pl.equals(p)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return usb.getIslandInfo(location).isLeader(p);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(String uuid, Location location) {
|
||||
return usb.getIslandInfo(location).getLeader().equals(uuid);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/17/2017.
|
||||
*/
|
||||
public class WorldGuardHook extends Hook {
|
||||
|
||||
private EpicFarming plugin = EpicFarming.pl();
|
||||
|
||||
public WorldGuardHook() {
|
||||
super("WorldGuard");
|
||||
if (isEnabled())
|
||||
plugin.hooks.WorldGuardHook = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player p, Location location) {
|
||||
try {
|
||||
return p.hasPermission(plugin.getDescription().getName() + ".bypass") || WorldGuardPlugin.inst().canBuild(p, location);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.songoda.epicfarming.player;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PlayerActionManager {
|
||||
|
||||
private final Map<UUID, PlayerData> registeredPlayers = new HashMap<>();
|
||||
|
||||
public PlayerData getPlayerAction(Player player) {
|
||||
return (player != null) ? registeredPlayers.computeIfAbsent(player.getUniqueId(), p -> new PlayerData(player.getUniqueId())) : null;
|
||||
}
|
||||
|
||||
public Collection<PlayerData> getRegisteredPlayers() {
|
||||
return Collections.unmodifiableCollection(registeredPlayers.values());
|
||||
}
|
||||
}
|
29
src/main/java/com/songoda/epicfarming/player/PlayerData.java
Normal file
29
src/main/java/com/songoda/epicfarming/player/PlayerData.java
Normal file
@ -0,0 +1,29 @@
|
||||
package com.songoda.epicfarming.player;
|
||||
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerData {
|
||||
|
||||
private final UUID playerUUID;
|
||||
private Farm farm = null;
|
||||
|
||||
public PlayerData(UUID playerUUID) {
|
||||
this.playerUUID = playerUUID;
|
||||
}
|
||||
|
||||
public Farm getFarm() {
|
||||
return farm;
|
||||
}
|
||||
|
||||
public void setFarm(Farm farm) {
|
||||
this.farm = farm;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return Bukkit.getPlayer(playerUUID);
|
||||
}
|
||||
}
|
107
src/main/java/com/songoda/epicfarming/utils/CropType.java
Normal file
107
src/main/java/com/songoda/epicfarming/utils/CropType.java
Normal file
@ -0,0 +1,107 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
* A list of all crop types available in Minecraft that can be
|
||||
* modified by CropsReborn
|
||||
*/
|
||||
public enum CropType {
|
||||
|
||||
WHEAT("Wheat", Material.CROPS, Material.WHEAT, Material.SEEDS),
|
||||
|
||||
CARROT("Carrot", Material.CARROT, Material.CARROT_ITEM, Material.CARROT_ITEM),
|
||||
|
||||
POTATO("Potato", Material.POTATO, Material.CARROT_ITEM, Material.POTATO_ITEM),
|
||||
|
||||
BEETROOT("Beetroot", Material.BEETROOT_BLOCK, Material.BEETROOT, Material.BEETROOT_SEEDS),
|
||||
|
||||
WATER_MELON_STEM("Watermelon", Material.MELON_STEM, Material.MELON, Material.MELON_SEEDS),
|
||||
|
||||
PUMPKIN_STEM("Pumpkin", Material.PUMPKIN_STEM, Material.PUMPKIN, Material.PUMPKIN_SEEDS),
|
||||
|
||||
NETHER_WARTS("Nether Wart", Material.NETHER_WART_BLOCK, Material.NETHER_WARTS, Material.NETHER_WARTS);
|
||||
|
||||
private final String name;
|
||||
private final Material yieldMaterial, blockMaterial, seedMaterial;
|
||||
|
||||
CropType(String name, Material blockMaterial, Material yieldMaterial, Material seedMaterial) {
|
||||
this.name = name;
|
||||
this.blockMaterial = blockMaterial;
|
||||
this.seedMaterial = seedMaterial;
|
||||
this.yieldMaterial = yieldMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the friendly name of the crop
|
||||
*
|
||||
* @return the name of the crop
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blockMaterial that represents this crop type
|
||||
*
|
||||
* @return the represented blockMaterial
|
||||
*/
|
||||
public Material getBlockMaterial() {
|
||||
return blockMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the yield Material that represents this crop type
|
||||
*
|
||||
* @return the represented yieldMaterial
|
||||
*/
|
||||
public Material getYieldMaterial() {
|
||||
return yieldMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blockMaterial that represents the seed item for this crop type
|
||||
*
|
||||
* @return the represented seed blockMaterial
|
||||
*/
|
||||
public Material getSeedMaterial() {
|
||||
return seedMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a specific blockMaterial is an enumerated crop type or not
|
||||
*
|
||||
* @param material the blockMaterial to check
|
||||
* @return true if it is a crop, false otherwise
|
||||
*/
|
||||
public static boolean isCrop(Material material) {
|
||||
for (CropType type : values())
|
||||
if (type.getBlockMaterial() == material) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a specific blockMaterial is an enumerated crop type seed or not
|
||||
*
|
||||
* @param material the blockMaterial to check
|
||||
* @return true if it is a seed, false otherwise
|
||||
*/
|
||||
public static boolean isCropSeed(Material material) {
|
||||
for (CropType type : values())
|
||||
if (type.getSeedMaterial() == material) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the crop type based on the specified blockMaterial
|
||||
*
|
||||
* @param material the crop blockMaterial
|
||||
* @return the respective CropType. null if none found
|
||||
*/
|
||||
public static CropType getCropType(Material material) {
|
||||
for (CropType type : values())
|
||||
if (type.getBlockMaterial() == material) return type;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
31
src/main/java/com/songoda/epicfarming/utils/Debugger.java
Normal file
31
src/main/java/com/songoda/epicfarming/utils/Debugger.java
Normal file
@ -0,0 +1,31 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
EpicFarming plugin = EpicFarming.pl();
|
||||
return plugin.getConfig().getBoolean("System.Debugger Enabled");
|
||||
}
|
||||
|
||||
}
|
74
src/main/java/com/songoda/epicfarming/utils/Methods.java
Normal file
74
src/main/java/com/songoda/epicfarming/utils/Methods.java
Normal file
@ -0,0 +1,74 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.Lang;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class Methods {
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
try {
|
||||
EpicFarming plugin = EpicFarming.pl();
|
||||
return Arconix.pl().getApi().getGUI().getGlass(plugin.getConfig().getBoolean("settings.Rainbow-Glass"), plugin.getConfig().getInt("Interfaces.Glass Type 1"));
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack getBackgroundGlass(boolean type) {
|
||||
try {
|
||||
EpicFarming plugin = EpicFarming.pl();
|
||||
if (type)
|
||||
return Arconix.pl().getApi().getGUI().getGlass(false, plugin.getConfig().getInt("Interfaces.Glass Type 2"));
|
||||
else
|
||||
return Arconix.pl().getApi().getGUI().getGlass(false, plugin.getConfig().getInt("Interfaces.Glass Type 3"));
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static 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);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static String formatName(int level, boolean full) {
|
||||
try {
|
||||
String name = Lang.NAME_FORMAT.getConfigValue(level);
|
||||
|
||||
String info = "";
|
||||
if (full) {
|
||||
info += Arconix.pl().getApi().format().convertToInvisibleString(level + ":");
|
||||
}
|
||||
|
||||
return info + Arconix.pl().getApi().format().formatText(name);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack makeFarmItem(int level) {
|
||||
ItemStack item = new ItemStack(Material.END_ROD, 1);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Arconix.pl().getApi().format().formatText(Methods.formatName(level, true)));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
}
|
246
src/main/java/com/songoda/epicfarming/utils/SettingsManager.java
Normal file
246
src/main/java/com/songoda/epicfarming/utils/SettingsManager.java
Normal file
@ -0,0 +1,246 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
import com.songoda.arconix.api.utils.ConfigWrapper;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by songo on 6/4/2017.
|
||||
*/
|
||||
public class SettingsManager implements Listener {
|
||||
|
||||
private String pluginName = "EpicFarming";
|
||||
private final EpicFarming instance;
|
||||
|
||||
private static ConfigWrapper defs;
|
||||
|
||||
private Map<Player, String> cat = new HashMap<>();
|
||||
|
||||
public SettingsManager(EpicFarming instance) {
|
||||
this.instance = instance;
|
||||
instance.saveResource("SettingDefinitions.yml", true);
|
||||
defs = new ConfigWrapper(instance, "", "SettingDefinitions.yml");
|
||||
defs.createNewFile("Loading data file", "EpicFarming SettingDefinitions file");
|
||||
instance.getServer().getPluginManager().registerEvents(this, instance);
|
||||
}
|
||||
|
||||
public Map<Player, String> current = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
if (e.getInventory() == null
|
||||
|| e.getCurrentItem() == null
|
||||
|| !e.getCurrentItem().hasItemMeta()
|
||||
|| !e.getCurrentItem().getItemMeta().hasDisplayName()
|
||||
|| e.getWhoClicked().getOpenInventory().getTopInventory() != e.getInventory()) {
|
||||
return;
|
||||
}
|
||||
if (e.getInventory().getTitle().equals(pluginName + " Settings Manager")) {
|
||||
|
||||
if (e.getCurrentItem().getType().equals(Material.STAINED_GLASS_PANE)) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
String type = ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName());
|
||||
cat.put((Player) e.getWhoClicked(), type);
|
||||
openEditor((Player) e.getWhoClicked());
|
||||
e.setCancelled(true);
|
||||
} else if (e.getInventory().getTitle().equals(pluginName + " Settings Editor")) {
|
||||
|
||||
if (e.getCurrentItem().getType().equals(Material.STAINED_GLASS_PANE)) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
e.setCancelled(true);
|
||||
|
||||
String key = cat.get(p) + "." + ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName());
|
||||
|
||||
if (instance.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
|
||||
boolean bool = (Boolean) instance.getConfig().get(key);
|
||||
if (!bool)
|
||||
instance.getConfig().set(key, true);
|
||||
else
|
||||
instance.getConfig().set(key, false);
|
||||
finishEditing(p);
|
||||
} else {
|
||||
editObject(p, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
if (!current.containsKey(p)) {
|
||||
return;
|
||||
}
|
||||
switch (instance.getConfig().get(current.get(p)).getClass().getName()) {
|
||||
case "java.lang.Integer":
|
||||
instance.getConfig().set(current.get(p), Integer.parseInt(e.getMessage()));
|
||||
break;
|
||||
case "java.lang.Double":
|
||||
instance.getConfig().set(current.get(p), Double.parseDouble(e.getMessage()));
|
||||
break;
|
||||
case "java.lang.String":
|
||||
instance.getConfig().set(current.get(p), e.getMessage());
|
||||
break;
|
||||
}
|
||||
finishEditing(p);
|
||||
e.setCancelled(true);
|
||||
|
||||
}
|
||||
|
||||
public void finishEditing(Player p) {
|
||||
current.remove(p);
|
||||
instance.saveConfig();
|
||||
openEditor(p);
|
||||
}
|
||||
|
||||
|
||||
public void editObject(Player p, String current) {
|
||||
this.current.put(p, ChatColor.stripColor(current));
|
||||
p.closeInventory();
|
||||
p.sendMessage("");
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&7Please enter a value for &6" + current + "&7."));
|
||||
if (instance.getConfig().get(current).getClass().getName().equals("java.lang.Integer")) {
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&cUse only numbers."));
|
||||
}
|
||||
p.sendMessage("");
|
||||
}
|
||||
|
||||
public void openSettingsManager(Player p) {
|
||||
Inventory i = Bukkit.createInventory(null, 27, pluginName + " Settings Manager");
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
i.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
|
||||
int spot = 10;
|
||||
for (String key : instance.getConfig().getConfigurationSection("").getKeys(false)) {
|
||||
ItemStack item = new ItemStack(Material.WOOL, 1, (byte) (spot - 9));
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setLore(Collections.singletonList(Arconix.pl().getApi().format().formatText("&6Click To Edit This Category.")));
|
||||
meta.setDisplayName(Arconix.pl().getApi().format().formatText("&f&l" + key));
|
||||
item.setItemMeta(meta);
|
||||
i.setItem(spot, item);
|
||||
spot++;
|
||||
}
|
||||
p.openInventory(i);
|
||||
}
|
||||
|
||||
public void openEditor(Player p) {
|
||||
Inventory i = Bukkit.createInventory(null, 54, pluginName + " Settings Editor");
|
||||
|
||||
int num = 0;
|
||||
for (String key : instance.getConfig().getConfigurationSection(cat.get(p)).getKeys(true)) {
|
||||
String fKey = cat.get(p) + "." + key;
|
||||
ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Arconix.pl().getApi().format().formatText("&6" + key));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
switch (instance.getConfig().get(fKey).getClass().getName()) {
|
||||
case "java.lang.Boolean":
|
||||
|
||||
item.setType(Material.LEVER);
|
||||
boolean bool = (Boolean) instance.getConfig().get(fKey);
|
||||
|
||||
if (!bool)
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&c" + false));
|
||||
else
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&a" + true));
|
||||
|
||||
break;
|
||||
case "java.lang.String":
|
||||
item.setType(Material.PAPER);
|
||||
String str = (String) instance.getConfig().get(fKey);
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&9" + str));
|
||||
break;
|
||||
case "java.lang.Integer":
|
||||
item.setType(Material.WATCH);
|
||||
|
||||
int in = (Integer) instance.getConfig().get(fKey);
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&5" + in));
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
if (defs.getConfig().contains(fKey)) {
|
||||
String text = defs.getConfig().getString(key);
|
||||
|
||||
Pattern regex = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL);
|
||||
Matcher m = regex.matcher(text);
|
||||
while (m.find()) {
|
||||
if (m.end() != text.length() || m.group().length() != 0)
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7" + m.group()));
|
||||
}
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
i.setItem(num, item);
|
||||
num++;
|
||||
}
|
||||
p.openInventory(i);
|
||||
}
|
||||
|
||||
public void updateSettings() {
|
||||
for (settings s : settings.values()) {
|
||||
if (s.setting.equals("Main.Upgrade Particle Type")) {
|
||||
if (instance.v1_7 || instance.v1_8)
|
||||
instance.getConfig().addDefault(s.setting, "WITCH_MAGIC");
|
||||
else
|
||||
instance.getConfig().addDefault(s.setting, s.option);
|
||||
} else
|
||||
instance.getConfig().addDefault(s.setting, s.option);
|
||||
}
|
||||
}
|
||||
|
||||
public enum settings {
|
||||
o1("Main.Upgrade With Economy", true),
|
||||
o2("Main.Upgrade With XP", true),
|
||||
o3("Main.Upgrade Particle Type", "SPELL_WITCH"),
|
||||
o4("Main.Sounds Enabled", true),
|
||||
o5("Main.Farm Tick Speed", 70),
|
||||
o6("Main.Growth Tick Speed", 20),
|
||||
o7("Main.Clear Tick Speed", 1800),
|
||||
|
||||
o8("Interfaces.Economy Icon", "DOUBLE_PLANT"),
|
||||
o9("Interfaces.XP Icon", "EXP_BOTTLE"),
|
||||
o10("Interfaces.Glass Type 1", 7),
|
||||
o11("Interfaces.Glass Type 2", 11),
|
||||
o12("Interfaces.Glass Type 3", 3),
|
||||
|
||||
o13("System.Debugger Enabled", false);
|
||||
|
||||
private String setting;
|
||||
private Object option;
|
||||
|
||||
settings(String setting, Object option) {
|
||||
this.setting = setting;
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user