Beispiel #1
0
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!(sender instanceof Player)) {
      sender.sendMessage(
          "This command does not support console useage."); // TODO: Needs more locale.
      return true;
    }

    Player player = (Player) sender;

    if (!mcPermissions.getInstance().admin(player)) {
      player.sendMessage(
          ChatColor.YELLOW
              + "[mcMMO] "
              + ChatColor.DARK_RED
              + mcLocale.getString("mcPlayerListener.NoPermission"));
      return true;
    }
    player.sendMessage(ChatColor.GRAY + "Starting conversion..."); // TODO: Needs more locale.
    Users.clearUsers();
    convertToMySQL();
    for (Player x : Bukkit.getServer().getOnlinePlayers()) {
      Users.addUser(x);
    }
    player.sendMessage(ChatColor.GREEN + "Conversion finished!"); // TODO: Needs more locale.

    return true;
  }
Beispiel #2
0
  /**
   * Get item results from Fishing.
   *
   * @param player The player that was fishing
   * @param event The event to modify
   */
  private static void getFishingResults(Player player, PlayerFishEvent event) {
    PlayerProfile PP = Users.getProfile(player);
    List<FishingTreasure> rewards = new ArrayList<FishingTreasure>();
    Item theCatch = (Item) event.getCaught();

    switch (getFishingLootTier(PP)) {
      case 1:
        rewards = LoadTreasures.fishingRewardsTier1;
        break;

      case 2:
        rewards = LoadTreasures.fishingRewardsTier2;
        break;

      case 3:
        rewards = LoadTreasures.fishingRewardsTier3;
        break;

      case 4:
        rewards = LoadTreasures.fishingRewardsTier4;
        break;

      case 5:
        rewards = LoadTreasures.fishingRewardsTier5;
        break;

      default:
        break;
    }

    if (LoadProperties.fishingDrops) {
      FishingTreasure treasure = rewards.get(random.nextInt(rewards.size()));

      if (random.nextDouble() * 100 <= treasure.getDropChance()) {
        Users.getProfile(player).addXP(SkillType.FISHING, treasure.getXp());
        theCatch.setItemStack(treasure.getDrop());
      }
    } else {
      theCatch.setItemStack(new ItemStack(Material.RAW_FISH));
    }

    short maxDurability = theCatch.getItemStack().getType().getMaxDurability();

    if (maxDurability > 0) {
      theCatch
          .getItemStack()
          .setDurability(
              (short) (random.nextInt(maxDurability))); // Change durability to random value
    }

    m.mcDropItem(player.getLocation(), new ItemStack(Material.RAW_FISH)); // Always drop a fish
    PP.addXP(SkillType.FISHING, LoadProperties.mfishing);
    Skills.XpCheckSkill(SkillType.FISHING, player);
  }
  /**
   * Monitor EntityTame events.
   *
   * @param event The event to watch
   */
  @EventHandler(priority = EventPriority.MONITOR)
  public void onEntityTame(EntityTameEvent event) {
    Player player = (Player) event.getOwner();

    if (mcPermissions.getInstance().taming(player)
        && !event.getEntity().hasMetadata("mcmmoSummoned")) {
      PlayerProfile PP = Users.getProfile(player);
      EntityType type = event.getEntityType();
      int xp = 0;

      switch (type) {
        case WOLF:
          xp = LoadProperties.mtameWolf;
          break;

        case OCELOT:
          xp = LoadProperties.mtameOcelot;
          break;

        default:
          break;
      }

      PP.addXP(SkillType.TAMING, xp);
      Skills.XpCheckSkill(SkillType.TAMING, player);
    }
  }
Beispiel #4
0
  public static void unarmedBonus(Player attacker, EntityDamageByEntityEvent event) {
    int bonus = 3;

    // Add 1 DMG for every 50 skill levels
    bonus += Users.getProfile(attacker).getSkillLevel(SkillType.UNARMED) / 50;

    if (bonus > 8) bonus = 8;

    event.setDamage(event.getDamage() + bonus);
  }
 public static void woodCuttingProcCheck(Player player, Block block) {
   PlayerProfile PP = Users.getProfile(player);
   byte type = block.getData();
   Material mat = Material.getMaterial(block.getTypeId());
   if (player != null) {
     if (Math.random() * 1000 <= PP.getSkill("woodcutting")) {
       ItemStack item = new ItemStack(mat, 1, (short) 0, type);
       block.getWorld().dropItemNaturally(block.getLocation(), item);
     }
   }
 }
