mirror of
https://github.com/songoda/EpicFarming.git
synced 2025-02-01 13:11:59 +01:00
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:
parent
6b550481af
commit
5c9993e2c8
@ -36,24 +36,26 @@ public class EpicFarming extends JavaPlugin implements Listener {
|
|||||||
public SettingsManager settingsManager;
|
public SettingsManager settingsManager;
|
||||||
public References references;
|
public References references;
|
||||||
public HookHandler hooks;
|
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_10 = Bukkit.getServer().getClass().getPackage().getName().contains("1_10");
|
||||||
public boolean v1_9 = Bukkit.getServer().getClass().getPackage().getName().contains("1_9");
|
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_7 = Bukkit.getServer().getClass().getPackage().getName().contains("1_7");
|
||||||
public boolean v1_8 = Bukkit.getServer().getClass().getPackage().getName().contains("1_8");
|
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 Locale locale;
|
||||||
|
|
||||||
private FarmingHandler farmingHandler;
|
private FarmingHandler farmingHandler;
|
||||||
private GrowthHandler growthHandler;
|
private GrowthHandler growthHandler;
|
||||||
|
|
||||||
private FarmManager farmManager;
|
private FarmManager farmManager;
|
||||||
private LevelManager levelManager;
|
private LevelManager levelManager;
|
||||||
private PlayerActionManager playerActionManager;
|
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() {
|
public void onEnable() {
|
||||||
INSTANCE = this;
|
INSTANCE = this;
|
||||||
@ -87,7 +89,7 @@ public class EpicFarming extends JavaPlugin implements Listener {
|
|||||||
Location location = Arconix.pl().getApi().serialize().unserializeLocation(locationStr);
|
Location location = Arconix.pl().getApi().serialize().unserializeLocation(locationStr);
|
||||||
int level = dataFile.getConfig().getInt("Farms." + locationStr + ".level");
|
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 farm = new Farm(location, levelManager.getLevel(level));
|
||||||
farm.loadInventory(items);
|
farm.loadInventory(items);
|
||||||
@ -166,6 +168,8 @@ public class EpicFarming extends JavaPlugin implements Listener {
|
|||||||
* Dump FarmManager to file.
|
* Dump FarmManager to file.
|
||||||
*/
|
*/
|
||||||
for (Farm farm : farmManager.getFarms().values()) {
|
for (Farm farm : farmManager.getFarms().values()) {
|
||||||
|
if (farm.getLocation() == null
|
||||||
|
|| farm.getLocation().getWorld() == null) continue;
|
||||||
String locationStr = Arconix.pl().getApi().serialize().serializeLocation(farm.getLocation());
|
String locationStr = Arconix.pl().getApi().serialize().serializeLocation(farm.getLocation());
|
||||||
dataFile.getConfig().set("Farms." + locationStr + ".level", farm.getLevel().getLevel());
|
dataFile.getConfig().set("Farms." + locationStr + ".level", farm.getLevel().getLevel());
|
||||||
dataFile.getConfig().set("Farms." + locationStr + ".Contents", farm.dumpInventory());
|
dataFile.getConfig().set("Farms." + locationStr + ".Contents", farm.dumpInventory());
|
||||||
@ -240,14 +244,6 @@ public class EpicFarming extends JavaPlugin implements Listener {
|
|||||||
dataFile.saveConfig();
|
dataFile.saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EpicFarming pl() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EpicFarming getInstance() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Locale getLocale() {
|
public Locale getLocale() {
|
||||||
return locale;
|
return locale;
|
||||||
}
|
}
|
||||||
|
@ -46,14 +46,13 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
|
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//ToDo: add the ability to specify level.
|
|
||||||
if (args.length >= 1) {
|
if (args.length >= 1) {
|
||||||
if (!(sender instanceof Player) && args.length == 1) return true;
|
if (!(sender instanceof Player)) return true;
|
||||||
|
|
||||||
Level level = instance.getLevelManager().getLowestLevel();
|
Level level = instance.getLevelManager().getLowestLevel();
|
||||||
Player player;
|
Player player;
|
||||||
if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) {
|
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;
|
return true;
|
||||||
} else if (args.length == 1) {
|
} else if (args.length == 1) {
|
||||||
player = (Player)sender;
|
player = (Player)sender;
|
||||||
@ -63,12 +62,14 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
|
|
||||||
|
|
||||||
if (args.length >= 3 && !instance.getLevelManager().isLevel(Integer.parseInt(args[2]))) {
|
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;
|
return true;
|
||||||
} else {
|
} else if (args.length != 1){
|
||||||
level = instance.getLevelManager().getLevel(Integer.parseInt(args[2]));
|
level = instance.getLevelManager().getLevel(Integer.parseInt(args[2]));
|
||||||
}
|
}
|
||||||
player.getInventory().addItem(Methods.makeFarmItem(level));
|
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) {
|
} 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!"));
|
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&cThat username does not exist, or the user is not online!"));
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,10 @@ interface.button.speed = "&7Speed: &6%speed%x"
|
|||||||
interface.button.autoharvest = "&7Auto Harvest: &6%status%"
|
interface.button.autoharvest = "&7Auto Harvest: &6%status%"
|
||||||
interface.button.autoreplant = "&7Auto Replant: &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 Messages
|
||||||
|
|
||||||
event.general.nopermission = "&cYou do not have permission to do that."
|
event.general.nopermission = "&cYou do not have permission to do that."
|
||||||
|
Loading…
Reference in New Issue
Block a user