public static Cause generateCauseFor(DamageSource damageSource) {
   if (damageSource instanceof EntityDamageSourceIndirect) {
     net.minecraft.entity.Entity source = damageSource.getEntity();
     Optional<User> owner =
         ((IMixinEntity) source).getTrackedPlayer(NbtDataUtil.SPONGE_ENTITY_CREATOR);
     if (owner.isPresent()) {
       return Cause.of(
           NamedCause.of(DamageEntityEvent.SOURCE, damageSource),
           NamedCause.of(DamageEntityEvent.CREATOR, owner.get()));
     } else {
       return Cause.of(NamedCause.of(DamageEntityEvent.SOURCE, damageSource));
     }
   } else if (damageSource instanceof EntityDamageSource) {
     net.minecraft.entity.Entity source = damageSource.getEntity();
     Optional<User> owner =
         ((IMixinEntity) source).getTrackedPlayer(NbtDataUtil.SPONGE_ENTITY_CREATOR);
     Optional<User> notifier =
         ((IMixinEntity) source).getTrackedPlayer(NbtDataUtil.SPONGE_ENTITY_NOTIFIER);
     List<Object> causeObjects = new ArrayList<>();
     causeObjects.add(NamedCause.of(DamageEntityEvent.SOURCE, damageSource));
     if (notifier.isPresent()) {
       causeObjects.add(NamedCause.of(DamageEntityEvent.NOTIFIER, notifier.get()));
     }
     if (owner.isPresent()) {
       causeObjects.add(NamedCause.of(DamageEntityEvent.CREATOR, owner.get()));
     }
     return Cause.of(causeObjects.toArray());
   } else if (damageSource instanceof BlockDamageSource) {
     List<Object> causeObjects = new ArrayList<>();
     Location<org.spongepowered.api.world.World> location =
         ((BlockDamageSource) damageSource).getLocation();
     BlockPos blockPos = VecHelper.toBlockPos(location);
     Optional<User> owner =
         ((IMixinChunk)
                 ((net.minecraft.world.World) location.getExtent())
                     .getChunkFromBlockCoords(blockPos))
             .getBlockOwner(blockPos);
     Optional<User> notifier =
         ((IMixinChunk)
                 ((net.minecraft.world.World) location.getExtent())
                     .getChunkFromBlockCoords(blockPos))
             .getBlockNotifier(blockPos);
     causeObjects.add(NamedCause.of(DamageEntityEvent.SOURCE, damageSource));
     if (notifier.isPresent()) {
       causeObjects.add(NamedCause.of(DamageEntityEvent.NOTIFIER, notifier.get()));
     }
     if (owner.isPresent()) {
       causeObjects.add(NamedCause.of(DamageEntityEvent.CREATOR, owner.get()));
     }
     return Cause.of(causeObjects.toArray());
   } else {
     return Cause.of(NamedCause.of(DamageEntityEvent.SOURCE, damageSource));
   }
 }