Beispiel #6
0
  @Override
  public void run() {
    for (Player player : plugin.getServer().getOnlinePlayers()) {
      long curTime = System.currentTimeMillis();
      if (player == null) continue;
      PlayerProfile PP = Users.getProfile(player);

      if (PP == null) continue;

      watchCooldown(player, PP, curTime);
    }
  }
  /**
   * Monitor EntityDamage events.
   *
   * @param event The event to monitor
   */
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onEntityDamage(EntityDamageEvent event) {
    if (event instanceof FakeEntityDamageEvent) {
      return;
    }

    Entity entity = event.getEntity();
    EntityType type = entity.getType();
    DamageCause cause = event.getCause();

    switch (type) {
      case PLAYER:

        /* Check for invincibility */
        Player player = (Player) entity;
        PlayerProfile PP = Users.getProfile(player);

        if (PP.getGodMode()) {
          event.setCancelled(true);
          return;
        }

        if (!m.isInvincible(player, event)) {
          if (cause == DamageCause.FALL && mcPermissions.getInstance().acrobatics(player)) {
            Acrobatics.acrobaticsCheck(player, event);
          } else if (cause == DamageCause.BLOCK_EXPLOSION
              && mcPermissions.getInstance().demolitionsExpertise(player)) {
            BlastMining.demolitionsExpertise(player, event);
          }

          if (event.getDamage() >= 1) {
            PP.setRecentlyHurt(System.currentTimeMillis());
          }
        }
        break;

      case WOLF:
        Wolf wolf = (Wolf) entity;

        if ((!m.isInvincible(wolf, event))
            && wolf.isTamed()
            && (wolf.getOwner() instanceof Player)) {
          Taming.preventDamage(event);
        }
        break;

      default:
        break;
    }
  }
  /**
   * Monitor EntityDeath events.
   *
   * @param event The event to monitor
   */
  @EventHandler(priority = EventPriority.MONITOR)
  public void onEntityDeath(EntityDeathEvent event) {
    LivingEntity x = event.getEntity();
    x.setFireTicks(0);

    /* Remove bleed track */
    mcBleedTimer.remove(x);

    Archery.arrowRetrievalCheck(x, plugin);

    if (x instanceof Player) {
      Users.getProfile((Player) x).resetBleedTicks();
    }
  }
  public static void treeFellerCheck(Player player, Block block, Plugin pluginx) {
    PlayerProfile PP = Users.getProfile(player);
    if (m.isAxes(player.getItemInHand())) {
      if (block != null) {
        if (!m.abilityBlockCheck(block)) return;
      }
      /*
       * CHECK FOR AXE PREP MODE
       */
      if (PP.getAxePreparationMode()) {
        PP.setAxePreparationMode(false);
      }
      int ticks = 2;
      int x = PP.getSkill("woodcutting");
      while (x >= 50) {
        x -= 50;
        ticks++;
      }

      if (!PP.getTreeFellerMode()
          && Skills.cooldownOver(
              player, PP.getTreeFellerDeactivatedTimeStamp(), LoadProperties.treeFellerCooldown)) {
        player.sendMessage(Messages.getString("Skills.TreeFellerOn"));
        for (Player y : pluginx.getServer().getOnlinePlayers()) {
          if (y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10)
            y.sendMessage(
                Messages.getString("Skills.TreeFellerPlayer", new Object[] {player.getName()}));
        }
        PP.setTreeFellerActivatedTimeStamp(System.currentTimeMillis());
        PP.setTreeFellerDeactivatedTimeStamp(System.currentTimeMillis() + (ticks * 1000));
        PP.setTreeFellerMode(true);
      }
      if (!PP.getTreeFellerMode()
          && !Skills.cooldownOver(
              player, PP.getTreeFellerDeactivatedTimeStamp(), LoadProperties.treeFellerCooldown)) {
        player.sendMessage(
            ChatColor.RED
                + "You are too tired to use that ability again."
                + ChatColor.YELLOW
                + " ("
                + Skills.calculateTimeLeft(
                    player,
                    PP.getTreeFellerDeactivatedTimeStamp(),
                    LoadProperties.treeFellerCooldown)
                + "s)");
      }
    }
  }
