示例#1
0
 // test and verification
 private void testTreeCalcDrop(
     final Material itemInHand,
     final Material block,
     final int amount,
     final TreeSpecies species) {
   ItemStack stack = testTreeCalcDrop(itemInHand, block, species);
   // TODO correct this once new trees are implemented correctly
   TreeSpecies tree = null;
   switch (stack.getType()) {
     case WOOD:
       tree = TreeSpecies.getByData(stack.getData().getData());
       break;
     case LOG:
       tree = ((Tree) stack.getData()).getSpecies();
       break;
     case LOG_2:
       tree = TreeSpecies.getByData((byte) (4 + (stack.getData().getData() & 3)));
       break;
     default:
       break;
   }
   Assert.assertEquals(species, tree);
   Assert.assertEquals(block, stack.getType());
   Assert.assertEquals(amount, stack.getAmount());
 }
 // data can be
 // birch, jungle, redwood, random
 private TreeSpecies getTreeSpecies(String data) {
   if (data.equalsIgnoreCase("birch")) {
     return TreeSpecies.BIRCH;
   } else if (data.equalsIgnoreCase("jungle")) {
     return TreeSpecies.JUNGLE;
   } else if (data.equalsIgnoreCase("redwood")) {
     return TreeSpecies.REDWOOD;
   } else if (data.equalsIgnoreCase("random")) {
     return TreeSpecies.values()[rand.nextInt(TreeSpecies.values().length)];
   } else {
     return TreeSpecies.GENERIC;
   }
 }
示例#3
0
  @SuppressWarnings("javadoc")
  @Deprecated
  public short parseDurability(final String string, final Material material) {
    try {
      return Short.parseShort(string);
    } catch (final NumberFormatException e) {
    }

    final String s = string.replace(' ', '_').toUpperCase();
    MaterialData data = null;

    try {
      switch (material) {
        case COAL:
          data = new Coal(CoalType.valueOf(s));
          break;
        case WOOD:
        case LOG:
          data = new Tree(TreeSpecies.valueOf(s));
          break;
        case LEAVES:
          data = new Leaves(TreeSpecies.valueOf(s));
          break;
        case STEP:
        case DOUBLE_STEP:
          data = new Step(Material.valueOf(s));
          break;
        case INK_SACK:
          data = new Dye();
          ((Dye) data).setColor(DyeColor.valueOf(s));
          break;
        case WOOL:
          data = new Wool(DyeColor.valueOf(s));
          break;
        case MONSTER_EGGS:
          data = new MonsterEggs(Material.valueOf(s));
          break;
        case SMOOTH_BRICK:
          data = new SmoothBrick(Material.valueOf(s));
          break;
        case SANDSTONE:
          data = new Sandstone(Material.valueOf(s));
      }
    } catch (final IllegalArgumentException e) {
    }

    return data == null ? 0 : (short) data.getData();
  } // */
  public static short getAnyDataShort(String objectString, String enumValue)
      throws IllegalArgumentException {
    // Firstly, can the string be cast directly as a short?
    try {
      Short s = Short.parseShort(enumValue);
      return s;
    } catch (NumberFormatException ex) {
    }

    // If not, test the enum
    if (objectString.equalsIgnoreCase("LOG")
        || objectString.equalsIgnoreCase("LEAVES")
        || objectString.equalsIgnoreCase("SAPLING")) {
      return (short) TreeSpecies.valueOf(enumValue).getData();
    } else if (objectString.equalsIgnoreCase("WOOL")
        || objectString.equalsIgnoreCase("CREATURE_SHEEP")) {
      return (short) DyeColor.valueOf(enumValue).getData();
    } else if (objectString.equalsIgnoreCase("INK_SACK")) {
      return (short) (0xF - DyeColor.valueOf(enumValue).getData());
    } else if (objectString.equalsIgnoreCase("COAL")) {
      return (short) (CoalType.valueOf(enumValue).getData());
    } else if (objectString.equalsIgnoreCase("CROPS")) {
      return (short) (CropState.valueOf(enumValue).getData());
    } else if (objectString.equalsIgnoreCase("STEP")
        || objectString.equalsIgnoreCase("DOUBLE_STEP")) {
      if (enumValue.equalsIgnoreCase("STONE")) return 0;
      else if (enumValue.equalsIgnoreCase("SANDSTONE")) return 1;
      else if (enumValue.equalsIgnoreCase("WOOD")) return 2;
      else if (enumValue.equalsIgnoreCase("COBBLESTONE")) return 3;
      else throw new IllegalArgumentException();
    } else if (objectString.equalsIgnoreCase("CREATURE_PIG")) {
      if (enumValue.equalsIgnoreCase("UNSADDLED")) return 0;
      else if (enumValue.equalsIgnoreCase("SADDLED")) return 1;
      else throw new IllegalArgumentException();
    } else if (objectString.equalsIgnoreCase("CREATURE_CREEPER")) {
      if (enumValue.equalsIgnoreCase("UNPOWERED")) return 0;
      else if (enumValue.equalsIgnoreCase("POWERED")) return 1;
      else throw new IllegalArgumentException();
    } else if (objectString.equalsIgnoreCase("CREATURE_WOLF")) {
      if (enumValue.equalsIgnoreCase("NEUTRAL")) return 0;
      else if (enumValue.equalsIgnoreCase("TAME")) return 1;
      else if (enumValue.equalsIgnoreCase("TAMED")) return 1;
      else if (enumValue.equalsIgnoreCase("ANGRY")) return 2;
      else throw new IllegalArgumentException();
    } else if (objectString.equalsIgnoreCase("CREATURE_SLIME")) {
      if (enumValue.equalsIgnoreCase("TINY")) return 1;
      else if (enumValue.equalsIgnoreCase("SMALL")) return 2;
      else if (enumValue.equalsIgnoreCase("BIG")) return 3;
      else if (enumValue.equalsIgnoreCase("HUGE")) return 4;
      else throw new IllegalArgumentException();
    } else {
      return 0;
    }
  }
