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.
This commit is contained in:
Brianna O'Keefe 2018-07-11 23:11:48 -04:00
parent 6b550481af
commit 5c9993e2c8
3 changed files with 22 additions and 21 deletions

View File

@ -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<ItemStack> items = (List<ItemStack>)dataFile.getConfig().getList("Farms." + locationStr + ".Contents");
List<ItemStack> items = (List<ItemStack>) 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;
}

View File

@ -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!"));
}

View File

@ -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."