Beispiel #10
0
  /**
   * Apply the Green Thumb ability to blocks.
   *
   * @param is The item in the player's hand
   * @param player The player activating the ability
   * @param block The block being used in the ability
   */
  public static void greenThumbBlocks(ItemStack is, Player player, Block block) {
    final int MAX_BONUS_LEVEL = 1500;

    PlayerProfile PP = Users.getProfile(player);
    int skillLevel = PP.getSkillLevel(SkillType.HERBALISM);
    int seeds = is.getAmount();

    player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1));
    /* No MOARE green terra :D
         if (skillLevel > MAX_BONUS_LEVEL || random.nextInt(1500) <= skillLevel) {
             greenTerra(player, block);
         }
         else {
             player.sendMessage(mcLocale.getString("mcPlayerListener.GreenThumbFail"));
         }
    */
  }
Beispiel #11
0
  /**
   * Process results from Fishing.
   *
   * @param event The event to modify
   */
  public static void processResults(PlayerFishEvent event) {
    Player player = event.getPlayer();
    PlayerProfile PP = Users.getProfile(player);

    getFishingResults(player, event);
    Item theCatch = (Item) event.getCaught();

    if (theCatch.getItemStack().getType() != Material.RAW_FISH) {
      final int ENCHANTMENT_CHANCE = 10;
      boolean enchanted = false;
      ItemStack fishingResults = theCatch.getItemStack();

      player.sendMessage(mcLocale.getString("Fishing.ItemFound"));
      if (ItemChecks.isArmor(fishingResults) || ItemChecks.isTool(fishingResults)) {
        if (random.nextInt(100) <= ENCHANTMENT_CHANCE) {
          for (Enchantment newEnchant : Enchantment.values()) {
            if (newEnchant.canEnchantItem(fishingResults)) {
              Map<Enchantment, Integer> resultEnchantments = fishingResults.getEnchantments();

              for (Enchantment oldEnchant : resultEnchantments.keySet()) {
                if (oldEnchant.conflictsWith(newEnchant)) {
                  return;
                }
              }

              /* Actual chance to have an enchantment is related to your fishing skill */
              if (random.nextInt(15) < Fishing.getFishingLootTier(PP)) {
                enchanted = true;
                int randomEnchantLevel = random.nextInt(newEnchant.getMaxLevel()) + 1;

                if (randomEnchantLevel < newEnchant.getStartLevel()) {
                  randomEnchantLevel = newEnchant.getStartLevel();
                }

                fishingResults.addEnchantment(newEnchant, randomEnchantLevel);
              }
            }
          }
        }
      }

      if (enchanted) {
        player.sendMessage(mcLocale.getString("Fishing.MagicFound"));
      }
    }
  }
Beispiel #12
0
 public static void disarmProcCheck(Player attacker, Player defender) {
   int skillLevel = Users.getProfile(attacker).getSkillLevel(SkillType.UNARMED);
   if (defender.getItemInHand() != null && defender.getItemInHand().getType() != Material.AIR) {
     if (skillLevel >= 1000) {
       if (Math.random() * 3000 <= 1000) {
         ItemStack item = defender.getItemInHand();
         defender.sendMessage(mcLocale.getString("Skills.Disarmed"));
         m.mcDropItem(defender.getLocation(), item);
         defender.setItemInHand(null);
       }
     } else {
       if (Math.random() * 3000 <= skillLevel) {
         ItemStack item = defender.getItemInHand();
         defender.sendMessage(mcLocale.getString("Skills.Disarmed"));
         m.mcDropItem(defender.getLocation(), item);
         defender.setItemInHand(null);
       }
     }
   }
 }
