|
6 | 6 | import io.github.thatsmusic99.headsplus.api.events.HeadCraftEvent; |
7 | 7 | import io.github.thatsmusic99.headsplus.api.events.PlayerHeadDropEvent; |
8 | 8 | import io.github.thatsmusic99.headsplus.api.events.SellHeadEvent; |
9 | | -import io.github.thatsmusic99.headsplus.commands.maincommand.DebugPrint; |
10 | 9 | import io.github.thatsmusic99.headsplus.util.DataManager; |
11 | | -import org.bukkit.event.EventHandler; |
| 10 | +import io.github.thatsmusic99.headsplus.util.events.HeadsPlusEventExecutor; |
| 11 | +import io.github.thatsmusic99.headsplus.util.events.HeadsPlusListener; |
| 12 | +import org.bukkit.Bukkit; |
| 13 | +import org.bukkit.entity.Player; |
| 14 | +import org.bukkit.event.EventPriority; |
12 | 15 | import org.bukkit.event.Listener; |
13 | 16 | import org.bukkit.scheduler.BukkitRunnable; |
14 | 17 |
|
15 | 18 | public class LeaderboardEvents implements Listener { |
16 | 19 |
|
17 | | - private final HeadsPlus hp = HeadsPlus.getInstance(); |
18 | | - |
19 | | - @EventHandler |
20 | | - public void onHeadDrop(EntityHeadDropEvent e) { |
21 | | - try { |
22 | | - if (!e.isCancelled()) { |
23 | | - if (e.getPlayer() != null) { |
24 | | - if (hp.isUsingLeaderboards()) { |
25 | | - if (hp.getConfiguration().getPerks().smite_on_head) { |
26 | | - for (int i = 0; i < 5; ++i) { |
27 | | - e.getLocation().getWorld().strikeLightning(e.getPlayer().getLocation()); |
| 20 | + public LeaderboardEvents() { |
| 21 | + super(); |
| 22 | + HeadsPlus hp = HeadsPlus.getInstance(); |
| 23 | + Bukkit.getPluginManager().registerEvent(EntityHeadDropEvent.class, new HeadsPlusListener<EntityHeadDropEvent>() { |
| 24 | + @Override |
| 25 | + public void onEvent(EntityHeadDropEvent event) { |
| 26 | + if (!event.isCancelled()) { |
| 27 | + if (event.getPlayer() != null) { |
| 28 | + Player player = event.getPlayer(); |
| 29 | + if (hp.isUsingLeaderboards()) { |
| 30 | + if (hp.getConfiguration().getPerks().smite_on_head) { |
| 31 | + for (int i = 0; i < 5; ++i) { |
| 32 | + event.getLocation().getWorld().strikeLightning(player.getLocation()); |
| 33 | + } |
28 | 34 | } |
| 35 | + HPPlayer.getHPPlayer(player).addXp(hp.getConfiguration().getMechanics().getInt("xp.head-drops") * event.getAmount()); |
| 36 | + new BukkitRunnable() { |
| 37 | + @Override |
| 38 | + public void run() { |
| 39 | + DataManager.addToTotal(player, event.getEntityType().name(), "headspluslb", event.getAmount()); |
| 40 | + } |
| 41 | + }.runTaskAsynchronously(hp); |
| 42 | + |
29 | 43 | } |
30 | | - HPPlayer.getHPPlayer(e.getPlayer()).addXp(hp.getConfiguration().getMechanics().getInt("xp.head-drops") * e.getAmount()); |
31 | | - new BukkitRunnable() { |
32 | | - @Override |
33 | | - public void run() { |
34 | | - DataManager.addToTotal(e.getPlayer(), e.getEntityType().name(), "headspluslb", e.getAmount()); |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + }, EventPriority.MONITOR, new HeadsPlusEventExecutor(EntityHeadDropEvent.class, "EntityHeadDropEvent"), hp); |
| 48 | + |
| 49 | + Bukkit.getPluginManager().registerEvent(PlayerHeadDropEvent.class, new HeadsPlusListener<PlayerHeadDropEvent>() { |
| 50 | + @Override |
| 51 | + public void onEvent(PlayerHeadDropEvent event) { |
| 52 | + if (!event.isCancelled()) { |
| 53 | + if (event.getPlayer() != null) { |
| 54 | + Player player = event.getPlayer(); |
| 55 | + if (hp.isUsingLeaderboards()) { |
| 56 | + if (hp.getConfiguration().getPerks().smite_on_head) { |
| 57 | + for (int i = 0; i < 5; ++i) { |
| 58 | + event.getLocation().getWorld().strikeLightning(player.getLocation()); |
| 59 | + } |
35 | 60 | } |
36 | | - }.runTaskAsynchronously(hp); |
| 61 | + HPPlayer.getHPPlayer(player).addXp(hp.getConfiguration().getMechanics().getInt("xp.head-drops") * event.getAmount()); |
| 62 | + new BukkitRunnable() { |
| 63 | + @Override |
| 64 | + public void run() { |
| 65 | + DataManager.addToTotal(player, "player", "headspluslb", event.getAmount()); |
| 66 | + } |
| 67 | + }.runTaskAsynchronously(hp); |
37 | 68 |
|
| 69 | + } |
38 | 70 | } |
39 | 71 | } |
40 | 72 | } |
41 | | - } catch (Exception ex) { |
42 | | - DebugPrint.createReport(ex, "Event (LeaderboardEvents)", false, null); |
43 | | - } |
| 73 | + }, EventPriority.MONITOR, new HeadsPlusEventExecutor(PlayerHeadDropEvent.class, "PlayerHeadDropEvent"), hp); |
44 | 74 |
|
45 | | - } |
46 | | - |
47 | | - @EventHandler |
48 | | - public void onPHeadDrop(PlayerHeadDropEvent e) { |
49 | | - try { |
50 | | - if (!e.isCancelled()) { |
51 | | - if (e.getPlayer() != null) { |
| 75 | + Bukkit.getPluginManager().registerEvent(SellHeadEvent.class, new HeadsPlusListener<SellHeadEvent>() { |
| 76 | + @Override |
| 77 | + public void onEvent(SellHeadEvent event) { |
| 78 | + if (!event.isCancelled()) { |
52 | 79 | if (hp.isUsingLeaderboards()) { |
53 | | - if (hp.getConfiguration().getPerks().smite_on_head) { |
54 | | - for (int i = 0; i < 5; ++i) { |
55 | | - e.getLocation().getWorld().strikeLightning(e.getPlayer().getLocation()); |
56 | | - } |
| 80 | + for (int is : event.getEntityAmounts().values()) { |
| 81 | + HPPlayer.getHPPlayer(event.getPlayer()).addXp(hp.getConfiguration().getMechanics().getInt("xp.selling") * is); |
57 | 82 | } |
58 | | - HPPlayer.getHPPlayer(e.getPlayer()).addXp(hp.getConfiguration().getMechanics().getInt("xp.head-drops") * e.getAmount()); |
59 | | - new BukkitRunnable() { |
60 | | - @Override |
61 | | - public void run() { |
62 | | - DataManager.addToTotal(e.getPlayer(), "player", "headspluslb", e.getAmount()); |
| 83 | + for (String s : event.getEntityAmounts().keySet()) { |
| 84 | + for (int i : event.getEntityAmounts().values()) { |
| 85 | + if (event.getEntityAmounts().get(s) == i) { |
| 86 | + new BukkitRunnable() { |
| 87 | + @Override |
| 88 | + public void run() { |
| 89 | + DataManager.addToTotal(event.getPlayer(), s, "headsplussh", i); |
| 90 | + } |
| 91 | + }.runTaskAsynchronously(hp); |
| 92 | + } |
63 | 93 | } |
64 | | - }.runTaskAsynchronously(hp); |
65 | | - |
| 94 | + } |
66 | 95 | } |
67 | 96 | } |
68 | 97 | } |
69 | | - } catch (Exception ex) { |
70 | | - DebugPrint.createReport(ex, "Event (LeaderboardEvents)", false, null); |
71 | | - } |
| 98 | + }, EventPriority.MONITOR, new HeadsPlusEventExecutor(SellHeadEvent.class, "SellHeadEvent"), hp); |
72 | 99 |
|
73 | | - } |
74 | | - |
75 | | - @EventHandler |
76 | | - public void onHeadSold(SellHeadEvent e) { |
77 | | - try { |
78 | | - if (!e.isCancelled()) { |
79 | | - if (hp.isUsingLeaderboards()) { |
80 | | - for (int is : e.getEntityAmounts().values()) { |
81 | | - HPPlayer.getHPPlayer(e.getPlayer()).addXp(hp.getConfiguration().getMechanics().getInt("xp.selling") * is); |
82 | | - } |
83 | | - for (String s : e.getEntityAmounts().keySet()) { |
84 | | - for (int i : e.getEntityAmounts().values()) { |
85 | | - if (e.getEntityAmounts().get(s) == i) { |
| 100 | + Bukkit.getPluginManager().registerEvent(HeadCraftEvent.class, new HeadsPlusListener<HeadCraftEvent>() { |
| 101 | + @Override |
| 102 | + public void onEvent(HeadCraftEvent event) { |
| 103 | + if (!event.isCancelled()) { |
| 104 | + if (hp.isUsingLeaderboards()) { |
| 105 | + if (event.getEntityType() != null) { |
| 106 | + if (!(event.getEntityType().equalsIgnoreCase("invalid") || event.getEntityType().isEmpty())) { |
86 | 107 | new BukkitRunnable() { |
87 | 108 | @Override |
88 | 109 | public void run() { |
89 | | - DataManager.addToTotal(e.getPlayer(), s, "headsplussh", i); |
| 110 | + HPPlayer.getHPPlayer(event.getPlayer()).addXp(hp.getConfiguration().getMechanics().getInt("xp.crafting") * event.getHeadsCrafted()); |
| 111 | + DataManager.addToTotal(event.getPlayer(), event.getEntityType(), "headspluscraft", event.getHeadsCrafted()); |
90 | 112 | } |
91 | 113 | }.runTaskAsynchronously(hp); |
92 | 114 | } |
93 | 115 | } |
94 | 116 | } |
95 | 117 | } |
96 | 118 | } |
97 | | - } catch (Exception ex) { |
98 | | - DebugPrint.createReport(ex, "Event (LeaderboardEvents)", false, null); |
99 | | - } |
100 | | - } |
101 | | - |
102 | | - @EventHandler |
103 | | - public void onHeadCraft(HeadCraftEvent e) { |
104 | | - try { |
105 | | - if (!e.isCancelled()) { |
106 | | - if (hp.isUsingLeaderboards()) { |
107 | | - if (e.getEntityType() != null) { |
108 | | - if (!(e.getEntityType().equalsIgnoreCase("invalid") || e.getEntityType().isEmpty())) { |
109 | | - new BukkitRunnable() { |
110 | | - @Override |
111 | | - public void run() { |
112 | | - HPPlayer.getHPPlayer(e.getPlayer()).addXp(hp.getConfiguration().getMechanics().getInt("xp.crafting") * e.getHeadsCrafted()); |
113 | | - DataManager.addToTotal(e.getPlayer(), e.getEntityType(), "headspluscraft", e.getHeadsCrafted()); |
114 | | - } |
115 | | - }.runTaskAsynchronously(hp); |
116 | | - } |
117 | | - } |
118 | | - } |
119 | | - } |
120 | | - } catch (Exception ex) { |
121 | | - DebugPrint.createReport(ex, "Event (LeaderboardEvents)", false, null); |
122 | | - } |
| 119 | + }, EventPriority.MONITOR, new HeadsPlusEventExecutor(HeadCraftEvent.class, "HeadCraftEvent"), hp); |
123 | 120 | } |
124 | 121 | } |
0 commit comments