public void run() {
   for (String s : lifewalkers.toArray(strArr)) {
     Player player = Bukkit.getServer().getPlayer(s);
     if (player != null) {
       if (isExpired(player)) {
         turnOff(player);
         continue;
       }
       Block feet = player.getLocation().getBlock();
       Block ground = feet.getRelative(BlockFace.DOWN);
       if (feet.getType() == Material.AIR
           && (ground.getType() == Material.DIRT || ground.getType() == Material.GRASS)) {
         if (ground.getType() == Material.DIRT) {
           ground.setType(Material.GRASS);
         }
         int rand = random.nextInt(100);
         if (rand < redFlowerChance) {
           feet.setType(Material.RED_ROSE);
           addUse(player);
           chargeUseCost(player);
         } else {
           rand -= redFlowerChance;
           if (rand < yellowFlowerChance) {
             feet.setType(Material.YELLOW_FLOWER);
             addUse(player);
             chargeUseCost(player);
           } else {
             rand -= yellowFlowerChance;
             if (rand < saplingChance) {
               feet.setType(Material.SAPLING);
               addUse(player);
               chargeUseCost(player);
             } else {
               rand -= saplingChance;
               if (rand < tallgrassChance) {
                 BlockState state = feet.getState();
                 state.setType(Material.LONG_GRASS);
                 state.setData(new LongGrass(GrassSpecies.NORMAL));
                 state.update(true);
                 addUse(player);
                 chargeUseCost(player);
               } else {
                 rand -= tallgrassChance;
                 if (rand < fernChance) {
                   BlockState state = feet.getState();
                   state.setType(Material.LONG_GRASS);
                   state.setData(new LongGrass(GrassSpecies.FERN_LIKE));
                   state.update(true);
                   addUse(player);
                   chargeUseCost(player);
                 }
               }
             }
           }
         }
       }
     }
   }
 }
 @Override
 public void setType(int x, int y, int z, Material type, MaterialData data) {
   BlockState block = world.getBlockAt(x, y, z).getState();
   block.setType(type);
   block.setData(data);
   block.update(true);
 }
