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

Add entity placing and breaking flags (Fixes WORLDGUARD-4080) #417

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,6 +66,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
* Handle events that need to be processed by region protection.
Expand Down Expand Up @@ -300,6 +301,7 @@ public void onSpawnEntity(SpawnEntityEvent event) {

Location target = event.getTarget();
EntityType type = event.getEffectiveType();
com.sk89q.worldedit.world.entity.EntityType weType = BukkitAdapter.adapt(type);

RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
RegionAssociable associable = createRegionAssociable(event.getCause());
Expand All @@ -312,7 +314,7 @@ public void onSpawnEntity(SpawnEntityEvent event) {
canSpawn = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.PLACE_VEHICLE));
what = "place vehicles";

/* Item pickup */
/* Item drops */
} else if (event.getEntity() instanceof Item) {
canSpawn = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.ITEM_DROP));
what = "drop items";
Expand All @@ -329,11 +331,13 @@ public void onSpawnEntity(SpawnEntityEvent event) {
/* Everything else */
} else {
canSpawn = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event));
what = "place " + type.name().replace('_', ' ').toLowerCase() + "s";
}

if (event.getEntity() instanceof Item) {
what = "drop items";
} else {
what = "place things";
if (!canSpawn) {
Set<com.sk89q.worldedit.world.entity.EntityType> entityTypes = query.queryValue(BukkitAdapter.adapt(target), associable, Flags.PLACE_ENTITY);
if (entityTypes != null && weType != null && entityTypes.contains(weType)) {
canSpawn = true;
}
}

Expand All @@ -351,6 +355,7 @@ public void onDestroyEntity(DestroyEntityEvent event) {

Location target = event.getTarget();
EntityType type = event.getEntity().getType();
com.sk89q.worldedit.world.entity.EntityType weType = BukkitAdapter.adapt(type);
RegionAssociable associable = createRegionAssociable(event.getCause());

RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
Expand All @@ -370,7 +375,14 @@ public void onDestroyEntity(DestroyEntityEvent event) {
/* Everything else */
} else {
canDestroy = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event));
what = "break things";
what = "break " + type.name().replace('_', ' ').toLowerCase() + "s";
}

if (!canDestroy) {
Set<com.sk89q.worldedit.world.entity.EntityType> entityTypes = query.queryValue(BukkitAdapter.adapt(target), associable, Flags.DESTROY_ENTITY);
if (entityTypes != null && weType != null && entityTypes.contains(weType)) {
canDestroy = true;
}
}

if (!canDestroy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public final class Flags {
public static final StateFlag ITEM_DROP = register(new StateFlag("item-drop", true)); // Intentionally true
public static final StateFlag EXP_DROPS = register(new StateFlag("exp-drops", true)); // Intentionally true

// These flags are similar to the ones above (used in tandem with BUILD),
// but they aren't checked at all if the player can build. Only if the
// player can't build thy are checked to see if the type is allowed
public static final SetFlag<EntityType> PLACE_ENTITY = register(new SetFlag<>("entity-place", new RegistryFlag<>(null, EntityType.REGISTRY)));
public static final SetFlag<EntityType> DESTROY_ENTITY = register(new SetFlag<>("entity-destroy", new RegistryFlag<>(null, EntityType.REGISTRY)));

// These flags adjust behavior and are not checked in tandem with the
// BUILD flag so they need to be TRUE for their defaults.

Expand Down