Permalink
Browse files

Prevent players and complex parts being pasted in schematics.

  • Loading branch information...
me4502 committed Jan 2, 2018
1 parent 6fc1449 commit 50f60da69fefc325c9b6186ff03f8fd48ab1ab55
@@ -24,6 +24,7 @@
import org.bukkit.entity.Ambient;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Boat;
import org.bukkit.entity.ComplexEntityPart;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.FallingBlock;
@@ -34,6 +35,7 @@
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable;
@@ -143,4 +145,9 @@ public boolean isTagged() {
public boolean isArmorStand() {
return entity.getType() == armorStandType;
}
@Override
public boolean isPasteable() {
return !(entity instanceof Player || entity instanceof ComplexEntityPart);
}
}
@@ -154,4 +154,11 @@
* @return true if an armor stand
*/
boolean isArmorStand();
/**
* Test whether this entity can be pasted.
*
* @return true if pasteable
*/
boolean isPasteable();
}
@@ -22,6 +22,7 @@
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.CombinedRegionFunction;
import com.sk89q.worldedit.function.RegionFunction;
@@ -36,6 +37,7 @@
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.regions.Region;
import java.util.Iterator;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
@@ -255,6 +257,15 @@ public Operation resume(RunContext run) throws WorldEditException {
ExtentEntityCopy entityCopy = new ExtentEntityCopy(from, destination, to, currentTransform);
entityCopy.setRemoving(removingEntities);
List<? extends Entity> entities = source.getEntities(region);
// Switch to entities.removeIf after Java 8 cutoff.
Iterator<? extends Entity> entityIterator = entities.iterator();
while (entityIterator.hasNext()) {
EntityType type = entityIterator.next().getFacet(EntityType.class);
if (type != null && !type.isPasteable()) {
entityIterator.remove();
}
}
EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy);
return new DelegateOperation(this, new OperationQueue(blockVisitor, entityVisitor));
} else {
@@ -25,6 +25,7 @@
import net.minecraft.entity.IMerchant;
import net.minecraft.entity.INpc;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.MultiPartEntityPart;
import net.minecraft.entity.item.EntityArmorStand;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.entity.item.EntityEnderEye;
@@ -40,6 +41,7 @@
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -141,4 +143,9 @@ public boolean isTagged() {
public boolean isArmorStand() {
return entity instanceof EntityArmorStand;
}
@Override
public boolean isPasteable() {
return !(entity instanceof EntityPlayerMP || entity instanceof MultiPartEntityPart);
}
}
@@ -30,7 +30,9 @@
import org.spongepowered.api.entity.hanging.Painting;
import org.spongepowered.api.entity.living.*;
import org.spongepowered.api.entity.living.animal.Animal;
import org.spongepowered.api.entity.living.complex.ComplexLivingPart;
import org.spongepowered.api.entity.living.golem.Golem;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.entity.projectile.Projectile;
import org.spongepowered.api.entity.vehicle.Boat;
import org.spongepowered.api.entity.vehicle.minecart.Minecart;
@@ -139,4 +141,9 @@ public boolean isTagged() {
public boolean isArmorStand() {
return entity instanceof ArmorStand;
}
@Override
public boolean isPasteable() {
return !(entity instanceof Player || entity instanceof ComplexLivingPart);
}
}

0 comments on commit 50f60da

Please sign in to comment.