Something weird going on lol

This commit is contained in:
NovaFox161 2018-05-06 12:51:39 -05:00
parent 107bdc6dc1
commit 6939dcd475
18 changed files with 557 additions and 125 deletions

View File

@ -181,5 +181,11 @@
<version>2.6</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</project>

View File

@ -44,6 +44,7 @@ public class EpicFarming extends JavaPlugin implements Listener {
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 Locale locale;
private FarmingHandler farmingHandler;
private GrowthHandler growthHandler;
@ -63,29 +64,18 @@ public class EpicFarming extends JavaPlugin implements Listener {
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();
// Locales
Locale.init(this);
Locale.saveDefaultLocale("en_US");
this.locale = Locale.getLocale(this.getConfig().getString("Locale", "en_US"));
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);
}
loadLevelManager();
farmManager = new FarmManager();
@ -123,6 +113,8 @@ public class EpicFarming extends JavaPlugin implements Listener {
this.getServer().getPluginManager().registerEvents(this, this);
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000);
new MCUpdate(this, true);
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
@ -142,6 +134,26 @@ public class EpicFarming extends JavaPlugin implements Listener {
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
}
private void loadLevelManager() {
// Load an instance of LevelManager
levelManager = new LevelManager();
/*
* Register Levels into LevelManager from configuration.
*/
levelManager.clear();
for (String levelName : getConfig().getConfigurationSection("settings.levels").getKeys(false)) {
int level = Integer.valueOf(levelName.split("-")[1]);
int costExperiance = getConfig().getInt("settings.levels." + levelName + ".Cost-xp");
int costEconomy = getConfig().getInt("settings.levels." + levelName + ".Cost-eco");
int radius = getConfig().getInt("settings.levels." + levelName + ".Radius");
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);
}
}
/*
* Saves registered farms to file.
*/
@ -169,7 +181,7 @@ public class EpicFarming extends JavaPlugin implements Listener {
hooks.hooksFile.createNewFile("Loading hooks File", "EpicFarming hooks File");
hooks = new HookHandler();
hooks.hook();
loadLanguageFile();
locale.reloadMessages();
references = new References();
reloadConfig();
saveConfig();
@ -223,17 +235,6 @@ public class EpicFarming extends JavaPlugin implements Listener {
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();
@ -247,6 +248,10 @@ public class EpicFarming extends JavaPlugin implements Listener {
return INSTANCE;
}
public Locale getLocale() {
return locale;
}
public FarmManager getFarmManager() {
return farmManager;
}

View File

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

View File

@ -5,7 +5,7 @@ public class References {
private String prefix;
public References() {
prefix = Lang.PREFIX.getConfigValue() + " ";
prefix = EpicFarming.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
}
public String getPrefix() {

View File

@ -1,4 +1,16 @@
package com.songoda.epicfarming.api;
public class IFarm {
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
public interface IFarm extends InventoryHolder {
void view(Player player);
void upgrade(UpgradeType type, Player player);
Location getLocation();
ILevel getLevel();
}

View File

@ -1,4 +1,23 @@
package com.songoda.epicfarming.api;
public class ILevel {
import java.util.List;
public interface ILevel {
List<String> getDescription();
int getLevel();
int getRadius();
boolean isAutoHarvest();
boolean isAutoReplant();
double getSpeedMultiplier();
int getCostExperiance();
int getCostEconomy();
}

View File

@ -1,4 +1,5 @@
package com.songoda.epicfarming.api;
public class UpgradeType {
public enum UpgradeType {
EXPERIENCE, ECONOMY
}

View File

@ -44,9 +44,11 @@ public class BlockListeners implements Listener {
@EventHandler
public void onGrow(BlockGrowEvent e) {
try {
if (checkForFarm(e.getNewState().getLocation())) {
e.setCancelled(true);
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
@ -55,10 +57,12 @@ public class BlockListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
try {
if (e.getPlayer().getItemInHand().getType() != Material.END_ROD
Material farmBlock = Material.valueOf(instance.getConfig().getString("Main.Farm Block Material"));
if (e.getPlayer().getItemInHand().getType() != farmBlock
|| Methods.getLevelFromItem(e.getItemInHand()) == 0) return;
if (e.getBlockAgainst().getType() == Material.END_ROD) e.setCancelled(true);
if (e.getBlockAgainst().getType() == farmBlock) e.setCancelled(true);
Location location = e.getBlock().getLocation();
@ -86,7 +90,7 @@ public class BlockListeners implements Listener {
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 (b2.getType() == Material.valueOf(instance.getConfig().getString("Main.Farm Block Material"))) {
if (!farmManager.getFarms().containsKey(b2.getLocation())) continue;
if (level.getRadius() != farmManager.getFarm(b2.getLocation()).getLevel().getRadius()) continue;
return true;
@ -102,7 +106,8 @@ public class BlockListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event) {
try {
if (event.getBlock().getType() != Material.END_ROD) return;
if (event.getBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Farm Block Material")))
return;
Farm farm = instance.getFarmManager().removeFarm(event.getBlock().getLocation());

View File

@ -23,13 +23,15 @@ public class InteractListeners implements Listener {
@EventHandler
public void onBlockInteract(PlayerInteractEvent e) {
try {
if (e.getClickedBlock() != null && e.getClickedBlock().getType() != Material.END_ROD) return;
if (e.getClickedBlock() != null && e.getClickedBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Farm Block Material")))
return;
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
Location location = e.getClickedBlock().getLocation();
if (instance.getFarmManager().getFarms().containsKey(location)) {
e.setCancelled(true);
instance.getFarmManager().getFarm(location).view(e.getPlayer());
}
} catch (Exception ex) {

View File

@ -1,6 +1,7 @@
package com.songoda.epicfarming.events;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.api.UpgradeType;
import com.songoda.epicfarming.farming.Farm;
import com.songoda.epicfarming.player.PlayerData;
import com.songoda.epicfarming.utils.Debugger;
@ -10,7 +11,6 @@ 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.
*/
@ -41,12 +41,12 @@ public class InventoryListeners implements Listener {
if (event.getSlot() == 11 && player.hasPermission("EpicFarming.Upgrade.XP")) {
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
farm.upgrade("XP", player);
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("ECO", player);
farm.upgrade(UpgradeType.ECONOMY, player);
player.closeInventory();
}
}
@ -59,9 +59,6 @@ public class InventoryListeners implements Listener {
@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);

View File

@ -1,22 +1,19 @@
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.api.IFarm;
import com.songoda.epicfarming.api.ILevel;
import com.songoda.epicfarming.api.UpgradeType;
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.*;
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;
@ -25,7 +22,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Farm implements InventoryHolder {
public class Farm implements IFarm {
private Location location;
private Level level;
@ -37,6 +34,7 @@ public class Farm implements InventoryHolder {
this.inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(),false));
}
@Override
public void view(Player player) {
try {
if (!player.hasPermission("epicfarming.view"))
@ -56,7 +54,7 @@ public class Farm implements InventoryHolder {
}
}
public void setupOverview(Player player) {
private void setupOverview(Player player, String... arg) {
Inventory inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(),false));
inventory.setContents(this.inventory.getContents());
this.inventory = inventory;
@ -67,14 +65,14 @@ public class Farm implements InventoryHolder {
int level = this.level.getLevel();
ItemStack item = new ItemStack(Material.END_ROD, 1);
ItemStack item = new ItemStack(Material.valueOf(instance.getConfig().getString("Main.Farm Block Material")), 1);
ItemMeta itemmeta = item.getItemMeta();
itemmeta.setDisplayName(Arconix.pl().getApi().format().formatText(Lang.LEVEL.getConfigValue(level)));
ArrayList<String> lore = this.level.getDescription();
itemmeta.setDisplayName(instance.getLocale().getMessage("general.nametag.farm", level));
List<String> lore = this.level.getDescription();
lore.add("");
if (nextLevel == null) lore.add(Lang.MAXED.getConfigValue());
if (nextLevel == null) lore.add(instance.getLocale().getMessage("event.upgrade.maxed"));
else {
lore.add(Lang.NEXT_LEVEL.getConfigValue(nextLevel.getLevel()));
lore.add(instance.getLocale().getMessage("interface.button.level", nextLevel.getLevel()));
lore.addAll(nextLevel.getDescription());
}
@ -83,23 +81,23 @@ public class Farm implements InventoryHolder {
ItemStack itemXP = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.XP Icon")), 1);
ItemMeta itemmetaXP = itemXP.getItemMeta();
itemmetaXP.setDisplayName(Lang.XPTITLE.getConfigValue());
itemmetaXP.setDisplayName(instance.getLocale().getMessage("interface.button.upgradewithxp"));
ArrayList<String> loreXP = new ArrayList<>();
if (nextLevel != null)
loreXP.add(Lang.XPLORE.getConfigValue(Integer.toString(nextLevel.getCostExperiance())));
loreXP.add(instance.getLocale().getMessage("interface.button.upgradewithxplore", nextLevel.getCostExperiance()));
else
loreXP.add(Lang.MAXED.getConfigValue());
loreXP.add(instance.getLocale().getMessage("event.upgrade.maxed"));
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());
itemmetaECO.setDisplayName(instance.getLocale().getMessage("interface.button.upgradewitheconomy"));
ArrayList<String> loreECO = new ArrayList<>();
if (nextLevel != null)
loreECO.add(Lang.ECOLORE.getConfigValue(Arconix.pl().getApi().format().formatEconomy(nextLevel.getCostExperiance())));
loreECO.add(instance.getLocale().getMessage("interface.button.upgradewitheconomylore", Arconix.pl().getApi().format().formatEconomy(nextLevel.getCostEconomy())));
else
loreECO.add(Lang.MAXED.getConfigValue());
loreECO.add(instance.getLocale().getMessage("event.upgrade.maxed"));
itemmetaECO.setLore(loreECO);
itemECO.setItemMeta(itemmetaECO);
@ -159,20 +157,21 @@ public class Farm implements InventoryHolder {
return items;
}
public void upgrade(String type, Player player) {
@Override
public void upgrade(UpgradeType 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") {
if (type == UpgradeType.EXPERIENCE) {
cost = level.getCostExperiance();
} else {
cost = level.getCostEconomy();
}
if (type == "ECO") {
if (type == UpgradeType.ECONOMY) {
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();
@ -180,19 +179,19 @@ public class Farm implements InventoryHolder {
econ.withdrawPlayer(player, cost);
upgradeFinal(level, player);
} else {
player.sendMessage(instance.references.getPrefix() + Lang.CANT_AFFORD.getConfigValue(null));
player.sendMessage(instance.getLocale().getMessage("event.upgrade.cannotafford"));
}
} else {
player.sendMessage("Vault is not installed.");
}
} else if (type == "XP") {
} else if (type == UpgradeType.EXPERIENCE) {
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));
player.sendMessage(instance.getLocale().getMessage("event.upgrade.cannotafford"));
}
}
}
@ -202,27 +201,25 @@ public class Farm implements InventoryHolder {
}
public void upgradeFinal(Level level, Player player) {
private 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()));
player.sendMessage(instance.getLocale().getMessage("event.upgrade.success", level.getLevel()));
} else {
player.sendMessage(Lang.YOU_MAXED.getConfigValue(Integer.toString(level.getLevel())));
player.sendMessage(instance.getLocale().getMessage("event.upgrade.successmaxed", 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.
//Cannot get this 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.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 {
@ -264,15 +261,23 @@ public class Farm implements InventoryHolder {
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
b2.getRelative(BlockFace.DOWN).setType(Material.SOIL);
b2.breakNaturally();
if (instance.getConfig().getBoolean("Main.Sounds Enabled"))
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
if (!instance.v1_7 && !instance.v1_8)
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
else
b2.getWorld().playSound(b2.getLocation(), Sound.valueOf("DIG_GRASS"), 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"))
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
if (!instance.v1_7 && !instance.v1_8)
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
else
b2.getWorld().playSound(b2.getLocation(), Sound.valueOf("DIG_GRASS"), 10, 15);
}
}, random.nextInt(30) + 1);
}
@ -282,6 +287,7 @@ public class Farm implements InventoryHolder {
return false;
}
@Override
public Location getLocation() {
return location.clone();
}
@ -290,7 +296,8 @@ public class Farm implements InventoryHolder {
this.location = location;
}
public Level getLevel() {
@Override
public ILevel getLevel() {
return level;
}
}

View File

@ -1,6 +1,7 @@
package com.songoda.epicfarming.farming;
import org.bukkit.Location;
import org.bukkit.block.Block;
import java.util.Collections;
import java.util.HashMap;
@ -22,6 +23,10 @@ public class FarmManager {
return registeredFarms.get(roundLocation(location));
}
public Farm getFarm(Block block) {
return getFarm(block.getLocation());
}
public Map<Location, Farm> getFarms() {
return Collections.unmodifiableMap(registeredFarms);
}

View File

@ -1,10 +1,12 @@
package com.songoda.epicfarming.farming;
import com.songoda.epicfarming.Lang;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.api.ILevel;
import java.util.ArrayList;
import java.util.List;
public class Level {
public class Level implements ILevel {
private int level, costExperiance, costEconomy, radius;
@ -12,7 +14,7 @@ public class Level {
private boolean autoHarvest, autoReplant;
private ArrayList<String> description = new ArrayList<>();
private List<String> description = new ArrayList<>();
public Level(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant) {
this.level = level;
@ -23,45 +25,55 @@ public class Level {
this.autoHarvest = autoHarvest;
this.autoReplant = autoReplant;
description.add(Lang.NEXT_RADIUS.getConfigValue(radius));
description.add(Lang.NEXT_SPEED.getConfigValue(speedMultiplier));
EpicFarming instance = EpicFarming.getInstance();
description.add(instance.getLocale().getMessage("interface.button.radius", radius));
description.add(instance.getLocale().getMessage("interface.button.speed", speedMultiplier));
if (autoHarvest)
description.add(Lang.NEXT_AUTO_HARVEST.getConfigValue(autoHarvest));
description.add(instance.getLocale().getMessage("interface.button.autoharvest", autoHarvest));
if (autoReplant)
description.add(Lang.NEXT_AUTO_REPLANT.getConfigValue(autoReplant));
description.add(instance.getLocale().getMessage("interface.button.autoreplant", autoReplant));
}
public ArrayList<String> getDescription() {
return (ArrayList<String>)description.clone();
@Override
public List<String> getDescription() {
return new ArrayList<>(description);
}
@Override
public int getLevel() {
return level;
}
@Override
public int getRadius() {
return radius;
}
@Override
public boolean isAutoHarvest() {
return autoHarvest;
}
@Override
public boolean isAutoReplant() {
return autoReplant;
}
@Override
public double getSpeedMultiplier() {
return speedMultiplier;
}
@Override
public int getCostExperiance() {
return costExperiance;
}
@Override
public int getCostEconomy() {
return costEconomy;
}

View File

@ -24,7 +24,12 @@ public class LevelManager {
public Level getHighestLevel() {
return registeredLevels.lastEntry().getValue();
}
public Map<Integer, Level> getLevels() {
return Collections.unmodifiableMap(registeredLevels);
}
public void clear() {
registeredLevels.clear();
}
}

View File

@ -2,7 +2,6 @@ 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;
@ -36,14 +35,14 @@ public class CommandHandler implements CommandExecutor {
sender.sendMessage("");
} else if (args[0].equalsIgnoreCase("reload")) {
if (!sender.hasPermission("epicfarming.admin")) {
sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERMS.getConfigValue());
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
} else {
instance.reload();
sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Configuration and Language files reloaded."));
}
} else if (args[0].equalsIgnoreCase("givefarmitem")) {
if (!sender.hasPermission("epicfarming.admin")) {
sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERMS.getConfigValue());
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
return true;
}
//ToDo: add the ability to specify level.
@ -58,7 +57,7 @@ public class CommandHandler implements CommandExecutor {
} else if (sender instanceof Player) {
if (args[0].equalsIgnoreCase("settings")) {
if (!sender.hasPermission("epicfarming.admin")) {
sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERMS.getConfigValue());
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
} else {
Player p = (Player) sender;
instance.settingsManager.openSettingsManager(p);

View File

@ -5,6 +5,7 @@ import com.songoda.epicfarming.farming.Crop;
import org.bukkit.Bukkit;
import org.bukkit.CropState;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.material.Crops;
@ -42,9 +43,12 @@ public class GrowthHandler {
BlockState cropState = crop.getLocation().getBlock().getState();
Crops cropData = (Crops) cropState.getData();
Material material = crop.getLocation().getBlock().getType();
switch(cropData.getState()) {
case SEEDED:
cropData.setState(CropState.GERMINATED);
if (material == Material.BEETROOT_BLOCK) cropData.setState(CropState.VERY_SMALL);
else cropData.setState(CropState.GERMINATED);
break;
case GERMINATED:
cropData.setState(CropState.VERY_SMALL);

View File

@ -2,15 +2,11 @@ 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() {
@ -50,7 +46,7 @@ public class Methods {
public static String formatName(int level, boolean full) {
try {
String name = Lang.NAME_FORMAT.getConfigValue(level);
String name = EpicFarming.getInstance().getLocale().getMessage("general.nametag.farm", level);
String info = "";
if (full) {
@ -65,7 +61,7 @@ public class Methods {
}
public static ItemStack makeFarmItem(int level) {
ItemStack item = new ItemStack(Material.END_ROD, 1);
ItemStack item = new ItemStack(Material.valueOf(EpicFarming.getInstance().getConfig().getString("Main.Farm Block Material")), 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(Arconix.pl().getApi().format().formatText(Methods.formatName(level, true)));
item.setItemMeta(meta);

View File

@ -225,14 +225,15 @@ public class SettingsManager implements Listener {
o5("Main.Farm Tick Speed", 70),
o6("Main.Growth Tick Speed", 20),
o7("Main.Clear Tick Speed", 1800),
o8("Main.Farm Block Material", "END_ROD"),
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),
o9("Interfaces.Economy Icon", "DOUBLE_PLANT"),
o10("Interfaces.XP Icon", "EXP_BOTTLE"),
o11("Interfaces.Glass Type 1", 7),
o12("Interfaces.Glass Type 2", 11),
o13("Interfaces.Glass Type 3", 3),
o13("System.Debugger Enabled", false);
o14("System.Debugger Enabled", false);
private String setting;
private Object option;