Add messages for actions or errors

This commit is contained in:
ChronosX88 2021-08-04 01:20:13 +03:00
parent e526dce1a1
commit a60c58df39
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
2 changed files with 65 additions and 27 deletions

View File

@ -87,42 +87,72 @@ public class InventoryEvents implements Listener {
clickedItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(itemConfig))); // Item that user clicked clickedItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(itemConfig))); // Item that user clicked
int slot = event.getSlot(); int slot = event.getSlot();
if ((event.getClick() == ClickType.LEFT) && (!OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".buyonly"))) { // Sell Mode if ((event.getClick() == ClickType.LEFT)) { // Sell Mode
double value = OreMarket.main().getGuiConfig().getDouble("items." + slot + ".value"); if (!OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".buyonly")) {
int stock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock"); double value = OreMarket.main().getGuiConfig().getDouble("items." + slot + ".value");
if (playerInventory.containsAtLeast(clickedItem, 1) || OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) { int stock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock");
if (OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) { if (playerInventory.containsAtLeast(clickedItem, 1) || OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) {
playerInventory.removeItem(event.getCurrentItem());
}
else {
playerInventory.removeItem(clickedItem);
}
addMoney(value, player);
valueChange(slot, value, true);
stockChange(slot, stock, 1, true);
}
}
if ((event.getClick() == ClickType.RIGHT) && (!OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".sellonly"))) { // Buy Mode
double value = OreMarket.main().getGuiConfig().getDouble("items." + slot + ".value");
int stock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock");
if (balance(player) > value) {
if ((stock > 1 || stock == -1) && (value > 1)) {
if (OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) { if (OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) {
playerInventory.addItem(event.getCurrentItem()); playerInventory.removeItem(event.getCurrentItem());
} }
else { else {
playerInventory.addItem(clickedItem); playerInventory.removeItem(clickedItem);
} }
takeMoney(value, player); addMoney(value, player);
valueChange(slot, value, false); valueChange(slot, value, true);
stockChange(slot, stock, 1, false); stockChange(slot, stock, 1, true);
String message = OreMarket.main().getGuiConfig().getString("gui.messages.successfully-sold", "&aYou have successfully sold the item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
} else {
String message = OreMarket.main().getGuiConfig().getString("gui.messages.no-item", "&cYou don't have that item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
} }
} else {
String message = OreMarket.main().getGuiConfig().getString("gui.messages.buy-only", "&cThis item can only be bought");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
}
if ((event.getClick() == ClickType.RIGHT)) { // Buy Mode
if (!OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".sellonly")) {
double value = OreMarket.main().getGuiConfig().getDouble("items." + slot + ".value");
int stock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock");
if (balance(player) > value) {
if (stock > 1 || stock == -1) {
if (value > 1) {
if (OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) {
playerInventory.addItem(event.getCurrentItem());
}
else {
playerInventory.addItem(clickedItem);
}
takeMoney(value, player);
valueChange(slot, value, false);
stockChange(slot, stock, 1, false);
String message = OreMarket.main().getGuiConfig().getString("gui.messages.successfully-bought", "&aYou have successfully bought the item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
} else {
String message = OreMarket.main().getGuiConfig().getString("gui.messages.price-too-low", "&cPrice of item is too low for buying!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
} else {
String message = OreMarket.main().getGuiConfig().getString("gui.messages.no-stocks", "&cMarket is run out of item stocks!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
} else {
String message = OreMarket.main().getGuiConfig().getString("gui.messages.insufficient-balance", "&cYou don't have enough money to buy this item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
} else {
String message = OreMarket.main().getGuiConfig().getString("gui.messages.sell-only", "&cThis item can only be sold");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
} }
} }
assert keySection != null; assert keySection != null;
for (String command : Objects.requireNonNull(OreMarket.main().getGuiConfig().getStringList("items." + event.getSlot() + ".commands"))) { for (String command : Objects.requireNonNull(OreMarket.main().getGuiConfig().getStringList("items." + event.getSlot() + ".commands"))) {
if (command != null) { String toSend = plh.format(command, player, keySection); if (command != null) {
String toSend = plh.format(command, player, keySection);
if (toSend.equals("[close]")) { if (toSend.equals("[close]")) {
player.closeInventory(); player.closeInventory();
} }

View File

@ -3,7 +3,15 @@
gui: gui:
title: '&4OreMarket' title: '&4OreMarket'
rows: 3 rows: 3
messages:
sell-only: "&cThis item can only be sold!"
buy-only: "&cThis item can only be bought"
no-item: "&cYou don't have that item!"
insufficient-balance: "&cYou don't have enough money to buy this item!"
price-too-low: "&cPrice of item is too low for buying!"
no-stocks: "&cMarket is run out of item stocks!"
successfully-bought: "&aYou have successfully bought the item!"
successfully-sold: "&aYou have successfully sold the item!"
items: items:
0: 0:
item: DIAMOND item: DIAMOND