This commit is contained in:
Brianna 2019-09-11 12:21:55 -04:00
parent 1b8a1b5acf
commit df6b7152a9
22 changed files with 358 additions and 398 deletions

View File

@ -5,8 +5,11 @@ import com.songoda.core.SongodaPlugin;
import com.songoda.core.commands.CommandManager;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.configuration.Config;
import com.songoda.core.gui.GuiManager;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.epicfarming.boost.BoostData;
import com.songoda.epicfarming.boost.BoostManager;
import com.songoda.epicfarming.commands.*;
import com.songoda.epicfarming.farming.Farm;
import com.songoda.epicfarming.farming.FarmManager;
import com.songoda.epicfarming.farming.Level;
@ -16,6 +19,7 @@ import com.songoda.epicfarming.listeners.InteractListeners;
import com.songoda.epicfarming.listeners.InventoryListeners;
import com.songoda.epicfarming.player.PlayerActionManager;
import com.songoda.epicfarming.player.PlayerData;
import com.songoda.epicfarming.settings.Settings;
import com.songoda.epicfarming.storage.Storage;
import com.songoda.epicfarming.storage.StorageRow;
import com.songoda.epicfarming.storage.types.StorageYaml;
@ -27,7 +31,6 @@ import com.songoda.epicfarming.utils.Methods;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.PluginManager;
@ -46,6 +49,7 @@ public class EpicFarming extends SongodaPlugin {
private final Config dataConfig = new Config(this, "data.yml");
private final Config levelsFile = new Config(this, "levels.yml");
private final GuiManager guiManager = new GuiManager(this);
private FarmManager farmManager;
private LevelManager levelManager;
private PlayerActionManager playerActionManager;
@ -82,18 +86,29 @@ public class EpicFarming extends SongodaPlugin {
// Run Songoda Updater
SongodaCore.registerPlugin(this, 21, CompatibleMaterial.WHEAT);
checkStorage();
// Load Economy
EconomyManager.load();
this.setupConfig();
// Setup Config
Settings.setupConfig();
this.setLocale(Settings.LANGUGE_MODE.getString(), false);
// Setup language
String langMode = getConfig().getString("System.Language Mode");
Locale.init(this);
Locale.saveDefaultLocale("en_US");
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode", langMode));
// Set economy preference
EconomyManager.getManager().setPreferredHook(Settings.ECONOMY_PLUGIN.getString());
dataFile.createNewFile("Loading Data File", "EpicFarming Data File");
this.loadDataFile();
// Register commands
this.commandManager = new CommandManager(this);
this.commandManager.addCommand(new CommandEpicFarming(this))
.addSubCommands(
new CommandBoost(this),
new CommandGiveFarmItem(this),
new CommandReload(this),
new CommandSettings(this)
);
dataConfig.load();
this.storage = new StorageYaml(this);
this.loadLevelManager();
@ -135,16 +150,14 @@ public class EpicFarming extends SongodaPlugin {
}
}
// Save data initially so that if the person reloads again fast they don't lose all their data.
this.saveToFile();
}, 10);
this.references = new References();
PluginManager pluginManager = Bukkit.getPluginManager();
// Register Listeners
guiManager.init();
PluginManager pluginManager = Bukkit.getPluginManager();
pluginManager.registerEvents(new BlockListeners(this), this);
pluginManager.registerEvents(new InteractListeners(this), this);
pluginManager.registerEvents(new InventoryListeners(this), this);
@ -159,6 +172,7 @@ public class EpicFarming extends SongodaPlugin {
HopperTask.startTask(this);
}, 20L);
// Start auto save
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000);
}
@ -166,7 +180,6 @@ public class EpicFarming extends SongodaPlugin {
public void onConfigReload() {
this.setLocale(getConfig().getString("System.Language Mode"), true);
this.locale.reloadMessages();
this.blacklistHandler.reload();
loadLevelManager();
}
@ -175,10 +188,6 @@ public class EpicFarming extends SongodaPlugin {
return Arrays.asList(levelsFile);
}
private void checkStorage() {
this.storage = new StorageYaml(this);
}
private void loadLevelManager() {
if (!levelsFile.getFile().exists())
this.saveResource("levels.yml", false);
@ -208,20 +217,9 @@ public class EpicFarming extends SongodaPlugin {
* Saves registered farms to file.
*/
private void saveToFile() {
checkStorage();
storage.doSave();
}
private void loadDataFile() {
dataFile.getConfig().options().copyDefaults(true);
dataFile.saveConfig();
}
public Locale getLocale() {
return locale;
}
public int getLevelFromItem(ItemStack item) {
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) return 0;
if (item.getItemMeta().getDisplayName().contains(":")) {
@ -231,10 +229,10 @@ public class EpicFarming extends SongodaPlugin {
}
public ItemStack makeFarmItem(Level level) {
ItemStack item = new ItemStack(Material.valueOf(EpicFarming.getInstance().getConfig().getString("Main.Farm Block Material")), 1);
ItemStack item = Settings.FARM_BLOCK_MATERIAL.getMaterial().getItem();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(Methods.formatText(Methods.formatName(level.getLevel(), true)));
String line = getLocale().getMessage("general.nametag.lore");
String line = getLocale().getMessage("general.nametag.lore").getMessage();
if (!line.equals("")) meta.setLore(Arrays.asList(line));
item.setItemMeta(meta);
return item;
@ -271,4 +269,8 @@ public class EpicFarming extends SongodaPlugin {
public EntityTask getEntityTask() {
return entityTask;
}
public GuiManager getGuiManager() {
return guiManager;
}
}

View File

@ -1,31 +1,35 @@
package com.songoda.epicfarming.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.boost.BoostData;
import com.songoda.epicfarming.command.AbstractCommand;
import com.songoda.epicfarming.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class CommandBoost extends AbstractCommand {
public CommandBoost(AbstractCommand parent) {
super("boost", parent, false);
final EpicFarming instance;
public CommandBoost(EpicFarming instance) {
super(false, "boost");
this.instance = instance;
}
@Override
protected ReturnType runCommand(EpicFarming instance, CommandSender sender, String... args) {
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 3) {
return ReturnType.SYNTAX_ERROR;
}
if (Bukkit.getPlayer(args[1]) == null) {
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&cThat player does not exist..."));
instance.getLocale().newMessage("&cThat player does not exist...").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
} else if (!Methods.isInt(args[2])) {
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&6" + args[2] + " &7is not a number..."));
} else if (!Methods.isInt(args[1])) {
instance.getLocale().newMessage("&6" + args[1] + " &7is not a number...").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
} else {
Calendar c = Calendar.getInstance();
@ -52,7 +56,7 @@ public class CommandBoost extends AbstractCommand {
c.add(Calendar.YEAR, Integer.parseInt(arr2[1]));
time = " &7for &6" + arr2[1] + " years&7.";
} else {
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7" + args[3] + " &7is invalid."));
instance.getLocale().newMessage("&7" + args[2] + " &7is invalid.").sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
}
} else {
@ -61,11 +65,17 @@ public class CommandBoost extends AbstractCommand {
BoostData boostData = new BoostData(Integer.parseInt(args[2]), c.getTime().getTime(), Bukkit.getPlayer(args[1]).getUniqueId());
instance.getBoostManager().addBoostToPlayer(boostData);
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Successfully boosted &6" + Bukkit.getPlayer(args[1]).getName() + "'s &7farms yield rates by &6" + args[2] + "x" + time));
instance.getLocale().newMessage("&7Successfully boosted &6" + Bukkit.getPlayer(args[0]).getName()
+ "'s &7furnaces reward amounts by &6" + args[2] + "x" + time).sendPrefixedMessage(sender);
}
return ReturnType.FAILURE;
}
@Override
protected List<String> onTab(CommandSender commandSender, String... strings) {
return null;
}
@Override
public String getPermissionNode() {
return "epicfarming.admin";

View File

@ -1,24 +1,30 @@
package com.songoda.epicfarming.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.command.AbstractCommand;
import com.songoda.epicfarming.utils.Methods;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.util.List;
public class CommandEpicFarming extends AbstractCommand {
public CommandEpicFarming() {
super("EpicFarming", null, false);
final EpicFarming instance;
public CommandEpicFarming(EpicFarming instance) {
super(false, "EpicFarming");
this.instance = instance;
}
@Override
protected ReturnType runCommand(EpicFarming instance, CommandSender sender, String... args) {
protected ReturnType runCommand(CommandSender sender, String... args) {
sender.sendMessage("");
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
instance.getLocale().newMessage("&7Version " + instance.getDescription().getVersion()
+ " Created with <3 by &5&l&oSongoda").sendPrefixedMessage(sender);
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
for (AbstractCommand command : instance.getCommandManager().getAllCommands()) {
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
}
}
sender.sendMessage("");
@ -26,6 +32,11 @@ public class CommandEpicFarming extends AbstractCommand {
return ReturnType.SUCCESS;
}
@Override
protected List<String> onTab(CommandSender commandSender, String... strings) {
return null;
}
@Override
public String getPermissionNode() {
return null;

View File

@ -1,52 +1,64 @@
package com.songoda.epicfarming.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.command.AbstractCommand;
import com.songoda.epicfarming.farming.Level;
import com.songoda.epicfarming.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class CommandGiveFarmItem extends AbstractCommand {
public CommandGiveFarmItem(AbstractCommand parent) {
super("givefarmitem", parent, false);
final EpicFarming instance;
public CommandGiveFarmItem(EpicFarming instance) {
super(false, "givefarmitem");
this.instance = instance;
}
@Override
protected ReturnType runCommand(EpicFarming instance, CommandSender sender, String... args) {
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length == 2) return ReturnType.SYNTAX_ERROR;
Level level = instance.getLevelManager().getLowestLevel();
Player player;
if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) {
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cThat player does not exist or is currently offline."));
Level level = instance.getLevelManager().getLowestLevel();
Player player;
if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) {
instance.getLocale().newMessage("&cThat player does not exist or is currently offline.").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
} else if (args.length == 1) {
if (!(sender instanceof Player)) {
instance.getLocale().newMessage("&cYou need to be a player to give a farm item to yourself.").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
} else if (args.length == 1) {
if (!(sender instanceof Player)) {
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cYou need to be a player to give a farm item to yourself."));
return ReturnType.FAILURE;
}
player = (Player)sender;
} else {
player = Bukkit.getPlayer(args[1]);
}
player = (Player) sender;
} else {
player = Bukkit.getPlayer(args[1]);
}
if (args.length >= 3 && !instance.getLevelManager().isLevel(Integer.parseInt(args[2]))) {
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cNot a valid level... The current valid levels are: &4" + instance.getLevelManager().getLowestLevel().getLevel() + "-" + instance.getLevelManager().getHighestLevel().getLevel() + "&c."));
return ReturnType.FAILURE;
} else if (args.length != 1){
if (args.length >= 3 && !instance.getLevelManager().isLevel(Integer.parseInt(args[2]))) {
instance.getLocale().newMessage("&cNot a valid level... The current valid levels are: &4"
+ instance.getLevelManager().getLowestLevel().getLevel() + "-"
+ instance.getLevelManager().getHighestLevel().getLevel() + "&c.").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
} else if (args.length != 1) {
level = instance.getLevelManager().getLevel(Integer.parseInt(args[2]));
}
player.getInventory().addItem(instance.makeFarmItem(level));
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.success", level.getLevel()));
level = instance.getLevelManager().getLevel(Integer.parseInt(args[2]));
}
player.getInventory().addItem(instance.makeFarmItem(level));
instance.getLocale().getMessage("command.give.success")
.processPlaceholder("level", level.getLevel()).sendPrefixedMessage(player);
return ReturnType.SUCCESS;
}
@Override
protected List<String> onTab(CommandSender commandSender, String... strings) {
return null;
}
@Override
public String getPermissionNode() {
return "epicfarming.admin";

View File

@ -1,21 +1,30 @@
package com.songoda.epicfarming.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.command.AbstractCommand;
import com.songoda.epicfarming.utils.Methods;
import org.bukkit.command.CommandSender;
import java.util.List;
public class CommandReload extends AbstractCommand {
public CommandReload(AbstractCommand parent) {
super("reload", parent, false);
final EpicFarming instance;
public CommandReload(EpicFarming instance) {
super(false, "reload");
this.instance = instance;
}
@Override
protected ReturnType runCommand(EpicFarming instance, CommandSender sender, String... args) {
instance.reload();
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Configuration and Language files reloaded."));
return ReturnType.SUCCESS;
protected ReturnType runCommand(CommandSender sender, String... args) {
instance.reloadConfig();
instance.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
return AbstractCommand.ReturnType.SUCCESS;
}
@Override
protected List<String> onTab(CommandSender commandSender, String... strings) {
return null;
}
@Override

View File

@ -1,22 +1,33 @@
package com.songoda.epicfarming.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.configuration.editor.PluginConfigGui;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.command.AbstractCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class CommandSettings extends AbstractCommand {
public CommandSettings(AbstractCommand parent) {
super("settings", parent, true);
final EpicFarming instance;
public CommandSettings(EpicFarming instance) {
super(true, "settings");
this.instance = instance;
}
@Override
protected ReturnType runCommand(EpicFarming instance, CommandSender sender, String... args) {
instance.getSettingsManager().openSettingsManager((Player)sender);
protected ReturnType runCommand(CommandSender sender, String... args) {
instance.getGuiManager().showGUI((Player) sender, new PluginConfigGui(instance));
return ReturnType.SUCCESS;
}
@Override
protected List<String> onTab(CommandSender commandSender, String... strings) {
return null;
}
@Override
public String getPermissionNode() {
return "epicfarming.admin";

View File

@ -1,6 +1,5 @@
package com.songoda.epicfarming.farming;
import com.songoda.epicfarming.api.farming.Farm;
import org.bukkit.Location;
public class Crop {

View File

@ -4,6 +4,7 @@ import com.songoda.core.hooks.EconomyManager;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.boost.BoostData;
import com.songoda.epicfarming.player.PlayerData;
import com.songoda.epicfarming.settings.Settings;
import com.songoda.epicfarming.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
@ -70,18 +71,23 @@ public class Farm {
ItemStack item = new ItemStack(Material.valueOf(instance.getConfig().getString("Main.Farm Block Material")), 1);
ItemMeta itemmeta = item.getItemMeta();
itemmeta.setDisplayName(instance.getLocale().getMessage("general.nametag.farm", level));
itemmeta.setDisplayName(instance.getLocale().getMessage("general.nametag.farm")
.processPlaceholder("level", level).getMessage());
List<String> lore = this.level.getDescription();
lore.add("");
if (nextLevel == null) lore.add(instance.getLocale().getMessage("event.upgrade.maxed"));
if (nextLevel == null) lore.add(instance.getLocale().getMessage("event.upgrade.maxed").getMessage());
else {
lore.add(instance.getLocale().getMessage("interface.button.level", nextLevel.getLevel()));
lore.add(instance.getLocale().getMessage("interface.button.level")
.processPlaceholder("level", nextLevel.getLevel()).getMessage());
lore.addAll(nextLevel.getDescription());
}
BoostData boostData = instance.getBoostManager().getBoost(placedBy);
if (boostData != null) {
String[] parts = instance.getLocale().getMessage("interface.button.boostedstats", Integer.toString(boostData.getMultiplier()), Methods.makeReadable(boostData.getEndTime() - System.currentTimeMillis())).split("\\|");
String[] parts = instance.getLocale().getMessage("interface.button.boostedstats")
.processPlaceholder("amount", Integer.toString(boostData.getMultiplier()))
.processPlaceholder("time", Methods.makeReadable(boostData.getEndTime() - System.currentTimeMillis()))
.getMessage().split("\\|");
lore.add("");
for (String line : parts)
lore.add(Methods.formatText(line));
@ -92,31 +98,29 @@ public class Farm {
ItemStack itemXP = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.XP Icon")), 1);
ItemMeta itemmetaXP = itemXP.getItemMeta();
itemmetaXP.setDisplayName(instance.getLocale().getMessage("interface.button.upgradewithxp"));
itemmetaXP.setDisplayName(instance.getLocale().getMessage("interface.button.upgradewithxp").getMessage());
ArrayList<String> loreXP = new ArrayList<>();
if (nextLevel != null)
loreXP.add(instance.getLocale().getMessage("interface.button.upgradewithxplore", nextLevel.getCostExperiance()));
loreXP.add(instance.getLocale().getMessage("interface.button.upgradewithxplore")
.processPlaceholder("cost", nextLevel.getCostExperiance()).getMessage());
else
loreXP.add(instance.getLocale().getMessage("event.upgrade.maxed"));
loreXP.add(instance.getLocale().getMessage("event.upgrade.maxed").getMessage());
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(instance.getLocale().getMessage("interface.button.upgradewitheconomy"));
itemmetaECO.setDisplayName(instance.getLocale().getMessage("interface.button.upgradewitheconomy").getMessage());
ArrayList<String> loreECO = new ArrayList<>();
if (nextLevel != null)
loreECO.add(instance.getLocale().getMessage("interface.button.upgradewitheconomylore", Methods.formatEconomy(nextLevel.getCostEconomy())));
loreECO.add(instance.getLocale().getMessage("interface.button.upgradewitheconomylore")
.processPlaceholder("cost", Methods.formatEconomy(nextLevel.getCostEconomy()))
.getMessage());
else
loreECO.add(instance.getLocale().getMessage("event.upgrade.maxed"));
loreECO.add(instance.getLocale().getMessage("event.upgrade.maxed").getMessage());
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("EpicFarming.Upgrade.XP")) {
inventory.setItem(11, itemXP);
}
@ -126,7 +130,7 @@ public class Farm {
if (instance.getConfig().getBoolean("Main.Upgrade With Economy") && player != null && player.hasPermission("EpicFarming.Upgrade.ECO")) {
inventory.setItem(15, itemECO);
}
/*
inventory.setItem(0, Methods.getBackgroundGlass(true));
inventory.setItem(1, Methods.getBackgroundGlass(true));
inventory.setItem(2, Methods.getBackgroundGlass(false));
@ -142,7 +146,7 @@ public class Farm {
inventory.setItem(20, Methods.getBackgroundGlass(false));
inventory.setItem(24, Methods.getBackgroundGlass(false));
inventory.setItem(25, Methods.getBackgroundGlass(true));
inventory.setItem(26, Methods.getBackgroundGlass(true));
inventory.setItem(26, Methods.getBackgroundGlass(true)); */
}
public Inventory getInventory() {
@ -206,9 +210,11 @@ public class Farm {
EpicFarming instance = EpicFarming.getInstance();
this.level = level;
if (instance.getLevelManager().getHighestLevel() != level) {
player.sendMessage(instance.getLocale().getMessage("event.upgrade.success", level.getLevel()));
instance.getLocale().getMessage("event.upgrade.success")
.processPlaceholder("level", level.getLevel()).sendPrefixedMessage(player);
} else {
player.sendMessage(instance.getLocale().getMessage("event.upgrade.successmaxed", level.getLevel()));
instance.getLocale().getMessage("event.upgrade.successmaxed")
.processPlaceholder("level", level.getLevel()).sendPrefixedMessage(player);
}
Location loc = location.clone().add(.5, .5, .5);
player.getWorld().spawnParticle(org.bukkit.Particle.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), loc, 200, .5, .5, .5);
@ -225,7 +231,7 @@ public class Farm {
public boolean tillLand(Location location) {
Player player = Bukkit.getPlayer(placedBy);
EpicFarming instance = EpicFarming.getInstance();
if (instance.getConfig().getBoolean("Main.Disable Auto Til Land")) return true;
if (Settings.DISABLE_AUTO_TIL_LAND.getBoolean()) return true;
Block block = location.getBlock();
int radius = level.getRadius();
int bx = block.getX();
@ -234,7 +240,6 @@ public class Farm {
for (int fx = -radius; fx <= radius; fx++) {
for (int fy = -2; fy <= 1; fy++) {
for (int fz = -radius; fz <= radius; fz++) {
if (!instance.getHookManager().canBuild(player, location)) continue;
Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
// ToDo: enum for all flowers.

View File

@ -27,20 +27,23 @@ public class Level {
EpicFarming instance = EpicFarming.getInstance();
description.add(instance
.getLocale()
.getMessage("interface.button.radius",
radius));
description.add(instance.getLocale().getMessage("interface.button.speed", speedMultiplier));
description.add(instance.getLocale().getMessage("interface.button.radius")
.processPlaceholder("radius", radius).getMessage());
description.add(instance.getLocale().getMessage("interface.button.speed")
.processPlaceholder("speed", speedMultiplier).getMessage());
if (autoHarvest)
description.add(instance.getLocale().getMessage("interface.button.autoharvest", autoHarvest));
description.add(instance.getLocale().getMessage("interface.button.autoharvest")
.processPlaceholder("status", autoHarvest).getMessage());
if (autoReplant)
description.add(instance.getLocale().getMessage("interface.button.autoreplant", autoReplant));
description.add(instance.getLocale().getMessage("interface.button.autoreplant")
.processPlaceholder("status", autoReplant).getMessage());
if (autoBreeding)
description.add(instance.getLocale().getMessage("interface.button.autobreeding", autoBreeding));
description.add(instance.getLocale().getMessage("interface.button.autobreeding")
.processPlaceholder("status", autoBreeding).getMessage());
}

View File

@ -0,0 +1,6 @@
package com.songoda.epicfarming.gui;
import com.songoda.core.gui.Gui;
public class GUIOverview extends Gui {
}

View File

@ -1,11 +1,10 @@
package com.songoda.epicfarming.listeners;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.api.farming.Farm;
import com.songoda.epicfarming.api.farming.Level;
import com.songoda.epicfarming.farming.Farm;
import com.songoda.epicfarming.farming.FarmManager;
import com.songoda.epicfarming.utils.Debugger;
import com.songoda.epicfarming.farming.Level;
import com.songoda.epicfarming.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -40,24 +39,14 @@ public class BlockListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockFade(BlockFadeEvent e) {
try {
if (checkForFarm(e.getBlock().getLocation())) {
e.setCancelled(true);
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
if (checkForFarm(e.getBlock().getLocation()))
e.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onGrow(BlockGrowEvent e) {
try {
if (checkForFarm(e.getNewState().getLocation())) {
e.setCancelled(true);
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
if (checkForFarm(e.getNewState().getLocation()))
e.setCancelled(true);
}
private int maxFarms(Player player) {
@ -71,54 +60,48 @@ public class BlockListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
try {
Material farmBlock = Material.valueOf(instance.getConfig().getString("Main.Farm Block Material"));
Material farmBlock = Material.valueOf(instance.getConfig().getString("Main.Farm Block Material"));
boolean allowNonCommandIssued = instance.getConfig().getBoolean("Main.Allow Non Command Issued Farm Items");
boolean allowNonCommandIssued = instance.getConfig().getBoolean("Main.Allow Non Command Issued Farm Items");
if (e.getPlayer().getItemInHand().getType() != farmBlock
|| instance.getLevelFromItem(e.getItemInHand()) == 0 && !allowNonCommandIssued) return;
if (e.getPlayer().getItemInHand().getType() != farmBlock
|| instance.getLevelFromItem(e.getItemInHand()) == 0 && !allowNonCommandIssued) return;
if (e.getBlockAgainst().getType() == farmBlock) e.setCancelled(true);
if (e.getBlockAgainst().getType() == farmBlock) e.setCancelled(true);
if (!instance.getHookManager().canBuild(e.getPlayer(), e.getBlock().getLocation())) return;
int amt = 0;
for (Farm farmm : instance.getFarmManager().getFarms().values()) {
if (!farmm.getPlacedBy().equals(e.getPlayer().getUniqueId())) continue;
amt ++;
}
int limit = maxFarms(e.getPlayer());
if (limit != -1 && amt >= limit) {
e.setCancelled(true);
e.getPlayer().sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.limit.hit", limit));
return;
}
Location location = e.getBlock().getLocation();
if (e.getBlockPlaced().getType().equals(Material.MELON_SEEDS)||e.getBlockPlaced().getType().equals(Material.PUMPKIN_SEEDS)){
if (checkForFarm(location)){
e.getPlayer().sendMessage(instance.getLocale().getMessage("event.warning.noauto"));
}
}
Bukkit.getScheduler().runTaskLater(instance, () -> {
int level = 1;
if (instance.getLevelFromItem(e.getItemInHand()) != 0) {
level = instance.getLevelFromItem(e.getItemInHand());
}
if (location.getBlock().getType() != farmBlock) return;
Farm farm = new Farm(location, instance.getLevelManager().getLevel(level), e.getPlayer().getUniqueId());
instance.getFarmManager().addFarm(location, farm);
farm.tillLand(e.getBlock().getLocation());
}, 1);
} catch (Exception ex) {
Debugger.runReport(ex);
int amt = 0;
for (Farm farmm : instance.getFarmManager().getFarms().values()) {
if (!farmm.getPlacedBy().equals(e.getPlayer().getUniqueId())) continue;
amt++;
}
int limit = maxFarms(e.getPlayer());
if (limit != -1 && amt >= limit) {
e.setCancelled(true);
instance.getLocale().getMessage("event.limit.hit")
.processPlaceholder("limit", limit).sendPrefixedMessage(e.getPlayer());
return;
}
Location location = e.getBlock().getLocation();
if (e.getBlockPlaced().getType().equals(Material.MELON_SEEDS) || e.getBlockPlaced().getType().equals(Material.PUMPKIN_SEEDS)) {
if (checkForFarm(location)) {
instance.getLocale().getMessage("event.warning.noauto").sendPrefixedMessage(e.getPlayer());
}
}
Bukkit.getScheduler().runTaskLater(instance, () -> {
int level = 1;
if (instance.getLevelFromItem(e.getItemInHand()) != 0) {
level = instance.getLevelFromItem(e.getItemInHand());
}
if (location.getBlock().getType() != farmBlock) return;
Farm farm = new Farm(location, instance.getLevelManager().getLevel(level), e.getPlayer().getUniqueId());
instance.getFarmManager().addFarm(location, farm);
farm.tillLand(e.getBlock().getLocation());
}, 1);
}
private boolean checkForFarm(Location location) {
@ -151,37 +134,27 @@ public class BlockListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
try {
if (event.getBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Farm Block Material")))
return;
if (event.getBlock().getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial().getMaterial())
return;
Farm farm = instance.getFarmManager().removeFarm(event.getBlock().getLocation());
Farm farm = instance.getFarmManager().removeFarm(event.getBlock().getLocation());
if (farm == null) return;
if (farm == null) return;
instance.getFarmTask().getCrops(farm, false);
if (!instance.getHookManager().canBuild(event.getPlayer(), event.getBlock().getLocation())) {
event.setCancelled(true);
return;
}
event.setCancelled(true);
instance.getFarmTask().getCrops(farm, false);
ItemStack item = instance.makeFarmItem(farm.getLevel());
event.setCancelled(true);
Block block = event.getBlock();
ItemStack item = instance.makeFarmItem(farm.getLevel());
block.setType(Material.AIR);
block.getLocation().getWorld().dropItemNaturally(block.getLocation().add(.5, .5, .5), item);
Block block = event.getBlock();
block.setType(Material.AIR);
block.getLocation().getWorld().dropItemNaturally(block.getLocation().add(.5, .5, .5), item);
for (ItemStack itemStack : ((Farm) farm).dumpInventory()) {
if (itemStack == null) continue;
farm.getLocation().getWorld().dropItemNaturally(farm.getLocation().add(.5, .5, .5), itemStack);
}
} catch (Exception ex) {
Debugger.runReport(ex);
for (ItemStack itemStack : farm.dumpInventory()) {
if (itemStack == null) continue;
farm.getLocation().getWorld().dropItemNaturally(farm.getLocation().add(.5, .5, .5), itemStack);
}
}
@ -218,30 +191,26 @@ public class BlockListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockExplode(BlockExplodeEvent event) {
try {
if (event.getBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Farm Block Material")))
return;
if (event.getBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Farm Block Material")))
return;
Farm farm = instance.getFarmManager().removeFarm(event.getBlock().getLocation());
Farm farm = instance.getFarmManager().removeFarm(event.getBlock().getLocation());
if (farm == null) return;
instance.getFarmTask().getCrops(farm, false);
if (farm == null) return;
instance.getFarmTask().getCrops(farm, false);
event.setCancelled(true);
event.setCancelled(true);
ItemStack item = instance.makeFarmItem(farm.getLevel());
ItemStack item = instance.makeFarmItem(farm.getLevel());
Block block = event.getBlock();
Block block = event.getBlock();
block.setType(Material.AIR);
block.getLocation().getWorld().dropItemNaturally(block.getLocation().add(.5, .5, .5), item);
block.setType(Material.AIR);
block.getLocation().getWorld().dropItemNaturally(block.getLocation().add(.5, .5, .5), item);
for (ItemStack itemStack : ((Farm) farm).dumpInventory()) {
if (itemStack == null) continue;
farm.getLocation().getWorld().dropItemNaturally(farm.getLocation().add(.5, .5, .5), itemStack);
}
} catch (Exception ex) {
Debugger.runReport(ex);
for (ItemStack itemStack : ((Farm) farm).dumpInventory()) {
if (itemStack == null) continue;
farm.getLocation().getWorld().dropItemNaturally(farm.getLocation().add(.5, .5, .5), itemStack);
}
}
}

View File

@ -1,8 +1,6 @@
package com.songoda.epicfarming.listeners;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.farming.Farm;
import com.songoda.epicfarming.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
@ -24,25 +22,16 @@ public class InteractListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockInteract(PlayerInteractEvent e) {
try {
if (e.getClickedBlock() == null || e.getClickedBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Farm Block Material")))
return;
if (e.getClickedBlock() == null || e.getClickedBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Farm Block Material")))
return;
if (!instance.getHookManager().canBuild(e.getPlayer(), e.getClickedBlock().getLocation())) {
e.setCancelled(true);
return;
}
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
Location location = e.getClickedBlock().getLocation();
Location location = e.getClickedBlock().getLocation();
if (instance.getFarmManager().getFarms().containsKey(location)) {
e.setCancelled(true);
((Farm)instance.getFarmManager().getFarm(location)).view(e.getPlayer());
}
} catch (Exception ex) {
Debugger.runReport(ex);
if (instance.getFarmManager().getFarms().containsKey(location)) {
e.setCancelled(true);
instance.getFarmManager().getFarm(location).view(e.getPlayer());
}
}
}

View File

@ -1,16 +1,16 @@
package com.songoda.epicfarming.listeners;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.api.farming.UpgradeType;
import com.songoda.epicfarming.farming.Farm;
import com.songoda.epicfarming.farming.UpgradeType;
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.
*/
@ -24,49 +24,40 @@ public class InventoryListeners implements Listener {
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
try {
if (instance.getPlayerActionManager().getPlayerAction((Player)event.getWhoClicked()).getFarm() == null
|| event.getInventory() == null || event.getRawSlot() >= event.getView().getTopInventory().getSize()) return;
if (instance.getPlayerActionManager().getPlayerAction((Player) event.getWhoClicked()).getFarm() == null
|| event.getRawSlot() >= event.getView().getTopInventory().getSize()) return;
if (event.getInventory().getType() != InventoryType.CHEST) 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);
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(UpgradeType.EXPERIENCE, player);
player.closeInventory();
}
Player player = (Player)event.getWhoClicked();
if (event.getSlot() == 11 && player.hasPermission("EpicFarming.Upgrade.XP")) {
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
farm.upgrade(UpgradeType.EXPERIENCE, player);
player.closeInventory();
}
} else if (event.getSlot() == 15 && player.hasPermission("EpicFarming.Upgrade.ECO")) {
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
farm.upgrade(UpgradeType.ECONOMY, player);
player.closeInventory();
}
} else if (event.getSlot() == 15 && player.hasPermission("EpicFarming.Upgrade.ECO")) {
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
farm.upgrade(UpgradeType.ECONOMY, player);
player.closeInventory();
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
}
@EventHandler
public void onClose(InventoryCloseEvent event) {
try {
PlayerData playerData = instance.getPlayerActionManager().getPlayerAction((Player)event.getPlayer());
PlayerData playerData = instance.getPlayerActionManager().getPlayerAction((Player) event.getPlayer());
if (playerData.getFarm() != null) {
playerData.getFarm().setViewing(null);
}
instance.getPlayerActionManager().getPlayerAction((Player)event.getPlayer()).setFarm(null);
} catch (Exception ex) {
Debugger.runReport(ex);
if (playerData.getFarm() != null) {
playerData.getFarm().setViewing(null);
}
instance.getPlayerActionManager().getPlayerAction((Player) event.getPlayer()).setFarm(null);
}
}

View File

@ -42,8 +42,8 @@ public class Settings {
public static final ConfigSetting ANIMATE = new ConfigSetting(config, "Main.Animate", true,
"Should the processed farm item be animated above the farm item?");
public static final ConfigSetting AUTO_TIL_LAND = new ConfigSetting(config, "Main.Disable Auto Til Land", false,
"Should farms auto til land around them?");
public static final ConfigSetting DISABLE_AUTO_TIL_LAND = new ConfigSetting(config, "Main.Disable Auto Til Land", false,
"Should farms not auto til land around them?");
public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(config, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(),
"Which economy plugin should be used?",

View File

@ -4,10 +4,6 @@ import com.songoda.core.configuration.Config;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.boost.BoostData;
import com.songoda.epicfarming.farming.Farm;
import com.songoda.epicFarming.EpicFarming;
import com.songoda.epicFarming.boost.BoostData;
import com.songoda.epicFarming.furnace.Furnace;
import com.songoda.epicFarming.utils.Methods;
import com.songoda.epicfarming.utils.Methods;
import java.util.List;
@ -37,10 +33,10 @@ public abstract class Storage {
if (farm.getLocation() == null
|| farm.getLocation().getWorld() == null) continue;
String locstr = Methods.serializeLocation(farm.getLocation());
prepareSaveItem("farms",new StorageItem("location",locstr),
new StorageItem("level",farm.getLevel().getLevel()),
new StorageItem("placedby",farm.getPlacedBy().toString()),
new StorageItem("contents",((Farm)farm).dumpInventory()));
prepareSaveItem("farms", new StorageItem("location", locstr),
new StorageItem("level", farm.getLevel().getLevel()),
new StorageItem("placedby", farm.getPlacedBy().toString()),
new StorageItem("contents", ((Farm) farm).dumpInventory()));
}
/*
@ -48,9 +44,9 @@ public abstract class Storage {
*/
for (BoostData boostData : instance.getBoostManager().getBoosts()) {
String endTime = String.valueOf(boostData.getEndTime());
prepareSaveItem("boosts",new StorageItem("endtime",endTime),
new StorageItem("amount",boostData.getMultiplier()),
new StorageItem("player",boostData.getPlayer()));
prepareSaveItem("boosts", new StorageItem("endtime", endTime),
new StorageItem("amount", boostData.getMultiplier()),
new StorageItem("player", boostData.getPlayer()));
}
}

View File

@ -1,14 +1,15 @@
package com.songoda.epicfarming.storage;
import com.songoda.epicFarming.utils.Methods;
import org.bukkit.Location;
import com.songoda.epicfarming.utils.Serializers;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class StorageItem {
private final Object object;
private Object object;
private String key = null;
public StorageItem(Object object) {
@ -29,16 +30,6 @@ public class StorageItem {
this.object = object.toString();
}
public StorageItem(String key, boolean type, List<Location> blocks) {
StringBuilder object = new StringBuilder();
for (Location location : blocks) {
object.append(Methods.serializeLocation(location));
object.append(";;");
}
this.key = key;
this.object = object.toString();
}
public String getKey() {
return key;
}
@ -77,4 +68,17 @@ public class StorageItem {
return list;
}
public List<ItemStack> asItemStackList() {
List<ItemStack> list = new ArrayList<>();
if (object == null) return list;
String obj = (String) object;
if (obj.equals("[]")) return list;
List<String> sers = new ArrayList<>(Arrays.asList(obj.split(";;")));
for (String ser : sers) {
list.add(Serializers.deserialize(ser));
}
return list;
}
}

View File

@ -1,9 +1,9 @@
package com.songoda.epicfarming.storage.types;
import com.songoda.epicFarming.EpicFarming;
import com.songoda.epicFarming.storage.Storage;
import com.songoda.epicFarming.storage.StorageItem;
import com.songoda.epicFarming.storage.StorageRow;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.storage.Storage;
import com.songoda.epicfarming.storage.StorageItem;
import com.songoda.epicfarming.storage.StorageRow;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemorySection;

View File

@ -1,9 +1,8 @@
package com.songoda.epicfarming.tasks;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.api.farming.Farm;
import com.songoda.epicfarming.boost.BoostData;
import com.songoda.epicfarming.utils.Debugger;
import com.songoda.epicfarming.farming.Farm;
import com.songoda.epicfarming.utils.EntityInfo;
import com.songoda.epicfarming.utils.Methods;
import org.bukkit.Location;
@ -138,7 +137,7 @@ public class EntityTask extends BukkitRunnable {
List<Entity> entities = new ArrayList<>(entities1);
Collections.shuffle(entities);
entities.removeIf(e -> lastBreed.containsKey(e) || !(e instanceof Ageable) || !((Ageable)e).isAdult());
entities.removeIf(e -> lastBreed.containsKey(e) || !(e instanceof Ageable) || !((Ageable) e).isAdult());
Map<EntityType, Long> counts =
entities.stream().collect(Collectors.groupingBy(Entity::getType, Collectors.counting()));
@ -200,16 +199,12 @@ public class EntityTask extends BukkitRunnable {
}
private boolean canMove(Inventory inventory, ItemStack item) {
try {
if (inventory.firstEmpty() != -1) return true;
if (inventory.firstEmpty() != -1) return true;
for (ItemStack stack : inventory.getContents()) {
if (stack.isSimilar(item) && stack.getAmount() < stack.getMaxStackSize()) {
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;
}

View File

@ -1,12 +1,10 @@
package com.songoda.epicfarming.tasks;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.api.farming.Farm;
import com.songoda.epicfarming.boost.BoostData;
import com.songoda.epicfarming.farming.Crop;
import com.songoda.epicfarming.farming.Farm;
import com.songoda.epicfarming.utils.CropType;
import com.songoda.epicfarming.utils.Debugger;
import com.songoda.epicfarming.utils.Methods;
import org.bukkit.CropState;
import org.bukkit.Location;
@ -18,7 +16,8 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Crops;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.*;
import java.util.List;
import java.util.Random;
public class FarmTask extends BukkitRunnable {
@ -117,9 +116,9 @@ public class FarmTask extends BukkitRunnable {
}
public List<Block> getCrops(Farm farm, boolean add) {
if (System.currentTimeMillis() - ((Farm)farm).getLastCached() > 30 * 1000 || !add) {
((Farm)farm).setLastCached(System.currentTimeMillis());
if (add) ((Farm)farm).clearCache();
if (System.currentTimeMillis() - ((Farm) farm).getLastCached() > 30 * 1000 || !add) {
((Farm) farm).setLastCached(System.currentTimeMillis());
if (add) ((Farm) farm).clearCache();
Block block = farm.getLocation().getBlock();
int radius = farm.getLevel().getRadius();
int bx = block.getX();
@ -133,10 +132,10 @@ public class FarmTask extends BukkitRunnable {
if (!(b2.getState().getData() instanceof Crops)) continue;
if (add) {
((Farm)farm).addCachedCrop(b2);
((Farm) farm).addCachedCrop(b2);
continue;
}
((Farm)farm).removeCachedCrop(b2);
((Farm) farm).removeCachedCrop(b2);
plugin.getGrowthTask().removeCropByLocation(b2.getLocation());
}
}
@ -146,16 +145,12 @@ public class FarmTask extends BukkitRunnable {
}
private boolean canMove(Inventory inventory, ItemStack item) {
try {
if (inventory.firstEmpty() != -1) return true;
if (inventory.firstEmpty() != -1) return true;
for (ItemStack stack : inventory.getContents()) {
if (stack.isSimilar(item) && stack.getAmount() < stack.getMaxStackSize()) {
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;
}

View File

@ -1,8 +1,8 @@
package com.songoda.epicfarming.tasks;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.api.farming.Farm;
import com.songoda.epicfarming.api.farming.FarmManager;
import com.songoda.epicfarming.farming.Farm;
import com.songoda.epicfarming.farming.FarmManager;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -16,7 +16,7 @@ public class HopperTask extends BukkitRunnable {
private static HopperTask instance;
private final FarmManager manager;
private HopperTask(EpicFarming plugin) {
this.manager = plugin.getFarmManager();
}

View File

@ -5,7 +5,6 @@ import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
@ -20,79 +19,34 @@ public class Methods {
private static Map<String, Location> serializeCache = new HashMap<>();
public static ItemStack getGlass() {
try {
EpicFarming instance = EpicFarming.getInstance();
return getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
public static ItemStack getBackgroundGlass(boolean type) {
try {
EpicFarming instance = EpicFarming.getInstance();
if (type)
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2"));
else
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3"));
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
private static ItemStack getGlass(Boolean rainbow, int type) {
int randomNum = 1 + (int) (Math.random() * 6);
ItemStack glass;
if (rainbow) {
glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) randomNum);
} else {
glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) type);
}
ItemMeta glassmeta = glass.getItemMeta();
glassmeta.setDisplayName("§l");
glass.setItemMeta(glassmeta);
return glass;
}
public static String formatName(int level, boolean full) {
try {
String name = EpicFarming.getInstance().getLocale().getMessage("general.nametag.farm", level);
String name = EpicFarming.getInstance().getLocale().getMessage("general.nametag.farm")
.processPlaceholder("level", level).getMessage();
String info = "";
if (full) {
info += Methods.convertToInvisibleString(level + ":");
}
return info + Methods.formatText(name);
} catch (Exception ex) {
Debugger.runReport(ex);
String info = "";
if (full) {
info += Methods.convertToInvisibleString(level + ":");
}
return null;
return info + Methods.formatText(name);
}
public static void animate(Location location, Material mat) {
try {
if (!EpicFarming.getInstance().getConfig().getBoolean("Main.Animate")) return;
Block block = location.getBlock();
if (block.getRelative(0, 1, 0).getType() != Material.AIR && EpicFarming.getInstance().getConfig().getBoolean("Main.Do Dispenser Animation"))
return;
Item i = block.getWorld().dropItem(block.getLocation().add(0.5, 1, 0.5), new ItemStack(mat));
if (!EpicFarming.getInstance().getConfig().getBoolean("Main.Animate")) return;
Block block = location.getBlock();
if (block.getRelative(0, 1, 0).getType() != Material.AIR && EpicFarming.getInstance().getConfig().getBoolean("Main.Do Dispenser Animation"))
return;
Item i = block.getWorld().dropItem(block.getLocation().add(0.5, 1, 0.5), new ItemStack(mat));
// Support for EpicHoppers suction.
i.setMetadata("grabbed", new FixedMetadataValue(EpicFarming.getInstance(), "true"));
// Support for EpicHoppers suction.
i.setMetadata("grabbed", new FixedMetadataValue(EpicFarming.getInstance(), "true"));
i.setMetadata("betterdrops_ignore", new FixedMetadataValue(EpicFarming.getInstance(), true));
i.setPickupDelay(3600);
i.setMetadata("betterdrops_ignore", new FixedMetadataValue(EpicFarming.getInstance(), true));
i.setPickupDelay(3600);
i.setVelocity(new Vector(0, .3, 0));
i.setVelocity(new Vector(0, .3, 0));
Bukkit.getScheduler().scheduleSyncDelayedTask(EpicFarming.getInstance(), i::remove, 10);
} catch (Exception ex) {
Debugger.runReport(ex);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(EpicFarming.getInstance(), i::remove, 10);
}
public static String formatText(String text) {
@ -136,14 +90,14 @@ public class Methods {
* @return The serialized data.
*/
public static String serializeLocation(Location location) {
if (location == null)
if (location == null || location.getWorld() == null)
return "";
String w = location.getWorld().getName();
double x = location.getX();
double y = location.getY();
double z = location.getZ();
String str = w + ":" + x + ":" + y + ":" + z;
str = str.replace(".0", "").replace("/", "");
str = str.replace(".0", "").replace(".", "/");
return str;
}

View File

@ -11,14 +11,13 @@ interface.button.upgradewithxplore = "&7Cost: &a%cost% Levels"
interface.button.upgradewitheconomy = "&aUpgrade with ECO"
interface.button.upgradewitheconomylore = "&7Cost: &a$%cost%"
interface.button.level = "&6Next Level &7%level%"
interface.button.radius = "&7Radius: &6%speed%"
interface.button.radius = "&7Radius: &6%radius%"
interface.button.speed = "&7Speed: &6%speed%x"
interface.button.autoharvest = "&7Auto Harvest: &6%status%"
interface.button.autoreplant = "&7Auto Replant: &6%status%"
interface.button.autobreeding = "&7Auto Breeding: &6%status%"
interface.button.boostedstats = "&a&lCurrently boosted!|&7Yield rate multiplied by &6%amount%x&7.|&7Expires in &6%time%&7."
#Command Messages
command.give.success = "&7You have been given a &6level %level% &7farm item."