From 5c9993e2c8bb2b70f8d22b93df3e9a553f2d0544 Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Wed, 11 Jul 2018 23:11:48 -0400 Subject: [PATCH] Now checks farm locations before saving to file as to prevent save fails. You can now give level 1 farm items using the command by providing no arguments. The give command will now provide helpful feedback on mistype and will also provide the recipient with a message on command success. --- .../com/songoda/epicfarming/EpicFarming.java | 28 ++++++++----------- .../epicfarming/handlers/CommandHandler.java | 11 ++++---- src/main/resources/en_US.lang | 4 +++ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/songoda/epicfarming/EpicFarming.java b/src/main/java/com/songoda/epicfarming/EpicFarming.java index 9ce0f8a..af497e4 100644 --- a/src/main/java/com/songoda/epicfarming/EpicFarming.java +++ b/src/main/java/com/songoda/epicfarming/EpicFarming.java @@ -36,24 +36,26 @@ public class EpicFarming extends JavaPlugin implements Listener { 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"); - + public ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml"); + private ConfigWrapper langFile = new ConfigWrapper(this, "", "lang.yml"); private Locale locale; - private FarmingHandler farmingHandler; private GrowthHandler growthHandler; - private FarmManager farmManager; private LevelManager levelManager; private PlayerActionManager playerActionManager; - public ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml"); + public static EpicFarming pl() { + return INSTANCE; + } + + public static EpicFarming getInstance() { + return INSTANCE; + } public void onEnable() { INSTANCE = this; @@ -87,7 +89,7 @@ public class EpicFarming extends JavaPlugin implements Listener { Location location = Arconix.pl().getApi().serialize().unserializeLocation(locationStr); int level = dataFile.getConfig().getInt("Farms." + locationStr + ".level"); - List items = (List)dataFile.getConfig().getList("Farms." + locationStr + ".Contents"); + List items = (List) dataFile.getConfig().getList("Farms." + locationStr + ".Contents"); Farm farm = new Farm(location, levelManager.getLevel(level)); farm.loadInventory(items); @@ -166,6 +168,8 @@ public class EpicFarming extends JavaPlugin implements Listener { * Dump FarmManager to file. */ for (Farm farm : farmManager.getFarms().values()) { + if (farm.getLocation() == null + || farm.getLocation().getWorld() == null) continue; 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()); @@ -240,14 +244,6 @@ public class EpicFarming extends JavaPlugin implements Listener { dataFile.saveConfig(); } - public static EpicFarming pl() { - return INSTANCE; - } - - public static EpicFarming getInstance() { - return INSTANCE; - } - public Locale getLocale() { return locale; } diff --git a/src/main/java/com/songoda/epicfarming/handlers/CommandHandler.java b/src/main/java/com/songoda/epicfarming/handlers/CommandHandler.java index 89b4150..442f334 100644 --- a/src/main/java/com/songoda/epicfarming/handlers/CommandHandler.java +++ b/src/main/java/com/songoda/epicfarming/handlers/CommandHandler.java @@ -46,14 +46,13 @@ public class CommandHandler implements CommandExecutor { sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission")); return true; } - //ToDo: add the ability to specify level. if (args.length >= 1) { - if (!(sender instanceof Player) && args.length == 1) return true; + if (!(sender instanceof Player)) return true; Level level = instance.getLevelManager().getLowestLevel(); Player player; if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) { - sender.sendMessage("Not a player..."); + sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&cThat player does not exist or is currently offline.")); return true; } else if (args.length == 1) { player = (Player)sender; @@ -63,12 +62,14 @@ public class CommandHandler implements CommandExecutor { if (args.length >= 3 && !instance.getLevelManager().isLevel(Integer.parseInt(args[2]))) { - sender.sendMessage("Not a level..."); + sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&cNot a valid level... The current valid levels are: &4" + instance.getLevelManager().getLowestLevel().getLevel() + "-" + instance.getLevelManager().getHighestLevel().getLevel() + "&c.")); return true; - } else { + } else if (args.length != 1){ level = instance.getLevelManager().getLevel(Integer.parseInt(args[2])); } player.getInventory().addItem(Methods.makeFarmItem(level)); + player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("command.give.success", level.getLevel())); + } 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!")); } diff --git a/src/main/resources/en_US.lang b/src/main/resources/en_US.lang index 4325065..e10aac9 100644 --- a/src/main/resources/en_US.lang +++ b/src/main/resources/en_US.lang @@ -15,6 +15,10 @@ interface.button.speed = "&7Speed: &6%speed%x" interface.button.autoharvest = "&7Auto Harvest: &6%status%" interface.button.autoreplant = "&7Auto Replant: &6%status%" +#Command Messages + +command.give.success = "&7You have been given a &6level %level% &7farm item." + #Event Messages event.general.nopermission = "&cYou do not have permission to do that."