Example #2
0
 @Override
 public SpongeBlockSnapshot createSpongeBlockSnapshot(
     IBlockState state, IBlockState extended, BlockPos pos, int updateFlag) {
   this.builder.reset();
   Location<World> location = new Location<>((World) this, VecHelper.toVector(pos));
   this.builder
       .blockState((BlockState) state)
       .extendedState((BlockState) extended)
       .worldId(location.getExtent().getUniqueId())
       .position(location.getBlockPosition());
   Optional<UUID> creator = getCreator(pos.getX(), pos.getY(), pos.getZ());
   Optional<UUID> notifier = getNotifier(pos.getX(), pos.getY(), pos.getZ());
   if (creator.isPresent()) {
     this.builder.creator(creator.get());
   }
   if (notifier.isPresent()) {
     this.builder.notifier(notifier.get());
   }
   if (state.getBlock() instanceof ITileEntityProvider) {
     net.minecraft.tileentity.TileEntity te = getTileEntity(pos);
     if (te != null) {
       TileEntity tile = (TileEntity) te;
       for (DataManipulator<?, ?> manipulator : tile.getContainers()) {
         this.builder.add(manipulator);
       }
       NBTTagCompound nbt = new NBTTagCompound();
       te.writeToNBT(nbt);
       this.builder.unsafeNbt(nbt);
     }
   }
   return new SpongeBlockSnapshot(this.builder, updateFlag);
 }
  public static ChangeBlockEvent.Break callBlockBreakEvent(Event event) {
    if (!(event instanceof ChangeBlockEvent.Break)) {
      throw new IllegalArgumentException("Event is not a valid ChangeBlockEventBreak");
    }

    ChangeBlockEvent.Break spongeEvent = (ChangeBlockEvent.Break) event;

    if (spongeEvent.getCause().first(Player.class).isPresent()) {
      Player player = spongeEvent.getCause().first(Player.class).get();
      Iterator<Transaction<BlockSnapshot>> iterator = spongeEvent.getTransactions().iterator();
      while (iterator.hasNext()) {
        Transaction<BlockSnapshot> transaction = iterator.next();
        Location<World> location = transaction.getOriginal().getLocation().get();
        net.minecraft.world.World world = (net.minecraft.world.World) location.getExtent();
        BlockPos pos =
            new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());

        StaticMixinHelper.breakEventExtendedState =
            (IBlockState) transaction.getOriginal().getExtendedState();
        BlockEvent.BreakEvent forgeEvent =
            new BlockEvent.BreakEvent(
                world,
                pos,
                (IBlockState) transaction.getOriginal().getState(),
                (EntityPlayer) player);
        StaticMixinHelper.breakEventExtendedState = null;

        ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
        if (forgeEvent.isCanceled()) {
          transaction.setValid(false);
        }
      }
    }
    return spongeEvent;
  }
  public void spawnEntity(Location<World> location, Vector3d velocity, CommandSource src) {
    Extent extent = location.getExtent();
    Optional<Entity> optional = extent.createEntity(EntityTypes.FIREBALL, location.getPosition());

    Entity fireball = optional.get();
    fireball.offer(Keys.VELOCITY, velocity);
    extent.spawnEntity(fireball, Cause.of(src));
  }
Example #5
0
 public List<Entity> getEntities() {
   List<Entity> entities = new ArrayList<Entity>();
   for (Location<World> loc : POS2) {
     Location<World> pos2 = loc.getRelative(Direction.UP);
     for (Entity entity : loc.getExtent().getEntities()) {
       if (entity.getLocation().getBlockPosition().equals(pos2.getBlockPosition())) {
         entities.add(entity);
       }
     }
   }
   return entities;
 }
Example #6
0
 @SuppressWarnings("unchecked")
 private void animation3() {
   for (Location<World> loc : POS2) {
     World world = loc.getExtent();
     Location<World>[] pos = mix(loc, POS1);
     for (Location<World> pos5 : pos) {
       Lightning light =
           (Lightning) world.createEntity(EntityTypes.LIGHTNING, pos5.getBlockPosition()).get();
       light.setEffect(true);
       world.spawnEntity(light, Causes.TELEPORT_LIGHTNING.build());
     }
   }
 }
  // Block events
  public static BlockEvent createBlockEvent(Event event) {
    if (!(event instanceof ChangeBlockEvent)) {
      throw new IllegalArgumentException("Event is not a valid ChangeBlockEvent.");
    }

    ChangeBlockEvent spongeEvent = (ChangeBlockEvent) event;
    Location<World> location =
        spongeEvent.getTransactions().get(0).getOriginal().getLocation().get();
    net.minecraft.world.World world = (net.minecraft.world.World) location.getExtent();
    BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    BlockEvent forgeEvent = new BlockEvent(world, pos, world.getBlockState(pos));
    return forgeEvent;
  }
  @Override
  public void accept(T t) {
    final Location<World> location = t.getLocation();

    final Explosion.Builder builder = Explosion.builder();
    builder.location(location);
    builder.canCauseFire(this.canCauseFire);
    builder.radius((float) this.radius);
    builder.shouldBreakBlocks(this.shouldBreakBlocks);
    builder.shouldDamageEntities(this.shouldDamageEntities);
    builder.shouldPlaySmoke(this.shouldPlaySmoke);

    location.getExtent().triggerExplosion(builder.build(), Cause.source(t).build());
  }
