diff --git a/src/main/java/ua/leonidius/trading/buy/Buy.java b/src/main/java/ua/leonidius/trading/buy/Buy.java index 9331da0..b40baf8 100644 --- a/src/main/java/ua/leonidius/trading/buy/Buy.java +++ b/src/main/java/ua/leonidius/trading/buy/Buy.java @@ -58,6 +58,9 @@ static void buy (Player player, Item item){ int meta = item.getDamage(); String name = ItemName.get(item); Message.BUY_YOU_BOUGHT.print(player, amount, name, id, meta, cost, Main.settings.currency); + if (Main.settings.logging) { + Message.BUY_LOG.log(player, amount, name, id, meta, cost, Main.settings.currency); + } } private static boolean canBuy (Item item){ diff --git a/src/main/java/ua/leonidius/trading/help/BuyListCmd.java b/src/main/java/ua/leonidius/trading/help/BuyListCmd.java index 7eeef2d..d4cde22 100644 --- a/src/main/java/ua/leonidius/trading/help/BuyListCmd.java +++ b/src/main/java/ua/leonidius/trading/help/BuyListCmd.java @@ -9,8 +9,8 @@ import cn.nukkit.utils.TextFormat; import ua.leonidius.trading.Main; import ua.leonidius.trading.buy.Buy; -import ua.leonidius.trading.utils.Message; import ua.leonidius.trading.utils.ItemName; +import ua.leonidius.trading.utils.Message; import java.util.Iterator; import java.util.Set; @@ -34,20 +34,8 @@ public BuyListCmd(){ } public boolean onCommand(CommandSender sender, Command command, String label, String[] args){ - String output; - Config cfg; - boolean isCmdBuyList; - if (command == Main.getPlugin().getCommand("buylist")){ - output = Message.LIST_CAN_BUY.toString(); - cfg = Main.buycfg; - isCmdBuyList = true; - } else if (command == Main.getPlugin().getCommand("selllist")){ - output = Message.LIST_CAN_SELL.toString(); - cfg = Main.sellcfg; - isCmdBuyList = false; - } else { - return false; - } + String output = Message.LIST_CAN_BUY.toString(); + Config cfg = Main.buycfg; Set keyset = cfg.getAll().keySet(); Iterator it = keyset.iterator(); if (it.hasNext()) { @@ -61,7 +49,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St String name = ItemName.get(id, meta); double price = Buy.getPrice(Item.get(id, meta)); String discountKey = "d-"+id+"-"+meta; - if (isCmdBuyList && Main.discountCfg.exists(discountKey)) { + if (Main.discountCfg.exists(discountKey)) { double discount = Main.discountCfg.getDouble(discountKey); output = output+" "+TextFormat.YELLOW+name +TextFormat.WHITE+" ("+id+":"+meta+")"+" - " @@ -80,7 +68,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St output = output +" "+Message.LIST_PRICES_IN.getText(settings.currency, "NOCOLOR"); sender.sendMessage(output); } else { - Message.LIST_NOTHING.print(sender, "NOCOLOR"); + Message.LIST_NOTHING.printError(sender); } return true; } diff --git a/src/main/java/ua/leonidius/trading/help/SellListCmd.java b/src/main/java/ua/leonidius/trading/help/SellListCmd.java index ce5754d..e22b282 100644 --- a/src/main/java/ua/leonidius/trading/help/SellListCmd.java +++ b/src/main/java/ua/leonidius/trading/help/SellListCmd.java @@ -1,19 +1,29 @@ package ua.leonidius.trading.help; +import cn.nukkit.command.Command; +import cn.nukkit.command.CommandExecutor; +import cn.nukkit.command.CommandSender; import cn.nukkit.command.PluginCommand; +import cn.nukkit.utils.Config; +import cn.nukkit.utils.TextFormat; import ua.leonidius.trading.Main; -import ua.leonidius.trading.help.BuyListCmd; +import ua.leonidius.trading.utils.ItemName; import ua.leonidius.trading.utils.Message; +import java.util.Iterator; +import java.util.Set; + +import static ua.leonidius.trading.Main.settings; + /** * Created by Leonidius20 on 21.03.17. */ -public class SellListCmd extends PluginCommand { +public class SellListCmd extends PluginCommand implements CommandExecutor { @SuppressWarnings("unchecked") public SellListCmd(){ super ("selllist", Main.getPlugin()); - this.setExecutor(new BuyListCmd()); + this.setExecutor(this); String[] aliases = {"slist"}; this.setDescription(Message.CMD_SELLLIST.toString()); this.setUsage("/selllist (/slist)"); @@ -21,4 +31,33 @@ public SellListCmd(){ this.getCommandParameters().clear(); } + public boolean onCommand(CommandSender sender, Command command, String s, String[] strings) { + String output = Message.LIST_CAN_SELL.toString(); + Config cfg = Main.sellcfg; + Set keyset = cfg.getAll().keySet(); + Iterator it = keyset.iterator(); + if (it.hasNext()) { + while (it.hasNext()) { + String key = it.next().toString(); + String[] idmeta = key.split("-"); + if (idmeta.length == 3) { + try { + int id = Integer.parseInt(idmeta[1]); + int meta = Integer.parseInt(idmeta[2]); + String name = ItemName.get(id, meta); + double price = cfg.getDouble(key); + output = output + " " + TextFormat.YELLOW + name + + TextFormat.WHITE + " (" + id + ":" + meta + ")" + " - " + + TextFormat.GREEN + price + + TextFormat.WHITE + ","; + } catch (NumberFormatException e) {} + } + } + output = output +" "+Message.LIST_PRICES_IN.getText(settings.currency, "NOCOLOR"); + sender.sendMessage(output); + } else { + Message.LIST_NOTHING.printError(sender); + } + return true; + } } diff --git a/src/main/java/ua/leonidius/trading/sell/Sell.java b/src/main/java/ua/leonidius/trading/sell/Sell.java index 1f8b86c..5c0e657 100644 --- a/src/main/java/ua/leonidius/trading/sell/Sell.java +++ b/src/main/java/ua/leonidius/trading/sell/Sell.java @@ -35,7 +35,9 @@ static void sellFromHand (Player player, Item item, int slot){ player.getInventory().clear(slot); EconomyAPI.getInstance().addMoney(player, cost); Message.SELL_YOU_SOLD.print(player, amount, name, id, meta, cost, Main.settings.currency); - + if (Main.settings.logging) { + Message.SELL_LOG.log(player, amount, name, id, meta, cost, Main.settings.currency); + } } static void sellItem(Player player, Item item) { @@ -73,8 +75,10 @@ static void sellItem(Player player, Item item) { String name = ItemName.get(item); player.getInventory().removeItem(item); EconomyAPI.getInstance().addMoney(player, cost); - Message.SELL_YOU_SOLD.print(player, amount, name, id, meta, cost, Main.settings.currency); + if (Main.settings.logging) { + Message.SELL_LOG.log(player, amount, name, id, meta, cost, Main.settings.currency); + } } public static int getItemCount(Player player, Item item){ diff --git a/src/main/java/ua/leonidius/trading/utils/Message.java b/src/main/java/ua/leonidius/trading/utils/Message.java index 37443ca..f090818 100644 --- a/src/main/java/ua/leonidius/trading/utils/Message.java +++ b/src/main/java/ua/leonidius/trading/utils/Message.java @@ -1,17 +1,18 @@ package ua.leonidius.trading.utils; - import cn.nukkit.Player; - import cn.nukkit.Server; - import cn.nukkit.command.CommandSender; - import cn.nukkit.level.Location; - import cn.nukkit.plugin.PluginBase; - import cn.nukkit.utils.Config; - import cn.nukkit.utils.TextFormat; - import java.io.File; - import java.io.InputStream; - import java.text.DecimalFormat; +import cn.nukkit.Player; +import cn.nukkit.Server; +import cn.nukkit.command.CommandSender; +import cn.nukkit.level.Location; +import cn.nukkit.plugin.PluginBase; +import cn.nukkit.utils.Config; +import cn.nukkit.utils.TextFormat; - import static ua.leonidius.trading.Main.settings; +import java.io.File; +import java.io.InputStream; +import java.text.DecimalFormat; + +import static ua.leonidius.trading.Main.settings; public enum Message { @@ -26,6 +27,7 @@ public enum Message { SELL_NOT_SELLING ("You cannot sell this item."), SELL_YOU_SOLD ("You have sold %1%x %2% (%3%:%4%) for %5%%6%."), + SELL_LOG ("Player %1% have sold %2%x %3% (%4%:%5%) for %6%%7%"), SELL_LESS_THAN_ONE ("You cannot sell less than one item."), SELL_NO_ITEM ("You have no items to sell."), SELL_NO_ITEM_MAX ("Not enough items, max possible amount will be sold (%1%)."), @@ -35,6 +37,7 @@ public enum Message { BUY_LESS_THAN_ONE ("You cannot buy less than one item."), BUY_NOT_ENOUGH_MONEY ("Not enough money."), BUY_YOU_BOUGHT ("You have bought %1%x %2% (%3%:%4%) for %5%%6%."), + BUY_LOG ("Player %1% have bought %2%x %3% (%4%:%5%) for %6%%7%"), BUY_NO_SPACE ("Not enough space in your inventory."), BUY_NO_SPACE_MAX ("Not enough space in your inventory, max possible amount will be purchased (%1%)."), BUY_NO_MONEY_MAX ("Not enough money, max possible amount will be purchased (%1%)."), diff --git a/src/main/java/ua/leonidius/trading/utils/Settings.java b/src/main/java/ua/leonidius/trading/utils/Settings.java index ea3dfc0..df0d13b 100644 --- a/src/main/java/ua/leonidius/trading/utils/Settings.java +++ b/src/main/java/ua/leonidius/trading/utils/Settings.java @@ -41,6 +41,8 @@ public Settings(Plugin plugin) { String error_color = "c"; @Path (value = "general.language") String language = "default"; + @Path (value = "general.transaction-logging") + public boolean logging = false; public String currency; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 359414d..08b0039 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -29,5 +29,7 @@ general: secondary-color: 2 #Color of error messages error-color: c + #Saving info about all transactions to log + transaction-logging: false #If true, a file with all strings will be created. You can edit the strings. save-translation: false \ No newline at end of file diff --git a/src/main/resources/lang/rus.lng b/src/main/resources/lang/rus.lng index 4101bb0..7d4c3ec 100644 --- a/src/main/resources/lang/rus.lng +++ b/src/main/resources/lang/rus.lng @@ -5,6 +5,7 @@ id_itemid: У вас в руках %1%, ID - %2%:%3%. sell_not_selling: Этот предмет нельзя продать. sell_you_sold: Продано %1% шт. %2% (%3%:%4%) за %5%%6%. +sell_log: Игрок %1% продал %2% шт. %3% (%4%:%5%) за %6%%7%. sell_less_than_one: Вы не можете продать меньше одного предмета. sell_no_item: У вас нету предметов для продажи. sell_no_item_max: Недостаточно предметов, будет продано макс. возможное кол-во (%1%). @@ -14,6 +15,7 @@ buy_not_selling: Этот предмет не продаётся. buy_less_than_one: Вы не можете купить меньше одного предмета. buy_not_enough_money: Недостаточно денег для покупки. buy_you_bought: Куплено %1% шт. %2% (%3%:%4%) за %5%%6%. +buy_log: Игрок %1% купил %2% шт. %3% (%4%:%5%) за %6%%7%. buy_no_space: Недостаточно места в инвентаре. buy_no_space_max: Недостаточно места в инвентаре, будет куплено макс. возможное кол-во (%1%). buy_no_money_max: Недостаточно денег, будет куплено макс. возможное кол-во (%1%). diff --git a/src/main/resources/lang/ukr.lng b/src/main/resources/lang/ukr.lng index 5a8499d..1a6b4bc 100644 --- a/src/main/resources/lang/ukr.lng +++ b/src/main/resources/lang/ukr.lng @@ -5,6 +5,7 @@ id_itemid: У вас в руках %1%, ID - %2%:%3%. sell_not_selling: Цей предмет не можна продавати. sell_you_sold: Продано %1% шт. %2% (%3%:%4%) за %5%%6%. +sell_log: Гравець %1% продав %2% шт. %3% (%4%:%5%) за %6%%7%. sell_less_than_one: Ви не можете продати менше одного предмета. sell_no_item: У вас немає предметів для продажу. sell_no_item_max: Недостатньо предметів, буде продано максимальну можливу кількість (%1%). @@ -14,6 +15,7 @@ buy_not_selling: Цей предмет не продається. buy_less_than_one: Ви не можете купити менше одного предмета. buy_not_enough_money: Недостатньо грошей для покупки. buy_you_bought: Придбано %1% шт. %2% (%3%:%4%) за %5%%6%. +buy_log: Гравець %1% придбав %2% шт. %3% (%4%:%5%) за %6%%7%. buy_no_space: Недостатньо місця в інвентарі. buy_no_space_max: Недостатньо місця в інвентарі, буде придбано максимальну можливу кількість (%1%). buy_no_money_max: Недостататньо грошей, буде придбано максимальну можливу кількість (%1%). diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 26932d6..f56b9e1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: Trading Commands main: ua.leonidius.trading.Main -version: 1.0.0 +version: 1.0.1 author: Leonidius20 api: ["1.0.0"] description: Shop and auction system, based on commands.