示例#5
0
  /**
   * Check XP gain for woodcutting.
   *
   * @param player The player breaking the block
   * @param block The block being broken
   */
  public static void woodcuttingBlockCheck(Player player, Block block) {
    PlayerProfile profile = Users.getProfile(player);
    int xp = 0;

    if (mcMMO.placeStore.isTrue(block)) {
      return;
    }

    if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) {
      xp = ModChecks.getCustomBlock(block).getXpGain();
    } else {
      byte type = block.getData();

      if ((type & 0x4) == 0x4) type ^= 0x4;

      if ((type & 0x8) == 0x8) type ^= 0x8;

      TreeSpecies species = TreeSpecies.getByData(type);

      // Apparently species can be null in certain cases (custom server mods?)
      // https://github.com/mcMMO-Dev/mcMMO/issues/229
      if (species == null) return;

      switch (species) {
        case GENERIC:
          xp += Config.getInstance().getWoodcuttingXPOak();
          break;

        case REDWOOD:
          xp += Config.getInstance().getWoodcuttingXPSpruce();
          break;

        case BIRCH:
          xp += Config.getInstance().getWoodcuttingXPBirch();
          break;

        case JUNGLE:
          xp += Config.getInstance().getWoodcuttingXPJungle();
          break;

        default:
          break;
      }
    }

    WoodCutting.woodCuttingProcCheck(player, block);
    Skills.xpProcessing(player, profile, SkillType.WOODCUTTING, xp);
  }
示例#6
0
  private Block getBlock(final Material material, final TreeSpecies type) {
    // TODO correct this once new trees are implemented correctly
    BlockState state = Mockito.mock(BlockState.class);
    if (material == Material.LOG_2) {
      Mockito.when(state.getData())
          .thenReturn(new MaterialData(material, (byte) (type.getData() - 4)));
    } else {
      Mockito.when(state.getData()).thenReturn(new Tree(type));
    }

    Block block = Mockito.mock(Block.class);
    Mockito.when(block.getType()).thenReturn(material);
    Mockito.when(block.getState()).thenReturn(state);
    Mockito.when(block.getWorld()).thenReturn(null);

    return block;
  }
