-
-
Notifications
You must be signed in to change notification settings - Fork 13
GH-394 Add combat sign editing blocker #394
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
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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.eternalcode.combat.config.implementation; | ||
|
|
||
| import eu.okaeri.configs.OkaeriConfig; | ||
| import eu.okaeri.configs.annotation.Comment; | ||
|
|
||
| public class SignEditingSettings extends OkaeriConfig { | ||
|
|
||
| @Comment({ | ||
| "# Prevent players from editing signs during combat.", | ||
| "# Disabled by default; created for sign traps where sign editing blocks ender pearl throws.", | ||
| "# Powstalo na potrzebe trapow z tabliczkami." | ||
| }) | ||
| public boolean disableSignEditingDuringCombat = false; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||||||
| package com.eternalcode.combat.fight.blocker; | ||||||||||
|
|
||||||||||
| import com.eternalcode.combat.config.implementation.PluginConfig; | ||||||||||
| import com.eternalcode.combat.fight.FightManager; | ||||||||||
| import java.util.UUID; | ||||||||||
| import org.bukkit.Material; | ||||||||||
| import org.bukkit.block.Block; | ||||||||||
| import org.bukkit.entity.Player; | ||||||||||
| import org.bukkit.event.EventHandler; | ||||||||||
| import org.bukkit.event.Event.Result; | ||||||||||
| import org.bukkit.event.Listener; | ||||||||||
| import org.bukkit.event.block.Action; | ||||||||||
| import org.bukkit.event.player.PlayerInteractEvent; | ||||||||||
| import org.bukkit.inventory.ItemStack; | ||||||||||
|
|
||||||||||
| public class SignEditingBlocker implements Listener { | ||||||||||
|
|
||||||||||
| private final FightManager fightManager; | ||||||||||
| private final PluginConfig config; | ||||||||||
|
|
||||||||||
| public SignEditingBlocker(FightManager fightManager, PluginConfig config) { | ||||||||||
| this.fightManager = fightManager; | ||||||||||
| this.config = config; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @EventHandler | ||||||||||
| void onInteract(PlayerInteractEvent event) { | ||||||||||
|
Comment on lines
+26
to
+27
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. To prevent potential bypasses of region protection or other plugins that restrict Ender Pearl usage (e.g., WorldGuard region flags banning pearls), it is highly recommended to run this event handler at a lower priority like
Suggested change
|
||||||||||
| if (!this.config.signEditing.disableSignEditingDuringCombat) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| Block clickedBlock = event.getClickedBlock(); | ||||||||||
| if (clickedBlock == null || !isSign(clickedBlock.getType())) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| Player player = event.getPlayer(); | ||||||||||
| UUID uniqueId = player.getUniqueId(); | ||||||||||
|
|
||||||||||
| if (!this.fightManager.isInCombat(uniqueId)) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| event.setUseInteractedBlock(Result.DENY); | ||||||||||
|
|
||||||||||
| ItemStack item = event.getItem(); | ||||||||||
| if (item != null && isEnderPearl(item.getType())) { | ||||||||||
| event.setUseItemInHand(Result.ALLOW); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static boolean isSign(Material material) { | ||||||||||
| return material.name().endsWith("_SIGN"); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static boolean isEnderPearl(Material material) { | ||||||||||
| return material == Material.ENDER_PEARL; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.eternalcode.combat.config.implementation; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class SignEditingSettingsTest { | ||
|
|
||
| @Test | ||
| void shouldDisableSignEditingBlockerByDefault() { | ||
| SignEditingSettings signEditingSettings = new SignEditingSettings(); | ||
|
|
||
| assertFalse(signEditingSettings.disableSignEditingDuringCombat); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.eternalcode.combat.fight.blocker; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import org.bukkit.Material; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class SignEditingBlockerTest { | ||
|
|
||
| @Test | ||
| void shouldRecognizeStandingSignMaterials() { | ||
| assertTrue(SignEditingBlocker.isSign(Material.OAK_SIGN)); | ||
| assertTrue(SignEditingBlocker.isSign(Material.CRIMSON_SIGN)); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldRecognizeWallSignMaterials() { | ||
| assertTrue(SignEditingBlocker.isSign(Material.OAK_WALL_SIGN)); | ||
| assertTrue(SignEditingBlocker.isSign(Material.WARPED_WALL_SIGN)); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldIgnoreNonSignMaterials() { | ||
| assertFalse(SignEditingBlocker.isSign(Material.CHEST)); | ||
| assertFalse(SignEditingBlocker.isSign(Material.ENDER_PEARL)); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldRecognizeEnderPearlMaterial() { | ||
| assertTrue(SignEditingBlocker.isEnderPearl(Material.ENDER_PEARL)); | ||
| assertFalse(SignEditingBlocker.isEnderPearl(Material.OAK_SIGN)); | ||
| } | ||
| } |
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.
Import
EventPriorityto support setting a lower priority on the event handler.