コード例 #1
0
  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());
    }
  }
コード例 #2
0
  @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));
    }
  }
コード例 #3
0
  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;
  }