示例#7
0
  /**
   * Check for double drops.
   *
   * @param player Player breaking the block
   * @param block The block being broken
   */
  private static void woodCuttingProcCheck(Player player, Block block) {

    final int MAX_CHANCE = advancedConfig.getMiningDoubleDropChance();
    final int MAX_BONUS_LEVEL = advancedConfig.getMiningDoubleDropMaxLevel();

    int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.WOODCUTTING);
    byte type = block.getData();

    if ((type & 0x4) == 0x4) type ^= 0x4;

    if ((type & 0x8) == 0x8) type ^= 0x8;

    Material mat = Material.getMaterial(block.getTypeId());

    int randomChance = 100;
    int chance = (int) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * skillLevel);
    if (chance > MAX_CHANCE) chance = MAX_CHANCE;

    if (player.hasPermission("mcmmo.perks.lucky.woodcutting")) {
      randomChance = (int) (randomChance * 0.75);
    }

    if (chance > random.nextInt(randomChance)
        && Permissions.getInstance().woodcuttingDoubleDrops(player)) {
      Config configInstance = Config.getInstance();
      ItemStack item;
      Location location;

      if (configInstance.getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) {
        CustomBlock customBlock = ModChecks.getCustomBlock(block);
        int minimumDropAmount = customBlock.getMinimumDropAmount();
        int maximumDropAmount = customBlock.getMaximumDropAmount();

        item = customBlock.getItemDrop();
        location = block.getLocation();

        if (minimumDropAmount != maximumDropAmount) {
          Misc.dropItems(location, item, minimumDropAmount);
          Misc.randomDropItems(location, item, 50, maximumDropAmount - minimumDropAmount);
        } else {
          Misc.dropItems(location, item, minimumDropAmount);
        }
      } else {
        item = (new MaterialData(mat, type)).toItemStack(1);

        location = block.getLocation();

        TreeSpecies species = TreeSpecies.getByData(type);

        /* Drop the block */
        switch (species) {
          case GENERIC:
            if (configInstance.getOakDoubleDropsEnabled()) {
              Misc.dropItem(location, item);
            }
            break;

          case REDWOOD:
            if (configInstance.getSpruceDoubleDropsEnabled()) {
              Misc.dropItem(location, item);
            }
            break;

          case BIRCH:
            if (configInstance.getBirchDoubleDropsEnabled()) {
              Misc.dropItem(location, item);
            }
            break;

          case JUNGLE:
            if (configInstance.getJungleDoubleDropsEnabled()) {
              Misc.dropItem(location, item);
            }
            break;

          default:
            break;
        }
      }
    }
  }