Beispiel #13
0
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (CommandHelper.noConsoleUsage(sender)) {
      return true;
    }

    if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mcgod")) {
      return true;
    }

    PlayerProfile PP = Users.getProfile((Player) sender);

    if (PP.getGodMode()) {
      sender.sendMessage(mcLocale.getString("mcPlayerListener.GodModeDisabled"));
    } else {
      sender.sendMessage(mcLocale.getString("mcPlayerListener.GodModeEnabled"));
    }

    PP.toggleGodMode();

    return true;
  }
Beispiel #14
0
  /**
   * Apply the Green Thumb ability to crops.
   *
   * @param block The block to apply the ability to
   * @param player The player using the ability
   * @param event The event triggering the ability
   * @param plugin mcMMO plugin instance
   */
  private static void greenThumbWheat(
      Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
    final int MAX_BONUS_LEVEL = 1500;

    PlayerProfile PP = Users.getProfile(player);
    int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
    PlayerInventory inventory = player.getInventory();
    boolean hasSeeds = inventory.contains(Material.SEEDS);
    Location loc = block.getLocation();

    if (hasSeeds && (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1500) <= herbLevel)) {
      event.setCancelled(true);

      m.mcDropItem(loc, new ItemStack(Material.WHEAT));
      m.mcRandomDropItems(loc, new ItemStack(Material.SEEDS), 50, 3);

      Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, PP), 1);

      inventory.removeItem(new ItemStack(Material.SEEDS));
      player.updateInventory();
    }
  }
Beispiel #15
0
  /**
   * Process Mining block drops.
   *
   * @param player The player mining the block
   * @param block The block being broken
   */
  public static void miningBlockCheck(Player player, Block block) {
    if (block.hasMetadata("mcmmoPlacedBlock")) {
      return;
    }

    miningXP(player, block);

    if (canBeSuperBroken(block.getType())) {
      final int MAX_BONUS_LEVEL = 1000;

      int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);

      if ((MAX_BONUS_LEVEL > 1000 || (Math.random() * 1000 <= skillLevel))
          && mcPermissions.getInstance().miningDoubleDrops(player)) {
        if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
          m.mcDropItem(block.getLocation(), new ItemStack(block.getType()));
        } else {
          miningDrops(block);
        }
      }
    }
  }
Beispiel #16
0
 public static void treeFeller(Block block, Player player) {
   PlayerProfile PP = Users.getProfile(player);
   int radius = 1;
   if (PP.getSkill("woodcutting") >= 500) radius++;
   if (PP.getSkill("woodcutting") >= 950) radius++;
   ArrayList<Block> blocklist = new ArrayList<Block>();
   ArrayList<Block> toAdd = new ArrayList<Block>();
   if (block != null) blocklist.add(block);
   while (isdone == false) {
     addBlocksToTreeFelling(blocklist, toAdd, radius);
   }
   // This needs to be a hashmap too!
   isdone = false;
   /*
    * Add blocks from the temporary 'toAdd' array list into the 'treeFeller' array list
    * We use this temporary list to prevent concurrent modification exceptions
    */
   for (Block x : toAdd) {
     if (!Config.getInstance().isTreeFellerWatched(x)) Config.getInstance().addTreeFeller(x);
   }
   toAdd.clear();
 }
Beispiel #17
0
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!LoadProperties.mcgodEnable) {
      sender.sendMessage("This command is not enabled.");
      return true;
    }

    if (!(sender instanceof Player)) {
      sender.sendMessage("This command does not support console useage.");
      return true;
    }

    Player player = (Player) sender;
    PlayerProfile PP = Users.getProfile(player);

    if (!mcPermissions.getInstance().mcgod(player)) {
      player.sendMessage(
          ChatColor.YELLOW
              + "[mcMMO] "
              + ChatColor.DARK_RED
              + mcLocale.getString("mcPlayerListener.NoPermission"));
      return true;
    }

    if (mcPermissions.getInstance().mcgod(player)) {
      if (PP.getGodMode()) {
        player.sendMessage(mcLocale.getString("mcPlayerListener.GodModeDisabled"));
        PP.toggleGodMode();
      } else {
        player.sendMessage(mcLocale.getString("mcPlayerListener.GodModeEnabled"));
        PP.toggleGodMode();
      }
    }

    return true;
  }
