From 298bfb1c38f034bb16110aaaddb0ef86e11be14f Mon Sep 17 00:00:00 2001
From: BenceX100 <52270269+BenceX100@users.noreply.github.com>
Date: Sun, 26 May 2024 15:19:31 +0200
Subject: [PATCH] 1.3.0
---
pom.xml | 2 +-
.../artillexstudios/axtrade/trade/TradeGui.java | 13 +++++++++----
.../axtrade/trade/TradePlayer.java | 16 ++++++++++++++--
3 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/pom.xml b/pom.xml
index a571f63..c991526 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.artillexstudios
AxTrade
- 1.2.0
+ 1.3.0
jar
AxTrade
diff --git a/src/main/java/com/artillexstudios/axtrade/trade/TradeGui.java b/src/main/java/com/artillexstudios/axtrade/trade/TradeGui.java
index 00b6c3d..41915b9 100644
--- a/src/main/java/com/artillexstudios/axtrade/trade/TradeGui.java
+++ b/src/main/java/com/artillexstudios/axtrade/trade/TradeGui.java
@@ -16,6 +16,7 @@ import dev.triumphteam.gui.guis.StorageGui;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.event.inventory.ClickType;
+import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@@ -120,9 +121,15 @@ public class TradeGui extends GuiFrame {
return;
}
- if (event.isShiftClick() && !slots.contains(event.getView().getTopInventory().firstEmpty())) {
+ if (event.getCurrentItem() != null && event.isShiftClick() && event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY && !slots.contains(event.getView().getTopInventory().firstEmpty())) {
event.setCancelled(true);
- return;
+ for (int i : slots) {
+ if (gui.getInventory().getItem(i) == null) {
+ gui.getInventory().setItem(i, event.getCurrentItem().clone());
+ event.getCurrentItem().setAmount(0);
+ break;
+ }
+ }
}
player.cancel();
@@ -230,8 +237,6 @@ public class TradeGui extends GuiFrame {
gui.updateItem(slot, new GuiItem(otherItems.get(n), event -> event.setCancelled(true)));
n++;
}
-
- updateTitle();
}
public List getItems() {
diff --git a/src/main/java/com/artillexstudios/axtrade/trade/TradePlayer.java b/src/main/java/com/artillexstudios/axtrade/trade/TradePlayer.java
index fe121b3..c7ec833 100644
--- a/src/main/java/com/artillexstudios/axtrade/trade/TradePlayer.java
+++ b/src/main/java/com/artillexstudios/axtrade/trade/TradePlayer.java
@@ -7,6 +7,7 @@ import com.artillexstudios.axtrade.utils.SoundUtils;
import org.bukkit.entity.Player;
import java.util.HashMap;
+import java.util.Objects;
import static com.artillexstudios.axtrade.AxTrade.CONFIG;
@@ -57,19 +58,30 @@ public class TradePlayer {
trade.update();
SoundUtils.playSound(player, "accept");
SoundUtils.playSound(otherPlayer.getPlayer(), "accept");
+
+ getTradeGui().updateTitle();
+ otherPlayer.getTradeGui().updateTitle();
}
public void cancel() {
if (confirmed != null) {
this.confirmed = null;
+ otherPlayer.setConfirmed(null);
SoundUtils.playSound(player, "cancel");
SoundUtils.playSound(otherPlayer.getPlayer(), "cancel");
+
+ getTradeGui().updateTitle();
+ otherPlayer.getTradeGui().updateTitle();
+ return;
}
- otherPlayer.setConfirmed(null);
+ if (otherPlayer.setConfirmed(null)) getTradeGui().updateTitle();
}
- public void setConfirmed(Integer confirmed) {
+ public boolean setConfirmed(Integer confirmed) {
+ if (Objects.equals(this.confirmed, confirmed)) return false;
this.confirmed = confirmed;
+ getTradeGui().updateTitle();
+ return true;
}
public void tick() {