-
-
Notifications
You must be signed in to change notification settings - Fork 551
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
base: master
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -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; | ||
} | ||
|
@@ -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; | ||
} | ||
} | ||
|
||
|
@@ -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) { | ||
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. You can generalize the 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 |
---|---|---|
|
@@ -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.*; | ||
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. Please do not use wildcard imports |
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.hanging.HangingBreakByEntityEvent; | ||
|
@@ -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 { | ||
|
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.
Please do not use wildcard imports