예제 #1
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;
  }
예제 #3
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());
 }
  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));
  }
예제 #5
0
  public static void createPlatform(Location<World> center) {
    platform(center, BlockTypes.STONE);

    platform(center.getRelative(Direction.UP), BlockTypes.AIR);
    platform(center.getRelative(Direction.UP).getRelative(Direction.UP), BlockTypes.AIR);
    platform(
        center.getRelative(Direction.UP).getRelative(Direction.UP).getRelative(Direction.UP),
        BlockTypes.AIR);
  }
예제 #6
0
 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));
   }
 }
예제 #7
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;
 }
예제 #8
0
 @Subscribe
 public void onBlockPlace(PlayerPlaceBlockEvent event) {
   Player player = event.getEntity();
   World world = player.getWorld();
   String worldname = world.getName();
   org.spongepowered.api.world.Location blockLoc = event.getLocation();
   final Location loc = SpongeUtil.getLocation(worldname, blockLoc);
   final Plot plot = MainUtil.getPlot(loc);
   if (plot != null) {
     if (blockLoc.getY() == 0) {
       event.setCancelled(true);
       return;
     }
     final PlotPlayer pp = SpongeUtil.getPlayer(player);
     if (!plot.hasOwner()) {
       if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
         return;
       }
       MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
       event.setCancelled(true);
       return;
     } else if (!plot.isAdded(pp.getUUID())) {
       final Flag destroy = FlagManager.getPlotFlag(plot, "place");
       BlockState state = blockLoc.getBlock();
       if ((destroy != null)
           && ((HashSet<PlotBlock>) destroy.getValue())
               .contains(SpongeMain.THIS.getPlotBlock(state))) {
         return;
       }
       if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
         return;
       }
       MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
       event.setCancelled(true);
     } else if (Settings.DONE_RESTRICTS_BUILDING && plot.getSettings().flags.containsKey("done")) {
       if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
         MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
         event.setCancelled(true);
         return;
       }
     }
     return;
   }
   final PlotPlayer pp = SpongeUtil.getPlayer(player);
   if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
     return;
   }
   if (MainUtil.isPlotArea(loc)) {
     MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
     event.setCancelled(true);
   }
 }
예제 #9
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());
  }
예제 #12
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);
     }
   }
 }
  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);
  }
예제 #14
0
 public static Location<?> getNextSign(Location<?> sign, String criterea, int searchRadius) {
   Location otherBlock = sign;
   Direction way = getBack(sign);
   boolean found = false;
   for (int i = 0; i < searchRadius; i++) {
     if (isSign(otherBlock.getRelative(way))) {
       otherBlock = otherBlock.getRelative(way);
       if (getTextRaw((Sign) otherBlock.getTileEntity().get(), 1).equalsIgnoreCase(criterea)) {
         found = true;
         break;
       }
     } else otherBlock = otherBlock.getRelative(way);
   }
   if (!found) return null;
   return otherBlock;
 }
 @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();
 }
예제 #16
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;
  }
예제 #18
0
 public BoundingBox2(Location parA, Location parB) {
   this(parA.getBlockPosition(), parB.getBlockPosition());
 }
  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;
  }
예제 #20
0
 public static Location<?> getBackBlock(Location<?> sign) {
   return sign.getRelative(getBack(sign));
 }