示例#8
0
  /**
   * Handle the calculations from Tree Feller.
   *
   * @param currentBlock The current block to be removed
   * @param toBeFelled The list of blocks left to be removed
   */
  private static void processTreeFelling(Block currentBlock, ArrayList<Block> toBeFelled) {
    Material type = currentBlock.getType();

    if (toBeFelled.size() >= Config.getInstance().getTreeFellerThreshold()) {
      return;
    }

    if (type.equals(Material.LOG) || type.equals(Material.LEAVES)) {
      toBeFelled.add(currentBlock);
    } else if (Config.getInstance().getBlockModsEnabled()
        && (ModChecks.isCustomLogBlock(currentBlock)
            || ModChecks.isCustomLeafBlock(currentBlock))) {
      toBeFelled.add(currentBlock);
    }

    Block xPositive = currentBlock.getRelative(1, 0, 0);
    Block xNegative = currentBlock.getRelative(-1, 0, 0);
    Block zPositive = currentBlock.getRelative(0, 0, 1);
    Block zNegative = currentBlock.getRelative(0, 0, -1);
    Block yPositive = currentBlock.getRelative(0, 1, 0);

    if (!mcMMO.placeStore.isTrue(currentBlock)) {
      if (!isTooAggressive(currentBlock, xPositive)
          && BlockChecks.treeFellerCompatible(xPositive)
          && !toBeFelled.contains(xPositive)) {
        processTreeFelling(xPositive, toBeFelled);
      }

      if (!isTooAggressive(currentBlock, xNegative)
          && BlockChecks.treeFellerCompatible(xNegative)
          && !toBeFelled.contains(xNegative)) {
        processTreeFelling(xNegative, toBeFelled);
      }

      if (!isTooAggressive(currentBlock, zPositive)
          && BlockChecks.treeFellerCompatible(zPositive)
          && !toBeFelled.contains(zPositive)) {
        processTreeFelling(zPositive, toBeFelled);
      }

      if (!isTooAggressive(currentBlock, zNegative)
          && BlockChecks.treeFellerCompatible(zNegative)
          && !toBeFelled.contains(zNegative)) {
        processTreeFelling(zNegative, toBeFelled);
      }
    }

    byte data = currentBlock.getData();

    if ((data & 0x4) == 0x4) data ^= 0x4;

    if ((data & 0x8) == 0x8) data ^= 0x8;

    if (TreeSpecies.getByData(data) == TreeSpecies.JUNGLE) {
      Block corner1 = currentBlock.getRelative(1, 0, 1);
      Block corner2 = currentBlock.getRelative(1, 0, -1);
      Block corner3 = currentBlock.getRelative(-1, 0, 1);
      Block corner4 = currentBlock.getRelative(-1, 0, -1);

      if (!mcMMO.placeStore.isTrue(currentBlock)) {
        if (!isTooAggressive(currentBlock, corner1)
            && BlockChecks.treeFellerCompatible(corner1)
            && !toBeFelled.contains(corner1)) {
          processTreeFelling(corner1, toBeFelled);
        }

        if (!isTooAggressive(currentBlock, corner2)
            && BlockChecks.treeFellerCompatible(corner2)
            && !toBeFelled.contains(corner2)) {
          processTreeFelling(corner2, toBeFelled);
        }

        if (!isTooAggressive(currentBlock, corner3)
            && BlockChecks.treeFellerCompatible(corner3)
            && !toBeFelled.contains(corner3)) {
          processTreeFelling(corner3, toBeFelled);
        }

        if (!isTooAggressive(currentBlock, corner4)
            && BlockChecks.treeFellerCompatible(corner4)
            && !toBeFelled.contains(corner4)) {
          processTreeFelling(corner4, toBeFelled);
        }
      }
    }

    if (BlockChecks.treeFellerCompatible(yPositive)) {
      if (!mcMMO.placeStore.isTrue(currentBlock) && !toBeFelled.contains(yPositive)) {
        processTreeFelling(yPositive, toBeFelled);
      }
    }
  }
示例#9
0
  public static int matchItemData(int id, String filter) {
    // Missing some key code, need to be finished sometime in future.
    try {
      return Integer.parseInt(filter);
    } catch (NumberFormatException ignored) {

    }

    if (Material.WOOD.getId() == id) {
      for (TreeSpecies search : TreeSpecies.values()) {
        if (filter.equalsIgnoreCase(search.toString())) {
          return search.getData();
        }
      }

      return 0;
    } else if (Material.WOOL.getId() == id) {
      for (DyeColor search : DyeColor.values()) {
        if (filter.equalsIgnoreCase(search.toString())) {
          return search.getWoolData();
        }
      }

      return 0;
    } else if (Material.INK_SACK.getId() == id) {
      for (DyeColor search : DyeColor.values()) {
        if (filter.equalsIgnoreCase(search.toString())) {
          return search.getDyeData();
        }
      }

      return 0;
    } else if (Material.STEP.getId() == id) {
      Step s = new Step();
      for (Material search : s.getTextures()) {
        if (filter.equalsIgnoreCase(search.toString())) {
          return s.getTextures().indexOf(search);
        }
      }

      return 0;
    } else if (Material.DOUBLE_STEP.getId() == id) {
      Step s = new Step();
      for (Material search : s.getTextures()) {
        if (filter.equalsIgnoreCase(search.toString())) {
          return s.getTextures().indexOf(search);
        }
      }

      return 0;
    } else if (Material.SMOOTH_BRICK.getId() == id) {
      SmoothBrick s = new SmoothBrick();
      for (Material search : s.getTextures()) {
        if (filter.equalsIgnoreCase(search.toString())) {
          return s.getTextures().indexOf(search);
        }
      }

      return 0;
    }

    return 0;
  }