Beispiel #18
0
  public static void levelUpNotification(SkillType skillType, SpoutPlayer sPlayer) {
    PlayerProfile PP = Users.getProfile(sPlayer);

    Material mat = null;
    switch (skillType) {
      case TAMING:
        switch (getNotificationTier(PP.getSkillLevel(skillType))) {
          case 1:
            mat = Material.PORK;
            break;
          case 2:
            mat = Material.PORK;
            break;
          case 3:
            mat = Material.GRILLED_PORK;
            break;
          case 4:
            mat = Material.GRILLED_PORK;
            break;
          case 5:
            mat = Material.BONE;
            break;
        }
        break;
      case MINING:
        switch (getNotificationTier(PP.getSkillLevel(skillType))) {
          case 1:
            mat = Material.COAL_ORE;
            break;
          case 2:
            mat = Material.IRON_ORE;
            break;
          case 3:
            mat = Material.GOLD_ORE;
            break;
          case 4:
            mat = Material.LAPIS_ORE;
            break;
          case 5:
            mat = Material.DIAMOND_ORE;
            break;
        }
        break;
      case WOODCUTTING:
        switch (getNotificationTier(PP.getSkillLevel(skillType))) {
          case 1:
            mat = Material.WOOD;
            break;
          case 2:
            mat = Material.WOOD;
            break;
          case 3:
            mat = Material.WOOD;
            break;
          case 4:
            mat = Material.LOG;
            break;
          case 5:
            mat = Material.LOG;
            break;
        }
        break;
      case REPAIR:
        switch (getNotificationTier(PP.getSkillLevel(skillType))) {
          case 1:
            mat = Material.COBBLESTONE;
            break;
          case 2:
            mat = Material.IRON_BLOCK;
            break;
          case 3:
            mat = Material.GOLD_BLOCK;
            break;
          case 4:
            mat = Material.LAPIS_BLOCK;
            break;
          case 5:
            mat = Material.DIAMOND_BLOCK;
            break;
        }
        break;
      case HERBALISM:
        switch (getNotificationTier(PP.getSkillLevel(skillType))) {
          case 1:
            mat = Material.YELLOW_FLOWER;
            break;
          case 2:
            mat = Material.RED_ROSE;
            break;
          case 3:
            mat = Material.BROWN_MUSHROOM;
            break;
          case 4:
            mat = Material.RED_MUSHROOM;
            break;
          case 5:
            mat = Material.PUMPKIN;
            break;
        }
        break;
      case ACROBATICS:
        switch (getNotificationTier(PP.getSkillLevel(skillType))) {
          case 1:
            mat = Material.LEATHER_BOOTS;
            break;
          case 2:
            mat = Material.CHAINMAIL_BOOTS;
            break;
          case 3:
            mat = Material.IRON_BOOTS;
            break;
          case 4:
            mat = Material.GOLD_BOOTS;
            break;
          case 5:
            mat = Material.DIAMOND_BOOTS;
            break;
        }
        break;
      case SWORDS:
        switch (getNotificationTier(PP.getSkillLevel(skillType))) {
          case 1:
            mat = Material.WOOD_SWORD;
            break;
          case 2:
            mat = Material.STONE_SWORD;
            break;
          case 3:
            mat = Material.IRON_SWORD;
            break;
          case 4:
            mat = Material.GOLD_SWORD;
            break;
          case 5:
            mat = Material.DIAMOND_SWORD;
            break;
        }
        break;
      case ARCHERY:
        mat = Material.ARROW;
        break;
      case UNARMED:
        switch (getNotificationTier(PP.getSkillLevel(skillType))) {
          case 1:
            mat = Material.LEATHER_HELMET;
            break;
          case 2:
            mat = Material.CHAINMAIL_HELMET;
            break;
          case 3:
            mat = Material.IRON_HELMET;
            break;
          case 4:
            mat = Material.GOLD_HELMET;
            break;
          case 5:
            mat = Material.DIAMOND_HELMET;
            break;
        }
        break;
      case EXCAVATION:
        switch (getNotificationTier(PP.getSkillLevel(skillType))) {
          case 1:
            mat = Material.WOOD_SPADE;
            break;
          case 2:
            mat = Material.STONE_SPADE;
            break;
          case 3:
            mat = Material.IRON_SPADE;
            break;
          case 4:
            mat = Material.GOLD_SPADE;
            break;
          case 5:
            mat = Material.DIAMOND_SPADE;
            break;
        }
        break;
      case AXES:
        switch (getNotificationTier(PP.getSkillLevel(skillType))) {
          case 1:
            mat = Material.WOOD_AXE;
            break;
          case 2:
            mat = Material.STONE_AXE;
            break;
          case 3:
            mat = Material.IRON_AXE;
            break;
          case 4:
            mat = Material.GOLD_AXE;
            break;
          case 5:
            mat = Material.DIAMOND_AXE;
            break;
        }
        break;
      default:
        mat = Material.WATCH;
        break;
    }
    sPlayer.sendNotification(
        ChatColor.GREEN + "Level Up!",
        ChatColor.YELLOW
            + m.getCapitalized(skillType.toString())
            + ChatColor.DARK_AQUA
            + " ("
            + ChatColor.GREEN
            + PP.getSkillLevel(skillType)
            + ChatColor.DARK_AQUA
            + ")",
        mat);
    playLevelUpNoise(sPlayer);
  }
