-
-
Notifications
You must be signed in to change notification settings - Fork 8
GH-304 Fix Folia enderpearl inflicting self damage on user #304
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
e8e866a
f2790bc
5c15805
b3f74a3
cf52708
01abfd4
a21075b
be21824
8d2ec8d
9a1246b
7e08a3a
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 |
|---|---|---|
|
|
@@ -2,6 +2,9 @@ | |
|
|
||
| public enum CancelTagReason { | ||
|
|
||
| TAGOUT | ||
| TAGOUT, | ||
| PERMISSION_BYPASS, | ||
| ADMIN, | ||
| CREATIVE_MODE, | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.eternalcode.combat.fight.controller; | ||
|
|
||
| import com.eternalcode.combat.config.implementation.PluginConfig; | ||
| import com.eternalcode.combat.fight.event.CancelTagReason; | ||
| import com.eternalcode.combat.fight.event.FightTagEvent; | ||
| import java.util.UUID; | ||
| import org.bukkit.Server; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.event.Listener; | ||
|
|
||
| public class FightBypassAdminController implements Listener { | ||
|
|
||
| private final Server server; | ||
| private final PluginConfig config; | ||
|
|
||
| public FightBypassAdminController(Server server, PluginConfig config) { | ||
| this.server = server; | ||
| this.config = config; | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
| void onFightTagEvent(FightTagEvent event) { | ||
| UUID uniqueId = event.getPlayer(); | ||
|
|
||
| Player player = this.server.getPlayer(uniqueId); | ||
| if (player == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (this.config.admin.excludeAdminsFromCombat && player.isOp()) { | ||
| event.setCancelReason(CancelTagReason.ADMIN); | ||
| event.setCancelled(true); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.eternalcode.combat.fight.controller; | ||
|
|
||
| import com.eternalcode.combat.config.implementation.PluginConfig; | ||
| import com.eternalcode.combat.fight.event.CancelTagReason; | ||
| import com.eternalcode.combat.fight.event.FightTagEvent; | ||
| import java.util.UUID; | ||
| import org.bukkit.GameMode; | ||
| import org.bukkit.Server; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.event.Listener; | ||
|
|
||
| public class FightBypassCreativeController implements Listener { | ||
|
|
||
| private final Server server; | ||
| private final PluginConfig config; | ||
|
|
||
| public FightBypassCreativeController(Server server, PluginConfig config) { | ||
| this.server = server; | ||
| this.config = config; | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
| void onFightTagEvent(FightTagEvent event) { | ||
| UUID uniqueId = event.getPlayer(); | ||
|
|
||
| Player player = this.server.getPlayer(uniqueId); | ||
| if (player == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (this.config.admin.excludeCreativePlayersFromCombat && player.getGameMode() == GameMode.CREATIVE) { | ||
| event.setCancelReason(CancelTagReason.CREATIVE_MODE); | ||
| event.setCancelled(true); | ||
| } | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.eternalcode.combat.fight.controller; | ||
|
|
||
| import com.eternalcode.combat.fight.event.CancelTagReason; | ||
| import com.eternalcode.combat.fight.event.FightTagEvent; | ||
| import java.util.UUID; | ||
| import org.bukkit.Server; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.event.Listener; | ||
|
|
||
| public class FightBypassPermissionController implements Listener { | ||
|
|
||
| private static final String BYPASS_PERMISSION = "eternalcombat.bypass"; | ||
|
|
||
| private final Server server; | ||
|
|
||
| public FightBypassPermissionController(Server server) { | ||
| this.server = server; | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
| void onFightTagEvent(FightTagEvent event) { | ||
| UUID uniqueId = event.getPlayer(); | ||
|
|
||
| Player player = this.server.getPlayer(uniqueId); | ||
| if (player == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (player.hasPermission(BYPASS_PERMISSION)) { | ||
| event.setCancelReason(CancelTagReason.PERMISSION_BYPASS); | ||
| event.setCancelled(true); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ | |
| import com.eternalcode.combat.config.implementation.PluginConfig; | ||
| import com.eternalcode.combat.fight.FightManager; | ||
| import com.eternalcode.combat.fight.event.CauseOfTag; | ||
| import org.bukkit.GameMode; | ||
| import org.bukkit.entity.EntityType; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.entity.Projectile; | ||
|
|
@@ -56,11 +55,11 @@ void onEntityDamageByEntity(EntityDamageByEntityEvent event) { | |
| return; | ||
| } | ||
|
|
||
| if (this.cannotBeTagged(attacker)) { | ||
| return; | ||
| } | ||
| UUID attackedUniqueId = attackedPlayerByPerson.getUniqueId(); | ||
| UUID attackerUniqueId = attacker.getUniqueId(); | ||
|
|
||
| if (this.cannotBeTagged(attackedPlayerByPerson)) { | ||
| // enderpearl on folia counts as attack on self | ||
| if (attackedUniqueId.equals(attackerUniqueId)) { | ||
| return; | ||
| } | ||
|
Comment on lines
+58
to
64
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. I assume this won't only be the cause for Ender Pearls, right? The if condition will also be met when, for example, a player shoots an arrow into the air and it hits them?
Member
Author
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. True, I couldn't figure out other scenarios. Thanks for the scenario! |
||
|
|
||
|
|
@@ -77,8 +76,6 @@ void onEntityDamageByEntity(EntityDamageByEntityEvent event) { | |
| } | ||
|
|
||
| Duration combatTime = this.config.settings.combatTimerDuration; | ||
| UUID attackedUniqueId = attackedPlayerByPerson.getUniqueId(); | ||
| UUID attackerUniqueId = attacker.getUniqueId(); | ||
|
|
||
| this.fightManager.tag(attackedUniqueId, combatTime, CauseOfTag.PLAYER, attackerUniqueId); | ||
| this.fightManager.tag(attackerUniqueId, combatTime, CauseOfTag.PLAYER, attackedUniqueId); | ||
|
|
@@ -99,15 +96,6 @@ void onEntityDamage(EntityDamageEvent event) { | |
| return; | ||
| } | ||
|
|
||
| if (this.cannotBeTagged(player)) { | ||
| return; | ||
| } | ||
|
|
||
| boolean hasBypass = player.hasPermission("eternalcombat.bypass"); | ||
| if (hasBypass) { | ||
| return; | ||
| } | ||
|
|
||
| Duration combatTime = this.config.settings.combatTimerDuration; | ||
| UUID uuid = player.getUniqueId(); | ||
|
|
||
|
|
@@ -145,18 +133,5 @@ private boolean isPlayerInDisabledWorld(Player player) { | |
| return this.config.settings.ignoredWorlds.contains(worldName); | ||
| } | ||
|
|
||
| private boolean cannotBeTagged(Player player) { | ||
| if (this.config.admin.excludeAdminsFromCombat && player.hasPermission("eternalcombat.bypass")) { | ||
| return true; | ||
| } | ||
|
|
||
| if (this.config.admin.excludeAdminsFromCombat && player.isOp()) { | ||
| return true; | ||
| } | ||
|
|
||
| return this.config.admin.excludeCreativePlayersFromCombat && player.getGameMode() == GameMode.CREATIVE; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.