Skip to content

Commit

Permalink
Fixes some issues + menu can now be renamed
Browse files Browse the repository at this point in the history
Fixes #14
Closes #11
  • Loading branch information
dentych committed Sep 6, 2015
1 parent 261c5b7 commit 030921f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 20 deletions.
8 changes: 4 additions & 4 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Do not touch this, if you are not asked to
# If you get an error about your config not being up-to-date, then
# go to the EnchantGUI bukkit page for instructions.
version: 1.3.2
version: 1.1

# This plugin is gathering some basic info about how many players/servers is using it.
# All data is collected anonymously and will not harm your server in any way.
# If you wish to opt-out of this service, though, just change this setting to true.
opt-out: false

# If set to true, the enchant icons will be shown as the item they can enchant.
# If set to false, the enchant icons will all be enchanted books.
show-enchants-as-items: true
# The name in the /eshop menu.
# Max 32 characters!
menu-name: EnchantGUI

# Payment currency can be one of two. Either 'money' for regular money (using Vault+Economy system)
# or 'xp' for experience points.
Expand Down
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: EnchantGUI
version: 1.0
version: 1.1
main: me.tychsen.enchantgui.Main

author: Dentych
Expand Down
33 changes: 29 additions & 4 deletions src/me/tychsen/enchantgui/EshopConfig.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
package me.tychsen.enchantgui;

import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.FileConfigurationOptions;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class EshopConfig {
private static EshopConfig instance;
private JavaPlugin plugin;
private FileConfiguration config;

public EshopConfig() {
instance = this;
this.plugin = Main.getInstance();
config = plugin.getConfig();
}

public int getPrice(Enchantment ench, int level) {
return config.getInt(ench.getName().toLowerCase() + ".level" + level);
String path = ench.getName().toLowerCase() + ".level" + level;
return config.getInt(path);
}

public void reloadConfig() {
plugin.reloadConfig();
config = plugin.getConfig();
public String getMenuName() {
String path = "menu-name";
if (config.contains(path) && config.isSet(path) && config.isString(path)) {
if (config.getString(path).length() > 32) {
return config.getString(path).substring(0, 32);
} else {
return config.getString(path);
}
} else {
return "EnchantGUI";
}
}

public void reloadConfig(CommandSender sender) {
if (sender.isOp() || sender.hasPermission("eshop.admin")) {
plugin.reloadConfig();
config = plugin.getConfig();
sender.sendMessage(EshopSystem.start + "Configuration file has been reloaded!");
}
}

public static EshopConfig getInstance() {
return instance;
}
}
5 changes: 0 additions & 5 deletions src/me/tychsen/enchantgui/EshopEventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ public boolean handleCommand(CommandSender sender, Command cmd) {
return true;
}

public void handleReload(CommandSender sender) {
esys.reloadConfig();
sender.sendMessage(esys.start + "Configuration file has been reloaded!");
}

/* Private methods */

/**
Expand Down
6 changes: 1 addition & 5 deletions src/me/tychsen/enchantgui/EshopSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public EshopSystem() {
public void showMainMenu(Player p) {
playerNavigation.put(p.getName(), 0);

Inventory inv = p.getServer().createInventory(p, inventorySize, "EnchantGUI");
Inventory inv = p.getServer().createInventory(p, inventorySize, config.getMenuName());
generateMainMenu(p, inv);
p.openInventory(inv);
}
Expand Down Expand Up @@ -84,10 +84,6 @@ public void purchaseEnchant(Player p, ItemStack item, int level) {
}
}

public void reloadConfig() {
config.reloadConfig();
}

private void generateMainMenu(Player p, Inventory inv) {
List<ItemStack> enchList = enchants.getEnchantList();
List<ItemStack> itemlist = new ArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion src/me/tychsen/enchantgui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("eshop")) {
if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
eshop.handleReload(sender);
EshopConfig.getInstance().reloadConfig(sender);
} else {
eshop.handleCommand(sender, command);
}
Expand Down

0 comments on commit 030921f

Please sign in to comment.