Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
OllieJW authored Oct 8, 2021
1 parent bf5ba94 commit aad20e4
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.olliejw</groupId>
<artifactId>OreMarket</artifactId>
<version>2.2.5</version>
<version>2.2.6</version>
<packaging>jar</packaging>

<name>OreMarket</name>
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/me/olliejw/oremarket/OreMarket.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,6 @@ private void createMsgConfig() {
e.printStackTrace();
}
}
public void reloadMsgConfig() {
try {
msgConfig.load(msgFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}

public static OreMarket main(){
return instance;
Expand Down
84 changes: 78 additions & 6 deletions src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@ private void changePlayerBalance(double Money, HumanEntity player, boolean opera
private double balance (HumanEntity Player) {
return OreMarket.getEconomy().getBalance((OfflinePlayer) Player);
}
/*SPOILER! private int getItemAmount (HumanEntity player, ItemStack item) {
if (item == null) {
return 0;
}
int amount = 0;
for (int i = 0; i < 36; i++) {
ItemStack slot = player.getInventory().getItem(i);
if (slot == null || !slot.isSimilar(item)) {
continue;
}
amount += slot.getAmount();
}
return amount;
}
private void removeItemAmount (HumanEntity player, ItemStack item) {
for (int i = 0; i < 36; i++) {
ItemStack slot = player.getInventory().getItem(i);
if (slot == null || !slot.equals(item)) {
continue;
}
slot.setAmount(0);
}
}*/

String title = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(OreMarket.main().getGuiConfig().getString("gui.title")));
Placeholders plh = new Placeholders();
Expand Down Expand Up @@ -112,11 +135,15 @@ else if (toSend.contains("[msg]")) {
int itemStock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock");

if (OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) {
// Take any type of the clicked item (e.g. custom name)
playerInventory.removeItem(event.getCurrentItem());
}
else {
// Take the EXACT item (e.g. exact custom name)
if (!(playerInventory.containsAtLeast(event.getCurrentItem(), 1))) {
String message = OreMarket.main().getMsgConfig().getString("messages.no-item", "&cYou don't have that item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return;
}
playerInventory.removeItem(event.getCurrentItem());
} else {
// Take any type of the clicked item (e.g. custom name)
playerInventory.removeItem(clickedItem);
}

Expand All @@ -127,6 +154,45 @@ else if (toSend.contains("[msg]")) {
String message = OreMarket.main().getMsgConfig().getString("messages.successfully-sold", "&aYou have successfully sold this item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
/* SPOILER!: if ((event.getClick() == ClickType.SHIFT_LEFT)) { // Sell ALL Mode
if (OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".buyonly")) {
// You cannot sell this, Buy only item
String message = OreMarket.main().getMsgConfig().getString("messages.buy-only", "&cThis item can only be bought");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return;
}
if (!(playerInventory.containsAtLeast(clickedItem, 1))) {
String message = OreMarket.main().getMsgConfig().getString("messages.no-item", "&cYou don't have that item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return;
}
double itemValue = OreMarket.main().getGuiConfig().getDouble("items." + slot + ".value");
int itemStock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock");
int itemAmount = getItemAmount(player, clickedItem);
if (OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) {
// Take the EXACT item and amount (e.g. exact custom name)
if (!(playerInventory.containsAtLeast(event.getCurrentItem(), 1))) {
String message = OreMarket.main().getMsgConfig().getString("messages.no-item", "&cYou don't have that item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return;
}
removeItemAmount(player, event.getCurrentItem());
}
else {
// Take any type of the clicked item (e.g. custom name)
removeItemAmount(player, clickedItem);
}
changePlayerBalance(itemValue*itemAmount, player, false, slot);
OreMarket.main().getGuiConfig().set("items." + slot + ".stock", itemStock+itemAmount);
OreMarket.main().saveGuiConfig();
String message = OreMarket.main().getMsgConfig().getString("messages.successfully-sold", "&aYou have successfully sold this item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}*/
if ((event.getClick() == ClickType.RIGHT)) { // Buy Mode
if (OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".sellonly")) {
// You cannot buy this, Sell only item
Expand All @@ -138,7 +204,13 @@ else if (toSend.contains("[msg]")) {
double itemValue = OreMarket.main().getGuiConfig().getDouble("items." + slot + ".value");
int itemStock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock");

if (itemStock > 0) {
// Is there any stock?
return;
}

if (balance(player) < itemValue) {
// Player has enough money?
String message = OreMarket.main().getMsgConfig().getString("messages.insufficient-balance", "&cYou don't have enough money to buy this item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return;
Expand All @@ -147,8 +219,7 @@ else if (toSend.contains("[msg]")) {
if (OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) {
// Take any type of the clicked item (e.g. custom name)
playerInventory.addItem(event.getCurrentItem());
}
else {
} else {
// Take the EXACT item (e.g. exact custom name)
playerInventory.addItem(clickedItem);
}
Expand All @@ -160,6 +231,7 @@ else if (toSend.contains("[msg]")) {
String message = OreMarket.main().getMsgConfig().getString("messages.successfully-bought", "&aYou have successfully bought the item!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}

mainGUI.createGUI((Player) player); // Reload GUI
}
}
Expand Down

0 comments on commit aad20e4

Please sign in to comment.