aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-API-Patches/0244-added-PlayerTradeEvent.patch
blob: 5288a1120599f410d9e103d9dddf4078d21e77ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 2 Jul 2020 16:10:10 -0700
Subject: [PATCH] added PlayerTradeEvent


diff --git a/src/main/java/io/papermc/paper/event/player/PlayerTradeEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerTradeEvent.java
new file mode 100755
index 0000000000000000000000000000000000000000..198e5464eae6b961c83148a57c18f91a4bb33cf6
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/PlayerTradeEvent.java
@@ -0,0 +1,121 @@
+package io.papermc.paper.event.player;
+
+import org.bukkit.entity.AbstractVillager;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.bukkit.inventory.MerchantRecipe;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Called when a player trades with a villager or wandering trader
+ */
+public class PlayerTradeEvent extends PlayerEvent implements Cancellable {
+
+    private static final HandlerList handlers = new HandlerList();
+    private boolean cancelled;
+
+    private boolean increaseTradeUses;
+    private boolean rewardExp;
+    private final AbstractVillager villager;
+    private MerchantRecipe trade;
+
+    public PlayerTradeEvent(@NotNull Player player, @NotNull AbstractVillager villager, @NotNull MerchantRecipe trade, boolean rewardExp, boolean increaseTradeUses) {
+        super(player);
+        this.villager = villager;
+        this.trade = trade;
+        this.rewardExp = rewardExp;
+        this.increaseTradeUses = increaseTradeUses;
+    }
+
+    /**
+     * Gets the Villager or Wandering trader associated with this event
+     * @return the villager or wandering trader
+     */
+    @NotNull
+    public AbstractVillager getVillager() {
+        return villager;
+    }
+
+    /**
+     * Gets the associated trade with this event
+     * @return the trade
+     */
+    @NotNull
+    public MerchantRecipe getTrade() {
+        return trade;
+    }
+
+    /**
+     * Sets the trade. This is then used to determine the next prices
+     * @param trade the trade to use
+     */
+    public void setTrade(@Nullable MerchantRecipe trade) {
+        this.trade = trade;
+    }
+
+    /**
+     * @return will trade try to reward exp
+     */
+    public boolean isRewardingExp() {
+        return rewardExp;
+    }
+
+    /**
+     * Sets whether the trade will try to reward exp
+     * @param rewardExp try to reward exp
+     */
+    public void setRewardExp(boolean rewardExp) {
+        this.rewardExp = rewardExp;
+    }
+
+    /**
+     * @return whether or not the trade will count as a use of the trade
+     */
+    public boolean willIncreaseTradeUses() {
+        return increaseTradeUses;
+    }
+
+    /**
+     * Sets whether or not the trade will count as a use
+     * @param increaseTradeUses true to count/false to not count
+     */
+    public void setIncreaseTradeUses(boolean increaseTradeUses) {
+        this.increaseTradeUses = increaseTradeUses;
+    }
+
+    /**
+     * Gets the cancellation state of this event. A cancelled event will not
+     * be executed in the server, but will still pass to other plugins
+     *
+     * @return true if this event is cancelled
+     */
+    @Override
+    public boolean isCancelled() {
+        return this.cancelled;
+    }
+
+    /**
+     * Sets the cancellation state of this event. A cancelled event will not
+     * be executed in the server, but will still pass to other plugins.
+     *
+     * @param cancel true if you wish to cancel this event
+     */
+    @Override
+    public void setCancelled(boolean cancel) {
+        this.cancelled = cancel;
+    }
+
+    @NotNull
+    @Override
+    public HandlerList getHandlers() {
+        return handlers;
+    }
+
+    @NotNull
+    public static HandlerList getHandlerList() {
+        return handlers;
+    }
+}