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

entity-armor-stand-destroy flag is added. #1913

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,7 @@
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.Dispenser;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Item;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Mob;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.entity.*;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please do not use wildcard imports

import org.bukkit.entity.minecart.HopperMinecart;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
Expand Down Expand Up @@ -762,6 +749,8 @@ public void onHangingBreak(HangingBreakEvent event) {
destroyEntityEvent.getRelevantFlags().add(Flags.ENTITY_ITEM_FRAME_DESTROY);
} else if (event.getEntity() instanceof Painting) {
destroyEntityEvent.getRelevantFlags().add(Flags.ENTITY_PAINTING_DESTROY);
} else if (event.getEntity() instanceof ArmorStand) {
destroyEntityEvent.getRelevantFlags().add(Flags.ENTITY_ARMOR_STAND_DESTROY);
}
Events.fireToCancel(event, destroyEntityEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
event.setCancelled(true);
return;
}
} else if (defender instanceof ArmorStand && !(attacker instanceof Player)) {
if (wcfg.blockEntityArmorStandDestroy) {
} else if (defender instanceof ArmorStand) {
if (checkArmorStandProtection(attacker, (ArmorStand) defender)) {
event.setCancelled(true);
return;
}
Expand Down Expand Up @@ -334,9 +334,10 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
event.setCancelled(true);
return;
}
} else if (defender instanceof ArmorStand && Entities.isNonPlayerCreature(attacker)) {
if (wcfg.blockEntityArmorStandDestroy) {
} else if (defender instanceof ArmorStand) {
if (checkArmorStandProtection(attacker, (ArmorStand) defender)) {
event.setCancelled(true);
return;
}
}

Expand Down Expand Up @@ -851,4 +852,27 @@ private boolean checkItemFrameProtection(Entity attacker, ItemFrame defender) {
return false;
}

/**
* Checks regions and config settings to protect items from being knocked
* out of armor stand.
* @param attacker attacking entity
* @param defender armor stand being damaged
* @return true if the event should be cancelled
*/
private boolean checkArmorStandProtection(Entity attacker, ArmorStand defender) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can generalize the checkItemFrameProctection method and pass a flag to that method.

That way you don't need double methods.

World world = defender.getWorld();
WorldConfiguration wcfg = getWorldConfig(world);
if (wcfg.useRegions) {
// bukkit throws this event when a player attempts to remove an item from a frame
if (!(attacker instanceof Player)) {
if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(defender.getLocation()), (RegionAssociable) null, Flags.ENTITY_ARMOR_STAND_DESTROY))) {
return true;
}
}
}
if (wcfg.blockEntityArmorStandDestroy && !(attacker instanceof Player)) {
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import org.bukkit.World;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.*;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please do not use wildcard imports

import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
Expand Down Expand Up @@ -90,6 +83,11 @@ public void onHangingBreak(HangingBreakEvent event) {
|| (wcfg.useRegions
&& !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(hanging.getLocation()), (RegionAssociable) null, Flags.ENTITY_ITEM_FRAME_DESTROY))))) {
event.setCancelled(true);
} else if (hanging instanceof ArmorStand
&& (wcfg.blockEntityArmorStandDestroy
|| (wcfg.useRegions
&& !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(hanging.getLocation()), (RegionAssociable) null, Flags.ENTITY_ARMOR_STAND_DESTROY))))) {
event.setCancelled(true);
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public final class Flags {
public static final StateFlag RAVAGER_RAVAGE = register(new StateFlag("ravager-grief", true));
public static final StateFlag ENTITY_PAINTING_DESTROY = register(new StateFlag("entity-painting-destroy", true));
public static final StateFlag ENTITY_ITEM_FRAME_DESTROY = register(new StateFlag("entity-item-frame-destroy", true));
public static final StateFlag ENTITY_ARMOR_STAND_DESTROY = register(new StateFlag("entity-armor-stand-destroy", true));

// mob spawning related
public static final StateFlag MOB_SPAWNING = register(new StateFlag("mob-spawning", true));
Expand Down