Beispiel #19
0
  /**
   * Monitor FoodLevelChange events.
   *
   * @param event The event to monitor
   */
  @EventHandler(priority = EventPriority.LOW)
  public void onFoodLevelChange(FoodLevelChangeEvent event) {
    if (LoadProperties.herbalismHungerBonus) {
      if (event.getEntity() instanceof Player) {
        Player player = (Player) event.getEntity();
        PlayerProfile PP = Users.getProfile(player);
        int currentFoodLevel = player.getFoodLevel();
        int newFoodLevel = event.getFoodLevel();

        /* Some foods have 3 ranks
         * Some foods have 5 ranks
         * The number of ranks is based on how 'common' the item is
         * We can adjust this quite easily if we find something is giving too much of a bonus
         */

        if (newFoodLevel > currentFoodLevel) {
          Material food = player.getItemInHand().getType();
          int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
          int foodChange = newFoodLevel - currentFoodLevel;
          int rankChange = 0;

          switch (food) {
            case BREAD:
              /* BREAD RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
              rankChange = 200;
              break;

            case COOKIE:
              /* COOKIE RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
              rankChange = 400;
              break;

            case MELON:
              /* MELON RESTORES  1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
              rankChange = 400;
              break;

            case MUSHROOM_SOUP:
              /* MUSHROOM SOUP RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
              rankChange = 200;
              break;

            default:
              return;
          }

          for (int i = 200; i <= 1000; i += rankChange) {
            if (herbLevel >= i) {
              foodChange++;
            }
          }

          /* Make sure we don't go over the max value */
          newFoodLevel = currentFoodLevel + foodChange;
          if (newFoodLevel > 20) {
            event.setFoodLevel(20);
          } else {
            event.setFoodLevel(newFoodLevel);
          }
        }
      }
    }
  }
Beispiel #20
0
  /**
   * Check for extra Herbalism drops.
   *
   * @param block The block to check for extra drops
   * @param player The player getting extra drops
   * @param event The event to use for Green Thumb
   * @param plugin mcMMO plugin instance
   */
  public static void herbalismProcCheck(
      final Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
    final PlayerProfile PP = Users.getProfile(player);
    final int MAX_BONUS_LEVEL = 1000;

    int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
    int id = block.getTypeId();
    Material type = block.getType();

    Byte data = block.getData();
    Location loc = block.getLocation();
    Material mat = null;
    int xp = 0;
    int catciDrops = 0;
    int caneDrops = 0;

    switch (type) {
      case BROWN_MUSHROOM:
      case RED_MUSHROOM:
        if (!block.hasMetadata("mcmmoPlacedBlock")) {
          mat = Material.getMaterial(id);
          xp = LoadProperties.mmushroom;
        }
        break;

      case CACTUS:
        for (int y = 0; y <= 2; y++) {
          Block b = block.getRelative(0, y, 0);
          if (b.getType().equals(Material.CACTUS)) {
            mat = Material.CACTUS;
            if (!b.hasMetadata("mcmmoPlacedBlock")) {
              if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) {
                catciDrops++;
              }
              xp += LoadProperties.mcactus;
            }
          }
        }
        break;

      case CROPS:
        if (data == CropState.RIPE.getData()) {
          mat = Material.WHEAT;
          xp = LoadProperties.mwheat;

          if (LoadProperties.wheatRegrowth && mcPermissions.getInstance().greenThumbWheat(player)) {
            greenThumbWheat(block, player, event, plugin);
          }
        }
        break;

      case MELON_BLOCK:
        if (!block.hasMetadata("mcmmoPlacedBlock")) {
          mat = Material.MELON;
          xp = LoadProperties.mmelon;
        }
        break;

      case NETHER_WARTS:
        if (data == (byte) 0x3) {
          mat = Material.NETHER_STALK;
          xp = LoadProperties.mnetherwart;
        }
        break;

      case PUMPKIN:
      case JACK_O_LANTERN:
        if (!block.hasMetadata("mcmmoPlacedBlock")) {
          mat = Material.getMaterial(id);
          xp = LoadProperties.mpumpkin;
        }
        break;

      case RED_ROSE:
      case YELLOW_FLOWER:
        if (!block.hasMetadata("mcmmoPlacedBlock")) {
          mat = Material.getMaterial(id);
          xp = LoadProperties.mflower;
        }
        break;

      case SUGAR_CANE_BLOCK:
        for (int y = 0; y <= 2; y++) {
          Block b = block.getRelative(0, y, 0);
          if (b.getType().equals(Material.SUGAR_CANE_BLOCK)) {
            mat = Material.SUGAR_CANE;
            if (!b.hasMetadata("mcmmoPlacedBlock")) {
              if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) {
                caneDrops++;
              }
              xp += LoadProperties.msugar;
            }
          }
        }
        break;

      case VINE:
        if (!block.hasMetadata("mcmmoPlacedBlock")) {
          mat = type;
          xp = LoadProperties.mvines;
        }
        break;

      case WATER_LILY:
        if (!block.hasMetadata("mcmmoPlacedBlock")) {
          mat = type;
          xp = LoadProperties.mlilypad;
        }
        break;

      default:
        break;
    }

    if (mat == null) {
      return;
    } else {
      ItemStack is = new ItemStack(mat);

      if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) {
        if (type.equals(Material.CACTUS)) {
          m.mcDropItems(loc, is, catciDrops);
        } else if (type.equals(Material.MELON_BLOCK)) {
          m.mcDropItems(loc, is, 3);
          m.mcRandomDropItems(loc, is, 50, 4);
        } else if (type.equals(Material.NETHER_WARTS)) {
          m.mcDropItems(loc, is, 2);
          m.mcRandomDropItems(loc, is, 50, 3);
        } else if (type.equals(Material.SUGAR_CANE_BLOCK)) {
          m.mcDropItems(loc, is, caneDrops);
        } else {
          m.mcDropItem(loc, is);
        }
      }

      PP.addXP(SkillType.HERBALISM, xp);
      Skills.XpCheckSkill(SkillType.HERBALISM, player);
    }
  }
