Change configuration values per command

This will probably be a bit buggy, so I recommend to keep editing the file manually. Also, all of the comments in the config.yml will get deleted after using the command!
This closes #10.
This commit is contained in:
Eric 2016-07-08 16:55:57 +02:00
parent 34468ef623
commit 47414009bf
16 changed files with 473 additions and 192 deletions

View File

@ -1,6 +1,5 @@
package de.epiceric.shopchest; package de.epiceric.shopchest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.config.Regex; import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.event.ShopPreCreateEvent; import de.epiceric.shopchest.event.ShopPreCreateEvent;
import de.epiceric.shopchest.event.ShopPreInfoEvent; import de.epiceric.shopchest.event.ShopPreInfoEvent;
@ -126,6 +125,36 @@ public class Commands extends BukkitCommand {
} else { } else {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_LIMITS)); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_LIMITS));
} }
} else if (args[0].equalsIgnoreCase("config")) {
if (perm.has(p, "shopchest.config")) {
if (args.length >= 4) {
String property = args[2];
String value = args[3];
if (args[1].equalsIgnoreCase("set")) {
plugin.getShopChestConfig().set(property, value);
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHANGED_CONFIG_SET, new LocalizedMessage.ReplacedRegex(Regex.PROPERTY, property), new LocalizedMessage.ReplacedRegex(Regex.VALUE, value)));
return true;
} else if (args[1].equalsIgnoreCase("add")) {
plugin.getShopChestConfig().add(property, value);
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHANGED_CONFIG_ADDED, new LocalizedMessage.ReplacedRegex(Regex.PROPERTY, property), new LocalizedMessage.ReplacedRegex(Regex.VALUE, value)));
return true;
} else if (args[1].equalsIgnoreCase("remove")) {
plugin.getShopChestConfig().remove(property, value);
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHANGED_CONFIG_REMOVED, new LocalizedMessage.ReplacedRegex(Regex.PROPERTY, property), new LocalizedMessage.ReplacedRegex(Regex.VALUE, value)));
return true;
} else {
sendBasicHelpMessage(p);
return true;
}
} else {
sendBasicHelpMessage(p);
return true;
}
} else {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CONFIG));
return true;
}
} else { } else {
sendBasicHelpMessage(p); sendBasicHelpMessage(p);
return true; return true;
@ -220,7 +249,7 @@ public class Commands extends BukkitCommand {
if (limit != -1) { if (limit != -1) {
if (ShopUtils.getShopAmount(p) >= limit) { if (ShopUtils.getShopAmount(p) >= limit) {
if (shopType != ShopType.ADMIN || !Config.exclude_admin_shops) { if (shopType != ShopType.ADMIN || !plugin.getShopChestConfig().exclude_admin_shops) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_LIMIT_REACHED, new LocalizedMessage.ReplacedRegex(Regex.LIMIT, String.valueOf(limit)))); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_LIMIT_REACHED, new LocalizedMessage.ReplacedRegex(Regex.LIMIT, String.valueOf(limit))));
return; return;
} }
@ -248,7 +277,7 @@ public class Commands extends BukkitCommand {
return; return;
} }
for (String item : Config.blacklist) { for (String item : plugin.getShopChestConfig().blacklist) {
ItemStack itemStack; ItemStack itemStack;
@ -264,7 +293,7 @@ public class Commands extends BukkitCommand {
} }
} }
for (String key : Config.minimum_prices) { for (String key : plugin.getShopChestConfig().minimum_prices) {
ItemStack itemStack; ItemStack itemStack;
double price = plugin.getConfig().getDouble("minimum-prices." + key); double price = plugin.getConfig().getDouble("minimum-prices." + key);
@ -293,7 +322,7 @@ public class Commands extends BukkitCommand {
} }
if (sellEnabled && buyEnabled) { if (sellEnabled && buyEnabled) {
if (Config.buy_greater_or_equal_sell) { if (plugin.getShopChestConfig().buy_greater_or_equal_sell) {
if (buyPrice < sellPrice) { if (buyPrice < sellPrice) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUY_PRICE_TOO_LOW, new LocalizedMessage.ReplacedRegex(Regex.MIN_PRICE, String.valueOf(sellPrice)))); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUY_PRICE_TOO_LOW, new LocalizedMessage.ReplacedRegex(Regex.MIN_PRICE, String.valueOf(sellPrice))));
return; return;
@ -311,7 +340,7 @@ public class Commands extends BukkitCommand {
} }
} }
double creationPrice = (shopType == ShopType.NORMAL) ? Config.shop_creation_price_normal : Config.shop_creation_price_admin; double creationPrice = (shopType == ShopType.NORMAL) ? plugin.getShopChestConfig().shop_creation_price_normal : plugin.getShopChestConfig().shop_creation_price_admin;
if (creationPrice > 0) { if (creationPrice > 0) {
if (plugin.getEconomy().getBalance(p) < creationPrice) { if (plugin.getEconomy().getBalance(p) < creationPrice) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_CREATE_NOT_ENOUGH_MONEY, new LocalizedMessage.ReplacedRegex(Regex.CREATION_PRICE, String.valueOf(creationPrice)))); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_CREATE_NOT_ENOUGH_MONEY, new LocalizedMessage.ReplacedRegex(Regex.CREATION_PRICE, String.valueOf(creationPrice))));
@ -359,12 +388,13 @@ public class Commands extends BukkitCommand {
* @param player Player who will receive the message * @param player Player who will receive the message
*/ */
private void sendBasicHelpMessage(Player player) { private void sendBasicHelpMessage(Player player) {
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name + " create <amount> <buy-price> <sell-price> [normal|admin] - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE)); player.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " create <amount> <buy-price> <sell-price> [normal|admin] - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE));
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name + " remove - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVE)); player.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " remove - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVE));
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name + " info - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_INFO)); player.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " info - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_INFO));
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name + " reload - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_RELOAD)); player.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " reload - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_RELOAD));
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name + " update - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_UPDATE)); player.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " update - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_UPDATE));
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name + " limits - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_LIMITS)); player.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " limits - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_LIMITS));
player.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " config <set|add|remove> <property> <value> - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_CONFIG));
} }
} }

View File

