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;
  }
예제 #2
0
 public void animatedTeleport() {
   Task.Builder builder = MoseCraft.getPlugin().getGame().getScheduler().createTaskBuilder();
   builder.intervalTicks(20);
   builder.async();
   builder.name(POS1.getBlockX() + "," + POS1.getBlockY() + "," + POS1.getBlockZ());
   builder.execute(new TeleportTask()).submit(MoseCraft.getPlugin().getGame());
 }
예제 #3
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());
     }
   }
 }
  // 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;
  }
  public static PlayerSleepInBedEvent createPlayerSleepInBedEvent(Event event) {
    if (!(event instanceof SleepingEvent.Pre)) {
      throw new IllegalArgumentException(
          "Event " + event + " is not a valid SleepingEvent.Pre event.");
    }

    SleepingEvent.Pre spongeEvent = (SleepingEvent.Pre) event;
    Optional<Player> player = spongeEvent.getCause().first(Player.class);
    if (!player.isPresent()) {
      return null;
    }
    Location<World> location = spongeEvent.getBed().getLocation().get();
    BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    return new PlayerSleepInBedEvent((EntityPlayer) player.get(), pos);
  }
  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;
  }
예제 #7
0
  @Listener
  public void PlayerMoveEvent(DisplaceEntityEvent event) {
    /*
     * Check the plugin is running.
     */
    if (!(BorderLands.isOperate())) {
      return;
    }
    /*
     * Check this movement is of a player.
     */
    if (!(event.getTargetEntity() instanceof Player)) {
      return;
    }
    locO = event.getFromTransform().getLocation();
    loc = event.getToTransform().getLocation();
    player = (Player) event.getTargetEntity();

    /*
     * Check if it's more than 1 block change for X or Z.
     */
    if ((locO.getBlockX() == loc.getBlockX()) && (locO.getBlockZ() == loc.getBlockZ())) {
      return;
    }

    DebugLog.DLog("PlayerMoveEvent");
    DebugLog.DLog("Player at: " + loc.getBlockX() + "," + loc.getBlockZ());
    DebugLog.DLog("In world:  " + player.getWorld().getName().toLowerCase());
    /*
     * For all borders.
     */
    for (String[] x : BorderLands.getBorders()) {
      /*
       * Check if the world matches.
       */
      if (!(player.getWorld().getName().toLowerCase().equals(x[0].toLowerCase()))) {
        continue;
      }
      /*
       * Check if the player is inside the border.
       */
      if (((loc.getBlockX() > (Integer.parseInt(x[1]) - Integer.parseInt(x[3])))
              && (loc.getBlockZ() > (Integer.parseInt(x[2]) - Integer.parseInt(x[4]))))
          && ((loc.getBlockX() < (Integer.parseInt(x[1]) + Integer.parseInt(x[5])))
              && (loc.getBlockZ() < (Integer.parseInt(x[2]) + Integer.parseInt(x[6]))))) {
        if (NotifiedInside.containsKey(player)) {
          if (NotifiedInside.get(player) == 0) {
            player.sendMessage(
                Texts.of(
                    TextColors.BLUE,
                    "[BorderLands]",
                    TextColors.GOLD,
                    " You are now",
                    TextColors.GREEN,
                    " inside ",
                    TextColors.GOLD,
                    "the border."));
            NotifiedInside.put(player, 1);
            Utilities.PassNotifyList.put(player, 0L);
          }
        } else {
          NotifiedInside.put(player, 1);
        }
      }
      /*
       * Check if player is above the max X value.
       */
      if (Utilities.isPostXPos(loc.getBlockX(), Integer.parseInt(x[1]), Integer.parseInt(x[5]))) {
        if (!(player.hasPermission(movePerm) || player.hasPermission("borderlands.move." + x[7]))) {
          Utilities.Notify(player);
          this.postXPosTele(player, Integer.parseInt(x[1]), Integer.parseInt(x[5]), true);
        } else {
          Utilities.PassNotify(player);
          NotifiedInside.put(player, 0);
        }
        continue;
      }
      /*
       * Check if player is below the minimum X value.
       */
      if (Utilities.isPreXNeg(loc.getBlockX(), Integer.parseInt(x[1]), Integer.parseInt(x[3]))) {
        if (!(player.hasPermission(movePerm) || player.hasPermission("borderlands.move." + x[7]))) {
          Utilities.Notify(player);
          this.postXPosTele(player, Integer.parseInt(x[1]), Integer.parseInt(x[3]), false);
        } else {
          Utilities.PassNotify(player);
          NotifiedInside.put(player, 0);
        }
        continue;
      }
      /*
       * Check if player is above the max Z value.
       */
      if (Utilities.isPostZPos(loc.getBlockZ(), Integer.parseInt(x[2]), Integer.parseInt(x[6]))) {
        if (!(player.hasPermission(movePerm) || player.hasPermission("borderlands.move." + x[7]))) {
          Utilities.Notify(player);
          this.postZPosTele(player, Integer.parseInt(x[2]), Integer.parseInt(x[6]), true);
        } else {
          Utilities.PassNotify(player);
          NotifiedInside.put(player, 0);
        }
        continue;
      }
      /*
       * Check if player is below the minimum Z value.
       */
      if (Utilities.isPreZNeg(loc.getBlockZ(), Integer.parseInt(x[2]), Integer.parseInt(x[4]))) {
        if (!(player.hasPermission(movePerm) || player.hasPermission("borderlands.move." + x[7]))) {
          Utilities.Notify(player);
          this.postZPosTele(player, Integer.parseInt(x[2]), Integer.parseInt(x[4]), false);
        } else {
          Utilities.PassNotify(player);
          NotifiedInside.put(player, 0);
        }
        continue;
      }
      continue;
    }
  }
  public static ChangeBlockEvent.Place callBlockPlaceEvent(Event event) {
    if (!(event instanceof ChangeBlockEvent.Place)) {
      throw new IllegalArgumentException("Event is not a valid ChangeBlockEventPlace");
    }

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

    if (spongeEvent.getCause().first(Player.class).isPresent()) {
      EntityPlayer player = (EntityPlayer) spongeEvent.getCause().first(Player.class).get();
      net.minecraft.world.World world = (net.minecraft.world.World) spongeEvent.getTargetWorld();

      if (spongeEvent.getTransactions().size() == 1) {
        BlockPos pos =
            VecHelper.toBlockPos(spongeEvent.getTransactions().get(0).getOriginal().getPosition());
        IBlockState state =
            (IBlockState) spongeEvent.getTransactions().get(0).getOriginal().getState();
        net.minecraftforge.common.util.BlockSnapshot blockSnapshot =
            new net.minecraftforge.common.util.BlockSnapshot(world, pos, state);
        IBlockState placedAgainst = Blocks.air.getDefaultState();
        if (StaticMixinHelper.packetPlayer != null
            && StaticMixinHelper.processingPacket instanceof C08PacketPlayerBlockPlacement) {
          C08PacketPlayerBlockPlacement packet =
              (C08PacketPlayerBlockPlacement) StaticMixinHelper.processingPacket;
          EnumFacing facing = EnumFacing.getFront(packet.getPlacedBlockDirection());
          placedAgainst =
              blockSnapshot.world.getBlockState(blockSnapshot.pos.offset(facing.getOpposite()));
        }

        BlockEvent.PlaceEvent forgeEvent =
            new BlockEvent.PlaceEvent(blockSnapshot, placedAgainst, player);
        ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
        if (forgeEvent.isCanceled()) {
          spongeEvent.getTransactions().get(0).setValid(false);
        }
      } else { // multi
        Iterator<Transaction<BlockSnapshot>> iterator = spongeEvent.getTransactions().iterator();
        List<net.minecraftforge.common.util.BlockSnapshot> blockSnapshots = new ArrayList<>();

        while (iterator.hasNext()) {
          Transaction<BlockSnapshot> transaction = iterator.next();
          Location<World> location = transaction.getOriginal().getLocation().get();
          IBlockState state = (IBlockState) transaction.getOriginal().getState();
          BlockPos pos =
              new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
          net.minecraftforge.common.util.BlockSnapshot blockSnapshot =
              new net.minecraftforge.common.util.BlockSnapshot(world, pos, state);
          blockSnapshots.add(blockSnapshot);
        }

        IBlockState placedAgainst = Blocks.air.getDefaultState();
        if (StaticMixinHelper.packetPlayer != null
            && StaticMixinHelper.processingPacket instanceof C08PacketPlayerBlockPlacement) {
          C08PacketPlayerBlockPlacement packet =
              (C08PacketPlayerBlockPlacement) StaticMixinHelper.processingPacket;
          EnumFacing facing = EnumFacing.getFront(packet.getPlacedBlockDirection());
          placedAgainst =
              blockSnapshots
                  .get(0)
                  .world
                  .getBlockState(blockSnapshots.get(0).pos.offset(facing.getOpposite()));
        }

        BlockEvent.MultiPlaceEvent forgeEvent =
            new BlockEvent.MultiPlaceEvent(blockSnapshots, placedAgainst, player);
        ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
        if (forgeEvent.isCanceled()) {
          while (iterator.hasNext()) {
            iterator.next().setValid(false);
          }
        }
      }
    }
    return spongeEvent;
  }