Beispiel #21
0
  /**
   * Award XP for Mining blocks.
   *
   * @param player The player to award XP to
   * @param block The block to award XP for
   */
  public static void miningXP(Player player, Block block) {
    PlayerProfile PP = Users.getProfile(player);
    Material type = block.getType();
    int xp = 0;

    switch (type) {
      case COAL_ORE:
        xp += LoadProperties.mcoal;
        break;

      case DIAMOND_ORE:
        xp += LoadProperties.mdiamond;
        break;

      case ENDER_STONE:
        xp += LoadProperties.mendstone;
        break;

      case GLOWING_REDSTONE_ORE:
      case REDSTONE_ORE:
        xp += LoadProperties.mredstone;
        break;

      case GLOWSTONE:
        xp += LoadProperties.mglowstone;
        break;

      case GOLD_ORE:
        xp += LoadProperties.mgold;
        break;

      case IRON_ORE:
        xp += LoadProperties.miron;
        break;

      case LAPIS_ORE:
        xp += LoadProperties.mlapis;
        break;

      case MOSSY_COBBLESTONE:
        xp += LoadProperties.mmossstone;
        break;

      case NETHERRACK:
        xp += LoadProperties.mnetherrack;
        break;

      case OBSIDIAN:
        xp += LoadProperties.mobsidian;
        break;

      case SANDSTONE:
        xp += LoadProperties.msandstone;
        break;

      case STONE:
        xp += LoadProperties.mstone;
        break;

      default:
        break;
    }

    PP.addXP(SkillType.MINING, xp, player);
    Skills.XpCheckSkill(SkillType.MINING, player);
  }