예제 #21
0
  @Override
  public boolean triggerMechanic(Location block, Sign sign, Human human, Boolean forceState) {

    if (!SignUtil.getTextRaw(sign, 1).equals("[Door]")) {

      Direction back =
          SignUtil.getTextRaw(sign, 1).equals("[Door Up]") ? Direction.UP : Direction.DOWN;

      Location baseBlock = block.getRelative(back);

      Location otherSide = getOtherEnd(block, back, maximumLength);
      if (otherSide == null) {
        if (human instanceof CommandSource)
          ((CommandSource) human).sendMessage(Texts.builder("Missing other end!").build());
        return true;
      }

      Location otherBase = otherSide.getRelative(back.getOpposite());

      if (!baseBlock.getBlock().equals(otherBase.getBlock())) {
        if (human instanceof CommandSource)
          ((CommandSource) human)
              .sendMessage(Texts.builder("Both ends must be the same material!").build());
        return true;
      }

      int leftBlocks = 0, rightBlocks = 0; // Default to 0. Single width bridge is the default.

      Location left = baseBlock.getRelative(SignUtil.getLeft(block));
      Location right = baseBlock.getRelative(SignUtil.getRight(block));

      // Calculate left distance
      Location otherLeft = otherBase.getRelative(SignUtil.getLeft(block));

      while (true) {
        if (leftBlocks >= maximumWidth) break;
        if (left.getBlock().equals(baseBlock.getBlock())
            && otherLeft.getBlock().equals(baseBlock.getBlock())) {
          leftBlocks++;
          left = left.getRelative(SignUtil.getLeft(block));
          otherLeft = otherLeft.getRelative(SignUtil.getLeft(block));
        } else {
          break;
        }
      }

      // Calculate right distance
      Location otherRight = otherBase.getRelative(SignUtil.getRight(block));

      while (true) {
        if (rightBlocks >= maximumWidth) break;
        if (right.getBlock().equals(baseBlock.getBlock())
            && otherRight.getBlock().equals(baseBlock.getBlock())) {
          rightBlocks++;
          right = right.getRelative(SignUtil.getRight(block));
          otherRight = otherRight.getRelative(SignUtil.getRight(block));
        } else {
          break;
        }
      }

      baseBlock = baseBlock.getRelative(back);

      BlockState type = block.getRelative(back).getBlock();
      if (baseBlock.getBlock().equals(type) && (forceState == null || !forceState))
        type = BlockTypes.AIR.getDefaultState();

      while (baseBlock.getBlockY() != otherSide.getBlockY() + (back == Direction.UP ? -1 : 1)) {

        baseBlock.setBlock(type);

        left = baseBlock.getRelative(SignUtil.getLeft(block));

        for (int i = 0; i < leftBlocks; i++) {
          left.setBlock(type);
          left = left.getRelative(SignUtil.getLeft(block));
        }

        right = baseBlock.getRelative(SignUtil.getRight(block));

        for (int i = 0; i < rightBlocks; i++) {
          right.setBlock(type);
          right = right.getRelative(SignUtil.getRight(block));
        }

        baseBlock = baseBlock.getRelative(back);
      }
    } else {
      if (human instanceof CommandSource)
        ((CommandSource) human)
            .sendMessage(Texts.builder("Door not activatable from here!").build());
      return false;
    }

    return true;
  }
예제 #22
0
  private static void platform(Location<World> center, BlockType type) {
    List<Location<World>> list = new ArrayList<>();

    Location<World> south = center.getRelative(Direction.SOUTH);
    Location<World> north = center.getRelative(Direction.NORTH);
    Location<World> east = center.getRelative(Direction.EAST);
    Location<World> west = center.getRelative(Direction.WEST);

    Location<World> north2 = north.getRelative(Direction.NORTH);
    Location<World> south2 = south.getRelative(Direction.SOUTH);
    Location<World> east2 = east.getRelative(Direction.EAST);
    Location<World> west2 = west.getRelative(Direction.WEST);

    list.add(center);

    list.add(north);
    list.add(south);
    list.add(east);
    list.add(west);

    list.add(north.getRelative(Direction.EAST));
    list.add(north.getRelative(Direction.WEST));
    list.add(south.getRelative(Direction.EAST));
    list.add(south.getRelative(Direction.WEST));

    list.add(north2);
    list.add(north2.getRelative(Direction.EAST));
    list.add(north2.getRelative(Direction.EAST).getRelative(Direction.EAST));
    list.add(north2.getRelative(Direction.WEST));
    list.add(north2.getRelative(Direction.WEST).getRelative(Direction.WEST));

    list.add(south2);
    list.add(south2.getRelative(Direction.EAST));
    list.add(south2.getRelative(Direction.EAST).getRelative(Direction.EAST));
    list.add(south2.getRelative(Direction.WEST));
    list.add(south2.getRelative(Direction.WEST).getRelative(Direction.WEST));

    list.add(east2);
    list.add(east2.getRelative(Direction.NORTH));
    list.add(east2.getRelative(Direction.SOUTH));

    list.add(west2);
    list.add(west2.getRelative(Direction.NORTH));
    list.add(west2.getRelative(Direction.SOUTH));

    for (Location<World> location : list) {
      location.setBlock(
          Main.getGame()
              .getRegistry()
              .createBuilder(BlockState.Builder.class)
              .blockType(type)
              .build());
    }
  }
