Skip to content

Commit

Permalink
closes #9
Browse files Browse the repository at this point in the history
Took 7 minutes
  • Loading branch information
kiranhart committed Oct 5, 2022
1 parent 5e5f8ab commit 890cd1f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/java/ca/tweetzy/auctionhouse/guis/GUISellItem.java
Expand Up @@ -17,6 +17,7 @@
import ca.tweetzy.core.utils.NumberUtils;
import ca.tweetzy.core.utils.PlayerUtils;
import ca.tweetzy.core.utils.TextUtils;
import lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.inventory.ClickType;
Expand Down Expand Up @@ -160,6 +161,10 @@ private void draw() {
put("%remaining_seconds%", times[3]);
}}), ClickType.LEFT, e -> {
e.gui.close();

// work-around to clicking closeable item with item on cursor
handleClosableCursorItem(e);

PlayerChatInput.PlayerChatInputBuilder<Long> builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player);
builder.isValidInput((p, str) -> {
String[] parts = ChatColor.stripColor(str).split(" ");
Expand Down Expand Up @@ -193,8 +198,12 @@ private void draw() {
}}), ClickType.LEFT, e -> {
setTheItemToBeListed();
setAllowClose(true);

e.gui.close();

// work-around to clicking closeable item with item on cursor
handleClosableCursorItem(e);

PlayerChatInput.PlayerChatInputBuilder<Double> builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player);
builder.isValidInput((p, str) -> {
if (validateChatNumber(str, Settings.MIN_AUCTION_PRICE.getDouble(), false) && validateChatNumber(str, Settings.MAX_AUCTION_PRICE.getDouble(), true)) {
Expand Down Expand Up @@ -225,8 +234,12 @@ private void draw() {
}}), ClickType.LEFT, e -> {
setTheItemToBeListed();
setAllowClose(true);

e.gui.close();

// work-around to clicking closeable item with item on cursor
handleClosableCursorItem(e);

PlayerChatInput.PlayerChatInputBuilder<Double> builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player);
builder.isValidInput((p, str) -> {
return validateChatNumber(str, Settings.MIN_AUCTION_START_PRICE.getDouble(), false) && validateChatNumber(str, Settings.MAX_AUCTION_START_PRICE.getDouble(), true);
Expand All @@ -253,8 +266,12 @@ private void draw() {
}}), ClickType.LEFT, e -> {
setTheItemToBeListed();
setAllowClose(true);

e.gui.close();

// work-around to clicking closeable item with item on cursor
handleClosableCursorItem(e);

PlayerChatInput.PlayerChatInputBuilder<Double> builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player);
builder.isValidInput((p, str) -> {
return validateChatNumber(str, Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble(), false) && validateChatNumber(str, Settings.MAX_AUCTION_INCREMENT_PRICE.getDouble(), true);
Expand Down Expand Up @@ -453,10 +470,20 @@ private void draw() {
AuctionHouse.getInstance().getAuctionPlayerManager().getUsingSellGUI().remove(e.player.getUniqueId());
setAllowClose(true);
e.gui.close();

if (e.cursor != null)
e.player.getInventory().addItem(e.cursor);
});

}

private void handleClosableCursorItem(@NonNull final GuiClickEvent e) {
if (e.cursor != null) {
AuctionHouse.getInstance().getAuctionPlayerManager().addItemToSellHolding(player.getUniqueId(), e.cursor);
this.itemToBeListed = e.cursor.clone();
}
}

private boolean validateChatNumber(String input, double requirement, boolean checkMax) {
String val = ChatColor.stripColor(input);
if (checkMax)
Expand Down

0 comments on commit 890cd1f

Please sign in to comment.