Skip to content
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

GH-200 Add option to exclude Creative mode players from combat #200

Merged
merged 4 commits into from
Oct 31, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ public static class Settings extends OkaeriConfig {
"# Setting this to true - admins cannot be tagged and will not tag other players on hit",
"# Setting this to false - admins can be tagged and can tag other players on hit"
})
public boolean excludeAdminFromCombat = false;
public boolean excludeOpFromCombat = false;

@Comment({"# If you want to exclude players in creative mode from combat, ",
"# Setting this to true - players in creative mode cannot be tagged and will not tag other players on hit",
"# Setting this to false - players in creative mode can be tag others"
})
public boolean excludeCreativeFromCombat = false;

@Comment("# Command blocking mode, available modes: WHITELIST, BLACKLIST")
public WhitelistBlacklistMode commandBlockingMode = WhitelistBlacklistMode.BLACKLIST;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -54,11 +55,11 @@ void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
UUID attackedUniqueId = attackedPlayerByPerson.getUniqueId();
UUID attackerUniqueId = attacker.getUniqueId();

if (attacker.isOp() && this.config.settings.excludeAdminFromCombat) {
if (this.cannotBeTagged(attacker)) {
return;
}

if (attackedPlayerByPerson.isOp() && this.config.settings.excludeAdminFromCombat) {
if (this.cannotBeTagged(attackedPlayerByPerson)) {
return;
}

Expand Down Expand Up @@ -92,6 +93,10 @@ void onEntityDamage(EntityDamageEvent event) {
return;
}

if (this.cannotBeTagged(player)) {
return;
}

Duration combatTime = this.config.settings.combatDuration;

UUID uuid = player.getUniqueId();
Expand Down Expand Up @@ -129,4 +134,15 @@ private boolean isPlayerInDisabledWorld(Player player) {
return this.config.settings.worldsToIgnore.contains(worldName);
}

private boolean cannotBeTagged(Player player) {
if (player.getGameMode().equals(GameMode.CREATIVE) && this.config.settings.excludeCreativeFromCombat) {
return true;
}

if (player.isOp() && this.config.settings.excludeOpFromCombat) {
return true;
}

return false;
}
}
Loading