This commit is contained in:
BenceX100 2024-05-26 15:19:31 +02:00
parent 727806f690
commit 298bfb1c38
3 changed files with 24 additions and 7 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.artillexstudios</groupId>
<artifactId>AxTrade</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<packaging>jar</packaging>
<name>AxTrade</name>

View File

@ -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<ItemStack> getItems() {

View File

@ -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() {