Skip to content

Commit 28ea66b

Browse files
Add PlayerShopClickEvent and Deprecated ShopClickEvent
1 parent 9dbfb07 commit 28ea66b

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* This file is a part of project QuickShop, the name is PlayerShopClickEvent.java
3+
* Copyright (C) PotatoCraft Studio and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License as published by the
7+
* Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
package org.maxgamer.quickshop.api.event;
21+
22+
import lombok.Getter;
23+
import org.bukkit.entity.Player;
24+
import org.jetbrains.annotations.NotNull;
25+
import org.maxgamer.quickshop.api.shop.Shop;
26+
27+
/**
28+
* A click event which have player variable
29+
* <p>
30+
* Since 5.1.1.3
31+
*/
32+
public class PlayerShopClickEvent extends ShopClickEvent {
33+
34+
35+
@Getter
36+
private final Player player;
37+
38+
/**
39+
* Call when shop was clicked.
40+
*
41+
* @param shop The shop bought from
42+
* @param player the player clicking shop
43+
*/
44+
public PlayerShopClickEvent(@NotNull Shop shop, Player player) {
45+
super(shop);
46+
this.player = player;
47+
}
48+
}

src/main/java/org/maxgamer/quickshop/api/event/ShopClickEvent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525

2626
/**
2727
* Calling when shop clicked
28+
* <p>
29+
* Deprecated, use PlayerShopClickEvent instead
2830
*/
31+
@Deprecated
2932
public class ShopClickEvent extends AbstractQSEvent implements Cancellable {
3033

3134
@NotNull

src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.jetbrains.annotations.Nullable;
4949
import org.maxgamer.quickshop.QuickShop;
5050
import org.maxgamer.quickshop.api.economy.AbstractEconomy;
51+
import org.maxgamer.quickshop.api.event.PlayerShopClickEvent;
5152
import org.maxgamer.quickshop.api.shop.Info;
5253
import org.maxgamer.quickshop.api.shop.Shop;
5354
import org.maxgamer.quickshop.api.shop.ShopAction;
@@ -213,6 +214,11 @@ private void postTrade(PlayerInteractEvent e) {
213214
}
214215
//Prevent use item by ancient
215216
e.setUseItemInHand(Event.Result.DENY);
217+
PlayerShopClickEvent event = new PlayerShopClickEvent(shop, p);
218+
if (Util.fireCancellableEvent(event)) {
219+
Util.debugLog("Ignore shop click, because some plugin cancel it.");
220+
return;
221+
}
216222
shop.onClick();
217223
this.playClickSound(e.getPlayer());
218224
// Text menu

src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import org.maxgamer.quickshop.QuickShop;
5151
import org.maxgamer.quickshop.api.chat.ComponentPackage;
5252
import org.maxgamer.quickshop.api.economy.EconomyCore;
53-
import org.maxgamer.quickshop.api.event.ShopClickEvent;
5453
import org.maxgamer.quickshop.api.event.ShopDeleteEvent;
5554
import org.maxgamer.quickshop.api.event.ShopInventoryCalculateEvent;
5655
import org.maxgamer.quickshop.api.event.ShopInventoryEvent;
@@ -578,11 +577,6 @@ public boolean matches(@Nullable ItemStack item) {
578577
@Override
579578
public void onClick() {
580579
Util.ensureThread(false);
581-
ShopClickEvent event = new ShopClickEvent(this);
582-
if (Util.fireCancellableEvent(event)) {
583-
Util.debugLog("Ignore shop click, because some plugin cancel it.");
584-
return;
585-
}
586580
refresh();
587581
setSignText();
588582
}

0 commit comments

Comments
 (0)