예제 #23
0
 /**
  * Gets whether or not the block at this location is a sign.
  *
  * @param block The location to check
  * @return If it is a sign
  */
 public static boolean isSign(Location<?> block) {
   return isSign(block.getBlock());
 }
예제 #24
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;
    }
  }
예제 #25
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);
         }
       }
     }
   }
 }
예제 #26
0
  /**
   * @param sign treated as sign post if it is such, or else assumed to be a wall sign (i.e., if you
   *     ask about a stone block, it's considered a wall sign).
   * @return the side of the sign containing the text (in other words, when a player places a new
   *     sign, while facing north, this will return south).
   */
  public static Direction getFront(Location<?> sign) {
    Optional<Direction> data = sign.get(Keys.DIRECTION);

    return data.orElse(Direction.NONE);
  }
예제 #27
0
 public static Location<?> getFrontBlock(Location<?> sign) {
   return sign.getRelative(getFront(sign));
 }
  @Inject(
      method = "processPlayer",
      at =
          @At(
              value = "FIELD",
              target = "net.minecraft.network.NetHandlerPlayServer.hasMoved:Z",
              ordinal = 2),
      cancellable = true)
  public void proccesPlayerMoved(C03PacketPlayer packetIn, CallbackInfo ci) {
    if (packetIn.isMoving() || packetIn.getRotating() && !this.playerEntity.isDead) {
      Player player = (Player) this.playerEntity;
      Vector3d fromrot = player.getRotation();

      // If Sponge used the player's current location, the delta might never be triggered which
      // could be exploited
      Location from = player.getLocation();
      if (this.lastMoveLocation != null) {
        from = this.lastMoveLocation;
      }

      Vector3d torot = new Vector3d(packetIn.getPitch(), packetIn.getYaw(), 0);
      Location to =
          new Location(
              player.getWorld(),
              packetIn.getPositionX(),
              packetIn.getPositionY(),
              packetIn.getPositionZ());

      // Minecraft sends a 0, 0, 0 position when rotation only update occurs, this needs to be
      // recognized and corrected
      boolean rotationOnly = !packetIn.isMoving() && packetIn.getRotating();
      if (rotationOnly) {
        // Correct the to location so it's not misrepresented to plugins, only when player rotates
        // without moving
        // In this case it's only a rotation update, which isn't related to the to location
        from = player.getLocation();
        to = from;
      }

      // Minecraft does the same with rotation when it's only a positional update
      boolean positionOnly = packetIn.isMoving() && !packetIn.getRotating();
      if (positionOnly) {
        // Correct the new rotation to match the old rotation
        torot = fromrot;
      }

      double deltaSquared = to.getPosition().distanceSquared(from.getPosition());
      double deltaAngleSquared = fromrot.distanceSquared(torot);

      // These magic numbers are sad but help prevent excessive lag from this event.
      // eventually it would be nice to not have them
      if (deltaSquared > ((1f / 16) * (1f / 16)) || deltaAngleSquared > (.15f * .15f)) {
        PlayerMoveEvent event =
            SpongeEventFactory.createPlayerMove(Sponge.getGame(), player, from, to, torot);
        Sponge.getGame().getEventManager().post(event);
        if (event.isCancelled()) {
          player.setLocationAndRotation(from, fromrot);
          this.lastMoveLocation = from;
          ci.cancel();
        } else if (!event.getNewLocation().equals(to)) {
          player.setLocationAndRotation(event.getNewLocation(), event.getRotation());
          this.lastMoveLocation = event.getNewLocation();
          ci.cancel();
        } else if (!from.equals(player.getLocation()) && this.justTeleported) {
          this.lastMoveLocation = player.getLocation();
          // Prevent teleports during the move event from causing odd behaviors
          this.justTeleported = false;
          ci.cancel();
        } else {
          this.lastMoveLocation = event.getNewLocation();
        }
      }
    }
  }
예제 #29
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());
     }
   }
 }