Fix TNT explosions for sponge

This commit is contained in:
Jesse Boyd 2016-03-27 19:10:08 +11:00
parent 357400c5ac
commit 3fb6ccbbb6

View File

@ -24,13 +24,20 @@ import com.plotsquared.listener.PlotListener;
import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer; import com.plotsquared.sponge.object.SpongePlayer;
import com.plotsquared.sponge.util.SpongeUtil; import com.plotsquared.sponge.util.SpongeUtil;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;
import org.spongepowered.api.block.BlockSnapshot; import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.block.BlockState; import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.data.Transaction; import org.spongepowered.api.data.Transaction;
import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes; import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.entity.explosive.Explosive; import org.spongepowered.api.entity.explosive.Explosive;
import org.spongepowered.api.entity.explosive.PrimedTNT;
import org.spongepowered.api.entity.living.Ambient; import org.spongepowered.api.entity.living.Ambient;
import org.spongepowered.api.entity.living.Living; import org.spongepowered.api.entity.living.Living;
import org.spongepowered.api.entity.living.animal.Animal; import org.spongepowered.api.entity.living.animal.Animal;
@ -53,16 +60,6 @@ import org.spongepowered.api.event.world.ExplosionEvent.Detonate;
import org.spongepowered.api.text.Text; import org.spongepowered.api.text.Text;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;
public class MainListener { public class MainListener {
/* /*
@ -185,12 +182,9 @@ public class MainListener {
} }
} }
@Listener
public void onSpawnEntity(SpawnEntityEvent event) throws Exception { public void onSpawnEntity(SpawnEntityEvent event) throws Exception {
World world = event.getTargetWorld(); World world = event.getTargetWorld();
PlotArea plotworld = PS.get().getPlotAreaByString(world.getName());
if (plotworld == null) {
return;
}
event.filterEntities((Predicate<Entity>) entity -> { event.filterEntities((Predicate<Entity>) entity -> {
if (entity instanceof Player) { if (entity instanceof Player) {
return true; return true;
@ -213,7 +207,7 @@ public class MainListener {
} }
int[] mobs = null; int[] mobs = null;
if (entity instanceof Living) { if (entity instanceof Living) {
if (!plotworld.MOB_SPAWNING) { if (!loc.getPlotArea().MOB_SPAWNING) {
return false; return false;
} }
Flag mobCap = FlagManager.getPlotFlagRaw(plot, "mob-cap"); Flag mobCap = FlagManager.getPlotFlagRaw(plot, "mob-cap");
@ -241,8 +235,7 @@ public class MainListener {
return false; return false;
} }
} }
} } else if (entity instanceof Monster) {
if (entity instanceof Monster) {
Flag monsterFlag = FlagManager.getPlotFlagRaw(plot, "hostile-cap"); Flag monsterFlag = FlagManager.getPlotFlagRaw(plot, "hostile-cap");
if (monsterFlag != null) { if (monsterFlag != null) {
int cap = (Integer) monsterFlag.getValue(); int cap = (Integer) monsterFlag.getValue();
@ -258,8 +251,7 @@ public class MainListener {
} }
} }
return true; return true;
} } else if ((entity instanceof Minecart) || (entity instanceof Boat)) {
if ((entity instanceof Minecart) || (entity instanceof Boat)) {
Flag vehicleFlag = FlagManager.getPlotFlagRaw(plot, "vehicle-cap"); Flag vehicleFlag = FlagManager.getPlotFlagRaw(plot, "vehicle-cap");
if (vehicleFlag != null) { if (vehicleFlag != null) {
int cap = (Integer) vehicleFlag.getValue(); int cap = (Integer) vehicleFlag.getValue();
@ -285,9 +277,8 @@ public class MainListener {
return false; return false;
} }
} }
if (entity instanceof PrimedTNT) { if (entity instanceof Explosive) {
Vector3d pos = entity.getLocation().getPosition(); entity.setCreator(plot.owner);
entity.setRotation(new Vector3d(MathMan.roundInt(pos.getX()), MathMan.roundInt(pos.getY()), MathMan.roundInt(pos.getZ())));
} }
return true; return true;
}); });
@ -386,23 +377,27 @@ public class MainListener {
} }
Optional<Explosive> source = event.getExplosion().getSourceExplosive(); Optional<Explosive> source = event.getExplosion().getSourceExplosive();
if (!source.isPresent()) { if (!source.isPresent()) {
event.setCancelled(true); event.filterAll();
return; return;
} }
Explosive tnt = source.get(); Explosive tnt = source.get();
Location origin = SpongeUtil.getLocation(worldname, tnt.getRotation()); UUID creator = tnt.getCreator().orElse(null);
Plot originPlot = origin.getPlot();
Location current = SpongeUtil.getLocation(tnt); Location current = SpongeUtil.getLocation(tnt);
Plot currentPlot = current.getPlot(); Plot currentPlot = current.getPlot();
if (!Objects.equals(originPlot, currentPlot)) { if (currentPlot == null) {
event.setCancelled(true); if (current.isPlotArea()) {
event.filterAll();
}
return; return;
} }
if (originPlot == null && current.getPlotAbs() == null) { if (creator != null) {
return; if (!currentPlot.isAdded(creator)) {
event.filterAll();
return;
}
} }
if (!FlagManager.isPlotFlagTrue(currentPlot, "explosion")) { if (currentPlot == null || !FlagManager.isPlotFlagTrue(currentPlot, "explosion")) {
event.setCancelled(true); event.filterAll();
return; return;
} }
event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() { event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() {