Пример #3
0
  /**
   * Process the Hylian Luck ability.
   *
   * @param blockState The {@link BlockState} to check ability activation for
   * @return true if the ability was successful, false otherwise
   */
  public boolean processHylianLuck(BlockState blockState) {
    if (!SkillUtils.activationSuccessful(
        SecondaryAbility.HYLIAN_LUCK, getPlayer(), getSkillLevel(), activationChance)) {
      return false;
    }

    List<HylianTreasure> treasures;

    switch (blockState.getType()) {
      case DEAD_BUSH:
      case LONG_GRASS:
      case SAPLING:
        treasures = TreasureConfig.getInstance().hylianFromBushes;
        break;

      case RED_ROSE:
      case YELLOW_FLOWER:
        if (mcMMO.getPlaceStore().isTrue(blockState)) {
          mcMMO.getPlaceStore().setFalse(blockState);
          return false;
        }

        treasures = TreasureConfig.getInstance().hylianFromFlowers;
        break;

      case FLOWER_POT:
        treasures = TreasureConfig.getInstance().hylianFromPots;
        break;

      default:
        return false;
    }

    Player player = getPlayer();

    if (treasures.isEmpty()
        || !EventUtils.simulateBlockBreak(blockState.getBlock(), player, false)) {
      return false;
    }

    blockState.setType(Material.AIR);

    Misc.dropItem(
        blockState.getLocation(),
        treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
    player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
    return true;
  }
  public void createMobSpawner(Vector pos, EntityType entityType) {
    Vector vec = translate(pos);
    if (boundingBox.isVectorInside(vec)) {
      BlockState state =
          world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState();
      delegate.backupBlockState(state.getBlock());

      state.setType(Material.MOB_SPAWNER);
      state.update(true);

      state = world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState();
      if (state instanceof CreatureSpawner) {
        ((CreatureSpawner) state).setSpawnedType(entityType);
      }
    }
  }
  public boolean createRandomItemsContainer(
      Vector pos,
      Random random,
      RandomItemsContent content,
      DirectionalContainer container,
      int maxStacks) {
    Vector vec = translate(pos);
    if (boundingBox.isVectorInside(vec)) {
      BlockState state =
          world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState();
      delegate.backupBlockState(state.getBlock());

      state.setType(container.getItemType());
      state.setData(container);
      state.update(true);

      return content.fillContainer(random, container, state, maxStacks);
    }
    return false;
  }
Пример #6
0
 /** Changes block to its state before change. */
 public void applyRollback() {
   BlockState state = this.blockLocation.getBlock().getState();
   state.setType(this.oldMaterial);
   state.setData(this.oldMaterialData);
   state.update(true, false); // Do not apply physics on rollbacks.
 }
Пример #7
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerInteract(PlayerInteractEvent event) {

    if (event.getAction() == Action.PHYSICAL) {
      return;
    }

    int mode = 0;
    Player player = event.getPlayer();
    Stick stick = null;

    stick = plugin.getStick(player);

    mode = stick.getMode();

    if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
      if (player.getGameMode() == GameMode.CREATIVE && stick.isEnabled()) {
        event.setCancelled(true);
      }
      return;
    }

    if (event.getAction() == Action.RIGHT_CLICK_BLOCK
        && stick.isThrowBuild()
        && player.getItemInHand().getType() != stick.getTool()) {
      return;
    }

    if (!stick.doRightClickModes()
        && (event.getAction() == Action.RIGHT_CLICK_AIR
            || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
      mode = Stick.REMOVE_MODE;
    }

    if (plugin.canUse(player, stick, mode)) {

      event.setCancelled(true);

      List<Block> targetBlocks =
          player.getLastTwoTargetBlocks(stick.getIgnore(), stick.getDistance());

      // sanity check
      if (targetBlocks.size() != 2) {
        plugin.log(Level.WARNING, "Did not get two blocks to work with");
        return;
      }

      Block targetedBlock = null;
      Block placedAgainstBlock = null;

      Item item = stick.getItem();

      if (!item.isBlock()) {
        item = MaterialUtils.getPlaceableMaterial(item);
        if (!item.isBlock()) {
          if (!stick.isThrowBuild()) {
            MessageUtils.send(player, ChatColor.RED, "Invalid item usage.");
          } else {
            event.setCancelled(false);
          }
          return;
        }
      }

      BlockEvent actionEvent = null;

      if (mode == Stick.REPLACE_MODE || mode == Stick.REMOVE_MODE) {
        targetedBlock = targetBlocks.get(1);
        placedAgainstBlock = targetBlocks.get(0);
      } else if (mode == Stick.BUILD_MODE) {
        targetedBlock = targetBlocks.get(0);
        placedAgainstBlock = targetBlocks.get(1);
      }

      if (targetedBlock.getLocation().getBlockY() == 0 && stick.doProtectBottom()) {
        plugin.log(Level.WARNING, "Player " + player.getDisplayName() + " hit rock bottom!");
        return;
      }

      if (LocationUtil.isSameLocation(player, targetedBlock)) {
        if (stick.isDebug()) {
          MessageUtils.send(player, "** boink **");
        }

        return;
      }

      BlockState after = targetedBlock.getState();
      after.setType(mode == Stick.REMOVE_MODE ? Material.AIR : item.getMaterial());

      MaterialData data = null;
      if (mode == Stick.REMOVE_MODE) {
        data = Material.AIR.getNewData((byte) 0);
      } else if (MaterialUtils.isSameMaterial(item.getMaterial(), Material.LADDER)) {
        BlockFace face = LocationUtil.getFace(player, targetedBlock);
        if (stick.isDebug()) {
          MessageUtils.send(player, "clicked " + face + " face! (" + player.getEyeLocation() + ")");
        }

        Ladder ladder = new Ladder();
        ladder.setFacingDirection(face);
        data = ladder;

      } else {
        data = item.getData();
      }

      if (data != null) after.setData(data);

      BlockState before = targetedBlock.getState();
      if (mode == Stick.REMOVE_MODE) {
        stick.setDoItemSwitch(true);
        actionEvent = new BlockBreakEvent(targetedBlock, player);
      } else if (MaterialUtils.isSameMaterial(item.getMaterial(), Material.FIRE)) {
        actionEvent = new BlockIgniteEvent(targetedBlock, IgniteCause.FLINT_AND_STEEL, player);
      } else {
        actionEvent =
            new BlockPlaceEvent(
                after.getBlock(),
                before,
                placedAgainstBlock,
                new ItemStack(stick.getTool()),
                player,
                true);
      }

      plugin.getServer().getPluginManager().callEvent(actionEvent);

      if (!((Cancellable) actionEvent).isCancelled()) {
        plugin.takeAction(before, after, player);
      }
    }
  }
Пример #8
0
  /** http://en.wikipedia.org/wiki/Flood_fill#Alternative_implementations */
  private void floodFill(
      final String player,
      final Block node,
      final Material portalMaterial,
      final Material targetMaterial,
      final PortalType portalType,
      final BlockFace dir1,
      final BlockFace dir2,
      final BlockFace dir3,
      final BlockFace dir4,
      final boolean isCleaning)
      throws Throwable {
    // final String worldName = node.getWorld().getName();
    //		if (!lazyWorldServerMap.containsKey(worldName))
    //		{
    //			lazyWorldServerMap.put(worldName, ((CraftWorld) node.getWorld()).getHandle());
    //		}

    // final WorldServer worldServer = lazyWorldServerMap.get(worldName);
    // worldServer.suppressPhysics = true;

    final Stack<Block> queue = new Stack<Block>();
    final Stack<Block> treatedBlocks = new Stack<Block>();

    queue.push(node);
    Block n = null;
    while (!queue.empty() && treatedBlocks.size() < maxPortalBlocs) {
      n = queue.pop();
      final Material type = n.getType();

      if (type == targetMaterial) {
        treatedBlocks.push(n);

        final BlockState state = n.getState();
        state.setType(portalMaterial);
        state.update(true, false); // force = true, applyPhysics = false
        // worldServer.setTypeId(n.getX(), n.getY(), n.getZ(), portalMaterial.getId());

        queue.push(n.getRelative(dir1));
        queue.push(n.getRelative(dir2));
        queue.push(n.getRelative(dir3));
        queue.push(n.getRelative(dir4));
      } else if (!isCleaning) {
        switch (portalType) {
          case NETHER:
            if (netherFrameBlock != null && type != portalMaterial && type != netherFrameBlock) {
              throw new IllegalFrameBlock(
                  "Unauthorized block "
                      + type
                      + " used to build "
                      + portalType
                      + " portal. Expected: "
                      + netherFrameBlock);
            }
            break;

          case ENDER:
            if (enderFrameBlock != null && type != portalMaterial && type != enderFrameBlock) {
              throw new IllegalFrameBlock(
                  "Unauthorized block "
                      + type
                      + " used to build "
                      + portalType
                      + " portal. Expexted: "
                      + enderFrameBlock);
            }
            break;

          default:
            LOGGER.warning("[CustomPortals] Unhandled portal type on FILLING: " + portalType);
        }
      }
    }
    if (!isCleaning) {
      LOGGER.info(
          "[CustomPortals] "
              + player
              + " has made the "
              + portalType
              + " portal of "
              + treatedBlocks.size()
              + " blocks from "
              + node.getWorld().getName()
              + " at "
              + node.getX()
              + ","
              + node.getY()
              + ","
              + node.getZ());
    } else {
      LOGGER.info(
          "[CustomPortals] "
              + player
              + " has cleaned the "
              + portalType
              + " portal of "
              + treatedBlocks.size()
              + " blocks from "
              + node.getWorld().getName()
              + " at "
              + node.getX()
              + ","
              + node.getY()
              + ","
              + node.getZ());
    }

    treatedBlocks.clear();
    queue.clear();
    // worldServer.suppressPhysics = false;
  }