Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
Returned transactions logging, bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonidius20 committed Jan 17, 2018
1 parent 769434e commit 2fca1a0
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 34 deletions.
3 changes: 3 additions & 0 deletions src/main/java/ua/leonidius/trading/buy/Buy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
22 changes: 5 additions & 17 deletions src/main/java/ua/leonidius/trading/help/BuyListCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()) {
Expand All @@ -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+")"+" - "
Expand All @@ -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;
}
Expand Down
45 changes: 42 additions & 3 deletions src/main/java/ua/leonidius/trading/help/SellListCmd.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,63 @@
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)");
this.setAliases(aliases);
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;
}
}
8 changes: 6 additions & 2 deletions src/main/java/ua/leonidius/trading/sell/Sell.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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){
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/ua/leonidius/trading/utils/Message.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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%)."),
Expand All @@ -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%)."),
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ua/leonidius/trading/utils/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/main/resources/lang/rus.lng
Original file line number Diff line number Diff line change
Expand Up @@ -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%).
Expand All @@ -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%).
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/lang/ukr.lng
Original file line number Diff line number Diff line change
Expand Up @@ -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%).
Expand All @@ -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%).
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 2fca1a0

Please sign in to comment.