Treat inventory minecarts under chest-access.

Fixes WORLDGUARD-3585.
This commit is contained in:
wizjany 2019-05-05 16:14:35 -04:00
parent c57dd20f24
commit 5180673878
2 changed files with 15 additions and 7 deletions

View File

@ -60,6 +60,7 @@
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Item;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.event.Event.Result;
@ -415,20 +416,24 @@ public void onUseEntity(UseEntityEvent event) {
String what;
/* Hostile / ambient mob override */
final EntityType type = event.getEntity().getType();
if (Entities.isHostile(event.getEntity()) || Entities.isAmbient(event.getEntity())
|| Entities.isNPC(event.getEntity()) || Entities.isVehicle(event.getEntity().getType())) {
|| Entities.isNPC(event.getEntity())) {
canUse = event.getRelevantFlags().isEmpty() || query.queryState(BukkitAdapter.adapt(target), associable, combine(event)) != State.DENY;
what = "use that";
/* Paintings, item frames, etc. */
} else if (Entities.isConsideredBuildingIfUsed(event.getEntity())) {
if (event.getEntity().getType() == EntityType.ITEM_FRAME && event.getCause().getFirstPlayer() != null
&& ((org.bukkit.entity.ItemFrame) event.getEntity()).getItem().getType() != Material.AIR) {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.ITEM_FRAME_ROTATE));
if (type == EntityType.ITEM_FRAME && event.getCause().getFirstPlayer() != null
&& ((ItemFrame) event.getEntity()).getItem().getType() != Material.AIR) {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.ITEM_FRAME_ROTATE));
what = "change that";
} else if (Entities.isMinecart(type)) {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.CHEST_ACCESS));
what = "open that";
} else {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event));
what = "change that";
}
what = "change that";
/* Ridden on use */
} else if (Entities.isRiddenOnUse(event.getEntity())) {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.RIDE, Flags.INTERACT));

View File

@ -29,6 +29,7 @@
import org.bukkit.entity.Flying;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Monster;
import org.bukkit.entity.NPC;
import org.bukkit.entity.Player;
@ -42,6 +43,7 @@
import org.bukkit.entity.Vehicle;
import org.bukkit.entity.WaterMob;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.projectiles.ProjectileSource;
import javax.annotation.Nullable;
@ -206,7 +208,8 @@ public static boolean isNonPlayerCreature(Entity entity) {
public static boolean isConsideredBuildingIfUsed(Entity entity) {
return entity instanceof Hanging
|| entity instanceof ArmorStand
|| entity instanceof EnderCrystal;
|| entity instanceof EnderCrystal
|| entity instanceof Minecart && entity instanceof InventoryHolder;
}
public static boolean isPotionArrow(Entity entity) {