Skip to content

Commit

Permalink
Added config file
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWoodworth committed Mar 25, 2016
1 parent a765c62 commit a8f7ee3
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 32 deletions.
5 changes: 4 additions & 1 deletion src/main/java/co/kepler/fastcraftplus/FastCraft.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.kepler.fastcraftplus;

import co.kepler.fastcraftplus.api.gui.GUI;
import co.kepler.fastcraftplus.config.Config;
import co.kepler.fastcraftplus.config.Language;
import co.kepler.fastcraftplus.craftgui.GUIFastCraft;
import org.bukkit.event.Listener;
Expand All @@ -11,6 +12,7 @@
public class FastCraft extends JavaPlugin implements Listener {
private static FastCraft instance;

private Config config;
private Language lang;

/**
Expand Down Expand Up @@ -63,7 +65,8 @@ public static void logInfo(String msg) {
public void onEnable() {
instance = this;

lang = new Language("EN"); // TODO Language from config
config = new Config();
lang = new Language(config.getLanguage());

GUIFastCraft.init();
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/co/kepler/fastcraftplus/config/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package co.kepler.fastcraftplus.config;

import co.kepler.fastcraftplus.FastCraft;
import org.bukkit.configuration.Configuration;

/**
* A class for access to the FastCraft+ configuration.
*/
public class Config {
private Configuration config;

public Config() {
loadConfig();
}

/**
* Loads config with default values, and saves to update the config.
*/
public void loadConfig() {
FastCraft fastCraft = FastCraft.getInstance();
fastCraft.saveDefaultConfig();
config = fastCraft.getConfig();
config.options().copyDefaults(true);
fastCraft.saveConfig();
}

public String getLanguage() {
return config.getString("language");
}
}
79 changes: 58 additions & 21 deletions src/main/java/co/kepler/fastcraftplus/config/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
public class Language {
private static final String NOT_FOUND = ChatColor.RED + "[Lang: %key%]";
private static final String NOT_FOUND_KEY = "key";

private YamlConfiguration lang;
private Map<Material, ItemNames> itemNames;

public final GUI gui = new GUI();
public final Commands commands = new Commands();
public final Items items = new Items();
private YamlConfiguration lang;
private Map<Material, ItemNames> itemNames;

/**
* Create an instance of Language
Expand Down Expand Up @@ -137,10 +135,15 @@ public class GUI {
public final Ingredients ingredients = new Ingredients();
public final Toolbar toolbar = new Toolbar();

public String title() { return get("gui.title"); }
public String title() {
return get("gui.title");
}

public class Ingredients {
public String label() { return get("gui.ingredients.label"); }
public String label() {
return get("gui.ingredients.label");
}

public String item(int amount, String item) {
return get("gui.ingredients.item", "amount", s(amount), "item", item);
}
Expand All @@ -151,57 +154,91 @@ public class Toolbar {

public final PagePrev pagePrev = new PagePrev();
public final PageNext pageNext = new PageNext();
public final CraftBasic craftBasic = new CraftBasic();
public final CraftItems craftItems = new CraftItems();
public final CraftArmor craftArmor = new CraftArmor();
public final CraftFireworks craftFireworks = new CraftFireworks();
public final Refresh refresh = new Refresh();
public final Multiplier multiplier = new Multiplier();
public final Workbench workbench = new Workbench();

public class PagePrev {
public String title() { return get(tb + "page-prev.title"); }
public String title() {
return get(tb + "page-prev.title");
}

public List<String> description(int prev, int total, int cur) {
return getList(tb + "page-prev.description", "prev", s(prev), "total", s(total), "cur", s(cur));
}
}

public class PageNext {
public String title() { return get(tb + "page-next.title"); }
public String title() {
return get(tb + "page-next.title");
}

public List<String> description(int prev, int total, int cur) {
return getList(tb + "page-next.description", "next", s(prev), "total", s(total), "cur", s(cur));
}
}

public class CraftBasic {
public String title() { return get(tb + "craft-basic.title"); }
public List<String> description() { return getList(tb + "craft-basic.description"); }
public class CraftItems {
public String title() {
return get(tb + "craft-items.title");
}

public List<String> description() {
return getList(tb + "craft-items.description");
}
}

public class CraftArmor {
public String title() { return get(tb + "craft-armor.title"); }
public List<String> description() { return getList(tb + "craft-armor.description"); }
public String title() {
return get(tb + "craft-armor.title");
}

public List<String> description() {
return getList(tb + "craft-armor.description");
}
}

public class CraftFireworks {
public String title() { return get(tb + "craft-fireworks.title"); }
public List<String> description() { return getList(tb + "craft-fireworks.description"); }
public String title() {
return get(tb + "craft-fireworks.title");
}

public List<String> description() {
return getList(tb + "craft-fireworks.description");
}
}

public class Refresh {
public String title() { return get(tb + "refresh.title"); }
public List<String> description() { return getList(tb + "refresh.description"); }
public String title() {
return get(tb + "refresh.title");
}

public List<String> description() {
return getList(tb + "refresh.description");
}
}

public class Multiplier {
public String title(int mult) { return get(tb + "multiplier.title", "mult", s(mult)); }
public String title(int mult) {
return get(tb + "multiplier.title", "mult", s(mult));
}

public List<String> description(int mult) {
return getList(tb + "refresh.description", "mult", s(mult));
}
}

public class Workbench {
public String title() { return get(tb + "workbench.title"); }
public List<String> description() { return getList(tb + "workbench.description"); }
public String title() {
return get(tb + "workbench.title");
}

public List<String> description() {
return getList(tb + "workbench.description");
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public boolean onClick(GUIButton.Click info) {

// Create Crafting button
btnTabCrafting = new GUIButtonGlowing(new GUIItemBuilder(Material.STICK)
.setDisplayName(FastCraft.lang().gui.toolbar.craftBasic.title())
.setLore(FastCraft.lang().gui.toolbar.craftBasic.description())
.setDisplayName(FastCraft.lang().gui.toolbar.craftItems.title())
.setLore(FastCraft.lang().gui.toolbar.craftItems.description())
.setHideInfo(true).build());
btnTabCrafting.setClickAction(new GUIButton.ClickAction() {
public boolean onClick(GUIButton.Click info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class LayoutFastCraft extends LayoutMulti {
private final GUIFastCraft gui;

private final Layout layoutNavbar;
private final LayoutRecipesBasic layoutCraftingBasic;
private final LayoutRecipesItems layoutCraftingItems;
private final LayoutRecipesArmor layoutCraftingArmor;
private final LayoutRecipesFireworks layoutCraftingFireworks;

Expand All @@ -22,7 +22,7 @@ public LayoutFastCraft(GUIFastCraft gui) {

// Initialize layout pages
layoutNavbar = getBottomLayout();
layoutCraftingBasic = new LayoutRecipesBasic(gui);
layoutCraftingItems = new LayoutRecipesItems(gui);
layoutCraftingArmor = new LayoutRecipesArmor(gui);
layoutCraftingFireworks = new LayoutRecipesFireworks(gui);

Expand Down Expand Up @@ -53,7 +53,7 @@ public Layout getLayoutNavbar() {
public LayoutRecipes getLayoutTab(CraftingTab tab) {
switch (tab) {
case CRAFTING:
return layoutCraftingBasic;
return layoutCraftingItems;
case ARMOR:
return layoutCraftingArmor;
case FIREWORKS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import co.kepler.fastcraftplus.crafting.RecipeUtil;

/**
* A recipes layout that shows basic crafting recipes.
* A recipes layout that shows item crafting recipes.
*/
public class LayoutRecipesBasic extends LayoutRecipes {
public class LayoutRecipesItems extends LayoutRecipes {

public LayoutRecipesBasic(GUIFastCraft gui) {
public LayoutRecipesItems(GUIFastCraft gui) {
super(gui);
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# language: EN Custom languages can be added by creating another file
# in the lang directory of the FastCraft+ jar file.

language: EN
4 changes: 2 additions & 2 deletions src/main/resources/lang/EN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ gui:
description: # Variables: prev, total, cur
- '&bGo to page %next%/%total%'

craft-basic:
craft-items:
title: '&aCraft Items'
description:
- '&bCraft basic items'
- '&bCraft items'

craft-armor:
title: '&aCraft Dyed Armor'
Expand Down

0 comments on commit a8f7ee3

Please sign in to comment.