@ -1,7 +1,6 @@
package de.epiceric.shopchest; package de.epiceric.shopchest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.config.LanguageConfiguration;
import de.epiceric.shopchest.config.Regex; import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage; import de.epiceric.shopchest.language.LocalizedMessage;
@ -23,14 +22,11 @@ import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.util.ArrayList; import java.util.ArrayList;
@ -38,6 +34,8 @@ import java.util.ArrayList;
public class ShopChest extends JavaPlugin { public class ShopChest extends JavaPlugin {
private static ShopChest instance; private static ShopChest instance;
private Config config = null;
private Economy econ = null; private Economy econ = null;
private Permission perm = null; private Permission perm = null;
private boolean lockette = false; private boolean lockette = false;
@ -46,7 +44,6 @@ public class ShopChest extends JavaPlugin {
private boolean isUpdateNeeded = false; private boolean isUpdateNeeded = false;
private String latestVersion = ""; private String latestVersion = "";
private String downloadLink = ""; private String downloadLink = "";
private LanguageConfiguration langConfig;
/** /**
* @return An instance of ShopChest * @return An instance of ShopChest
@ -78,69 +75,6 @@ public class ShopChest extends JavaPlugin {
return perm != null; return perm != null;
} }
/**
* Initializes the language configuration
*/
private void initLanguageConfig() {
langConfig = new LanguageConfiguration(this);
File langFolder = new File(getDataFolder(), "lang");
if (!(new File(langFolder, "en_US.lang")).exists())
saveResource("lang/en_US.lang", false);
if (!(new File(langFolder, "de_DE.lang")).exists())
saveResource("lang/de_DE.lang", false);
File langConfigFile = new File(langFolder, Config.language_file + ".lang");
File langDefaultFile = new File(langFolder, "en_US.lang");
if (!langConfigFile.exists()) {
if (!langDefaultFile.exists()) {
try {
Reader r = getTextResource("lang/" + langConfigFile.getName());
if (r == null) {
r = getTextResource("lang/en_US.lang");
getLogger().info("Using locale \"en_US\" (Streamed from jar file)");
} else {
getLogger().info("Using locale \"" + langConfigFile.getName().substring(0, langConfigFile.getName().length() - 5) + "\" (Streamed from jar file)");
}
BufferedReader br = new BufferedReader(r);
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append("\n");
line = br.readLine();
}
langConfig.loadFromString(sb.toString());
} catch (IOException | InvalidConfigurationException ex) {
ex.printStackTrace();
getLogger().warning("Using default language values");
}
} else {
try {
langConfig.load(langDefaultFile);
getLogger().info("Using locale \"en_US\"");
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
getLogger().warning("Using default language values");
}
}
} else {
try {
getLogger().info("Using locale \"" + langConfigFile.getName().substring(0, langConfigFile.getName().length() - 5) + "\"");
langConfig.load(langConfigFile);
} catch (IOException | InvalidConfigurationException ex) {
ex.printStackTrace();
getLogger().warning("Using default language values");
}
}
}
@Override @Override
public void onEnable() { public void onEnable() {
@ -178,11 +112,9 @@ public class ShopChest extends JavaPlugin {
return; return;
} }
initLanguageConfig(); config = new Config(this);
LanguageUtils.load(); LanguageUtils.load();
saveResource("item_names.txt", true); saveResource("item_names.txt", true);
reloadConfig();
saveDefaultConfig();
try { try {
Metrics metrics = new Metrics(this); Metrics metrics = new Metrics(this);
@ -222,7 +154,7 @@ public class ShopChest extends JavaPlugin {
@Override @Override
public int getValue() { public int getValue() {
if (Config.database_type == Database.DatabaseType.SQLite) if (config.database_type == Database.DatabaseType.SQLite)
return 1; return 1;
return 0; return 0;
@ -234,7 +166,7 @@ public class ShopChest extends JavaPlugin {
@Override @Override
public int getValue() { public int getValue() {
if (Config.database_type == Database.DatabaseType.MySQL) if (config.database_type == Database.DatabaseType.MySQL)
return 1; return 1;
return 0; return 0;
@ -247,7 +179,7 @@ public class ShopChest extends JavaPlugin {
getLogger().severe("Could not submit stats."); getLogger().severe("Could not submit stats.");
} }
if (Config.database_type == Database.DatabaseType.SQLite) { if (config.database_type == Database.DatabaseType.SQLite) {
getLogger().info("Using SQLite"); getLogger().info("Using SQLite");
database = new SQLite(this); database = new SQLite(this);
} else { } else {
@ -258,7 +190,10 @@ public class ShopChest extends JavaPlugin {
lockette = getServer().getPluginManager().getPlugin("Lockette") != null; lockette = getServer().getPluginManager().getPlugin("Lockette") != null;
lwc = getServer().getPluginManager().getPlugin("LWC") != null; lwc = getServer().getPluginManager().getPlugin("LWC") != null;
UpdateChecker uc = new UpdateChecker(this); Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() {
@Override
public void run() {
UpdateChecker uc = new UpdateChecker(ShopChest.this);
UpdateCheckerResult result = uc.check(); UpdateCheckerResult result = uc.check();
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CHECKING)); Bukkit.getConsoleSender().sendMessage("[ShopChest] " + LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CHECKING));
@ -308,20 +243,22 @@ public class ShopChest extends JavaPlugin {
isUpdateNeeded = false; isUpdateNeeded = false;
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_ERROR)); Bukkit.getConsoleSender().sendMessage("[ShopChest] " + LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_ERROR));
} }
}
});
try { try {
Commands.registerCommand(new Commands(this, Config.main_command_name, "Manage Shops.", "", new ArrayList<String>()), this); Commands.registerCommand(new Commands(this, config.main_command_name, "Manage Shops.", "", new ArrayList<String>()), this);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
initializeShops(); initializeShops();
getServer().getPluginManager().registerEvents(new HologramUpdateListener(), this); getServer().getPluginManager().registerEvents(new HologramUpdateListener(this), this);
getServer().getPluginManager().registerEvents(new ItemProtectListener(), this); getServer().getPluginManager().registerEvents(new ItemProtectListener(), this);
getServer().getPluginManager().registerEvents(new ShopInteractListener(this), this); getServer().getPluginManager().registerEvents(new ShopInteractListener(this), this);
getServer().getPluginManager().registerEvents(new NotifyUpdateOnJoinListener(this), this); getServer().getPluginManager().registerEvents(new NotifyUpdateOnJoinListener(this), this);
getServer().getPluginManager().registerEvents(new ChestProtectListener(), this); getServer().getPluginManager().registerEvents(new ChestProtectListener(this), this);
getServer().getPluginManager().registerEvents(new ItemCustomNameListener(), this); getServer().getPluginManager().registerEvents(new ItemCustomNameListener(), this);
if (getServer().getPluginManager().getPlugin("ClearLag") != null) if (getServer().getPluginManager().getPlugin("ClearLag") != null)
@ -354,13 +291,6 @@ public class ShopChest extends JavaPlugin {
getLogger().info("Initialized " + String.valueOf(count) + " Shops"); getLogger().info("Initialized " + String.valueOf(count) + " Shops");
} }
/**
* @return ShopChest's {@link LanguageConfiguration}
*/
public LanguageConfiguration getLanguageConfig() {
return langConfig;
}
/** /**
* @return Registered Economy of Vault * @return Registered Economy of Vault
*/ */
@ -441,4 +371,21 @@ public class ShopChest extends JavaPlugin {
this.downloadLink = downloadLink; this.downloadLink = downloadLink;
} }
/**
* @return The {@link Config} of ShopChset
*/
public Config getShopChestConfig() {
return config;
}
/**
* Provides a reader for a text file located inside the jar.
* The returned reader will read text with the UTF-8 charset.
* @param file - the filename of the resource to load
* @return null if getResource(String) returns null
* @throws IllegalArgumentException - if file is null
*/
public Reader getTextResourceP(String file) throws IllegalArgumentException {
return getTextResource(file);
}
} }

View File

@ -1,8 +1,14 @@
package de.epiceric.shopchest.config; package de.epiceric.shopchest.config;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.sql.Database; import de.epiceric.shopchest.sql.Database;
import org.bukkit.configuration.InvalidConfigurationException;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -10,88 +16,324 @@ import java.util.Set;
public class Config { public class Config {
private static ShopChest plugin = ShopChest.getInstance(); private ShopChest plugin;
private LanguageConfiguration langConfig;
/** /**
* The hostname used in ShopChest's MySQL database * The hostname used in ShopChest's MySQL database
**/ **/
public static String database_mysql_host = plugin.getConfig().getString("database.mysql.hostname"); public String database_mysql_host;
/** The port used for ShopChest's MySQL database **/ /** The port used for ShopChest's MySQL database **/
public static int database_mysql_port = plugin.getConfig().getInt("database.mysql.port"); public int database_mysql_port;
/** The database used for ShopChest's MySQL database **/ /** The database used for ShopChest's MySQL database **/
public static String database_mysql_database = plugin.getConfig().getString("database.mysql.database"); public String database_mysql_database;
/** The username used in ShopChest's MySQL database **/ /** The username used in ShopChest's MySQL database **/
public static String database_mysql_username = plugin.getConfig().getString("database.mysql.username"); public String database_mysql_username;
/** The password used in ShopChest's MySQL database **/ /** The password used in ShopChest's MySQL database **/
public static String database_mysql_password = plugin.getConfig().getString("database.mysql.password"); public String database_mysql_password;
/** The database type used for ShopChest. **/ /** The database type used for ShopChest. **/
public static Database.DatabaseType database_type = Database.DatabaseType.valueOf(plugin.getConfig().getString("database.type")); public Database.DatabaseType database_type;
/** /**
* The amount of attempts, ShopChest tries to reconnect to the database, when the connection is lost, until giving up * The amount of attempts, ShopChest tries to reconnect to the database, when the connection is lost, until giving up
**/ **/
public static int database_reconnect_attempts = plugin.getConfig().getInt("database.reconnect-attempts"); public int database_reconnect_attempts;
/** /**
* <p>The minimum prices for certain items</p> * <p>The minimum prices for certain items</p>
* This returns a key set, which contains e.g "STONE", "STONE:1", of the <i>minimum-prices</i> section in ShopChest's config. * This returns a key set, which contains e.g "STONE", "STONE:1", of the <i>minimum-prices</i> section in ShopChest's config.
* To actually retrieve the price for an item, you have to get the Double <i>minimum-prices.<b>key</b></i>. * To actually retrieve the price for an item, you have to get the Double <i>minimum-prices.<b>key</b></i>.
**/ **/
public static Set<String> minimum_prices = (plugin.getConfig().getConfigurationSection("minimum-prices") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("minimum-prices").getKeys(true); public Set<String> minimum_prices;
/** /**
* <p>The shop limits of certain groups</p> * <p>The shop limits of certain groups</p>
* This returns a key set, which contains the group names, of the <i>shop-limits.group</i> section in ShopChest's config. * This returns a key set, which contains the group names, of the <i>shop-limits.group</i> section in ShopChest's config.
* To actually retrieve the limits for a group, you have to get the Integer <i>shop-limits.group.<b>key</b></i>. * To actually retrieve the limits for a group, you have to get the Integer <i>shop-limits.group.<b>key</b></i>.
**/ **/
public static Set<String> shopLimits_group = (plugin.getConfig().getConfigurationSection("shop-limits.group") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.group").getKeys(true); public Set<String> shopLimits_group;
/** /**
* <p>The shop limits of certain players</p> * <p>The shop limits of certain players</p>
* This returns a key set, which contains the player names, of the <i>shop-limits.player</i> section in ShopChest's config. * This returns a key set, which contains the player names, of the <i>shop-limits.player</i> section in ShopChest's config.
* To actually retrieve the limits for a player, you have to get the Integer <i>shop-limits.player.<b>key</b></i>. * To actually retrieve the limits for a player, you have to get the Integer <i>shop-limits.player.<b>key</b></i>.
**/ **/
public static Set<String> shopLimits_player = (plugin.getConfig().getConfigurationSection("shop-limits.player") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.player").getKeys(true); public Set<String> shopLimits_player;
/** /**
* <p>List containing items, of which players can't create a shop</p> * <p>List containing items, of which players can't create a shop</p>
* If this list contains an item (e.g "STONE", "STONE:1"), it's in the blacklist. * If this list contains an item (e.g "STONE", "STONE:1"), it's in the blacklist.
**/ **/
public static List<String> blacklist = (plugin.getConfig().getStringList("blacklist") == null) ? new ArrayList<String>() : plugin.getConfig().getStringList("blacklist"); public List<String> blacklist;
/** Whether the buy price of a shop must be greater than or equal the sell price **/ /** Whether the buy price of a shop must be greater than or equal the sell price **/
public static boolean buy_greater_or_equal_sell = plugin.getConfig().getBoolean("buy-greater-or-equal-sell"); public boolean buy_greater_or_equal_sell;
/** Whether shops should be protected by hoppers **/ /** Whether shops should be protected by hoppers **/
public static boolean hopper_protection = plugin.getConfig().getBoolean("hopper-protection"); public boolean hopper_protection;
/** Whether shops should be protected by explosions **/ /** Whether shops should be protected by explosions **/
public static boolean explosion_protection = plugin.getConfig().getBoolean("explosion-protection"); public boolean explosion_protection;
/** Whether admin shops should be excluded of the shop limits **/ /** Whether admin shops should be excluded of the shop limits **/
public static boolean exclude_admin_shops = plugin.getConfig().getBoolean("shop-limits.exclude-admin-shops"); public boolean exclude_admin_shops;
/** The maximum distance between a player and a shop to see the hologram **/ /** The maximum distance between a player and a shop to see the hologram **/
public static double maximal_distance = plugin.getConfig().getDouble("maximal-distance"); public double maximal_distance;
/** The price a player has to pay in order to create a normal shop **/ /** The price a player has to pay in order to create a normal shop **/
public static double shop_creation_price_normal = plugin.getConfig().getDouble("shop-creation-price.normal"); public double shop_creation_price_normal;
/** The price a player has to pay in order to create an admin shop **/ /** The price a player has to pay in order to create an admin shop **/
public static double shop_creation_price_admin = plugin.getConfig().getDouble("shop-creation-price.admin"); public double shop_creation_price_admin;
/** The default shop limit for players and groups that are not listed in {@link #shopLimits_player} or in {@link #shopLimits_group} **/ /** The default shop limit for players and groups that are not listed in {@link #shopLimits_player} or in {@link #shopLimits_group} **/
public static int default_limit = plugin.getConfig().getInt("shop-limits.default"); public int default_limit;
/** The main command of ShopChest <i>(default: shop)</i> **/ /** The main command of ShopChest <i>(default: shop)</i> **/
public static String main_command_name = plugin.getConfig().getString("main-command-name"); public String main_command_name;
/** The language file to use (e.g <i>en_US</i>, <i>de_DE</i>) **/ /** The language file to use (e.g <i>en_US</i>, <i>de_DE</i>) **/
public static String language_file = plugin.getConfig().getString("language-file"); public String language_file;
public Config(ShopChest plugin) {
this.plugin = plugin;
plugin.saveDefaultConfig();
plugin.reloadConfig();
reload(true, true);
}
/**
* <p>Set a configuration value</p>
* <i>Config is automatically reloaded</i>
*
* @param property Property to change
* @param value Value to set
*/
public void set(String property, String value) {
boolean langChange = (property.equalsIgnoreCase("language-file"));
try {
int intValue = Integer.parseInt(value);
plugin.getConfig().set(property, intValue);
plugin.saveConfig();
plugin.reloadConfig();
reload(false, langChange);
return;
} catch (NumberFormatException e) { /* Value not an integer */ }
try {
double doubleValue = Double.parseDouble(value);
plugin.getConfig().set(property, doubleValue);
plugin.saveConfig();
plugin.reloadConfig();
reload(false, langChange);
return;
} catch (NumberFormatException e) { /* Value not a double */ }
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
boolean boolValue = Boolean.parseBoolean(value);
plugin.getConfig().set(property, boolValue);
} else {
plugin.getConfig().set(property, value);
}
plugin.saveConfig();
plugin.reloadConfig();
reload(false, langChange);
}
/**
* Add a value to a list in the config.yml.
* If the list does not exist, a new list with the given value will be created
* @param property Location of the list
* @param value Value to add
*/
public void add(String property, String value) {
List list = (plugin.getConfig().getList(property) == null) ? new ArrayList<>() : plugin.getConfig().getList(property);
try {
int intValue = Integer.parseInt(value);
list.add(intValue);
plugin.saveConfig();
plugin.reloadConfig();
reload(false, false);
return;
} catch (NumberFormatException e) { /* Value not an integer */ }
try {
double doubleValue = Double.parseDouble(value);
list.add(doubleValue);
plugin.saveConfig();
plugin.reloadConfig();
reload(false, false);
return;
} catch (NumberFormatException e) { /* Value not a double */ }
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
boolean boolValue = Boolean.parseBoolean(value);
list.add(boolValue);
} else {
list.add(value);
}
plugin.saveConfig();
plugin.reloadConfig();
reload(false, false);
}
public void remove(String property, String value) {
List list = (plugin.getConfig().getList(property) == null) ? new ArrayList<>() : plugin.getConfig().getList(property);
try {
int intValue = Integer.parseInt(value);
list.remove(intValue);
plugin.saveConfig();
plugin.reloadConfig();
reload(false, false);
return;
} catch (NumberFormatException e) { /* Value not an integer */ }
try {
double doubleValue = Double.parseDouble(value);
list.remove(doubleValue);
plugin.saveConfig();
plugin.reloadConfig();
reload(false, false);
return;
} catch (NumberFormatException e) { /* Value not a double */ }
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
boolean boolValue = Boolean.parseBoolean(value);
list.remove(boolValue);
} else {
list.remove(value);
}
plugin.saveConfig();
plugin.reloadConfig();
reload(false, false);
}
/**
* Reload the configuration values from config.yml
*/
public void reload(boolean firstLoad, boolean langReload) {
database_mysql_host = plugin.getConfig().getString("database.mysql.hostname");
database_mysql_port = plugin.getConfig().getInt("database.mysql.port");
database_mysql_database = plugin.getConfig().getString("database.mysql.database");
database_mysql_username = plugin.getConfig().getString("database.mysql.username");
database_mysql_password = plugin.getConfig().getString("database.mysql.password");
database_type = Database.DatabaseType.valueOf(plugin.getConfig().getString("database.type"));
database_reconnect_attempts = plugin.getConfig().getInt("database.reconnect-attempts");
minimum_prices = (plugin.getConfig().getConfigurationSection("minimum-prices") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("minimum-prices").getKeys(true);
shopLimits_group = (plugin.getConfig().getConfigurationSection("shop-limits.group") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.group").getKeys(true);
shopLimits_player = (plugin.getConfig().getConfigurationSection("shop-limits.player") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.player").getKeys(true);
blacklist = (plugin.getConfig().getStringList("blacklist") == null) ? new ArrayList<String>() : plugin.getConfig().getStringList("blacklist");
buy_greater_or_equal_sell = plugin.getConfig().getBoolean("buy-greater-or-equal-sell");
hopper_protection = plugin.getConfig().getBoolean("hopper-protection");
explosion_protection = plugin.getConfig().getBoolean("explosion-protection");
exclude_admin_shops = plugin.getConfig().getBoolean("shop-limits.exclude-admin-shops");
maximal_distance = plugin.getConfig().getDouble("maximal-distance");
shop_creation_price_normal = plugin.getConfig().getDouble("shop-creation-price.normal");
shop_creation_price_admin = plugin.getConfig().getDouble("shop-creation-price.admin");
default_limit = plugin.getConfig().getInt("shop-limits.default");
main_command_name = plugin.getConfig().getString("main-command-name");
language_file = plugin.getConfig().getString("language-file");
if (firstLoad || langReload) loadLanguageConfig();
if (!firstLoad && langReload) LanguageUtils.load();
}
/**
* @return ShopChest's {@link LanguageConfiguration}
*/
public LanguageConfiguration getLanguageConfig() {
return langConfig;
}
private void loadLanguageConfig() {
langConfig = new LanguageConfiguration(plugin);
File langFolder = new File(plugin.getDataFolder(), "lang");
if (!(new File(langFolder, "en_US.lang")).exists())
plugin.saveResource("lang/en_US.lang", false);
if (!(new File(langFolder, "de_DE.lang")).exists())
plugin.saveResource("lang/de_DE.lang", false);
File langConfigFile = new File(langFolder, language_file + ".lang");
File langDefaultFile = new File(langFolder, "en_US.lang");
if (!langConfigFile.exists()) {
if (!langDefaultFile.exists()) {
try {
Reader r = plugin.getTextResourceP("lang/" + langConfigFile.getName());
if (r == null) {
r = plugin.getTextResourceP("lang/en_US.lang");
plugin.getLogger().info("Using locale \"en_US\" (Streamed from jar file)");
} else {
plugin.getLogger().info("Using locale \"" + langConfigFile.getName().substring(0, langConfigFile.getName().length() - 5) + "\" (Streamed from jar file)");
}
BufferedReader br = new BufferedReader(r);
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append("\n");
line = br.readLine();
}
langConfig.loadFromString(sb.toString());
} catch (IOException | InvalidConfigurationException ex) {
ex.printStackTrace();
plugin.getLogger().warning("Using default language values");
}
} else {
try {
langConfig.load(langDefaultFile);
plugin.getLogger().info("Using locale \"en_US\"");
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
plugin.getLogger().warning("Using default language values");
}
}
} else {
try {
plugin.getLogger().info("Using locale \"" + langConfigFile.getName().substring(0, langConfigFile.getName().length() - 5) + "\"");
langConfig.load(langConfigFile);
} catch (IOException | InvalidConfigurationException ex) {
ex.printStackTrace();
plugin.getLogger().warning("Using default language values");
}
}
}
} }

View File

@ -5,6 +5,7 @@ import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -47,7 +48,7 @@ public class LanguageConfiguration extends FileConfiguration {
@Override @Override
public void load(File file) throws IOException, InvalidConfigurationException { public void load(File file) throws IOException, InvalidConfigurationException {
FileInputStream fis = new FileInputStream(file); FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis, "UTF-8"); InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(isr); BufferedReader br = new BufferedReader(isr);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

View File

@ -15,7 +15,9 @@ public enum Regex {
LIMIT("%LIMIT%"), LIMIT("%LIMIT%"),
PLAYER("%PLAYER%"), PLAYER("%PLAYER%"),
POTION_EFFECT("%POTION-EFFECT%"), POTION_EFFECT("%POTION-EFFECT%"),
MUSIC_TITLE("%MUSIC-TITLE%"); MUSIC_TITLE("%MUSIC-TITLE%"),
PROPERTY("%PROPERTY%"),
VALUE("%VALUE%");
private String name; private String name;

View File

@ -21,7 +21,7 @@ import java.util.ArrayList;
public class LanguageUtils { public class LanguageUtils {
private static ShopChest plugin = ShopChest.getInstance(); private static ShopChest plugin = ShopChest.getInstance();
private static LanguageConfiguration langConfig = plugin.getLanguageConfig(); private static LanguageConfiguration langConfig;
private static ArrayList<ItemName> itemNames = new ArrayList<>(); private static ArrayList<ItemName> itemNames = new ArrayList<>();
private static ArrayList<EnchantmentName> enchantmentNames = new ArrayList<>(); private static ArrayList<EnchantmentName> enchantmentNames = new ArrayList<>();
@ -34,6 +34,17 @@ public class LanguageUtils {
public static void load() { public static void load() {
langConfig = plugin.getShopChestConfig().getLanguageConfig();
itemNames.clear();
enchantmentNames.clear();
enchantmentLevelNames.clear();
potionEffectNames.clear();
entityNames.clear();
potionNames.clear();
musicDiscNames.clear();
messages.clear();
// Add Block Names // Add Block Names
itemNames.add(new ItemName(Material.STONE, langConfig.getString("tile.stone.stone.name", "Stone"))); itemNames.add(new ItemName(Material.STONE, langConfig.getString("tile.stone.stone.name", "Stone")));
itemNames.add(new ItemName(Material.STONE, 1, langConfig.getString("tile.stone.granite.name", "Granite"))); itemNames.add(new ItemName(Material.STONE, 1, langConfig.getString("tile.stone.granite.name", "Granite")));
@ -899,12 +910,17 @@ public class LanguageUtils {
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_RELOAD, langConfig.getString("message.noPermission.reload", "&cYou don't have permission to reload the shops."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_RELOAD, langConfig.getString("message.noPermission.reload", "&cYou don't have permission to reload the shops.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_UPDATE, langConfig.getString("message.noPermission.update", "&cYou don't have permission to check for updates."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_UPDATE, langConfig.getString("message.noPermission.update", "&cYou don't have permission to check for updates.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_LIMITS, langConfig.getString("message.noPermission.limits", "&cYou don't have permission to view the shop limits."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_LIMITS, langConfig.getString("message.noPermission.limits", "&cYou don't have permission to view the shop limits.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_CONFIG, langConfig.getString("message.noPermission.config", "&cYou don't have permission to change configuration values.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE, langConfig.getString("message.commandDescription.create", "Create a shop."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE, langConfig.getString("message.commandDescription.create", "Create a shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVE, langConfig.getString("message.commandDescription.remove", "Remove a shop."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVE, langConfig.getString("message.commandDescription.remove", "Remove a shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_INFO, langConfig.getString("message.commandDescription.info", "Retrieve shop information."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_INFO, langConfig.getString("message.commandDescription.info", "Retrieve shop information.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_RELOAD, langConfig.getString("message.commandDescription.reload", "Reload shops."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_RELOAD, langConfig.getString("message.commandDescription.reload", "Reload shops.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_UPDATE, langConfig.getString("message.commandDescription.update", "Check for Updates."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_UPDATE, langConfig.getString("message.commandDescription.update", "Check for Updates.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_LIMITS, langConfig.getString("message.commandDescription.limits", "View shop limits."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_LIMITS, langConfig.getString("message.commandDescription.limits", "View shop limits.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_CONFIG, langConfig.getString("message.commandDescription.config", "Change configuration values.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHANGED_CONFIG_SET, langConfig.getString("message.config.set", "&6Changed &a%PROPERTY% &6to &a%VALUE%&6."), Regex.PROPERTY, Regex.VALUE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHANGED_CONFIG_REMOVED, langConfig.getString("message.config.removed", "&6Removed &a%VALUE% &6from &a%PROPERTY%&6."), Regex.PROPERTY, Regex.VALUE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHANGED_CONFIG_ADDED, langConfig.getString("message.config.added", "&6Added &a%VALUE% &6to &a%PROPERTY%&6."), Regex.PROPERTY, Regex.VALUE));
} }
/** /**

View File

@ -108,12 +108,17 @@ public class LocalizedMessage {
NO_PERMISSION_RELOAD, NO_PERMISSION_RELOAD,
NO_PERMISSION_UPDATE, NO_PERMISSION_UPDATE,
NO_PERMISSION_LIMITS, NO_PERMISSION_LIMITS,
NO_PERMISSION_CONFIG,
COMMAND_DESC_CREATE, COMMAND_DESC_CREATE,
COMMAND_DESC_REMOVE, COMMAND_DESC_REMOVE,
COMMAND_DESC_INFO, COMMAND_DESC_INFO,
COMMAND_DESC_RELOAD, COMMAND_DESC_RELOAD,
COMMAND_DESC_UPDATE, COMMAND_DESC_UPDATE,
COMMAND_DESC_LIMITS COMMAND_DESC_LIMITS,
COMMAND_DESC_CONFIG,
CHANGED_CONFIG_SET,
CHANGED_CONFIG_REMOVED,
CHANGED_CONFIG_ADDED
} }
public static class ReplacedRegex { public static class ReplacedRegex {

View File

@ -1,7 +1,6 @@
package de.epiceric.shopchest.listeners; package de.epiceric.shopchest.listeners;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage; import de.epiceric.shopchest.language.LocalizedMessage;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
@ -26,6 +25,12 @@ import java.util.ArrayList;
public class ChestProtectListener implements Listener { public class ChestProtectListener implements Listener {
private ShopChest plugin;
public ChestProtectListener(ShopChest plugin) {
this.plugin = plugin;
}
@EventHandler @EventHandler
public void onBlockBreak(BlockBreakEvent e) { public void onBlockBreak(BlockBreakEvent e) {
if (ShopUtils.isShop(e.getBlock().getLocation())) { if (ShopUtils.isShop(e.getBlock().getLocation())) {
@ -36,7 +41,7 @@ public class ChestProtectListener implements Listener {
@EventHandler @EventHandler
public void onBlockExplode(BlockExplodeEvent e) { public void onBlockExplode(BlockExplodeEvent e) {
if (Config.explosion_protection) { if (plugin.getShopChestConfig().explosion_protection) {
ArrayList<Block> bl = new ArrayList<>(e.blockList()); ArrayList<Block> bl = new ArrayList<>(e.blockList());
for (Block b : bl) { for (Block b : bl) {
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
@ -48,7 +53,7 @@ public class ChestProtectListener implements Listener {
@EventHandler @EventHandler
public void onEntityExplode(EntityExplodeEvent e) { public void onEntityExplode(EntityExplodeEvent e) {
if (Config.explosion_protection) { if (plugin.getShopChestConfig().explosion_protection) {
ArrayList<Block> bl = new ArrayList<>(e.blockList()); ArrayList<Block> bl = new ArrayList<>(e.blockList());
for (Block b : bl) { for (Block b : bl) {
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
@ -100,7 +105,7 @@ public class ChestProtectListener implements Listener {
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onItemMove(InventoryMoveItemEvent e) { public void onItemMove(InventoryMoveItemEvent e) {
if (Config.hopper_protection) { if (plugin.getShopChestConfig().hopper_protection) {
if ((e.getSource().getType().equals(InventoryType.CHEST)) && (!e.getInitiator().getType().equals(InventoryType.PLAYER))) { if ((e.getSource().getType().equals(InventoryType.CHEST)) && (!e.getInitiator().getType().equals(InventoryType.PLAYER))) {
if (e.getSource().getHolder() instanceof DoubleChest) { if (e.getSource().getHolder() instanceof DoubleChest) {

View File

@ -1,6 +1,6 @@
package de.epiceric.shopchest.listeners; package de.epiceric.shopchest.listeners;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
import org.bukkit.Location; import org.bukkit.Location;
@ -11,6 +11,12 @@ import org.bukkit.event.player.PlayerMoveEvent;
public class HologramUpdateListener implements Listener { public class HologramUpdateListener implements Listener {
private ShopChest plugin;
public HologramUpdateListener(ShopChest plugin) {
this.plugin = plugin;
}
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent e) { public void onPlayerMove(PlayerMoveEvent e) {
@ -25,7 +31,7 @@ public class HologramUpdateListener implements Listener {
if (playerLocation.getWorld().equals(shopLocation.getWorld())) { if (playerLocation.getWorld().equals(shopLocation.getWorld())) {
if (playerLocation.distance(shop.getHologram().getLocation()) <= Config.maximal_distance) { if (playerLocation.distance(shop.getHologram().getLocation()) <= plugin.getShopChestConfig().maximal_distance) {
if (!shop.getHologram().isVisible(p)) { if (!shop.getHologram().isVisible(p)) {
shop.getHologram().showPlayer(p); shop.getHologram().showPlayer(p);

View File

@ -3,7 +3,6 @@ package de.epiceric.shopchest.listeners;
import com.griefcraft.lwc.LWC; import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection; import com.griefcraft.model.Protection;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.config.Regex; import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.event.ShopBuySellEvent; import de.epiceric.shopchest.event.ShopBuySellEvent;
import de.epiceric.shopchest.event.ShopCreateEvent; import de.epiceric.shopchest.event.ShopCreateEvent;
@ -244,14 +243,14 @@ public class ShopInteractListener implements Listener {
* @param shopType Type of the shop * @param shopType Type of the shop
*/ */
private void create(Player executor, Location location, ItemStack product, double buyPrice, double sellPrice, ShopType shopType) { private void create(Player executor, Location location, ItemStack product, double buyPrice, double sellPrice, ShopType shopType) {
int id = database.getNextFreeID(Config.database_reconnect_attempts); int id = database.getNextFreeID(plugin.getShopChestConfig().database_reconnect_attempts);
if (id == 0) { if (id == 0) {
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Regex.ERROR, "Could not connect to database"))); executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Regex.ERROR, "Could not connect to database")));
return; return;
} }
double creationPrice = (shopType == ShopType.NORMAL) ? Config.shop_creation_price_normal : Config.shop_creation_price_admin; double creationPrice = (shopType == ShopType.NORMAL) ? plugin.getShopChestConfig().shop_creation_price_normal : plugin.getShopChestConfig().shop_creation_price_admin;
ShopCreateEvent event = new ShopCreateEvent(executor, Shop.createImaginaryShop(executor, product, buyPrice, sellPrice,shopType), creationPrice); ShopCreateEvent event = new ShopCreateEvent(executor, Shop.createImaginaryShop(executor, product, buyPrice, sellPrice,shopType), creationPrice);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);

View File

@ -1,7 +1,6 @@
package de.epiceric.shopchest.sql; package de.epiceric.shopchest.sql;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.shop.Shop.ShopType; import de.epiceric.shopchest.shop.Shop.ShopType;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
@ -20,10 +19,12 @@ public abstract class Database {
public ShopChest plugin; public ShopChest plugin;
public Connection connection; public Connection connection;
private int attempts = Config.database_reconnect_attempts; private int attempts;
public Database(ShopChest plugin) { public Database(ShopChest plugin) {
this.plugin = plugin; this.plugin = plugin;
this.attempts = plugin.getShopChestConfig().database_reconnect_attempts;
initialize(); initialize();
} }

View File

@ -1,7 +1,6 @@
package de.epiceric.shopchest.sql; package de.epiceric.shopchest.sql;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
@ -21,10 +20,10 @@ public class MySQL extends Database {
Class.forName("com.mysql.jdbc.Driver"); Class.forName("com.mysql.jdbc.Driver");
String connectUrl = "jdbc:mysql://" + Config.database_mysql_host + ":" + Config.database_mysql_port + "/" + Config.database_mysql_database; String connectUrl = "jdbc:mysql://" + plugin.getShopChestConfig().database_mysql_host + ":" + plugin.getShopChestConfig().database_mysql_port + "/" + plugin.getShopChestConfig().database_mysql_database;
plugin.getLogger().info("Connecting to MySQL Server \"" + connectUrl + "\" as user \"" + Config.database_mysql_username + "\""); plugin.getLogger().info("Connecting to MySQL Server \"" + connectUrl + "\" as user \"" + plugin.getShopChestConfig().database_mysql_username + "\"");
connection = DriverManager.getConnection(connectUrl, Config.database_mysql_username, Config.database_mysql_password); connection = DriverManager.getConnection(connectUrl, plugin.getShopChestConfig().database_mysql_username, plugin.getShopChestConfig().database_mysql_password);
return connection; return connection;
} catch (Exception ex) { } catch (Exception ex) {

View File

@ -81,7 +81,7 @@ public class ShopUtils {
} }
if (addToDatabase) if (addToDatabase)
plugin.getShopDatabase().addShop(shop, Config.database_reconnect_attempts); plugin.getShopDatabase().addShop(shop, plugin.getShopChestConfig().database_reconnect_attempts);
} }
@ -108,7 +108,7 @@ public class ShopUtils {
shop.removeHologram(); shop.removeHologram();
if (removeFromDatabase) if (removeFromDatabase)
plugin.getShopDatabase().removeShop(shop, Config.database_reconnect_attempts); plugin.getShopDatabase().removeShop(shop, plugin.getShopChestConfig().database_reconnect_attempts);
} }
/** /**
@ -117,12 +117,12 @@ public class ShopUtils {
* @return The shop limits of the given player * @return The shop limits of the given player
*/ */
public static int getShopLimit(Player p) { public static int getShopLimit(Player p) {
int limit = Config.default_limit; int limit = plugin.getShopChestConfig().default_limit;
if (plugin.getPermission().hasGroupSupport()) { if (plugin.getPermission().hasGroupSupport()) {
List<String> groups = new ArrayList<String>(); List<String> groups = new ArrayList<String>();
for (String key : Config.shopLimits_group) { for (String key : plugin.getShopChestConfig().shopLimits_group) {
for (int i = 0; i < plugin.getPermission().getGroups().length; i++) { for (int i = 0; i < plugin.getPermission().getGroups().length; i++) {
if (plugin.getPermission().getGroups()[i].equals(key)) { if (plugin.getPermission().getGroups()[i].equals(key)) {
if (plugin.getPermission().playerInGroup(p, key)) { if (plugin.getPermission().playerInGroup(p, key)) {
@ -153,7 +153,7 @@ public class ShopUtils {
} }
} }
for (String key : Config.shopLimits_player) { for (String key : plugin.getShopChestConfig().shopLimits_player) {
int pLimit = ShopChest.getInstance().getConfig().getInt("shop-limits.player." + key); int pLimit = ShopChest.getInstance().getConfig().getInt("shop-limits.player." + key);
if (Utils.isUUID(key)) { if (Utils.isUUID(key)) {
if (p.getUniqueId().equals(UUID.fromString(key))) { if (p.getUniqueId().equals(UUID.fromString(key))) {
@ -179,7 +179,7 @@ public class ShopUtils {
for (Shop shop : ShopUtils.getShops()) { for (Shop shop : ShopUtils.getShops()) {
if (shop.getVendor().equals(p)) { if (shop.getVendor().equals(p)) {
if (shop.getShopType() != Shop.ShopType.ADMIN || !Config.exclude_admin_shops) { if (shop.getShopType() != Shop.ShopType.ADMIN || !plugin.getShopChestConfig().exclude_admin_shops) {
shopCount++; shopCount++;
if (shop.getChest().getInventory().getHolder() instanceof DoubleChest) if (shop.getChest().getInventory().getHolder() instanceof DoubleChest)
@ -196,6 +196,8 @@ public class ShopUtils {
* @return Amount of shops, which were reloaded * @return Amount of shops, which were reloaded
*/ */
public static int reloadShops() { public static int reloadShops() {
plugin.getShopChestConfig().reload(false, true);
for (Shop shop : ShopUtils.getShops()) { for (Shop shop : ShopUtils.getShops()) {
ShopUtils.removeShop(shop, false); ShopUtils.removeShop(shop, false);
} }
@ -212,10 +214,10 @@ public class ShopUtils {
} }
int count = 0; int count = 0;
for (int id = 1; id < plugin.getShopDatabase().getHighestID(Config.database_reconnect_attempts) + 1; id++) { for (int id = 1; id < plugin.getShopDatabase().getHighestID(plugin.getShopChestConfig().database_reconnect_attempts) + 1; id++) {
try { try {
Shop shop = (Shop) plugin.getShopDatabase().get(id, Database.ShopInfo.SHOP, Config.database_reconnect_attempts); Shop shop = (Shop) plugin.getShopDatabase().get(id, Database.ShopInfo.SHOP, plugin.getShopChestConfig().database_reconnect_attempts);
ShopUtils.addShop(shop, false); ShopUtils.addShop(shop, false);
} catch (NullPointerException e) { } catch (NullPointerException e) {
continue; continue;

View File

@ -63,13 +63,18 @@ message.noPermission.sell=&cDu hast keine Berechtigung etwas zu verkaufen.
message.noPermission.remove-others=&cDu hast keine Berechtigung diesen Shop zu entfernen. message.noPermission.remove-others=&cDu hast keine Berechtigung diesen Shop zu entfernen.
message.noPermission.reload=&cDu hast keine Berechtigung die Shops neu zu laden. message.noPermission.reload=&cDu hast keine Berechtigung die Shops neu zu laden.
message.noPermission.update=&cDu hast keine Berechtigung nach Aktualisierungen zu suchen. message.noPermission.update=&cDu hast keine Berechtigung nach Aktualisierungen zu suchen.
message.noPermission.limits=&cDu hast keine Berechtigung die Shop Limits zu sehen message.noPermission.limits=&cDu hast keine Berechtigung die Shop Limits zu sehen.
message.noPermission.config=&cDu hast keine Berechtigung Konfigurationswerte zu verändern.
message.commandDescription.create=Erstelle einen Shop. message.commandDescription.create=Erstelle einen Shop.
message.commandDescription.remove=Entferne einen Shop. message.commandDescription.remove=Entferne einen Shop.
message.commandDescription.info=Rufe Informationen über den Shop ab. message.commandDescription.info=Rufe Informationen über den Shop ab.
message.commandDescription.reload=Lade die Shops neu. message.commandDescription.reload=Lade die Shops neu.
message.commandDescription.update=Suche nach Aktualisierungen. message.commandDescription.update=Suche nach Aktualisierungen.
message.commandDescription.limits=Betrachte die Shop Limits. message.commandDescription.limits=Betrachte die Shop Limits.
message.commandDescription.config=Verändere Konfigurationswerte.
message.config.set=&6Eigenschaft &a%PROPERTY% &6wurde auf &a%VALUE% &6gesetzt.
message.config.added=&6Wert &a%VALUE% &6wurde zu &a%PROPERTY% &6hinzugefügt.
message.config.removed=&6Wert &a%VALUE% &6wurde aus &a%PROPERTY% &6entfernt.
effect.absorption=Absorption effect.absorption=Absorption
effect.blindness=Blindheit effect.blindness=Blindheit

View File

@ -224,6 +224,9 @@ message.noPermission.update=&cYou don't have permission to check for updates.
# Set the message when a not permitted player tries to view the shop limits. # Set the message when a not permitted player tries to view the shop limits.
message.noPermission.limits=&cYou don't have permission to view the shop limits. message.noPermission.limits=&cYou don't have permission to view the shop limits.
# Set the message when a not permitted player tries to change configuration values.
message.noPermission.config=&cYou don't have permission to change configuration values.
# Set the command description message for '/shop create' when you type '/shop'. # Set the command description message for '/shop create' when you type '/shop'.
message.commandDescription.create=Create a shop. message.commandDescription.create=Create a shop.
@ -242,6 +245,21 @@ message.commandDescription.update=Check for Updates.
# Set the command description message for '/shop limits' when you type '/shop'. # Set the command description message for '/shop limits' when you type '/shop'.
message.commandDescription.limits=View shop limits. message.commandDescription.limits=View shop limits.
# Set the command description message for '/shop config' when you type '/shop'.
message.commandDescription.config=Change configuration values.
# Set the message a player gets after setting a configuration value per command
# Usable regex: %PROPERTY%, %VALUE%
message.config.set=&6Changed &a%PROPERTY% &6to &a%VALUE%&6.
# Set the message a player gets after adding a value to a list in the configuration per command
# Usable regex: %PROPERTY%, %VALUE%
message.config.added=&6Added &a%VALUE% &6to &a%PROPERTY%&6.
# Set the message a player gets after removing a value from a list in the configuration per command
# Usable regex: %PROPERTY%, %VALUE%
message.config.removed=&6Removed &a%VALUE% &6from &a%PROPERTY%&6.
# Effect names that will be displayed in the place of %POTION-EFFECT% # Effect names that will be displayed in the place of %POTION-EFFECT%
effect.none=No Effects effect.none=No Effects
effect.moveSpeed=Speed effect.moveSpeed=Speed

View File

@ -58,3 +58,6 @@ permissions:
shopchest.limits: shopchest.limits:
description: Allows you to view shop limits. description: Allows you to view shop limits.
default: true default: true
shopchest.config:
description: Allows you to change configuration values per command.
default: op