View difference between Paste ID: Ptx6qMDG and x7c2w5vA
SHOW: | | - or go back to the newest paste.
1
package pl.pszemopl.pplextraefekty.events;
2
3
import org.bukkit.Bukkit;
4
import org.bukkit.Material;
5
import org.bukkit.entity.Player;
6
import org.bukkit.event.EventHandler;
7
import org.bukkit.event.Listener;
8
import org.bukkit.event.inventory.InventoryClickEvent;
9
import org.bukkit.inventory.ItemStack;
10
import org.bukkit.potion.PotionEffect;
11
import org.bukkit.potion.PotionEffectType;
12
import pl.pszemopl.pplextraefekty.configurations.Config;
13
import pl.pszemopl.pplextraefekty.utils.ChatUtil;
14
15
public class InventoryClickListener implements Listener {
16
    @SuppressWarnings("deprecation")
17
	@EventHandler
18
    public void onClickMain(InventoryClickEvent event) {
19
        Player p = (Player) event.getWhoClicked();
20
		if (event.getClickedInventory().getName() == null) return;
21
        if (ChatUtil.fixColor(Config.NAME).equalsIgnoreCase(event.getClickedInventory().getName())) {
22
            event.setCancelled(true);
23
            if (event.getSlot() == Config.SPEED_SLOT) {
24
                if (p.getInventory().containsAtLeast(new ItemStack(Material.getMaterial(Config.SPEED_CURRENCY)), Config.SPEED_AMOUNT)) {
25
                    p.getInventory().removeItem(new ItemStack(Material.getMaterial(Config.SPEED_CURRENCY), Config.SPEED_AMOUNT));
26
                    p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Config.SPEED_DURATION, 1, true));
27
                    p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, Config.SPEED_DURATION, 1, true));
28
                    p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Config.SPEED_DURATION, 0, true));
29
                    p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, Config.SPEED_DURATION1, 0, true));
30
                    p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, Config.SPEED_DURATION1, 0, true));
31
                    ChatUtil.sendMessage(p, Config.SPEED_BUYMESS);
32
                    Bukkit.getOnlinePlayers().forEach(all -> ChatUtil.sendMessage(all, Config.SPEED_BUYBC.replace("{PLAYER}", p.getName())));
33
                    p.sendTitle(ChatUtil.fixColor(Config.SPEED_BUYTITLE), ChatUtil.fixColor(Config.SPEED_BUYSUBTITLE));
34
                } else {
35
                    ChatUtil.sendMessage(p, Config.SPEED_LACK);
36
                }
37
            }
38
            if (event.getSlot() == Config.STRENGTH_SLOT) {
39
                if (p.getInventory().containsAtLeast(new ItemStack(Material.getMaterial(Config.STRENGTH_CURRENCY)), Config.STRENGTH_AMOUNT)) {
40
                    p.getInventory().removeItem(new ItemStack(Material.getMaterial(Config.STRENGTH_CURRENCY), Config.STRENGTH_AMOUNT));
41
                    p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, Config.STRENGTH_DURATION, 0, true));
42
                    ChatUtil.sendMessage(p, Config.STRENGTH_BUYMESS);
43
                    Bukkit.getOnlinePlayers().forEach(all -> ChatUtil.sendMessage(all, Config.STRENGTH_BUYBC.replace("{PLAYER}", p.getName())));
44
                    p.sendTitle(ChatUtil.fixColor(Config.STRENGTH_BUYTITLE), ChatUtil.fixColor(Config.STRENGTH_BUYSUBTITLE));
45
                } else {
46
                    ChatUtil.sendMessage(p, Config.STRENGTH_LACK);
47
                }
48
            }
49
            if (event.getSlot() == Config.HASTE_SLOT) {
50
                if (p.getInventory().containsAtLeast(new ItemStack(Material.getMaterial(Config.HASTE_CURRENCY)), Config.HASTE_AMOUNT)) {
51
                    p.getInventory().removeItem(new ItemStack(Material.getMaterial(Config.HASTE_CURRENCY), Config.HASTE_AMOUNT));
52
                    p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, Config.HASTE_DURATION, 0, true));
53
                    ChatUtil.sendMessage(p, Config.HASTE_BUYMESS);
54
                    Bukkit.getOnlinePlayers().forEach(all -> ChatUtil.sendMessage(all, Config.HASTE_BUYBC.replace("{PLAYER}", p.getName())));
55
                    p.sendTitle(ChatUtil.fixColor(Config.HASTE_BUYTITLE), ChatUtil.fixColor(Config.HASTE_BUYSUBTITLE));
56
                } else {
57
                    ChatUtil.sendMessage(p, Config.HASTE_LACK);
58
                }
59
            }
60
        }
61
    }
62
}