Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eternalcombat-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ bukkit {

tasks {
runServer {
minecraftVersion("1.21.10")
minecraftVersion("1.21.11")
downloadPlugins.modrinth("WorldEdit", Versions.WORLDEDIT)
downloadPlugins.modrinth("PacketEvents", "${Versions.PACKETEVENTS}+spigot")
downloadPlugins.modrinth("WorldGuard", Versions.WORLDGUARD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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 pearlTeleportBlockedDuringCombat notice in FightPearlSettings as suggested in my other comment.

        event.setCancelled(true);

        this.noticeService.create()
            .player(event.getPlayer())
            .notice(this.settings.pearlTeleportBlockedDuringCombat)
            .send();

Copy link
Member

Choose a reason for hiding this comment

The 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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 FightPearlController to inform the player why their teleport was cancelled.

Suggested change
public boolean preventPearlStasis = false;
public boolean preventPearlStasis = false;
@Comment("# Message sent when a player's ender pearl teleport is cancelled during combat")
public Notice pearlTeleportBlockedDuringCombat = BukkitNotice.builder()
.chat("<red>You cannot teleport with an ender pearl while in combat!>")
.build();


@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"
Expand All @@ -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();
}