-
-
Notifications
You must be signed in to change notification settings - Fork 9
GH-331 Add pearl stasis prevention feature #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| import org.bukkit.event.entity.EntityDamageByEntityEvent; | ||
| import org.bukkit.event.entity.EntityDamageEvent; | ||
| import org.bukkit.event.entity.ProjectileLaunchEvent; | ||
| import org.bukkit.event.player.PlayerTeleportEvent; | ||
| import org.bukkit.inventory.ItemStack; | ||
|
|
||
| public class FightPearlController implements Listener { | ||
|
|
@@ -80,6 +81,31 @@ public void onPearlDamage(EntityDamageByEntityEvent event) { | |
| event.setDamage(0.0); | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.HIGHEST) | ||
| public void onPearlStasisTeleport(PlayerTeleportEvent event) { | ||
| if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) { | ||
| return; | ||
| } | ||
|
|
||
| if (!this.settings.preventPearlStasis) { | ||
| return; | ||
| } | ||
|
|
||
| Player player = event.getPlayer(); | ||
| UUID playerId = player.getUniqueId(); | ||
|
|
||
| if (!this.fightManager.isInCombat(playerId)) { | ||
| return; | ||
| } | ||
|
|
||
| event.setCancelled(true); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are blocking not only stasis teleports but also using normal pearls - ex. teleporting closer to the opponent during fight |
||
|
|
||
| this.noticeService.create() | ||
| .player(playerId) | ||
| .notice(this.settings.pearlTeleportBlockedDuringCombat) | ||
| .send(); | ||
| } | ||
|
|
||
| private void handlePearlCooldown(ProjectileLaunchEvent event, Player player, UUID playerId) { | ||
| if (this.settings.pearlThrowDelay.isZero()) { | ||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,12 @@ public class FightPearlSettings extends OkaeriConfig { | |||||||||||||||
| @Comment("# Set true, If you want add cooldown to pearls") | ||||||||||||||||
| public boolean pearlCooldownEnabled = false; | ||||||||||||||||
|
|
||||||||||||||||
| @Comment({ | ||||||||||||||||
| "# Prevent players from using ender pearl stasis to avoid combat.", | ||||||||||||||||
| "# This setting prevents the player from teleporting with a statis pearl during combat." | ||||||||||||||||
| }) | ||||||||||||||||
| public boolean preventPearlStasis = false; | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good practice to provide feedback to the player when an action is blocked. Consider adding a configurable message for when pearl stasis is prevented. This message can then be used in
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| @Comment({ | ||||||||||||||||
| "# Block throwing pearls with delay?", | ||||||||||||||||
| "# If you set this to for example 3s, player will have to wait 3 seconds before throwing another pearl" | ||||||||||||||||
|
|
@@ -37,4 +43,8 @@ public class FightPearlSettings extends OkaeriConfig { | |||||||||||||||
| .chat("<red>You must wait {TIME} before next throw!") | ||||||||||||||||
| .build(); | ||||||||||||||||
|
|
||||||||||||||||
| @Comment("# Message sent when player tries to teleport with ender pearl, but are disabled") | ||||||||||||||||
| public Notice pearlTeleportBlockedDuringCombat = BukkitNotice.builder() | ||||||||||||||||
| .chat("<red>Teleporting through ender pearls is not allowed during combat!") | ||||||||||||||||
| .build(); | ||||||||||||||||
| } | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve user experience, you should notify the player why their teleportation was cancelled. This provides clear feedback and avoids confusion. This change assumes you've added a corresponding
pearlTeleportBlockedDuringCombatnotice inFightPearlSettingsas suggested in my other comment.