Example #9
0
 @Subscribe
 public void onFloraGrow(FloraGrowEvent event) {
   org.spongepowered.api.world.Location block = event.getLocation();
   Extent extent = block.getExtent();
   if (extent instanceof World) {
     World world = (World) extent;
     final String worldname = world.getName();
     if (!PS.get().isPlotWorld(worldname)) {
       return;
     }
     if (MainUtil.isPlotRoad(SpongeUtil.getLocation(worldname, block))) {
       event.setCancelled(true);
     }
   }
 }
 @SuppressWarnings("unchecked")
 public void createSpongeData() {
   List<BlockPos> affectedPositions = this.explosion.func_180343_e();
   ImmutableList.Builder<BlockTransaction> builder =
       new ImmutableList.Builder<BlockTransaction>();
   for (BlockPos pos : affectedPositions) {
     Location<World> location = new Location<World>((World) this.world, VecHelper.toVector(pos));
     BlockSnapshot originalSnapshot =
         ((IMixinBlockSnapshot)
                 net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(this.world, pos))
             .createSpongeBlockSnapshot();
     final SpongeBlockSnapshotBuilder replacementBuilder =
         new SpongeBlockSnapshotBuilder()
             .blockState(BlockTypes.AIR.getDefaultState())
             .position(location.getBlockPosition())
             .worldId(location.getExtent().getUniqueId());
     BlockSnapshot replacementSnapshot = replacementBuilder.build();
     builder.add(new BlockTransaction(originalSnapshot, replacementSnapshot)).build();
   }
   this.blockTransactions = builder.build();
 }
Example #11
0
 @SuppressWarnings("unchecked")
 private void animation2() {
   for (Location<World> loc : POS2) {
     World world = loc.getExtent();
     Location<World> pos1 =
         world.getLocation(loc.getBlockX() - 3, loc.getBlockY(), loc.getBlockZ() + 3);
     Location<World> pos2 =
         world.getLocation(loc.getBlockX() + 3, loc.getBlockY(), loc.getBlockZ() + 3);
     Location<World> pos3 =
         world.getLocation(loc.getBlockX() - 3, loc.getBlockY(), loc.getBlockZ() - 3);
     Location<World> pos4 =
         world.getLocation(loc.getBlockX() + 3, loc.getBlockY(), loc.getBlockZ() + 3);
     Location<World>[] pos = mix(pos1, pos2, pos3, pos4);
     for (Location<World> pos5 : pos) {
       Lightning light =
           (Lightning) world.createEntity(EntityTypes.LIGHTNING, pos5.getBlockPosition()).get();
       light.setEffect(true);
       world.spawnEntity(light, Causes.TELEPORT_LIGHTNING.build());
     }
   }
 }
Example #12
0
 @Subscribe
 public void onBlockMove(BlockMoveEvent event) {
   org.spongepowered.api.world.Location block = event.getLocations().get(0);
   Extent extent = block.getExtent();
   if (extent instanceof World) {
     World world = (World) extent;
     final String worldname = world.getName();
     if (!PS.get().isPlotWorld(worldname)) {
       return;
     }
     event.filterLocations(
         new Predicate<org.spongepowered.api.world.Location<World>>() {
           @Override
           public boolean apply(org.spongepowered.api.world.Location loc) {
             if (MainUtil.isPlotRoad(SpongeUtil.getLocation(worldname, loc))) {
               return false;
             }
             return true;
           }
         });
   }
 }
  public static BlockEvent.PlaceEvent createBlockPlaceEvent(Event event) {
    if (!(event instanceof ChangeBlockEvent.Place)) {
      throw new IllegalArgumentException("Event is not a valid ChangeBlockEvent.Place event.");
    }

    ChangeBlockEvent.Place spongeEvent = (ChangeBlockEvent.Place) event;
    Location<World> location =
        spongeEvent.getTransactions().get(0).getOriginal().getLocation().get();
    net.minecraft.world.World world = (net.minecraft.world.World) location.getExtent();
    BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    BlockSnapshot replacementBlock = spongeEvent.getTransactions().get(0).getFinal();
    IBlockState state = (IBlockState) replacementBlock.getState();
    Optional<Player> player = spongeEvent.getCause().first(Player.class);
    if (!player.isPresent()) {
      return null;
    }

    net.minecraftforge.common.util.BlockSnapshot forgeSnapshot =
        new net.minecraftforge.common.util.BlockSnapshot(world, pos, state);
    BlockEvent.PlaceEvent forgeEvent =
        new BlockEvent.PlaceEvent(
            forgeSnapshot, world.getBlockState(pos), (EntityPlayer) player.get());
    return forgeEvent;
  }
