forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CreationFeeGetter.java
53 lines (42 loc) · 1.82 KB
/
CreationFeeGetter.java
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
package com.Acrobot.ChestShop.Listeners.PostShopCreation;
import static com.Acrobot.ChestShop.Permission.NOFEE;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Economy.Economy;
import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencySubtractEvent;
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import java.math.BigDecimal;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
/**
* @author Acrobot
*/
public class CreationFeeGetter implements Listener {
@EventHandler
public static void onShopCreation(ShopCreatedEvent event) {
double shopCreationPrice = Properties.SHOP_CREATION_PRICE;
if (shopCreationPrice == 0) {
return;
}
if (ChestShopSign.isAdminShop(event.getSign())) {
return;
}
Player player = event.getPlayer();
if (Permission.has(player, NOFEE)) {
return;
}
CurrencySubtractEvent subtractionEvent = new CurrencySubtractEvent(BigDecimal.valueOf(shopCreationPrice), player);
ChestShop.callEvent(subtractionEvent);
if (!Economy.getServerAccountName().isEmpty()) {
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(BigDecimal.valueOf(shopCreationPrice), NameManager.getServerAccountUUID(), player.getWorld());
ChestShop.callEvent(currencyAddEvent);
}
player.sendMessage(Messages.prefix(Messages.SHOP_FEE_PAID.replace("%amount", Economy.formatBalance(shopCreationPrice))));
}
}