diff --git a/TNE/src/net/tnemc/core/TNE.java b/TNE/src/net/tnemc/core/TNE.java index 7ba9e40c..da8d9887 100644 --- a/TNE/src/net/tnemc/core/TNE.java +++ b/TNE/src/net/tnemc/core/TNE.java @@ -71,6 +71,7 @@ import java.util.Map; import java.util.TreeMap; import java.util.UUID; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -188,6 +189,12 @@ public void onEnable() { loader = new ModuleLoader(); loader.load(); + if(!loader.hasModule("MySQL") && !loader.hasModule("H2")) { + new File(getDataFolder(), "modules").mkdir(); + ModuleLoader.downloadModule("h2"); + loader.load("H2"); + } + //Load modules loader.getModules().forEach((key, value)->{ TNEModuleLoadEvent event = new TNEModuleLoadEvent(key, value.getInfo().version()); @@ -291,6 +298,11 @@ public void onEnable() { consoleName = (configurations().getString("Core.Server.Account.Name").length() <= 100)? configurations().getString("Core.Server.Account.Name") : "Server_Account"; useUUID = configurations().getBoolean("Core.UUID"); + + if(!loader.hasModuleWithoutCase(configurations().getString("Core.Database.Type"))) { + getLogger().log(Level.SEVERE, "Unable to locate module with specified database type."); + } + TNESaveManager sManager = new TNESaveManager(new TNEDataManager( configurations().getString("Core.Database.Type").toLowerCase(), configurations().getString("Core.Database.MySQL.Host"), diff --git a/TNE/src/net/tnemc/core/commands/module/ModuleCommand.java b/TNE/src/net/tnemc/core/commands/module/ModuleCommand.java index 37b17ec7..cab0f7c2 100644 --- a/TNE/src/net/tnemc/core/commands/module/ModuleCommand.java +++ b/TNE/src/net/tnemc/core/commands/module/ModuleCommand.java @@ -15,6 +15,7 @@ public class ModuleCommand extends TNECommand { public ModuleCommand(TNE plugin) { super(plugin); + subCommands.add(new ModuleDownloadCommand(plugin)); subCommands.add(new ModuleInfoCommand(plugin)); subCommands.add(new ModuleListCommand(plugin)); subCommands.add(new ModuleLoadCommand(plugin)); diff --git a/TNE/src/net/tnemc/core/commands/module/ModuleDownloadCommand.java b/TNE/src/net/tnemc/core/commands/module/ModuleDownloadCommand.java new file mode 100644 index 00000000..0d76803b --- /dev/null +++ b/TNE/src/net/tnemc/core/commands/module/ModuleDownloadCommand.java @@ -0,0 +1,75 @@ +package net.tnemc.core.commands.module; + +import net.tnemc.core.TNE; +import net.tnemc.core.commands.TNECommand; +import net.tnemc.core.common.Message; +import net.tnemc.core.common.WorldVariant; +import net.tnemc.core.common.account.WorldFinder; +import net.tnemc.core.common.module.ModuleLoader; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; + +/** + * The New Economy Minecraft Server Plugin + *

+ * Created by Daniel on 8/8/2018. + *

+ * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to + * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. + * Created by creatorfromhell on 06/30/2017. + */ +public class ModuleDownloadCommand extends TNECommand { + + public ModuleDownloadCommand(TNE plugin) { + super(plugin); + } + + @Override + public String getName() { + return "download"; + } + + @Override + public String[] getAliases() { + return new String[] { + "dl" + }; + } + + @Override + public String getNode() { + return "tne.module.download"; + } + + @Override + public boolean console() { + return true; + } + + @Override + public String getHelp() { + return "Messages.Commands.Module.Download"; + } + + @Override + public boolean execute(CommandSender sender, String command, String[] arguments) { + if(arguments.length >= 1) { + final String moduleName = arguments[0].toLowerCase().trim(); + final String world = WorldFinder.getWorld(sender, WorldVariant.ACTUAL); + if(!ModuleLoader.modulePaths.containsKey(moduleName)) { + Message message = new Message("Messages.Module.Invalid"); + message.addVariable("$module", moduleName); + message.translate(world, sender); + return false; + } + Bukkit.getScheduler().runTaskAsynchronously(TNE.instance(), ()->ModuleLoader.downloadModule(moduleName)); + Message message = new Message("Messages.Module.Downloaded"); + message.addVariable("$module", moduleName); + message.translate(world, sender); + return true; + } + help(sender); + return false; + } +} \ No newline at end of file diff --git a/TNE/src/net/tnemc/core/commands/money/MoneyNoteCommand.java b/TNE/src/net/tnemc/core/commands/money/MoneyNoteCommand.java index d1528b78..4fbddec3 100644 --- a/TNE/src/net/tnemc/core/commands/money/MoneyNoteCommand.java +++ b/TNE/src/net/tnemc/core/commands/money/MoneyNoteCommand.java @@ -72,6 +72,11 @@ public boolean execute(CommandSender sender, String command, String[] arguments) return false; } + if(!currency.isNotable()) { + new Message("Messages.Money.NoteFailed").translate(world, sender); + return false; + } + String parsed = CurrencyFormatter.parseAmount(currency, world, arguments[0]); if(parsed.contains("Messages")) { Message max = new Message(parsed); @@ -96,7 +101,7 @@ public boolean execute(CommandSender sender, String command, String[] arguments) if(result.proceed()) { - ItemStack stack = TNE.manager().currencyManager().createNote(id, currency.name(), world, value); + ItemStack stack = TNE.manager().currencyManager().createNote(currency.name(), world, value); getPlayer(sender).getInventory().addItem(stack); Message message = new Message(result.recipientMessage()); message.addVariable("$player", arguments[0]); diff --git a/TNE/src/net/tnemc/core/common/CurrencyManager.java b/TNE/src/net/tnemc/core/common/CurrencyManager.java index 89f73cac..f782ec2d 100644 --- a/TNE/src/net/tnemc/core/common/CurrencyManager.java +++ b/TNE/src/net/tnemc/core/common/CurrencyManager.java @@ -306,7 +306,7 @@ public void register(net.tnemc.core.economy.currency.Currency currency) { addCurrency(TNE.instance().defaultWorld, TNECurrency.fromReserve(currency)); } - public ItemStack createNote(UUID id, String currency, String world, BigDecimal amount) { + public ItemStack createNote(String currency, String world, BigDecimal amount) { ItemStack stack = new ItemStack(Material.PAPER, 1); ItemMeta meta = stack.getItemMeta(); diff --git a/TNE/src/net/tnemc/core/common/account/TNEAccount.java b/TNE/src/net/tnemc/core/common/account/TNEAccount.java index 18cefa33..3b42192b 100644 --- a/TNE/src/net/tnemc/core/common/account/TNEAccount.java +++ b/TNE/src/net/tnemc/core/common/account/TNEAccount.java @@ -180,6 +180,21 @@ public BigDecimal getHoldings(String world, String currency, boolean core, boole return holdings; } + public BigDecimal getNonCoreHoldings(String world, String currency, boolean database) { + BigDecimal holdings = BigDecimal.ZERO; + for (Map.Entry> entry : TNE.manager().getHoldingsHandlers().descendingMap().entrySet()) { + for (HoldingsHandler handler : entry.getValue()) { + if (!handler.coreHandler()) { + if (handler.userContains().equalsIgnoreCase("") || + displayName().contains(handler.userContains())) { + holdings = holdings.add(handler.getHoldings(identifier(), world, TNE.manager().currencyManager().get(world, currency), database)); + } + } + } + } + return holdings; + } + public void saveItemCurrency(String world) { saveItemCurrency(world, true); } diff --git a/TNE/src/net/tnemc/core/common/configurations/MessageConfigurations.java b/TNE/src/net/tnemc/core/common/configurations/MessageConfigurations.java index 768bc9d3..bc46c828 100644 --- a/TNE/src/net/tnemc/core/common/configurations/MessageConfigurations.java +++ b/TNE/src/net/tnemc/core/common/configurations/MessageConfigurations.java @@ -88,6 +88,7 @@ public void load(FileConfiguration configurationFile) { configurations.put("Messages.Language.Reload", "Successfully reloaded all language files."); configurations.put("Messages.Language.Set", "Successfully set your language to $language."); + configurations.put("Messages.Module.Downloaded", "$module has been downloaded successfully."); configurations.put("Messages.Module.Info", "==== Module Info for $module ====Author: $authorVersion: $version"); configurations.put("Messages.Module.Invalid", "Unable to find a module with the name of \"$module\"."); configurations.put("Messages.Module.List", "This server is currently uses these TNE Modules: $modules."); @@ -114,7 +115,6 @@ public void load(FileConfiguration configurationFile) { configurations.put("Messages.Money.Converted", "Successfully exchanged \"$from_amount\" to \"$amount\"."); configurations.put("Messages.Money.Noted", "A note has been given to you in the amount of $amount for currency $currency."); configurations.put("Messages.Money.NoteClaimed", "Successfully claimed note for currency $currency in the amount of $amount.Your new balance is $balance."); - configurations.put("Messages.Money.NoteFailed", "I'm sorry, but your attempt to claim that currency note failed!."); configurations.put("Messages.Money.NoteMinimum", "The minimum note amount of $amount was not met."); configurations.put("Messages.Money.NoteFailed", "I'm sorry, but your attempt to claim that currency note failed!."); configurations.put("Messages.Money.Top", "=========[Economy Top]========= Page: $page/$page_top"); @@ -168,6 +168,7 @@ public void load(FileConfiguration configurationFile) { configurations.put("Messages.Commands.Language.Reload", "/language reload - Reloads all language files."); configurations.put("Messages.Commands.Language.Set", "/language set - Sets your current language to the one specified."); + configurations.put("Messages.Commands.Module.Download", "/tnem dl - Attempts to download the specified module."); configurations.put("Messages.Commands.Module.Info", "/tnem info - Displays some information about a module.- Module ~ The module to look up."); configurations.put("Messages.Commands.Module.List", "/tnem list - Lists all loaded TNE modules."); configurations.put("Messages.Commands.Module.Load", "/tnem load - Load a module from the modules directory.- Module ~ The module to load."); diff --git a/TNE/src/net/tnemc/core/common/module/Module.java b/TNE/src/net/tnemc/core/common/module/Module.java index 2ac51b03..9d41d656 100644 --- a/TNE/src/net/tnemc/core/common/module/Module.java +++ b/TNE/src/net/tnemc/core/common/module/Module.java @@ -39,6 +39,10 @@ public abstract class Module { public Module() { } + public String updateURL() { + return ""; + } + /** * @return a list of the classes that contain {@link net.tnemc.core.common.module.injectors.ModuleInjector module injectors} for this module. */ diff --git a/TNE/src/net/tnemc/core/common/module/ModuleLoader.java b/TNE/src/net/tnemc/core/common/module/ModuleLoader.java index a9373c84..751a00d8 100644 --- a/TNE/src/net/tnemc/core/common/module/ModuleLoader.java +++ b/TNE/src/net/tnemc/core/common/module/ModuleLoader.java @@ -8,8 +8,14 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.lang.reflect.Method; +import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; @@ -32,6 +38,15 @@ **/ public class ModuleLoader { + public static Map modulePaths = new HashMap<>(); + + static { + modulePaths.put("conversion", "https://github.com/TheNewEconomy/TNE-Bukkit/releases/download/Conversion/Conversion.jar"); + modulePaths.put("h2", "https://github.com/TheNewEconomy/TNE-Bukkit/releases/download/H2/H2.jar"); + modulePaths.put("mobs", "https://github.com/TheNewEconomy/TNE-Bukkit/releases/download/Mobs/Mobs.jar"); + modulePaths.put("mysql", "https://github.com/TheNewEconomy/TNE-Bukkit/releases/download/mysql/MySQL.jar"); + } + private File modulesYAML; private FileConfiguration moduleConfigurations; private Map modules = new HashMap<>(); @@ -79,6 +94,13 @@ public boolean hasModule(String moduleName) { return modules.containsKey(moduleName); } + public boolean hasModuleWithoutCase(String moduleName) { + for (String key : modules.keySet()) { + if(key.equalsIgnoreCase(moduleName)) return true; + } + return false; + } + public ModuleEntry getModule(String moduleName) { return modules.get(moduleName); } @@ -100,7 +122,7 @@ public String findPath(String moduleName) { public void unload(String moduleName) { if(hasModule(moduleName)) { ModuleEntry entry = getModule(moduleName); - entry.getModule().getListeners(TNE.instance()).forEach(value->value.unregister()); + entry.getModule().getListeners(TNE.instance()).forEach(ModuleListener::unregister); entry.getModule().unload(TNE.instance()); entry.unload(); @@ -178,12 +200,8 @@ private Module getModuleClass(String modulePath) { mainClass = urlClassLoader.loadClass(moduleMain); moduleClass = mainClass.asSubclass(Module.class); module = moduleClass.newInstance(); - module.moduleInjectors().forEach(value->registerInjectors(value)); - } catch (MalformedURLException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InstantiationException e) { + module.moduleInjectors().forEach(this::registerInjectors); + } catch (MalformedURLException | IllegalAccessException | InstantiationException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { TNE.logger().info("Unable to locate module main class for file " + file.getName()); @@ -247,4 +265,32 @@ public Map getModules() { public String getLastVersion(String name) { return moduleConfigurations.getString("Modules.DONTMODIFY." + name, modules.get(name).getInfo().version()); } + + public static void downloadModule(String module) { + if(modulePaths.containsKey(module)) { + try { + final String fileURL = modulePaths.get(module); + final URL url = new URL(fileURL); + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + int responseCode = httpConn.getResponseCode(); + if (responseCode == HttpURLConnection.HTTP_OK) { + String fileName = fileURL.substring(fileURL.lastIndexOf("/") + 1, fileURL.length()); + + InputStream in = httpConn.getInputStream(); + FileOutputStream out = new FileOutputStream(TNE.instance().getDataFolder() + File.separator + "modules" + File.separator + fileName); + + int bytesRead = -1; + byte[] buffer = new byte[4096]; + while ((bytesRead = in.read(buffer)) != -1) { + out.write(buffer, 0, bytesRead); + } + + out.close(); + in.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } } \ No newline at end of file diff --git a/TNE/src/net/tnemc/core/common/transaction/type/TNETransactionType.java b/TNE/src/net/tnemc/core/common/transaction/type/TNETransactionType.java index 1f3a9803..a8e3b3a1 100644 --- a/TNE/src/net/tnemc/core/common/transaction/type/TNETransactionType.java +++ b/TNE/src/net/tnemc/core/common/transaction/type/TNETransactionType.java @@ -64,12 +64,12 @@ default TransactionResult perform(Transaction transaction) { TNE.debug("Account null: " + (tneTransaction.getInitiator() == null)); TNE.debug("Transaction.initiator null: " + (tneTransaction == null)); TNE.debug("Transaction.initiatorCharge null: " + (tneTransaction.initiatorCharge() == null)); - proceed = canCharge(tneTransaction.getInitiator(), tneTransaction.initiatorBalance().getAmount(), tneTransaction.initiatorCharge().getAmount(), tneTransaction.initiatorCharge()); + proceed = canCharge(tneTransaction.initiatorBalance().getAmount(), tneTransaction.initiatorCharge().getAmount(), tneTransaction.initiatorCharge()); } if(affected().equals(TransactionAffected.BOTH) || affected().equals(TransactionAffected.RECIPIENT)) { TNE.debug("second if"); if(affected().equals(TransactionAffected.BOTH) && proceed || affected().equals(TransactionAffected.RECIPIENT)) { - proceed = canCharge(tneTransaction.getRecipient(), tneTransaction.recipientBalance().getAmount(), tneTransaction.recipientCharge().getAmount(), tneTransaction.recipientCharge()); + proceed = canCharge(tneTransaction.recipientBalance().getAmount(), tneTransaction.recipientCharge().getAmount(), tneTransaction.recipientCharge()); } } @@ -93,15 +93,16 @@ default TransactionResult perform(Transaction transaction) { } default boolean handleCharge(TNEAccount account, BigDecimal balance, BigDecimal amount, TransactionCharge charge) { + if(amount.compareTo(BigDecimal.ZERO) == 0) return true; if(charge.getType().equals(TransactionChargeType.LOSE)) { - account.setHoldings(charge.getWorld(), charge.getCurrency().name(), balance.subtract(amount), false, false); + account.removeHoldings(amount, charge.getCurrency(), charge.getWorld()); return true; } - account.setHoldings(charge.getWorld(), charge.getCurrency().name(), balance.add(amount), false, false); + account.setHoldings(charge.getWorld(), charge.getCurrency().name(), balance.subtract(account.getNonCoreHoldings(charge.getWorld(), charge.getCurrency().name(), false)).add(amount)); return true; } - default boolean canCharge(TNEAccount account, BigDecimal balance, BigDecimal amount, TransactionCharge charge) { + default boolean canCharge(BigDecimal balance, BigDecimal amount, TransactionCharge charge) { if(charge.getType().equals(TransactionChargeType.LOSE)) { return balance.compareTo(amount) >= 0; } diff --git a/TNE/src/net/tnemc/core/listeners/PlayerListener.java b/TNE/src/net/tnemc/core/listeners/PlayerListener.java index 7960c657..97be7ac0 100644 --- a/TNE/src/net/tnemc/core/listeners/PlayerListener.java +++ b/TNE/src/net/tnemc/core/listeners/PlayerListener.java @@ -24,7 +24,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.AsyncPlayerChatEvent; @@ -240,19 +239,6 @@ public void onChat(AsyncPlayerChatEvent event) { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onCraftEvent(CraftItemEvent event) { - if(!TNE.configurations().getBoolean("Core.Server.CurrencyCrafting")) { - final String world = WorldFinder.getWorld(event.getWhoClicked(), WorldVariant.BALANCE); - for (ItemStack item : event.getInventory().getMatrix()) { - if (item != null && TNE.manager().currencyManager().currencyFromItem(world, item).isPresent()) { - event.setCancelled(true); - break; - } - } - } - } - @EventHandler(priority = EventPriority.HIGHEST) public void onLevelChange(final PlayerLevelChangeEvent event) { if(TNE.manager().isXPGain(IDFinder.getID(event.getPlayer()))) { diff --git a/TNE/src/net/tnemc/resources/config.yml b/TNE/src/net/tnemc/resources/config.yml index 522234a0..d8eb916e 100644 --- a/TNE/src/net/tnemc/resources/config.yml +++ b/TNE/src/net/tnemc/resources/config.yml @@ -28,9 +28,6 @@ Core: #Whether or not experience gains should be disabled. This will help for servers that use Experience as currency. ExperienceGain: false - #Whether or not players are able to use their currency for crafting. - CurrencyCrafting: true - #Whether or not players are able to use currency in villager trades. CurrencyTrading: true diff --git a/TNE/src/net/tnemc/resources/mobs.yml b/TNE/src/net/tnemc/resources/mobs.yml index 6423f73d..41d5c307 100644 --- a/TNE/src/net/tnemc/resources/mobs.yml +++ b/TNE/src/net/tnemc/resources/mobs.yml @@ -20,13 +20,20 @@ Mobs: #Settings relating to item multipliers. #Here you may specify multipliers for killing entities with certain items. Multipliers: - DIAMOND_SWORD: + EXAMPLE_ITEM: #The chance to get this multiplier. Value must be between 0 and 100 Chance: 10 #The multiplier that is applied when killing an entity with this item. Multiplier: 10.00 + FIST: + #The chance to get this multiplier. Value must be between 0 and 100 + Chance: 100 + + #The multiplier that is applied when killing an entity with this item. + Multiplier: 1 + #Reward configurations for individual mobs #The configurations used for mobs that are not in vanilla MC or in your version of Bukkit Default: diff --git a/TNE/src/net/tnemc/resources/plugin.yml b/TNE/src/net/tnemc/resources/plugin.yml index 85dbc634..17db06d9 100644 --- a/TNE/src/net/tnemc/resources/plugin.yml +++ b/TNE/src/net/tnemc/resources/plugin.yml @@ -1,6 +1,6 @@ #General Data name: TheNewEconomy -version: 0.1.1.1 +version: 0.1.1.2 description: A modular feature-packed Bukkit Economy Plugin. author: creatorfromhell api-version: 1.13 diff --git a/TNEMobs/src/net/tnemc/mobs/MobConfiguration.java b/TNEMobs/src/net/tnemc/mobs/MobConfiguration.java index 1fb582c8..90951ca7 100644 --- a/TNEMobs/src/net/tnemc/mobs/MobConfiguration.java +++ b/TNEMobs/src/net/tnemc/mobs/MobConfiguration.java @@ -45,6 +45,14 @@ public void load(FileConfiguration configurationFile) { configurations.put("Mobs.Messages.KilledVowel", "You received $reward for killing an $mob."); configurations.put("Mobs.Messages.NPCTag", "I'm sorry, but you cannot use a name tag on a villager"); + if(configurationFile.contains("Mobs.Multipliers")) { + Set keys = configurationFile.getConfigurationSection("Mobs.Multipliers").getKeys(false); + for(String material : keys) { + configurations.put("Mobs.Multipliers." + material + ".Chance", 100); + configurations.put("Mobs.Multipliers." + material + ".Multiplier", 1); + } + } + for(EntityType type : EntityType.values()) { configurations.put("Mobs." + type.name() + ".Enabled", true); configurations.put("Mobs." + type.name() + ".RewardCurrency", "Default"); diff --git a/TNEMobs/src/net/tnemc/mobs/MobsListener.java b/TNEMobs/src/net/tnemc/mobs/MobsListener.java index 46201182..64991398 100644 --- a/TNEMobs/src/net/tnemc/mobs/MobsListener.java +++ b/TNEMobs/src/net/tnemc/mobs/MobsListener.java @@ -12,6 +12,7 @@ import net.tnemc.core.economy.transaction.charge.TransactionCharge; import net.tnemc.core.economy.transaction.charge.TransactionChargeType; import net.tnemc.core.economy.transaction.result.TransactionResult; +import org.bukkit.Material; import org.bukkit.entity.Ageable; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; @@ -25,6 +26,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.inventory.ItemStack; import java.math.BigDecimal; import java.util.UUID; @@ -165,6 +167,8 @@ public void onEntityDeath(final EntityDeathEvent event) { } //System.out.println("Mob Name1: " + mob); + final ItemStack tool = event.getEntity().getKiller().getInventory().getItemInMainHand(); + final String material = (tool != null && tool.getType() != null && !tool.getType().equals(Material.AIR))? tool.getType().name() : "FIST"; if (!MobsModule.instance().fileConfiguration.contains("Mobs." + mob)) mob = "Default"; //System.out.println("Mob Name2: " + mob); @@ -172,7 +176,7 @@ public void onEntityDeath(final EntityDeathEvent event) { mob = "Custom.Entries." + entity.getCustomName(); String currency = MobsModule.instance().mobCurrency(mob, world, id.toString()); reward = (player) ? MobsModule.instance().playerReward(mob, world, id.toString()) : MobsModule.instance().mobReward(mob, world, id.toString()); - //reward = CurrencyFormatter.round(world, currency, reward.multiply(MobsModule.instance().getRewardMultiplier(mob, world, id.toString()))); + reward = CurrencyFormatter.round(world, currency, reward.multiply(MobsModule.instance().multiplier(material, world, id.toString()))); String formatted = (mob.equalsIgnoreCase("Default") && event.getEntityType().toString() != null) ? event.getEntityType().toString() : mob; //System.out.println("Mob Name3: " + mob); if (entity.getCustomName() != null && MobsModule.instance().fileConfiguration.contains("Mobs.Custom.Entries." + entity.getCustomName())) diff --git a/TNEMobs/src/net/tnemc/mobs/MobsModule.java b/TNEMobs/src/net/tnemc/mobs/MobsModule.java index 14d742f1..2afd59a1 100644 --- a/TNEMobs/src/net/tnemc/mobs/MobsModule.java +++ b/TNEMobs/src/net/tnemc/mobs/MobsModule.java @@ -12,6 +12,7 @@ import java.io.Reader; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; +import java.util.Random; import java.util.UUID; /** @@ -113,6 +114,20 @@ public Boolean mobAge(String world, String player) { return TNE.instance().api().getBoolean("Mobs.EnableAge", world, player); } + public BigDecimal multiplier(String material, String world, String player) { + if(TNE.instance().api().getConfiguration("Mobs.Multipliers." + material + ".Chance", world, player) == null + || TNE.instance().api().getConfiguration("Mobs.Multipliers." + material + ".Multiplier", world, player) == null) { + return BigDecimal.ONE; + } + final int chance = TNE.instance().api().getInteger("Mobs.Multipliers." + material + ".Chance", world, player); + if(chance > 0) { + if(new Random().nextFloat() <= (chance/100)) { + return TNE.instance().api().getBigDecimal("Mobs.Multipliers." + material + ".Multiplier", world, player); + } + } + return BigDecimal.ONE; + } + public Boolean mobEnabled(String mob, String world, String player) { //System.out.println("ConfigurationManager.mobEnabled(" + mob + ", " + world + "," + player + ")"); TNE.debug(TNE.instance().api().getConfiguration("Mobs." + mob + ".Enabled", world, player) + "");