@Inject(
      method = "onUpdate",
      at =
          @At(
              value = "INVOKE",
              target = "Lnet/minecraft/entity/effect/EntityLightningBolt;setDead()V"))
  public void onSetDead(CallbackInfo ci) {
    if (this.isDead) {
      return;
    }
    World world = (World) this.worldObj;
    LightningEvent.Strike strike =
        SpongeEventFactory.createLightningEventStrike(
            this.cause, this.struckEntities, this.struckEntitySnapshots, world, this.struckBlocks);
    Sponge.getEventManager().post(strike);

    if (!strike.isCancelled()) {
      for (Transaction<BlockSnapshot> bt : strike.getTransactions()) {
        if (bt.isValid()) {
          BlockSnapshot bs = bt.getFinal();
          world.setBlock(bs.getPosition(), bs.getState());
        }
      }
      for (Entity e : strike.getEntities()) {
        ((net.minecraft.entity.Entity) e).onStruckByLightning((EntityLightningBolt) (Object) this);
      }
      SpongeImpl.postEvent(SpongeEventFactory.createLightningEventPost(this.cause));
    }
  }
  public void revertActiveVisual(Player player) {
    if (this.visualRevertTask != null) {
      this.visualRevertTask.cancel();
    }

    if (this.visualClaimId != null) {
      Claim claim =
          GriefPrevention.instance.dataStore.getClaim(this.worldProperties, this.visualClaimId);
      if (claim != null) {
        claim.playersWatching.remove(this.playerID);
      }
    }
    this.visualClaimId = null;
    if (this.visualBlocks == null
        || !player
            .getWorld()
            .equals(this.visualBlocks.get(0).getFinal().getLocation().get().getExtent())) {
      return;
    }

    for (int i = 0; i < this.visualBlocks.size(); i++) {
      BlockSnapshot snapshot = this.visualBlocks.get(i).getOriginal();
      player.sendBlockChange(snapshot.getPosition(), snapshot.getState());
    }
  }
  private Object mockParam(final Class<?> paramType) {
    if (paramType == byte.class) {
      return (byte) 0;
    } else if (paramType == short.class) {
      return (short) 0;
    } else if (paramType == int.class) {
      return 0;
    } else if (paramType == long.class) {
      return (long) 0;
    } else if (paramType == float.class) {
      return (float) 0;
    } else if (paramType == double.class) {
      return (double) 0;
    } else if (paramType == char.class) {
      return (char) 0;
    } else if (paramType == boolean.class) {
      return false;
    } else if (paramType == String.class) {
      return "Cupcakes";
    } else if (Enum.class.isAssignableFrom(paramType)) {
      return paramType.getEnumConstants()[0];
    } else if (Location.class.isAssignableFrom(paramType)) {
      return new Location<Extent>((Extent) mockParam(Extent.class), 0, 0, 0);
    } else if (paramType == Text[].class) {
      return new Text[] {};
    } else if (BlockSnapshot.class.isAssignableFrom(paramType)) {
      BlockSnapshot mock = (BlockSnapshot) mock(paramType);

      final Answer<Object> answer =
          new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
              return mock(paramType);
            }
          };

      when(mock.copy()).thenAnswer(answer);
      return mock;
    } else if (DataManipulator.class.isAssignableFrom(paramType)) {
      DataManipulator<?, ?> mock = (DataManipulator) mock(paramType);

      final Answer<Object> answer =
          new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
              return mock(paramType);
            }
          };
      when(mock.copy()).thenAnswer(answer);

      return mock;
    } else if (paramType == UUID.class) {
      return UUID.randomUUID();
    } else {
      return mock(paramType, withSettings().defaultAnswer(Mockito.RETURNS_MOCKS));
    }
  }
  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;
  }
Exemplo n.º 5
0
 @Override
 public boolean restoreSnapshot(
     int x, int y, int z, BlockSnapshot snapshot, boolean force, boolean notifyNeighbors) {
   snapshot = snapshot.withLocation(new Location<>(this, new Vector3i(x, y, z)));
   return snapshot.restore(force, notifyNeighbors);
 }
Exemplo n.º 6
0
 @Override
 public boolean restoreSnapshot(BlockSnapshot snapshot, boolean force, boolean notifyNeighbors) {
   return snapshot.restore(force, notifyNeighbors);
 }