|
1 | 1 | package com.eternalcode.combat.fight.pearl; |
2 | 2 |
|
3 | 3 | import com.eternalcode.combat.config.implementation.PluginConfig; |
| 4 | +import com.eternalcode.combat.fight.FightManager; |
4 | 5 | import com.eternalcode.combat.notification.NoticeService; |
5 | 6 | import com.eternalcode.combat.util.DurationUtil; |
6 | 7 | import java.time.Duration; |
|
13 | 14 | import org.bukkit.event.entity.EntityDamageByEntityEvent; |
14 | 15 | import org.bukkit.event.entity.EntityDamageEvent; |
15 | 16 | import org.bukkit.event.entity.ProjectileLaunchEvent; |
| 17 | +import org.bukkit.event.player.PlayerTeleportEvent; |
16 | 18 |
|
17 | 19 | public class PearlController implements Listener { |
18 | 20 |
|
19 | 21 | private final PluginConfig pluginConfig; |
20 | 22 | private final PearlService pearlService; |
21 | 23 | private final NoticeService noticeService; |
| 24 | + private final FightManager fightManager; |
22 | 25 |
|
23 | 26 | public PearlController( |
24 | 27 | PluginConfig pluginConfig, |
25 | | - PearlService pearlService, NoticeService noticeService |
| 28 | + PearlService pearlService, NoticeService noticeService, FightManager fightManager |
26 | 29 | ) { |
27 | 30 | this.pluginConfig = pluginConfig; |
28 | 31 | this.pearlService = pearlService; |
29 | 32 | this.noticeService = noticeService; |
| 33 | + this.fightManager = fightManager; |
30 | 34 | } |
31 | 35 |
|
32 | 36 | @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) |
@@ -79,4 +83,30 @@ public void onPearlDamage(EntityDamageByEntityEvent event) { |
79 | 83 | event.setDamage(0.0); |
80 | 84 | } |
81 | 85 |
|
| 86 | + |
| 87 | + @EventHandler(priority = EventPriority.HIGHEST) |
| 88 | + public void onPearlTeleport(PlayerTeleportEvent event) { |
| 89 | + if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) { |
| 90 | + return; |
| 91 | + } |
| 92 | + |
| 93 | + if (!this.pluginConfig.pearl.pearlThrowDisabledDuringCombat) { |
| 94 | + return; |
| 95 | + } |
| 96 | + |
| 97 | + Player player = event.getPlayer(); |
| 98 | + UUID playerId = player.getUniqueId(); |
| 99 | + |
| 100 | + if (!this.fightManager.isInCombat(playerId)) { |
| 101 | + return; |
| 102 | + } |
| 103 | + |
| 104 | + event.setCancelled(true); |
| 105 | + |
| 106 | + this.noticeService.create() |
| 107 | + .player(playerId) |
| 108 | + .notice(this.pluginConfig.pearl.pearlThrowBlockedDuringCombat) |
| 109 | + .send(); |
| 110 | + } |
| 111 | + |
82 | 112 | } |
0 commit comments