Example #14
0
 @Subscribe
 public void onWorldChange(EntityTeleportEvent event) {
   Entity entity = event.getEntity();
   if (entity instanceof Player) {
     org.spongepowered.api.world.Location from = event.getOldLocation();
     org.spongepowered.api.world.Location to = event.getNewLocation();
     int x2;
     if (getInt(from.getX()) != (x2 = getInt(to.getX()))) {
       Player player = (Player) entity;
       PlotPlayer pp = SpongeUtil.getPlayer(player);
       Extent extent = to.getExtent();
       if (!(extent instanceof World)) {
         pp.deleteMeta("location");
         return;
       }
       pp.setMeta("location", SpongeUtil.getLocation(player));
       World world = (World) extent;
       String worldname = ((World) extent).getName();
       PlotWorld plotworld = PS.get().getPlotWorld(worldname);
       if (plotworld == null) {
         return;
       }
       PlotManager plotManager = PS.get().getPlotManager(worldname);
       PlotId id = plotManager.getPlotId(plotworld, x2, 0, getInt(to.getZ()));
       Plot lastPlot = (Plot) pp.getMeta("lastplot");
       if (id == null) {
         if (lastPlot == null) {
           return;
         }
         if (!PlotListener.plotExit(pp, lastPlot)) {
           MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
           if (lastPlot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
             event.setNewLocation(from);
           } else {
             event.setNewLocation(world.getSpawnLocation());
           }
           return;
         }
       } else if (lastPlot != null && id.equals(lastPlot.id)) {
         return;
       } else {
         Plot plot = MainUtil.getPlot(worldname, id);
         if (!PlotListener.plotEntry(pp, plot)) {
           MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
           if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
             event.setNewLocation(from);
           } else {
             event.setNewLocation(world.getSpawnLocation());
           }
           return;
         }
       }
       Integer border = MainUtil.worldBorder.get(worldname);
       if (border != null) {
         if (x2 > border) {
           Vector3d pos = to.getPosition();
           to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ()));
           event.setNewLocation(to);
           MainUtil.sendMessage(pp, C.BORDER);
         } else if (x2 < -border) {
           Vector3d pos = to.getPosition();
           to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ()));
           event.setNewLocation(to);
           MainUtil.sendMessage(pp, C.BORDER);
         }
       }
       return;
     }
     int z2;
     if (getInt(from.getZ()) != (z2 = getInt(to.getZ()))) {
       Player player = (Player) entity;
       PlotPlayer pp = SpongeUtil.getPlayer(player);
       Extent extent = to.getExtent();
       if (!(extent instanceof World)) {
         pp.deleteMeta("location");
         return;
       }
       pp.setMeta("location", SpongeUtil.getLocation(player));
       World world = (World) extent;
       String worldname = ((World) extent).getName();
       PlotWorld plotworld = PS.get().getPlotWorld(worldname);
       if (plotworld == null) {
         return;
       }
       PlotManager plotManager = PS.get().getPlotManager(worldname);
       PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2);
       Plot lastPlot = (Plot) pp.getMeta("lastplot");
       if (id == null) {
         if (lastPlot == null) {
           return;
         }
         if (!PlotListener.plotExit(pp, lastPlot)) {
           MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
           if (lastPlot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
             event.setNewLocation(from);
           } else {
             event.setNewLocation(player.getWorld().getSpawnLocation());
           }
           return;
         }
       } else if (lastPlot != null && id.equals(lastPlot.id)) {
         return;
       } else {
         Plot plot = MainUtil.getPlot(worldname, id);
         if (!PlotListener.plotEntry(pp, plot)) {
           MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
           if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
             event.setNewLocation(from);
           } else {
             event.setNewLocation(player.getWorld().getSpawnLocation());
           }
           return;
         }
       }
       Integer border = MainUtil.worldBorder.get(worldname);
       if (border != null) {
         if (z2 > border) {
           Vector3d pos = to.getPosition();
           to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4));
           event.setNewLocation(to);
           MainUtil.sendMessage(pp, C.BORDER);
         } else if (z2 < -border) {
           Vector3d pos = to.getPosition();
           to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4));
           event.setNewLocation(to);
           MainUtil.sendMessage(pp, C.BORDER);
         }
       }
     }
   }
 }