Beispiel #22
0
 public static void updateXpBar(Player player) {
   playerHUDs.get(player).updateXpBarDisplay(Users.getProfile(player).getHUDType(), player);
 }
Beispiel #23
0
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    Player player = null;
    if (sender instanceof Player) {
      player = (Player) sender;
    }

    if (player != null && !mcPermissions.getInstance().mmoedit(player)) {
      sender.sendMessage("This command requires permissions.");
      return true;
    }

    if (!LoadProperties.mmoeditEnable) {
      sender.sendMessage("This command is not enabled.");
      return true;
    }

    if (!(sender instanceof Player)) {
      if (args.length < 2) {
        System.out.println("Usage is /mmoedit playername skillname newvalue");
        return true;
      } else if (args.length == 3) {
        if ((plugin.getServer().getPlayer(args[0]) != null)
            && m.isInt(args[2])
            && Skills.isSkill(args[1])) {
          int newvalue = Integer.valueOf(args[2]);
          Users.getProfile(plugin.getServer().getPlayer(args[0]))
              .modifyskill(Skills.getSkillType(args[1]), newvalue);
          System.out.println(
              args[1]
                  + " has been modified for "
                  + plugin.getServer().getPlayer(args[0]).getName()
                  + ".");
        }
      } else {
        System.out.println("Usage is /mmoedit playername skillname newvalue");
      }

      return true;
    }

    PlayerProfile PP = Users.getProfile(player);

    if (!mcPermissions.getInstance().mmoedit(player)) {
      player.sendMessage(
          ChatColor.YELLOW
              + "[mcMMO] "
              + ChatColor.DARK_RED
              + mcLocale.getString("mcPlayerListener.NoPermission"));
      return true;
    }
    if (args.length < 2) {
      player.sendMessage(ChatColor.RED + "Usage is /mmoedit playername skillname newvalue");
      return true;
    }
    if (args.length == 3) {
      if ((plugin.getServer().getPlayer(args[0]) != null)
          && m.isInt(args[2])
          && Skills.isSkill(args[1])) {
        int newvalue = Integer.valueOf(args[2]);
        Users.getProfile(plugin.getServer().getPlayer(args[0]))
            .modifyskill(Skills.getSkillType(args[1]), newvalue);
        player.sendMessage(ChatColor.RED + args[1] + " has been modified.");
      }
    } else if (args.length == 2) {
      if (m.isInt(args[1]) && Skills.isSkill(args[0])) {
        int newvalue = Integer.valueOf(args[1]);
        PP.modifyskill(Skills.getSkillType(args[0]), newvalue);
        player.sendMessage(ChatColor.RED + args[0] + " has been modified.");
      }
    } else {
      player.sendMessage(ChatColor.RED + "Usage is /mmoedit playername skillname newvalue");
    }

    return true;
  }